Skip to content

Commit

Permalink
incorporated review comments
Browse files Browse the repository at this point in the history
Signed-off-by: msvinaykumar <vinakuma@redhat.com>
  • Loading branch information
msvinaykumar committed Aug 23, 2023
1 parent aa6e7b9 commit 386edc9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*******************************************************************************/
package com.autotune.analyzer.experiment;

import com.autotune.analyzer.exceptions.KruizeResponse;
import com.autotune.analyzer.kruizeObject.KruizeObject;
import com.autotune.analyzer.performanceProfiles.PerformanceProfileInterface.PerfProfileInterface;
import com.autotune.analyzer.serviceObjects.Converters;
Expand All @@ -36,7 +37,10 @@
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Field;
import java.sql.Timestamp;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Initiates new experiment data validations and push into queue for worker to
Expand All @@ -49,26 +53,28 @@ public class ExperimentInitiator {
List<UpdateResultsAPIObject> failedUpdateResultsAPIObjects = new ArrayList<>();
private ValidationOutputData validationOutputData;

public static HashMap<Integer, String> getErrorMap(List<String> errorMessages) {
HashMap<Integer, String> errorMap;
public static List<KruizeResponse> getErrorMap(List<String> errorMessages) {
List<KruizeResponse> responses;
if (null != errorMessages) {
errorMap = new HashMap<>();
responses = new ArrayList<>();
errorMessages.forEach(
(errorText) -> {
if (AnalyzerErrorConstants.APIErrors.updateResultsAPI.ERROR_CODE_MAP.containsKey(errorText)) {
errorMap.put(
AnalyzerErrorConstants.APIErrors.updateResultsAPI.ERROR_CODE_MAP.get(errorText),
errorText
responses.add(
new KruizeResponse(errorText, AnalyzerErrorConstants.APIErrors.updateResultsAPI.ERROR_CODE_MAP.get(errorText), "", "ERROR", null)
);

} else {
errorMap.put(HttpServletResponse.SC_BAD_REQUEST, errorText);
responses.add(
new KruizeResponse(errorText, HttpServletResponse.SC_BAD_REQUEST, "", "ERROR", null)
);
}
}
);
} else {
errorMap = null;
responses = null;
}
return errorMap;
return responses;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*******************************************************************************/
package com.autotune.analyzer.serviceObjects;

import com.autotune.analyzer.exceptions.KruizeResponse;
import com.autotune.analyzer.serviceObjects.verification.annotators.CompareDate;
import com.autotune.analyzer.serviceObjects.verification.annotators.KubernetesElementsCheck;
import com.autotune.analyzer.serviceObjects.verification.annotators.PerformanceProfileCheck;
Expand All @@ -27,7 +28,6 @@
import jakarta.validation.constraints.Size;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;

@CompareDate(groups = BaseSO.InitialValidation.class, message = AnalyzerErrorConstants.AutotuneObjectErrors.WRONG_TIMESTAMP)
Expand All @@ -50,7 +50,7 @@ public class UpdateResultsAPIObject extends BaseSO {
@SerializedName(KruizeConstants.JSONKeys.KUBERNETES_OBJECTS)
private List<KubernetesAPIObject> kubernetesAPIObjects;

private HashMap<Integer, String> errors;
private List<KruizeResponse> errors;

public Timestamp getStartTimestamp() {
return startTimestamp;
Expand All @@ -76,11 +76,11 @@ public void setKubernetesObjects(List<KubernetesAPIObject> kubernetesAPIObjects)
this.kubernetesAPIObjects = kubernetesAPIObjects;
}

public HashMap<Integer, String> getErrors() {
public List<KruizeResponse> getErrors() {
return errors;
}

public void setErrors(HashMap<Integer, String> errors) {
public void setErrors(List<KruizeResponse> errors) {
this.errors = errors;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,9 @@ def test_update_results_with_same_result(cluster_type):
TIMESTAMP_PRESENT_MSG = 'An entry for this record already exists!'

print(TIMESTAMP_PRESENT_MSG)
print(data['data'][0]['errors']["409"])
print(data['data'][0]['errors'][0]['message'])
assert data['message'] == 'Out of a total of 1 records, 1 failed to save'
assert data['data'][0]['errors']["409"] == TIMESTAMP_PRESENT_MSG
assert data['data'][0]['errors'][0]['message'] == TIMESTAMP_PRESENT_MSG

response = delete_experiment(input_json_file)
print("delete exp = ", response.status_code)
Expand Down Expand Up @@ -534,12 +534,12 @@ def test_update_results_with_valid_and_invalid_interval_duration(test_name, inte
assert response.status_code == ERROR_STATUS_CODE
assert data['status'] == ERROR_STATUS
assert data['message'] == 'Out of a total of 1 records, 1 failed to save'
assert data['data'][0]['errors']['400'] == UPDATE_RESULTS_DATE_PRECEDE_ERROR_MSG
assert data['data'][0]['errors'][0]['message'] == UPDATE_RESULTS_DATE_PRECEDE_ERROR_MSG
else:
assert response.status_code == ERROR_STATUS_CODE
assert data['status'] == ERROR_STATUS
assert data['message'] == 'Out of a total of 1 records, 1 failed to save'
assert data['data'][0]['errors']['400'] == INVALID_INTERVAL_DURATION_MSG
assert data['data'][0]['errors'][0]['message'] == INVALID_INTERVAL_DURATION_MSG

response = delete_experiment(input_json_file)
print("delete exp = ", response.status_code)

0 comments on commit 386edc9

Please sign in to comment.