RawCDR interface now properly returns duration

This commit is contained in:
DanB
2014-04-27 09:19:30 +02:00
parent 330fb7b894
commit f0095dbcb3
8 changed files with 23 additions and 16 deletions

View File

@@ -165,9 +165,8 @@ func (fsCdr FSCdr) GetHangupTime() (t time.Time, err error) {
}
// Extracts duration as considered by the telecom switch
func (fsCdr FSCdr) GetDuration() time.Duration {
dur, _ := utils.ParseDurationWithSecs(fsCdr.vars[FS_DURATION])
return dur
func (fsCdr FSCdr) GetDuration() (time.Duration, error) {
return utils.ParseDurationWithSecs(fsCdr.vars[FS_DURATION])
}
func (fsCdr FSCdr) Store() (result string, err error) {
@@ -192,7 +191,8 @@ func (fsCdr FSCdr) Store() (result string, err error) {
return "", err
}
result += strconv.FormatInt(et.UnixNano(), 10) + "|"
result += strconv.FormatInt(int64(fsCdr.GetDuration().Seconds()), 10) + "|"
dur, _ := fsCdr.GetDuration()
result += strconv.FormatInt(int64(dur.Seconds()), 10) + "|"
return
}

View File

@@ -87,8 +87,9 @@ func TestCDRFields(t *testing.T) {
if answerTime.UTC() != expectedATime {
t.Error("Error parsing answerTime: ", answerTime.UTC())
}
if fsCdr.GetDuration() != 4000000000 {
t.Error("Error parsing duration: ", fsCdr.GetDuration())
dur, _ := fsCdr.GetDuration()
if dur != 4000000000 {
t.Error("Error parsing duration: ", dur)
}
cfg.CDRSExtraFields = []*utils.RSRField{&utils.RSRField{Id: "sip_user_agent"}, &utils.RSRField{Id: "read_codec"}, &utils.RSRField{Id: "write_codec"}}
extraFields := fsCdr.GetExtraFields()

View File

@@ -523,6 +523,7 @@ func (self *SQLStorage) SetCdr(cdr utils.RawCDR) (err error) {
// map[account:1001 direction:out orig_ip:172.16.1.1 tor:call accid:accid23 answer_time:2013-02-03 19:54:00 cdrsource:freeswitch_csv destination:+4986517174963 duration:62 reqtype:prepaid subject:1001 supplier:supplier1 tenant:cgrates.org]
setupTime, _ := cdr.GetSetupTime() // Ignore errors, we want to store the cdr no matter what
answerTime, _ := cdr.GetAnswerTime() // Ignore errors, we want to store the cdr no matter what
dur, _ := cdr.GetDuration()
_, err = self.Db.Exec(fmt.Sprintf("INSERT INTO %s VALUES (NULL,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s', %d)",
utils.TBL_CDRS_PRIMARY,
cdr.GetCgrId(),
@@ -538,7 +539,7 @@ func (self *SQLStorage) SetCdr(cdr utils.RawCDR) (err error) {
cdr.GetDestination(),
setupTime,
answerTime,
cdr.GetDuration(),
dur,
))
if err != nil {
Logger.Err(fmt.Sprintf("failed to execute cdr insert statement: %v", err))

View File

@@ -104,9 +104,8 @@ func (cgrCdr CgrCdr) GetAnswerTime() (t time.Time, err error) {
}
// Extracts duration as considered by the telecom switch
func (cgrCdr CgrCdr) GetDuration() time.Duration {
dur, _ := ParseDurationWithSecs(cgrCdr[DURATION])
return dur
func (cgrCdr CgrCdr) GetDuration() (time.Duration, error) {
return ParseDurationWithSecs(cgrCdr[DURATION])
}
// Used in mediation, fieldsMandatory marks whether missing field out of request represents error or can be ignored
@@ -126,6 +125,10 @@ func (cgrCdr CgrCdr) AsStoredCdr(runId, reqTypeFld, directionFld, tenantFld, tor
return nil, errors.New(fmt.Sprintf("%s:%s", ERR_MANDATORY_IE_MISSING, ACCID))
}
}
// MetaDefault will automatically be converted to their standard values
//if reqTypeFld == META_DEFAULT {
// reqTypeFld =
//}
if rtCdr.CdrHost, hasKey = cgrCdr[CDRHOST]; !hasKey && fieldsMandatory {
return nil, errors.New(fmt.Sprintf("%s:%s", ERR_MANDATORY_IE_MISSING, CDRHOST))
}

View File

@@ -72,7 +72,8 @@ func TestCgrCdrFields(t *testing.T) {
if answerTime.UTC() != expectedATime {
t.Error("Error parsing cdr: ", cgrCdr)
}
if cgrCdr.GetDuration() != time.Duration(10)*time.Second {
dur, _ := cgrCdr.GetDuration()
if dur != time.Duration(10)*time.Second {
t.Error("Error parsing cdr: ", cgrCdr)
}
extraFields := cgrCdr.GetExtraFields()

View File

@@ -39,7 +39,7 @@ type RawCDR interface {
GetReqType() string
GetSetupTime() (time.Time, error) // Time when the call was set-up
GetAnswerTime() (time.Time, error) // Time when the call was answered
GetDuration() time.Duration
GetDuration() (time.Duration, error)
GetExtraFields() map[string]string //Stores extra CDR Fields
AsStoredCdr(string, string, string, string, string, string, string, string, string, string, string, []string, bool) (*StoredCdr, error) // Based on fields queried will return a particular instance of RatedCDR
}

View File

@@ -45,7 +45,7 @@ func NewStoredCdrFromRawCDR(rawcdr RawCDR) (*StoredCdr, error) {
if rtCdr.AnswerTime, err = rawcdr.GetAnswerTime(); err != nil {
return nil, err
}
rtCdr.Duration = rawcdr.GetDuration()
rtCdr.Duration, _ = rawcdr.GetDuration()
rtCdr.ExtraFields = rawcdr.GetExtraFields()
rtCdr.MediationRunId = DEFAULT_RUNID
rtCdr.Cost = -1
@@ -128,8 +128,8 @@ func (storedCdr *StoredCdr) GetAnswerTime() (time.Time, error) {
return storedCdr.AnswerTime, nil
}
func (storedCdr *StoredCdr) GetDuration() time.Duration {
return storedCdr.Duration
func (storedCdr *StoredCdr) GetDuration() (time.Duration, error) {
return storedCdr.Duration, nil
}
func (storedCdr *StoredCdr) GetExtraFields() map[string]string {

View File

@@ -90,7 +90,8 @@ func TestStoredCdrFields(t *testing.T) {
if answerTime.UTC() != expectedATime {
t.Error("Error parsing cdr: ", ratedCdr)
}
if ratedCdr.GetDuration() != 10 {
dur, _ := ratedCdr.GetDuration()
if dur != 10 {
t.Error("Error parsing cdr: ", ratedCdr)
}
extraFields := ratedCdr.GetExtraFields()