Example #1
0
func ReceiveTaskCommand(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	id := r.URL.Query().Get(":ID")
	sInterface, err := db.Get(liboct.DBScheduler, id)
	if err != nil {
		liboct.RenderError(w, err)
		return
	}
	s, _ := liboct.SchedulerFromString(sInterface.String())

	result, _ := ioutil.ReadAll(r.Body)
	logrus.Debugf("Receive task Command %s", string(result))
	r.Body.Close()
	/* Donnot use this now FIXME
	var cmd liboct.TestActionCommand
	json.Unmarshal([]byte(result), &cmd)
	*/
	action, err := liboct.TestActionFromString(string(result))
	if err != nil {
		liboct.RenderError(w, err)
		return
	}

	err = s.Command(action)
	db.Update(liboct.DBScheduler, id, s)
	if err != nil {
		liboct.RenderError(w, err)
	} else {
		liboct.RenderOK(w, "", nil)
	}
}
Example #2
0
func PostTaskAction(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	result, _ := ioutil.ReadAll(r.Body)
	r.Body.Close()
	action, err := liboct.TestActionFromString(string(result))
	if err != nil {
		liboct.RenderError(w, err)
		return
	}
	id := r.URL.Query().Get(":TaskID")
	taskInterface, err := db.Get(liboct.DBTask, id)
	if err != nil {
		liboct.RenderError(w, err)
		return
	}

	task, _ := liboct.TaskFromString(taskInterface.String())
	if e := task.Command(action); e != nil {
		liboct.RenderError(w, err)
	} else {
		liboct.RenderOK(w, "", nil)
	}
}