Skip to content

Commit

Permalink
Removed end_date from mandatory feilds
Browse files Browse the repository at this point in the history
Signed-off-by: msvinaykumar <vinakuma@redhat.com>
  • Loading branch information
msvinaykumar committed Jul 21, 2023
1 parent 781b0a1 commit ce58974
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 44 deletions.
27 changes: 2 additions & 25 deletions src/main/java/com/autotune/analyzer/serviceObjects/Converters.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.autotune.analyzer.serviceObjects;

import com.autotune.analyzer.exceptions.InvalidValueException;
import com.autotune.analyzer.kruizeObject.ExperimentUseCaseType;
import com.autotune.analyzer.kruizeObject.KruizeObject;
import com.autotune.analyzer.kruizeObject.ObjectiveFunction;
import com.autotune.analyzer.kruizeObject.SloInfo;
Expand All @@ -25,6 +26,7 @@

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -274,31 +276,6 @@ public static ContainerData getLatestRecommendations(ContainerData containerData
}
return clonedContainerData;
}
public static void getLatestResults(ContainerData containerData) {
// ContainerData clonedContainerData = Utils.getClone(containerData, ContainerData.class);
if (null != containerData) {
HashMap<Timestamp, IntervalResults> results = containerData.getResults();
Timestamp latestTimestamp = null;
List<Timestamp> tempList = new ArrayList<>();
for (Timestamp timestamp : results.keySet()) {
if (null == latestTimestamp) {
latestTimestamp = timestamp;
} else {
if (timestamp.after(latestTimestamp)) {
tempList.add(latestTimestamp);
latestTimestamp = timestamp;
} else {
tempList.add(timestamp);
}
}
}
for (Timestamp timestamp : tempList) {
results.remove(timestamp);
}
containerData.setResults(results);
}
// return containerData;
}

public static void getLatestResults(ContainerData containerData) {
if (null != containerData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private void loadResults(Map<String, KruizeObject> mKruizeExperimentMap, String
if (experimentName == null || experimentName.isEmpty())
new ExperimentDBService().loadAllResults(mKruizeExperimentMap);
else
new ExperimentDBService().loadResultsFromDBByName(mKruizeExperimentMap, experimentName);
new ExperimentDBService().loadResultsFromDBByName(mKruizeExperimentMap, experimentName, null, null);

} catch (Exception e) {
LOGGER.error("Failed to load saved results data: {} ", e.getMessage());
Expand Down Expand Up @@ -352,7 +352,7 @@ private void buildRecommendationsResponse(Map<String, KruizeObject> mKruizeExper
ko,
getLatest,
false,
null);
(String) null);

mergeRecommendationsInKruizeObject(listRecommendationsAPIObject, ko);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.autotune.analyzer.experiment.ExperimentInitiator;
import com.autotune.analyzer.kruizeObject.KruizeObject;
import com.autotune.analyzer.recommendations.RecommendationConstants;
import com.autotune.analyzer.serviceObjects.ContainerAPIObject;
import com.autotune.analyzer.serviceObjects.Converters;
import com.autotune.analyzer.serviceObjects.ListRecommendationsAPIObject;
Expand Down Expand Up @@ -74,25 +75,29 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
}

// Check if interval_end_time is provided
if (intervalEndTimeStr == null || intervalEndTimeStr.isEmpty()) {
/*
if (intervalEndTimeStr == null || intervalEndTimeStr.isEmpty()) {
sendErrorResponse(response, null, HttpServletResponse.SC_BAD_REQUEST, AnalyzerErrorConstants.APIErrors.UpdateRecommendationsAPI.INTERVAL_END_TIME_MANDATORY);
return;
}
}*/

LOGGER.debug("experiment_name : {} and interval_end_time : {}", experiment_name, intervalEndTimeStr);
// Convert interval_endtime to UTC date format
if (!Utils.DateUtils.isAValidDate(KruizeConstants.DateFormats.STANDARD_JSON_DATE_FORMAT, intervalEndTimeStr)) {
sendErrorResponse(
response,
new Exception(AnalyzerErrorConstants.APIErrors.ListRecommendationsAPI.INVALID_TIMESTAMP_EXCPTN),
HttpServletResponse.SC_BAD_REQUEST,
String.format(AnalyzerErrorConstants.APIErrors.ListRecommendationsAPI.INVALID_TIMESTAMP_MSG, intervalEndTimeStr)
);
return;
Timestamp interval_end_time = null ;
if (intervalEndTimeStr != null ) {
if (!Utils.DateUtils.isAValidDate(KruizeConstants.DateFormats.STANDARD_JSON_DATE_FORMAT, intervalEndTimeStr)) {
sendErrorResponse(
response,
new Exception(AnalyzerErrorConstants.APIErrors.ListRecommendationsAPI.INVALID_TIMESTAMP_EXCPTN),
HttpServletResponse.SC_BAD_REQUEST,
String.format(AnalyzerErrorConstants.APIErrors.ListRecommendationsAPI.INVALID_TIMESTAMP_MSG, intervalEndTimeStr)
);
return;
}
//Check if data exist
interval_end_time = Utils.DateUtils.getTimeStampFrom(KruizeConstants.DateFormats.STANDARD_JSON_DATE_FORMAT, intervalEndTimeStr);
}

//Check if data exist
Timestamp interval_end_time = Utils.DateUtils.getTimeStampFrom(KruizeConstants.DateFormats.STANDARD_JSON_DATE_FORMAT, intervalEndTimeStr);
ExperimentResultData experimentResultData = null;
try {
experimentResultData = new ExperimentDBService().getExperimentResultData(experiment_name, interval_end_time);
Expand Down Expand Up @@ -129,7 +134,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
if (success)
sendSuccessResponse(response, kruizeObject, interval_end_time);
else {
sendErrorResponse(response, null, HttpServletResponse.SC_BAD_REQUEST, AnalyzerConstants.RecommendationNotificationMsgConstant.NOT_ENOUGH_DATA);
sendErrorResponse(response, null, HttpServletResponse.SC_BAD_REQUEST, RecommendationConstants.RecommendationNotificationMsgConstant.NOT_ENOUGH_DATA);
}
}
} catch (Exception e) {
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/autotune/database/dao/ExperimentDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,16 @@ public KruizeRecommendationEntry loadRecommendationsByExperimentNameAndDate(Stri
public KruizeResultsEntry getKruizeResultsEntry(String experiment_name, Timestamp interval_end_time) throws Exception {
KruizeResultsEntry kruizeResultsEntry = null;
try (Session session = KruizeHibernateUtil.getSessionFactory().openSession()) {
kruizeResultsEntry = session.createQuery(SELECT_FROM_RESULTS_BY_EXP_NAME_AND_END_TIME, KruizeResultsEntry.class)
.setParameter(KruizeConstants.JSONKeys.EXPERIMENT_NAME, experiment_name)
.setParameter(KruizeConstants.JSONKeys.INTERVAL_END_TIME, interval_end_time)
.getSingleResult();
if (null != interval_end_time) {
kruizeResultsEntry = session.createQuery(SELECT_FROM_RESULTS_BY_EXP_NAME_AND_END_TIME, KruizeResultsEntry.class)
.setParameter(KruizeConstants.JSONKeys.EXPERIMENT_NAME, experiment_name)
.setParameter(KruizeConstants.JSONKeys.INTERVAL_END_TIME, interval_end_time)
.getSingleResult();
}else{
kruizeResultsEntry = session.createQuery(SELECT_FROM_RESULTS_BY_EXP_NAME_AND_MAX_END_TIME, KruizeResultsEntry.class)
.setParameter(KruizeConstants.JSONKeys.EXPERIMENT_NAME, experiment_name)
.getSingleResult();
}
} catch (NoResultException e) {
LOGGER.error("Data not found in kruizeResultsEntry for exp_name:{} interval_end_time:{} ", experiment_name, interval_end_time);
kruizeResultsEntry = null;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/autotune/database/helper/DBConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public static final class SQLQUERY {
public static final String SELECT_FROM_RESULTS_BY_EXP_NAME = "from KruizeResultsEntry k WHERE k.experiment_name = :experimentName";
public static final String SELECT_FROM_RESULTS_BY_EXP_NAME_AND_DATE_RANGE = String.format("from KruizeResultsEntry k WHERE k.experiment_name = :%s and k.interval_end_time <= :%s ORDER BY k.interval_end_time DESC", KruizeConstants.JSONKeys.EXPERIMENT_NAME, KruizeConstants.JSONKeys.INTERVAL_END_TIME, KruizeConstants.JSONKeys.INTERVAL_START_TIME);
public static final String SELECT_FROM_RESULTS_BY_EXP_NAME_AND_END_TIME = String.format("from KruizeResultsEntry k WHERE k.experiment_name = :%s and k.interval_end_time = :%s", 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.experiment_name = :%s and k.interval_end_time = (SELECT MAX(e.interval_end_time) FROM KruizeResultsEntry e where e.experiment_name = :%s )", KruizeConstants.JSONKeys.EXPERIMENT_NAME , KruizeConstants.JSONKeys.EXPERIMENT_NAME);
public static final String SELECT_FROM_RECOMMENDATIONS_BY_EXP_NAME = "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.experiment_name = :%s and k.interval_end_time= :%s", KruizeConstants.JSONKeys.EXPERIMENT_NAME, KruizeConstants.JSONKeys.INTERVAL_END_TIME);
public static final String SELECT_FROM_RECOMMENDATIONS = "from KruizeRecommendationEntry";
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/autotune/utils/KruizeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ private DBConstants() {
public static final class DateFormats {
public static final String STANDARD_JSON_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
public static final String DB_EXTRACTION_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
public static final long MILLI_SECONDS_FOR_DAY = 24 * 60 * 60 * 1000;
public static final long MINUTES_FOR_DAY = 24 * 60;

private DateFormats() {

Expand Down

0 comments on commit ce58974

Please sign in to comment.