-
Notifications
You must be signed in to change notification settings - Fork 62
Add Validations for the BulkAPI Params #1557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: mvp_demo
Are you sure you want to change the base?
Changes from 10 commits
87ed0af
baea6e2
6f43da5
84defdd
f8723ee
dad58e2
1dd338f
2dba984
bc31d67
a2443b8
44d9dca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package com.autotune.common.bulk; | ||
|
|
||
| import com.autotune.analyzer.serviceObjects.BulkInput; | ||
| import com.autotune.analyzer.serviceObjects.BulkJobStatus; | ||
| import com.autotune.common.data.ValidationOutputData; | ||
| import com.autotune.common.datasource.DataSourceInfo; | ||
| import com.autotune.common.datasource.DataSourceOperatorImpl; | ||
| import com.autotune.common.utils.CommonUtils; | ||
| import com.autotune.database.dao.ExperimentDAOImpl; | ||
| import com.autotune.database.service.ExperimentDBService; | ||
| import com.autotune.database.table.lm.KruizeBulkJobEntry; | ||
| import com.autotune.utils.KruizeConstants; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.time.Duration; | ||
| import java.time.OffsetDateTime; | ||
| import java.time.format.DateTimeParseException; | ||
|
|
||
| public class BulkServiceValidation { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a Javadoc could be a bit helpful for the devs to understand about this class. |
||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(BulkServiceValidation.class); | ||
|
|
||
| public static ValidationOutputData validate(BulkInput payload, String jobID) throws Exception { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Java doc for this and other methods would be helpful as well. |
||
|
|
||
| ValidationOutputData validationOutputData; | ||
|
|
||
| validationOutputData = buildErrorOutput(validateTimeRange(payload.getTime_range()), jobID); | ||
| if (validationOutputData != null) return validationOutputData; | ||
|
|
||
| if (payload.getDatasource() != null) { | ||
| validationOutputData = buildErrorOutput(validateDatasourceConnection(payload.getDatasource()), jobID); | ||
| } | ||
|
|
||
| if (validationOutputData == null) { | ||
| validationOutputData = new ValidationOutputData(true, "", 200); | ||
| } | ||
| return validationOutputData; | ||
| } | ||
|
|
||
| private static ValidationOutputData buildErrorOutput(String errorMsg, String jobID) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a java doc would be helpful |
||
| if (errorMsg != null && !errorMsg.isEmpty()) { | ||
| return new ValidationOutputData(false, errorMsg + " for the jobId: " + jobID, 400); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| public static String validateDatasourceConnection(String datasourceName) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a java doc would be helpful |
||
| String errorMessage = ""; | ||
| try { | ||
| DataSourceInfo dataSourceInfo = null; | ||
| try { | ||
| dataSourceInfo = new ExperimentDBService().loadDataSourceFromDBByName(datasourceName); | ||
| } catch (Exception e) { | ||
| errorMessage = String.format(KruizeConstants.DataSourceConstants.DataSourceMetadataErrorMsgs.LOAD_DATASOURCE_FROM_DB_ERROR, datasourceName, e.getMessage()); | ||
| LOGGER.error(errorMessage); | ||
| return errorMessage; | ||
| } | ||
| LOGGER.info(KruizeConstants.DataSourceConstants.DataSourceInfoMsgs.VERIFYING_DATASOURCE_REACHABILITY, datasourceName); | ||
| DataSourceOperatorImpl op = DataSourceOperatorImpl.getInstance().getOperator(KruizeConstants.SupportedDatasources.PROMETHEUS); | ||
| if (dataSourceInfo == null || op.isServiceable(dataSourceInfo) == CommonUtils.DatasourceReachabilityStatus.NOT_REACHABLE) { | ||
| errorMessage = KruizeConstants.DataSourceConstants.DataSourceErrorMsgs.DATASOURCE_NOT_SERVICEABLE; | ||
| LOGGER.error(errorMessage); | ||
| } | ||
| } catch (Exception ex) { | ||
| errorMessage = ex.getMessage(); | ||
| LOGGER.error(errorMessage); | ||
| } | ||
| return errorMessage; | ||
| } | ||
|
|
||
| public static String validateTimeRange(BulkInput.TimeRange timeRange) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a java doc would be helpful |
||
| String errorMessage = ""; | ||
| if (timeRange == null || timeRange.isEmpty()) { | ||
| LOGGER.debug("No time range specified"); | ||
| return errorMessage; | ||
| } | ||
| try { | ||
| OffsetDateTime startTime = OffsetDateTime.parse(timeRange.getStart()); | ||
| OffsetDateTime endTime = OffsetDateTime.parse(timeRange.getEnd()); | ||
|
|
||
| if (startTime.isAfter(endTime)) { | ||
| errorMessage = KruizeConstants.KRUIZE_BULK_API.INVALID_START_TIME; | ||
| return errorMessage; | ||
| } | ||
|
|
||
| } catch (DateTimeParseException ex) { | ||
| errorMessage = KruizeConstants.KRUIZE_BULK_API.INVALID_DATE_FORMAT; | ||
| } catch (Exception e) { | ||
| errorMessage = KruizeConstants.KRUIZE_BULK_API.TIME_RANGE_EXCEPTION; | ||
| } | ||
| return errorMessage; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@khansaad Thanks for raising the validations PR. Please kindly add the Copyrights header, as it's a new file.