user budget sone and redis back on speed

This commit is contained in:
Radu Ioan Fericean
2012-02-20 22:03:55 +02:00
parent 9b35bb8ce3
commit 23bf64e819
8 changed files with 164 additions and 20 deletions

View File

@@ -19,12 +19,14 @@ var (
apfile = flag.String("apfile", "ap.json", "Activation Periods containing intervals file")
destfile = flag.String("destfile", "dest.json", "Destinations file")
tpfile = flag.String("tpfile", "tp.json", "Tariff plans file")
ubfile = flag.String("ubfile", "ub.json", "User budgets file")
)
func writeToStorage(storage timespans.StorageGetter,
callDescriptors []*timespans.CallDescriptor,
destinations []*timespans.Destination,
tariffPlans []*timespans.TariffPlan) {
tariffPlans []*timespans.TariffPlan,
userBudgets []*timespans.UserBudget) {
for _, cd := range callDescriptors {
storage.SetActivationPeriods(cd.GetKey(), cd.ActivationPeriods)
log.Printf("Storing %q", cd.GetKey())
@@ -37,6 +39,10 @@ func writeToStorage(storage timespans.StorageGetter,
storage.SetTariffPlan(tp)
log.Printf("Storing %q", tp.Id)
}
for _, ub := range userBudgets {
storage.SetUserBudget(ub)
log.Printf("Storing %q", ub.Id)
}
}
func main() {
@@ -92,19 +98,35 @@ func main() {
}
fin.Close()
// reading user budgets
fin, err = os.Open(*ubfile)
if err != nil {
log.Print("Cannot open user budgets input file", err)
}
dec = json.NewDecoder(fin)
var userBudgets []*timespans.UserBudget
if err := dec.Decode(&userBudgets); err != nil {
log.Println(err)
return
}
fin.Close()
switch *storage {
case "kyoto":
storage, _ := timespans.NewKyotoStorage(*kyotofile)
defer storage.Close()
writeToStorage(storage, callDescriptors, destinations, tariffPlans)
writeToStorage(storage, callDescriptors, destinations, tariffPlans, userBudgets)
case "mongo":
storage, _ := timespans.NewMongoStorage("127.0.0.1", "test")
defer storage.Close()
writeToStorage(storage, callDescriptors, destinations, tariffPlans)
writeToStorage(storage, callDescriptors, destinations, tariffPlans, userBudgets)
default:
storage, _ := timespans.NewRedisStorage(*redisserver, *redisdb)
defer storage.Close()
writeToStorage(storage, callDescriptors, destinations, tariffPlans)
writeToStorage(storage, callDescriptors, destinations, tariffPlans, userBudgets)
}
}