From 5548052cc275f38bf9b02d2bdae429ac28e02ef6 Mon Sep 17 00:00:00 2001 From: Hanguang Zhang Date: Thu, 30 Jan 2020 11:10:23 -0800 Subject: [PATCH] Revert "merge changes from alpha branch: change setting name and fix stop AD request" (#38) This reverts commit 363daa6af5bbf416311ed7860c489a2848584d05, reversing changes made to caebb97d91a87369aa33f9fc90d4b87eba12eb76. This also reverts commit ff190fa038a71564adbf9aa86ca406123096c026 --- .../rest/RestDeleteAnomalyDetectorAction.java | 18 +++++------ .../ad/settings/AnomalyDetectorSettings.java | 30 +++++++++---------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestDeleteAnomalyDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestDeleteAnomalyDetectorAction.java index c6a08a06..7f7558c1 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestDeleteAnomalyDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestDeleteAnomalyDetectorAction.java @@ -17,15 +17,15 @@ import com.amazon.opendistroforelasticsearch.ad.model.AnomalyDetector; import com.amazon.opendistroforelasticsearch.ad.rest.handler.AnomalyDetectorActionHandler; -import com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorAction; -import com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorRequest; -import com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorResponse; +import com.amazon.opendistroforelasticsearch.ad.transport.DeleteDetectorAction; +import com.amazon.opendistroforelasticsearch.ad.transport.DeleteDetectorRequest; import com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; @@ -89,8 +89,8 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli return channel -> { if (channel.request().method() == RestRequest.Method.POST) { logger.info("Stop anomaly detector {}", detectorId); - StopDetectorRequest stopDetectorRequest = new StopDetectorRequest(detectorId); - client.execute(StopDetectorAction.INSTANCE, stopDetectorRequest, stopAdDetectorListener(channel, detectorId)); + DeleteDetectorRequest deleteDetectorRequest = new DeleteDetectorRequest().adID(detectorId); + client.execute(DeleteDetectorAction.INSTANCE, deleteDetectorRequest, stopAdDetectorListener(channel, detectorId)); } else if (channel.request().method() == RestRequest.Method.DELETE) { logger.info("Delete anomaly detector {}", detectorId); handler @@ -117,11 +117,11 @@ private void deleteAnomalyDetectorDoc( client.delete(deleteRequest, new RestStatusToXContentListener<>(channel)); } - private ActionListener stopAdDetectorListener(RestChannel channel, String detectorId) { - return new ActionListener() { + private ActionListener stopAdDetectorListener(RestChannel channel, String detectorId) { + return new ActionListener() { @Override - public void onResponse(StopDetectorResponse stopDetectorResponse) { - if (stopDetectorResponse.success()) { + public void onResponse(AcknowledgedResponse deleteDetectorResponse) { + if (deleteDetectorResponse.isAcknowledged()) { logger.info("AD model deleted successfully for detector {}", detectorId); channel.sendResponse(new BytesRestResponse(RestStatus.OK, "AD model deleted successfully")); } else { diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/settings/AnomalyDetectorSettings.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/settings/AnomalyDetectorSettings.java index 314d1a98..1c669888 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/settings/AnomalyDetectorSettings.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/settings/AnomalyDetectorSettings.java @@ -29,14 +29,14 @@ public final class AnomalyDetectorSettings { private AnomalyDetectorSettings() {} public static final Setting MAX_ANOMALY_DETECTORS = Setting - .intSetting("opendistro.anomaly_detection.max_anomaly_detectors", 1000, Setting.Property.NodeScope, Setting.Property.Dynamic); + .intSetting("ml.anomaly_detectors.max_anomaly_detectors", 1000, Setting.Property.NodeScope, Setting.Property.Dynamic); public static final Setting MAX_ANOMALY_FEATURES = Setting - .intSetting("opendistro.anomaly_detection.max_anomaly_features", 5, Setting.Property.NodeScope, Setting.Property.Dynamic); + .intSetting("ml.anomaly_detectors.max_anomaly_features", 5, Setting.Property.NodeScope, Setting.Property.Dynamic); public static final Setting REQUEST_TIMEOUT = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.request_timeout", + "ml.anomaly_detectors.request_timeout", TimeValue.timeValueSeconds(10), Setting.Property.NodeScope, Setting.Property.Dynamic @@ -44,7 +44,7 @@ private AnomalyDetectorSettings() {} public static final Setting DETECTION_INTERVAL = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.detection_interval", + "ml.anomaly_detectors.detection_interval", TimeValue.timeValueMinutes(10), Setting.Property.NodeScope, Setting.Property.Dynamic @@ -52,7 +52,7 @@ private AnomalyDetectorSettings() {} public static final Setting DETECTION_WINDOW_DELAY = Setting .timeSetting( - "opendistro.anomaly_detection.detection_window_delay", + "ml.anomaly_detectors.detection_window_delay", TimeValue.timeValueMinutes(0), Setting.Property.NodeScope, Setting.Property.Dynamic @@ -60,7 +60,7 @@ private AnomalyDetectorSettings() {} public static final Setting AD_RESULT_ROLLOVER_PERIOD = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.ad_result_rollover_period", + "ml.anomaly_detectors.ad_result_rollover_period", TimeValue.timeValueHours(12), Setting.Property.NodeScope, Setting.Property.Dynamic @@ -68,7 +68,7 @@ private AnomalyDetectorSettings() {} public static final Setting AD_RESULT_HISTORY_ROLLOVER_PERIOD = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.ad_result_history_rollover_period", + "ml.anomaly_detectors.ad_result_history_rollover_period", TimeValue.timeValueHours(12), Setting.Property.NodeScope, Setting.Property.Dynamic @@ -76,23 +76,21 @@ private AnomalyDetectorSettings() {} public static final Setting AD_RESULT_HISTORY_INDEX_MAX_AGE = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.ad_result_history_max_age", + "ml.anomaly_detectors.ad_result_history_max_age", TimeValue.timeValueHours(24), Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting AD_RESULT_HISTORY_MAX_DOCS = Setting - .longSetting("opendistro.anomaly_detection.ad_result_history_max_docs", 10000L, 0L, - Setting.Property.NodeScope, Setting.Property.Dynamic); + .longSetting("ml.anomaly_detectors.ad_result_history_max_docs", 10000L, 0L, Setting.Property.NodeScope, Setting.Property.Dynamic); public static final Setting MAX_RETRY_FOR_UNRESPONSIVE_NODE = Setting - .intSetting("opendistro.anomaly_detection.max_retry_for_unresponsive_node", 5, 0, - Setting.Property.NodeScope, Setting.Property.Dynamic); + .intSetting("ml.anomaly_detectors.max_retry_for_unresponsive_node", 5, 0, Setting.Property.NodeScope, Setting.Property.Dynamic); public static final Setting COOLDOWN_MINUTES = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.cooldown_minutes", + "ml.anomaly_detectors.cooldown_minutes", TimeValue.timeValueMinutes(5), Setting.Property.NodeScope, Setting.Property.Dynamic @@ -100,7 +98,7 @@ private AnomalyDetectorSettings() {} public static final Setting BACKOFF_MINUTES = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.backoff_minutes", + "ml.anomaly_detectors.backoff_minutes", TimeValue.timeValueMinutes(15), Setting.Property.NodeScope, Setting.Property.Dynamic @@ -108,14 +106,14 @@ private AnomalyDetectorSettings() {} public static final Setting BACKOFF_INITIAL_DELAY = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.backoff_initial_delay", + "ml.anomaly_detectors.backoff_initial_delay", TimeValue.timeValueMillis(1000), Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting MAX_RETRY_FOR_BACKOFF = Setting - .intSetting("opendistro.anomaly_detection.max_retry_for_backoff", 3, 0, Setting.Property.NodeScope, Setting.Property.Dynamic); + .intSetting("ml.anomaly_detectors.max_retry_for_backoff", 3, 0, Setting.Property.NodeScope, Setting.Property.Dynamic); public static final String ANOMALY_DETECTORS_INDEX_MAPPING_FILE = "mappings/anomaly-detectors.json"; public static final String ANOMALY_RESULTS_INDEX_MAPPING_FILE = "mappings/anomaly-results.json";