Repository: kruize/autotune
Issue: Remove resultData from the KruizeObject

Currently we're a getting a redundant result response in the `listExperiments` API. We need to remove the `resultData` object from the JSON and keep the results inside `kubernetes_objects`

Changed files:
src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java, src/main/java/com/autotune/analyzer/experiment/ExperimentResultValidation.java, src/main/java/com/autotune/analyzer/experiment/ExperimentInterfaceImpl.java

diff --git a/src/main/java/com/autotune/analyzer/experiment/ExperimentInterfaceImpl.java b/src/main/java/com/autotune/analyzer/experiment/ExperimentInterfaceImpl.java
index b22d187c..4da1efb6 100644
--- a/src/main/java/com/autotune/analyzer/experiment/ExperimentInterfaceImpl.java
+++ b/src/main/java/com/autotune/analyzer/experiment/ExperimentInterfaceImpl.java
@@ -66,13 +66,6 @@ public class ExperimentInterfaceImpl implements ExperimentInterface {
                 (resultData) -> {
                     resultData.setStatus(AnalyzerConstants.ExperimentStatus.QUEUED);
                     KruizeObject ko = mainKruizeExperimentMap.get(resultData.getExperiment_name());
-                    Set<ExperimentResultData> results;
-                    if (ko.getResultData() == null)
-                        results = new HashSet<>();
-                    else
-                        results = ko.getResultData();
-                    results.add(resultData);
-                    ko.setResultData(results);
                     // creating a temp map to store k8sdata
                     HashMap<String, K8sObject> k8sObjectHashMap = new HashMap<>();
                     for (K8sObject k8sObj : ko.getKubernetes_objects())
diff --git a/src/main/java/com/autotune/analyzer/experiment/ExperimentResultValidation.java b/src/main/java/com/autotune/analyzer/experiment/ExperimentResultValidation.java
index f41e2438..76a6ee22 100644
--- a/src/main/java/com/autotune/analyzer/experiment/ExperimentResultValidation.java
+++ b/src/main/java/com/autotune/analyzer/experiment/ExperimentResultValidation.java
@@ -18,11 +18,13 @@ package com.autotune.analyzer.experiment;
 import com.autotune.analyzer.utils.AnalyzerErrorConstants;
 import com.autotune.analyzer.performanceProfiles.utils.PerformanceProfileUtil;
 import com.autotune.common.data.ValidationOutputData;
+import com.autotune.common.data.result.ContainerData;
 import com.autotune.common.data.result.ExperimentResultData;
 import com.autotune.analyzer.kruizeObject.KruizeObject;
 import com.autotune.analyzer.performanceProfiles.PerformanceProfile;
 import com.autotune.analyzer.utils.AnalyzerConstants;
 import com.autotune.common.data.result.IntervalResults;
+import com.autotune.common.k8sObjects.K8sObject;
 import com.autotune.utils.KruizeConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -76,8 +78,16 @@ public class ExperimentResultValidation {
                         }
                         // check if resultData is present
                         boolean isExist = false;
-                        if (null != kruizeObject.getResultData())
-                            isExist = kruizeObject.getResultData().contains(resultData);
+                        for (K8sObject k8sObject : kruizeObject.getKubernetes_objects()) {
+                            for (ContainerData containerData : k8sObject.getContainerDataMap().values()) {
+                                if (null != containerData.getResults()) {
+                                    if (null != containerData.getResults().get(resultData.getEndtimestamp())) {
+                                        isExist = true;
+                                        break;
+                                    }
+                                }
+                            }
+                        }
                         if (isExist) {
                             errorMsg = errorMsg.concat(String.format("Experiment name : %s already contains result for timestamp : %s", resultData.getExperiment_name(), resultData.getEndtimestamp()));
                             resultData.setValidationOutputData(new ValidationOutputData(false, errorMsg, HttpServletResponse.SC_CONFLICT));
diff --git a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java
index 81fae424..525b36fc 100644
--- a/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java
+++ b/src/main/java/com/autotune/analyzer/kruizeObject/KruizeObject.java
@@ -59,7 +59,6 @@ public final class KruizeObject {
     private TrialSettings trial_settings;
     private RecommendationSettings recommendation_settings;
     private ExperimentUseCaseType experimentUseCaseType;
-    private Set<ExperimentResultData> resultData;                   // TODO: Need to remove this
     private ValidationOutputData validationData;
     private List<K8sObject> kubernetes_objects;
 
@@ -203,13 +202,6 @@ public final class KruizeObject {
         this.experimentUseCaseType = experimentUseCaseType;
     }
 
-    public Set<ExperimentResultData> getResultData() {
-        return resultData;
-    }
-
-    public void setResultData(Set<ExperimentResultData> resultData) {
-        this.resultData = resultData;
-    }
 
     public ValidationOutputData getValidationData() {
         return validationData;
@@ -277,7 +269,6 @@ public final class KruizeObject {
                 ", trial_settings=" + trial_settings +
                 ", recommendation_settings=" + recommendation_settings +
                 ", experimentUseCaseType=" + experimentUseCaseType +
-                ", resultData=" + resultData +
                 ", validationData=" + validationData +
                 ", kubernetes_objects=" + kubernetes_objects +
                 '}';