From d326fff819a3e4083dfe60d01e22658259dc70a8 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Sat, 7 Jul 2012 12:47:18 +0300 Subject: [PATCH] updated http tool --- cmd/cgr-balancer/http_responder.go | 124 ++++++++++-------- cmd/stress/cgr-spansstress/cgr-spansstress.go | 11 +- 2 files changed, 78 insertions(+), 57 deletions(-) diff --git a/cmd/cgr-balancer/http_responder.go b/cmd/cgr-balancer/http_responder.go index 578d79d12..436397775 100644 --- a/cmd/cgr-balancer/http_responder.go +++ b/cmd/cgr-balancer/http_responder.go @@ -30,107 +30,117 @@ type IncorrectParameters struct { } /* -curl "http://127.0.0.1:8000/getcost?tenant=vdf&subj=rif&dest=0257" +curl "http://127.0.0.1:8000/getcost?direction=out&tenant=vdf&tor=0&subj=rif&dest=0257" */ func getCostHandler(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) r.ParseForm() - tenant, ok1 := r.Form["tenant"] - subj, ok2 := r.Form["subj"] - dest, ok3 := r.Form["dest"] - if !ok1 || !ok2 || !ok3 { + direction, ok1 := r.Form["direction"] + tenant, ok2 := r.Form["tenant"] + tor, ok3 := r.Form["tor"] + subj, ok4 := r.Form["subj"] + dest, ok5 := r.Form["dest"] + if !ok1 || !ok2 || !ok3 || !ok4 || !ok5 { enc.Encode(IncorrectParameters{"Incorrect parameters"}) return } - arg := ×pans.CallDescriptor{Tenant: tenant[0], Subject: subj[0], Destination: dest[0]} + arg := ×pans.CallDescriptor{Direction: direction[0], Tenant: tenant[0], TOR: tor[0], Subject: subj[0], Destination: dest[0]} callCost := GetCallCost(arg, "Responder.GetCost") enc.Encode(callCost) } /* -curl "http://127.0.0.1:8000/debitbalance?tenant=vdf&subj=rif&dest=0257@amount=100" +curl "http://127.0.0.1:8000/debitbalance?direction=out&tenant=vdf&tor=0&subj=rif&dest=0257@amount=100" */ func debitBalanceHandler(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) r.ParseForm() - tenant, ok1 := r.Form["tenant"] - subj, ok2 := r.Form["subj"] - dest, ok3 := r.Form["dest"] - amount_s, ok4 := r.Form["amount"] + direction, ok1 := r.Form["direction"] + tenant, ok2 := r.Form["tenant"] + tor, ok3 := r.Form["tor"] + subj, ok4 := r.Form["subj"] + dest, ok5 := r.Form["dest"] + amount_s, ok6 := r.Form["amount"] amount, err := strconv.ParseFloat(amount_s[0], 64) - if !ok1 || !ok2 || !ok3 || ok4 || err != nil { + if !ok1 || !ok2 || !ok3 || !ok4 || !ok5 || !ok6 || err != nil { enc.Encode(IncorrectParameters{"Incorrect parameters"}) return } - arg := ×pans.CallDescriptor{Tenant: tenant[0], Subject: subj[0], Destination: dest[0], Amount: amount} + arg := ×pans.CallDescriptor{Direction: direction[0], Tenant: tenant[0], TOR: tor[0], Subject: subj[0], Destination: dest[0], Amount: amount} result := CallMethod(arg, "Responder.DebitCents") enc.Encode(result) } /* -curl "http://127.0.0.1:8000/debitsms?tenant=vdf&subj=rif&dest=0257@amount=100" +curl "http://127.0.0.1:8000/debitsms?direction=out&tenant=vdf&tor=0&subj=rif&dest=0257@amount=100" */ func debitSMSHandler(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) r.ParseForm() - tenant, ok1 := r.Form["tenant"] - subj, ok2 := r.Form["subj"] - dest, ok3 := r.Form["dest"] - amount_s, ok4 := r.Form["amount"] + direction, ok1 := r.Form["direction"] + tenant, ok2 := r.Form["tenant"] + tor, ok3 := r.Form["tor"] + subj, ok4 := r.Form["subj"] + dest, ok5 := r.Form["dest"] + amount_s, ok6 := r.Form["amount"] amount, err := strconv.ParseFloat(amount_s[0], 64) - if !ok1 || !ok2 || !ok3 || !ok4 || err != nil { + if !ok1 || !ok2 || !ok3 || !ok4 || !ok5 || !ok6 || err != nil { enc.Encode(IncorrectParameters{"Incorrect parameters"}) return } - arg := ×pans.CallDescriptor{Tenant: tenant[0], Subject: subj[0], Destination: dest[0], Amount: amount} + arg := ×pans.CallDescriptor{Direction: direction[0], Tenant: tenant[0], TOR: tor[0], Subject: subj[0], Destination: dest[0], Amount: amount} result := CallMethod(arg, "Responder.DebitSMS") enc.Encode(result) } /* -curl "http://127.0.0.1:8000/debitseconds?tenant=vdf&subj=rif&dest=0257@amount=100" +curl "http://127.0.0.1:8000/debitseconds?direction=out&tenant=vdf&tor=0&subj=rif&dest=0257@amount=100" */ func debitSecondsHandler(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) r.ParseForm() - tenant, ok1 := r.Form["tenant"] - subj, ok2 := r.Form["subj"] - dest, ok3 := r.Form["dest"] - amount_s, ok4 := r.Form["amount"] + direction, ok1 := r.Form["direction"] + tenant, ok2 := r.Form["tenant"] + tor, ok3 := r.Form["tor"] + subj, ok4 := r.Form["subj"] + dest, ok5 := r.Form["dest"] + amount_s, ok6 := r.Form["amount"] amount, err := strconv.ParseFloat(amount_s[0], 64) - if !ok1 || !ok2 || !ok3 || !ok4 || err != nil { + if !ok1 || !ok2 || !ok3 || !ok4 || !ok5 || !ok6 || err != nil { enc.Encode(IncorrectParameters{"Incorrect parameters"}) return } - arg := ×pans.CallDescriptor{Tenant: tenant[0], Subject: subj[0], Destination: dest[0], Amount: amount} + arg := ×pans.CallDescriptor{Direction: direction[0], Tenant: tenant[0], TOR: tor[0], Subject: subj[0], Destination: dest[0], Amount: amount} result := CallMethod(arg, "Responder.DebitSeconds") enc.Encode(result) } /* -curl "http://127.0.0.1:8000/getmaxsessiontime?tenant=vdf&subj=rif&dest=0257@amount=100" +curl "http://127.0.0.1:8000/getmaxsessiontime?direction=out&tenant=vdf&tor=0&subj=rif&dest=0257@amount=100" */ func getMaxSessionTimeHandler(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) r.ParseForm() - tenant, ok1 := r.Form["tenant"] - subj, ok2 := r.Form["subj"] - dest, ok3 := r.Form["dest"] - amount_s, ok4 := r.Form["amount"] + direction, ok1 := r.Form["direction"] + tenant, ok2 := r.Form["tenant"] + tor, ok3 := r.Form["tor"] + subj, ok4 := r.Form["subj"] + dest, ok5 := r.Form["dest"] + amount_s, ok6 := r.Form["amount"] amount, err := strconv.ParseFloat(amount_s[0], 64) - if !ok1 || !ok2 || !ok3 || !ok4 || err != nil { + if !ok1 || !ok2 || !ok3 || !ok4 || !ok5 || !ok6 || err != nil { enc.Encode(IncorrectParameters{"Incorrect parameters"}) return } - arg := ×pans.CallDescriptor{Tenant: tenant[0], Subject: subj[0], Destination: dest[0], Amount: amount} + arg := ×pans.CallDescriptor{Direction: direction[0], Tenant: tenant[0], TOR: tor[0], Subject: subj[0], Destination: dest[0], Amount: amount} result := CallMethod(arg, "Responder.GetMaxSessionTime") enc.Encode(result) } /* -curl "http://127.0.0.1:8000/addvolumediscountseconds?tenant=vdf&subj=rif&dest=0257@amount=100" +curl "http://127.0.0.1:8000/addvolumediscountseconds?direction=out&tenant=vdf&tor=0&subj=rif&dest=0257@amount=100" */ -func addVolumeDiscountSeconds(w http.ResponseWriter, r *http.Request) { +/*func addVolumeDiscountSeconds(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) r.ParseForm() tenant, ok1 := r.Form["tenant"] @@ -142,15 +152,15 @@ func addVolumeDiscountSeconds(w http.ResponseWriter, r *http.Request) { enc.Encode(IncorrectParameters{"Incorrect parameters"}) return } - arg := ×pans.CallDescriptor{Tenant: tenant[0], Subject: subj[0], Destination: dest[0], Amount: amount} + arg := ×pans.CallDescriptor{Direction: direction[0], Tenant: tenant[0], TOR: tor[0], Subject: subj[0], Destination: dest[0], Amount: amount} result := CallMethod(arg, "Responder.AddVolumeDiscountSeconds") enc.Encode(result) -} +}*/ /* -curl "http://127.0.0.1:8000/resetvolumediscountseconds?tenant=vdf&subj=rif&dest=0257" +curl "http://127.0.0.1:8000/resetvolumediscountseconds?direction=out&tenant=vdf&tor=0&subj=rif&dest=0257" */ -func resetVolumeDiscountSeconds(w http.ResponseWriter, r *http.Request) { +/*func resetVolumeDiscountSeconds(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) r.ParseForm() tenant, ok1 := r.Form["tenant"] @@ -160,35 +170,37 @@ func resetVolumeDiscountSeconds(w http.ResponseWriter, r *http.Request) { enc.Encode(IncorrectParameters{"Incorrect parameters"}) return } - arg := ×pans.CallDescriptor{Tenant: tenant[0], Subject: subj[0], Destination: dest[0]} + arg := ×pans.CallDescriptor{Direction: direction[0], Tenant: tenant[0], TOR: tor[0], Subject: subj[0], Destination: dest[0]} result := CallMethod(arg, "Responder.ResetVolumeDiscountSeconds") enc.Encode(result) -} +}*/ /* -curl "http://127.0.0.1:8000/addrecievedcallseconds?tenant=vdf&subj=rif&dest=0257@amount=100" +curl "http://127.0.0.1:8000/addrecievedcallseconds?direction=out&tenant=vdf&tor=0&subj=rif&dest=0257@amount=100" */ func addRecievedCallSeconds(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) r.ParseForm() - tenant, ok1 := r.Form["tenant"] - subj, ok2 := r.Form["subj"] - dest, ok3 := r.Form["dest"] - amount_s, ok4 := r.Form["amount"] + direction, ok1 := r.Form["direction"] + tenant, ok2 := r.Form["tenant"] + tor, ok3 := r.Form["tor"] + subj, ok4 := r.Form["subj"] + dest, ok5 := r.Form["dest"] + amount_s, ok6 := r.Form["amount"] amount, err := strconv.ParseFloat(amount_s[0], 64) - if !ok1 || !ok2 || !ok3 || !ok4 || err != nil { + if !ok1 || !ok2 || !ok3 || !ok4 || !ok5 || !ok6 || err != nil { enc.Encode(IncorrectParameters{"Incorrect parameters"}) return } - arg := ×pans.CallDescriptor{Tenant: tenant[0], Subject: subj[0], Destination: dest[0], Amount: amount} + arg := ×pans.CallDescriptor{Direction: direction[0], Tenant: tenant[0], TOR: tor[0], Subject: subj[0], Destination: dest[0], Amount: amount} result := CallMethod(arg, "Responder.AddRecievedCallSeconds") enc.Encode(result) } /* -curl "http://127.0.0.1:8000/resetuserbudget?tenant=vdf&subj=rif&dest=0257" +curl "http://127.0.0.1:8000/resetuserbudget?direction=out&tenant=vdf&tor=0&subj=rif&dest=0257" */ -func resetUserBudget(w http.ResponseWriter, r *http.Request) { +/*func resetUserBudget(w http.ResponseWriter, r *http.Request) { enc := json.NewEncoder(w) r.ParseForm() tenant, ok1 := r.Form["tenant"] @@ -198,10 +210,10 @@ func resetUserBudget(w http.ResponseWriter, r *http.Request) { enc.Encode(IncorrectParameters{"Incorrect parameters"}) return } - arg := ×pans.CallDescriptor{Tenant: tenant[0], Subject: subj[0], Destination: dest[0]} + arg := ×pans.CallDescriptor{Direction: direction[0], Tenant: tenant[0], TOR: tor[0], Subject: subj[0], Destination: dest[0]} result := CallMethod(arg, "Responder.ResetUserBudget") enc.Encode(result) -} +}*/ func listenToHttpRequests() { http.Handle("/static/", http.FileServer(http.Dir(""))) @@ -210,10 +222,10 @@ func listenToHttpRequests() { http.HandleFunc("/debitsms", debitSMSHandler) http.HandleFunc("/debitseconds", debitSecondsHandler) http.HandleFunc("/getmaxsessiontime", debitSecondsHandler) - http.HandleFunc("/addvolumediscountseconds", addVolumeDiscountSeconds) - http.HandleFunc("/resetvolumediscountseconds", resetVolumeDiscountSeconds) + // http.HandleFunc("/addvolumediscountseconds", addVolumeDiscountSeconds) + // http.HandleFunc("/resetvolumediscountseconds", resetVolumeDiscountSeconds) http.HandleFunc("/addrecievedcallseconds", addRecievedCallSeconds) - http.HandleFunc("/resetuserbudget", resetUserBudget) + // http.HandleFunc("/resetuserbudget", resetUserBudget) http.HandleFunc("/", statusHandler) http.HandleFunc("/getmem", memoryHandler) http.HandleFunc("/raters", ratersHandler) diff --git a/cmd/stress/cgr-spansstress/cgr-spansstress.go b/cmd/stress/cgr-spansstress/cgr-spansstress.go index c586d634b..750971d15 100644 --- a/cmd/stress/cgr-spansstress/cgr-spansstress.go +++ b/cmd/stress/cgr-spansstress/cgr-spansstress.go @@ -30,6 +30,7 @@ import ( var ( cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") + memprofile = flag.String("memprofile", "", "write memory profile to this file") runs = flag.Int("runs", 10000, "stress cycle number") ) @@ -45,7 +46,15 @@ func main() { pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } - + if *memprofile != "" { + f, err := os.Create(*memprofile) + if err != nil { + log.Fatal(err) + } + pprof.WriteHeapProfile(f) + f.Close() + return + } t1 := time.Date(2012, time.February, 02, 17, 30, 0, 0, time.UTC) t2 := time.Date(2012, time.February, 02, 18, 30, 0, 0, time.UTC) cd := timespans.CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}