From b343d89293dbb65759dbc371198585b097d42234 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 22 Oct 2013 14:13:28 +0300 Subject: [PATCH] added rating plans history --- history/file_scribe.go | 19 +++++++++++++++++++ history/mock_scribe.go | 12 ++++++++++++ history/scribe.go | 1 + 3 files changed, 32 insertions(+) diff --git a/history/file_scribe.go b/history/file_scribe.go index c974876f7..3d4fe4a6d 100644 --- a/history/file_scribe.go +++ b/history/file_scribe.go @@ -33,6 +33,7 @@ import ( const ( DESTINATIONS_FILE = "destinations.json" + RATING_PLANS_FILE = "rating_plans.json" RATING_PROFILES_FILE = "rating_profiles.json" ) @@ -41,6 +42,7 @@ type FileScribe struct { fileRoot string gitCommand string destinations records + ratingPlans records ratingProfiles records loopChecker chan int waitingFile string @@ -70,6 +72,9 @@ func (s *FileScribe) Record(rec *Record, out *int) error { case strings.HasPrefix(rec.Key, DESTINATION_PREFIX): s.destinations = s.destinations.SetOrAdd(&Record{rec.Key[len(DESTINATION_PREFIX):], rec.Object}) fileToSave = DESTINATIONS_FILE + case strings.HasPrefix(rec.Key, RATING_PLAN_PREFIX): + s.ratingPlans = s.ratingPlans.SetOrAdd(&Record{rec.Key[len(RATING_PLAN_PREFIX):], rec.Object}) + fileToSave = RATING_PLANS_FILE case strings.HasPrefix(rec.Key, RATING_PROFILE_PREFIX): s.ratingProfiles = s.ratingProfiles.SetOrAdd(&Record{rec.Key[len(RATING_PROFILE_PREFIX):], rec.Object}) fileToSave = RATING_PROFILES_FILE @@ -120,6 +125,11 @@ func (s *FileScribe) gitInit() error { } else { f.Close() } + if f, err := os.Create(filepath.Join(s.fileRoot, RATING_PLANS_FILE)); err != nil { + return errors.New(" Error writing rating plans file: " + err.Error()) + } else { + f.Close() + } if f, err := os.Create(filepath.Join(s.fileRoot, RATING_PROFILES_FILE)); err != nil { return errors.New(" Error writing rating profiles file: " + err.Error()) } else { @@ -159,6 +169,11 @@ func (s *FileScribe) load(filename string) error { return errors.New(" Error loading destinations: " + err.Error()) } s.destinations.Sort() + case RATING_PLANS_FILE: + if err := d.Decode(&s.ratingPlans); err != nil && err != io.EOF { + return errors.New(" Error loading rating plans: " + err.Error()) + } + s.ratingPlans.Sort() case RATING_PROFILES_FILE: if err := d.Decode(&s.ratingProfiles); err != nil && err != io.EOF { return errors.New(" Error loading rating profiles: " + err.Error()) @@ -182,6 +197,10 @@ func (s *FileScribe) save(filename string) error { if err := s.format(b, s.destinations); err != nil { return err } + case RATING_PLANS_FILE: + if err := s.format(b, s.ratingPlans); err != nil { + return err + } case RATING_PROFILES_FILE: if err := s.format(b, s.ratingProfiles); err != nil { return err diff --git a/history/mock_scribe.go b/history/mock_scribe.go index 7b2a5af65..c9afa1a37 100644 --- a/history/mock_scribe.go +++ b/history/mock_scribe.go @@ -30,8 +30,10 @@ import ( type MockScribe struct { sync.Mutex destinations records + ratingPlans records ratingProfiles records DestBuf bytes.Buffer + RplBuf bytes.Buffer RpBuf bytes.Buffer } @@ -44,6 +46,9 @@ func (s *MockScribe) Record(rec *Record, out *int) error { case strings.HasPrefix(rec.Key, DESTINATION_PREFIX): s.destinations = s.destinations.SetOrAdd(&Record{rec.Key[len(DESTINATION_PREFIX):], rec.Object}) s.save(DESTINATIONS_FILE) + case strings.HasPrefix(rec.Key, RATING_PLAN_PREFIX): + s.ratingPlans = s.ratingPlans.SetOrAdd(&Record{rec.Key[len(RATING_PLAN_PREFIX):], rec.Object}) + s.save(RATING_PLANS_FILE) case strings.HasPrefix(rec.Key, RATING_PROFILE_PREFIX): s.ratingProfiles = s.ratingProfiles.SetOrAdd(&Record{rec.Key[len(RATING_PROFILE_PREFIX):], rec.Object}) s.save(RATING_PROFILES_FILE) @@ -63,6 +68,13 @@ func (s *MockScribe) save(filename string) error { if err := s.format(b, s.destinations); err != nil { return err } + case RATING_PLANS_FILE: + s.RplBuf.Reset() + b := bufio.NewWriter(&s.RplBuf) + defer b.Flush() + if err := s.format(b, s.ratingPlans); err != nil { + return err + } case RATING_PROFILES_FILE: s.RpBuf.Reset() b := bufio.NewWriter(&s.RpBuf) diff --git a/history/scribe.go b/history/scribe.go index a1dd72aff..8391feb0e 100644 --- a/history/scribe.go +++ b/history/scribe.go @@ -23,6 +23,7 @@ import ( ) const ( + RATING_PLAN_PREFIX = "rpl_" RATING_PROFILE_PREFIX = "rpf_" DESTINATION_PREFIX = "dst_" )