Skip to content

Commit

Permalink
removes redundant methods and DB constants using cluster_name to load…
Browse files Browse the repository at this point in the history
… results
  • Loading branch information
shreyabiradar07 committed Oct 4, 2023
1 parent 903ca29 commit b0b2440
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 66 deletions.
3 changes: 0 additions & 3 deletions src/main/java/com/autotune/database/dao/ExperimentDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public interface ExperimentDAO {
// Load all results for a particular experimentName
List<KruizeResultsEntry> loadResultsByExperimentName(String experimentName, String cluster_name, Timestamp interval_start_time, Integer limitRows) throws Exception;

// Load all results for a particular clusterName
List<KruizeResultsEntry> loadResultsByClusterName(String clusterName, Timestamp interval_start_time, Integer limitRows) throws Exception;

// Load all recommendations of a particular experiment
List<KruizeRecommendationEntry> loadRecommendationsByExperimentName(String experimentName) throws Exception;
// Load all recommendations of a particular cluster
Expand Down
30 changes: 0 additions & 30 deletions src/main/java/com/autotune/database/dao/ExperimentDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,36 +520,6 @@ public List<KruizeResultsEntry> loadResultsByExperimentName(String experimentNam
}
return kruizeResultsEntries;
}
@Override
public List<KruizeResultsEntry> loadResultsByClusterName(String clusterName, Timestamp interval_end_time, Integer limitRows) throws Exception {
// TODO: load only experimentStatus=inProgress , playback may not require completed experiments
List<KruizeResultsEntry> kruizeResultsEntries = null;
String statusValue = "failure";
Timer.Sample timerLoadResultsExpName = Timer.start(MetricsConfig.meterRegistry());
try (Session session = KruizeHibernateUtil.getSessionFactory().openSession()) {
if (null != limitRows && null != interval_end_time) {
kruizeResultsEntries = session.createQuery(DBConstants.SQLQUERY.SELECT_FROM_RESULTS_BY_CLUSTER_NAME_AND_DATE_RANGE, KruizeResultsEntry.class)
.setParameter(KruizeConstants.JSONKeys.CLUSTER_NAME, clusterName)
.setParameter(KruizeConstants.JSONKeys.INTERVAL_END_TIME, interval_end_time)
.setMaxResults(limitRows)
.list();
statusValue = "success";
} else {
kruizeResultsEntries = session.createQuery(DBConstants.SQLQUERY.SELECT_FROM_RESULTS_BY_CLUSTER_NAME, KruizeResultsEntry.class)
.setParameter("clsuterName", clusterName).list();
statusValue = "success";
}
} catch (Exception e) {
LOGGER.error("Not able to load results due to: {}", e.getMessage());
throw new Exception("Error while loading results from the database due to : " + e.getMessage());
} finally {
if (null != timerLoadResultsExpName) {
MetricsConfig.timerLoadResultsExpName = MetricsConfig.timerBLoadResultsExpName.tag("status", statusValue).register(MetricsConfig.meterRegistry());
timerLoadResultsExpName.stop(MetricsConfig.timerLoadResultsExpName);
}
}
return kruizeResultsEntries;
}

@Override
public List<KruizeRecommendationEntry> loadRecommendationsByExperimentName(String experimentName) throws Exception {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/autotune/database/helper/DBConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public static final class SQLQUERY {
KruizeConstants.JSONKeys.CLUSTER_NAME, KruizeConstants.JSONKeys.EXPERIMENT_NAME, KruizeConstants.JSONKeys.INTERVAL_START_TIME, KruizeConstants.JSONKeys.INTERVAL_END_TIME);
public static final String SELECT_FROM_RESULTS_BY_EXP_NAME_AND_END_TIME = String.format("from KruizeResultsEntry k WHERE k.cluster_name = :%s and k.experiment_name = :%s and k.interval_end_time = :%s", KruizeConstants.JSONKeys.CLUSTER_NAME, KruizeConstants.JSONKeys.EXPERIMENT_NAME, KruizeConstants.JSONKeys.INTERVAL_END_TIME);
public static final String SELECT_FROM_RESULTS_BY_EXP_NAME_AND_MAX_END_TIME = String.format("from KruizeResultsEntry k WHERE k.cluster_name = :%s and k.experiment_name = :%s and k.interval_end_time = (SELECT MAX(e.interval_end_time) FROM KruizeResultsEntry e where e.experiment_name = :%s )", KruizeConstants.JSONKeys.CLUSTER_NAME, KruizeConstants.JSONKeys.EXPERIMENT_NAME, KruizeConstants.JSONKeys.EXPERIMENT_NAME);
public static final String SELECT_FROM_RESULTS_BY_CLUSTER_NAME = "from KruizeResultsEntry k WHERE k.cluster_name = :clusterName";
public static final String SELECT_FROM_RESULTS_BY_CLUSTER_NAME_AND_DATE_RANGE = String.format("from KruizeResultsEntry k WHERE k.cluster_name = :%s and k.interval_end_time <= :%s ORDER BY k.interval_end_time DESC", KruizeConstants.JSONKeys.CLUSTER_NAME, KruizeConstants.JSONKeys.INTERVAL_END_TIME, KruizeConstants.JSONKeys.INTERVAL_START_TIME);
public static final String SELECT_FROM_RECOMMENDATIONS_BY_EXP_NAME = String.format("from KruizeRecommendationEntry k WHERE k.experiment_name = :experimentName");
public static final String SELECT_FROM_RECOMMENDATIONS_BY_EXP_NAME_AND_END_TIME = String.format("from KruizeRecommendationEntry k WHERE k.cluster_name= :%s and k.experiment_name = :%s and k.interval_end_time= :%s", KruizeConstants.JSONKeys.CLUSTER_NAME, KruizeConstants.JSONKeys.EXPERIMENT_NAME, KruizeConstants.JSONKeys.INTERVAL_END_TIME);
public static final String SELECT_FROM_RECOMMENDATIONS_BY_CLUSTER_NAME = "from KruizeRecommendationEntry k WHERE k.cluster_name = :clusterName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,32 +189,7 @@ public void loadRecommendationsFromDBByName(Map<String, KruizeObject> mainKruize
}
}
}
// Todo - confirm if experimentResultData to be changed to clusterResultData
public void loadResultsFromDBByClusterName(Map<String, KruizeObject> mainKruizeExperimentMap, String clusterName, Timestamp interval_end_time, Integer limitRows) throws Exception {
ExperimentInterface experimentInterface = new ExperimentInterfaceImpl();
// Load results from the DB and save to local
List<KruizeResultsEntry> kruizeResultsEntries = experimentDAO.loadResultsByClusterName(clusterName, interval_end_time, limitRows);
if (null != kruizeResultsEntries && !kruizeResultsEntries.isEmpty()) {
List<UpdateResultsAPIObject> updateResultsAPIObjects = DBHelpers.Converters.KruizeObjectConverters.convertResultEntryToUpdateResultsAPIObject(kruizeResultsEntries);
if (null != updateResultsAPIObjects && !updateResultsAPIObjects.isEmpty()) {
List<ExperimentResultData> resultDataList = new ArrayList<>();
for (UpdateResultsAPIObject updateResultsAPIObject : updateResultsAPIObjects) {
try {
ExperimentResultData experimentResultData = Converters.KruizeObjectConverters.convertUpdateResultsAPIObjToExperimentResultData(updateResultsAPIObject);
if (experimentResultData != null)
resultDataList.add(experimentResultData);
else
LOGGER.warn("Converted experimentResultData is null");
} catch (IllegalArgumentException e) {
LOGGER.error("Failed to convert DB data to local: {}", e.getMessage());
} catch (Exception e) {
LOGGER.error("Unexpected error: {}", e.getMessage());
}
}
experimentInterface.addResultsToLocalStorage(mainKruizeExperimentMap, resultDataList);
}
}
}

public void loadRecommendationsFromDBByClusterName(Map<String, KruizeObject> mainKruizeExperimentMap, String clusterName) throws Exception {
ExperimentInterface experimentInterface = new ExperimentInterfaceImpl();
// Load Recommendations from DB and save to local
Expand Down Expand Up @@ -388,11 +363,6 @@ public void loadExperimentAndRecommendationsFromDBByName(Map<String, KruizeObjec
loadRecommendationsFromDBByName(mainKruizeExperimentMap, experimentName);
}

public void loadExperimentsAndResultsFromDBByClusterName(Map<String, KruizeObject> mainKruizeExperimentMap, String clusterName) throws Exception {

loadExperimentsFromDBByClusterName(mainKruizeExperimentMap, clusterName);
loadResultsFromDBByClusterName(mainKruizeExperimentMap, clusterName, null, null);
}
public void loadExperimentsAndRecommendationsFromDBByClusterName(Map<String, KruizeObject> mainKruizeExperimentMap, String clusterName) throws Exception {
loadExperimentsFromDBByClusterName(mainKruizeExperimentMap, clusterName);
loadRecommendationsFromDBByClusterName(mainKruizeExperimentMap, clusterName);
Expand Down

0 comments on commit b0b2440

Please sign in to comment.