示例#1
0
// Computes the LCR for a specific request emulating a call
func (self *ApierV1) GetLcr(lcrReq engine.LcrRequest, lcrReply *engine.LcrReply) error {
	cd, err := lcrReq.AsCallDescriptor(self.Config.DefaultTimezone)
	if err != nil {
		return err
	}
	var lcrQried engine.LCRCost
	if err := self.Responder.GetLCR(&engine.AttrGetLcr{CallDescriptor: cd, Paginator: lcrReq.Paginator}, &lcrQried); err != nil {
		return utils.NewErrServerError(err)
	}
	if lcrQried.Entry == nil {
		return utils.ErrNotFound
	}
	lcrReply.DestinationId = lcrQried.Entry.DestinationId
	lcrReply.RPCategory = lcrQried.Entry.RPCategory
	lcrReply.Strategy = lcrQried.Entry.Strategy
	for _, qriedSuppl := range lcrQried.SupplierCosts {
		if qriedSuppl.Error != "" {
			utils.Logger.Err(fmt.Sprintf("LCR_ERROR: supplier <%s>, error <%s>", qriedSuppl.Supplier, qriedSuppl.Error))
			if !lcrReq.IgnoreErrors {
				return fmt.Errorf("%s:%s", utils.ErrServerError.Error(), "LCR_COMPUTE_ERRORS")
			}
			continue
		}
		if dtcs, err := utils.NewDTCSFromRPKey(qriedSuppl.Supplier); err != nil {
			return utils.NewErrServerError(err)
		} else {
			lcrReply.Suppliers = append(lcrReply.Suppliers, &engine.LcrSupplier{Supplier: dtcs.Subject, Cost: qriedSuppl.Cost, QOS: qriedSuppl.QOS})
		}
	}
	return nil
}
示例#2
0
// Queries LCR and sets the cgr_lcr channel variable
func (sm *FSSessionManager) setCgrLcr(ev engine.Event, connId string) error {
	var lcrCost engine.LCRCost
	startTime, err := ev.GetSetupTime(utils.META_DEFAULT, sm.timezone)
	if err != nil {
		return err
	}
	cd := &engine.CallDescriptor{
		Direction:   ev.GetDirection(utils.META_DEFAULT),
		Tenant:      ev.GetTenant(utils.META_DEFAULT),
		Category:    ev.GetCategory(utils.META_DEFAULT),
		Subject:     ev.GetSubject(utils.META_DEFAULT),
		Account:     ev.GetAccount(utils.META_DEFAULT),
		Destination: ev.GetDestination(utils.META_DEFAULT),
		TimeStart:   startTime,
		TimeEnd:     startTime.Add(config.CgrConfig().MaxCallDuration),
	}
	if err := sm.rater.GetLCR(&engine.AttrGetLcr{CallDescriptor: cd}, &lcrCost); err != nil {
		return err
	}
	supps := []string{}
	for _, supplCost := range lcrCost.SupplierCosts {
		if dtcs, err := utils.NewDTCSFromRPKey(supplCost.Supplier); err != nil {
			return err
		} else if len(dtcs.Subject) != 0 {
			supps = append(supps, dtcs.Subject)
		}
	}
	fsArray := SliceAsFsArray(supps)
	if _, err = sm.conns[connId].SendApiCmd(fmt.Sprintf("uuid_setvar %s cgr_notify %s\n\n", ev.GetUUID(), fsArray)); err != nil {
		return err
	}
	return nil
}
示例#3
0
文件: lcr.go 项目: iwada/cgrates
func (lc *LCRCost) SuppliersSlice() ([]string, error) {
	if lc.Entry == nil {
		return nil, utils.ErrNotFound
	}
	supps := []string{}
	for _, supplCost := range lc.SupplierCosts {
		if supplCost.Error != "" {
			continue // Do not add the supplier with cost errors to list of suppliers available
		}
		if dtcs, err := utils.NewDTCSFromRPKey(supplCost.Supplier); err != nil {
			return nil, err
		} else if len(dtcs.Subject) != 0 {
			supps = append(supps, dtcs.Subject)
		}
	}
	if len(supps) == 0 {
		return nil, utils.ErrNotFound
	}
	return supps, nil
}