diff --git a/build.gradle b/build.gradle index f975c6a2a..42b0246e8 100644 --- a/build.gradle +++ b/build.gradle @@ -755,18 +755,9 @@ dependencies { // compileOnly "org.opensearch:opensearch-job-scheduler-spi:${job_scheduler_version}" // Removed Common Utils dependency from AD // implementation "org.opensearch:common-utils:${common_utils_version}" -<<<<<<< Upstream, based on 1ba8bc66a5e1deda321dfda1d63639ed02e2b670 -<<<<<<< HEAD implementation "org.opensearch.sdk:opensearch-sdk-java:1.0.0-SNAPSHOT" implementation "org.opensearch.client:opensearch-rest-client:${opensearch_version}" -======= - implementation "org.opensearch:opensearch-sdk-java:1.0.0-SNAPSHOT" ->>>>>>> 6f76601 (Add High Level Rest Client to extension) -======= - implementation "org.opensearch.sdk:opensearch-sdk-java:1.0.0-SNAPSHOT" ->>>>>>> 1ca3b79 Fix compile errors implementation "org.opensearch.client:opensearch-java:${opensearch_version}" - implementation "org.opensearch.client:opensearch-rest-client:${opensearch_version}" implementation "org.opensearch.client:opensearch-rest-high-level-client:${opensearch_version}" implementation group: 'com.google.guava', name: 'guava', version:'31.0.1-jre' implementation group: 'com.google.guava', name: 'failureaccess', version:'1.0.1' diff --git a/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java b/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java index 4c6bc8a4e..21a011502 100644 --- a/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java +++ b/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java @@ -249,12 +249,12 @@ public Collection createComponents( Interpolator interpolator = new LinearUniformInterpolator(singleFeatureLinearUniformInterpolator); // SearchFeatureDao is Injected for IndexAnomalyDetectorTrasnportAction constructor SearchFeatureDao searchFeatureDao = new SearchFeatureDao( - null, // Client client, + null, // client, xContentRegistry, interpolator, clientUtil, settings, - null, // ClusterService clusterService, + null, // clusterService, AnomalyDetectorSettings.NUM_SAMPLES_PER_TREE ); @@ -874,8 +874,6 @@ public List getNamedXContent() { new ActionHandler<>(DeleteAnomalyDetectorAction.INSTANCE, DeleteAnomalyDetectorTransportAction.class), new ActionHandler<>(GetAnomalyDetectorAction.INSTANCE, GetAnomalyDetectorTransportAction.class), new ActionHandler<>(IndexAnomalyDetectorAction.INSTANCE, IndexAnomalyDetectorTransportAction.class) - */ - /* @anomaly-detection.create-detector new ActionHandler<>(AnomalyDetectorJobAction.INSTANCE, AnomalyDetectorJobTransportAction.class), new ActionHandler<>(ADResultBulkAction.INSTANCE, ADResultBulkTransportAction.class), new ActionHandler<>(EntityResultAction.INSTANCE, EntityResultTransportAction.class), diff --git a/src/main/java/org/opensearch/ad/feature/SearchFeatureDao.java b/src/main/java/org/opensearch/ad/feature/SearchFeatureDao.java index 26e881e9d..317d4c42e 100644 --- a/src/main/java/org/opensearch/ad/feature/SearchFeatureDao.java +++ b/src/main/java/org/opensearch/ad/feature/SearchFeatureDao.java @@ -123,7 +123,8 @@ public SearchFeatureDao( settingsUpdateConsumers.put(PAGE_SIZE, it -> this.pageSize = (int) it); clusterService.addSettingsUpdateConsumer(settingsUpdateConsumers); } catch (Exception e) { - // TODO Handle this + // FIXME Handle this here or in SDKClusterService after bug fix + // https://github.com/opensearch-project/opensearch-sdk-java/issues/366 } this.minimumDocCountForPreview = minimumDocCount; this.previewTimeoutInMilliseconds = previewTimeoutInMilliseconds; diff --git a/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java b/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java index cd1c749b8..7d31bdd00 100644 --- a/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java +++ b/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java @@ -175,7 +175,7 @@ public AnomalyDetectionIndices( int maxUpdateRunningTimes ) { this.client = restClient; - this.adminClient = restClient; + this.adminClient = client.admin(); this.clusterService = sdkClusterService; this.threadPool = threadPool; // this.clusterService.addLocalNodeMasterListener(this); @@ -203,7 +203,8 @@ public AnomalyDetectionIndices( try { this.clusterService.addSettingsUpdateConsumer(settingToConsumerMap); } catch (Exception e) { - // TODO Handle this + // FIXME Handle this here or in SDKClusterService after bug fix + // https://github.com/opensearch-project/opensearch-sdk-java/issues/366 } this.settings = Settings.builder().put("index.hidden", true).build(); diff --git a/src/main/java/org/opensearch/ad/rest/AbstractAnomalyDetectorAction.java b/src/main/java/org/opensearch/ad/rest/AbstractAnomalyDetectorAction.java index 02bba083d..b24019893 100644 --- a/src/main/java/org/opensearch/ad/rest/AbstractAnomalyDetectorAction.java +++ b/src/main/java/org/opensearch/ad/rest/AbstractAnomalyDetectorAction.java @@ -59,7 +59,8 @@ public AbstractAnomalyDetectorAction(ExtensionsRunner extensionsRunner) { try { clusterService.addSettingsUpdateConsumer(settingToConsumerMap); } catch (Exception e) { - // FIXME handle this + // FIXME Handle this here or in SDKClusterService after bug fix + // https://github.com/opensearch-project/opensearch-sdk-java/issues/366 } } } diff --git a/src/main/java/org/opensearch/ad/rest/RestIndexAnomalyDetectorAction.java b/src/main/java/org/opensearch/ad/rest/RestIndexAnomalyDetectorAction.java index 67037372f..828c31bc1 100644 --- a/src/main/java/org/opensearch/ad/rest/RestIndexAnomalyDetectorAction.java +++ b/src/main/java/org/opensearch/ad/rest/RestIndexAnomalyDetectorAction.java @@ -193,6 +193,8 @@ private ExtensionRestResponse indexAnomalyDetectorResponse(ExtensionRestRequest RestStatus restStatus = RestStatus.CREATED; if (request.method() == RestRequest.Method.PUT) { restStatus = RestStatus.OK; + } else { + logger.info("Detector ID: {}", response.getId()); } ExtensionRestResponse extensionRestResponse = new ExtensionRestResponse( request, diff --git a/src/main/java/org/opensearch/ad/rest/handler/AbstractAnomalyDetectorActionHandler.java b/src/main/java/org/opensearch/ad/rest/handler/AbstractAnomalyDetectorActionHandler.java index af44d264e..ef5c508eb 100644 --- a/src/main/java/org/opensearch/ad/rest/handler/AbstractAnomalyDetectorActionHandler.java +++ b/src/main/java/org/opensearch/ad/rest/handler/AbstractAnomalyDetectorActionHandler.java @@ -12,7 +12,6 @@ package org.opensearch.ad.rest.handler; import static org.opensearch.ad.constant.CommonErrorMessages.FAIL_TO_FIND_DETECTOR_MSG; -import static org.opensearch.ad.model.ADTaskType.HISTORICAL_DETECTOR_TASK_TYPES; import static org.opensearch.ad.model.AnomalyDetector.ANOMALY_DETECTORS_INDEX; import static org.opensearch.ad.util.ParseUtils.listEqualsWithoutConsideringOrder; import static org.opensearch.ad.util.ParseUtils.parseAggregators; @@ -385,6 +384,8 @@ protected void validateTimeField(boolean indexingDryRun) { // FIXME Need to implement this; does shard level actions on the cluster // https://github.com/opensearch-project/opensearch-sdk-java/issues/361 // client.execute(GetFieldMappingsAction.INSTANCE, getMappingsRequest, mappingsListener); + // For now just skip and go to the next step: + prepareAnomalyDetectorIndexing(indexingDryRun); } /** @@ -403,6 +404,8 @@ protected void prepareAnomalyDetectorIndexing(boolean indexingDryRun) { // () -> updateAnomalyDetector(detectorId, indexingDryRun), // xContentRegistry // ); + // FIXME Substitute call for the above, remove when JS work enables above code + updateAnomalyDetector(detectorId, indexingDryRun); } else { createAnomalyDetector(indexingDryRun); } @@ -445,14 +448,17 @@ private void onGetAnomalyDetectorResponse(GetResponse response, boolean indexing return; } - adTaskManager.getAndExecuteOnLatestDetectorLevelTask(detectorId, HISTORICAL_DETECTOR_TASK_TYPES, (adTask) -> { - if (adTask.isPresent() && !adTask.get().isDone()) { - // can't update detector if there is AD task running - listener.onFailure(new OpenSearchStatusException("Detector is running", RestStatus.INTERNAL_SERVER_ERROR)); - } else { - validateExistingDetector(existingDetector, indexingDryRun); - } - }, transportService, true, listener); + // FIXME: Need to implement ADTaskManager extension point + // https://github.com/opensearch-project/opensearch-sdk-java/issues/371 + + // adTaskManager.getAndExecuteOnLatestDetectorLevelTask(detectorId, HISTORICAL_DETECTOR_TASK_TYPES, (adTask) -> { + // if (adTask.isPresent() && !adTask.get().isDone()) { + // // can't update detector if there is AD task running + // listener.onFailure(new OpenSearchStatusException("Detector is running", RestStatus.INTERNAL_SERVER_ERROR)); + // } else { + validateExistingDetector(existingDetector, indexingDryRun); + // } + // }, transportService, true, listener); } catch (IOException e) { String message = "Failed to parse anomaly detector " + detectorId; logger.error(message, e); @@ -668,6 +674,8 @@ protected void validateCategoricalField(String detectorId, boolean indexingDryRu // FIXME Need to implement this; does shard level actions on the cluster // https://github.com/opensearch-project/opensearch-sdk-java/issues/361 // client.execute(GetFieldMappingsAction.INSTANCE, getMappingsRequest, mappingsListener); + // For now just skip and go to the next step: + searchAdInputIndices(detectorId, indexingDryRun); } protected void searchAdInputIndices(String detectorId, boolean indexingDryRun) {