Exemplo n.º 1
0
func getstopPayload(stpRecid string) comdef.RecordReq {

	var stpData comdef.RecordReq
	slice := make([]comdef.RecordData, 1)
	nwTime := time.Now()
	for i := range recDataGlb {
		if stpRecid == recDataGlb[i].RecordingID {
			slice[0].Action = "SET"
			slice[0].RecordingID = stpRecid
			slice[0].ScheduledTime = recDataGlb[i].ScheduledTime
			slice[0].AccountID = recDataGlb[i].AccountID
			slice[0].StartTime = recDataGlb[i].StartTime //nowTime.Add(time.Duration(1*30) * time.Second).Format(comdef.TimeFrmtStr) //r.PostFormValue("StartTime")
			slice[0].EndTime = nwTime.Format(comdef.TimeFrmtStr)
			slice[0].StreamID = recDataGlb[i].StreamID
			slice[0].AdZone = recDataGlb[i].AdZone
			slice[0].StationID = recDataGlb[i].StationID
			slice[0].UpdateURL = updateURL //hard coded the scheduler to localhost
			slice[0].ListingID = recDataGlb[i].ListingID

		}
	}
	stpData.RequestID = fmt.Sprintf("xxxxxxxx-aaaa-bbbb-cccc-%v", time.Now().UnixNano)
	stpData.Entries = slice
	return stpData
}
Exemplo n.º 2
0
//getrecPayload to generate the recording payload in JSON using the post value from the form
func getrecPayload(r *http.Request) (comdef.RecordReq, int) {

	var recData comdef.RecordReq

	r.ParseForm()
	recordingID = fmt.Sprintf("XRID-%d-%d", nowTime.Unix(), recEntries)
	ScheduledTime := genCurentTime()

	slice := make([]comdef.RecordData, 1) //Created a slice only for one entry

	slice[0].RecordingID = recordingID
	slice[0].Action = r.PostFormValue("Action")
	slice[0].ScheduledTime = ScheduledTime
	slice[0].AccountID = r.PostFormValue("AccountID")
	slice[0].StartTime = r.PostFormValue("StartTime") //nowTime.Add(time.Duration(1*30) * time.Second).Format(comdef.TimeFrmtStr) //r.PostFormValue("StartTime")
	slice[0].EndTime = r.PostFormValue("EndTime")     //nowTime.Add(time.Duration((2)*30) * time.Second).Format(comdef.TimeFrmtStr)
	slice[0].StreamID = r.PostFormValue("StreamID")
	slice[0].AdZone = r.PostFormValue("azone")
	slice[0].StationID = r.PostFormValue("StationID")
	slice[0].UpdateURL = updateURL //hard coded the scheduler to localhost
	slice[0].ListingID = r.PostFormValue("ListingID")

	numRec, _ = strconv.Atoi(r.PostFormValue("NoOfRec")) //To get the no of recordings to be scheduled

	recData.RequestID = fmt.Sprintf("xxxxxxxx-aaaa-bbbb-cccc-%v", time.Now().UnixNano)
	recData.Entries = slice
	writeRecordData(recData)
	return recData, numRec
}
Exemplo n.º 3
0
//Process Record Request from external source.  It will forward the request to Recorder Manager
//and forward the response received from RM to the external source.
func processBridgeRecord(input httpctxserver.HandlerProcessInput) (bool, int, error) {

	var (
		req   *comdef.RecordReq
		resp  *comdef.RecordResp
		found bool
	)

	//Sanity check to make sure req and resp data type are passed in correctly
	if req, found = input.Req.(*comdef.RecordReq); found != true || req == nil {
		err := errors.New("Unsupported req type for Bridge Record")
		log.Fatal(err)
		return false, http.StatusInternalServerError, err
	}

	if resp, found = input.Resp.(*comdef.RecordResp); found != true || resp == nil {
		err := errors.New("Unsupported resp type for Bridge Record")
		log.Fatal(err)
		return false, http.StatusInternalServerError, err
	}

	//sanity check if we have a URL for RM
	if len(rmURL) == 0 {
		log.Printf("Cannot Forward request to Recorder Manager, no RM URL available")
		err := errors.New("No RM URL is aviable")
		return false, http.StatusBadGateway, err
	}

	//fake request id
	req.RequestID = fmt.Sprintf("xxxxxxxx-aaaa-bbbb-cccc-%v", time.Now().UnixNano)

	//Send request to RM
	httpStatus, err := httputilfuncs.PostHTTPJSONString(rmURL, *req, resp, timeOut)
	if err != nil {
		log.Printf("Error when sending Update Request, err: %v", err)
		return false, http.StatusBadGateway, nil

	}

	//forward the RM response back to external source
	log.Printf("HttpStatus: %d, Resp: %v", httpStatus, *resp)
	if httpStatus == http.StatusOK {
		return true, httpStatus, nil
	}

	return false, httpStatus, nil

}
Exemplo n.º 4
0
func getdelPayload(delRecid string) comdef.RecordReq {
	var delData comdef.RecordReq
	slice := make([]comdef.RecordData, 1)

	for i := range recDataGlb {
		if delRecid == recDataGlb[i].RecordingID {
			slice[0].Action = "REMOVE"
			slice[0].RecordingID = delRecid
			slice[0].ScheduledTime = recDataGlb[i].ScheduledTime
			slice[0].AccountID = recDataGlb[i].AccountID

		}
	}
	delData.RequestID = fmt.Sprintf("xxxxxxxx-aaaa-bbbb-cccc-%v", time.Now().UnixNano)
	delData.Entries = slice
	return delData
}