From b0b2440afe84515e00041373ef5a1548c1c7d4f5 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 4 Oct 2023 15:08:00 +0530 Subject: [PATCH] removes redundant methods and DB constants using cluster_name to load results --- .../autotune/database/dao/ExperimentDAO.java | 3 -- .../database/dao/ExperimentDAOImpl.java | 30 ----------------- .../autotune/database/helper/DBConstants.java | 2 -- .../database/service/ExperimentDBService.java | 32 +------------------ 4 files changed, 1 insertion(+), 66 deletions(-) diff --git a/src/main/java/com/autotune/database/dao/ExperimentDAO.java b/src/main/java/com/autotune/database/dao/ExperimentDAO.java index efa3baf0d..7c4838cd5 100644 --- a/src/main/java/com/autotune/database/dao/ExperimentDAO.java +++ b/src/main/java/com/autotune/database/dao/ExperimentDAO.java @@ -54,9 +54,6 @@ public interface ExperimentDAO { // Load all results for a particular experimentName List loadResultsByExperimentName(String experimentName, String cluster_name, Timestamp interval_start_time, Integer limitRows) throws Exception; - // Load all results for a particular clusterName - List loadResultsByClusterName(String clusterName, Timestamp interval_start_time, Integer limitRows) throws Exception; - // Load all recommendations of a particular experiment List loadRecommendationsByExperimentName(String experimentName) throws Exception; // Load all recommendations of a particular cluster diff --git a/src/main/java/com/autotune/database/dao/ExperimentDAOImpl.java b/src/main/java/com/autotune/database/dao/ExperimentDAOImpl.java index 5735e0465..0c6ad3136 100644 --- a/src/main/java/com/autotune/database/dao/ExperimentDAOImpl.java +++ b/src/main/java/com/autotune/database/dao/ExperimentDAOImpl.java @@ -520,36 +520,6 @@ public List loadResultsByExperimentName(String experimentNam } return kruizeResultsEntries; } - @Override - public List loadResultsByClusterName(String clusterName, Timestamp interval_end_time, Integer limitRows) throws Exception { - // TODO: load only experimentStatus=inProgress , playback may not require completed experiments - List 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 loadRecommendationsByExperimentName(String experimentName) throws Exception { diff --git a/src/main/java/com/autotune/database/helper/DBConstants.java b/src/main/java/com/autotune/database/helper/DBConstants.java index cce4821e3..480df4ba7 100644 --- a/src/main/java/com/autotune/database/helper/DBConstants.java +++ b/src/main/java/com/autotune/database/helper/DBConstants.java @@ -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"; diff --git a/src/main/java/com/autotune/database/service/ExperimentDBService.java b/src/main/java/com/autotune/database/service/ExperimentDBService.java index 0b50ef6b7..ee3083ea3 100644 --- a/src/main/java/com/autotune/database/service/ExperimentDBService.java +++ b/src/main/java/com/autotune/database/service/ExperimentDBService.java @@ -189,32 +189,7 @@ public void loadRecommendationsFromDBByName(Map mainKruize } } } - // Todo - confirm if experimentResultData to be changed to clusterResultData - public void loadResultsFromDBByClusterName(Map 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 kruizeResultsEntries = experimentDAO.loadResultsByClusterName(clusterName, interval_end_time, limitRows); - if (null != kruizeResultsEntries && !kruizeResultsEntries.isEmpty()) { - List updateResultsAPIObjects = DBHelpers.Converters.KruizeObjectConverters.convertResultEntryToUpdateResultsAPIObject(kruizeResultsEntries); - if (null != updateResultsAPIObjects && !updateResultsAPIObjects.isEmpty()) { - List 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 mainKruizeExperimentMap, String clusterName) throws Exception { ExperimentInterface experimentInterface = new ExperimentInterfaceImpl(); // Load Recommendations from DB and save to local @@ -388,11 +363,6 @@ public void loadExperimentAndRecommendationsFromDBByName(Map mainKruizeExperimentMap, String clusterName) throws Exception { - - loadExperimentsFromDBByClusterName(mainKruizeExperimentMap, clusterName); - loadResultsFromDBByClusterName(mainKruizeExperimentMap, clusterName, null, null); - } public void loadExperimentsAndRecommendationsFromDBByClusterName(Map mainKruizeExperimentMap, String clusterName) throws Exception { loadExperimentsFromDBByClusterName(mainKruizeExperimentMap, clusterName); loadRecommendationsFromDBByClusterName(mainKruizeExperimentMap, clusterName);