// ConvertESToResp .... convert elasticsearch to response
ConvertESToResp .... convert elasticsearch to response
// ConvertESToResp .... convert elasticsearch to response
func ConvertESToResp(input models.DocumentResponse, logs []models.HPALog) models.ApplicationHealthAnalyzeResponse {
	code, err := strconv.Atoi(input.StatusCode)
	if err != nil {
		code = 200
	}
	resp := models.ApplicationHealthAnalyzeResponse{
		JobID:      input.ID,
		StatusCode: int32(code),
		Status:     ConvertStatusToExternal(input.Status),
		Reason:     input.Reason,
	}
	if logs != nil {
		hpaLogs := make([]map[string]interface{}, 0)
		for _, l := range logs {
			hpaLogEntry := map[string]interface{}{}
			hpaLogEntry["timestamp"] = strconv.FormatFloat(l.Timestamp, 'f', -1, 64)
			hpaLog := map[string]interface{}{}
			hpaLog["hpascore"] = l.Log.HPAScore
			hpaLog["reason"] = l.Log.Reason
			details := []map[string]interface{}{}
			for _, d := range l.Log.Details {
				detail := map[string]interface{}{}
				detail["metricAlias"] = d.MetricType
				detail["current"] = d.Current
				detail["upper"] = d.Upper
				detail["lower"] = d.Lower
				details = append(details, detail)
			}
			hpaLog["details"] = details
			hpaLogEntry["hpalog"] = hpaLog
			hpaLogs = append(hpaLogs, hpaLogEntry)
		}
		resp.HPALog = hpaLogs
	}
	return resp
}
func ConvertESToResp ( input models . DocumentResponse , logs [ ] models . HPALog ) models . ApplicationHealthAnalyzeResponse { code , err := strconv . Atoi ( input . StatusCode ) if err != nil { code = 200 } resp := models . ApplicationHealthAnalyzeResponse { JobID : input . ID , StatusCode : int32 ( code ) , Status : ConvertStatusToExternal ( input . Status ) , Reason : input . Reason , } if logs != nil { hpaLogs := make ( [ ] map [ string ] interface { } , 0 ) for _ , l := range logs { hpaLogEntry := map [ string ] interface { } { } hpaLogEntry [ " " ] = strconv . FormatFloat ( l . Timestamp , 'f' , - 1 , 64 ) hpaLog := map [ string ] interface { } { } hpaLog [ " " ] = l . Log . HPAScore hpaLog [ " " ] = l . Log . Reason details := [ ] map [ string ] interface { } { } for _ , d := range l . Log . Details { detail := map [ string ] interface { } { } detail [ " " ] = d . MetricType detail [ " " ] = d . Current detail [ " " ] = d . Upper detail [ " " ] = d . Lower details = append ( details , detail ) } hpaLog [ " " ] = details hpaLogEntry [ " " ] = hpaLog hpaLogs = append ( hpaLogs , hpaLogEntry ) } resp . HPALog = hpaLogs } return resp }
ConvertESToResp .... convert elasticsearch to response
ConvertESToResp .... convert elasticsearch to response