Пример #1
0
func (restapi *restAPI) getOptimalAndActualMakespans(w http.ResponseWriter, r *http.Request) {
	// get number of days back
	numberBuilds, err := util.GetIntValue(r, "number", 0)
	if err != nil {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: err.Error()})
		return
	}
	if numberBuilds == 0 {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: "invalid number builds"})
		return
	}

	isCSV, err := util.GetBoolValue(r, "csv", true)
	if err != nil {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: err.Error()})
		return
	}

	makespanData, err := getMakespanRatios(numberBuilds)
	if err != nil {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: err.Error()})
		return
	}

	if isCSV {
		util.WriteCSVResponse(w, http.StatusOK, makespanData)
		return
	}
	restapi.WriteJSON(w, http.StatusOK, makespanData)

}
Пример #2
0
func (restapi *restAPI) getHostUtilizationStats(w http.ResponseWriter, r *http.Request) {
	// get granularity (in seconds)
	granularity, err := util.GetIntValue(r, "granularity", 0)
	if err != nil {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: err.Error()})
		return
	}
	if granularity == 0 {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: "invalid granularity"})
		return
	}

	// get number of days back
	daysBack, err := util.GetIntValue(r, "numberDays", 0)
	if err != nil {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: err.Error()})
		return
	}
	if daysBack == 0 {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: "invalid days back"})
		return
	}

	isCSV, err := util.GetBoolValue(r, "csv", true)
	if err != nil {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: err.Error()})
		return
	}
	buckets, err := model.CreateAllHostUtilizationBuckets(daysBack, granularity)
	if err != nil {
		restapi.WriteJSON(w, http.StatusInternalServerError, responseError{Message: fmt.Sprintf("error getting buckets: %v", err.Error())})
		return
	}
	restBuckets := []restHostUtilizationBucket{}
	// convert the time.Durations into integers
	for _, b := range buckets {
		r := restHostUtilizationBucket{
			StaticHost:  int(b.StaticHost),
			DynamicHost: int(b.DynamicHost),
			Task:        int(b.Task),
			StartTime:   b.StartTime,
			EndTime:     b.EndTime,
		}
		restBuckets = append(restBuckets, r)
	}

	if isCSV {
		util.WriteCSVResponse(w, http.StatusOK, restBuckets)
		return
	}
	restapi.WriteJSON(w, http.StatusOK, buckets)
}
Пример #3
0
func (restapi *restAPI) getAverageSchedulerStats(w http.ResponseWriter, r *http.Request) {
	// get granularity (in seconds)
	granularity, err := util.GetIntValue(r, "granularity", 0)
	if err != nil {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: err.Error()})
		return
	}
	if granularity == 0 {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: "invalid granularity"})
		return
	}

	// get number of days back
	daysBack, err := util.GetIntValue(r, "numberDays", 0)
	if err != nil {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: err.Error()})
		return
	}
	if daysBack == 0 {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: "invalid days back"})
		return
	}
	isCSV, err := util.GetBoolValue(r, "csv", true)
	if err != nil {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: err.Error()})
		return
	}

	distroId := mux.Vars(r)["distro_id"]
	if distroId == "" {
		restapi.WriteJSON(w, http.StatusBadRequest, responseError{Message: "invalid distro id"})
		return
	}

	bounds := model.CalculateBounds(daysBack, granularity)

	buckets, err := model.AverageStatistics(distroId, bounds)
	if err != nil {
		restapi.WriteJSON(w, http.StatusInternalServerError, responseError{Message: fmt.Sprintf("error getting buckets: %v", err.Error())})
		return
	}
	restBuckets := []restAvgBucket{}
	// convert the time.Durations into integers
	for _, b := range buckets {
		r := restAvgBucket{
			Id:          b.Id,
			AverageTime: int(b.AverageTime),
			NumberTasks: b.NumberTasks,
			Start:       b.Start,
			End:         b.End,
		}
		restBuckets = append(restBuckets, r)
	}

	if isCSV {
		util.WriteCSVResponse(w, http.StatusOK, restBuckets)
		return
	}
	restapi.WriteJSON(w, http.StatusOK, buckets)

}