new functionality added to rater and balancer interface too

This commit is contained in:
Radu Ioan Fericean
2012-03-02 16:27:00 +02:00
parent cd41ea5f9e
commit 2df65dd173
4 changed files with 143 additions and 10 deletions

View File

@@ -139,6 +139,82 @@ func getMaxSessionTimeHandler(w http.ResponseWriter, r *http.Request) {
enc.Encode(result)
}
/*
curl "http://127.0.0.1:8000/addvolumediscountseconds?cstmid=vdf&subj=rif&dest=0257@amount=100"
*/
func addVolumeDiscountSeconds(w http.ResponseWriter, r *http.Request) {
enc := json.NewEncoder(w)
r.ParseForm()
cstmid, ok1 := r.Form["cstmid"]
subj, ok2 := r.Form["subj"]
dest, ok3 := r.Form["dest"]
amount_s, ok4 := r.Form["amount"]
amount, err := strconv.ParseFloat(amount_s[0], 64)
if !ok1 || !ok2 || !ok3 || !ok4 || err != nil {
enc.Encode(IncorrectParameters{"Incorrect parameters"})
return
}
arg := &timespans.CallDescriptor{CstmId: cstmid[0], Subject: subj[0], DestinationPrefix: dest[0], Amount: amount}
result := CallMethod(arg, "Storage.AddVolumeDiscountSeconds")
enc.Encode(result)
}
/*
curl "http://127.0.0.1:8000/resetvolumediscountseconds?cstmid=vdf&subj=rif&dest=0257"
*/
func resetVolumeDiscountSeconds(w http.ResponseWriter, r *http.Request) {
enc := json.NewEncoder(w)
r.ParseForm()
cstmid, ok1 := r.Form["cstmid"]
subj, ok2 := r.Form["subj"]
dest, ok3 := r.Form["dest"]
if !ok1 || !ok2 || !ok3 {
enc.Encode(IncorrectParameters{"Incorrect parameters"})
return
}
arg := &timespans.CallDescriptor{CstmId: cstmid[0], Subject: subj[0], DestinationPrefix: dest[0]}
result := CallMethod(arg, "Storage.ResetVolumeDiscountSeconds")
enc.Encode(result)
}
/*
curl "http://127.0.0.1:8000/addrecievedcallseconds?cstmid=vdf&subj=rif&dest=0257@amount=100"
*/
func addRecievedCallSeconds(w http.ResponseWriter, r *http.Request) {
enc := json.NewEncoder(w)
r.ParseForm()
cstmid, ok1 := r.Form["cstmid"]
subj, ok2 := r.Form["subj"]
dest, ok3 := r.Form["dest"]
amount_s, ok4 := r.Form["amount"]
amount, err := strconv.ParseFloat(amount_s[0], 64)
if !ok1 || !ok2 || !ok3 || !ok4 || err != nil {
enc.Encode(IncorrectParameters{"Incorrect parameters"})
return
}
arg := &timespans.CallDescriptor{CstmId: cstmid[0], Subject: subj[0], DestinationPrefix: dest[0], Amount: amount}
result := CallMethod(arg, "Storage.AddRecievedCallSeconds")
enc.Encode(result)
}
/*
curl "http://127.0.0.1:8000/resetuserbudget?cstmid=vdf&subj=rif&dest=0257"
*/
func resetUserBudget(w http.ResponseWriter, r *http.Request) {
enc := json.NewEncoder(w)
r.ParseForm()
cstmid, ok1 := r.Form["cstmid"]
subj, ok2 := r.Form["subj"]
dest, ok3 := r.Form["dest"]
if !ok1 || !ok2 || !ok3 {
enc.Encode(IncorrectParameters{"Incorrect parameters"})
return
}
arg := &timespans.CallDescriptor{CstmId: cstmid[0], Subject: subj[0], DestinationPrefix: dest[0]}
result := CallMethod(arg, "Storage.ResetUserBudget")
enc.Encode(result)
}
func listenToHttpRequests() {
http.HandleFunc("/", statusHandler)
http.HandleFunc("/getcost", getCostHandler)
@@ -146,6 +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("/addrecievedcallseconds", addRecievedCallSeconds)
http.HandleFunc("/resetuserbudget", resetUserBudget)
log.Print("The server is listening on ", *httpApiAddress)
http.ListenAndServe(*httpApiAddress, nil)
}

View File

@@ -55,6 +55,26 @@ func (r *Responder) GetMaxSessionTime(arg timespans.CallDescriptor, replay *floa
return
}
func (r *Responder) AddVolumeDiscountSeconds(arg timespans.CallDescriptor, replay *float64) (err error) {
*replay = CallMethod(&arg, "Storage.AddVolumeDiscountSeconds")
return
}
func (r *Responder) ResetVolumeDiscountSeconds(arg timespans.CallDescriptor, replay *float64) (err error) {
*replay = CallMethod(&arg, "Storage.ResetVolumeDiscountSeconds")
return
}
func (r *Responder) AddRecievedCallSeconds(arg timespans.CallDescriptor, replay *float64) (err error) {
*replay = CallMethod(&arg, "Storage.AddRecievedCallSeconds")
return
}
func (r *Responder) ResetUserBudget(arg timespans.CallDescriptor, replay *float64) (err error) {
*replay = CallMethod(&arg, "Storage.ResetUserBudget")
return
}
/*
Creates the json rpc server.
*/

View File

@@ -83,6 +83,38 @@ func (s *Storage) GetMaxSessionTime(cd timespans.CallDescriptor, reply *float64)
return err
}
func (s *Storage) AddVolumeDiscountSeconds(cd timespans.CallDescriptor, reply *float64) (err error) {
descriptor := &cd
descriptor.SetStorageGetter(s.sg)
e := descriptor.AddVolumeDiscountSeconds()
*reply, err = 0, e
return err
}
func (s *Storage) ResetVolumeDiscountSeconds(cd timespans.CallDescriptor, reply *float64) (err error) {
descriptor := &cd
descriptor.SetStorageGetter(s.sg)
e := descriptor.ResetVolumeDiscountSeconds()
*reply, err = 0, e
return err
}
func (s *Storage) AddRecievedCallSeconds(cd timespans.CallDescriptor, reply *float64) (err error) {
descriptor := &cd
descriptor.SetStorageGetter(s.sg)
e := descriptor.AddRecievedCallSeconds()
*reply, err = 0, e
return err
}
func (s *Storage) ResetUserBudget(cd timespans.CallDescriptor, reply *float64) (err error) {
descriptor := &cd
descriptor.SetStorageGetter(s.sg)
e := descriptor.ResetUserBudget()
*reply, err = 0, e
return err
}
/*
RPC method that trigers rater shutdown in case of server exit.
*/

View File

@@ -223,6 +223,17 @@ func (cd *CallDescriptor) GetCost() (*CallCost, error) {
return cc, err
}
/*
The output structure that will be returned with the call cost information.
*/
type CallCost struct {
TOR int
CstmId, Subject, DestinationPrefix string
Cost, ConnectFee float64
Timespans []*TimeSpan
}
/*
Returns the cost of a second in the present time conditions.
*/
@@ -361,13 +372,3 @@ func (cd *CallDescriptor) ResetUserBudget() (err error) {
}
return err
}
/*
The output structure that will be returned with the call cost information.
*/
type CallCost struct {
TOR int
CstmId, Subject, DestinationPrefix string
Cost, ConnectFee float64
Timespans []*TimeSpan
}