Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Feb 7, 2023
1 parent 01dd362 commit 7f68dc7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public SearchFeatureDao(
settingsUpdateConsumers.put(PAGE_SIZE, it -> this.pageSize = (int) it);
clusterService.getClusterSettings().addSettingsUpdateConsumer(settingsUpdateConsumers);
} catch (Exception e) {
// TODO Handle this
// FIXME Handle this
// https://github.com/opensearch-project/opensearch-sdk-java/issues/422
}
this.minimumDocCountForPreview = minimumDocCount;
this.previewTimeoutInMilliseconds = previewTimeoutInMilliseconds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public AnomalyDetectionIndices(
this.adminClient = restClient;
this.clusterService = sdkClusterService;
this.threadPool = threadPool;
// FIXME Implement this
// https://github.com/opensearch-project/opensearch-sdk-java/issues/423
// this.clusterService.addLocalNodeMasterListener(this);
this.historyRolloverPeriod = AD_RESULT_HISTORY_ROLLOVER_PERIOD.get(settings);
this.historyMaxDocs = AD_RESULT_HISTORY_MAX_DOCS_PER_SHARD.get(settings);
Expand All @@ -203,7 +205,8 @@ public AnomalyDetectionIndices(
try {
this.clusterService.getClusterSettings().addSettingsUpdateConsumer(settingToConsumerMap);
} catch (Exception e) {
// TODO Handle this
// FIXME Handle this
// https://github.com/opensearch-project/opensearch-sdk-java/issues/422
}

this.settings = Settings.builder().put("index.hidden", true).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.extensions.rest.ExtensionRestRequest;
import org.opensearch.extensions.rest.ExtensionRestResponse;
import org.opensearch.rest.BytesRestResponse;
import org.opensearch.rest.RestChannel;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.RestStatus;
import org.opensearch.sdk.ExtensionsRunner;
Expand Down Expand Up @@ -118,16 +116,13 @@ public List<RouteHandler> routeHandlers() {
}
};

protected void sendAnomalyDetectorValidationParseResponse(DetectorValidationIssue issue, RestChannel channel) throws IOException {
try {
BytesRestResponse restResponse = new BytesRestResponse(
RestStatus.OK,
new ValidateAnomalyDetectorResponse(issue).toXContent(channel.newBuilder())
);
channel.sendResponse(restResponse);
} catch (Exception e) {
channel.sendResponse(new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, e.getMessage()));
}
protected ExtensionRestResponse sendAnomalyDetectorValidationParseResponse(ExtensionRestRequest request, DetectorValidationIssue issue)
throws IOException {
return new ExtensionRestResponse(
request,
RestStatus.OK,
new ValidateAnomalyDetectorResponse(issue).toXContent(JsonXContent.contentBuilder())
);
}

private Boolean validationTypesAreAccepted(String validationType) {
Expand Down Expand Up @@ -161,11 +156,7 @@ protected ExtensionRestResponse prepareRequest(ExtensionRestRequest request) thr
ADException.getType(),
ADException.getMessage()
);
return new ExtensionRestResponse(
request,
RestStatus.OK,
new ValidateAnomalyDetectorResponse(issue).toXContent(JsonXContent.contentBuilder())
);
return sendAnomalyDetectorValidationParseResponse(request, issue);
} else {
throw ex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public IndexAnomalyDetectorTransportAction(
try {
sdkClusterService.getClusterSettings().addSettingsUpdateConsumer(FILTER_BY_BACKEND_ROLES, it -> filterByEnabled = it);
} catch (Exception e) {
// TODO Handle this
// FIXME Handle this
// https://github.com/opensearch-project/opensearch-sdk-java/issues/422
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public ValidateAnomalyDetectorTransportAction(
try {
clusterService.getClusterSettings().addSettingsUpdateConsumer(FILTER_BY_BACKEND_ROLES, it -> filterByEnabled = it);
} catch (Exception e) {
// TODO Handle this
// FIXME Handle this
// https://github.com/opensearch-project/opensearch-sdk-java/issues/422
}
this.searchFeatureDao = searchFeatureDao;
this.clock = Clock.systemUTC();
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/opensearch/ad/util/ParseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,8 @@ public static void getDetector(
NamedXContentRegistry xContentRegistry,
boolean filterByBackendRole
) {
logger.info("in getDetector()");
if (clusterService.state().metadata().indices().containsKey(AnomalyDetector.ANOMALY_DETECTORS_INDEX)) {
logger.info("Cluster metadata contains {}", AnomalyDetector.ANOMALY_DETECTORS_INDEX);
GetRequest request = new GetRequest(AnomalyDetector.ANOMALY_DETECTORS_INDEX).id(detectorId);
logger.info("Creating get request for detector {}", detectorId);
client
.get(
request,
Expand All @@ -549,7 +546,6 @@ public static void getDetector(
)
);
} else {
logger.info("Index not found: {}", AnomalyDetector.ANOMALY_DETECTORS_INDEX);
listener.onFailure(new IndexNotFoundException(AnomalyDetector.ANOMALY_DETECTORS_INDEX));
}
}
Expand Down

0 comments on commit 7f68dc7

Please sign in to comment.