Example #1
0
func GetRequestParent(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	uuid := vars["uuid"]

	req := model.GetRequest(uuid)
	if req == nil {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	parent := model.GetRequest(req.ParentUuid)
	json.NewEncoder(w).Encode(parent)
}
Example #2
0
func GetRequestRequestGroup(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	uuid := vars["uuid"]

	req := model.GetRequest(uuid)
	if req == nil || req.GroupUuid == "" {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	rg := model.GetRequestGroup(req.GroupUuid)
	if req == nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	result := struct {
		Requests     []*model.Request `json:"requests"`
		ParentsIndex []int            `json:"parents_index"`
	}{}

	result.ParentsIndex = rg.ParentsIndex
	result.Requests = rg.DetailRequests()

	json.NewEncoder(w).Encode(result)
}
Example #3
0
func GetRequestRootRequest(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	uuid := vars["uuid"]

	req := model.GetRequest(uuid)
	if req == nil || req.GroupUuid == "" {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	root := model.GetRequest(req.GroupUuid)
	if root == nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	json.NewEncoder(w).Encode(root)
}
Example #4
0
func PostData(w http.ResponseWriter, r *http.Request) {
	data := make([]Data, 0)
	if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	for _, item := range data {
		if item.Request.Uuid == "" {
			// TBD
			continue
		}

		switch item.Event {
		case RequestBeginEvent:
			if item.Request.Exist() {
				// TBD
				continue
			}

			item.Request.GroupUuid = ""
			item.Request.CreateTs = time.Now().UTC().Unix()
			item.Request.UpdateTs = item.Request.CreateTs
			item.Request.Save()
		case RequestEndEvent:
			req := model.GetRequest(item.Request.Uuid)
			if req == nil {
				// TBD
				continue
			}

			req.EndTs = item.Request.EndTs
			req.EndMetadata = item.Request.EndMetadata
			req.UpdateTs = time.Now().UTC().Unix()
			req.Update()
		default:
			// TBD
			continue
		}
	}
}
Example #5
0
func GetRequestInvokeChain(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	uuid := vars["uuid"]

	req := model.GetRequest(uuid)
	if req == nil || req.GroupUuid == "" {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	rg := model.GetRequestGroup(req.GroupUuid)
	if req == nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	ic := model.GetInvokeChain(rg.InvokeChainId)
	if ic == nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	json.NewEncoder(w).Encode(ic)
}