From 7e98df382b48607ad1a6539ff0ae0699f7b35a41 Mon Sep 17 00:00:00 2001 From: Zhang Date: Tue, 3 Dec 2019 16:54:19 -0800 Subject: [PATCH 01/13] build artifacts for rpm, deb, zip --- build.gradle | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/build.gradle b/build.gradle index e8158b15..fd730163 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,10 @@ buildscript { } } +plugins { + id 'nebula.ospackage' version "5.3.0" +} + repositories { mavenCentral() maven { url "https://plugins.gradle.org/m2/" } @@ -39,6 +43,7 @@ repositories { ext { opendistroVersion = '1.2.1' + isSnapshot = "true" == System.getProperty("build.snapshot", "true") } version = "${opendistroVersion}.0-alpha" @@ -303,3 +308,54 @@ dependencies { checkstyle "com.puppycrawl.tools:checkstyle:${project.checkstyle.toolVersion}" } + +apply plugin: 'nebula.ospackage' + +// This is afterEvaluate because the bundlePlugin ZIP task is updated afterEvaluate and changes the ZIP name to match the plugin name +afterEvaluate { + ospackage { + packageName = "${name}" + release = isSnapshot ? "0.1" : '1' + version = "${project.version}" - "-SNAPSHOT" + + into '/usr/share/elasticsearch/plugins' + from(zipTree(bundlePlugin.archivePath)) { + into esplugin.name + } + + user 'root' + permissionGroup 'root' + fileMode 0644 + dirMode 0755 + + requires('elasticsearch-oss', versions.elasticsearch, EQUAL) + packager = 'Amazon' + vendor = 'Amazon' + os = 'LINUX' + prefix '/usr' + + license 'ASL-2.0' + maintainer 'OpenDistro for Elasticsearch Team ' + url 'https://opendistro.github.io/elasticsearch/downloads' + summary ''' + Anomaly Detection plugin for OpenDistro for Elasticsearch. + Reference documentation can be found at https://opendistro.github.io/for-elasticsearch-docs/. + '''.stripIndent().replace('\n', ' ').trim() + } + + buildRpm { + arch = 'NOARCH' + archiveName "${packageName}-${version}.rpm" + dependsOn 'assemble' + } + + buildDeb { + arch = 'amd64' + archiveName "${packageName}-${version}.deb" + dependsOn 'assemble' + } + + task buildPackages(type: GradleBuild) { + tasks = ['build', 'buildRpm', 'buildDeb'] + } +} From 562f74a5dcaf0cf27cf84ac2427574bd8b7214b8 Mon Sep 17 00:00:00 2001 From: Zhang Date: Mon, 10 Feb 2020 10:52:25 -0800 Subject: [PATCH 02/13] build es7.4 and change Action to ActionType --- build.gradle | 6 +++--- gradle/wrapper/gradle-wrapper.properties | 2 +- .../ad/transport/ADStatsAction.java | 15 +++------------ .../ad/transport/AnomalyResultAction.java | 16 +++------------- .../ad/transport/CronAction.java | 10 +++------- .../ad/transport/DeleteDetectorAction.java | 11 +++-------- .../ad/transport/DeleteModelAction.java | 6 +++--- .../ad/transport/RCFResultAction.java | 18 +++--------------- .../ad/transport/StopDetectorAction.java | 16 +++------------- .../ad/transport/ThresholdResultAction.java | 16 +++------------- .../ad/util/ClientUtil.java | 4 ++-- 11 files changed, 30 insertions(+), 90 deletions(-) diff --git a/build.gradle b/build.gradle index 22060d4c..b12eacc0 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { ext { es_mv = '7.2' es_group = "org.elasticsearch" - es_version = '7.2.1' + es_version = '7.4.2' es_distribution = 'oss-zip' } repositories { @@ -43,11 +43,11 @@ repositories { } ext { - opendistroVersion = '1.2.1' + opendistroVersion = '1.4.0' isSnapshot = "true" == System.getProperty("build.snapshot", "true") } -version = "${opendistroVersion}.0-alpha" +version = "${opendistroVersion}.0" apply plugin: 'java' apply plugin: 'idea' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 26b107ca..063322f7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsAction.java index 84e4c148..900e6c6c 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsAction.java @@ -15,13 +15,13 @@ package com.amazon.opendistroforelasticsearch.ad.transport; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.common.io.stream.Writeable; /** * ADStatsAction class */ -public class ADStatsAction extends Action { +public class ADStatsAction extends ActionType { public static final ADStatsAction INSTANCE = new ADStatsAction(); public static final String NAME = "cluster:admin/ad_stats_action"; @@ -30,16 +30,7 @@ public class ADStatsAction extends Action { * Constructor */ private ADStatsAction() { - super(NAME); + super(NAME, ADStatsResponse::new); } - @Override - public ADStatsResponse newResponse() { - throw new UnsupportedOperationException("Usage of Streamable is to be replaced by Writeable"); - } - - @Override - public Writeable.Reader getResponseReader() { - return ADStatsResponse::new; - } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultAction.java index 365e3ebd..758e522f 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultAction.java @@ -15,25 +15,15 @@ package com.amazon.opendistroforelasticsearch.ad.transport; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.common.io.stream.Writeable; -public class AnomalyResultAction extends Action { +public class AnomalyResultAction extends ActionType { public static final AnomalyResultAction INSTANCE = new AnomalyResultAction(); public static final String NAME = "cluster:admin/ad/result"; private AnomalyResultAction() { - super(NAME); + super(NAME, AnomalyResultResponse::new); } - @Override - public AnomalyResultResponse newResponse() { - throw new UnsupportedOperationException("Usage of Streamable is to be replaced by Writeable"); - } - - @Override - public Writeable.Reader getResponseReader() { - // return constructor method reference - return AnomalyResultResponse::new; - } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronAction.java index d974eba6..d9df8c59 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronAction.java @@ -15,18 +15,14 @@ package com.amazon.opendistroforelasticsearch.ad.transport; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; -public class CronAction extends Action { +public class CronAction extends ActionType { public static final CronAction INSTANCE = new CronAction(); public static final String NAME = "cluster:admin/ad/cron"; private CronAction() { - super(NAME); + super(NAME, CronResponse::new); } - @Override - public CronResponse newResponse() { - return new CronResponse(); - } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorAction.java index e961067f..92f38909 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorAction.java @@ -15,21 +15,16 @@ package com.amazon.opendistroforelasticsearch.ad.transport; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.support.master.AcknowledgedResponse; -public class DeleteDetectorAction extends Action { +public class DeleteDetectorAction extends ActionType { public static final DeleteDetectorAction INSTANCE = new DeleteDetectorAction(); public static final String NAME = "cluster:admin/ad/detector/delete"; private DeleteDetectorAction() { - super(NAME); - } - - @Override - public AcknowledgedResponse newResponse() { - return new AcknowledgedResponse(); + super(NAME, AcknowledgedResponse::new); } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java index 94051747..937f22d2 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java @@ -15,14 +15,14 @@ package com.amazon.opendistroforelasticsearch.ad.transport; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; -public class DeleteModelAction extends Action { +public class DeleteModelAction extends ActionType { public static final DeleteModelAction INSTANCE = new DeleteModelAction(); public static final String NAME = "cluster:admin/ad/model/delete"; private DeleteModelAction() { - super(NAME); + super(NAME, DeleteModelResponse::new); } @Override diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultAction.java index 65680056..a10451ee 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultAction.java @@ -15,26 +15,14 @@ package com.amazon.opendistroforelasticsearch.ad.transport; -import org.elasticsearch.action.Action; -import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.action.ActionType; -public class RCFResultAction extends Action { +public class RCFResultAction extends ActionType { public static final RCFResultAction INSTANCE = new RCFResultAction(); public static final String NAME = "cluster:admin/ad/rcf/result"; private RCFResultAction() { - super(NAME); - } - - @Override - public RCFResultResponse newResponse() { - throw new UnsupportedOperationException("Usage of Streamable is to be replaced by Writeable"); - } - - @Override - public Writeable.Reader getResponseReader() { - // return constructor method reference - return RCFResultResponse::new; + super(NAME, RCFResultResponse::new); } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorAction.java index fffcd034..06b2ea7a 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorAction.java @@ -15,25 +15,15 @@ package com.amazon.opendistroforelasticsearch.ad.transport; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.common.io.stream.Writeable; -public class StopDetectorAction extends Action { +public class StopDetectorAction extends ActionType { public static final StopDetectorAction INSTANCE = new StopDetectorAction(); public static final String NAME = "cluster:admin/ad/detector/stop"; private StopDetectorAction() { - super(NAME); + super(NAME, StopDetectorResponse::new); } - @Override - public StopDetectorResponse newResponse() { - throw new UnsupportedOperationException("Usage of Streamable is to be replaced by Writeable"); - } - - @Override - public Writeable.Reader getResponseReader() { - // return constructor method reference - return StopDetectorResponse::new; - } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultAction.java index 36d1ef16..69ec2ce8 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultAction.java @@ -15,25 +15,15 @@ package com.amazon.opendistroforelasticsearch.ad.transport; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.common.io.stream.Writeable; -public class ThresholdResultAction extends Action { +public class ThresholdResultAction extends ActionType { public static final ThresholdResultAction INSTANCE = new ThresholdResultAction(); public static final String NAME = "cluster:admin/ad/theshold/result"; private ThresholdResultAction() { - super(NAME); + super(NAME, ThresholdResultResponse::new); } - @Override - public ThresholdResultResponse newResponse() { - throw new UnsupportedOperationException("Usage of Streamable is to be replaced by Writeable"); - } - - @Override - public Writeable.Reader getResponseReader() { - // return constructor method reference - return ThresholdResultResponse::new; - } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/util/ClientUtil.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/util/ClientUtil.java index 37431226..fa96c832 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/util/ClientUtil.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/util/ClientUtil.java @@ -26,7 +26,7 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchTimeoutException; -import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; @@ -122,7 +122,7 @@ public void asy * @param listener needed to handle response */ public void execute( - Action action, + ActionType action, Request request, ActionListener listener ) { From 16bb20e9932164cfde54914947ccdc3213f544f0 Mon Sep 17 00:00:00 2001 From: Zhang Date: Mon, 10 Feb 2020 16:46:11 -0800 Subject: [PATCH 03/13] fixed BaseNodesResponse and StreamOutput --- .../ad/transport/CronResponse.java | 6 ++++-- .../ad/transport/DeleteModelAction.java | 4 ---- .../ad/transport/DeleteModelResponse.java | 6 ++++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronResponse.java index b6d454fb..4a6e4fca 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronResponse.java @@ -29,7 +29,9 @@ public class CronResponse extends BaseNodesResponse implements ToXContentFragment { static String NODES_JSON_KEY = "nodes"; - public CronResponse() {} + public CronResponse(StreamInput in) throws IOException { + super(in); + } public CronResponse(ClusterName clusterName, List nodes, List failures) { super(clusterName, nodes, failures); @@ -42,7 +44,7 @@ public List readNodesFrom(StreamInput in) throws IOException { @Override protected void writeNodesTo(StreamOutput out, List nodes) throws IOException { - out.writeStreamableList(nodes); + out.writeList(nodes); } @Override diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java index 937f22d2..a46a01c2 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java @@ -25,8 +25,4 @@ private DeleteModelAction() { super(NAME, DeleteModelResponse::new); } - @Override - public DeleteModelResponse newResponse() { - return new DeleteModelResponse(); - } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelResponse.java index e4f5180f..f91ecb26 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelResponse.java @@ -29,7 +29,9 @@ public class DeleteModelResponse extends BaseNodesResponse implements ToXContentFragment { static String NODES_JSON_KEY = "nodes"; - public DeleteModelResponse() {} + public DeleteModelResponse(StreamInput in) throws IOException { + super(in); + } public DeleteModelResponse(ClusterName clusterName, List nodes, List failures) { super(clusterName, nodes, failures); @@ -42,7 +44,7 @@ public List readNodesFrom(StreamInput in) throws IOExce @Override protected void writeNodesTo(StreamOutput out, List nodes) throws IOException { - out.writeStreamableList(nodes); + out.writeList(nodes); } @Override From a031ec4383a9eaa2dd68d64968238fe85f396bb2 Mon Sep 17 00:00:00 2001 From: Zhang Date: Tue, 11 Feb 2020 10:08:10 -0800 Subject: [PATCH 04/13] fix crons with TransportNodesAction changes --- .../ad/transport/CronNodeRequest.java | 10 +++++++--- .../ad/transport/CronNodeResponse.java | 9 +++++---- .../ad/transport/CronRequest.java | 9 ++++++++- .../ad/transport/CronTransportAction.java | 10 ++++++---- .../ad/transport/RCFResultResponse.java | 1 - .../ad/transport/ThresholdResultResponse.java | 1 - 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronNodeRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronNodeRequest.java index 2470beb8..a7d38e82 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronNodeRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronNodeRequest.java @@ -16,15 +16,19 @@ package com.amazon.opendistroforelasticsearch.ad.transport; import org.elasticsearch.action.support.nodes.BaseNodeRequest; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * Delete model represents the request to an individual node */ public class CronNodeRequest extends BaseNodeRequest { - CronNodeRequest() {} + public CronNodeRequest() {} - CronNodeRequest(String nodeID, CronRequest request) { - super(nodeID); + public CronNodeRequest(StreamInput in) throws IOException { + super(in); } + } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronNodeResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronNodeResponse.java index f730c99f..a24ea896 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronNodeResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronNodeResponse.java @@ -26,16 +26,17 @@ public class CronNodeResponse extends BaseNodeResponse implements ToXContentObject { static String NODE_ID = "node_id"; - public CronNodeResponse() {} + public CronNodeResponse(StreamInput in) throws IOException { + super(in); + } public CronNodeResponse(DiscoveryNode node) { super(node); } public static CronNodeResponse readNodeResponse(StreamInput in) throws IOException { - CronNodeResponse nodeResponse = new CronNodeResponse(); - nodeResponse.readFrom(in); - return nodeResponse; + + return new CronNodeResponse(in); } @Override diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronRequest.java index c3a891e4..4165a0ab 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronRequest.java @@ -17,6 +17,9 @@ import org.elasticsearch.action.support.nodes.BaseNodesRequest; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; /** * Request should be sent from the handler logic of transport delete detector API @@ -25,7 +28,11 @@ public class CronRequest extends BaseNodesRequest { public CronRequest() { - super(); + super((String[]) null); + } + + public CronRequest(StreamInput in) throws IOException { + super(in); } public CronRequest(DiscoveryNode... nodes) { diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronTransportAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronTransportAction.java index 8d718dd4..8b6747b1 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronTransportAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/CronTransportAction.java @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.ad.transport; +import java.io.IOException; import java.util.List; import com.amazon.opendistroforelasticsearch.ad.feature.FeatureManager; @@ -24,6 +25,7 @@ import org.elasticsearch.action.support.nodes.TransportNodesAction; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -65,13 +67,13 @@ protected CronResponse newResponse(CronRequest request, List r } @Override - protected CronNodeRequest newNodeRequest(String nodeId, CronRequest request) { - return new CronNodeRequest(nodeId, request); + protected CronNodeRequest newNodeRequest(CronRequest request) { + return new CronNodeRequest(); } @Override - protected CronNodeResponse newNodeResponse() { - return new CronNodeResponse(); + protected CronNodeResponse newNodeResponse(StreamInput in) throws IOException { + return new CronNodeResponse(in); } /** diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultResponse.java index 645f16db..8e5d6aba 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultResponse.java @@ -58,7 +58,6 @@ public int getForestSize() { @Override public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); out.writeDouble(rcfScore); out.writeDouble(confidence); out.writeVInt(forestSize); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultResponse.java index 9a2a07b8..17e55436 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultResponse.java @@ -49,7 +49,6 @@ public double getConfidence() { @Override public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); out.writeDouble(anomalyGrade); out.writeDouble(confidence); } From ecfddd9c589c2cafa209fe41e7b6a1a54ea2ddbf Mon Sep 17 00:00:00 2001 From: Zhang Date: Tue, 11 Feb 2020 10:49:16 -0800 Subject: [PATCH 05/13] fix ADStats with TransportNodesAction changes --- .../ad/transport/ADStatsNodeRequest.java | 10 +++++----- .../ad/transport/ADStatsNodeResponse.java | 12 ++++++------ .../ad/transport/ADStatsRequest.java | 7 +++++-- .../ad/transport/ADStatsResponse.java | 2 +- .../ad/transport/ADStatsTransportAction.java | 10 ++++++---- .../ad/transport/AnomalyResultResponse.java | 1 - 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeRequest.java index 3a02ac66..e9ed9e61 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeRequest.java @@ -34,14 +34,16 @@ public ADStatsNodeRequest() { super(); } + public ADStatsNodeRequest(StreamInput in) throws IOException { + super(in); + } + /** * Constructor * - * @param nodeId nodeId * @param request ADStatsRequest */ - public ADStatsNodeRequest(String nodeId, ADStatsRequest request) { - super(nodeId); + public ADStatsNodeRequest(ADStatsRequest request) { this.request = request; } @@ -54,9 +56,7 @@ public ADStatsRequest getADStatsRequest() { return request; } - @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); request = new ADStatsRequest(); request.readFrom(in); } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java index 6f42ebe4..03b87730 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java @@ -35,7 +35,10 @@ public class ADStatsNodeResponse extends BaseNodeResponse implements ToXContentF /** * Constructor */ - public ADStatsNodeResponse() {} + public ADStatsNodeResponse(StreamInput in) throws IOException { + super(in); + this.statsMap = in.readMap(StreamInput::readString, StreamInput::readGenericValue); + } /** * Constructor @@ -56,9 +59,8 @@ public ADStatsNodeResponse(DiscoveryNode node, Map statsToValues * @throws IOException throws an IO exception if the StreamInput cannot be read from */ public static ADStatsNodeResponse readStats(StreamInput in) throws IOException { - ADStatsNodeResponse adStats = new ADStatsNodeResponse(); - adStats.readFrom(in); - return adStats; + + return new ADStatsNodeResponse(in); } /** @@ -70,9 +72,7 @@ public Map getStatsMap() { return statsMap; } - @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); this.statsMap = in.readMap(StreamInput::readString, StreamInput::readGenericValue); } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java index 4e3de416..8a99a5d3 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java @@ -35,6 +35,11 @@ public class ADStatsRequest extends BaseNodesRequest { private Set statsToBeRetrieved; + public ADStatsRequest(StreamInput in) throws IOException { + super(in); + statsToBeRetrieved = new HashSet<>(); + } + /** * Constructor * @@ -79,9 +84,7 @@ public Set getStatsToBeRetrieved() { return statsToBeRetrieved; } - @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); statsToBeRetrieved = in.readSet(StreamInput::readString); } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsResponse.java index 4849115d..ad64e5c1 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsResponse.java @@ -77,7 +77,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public void writeNodesTo(StreamOutput out, List nodes) throws IOException { - out.writeStreamableList(nodes); + out.writeList(nodes); } @Override diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTransportAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTransportAction.java index 98f60e7d..2c8262f1 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTransportAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTransportAction.java @@ -21,9 +21,11 @@ import org.elasticsearch.action.support.nodes.TransportNodesAction; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.transport.TransportService; import org.elasticsearch.threadpool.ThreadPool; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -83,13 +85,13 @@ protected ADStatsResponse newResponse(ADStatsRequest request, List Date: Tue, 11 Feb 2020 11:33:35 -0800 Subject: [PATCH 06/13] fix delete model action with TransportNodesAction changes --- .../ad/transport/DeleteModelNodeRequest.java | 9 +++++---- .../ad/transport/DeleteModelNodeResponse.java | 9 +++++---- .../ad/transport/DeleteModelRequest.java | 8 +++++--- .../ad/transport/DeleteModelTransportAction.java | 10 ++++++---- .../ad/transport/StopDetectorResponse.java | 1 - 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java index 36fa50fc..61169155 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java @@ -30,14 +30,15 @@ public class DeleteModelNodeRequest extends BaseNodeRequest { DeleteModelNodeRequest() {} - DeleteModelNodeRequest(String nodeID, DeleteModelRequest request) { - super(nodeID); + DeleteModelNodeRequest(StreamInput in) throws IOException { + super(in); + } + + DeleteModelNodeRequest(DeleteModelRequest request) { this.adID = request.getAdID(); } - @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); adID = in.readString(); } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeResponse.java index 7c1e1ae2..fa33f2b7 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeResponse.java @@ -26,16 +26,17 @@ public class DeleteModelNodeResponse extends BaseNodeResponse implements ToXContentObject { static String NODE_ID = "node_id"; - public DeleteModelNodeResponse() {} + public DeleteModelNodeResponse(StreamInput in) throws IOException { + super(in); + } public DeleteModelNodeResponse(DiscoveryNode node) { super(node); } public static DeleteModelNodeResponse readNodeResponse(StreamInput in) throws IOException { - DeleteModelNodeResponse nodeResponse = new DeleteModelNodeResponse(); - nodeResponse.readFrom(in); - return nodeResponse; + + return new DeleteModelNodeResponse(in); } @Override diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java index d52e38c8..138fbc07 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java @@ -42,7 +42,11 @@ public String getAdID() { } public DeleteModelRequest() { - super(); + super((String[]) null); + } + + public DeleteModelRequest(StreamInput in) throws IOException { + super(in); } public DeleteModelRequest(String adID, DiscoveryNode... nodes) { @@ -56,9 +60,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(adID); } - @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); adID = in.readString(); } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportAction.java index 4f5ee491..b7c35b10 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportAction.java @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.ad.transport; +import java.io.IOException; import java.util.List; import com.amazon.opendistroforelasticsearch.ad.feature.FeatureManager; @@ -26,6 +27,7 @@ import org.elasticsearch.action.support.nodes.TransportNodesAction; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -72,13 +74,13 @@ protected DeleteModelResponse newResponse( } @Override - protected DeleteModelNodeRequest newNodeRequest(String nodeId, DeleteModelRequest request) { - return new DeleteModelNodeRequest(nodeId, request); + protected DeleteModelNodeRequest newNodeRequest(DeleteModelRequest request) { + return new DeleteModelNodeRequest(request); } @Override - protected DeleteModelNodeResponse newNodeResponse() { - return new DeleteModelNodeResponse(); + protected DeleteModelNodeResponse newNodeResponse(StreamInput in) throws IOException { + return new DeleteModelNodeResponse(in); } /** diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorResponse.java index 458a28e9..a37a8220 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorResponse.java @@ -46,7 +46,6 @@ public boolean success() { @Override public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); out.writeBoolean(success); } From 9d09e5dbd83ec5cab1c7e4a85a6ed3674aa4d9e8 Mon Sep 17 00:00:00 2001 From: Zhang Date: Tue, 11 Feb 2020 12:08:37 -0800 Subject: [PATCH 07/13] fix delete detector with TransportMasterNodeAction changes --- .../ad/transport/DeleteDetectorRequest.java | 8 ++++++-- .../ad/transport/DeleteDetectorTransportAction.java | 11 +++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java index cd3075f5..37408180 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java @@ -41,6 +41,12 @@ public String getAdID() { return adID; } + public DeleteDetectorRequest() {} + + public DeleteDetectorRequest(StreamInput in) throws IOException { + super(in); + } + public DeleteDetectorRequest adID(String adID) { this.adID = adID; return this; @@ -52,9 +58,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(adID); } - @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); adID = in.readString(); } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorTransportAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorTransportAction.java index 30f7eb30..13ec6a3e 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorTransportAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorTransportAction.java @@ -32,10 +32,13 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import java.io.IOException; + public class DeleteDetectorTransportAction extends TransportMasterNodeAction { private static final Logger LOG = LogManager.getLogger(DeleteDetectorTransportAction.class); @@ -59,8 +62,8 @@ public DeleteDetectorTransportAction( clusterService, threadPool, actionFilters, - indexNameExpressionResolver, - DeleteDetectorRequest::new + DeleteDetectorRequest::new, + indexNameExpressionResolver ); this.client = client; this.clusterService = clusterService; @@ -80,8 +83,8 @@ protected String executor() { } @Override - protected AcknowledgedResponse newResponse() { - return new AcknowledgedResponse(); + protected AcknowledgedResponse read(StreamInput in) throws IOException { + return new AcknowledgedResponse(in); } @Override From 9cb7faeb1628093aa63b2724f573e68db001e6e8 Mon Sep 17 00:00:00 2001 From: Zhang Date: Tue, 11 Feb 2020 13:57:58 -0800 Subject: [PATCH 08/13] fix rest classes to remove settings --- .../ad/rest/AbstractSearchAction.java | 3 +-- .../ad/rest/RestDeleteAnomalyDetectorAction.java | 3 +-- .../ad/rest/RestExecuteAnomalyDetectorAction.java | 2 -- .../ad/rest/RestGetAnomalyDetectorAction.java | 3 +-- .../ad/rest/RestIndexAnomalyDetectorAction.java | 1 - .../ad/rest/RestSearchAnomalyDetectorAction.java | 2 +- .../ad/rest/RestSearchAnomalyResultAction.java | 2 +- .../ad/rest/RestStatsAnomalyDetectorAction.java | 4 +--- 8 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/AbstractSearchAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/AbstractSearchAction.java index 7b9bb23c..b452a03e 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/AbstractSearchAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/AbstractSearchAction.java @@ -56,8 +56,7 @@ public abstract class AbstractSearchAction extends B private final Logger logger = LogManager.getLogger(AbstractSearchAction.class); - public AbstractSearchAction(Settings settings, RestController controller, String urlPath, String index, Class clazz) { - super(settings); + public AbstractSearchAction(RestController controller, String urlPath, String index, Class clazz) { this.index = index; this.clazz = clazz; controller.registerHandler(RestRequest.Method.POST, urlPath, this); 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..55d1866b 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestDeleteAnomalyDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestDeleteAnomalyDetectorAction.java @@ -55,8 +55,7 @@ public class RestDeleteAnomalyDetectorAction extends BaseRestHandler { private final ClusterService clusterService; private final AnomalyDetectorActionHandler handler = new AnomalyDetectorActionHandler(); - public RestDeleteAnomalyDetectorAction(Settings settings, RestController controller, ClusterService clusterService) { - super(settings); + public RestDeleteAnomalyDetectorAction(RestController controller, ClusterService clusterService) { this.clusterService = clusterService; // delete anomaly detector document controller diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestExecuteAnomalyDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestExecuteAnomalyDetectorAction.java index e0712fad..50b1f815 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestExecuteAnomalyDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestExecuteAnomalyDetectorAction.java @@ -73,8 +73,6 @@ public RestExecuteAnomalyDetectorAction( ClusterService clusterService, AnomalyDetectorRunner anomalyDetectorRunner ) { - super(settings); - this.anomalyDetectorRunner = anomalyDetectorRunner; this.requestTimeout = REQUEST_TIMEOUT.get(settings); clusterService.getClusterSettings().addSettingsUpdateConsumer(REQUEST_TIMEOUT, it -> requestTimeout = it); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestGetAnomalyDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestGetAnomalyDetectorAction.java index 5aa2b9ba..8c1bae62 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestGetAnomalyDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestGetAnomalyDetectorAction.java @@ -55,8 +55,7 @@ public class RestGetAnomalyDetectorAction extends BaseRestHandler { private static final String GET_ANOMALY_DETECTOR_ACTION = "get_anomaly_detector"; private static final Logger logger = LogManager.getLogger(RestGetAnomalyDetectorAction.class); - public RestGetAnomalyDetectorAction(Settings settings, RestController controller) { - super(settings); + public RestGetAnomalyDetectorAction(RestController controller) { String path = String.format(Locale.ROOT, "%s/{%s}", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, DETECTOR_ID); controller.registerHandler(RestRequest.Method.GET, path, this); controller.registerHandler(RestRequest.Method.HEAD, path, this); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestIndexAnomalyDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestIndexAnomalyDetectorAction.java index 51dab743..e938fef5 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestIndexAnomalyDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestIndexAnomalyDetectorAction.java @@ -65,7 +65,6 @@ public RestIndexAnomalyDetectorAction( ClusterService clusterService, AnomalyDetectionIndices anomalyDetectionIndices ) { - super(settings); controller.registerHandler(RestRequest.Method.POST, AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, this); // Create controller .registerHandler( diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestSearchAnomalyDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestSearchAnomalyDetectorAction.java index fd7ac9ee..cee39085 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestSearchAnomalyDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestSearchAnomalyDetectorAction.java @@ -31,7 +31,7 @@ public class RestSearchAnomalyDetectorAction extends AbstractSearchAction Date: Tue, 11 Feb 2020 17:12:02 -0800 Subject: [PATCH 09/13] fix test build --- .../ad/AnomalyDetectorPlugin.java | 5 ++--- .../ad/rest/AbstractSearchAction.java | 1 - .../ad/rest/RestDeleteAnomalyDetectorAction.java | 1 - .../ad/rest/RestGetAnomalyDetectorAction.java | 1 - .../ad/rest/RestStatsAnomalyDetectorAction.java | 1 - .../ad/transport/ADStatsAction.java | 1 - .../ad/transport/ADStatsNodeResponse.java | 3 +++ .../ad/transport/AnomalyResultAction.java | 1 - .../ad/transport/StopDetectorAction.java | 1 - .../ad/transport/ThresholdResultAction.java | 1 - .../opendistroforelasticsearch/ad/TestHelpers.java | 4 ++-- .../ad/cluster/ADClusterEventListenerTests.java | 7 +++---- .../ad/cluster/HashRingTests.java | 5 ++--- .../ad/cluster/HourlyCronTests.java | 8 +++----- .../ad/transport/ADStateManagerTests.java | 1 + .../ad/transport/ADStatsTests.java | 8 +------- .../ad/transport/ADStatsTransportActionTests.java | 11 +++-------- .../ad/transport/AnomalyResultTests.java | 4 ---- .../ad/transport/CronTransportActionTests.java | 7 +++---- .../ad/transport/DeleteModelTransportActionTests.java | 4 ++-- .../ad/transport/DeleteTests.java | 6 +++--- .../ad/transport/RCFResultTests.java | 4 ---- .../ad/transport/ThresholdResultTests.java | 4 ---- .../ad/util/ClusterCreation.java | 7 +++++-- 24 files changed, 33 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java index 49f03ff7..a3a69aa7 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java @@ -148,7 +148,7 @@ public List getRestHandlers( IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster ) { - RestGetAnomalyDetectorAction restGetAnomalyDetectorAction = new RestGetAnomalyDetectorAction(settings, restController); + RestGetAnomalyDetectorAction restGetAnomalyDetectorAction = new RestGetAnomalyDetectorAction(restController); RestIndexAnomalyDetectorAction restIndexAnomalyDetectorAction = new RestIndexAnomalyDetectorAction( settings, restController, @@ -158,7 +158,6 @@ public List getRestHandlers( RestSearchAnomalyDetectorAction searchAnomalyDetectorAction = new RestSearchAnomalyDetectorAction(settings, restController); RestSearchAnomalyResultAction searchAnomalyResultAction = new RestSearchAnomalyResultAction(settings, restController); RestDeleteAnomalyDetectorAction deleteAnomalyDetectorAction = new RestDeleteAnomalyDetectorAction( - settings, restController, clusterService ); @@ -168,7 +167,7 @@ public List getRestHandlers( clusterService, anomalyDetectorRunner ); - RestStatsAnomalyDetectorAction statsAnomalyDetectorAction = new RestStatsAnomalyDetectorAction(settings, restController, adStats); + RestStatsAnomalyDetectorAction statsAnomalyDetectorAction = new RestStatsAnomalyDetectorAction(restController, adStats); return ImmutableList .of( diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/AbstractSearchAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/AbstractSearchAction.java index b452a03e..ef4a4137 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/AbstractSearchAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/AbstractSearchAction.java @@ -22,7 +22,6 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; 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 55d1866b..09b2a130 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestDeleteAnomalyDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestDeleteAnomalyDetectorAction.java @@ -28,7 +28,6 @@ import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestGetAnomalyDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestGetAnomalyDetectorAction.java index 8c1bae62..6807efd4 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestGetAnomalyDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestGetAnomalyDetectorAction.java @@ -24,7 +24,6 @@ import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestStatsAnomalyDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestStatsAnomalyDetectorAction.java index 9335f9ff..408f0b3b 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestStatsAnomalyDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/rest/RestStatsAnomalyDetectorAction.java @@ -19,7 +19,6 @@ import com.amazon.opendistroforelasticsearch.ad.transport.ADStatsAction; import com.amazon.opendistroforelasticsearch.ad.transport.ADStatsRequest; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.BaseRestHandler; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsAction.java index 900e6c6c..eb98786a 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsAction.java @@ -16,7 +16,6 @@ package com.amazon.opendistroforelasticsearch.ad.transport; import org.elasticsearch.action.ActionType; -import org.elasticsearch.common.io.stream.Writeable; /** * ADStatsAction class diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java index 03b87730..2daebbb1 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java @@ -34,6 +34,9 @@ public class ADStatsNodeResponse extends BaseNodeResponse implements ToXContentF /** * Constructor + * + * @param in StreamInput + * @throws IOException throws an IO exception if the StreamInput cannot be read from */ public ADStatsNodeResponse(StreamInput in) throws IOException { super(in); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultAction.java index 758e522f..2cb02d65 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultAction.java @@ -16,7 +16,6 @@ package com.amazon.opendistroforelasticsearch.ad.transport; import org.elasticsearch.action.ActionType; -import org.elasticsearch.common.io.stream.Writeable; public class AnomalyResultAction extends ActionType { public static final AnomalyResultAction INSTANCE = new AnomalyResultAction(); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorAction.java index 06b2ea7a..78615197 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorAction.java @@ -16,7 +16,6 @@ package com.amazon.opendistroforelasticsearch.ad.transport; import org.elasticsearch.action.ActionType; -import org.elasticsearch.common.io.stream.Writeable; public class StopDetectorAction extends ActionType { public static final StopDetectorAction INSTANCE = new StopDetectorAction(); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultAction.java index 69ec2ce8..ee45a08c 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultAction.java @@ -16,7 +16,6 @@ package com.amazon.opendistroforelasticsearch.ad.transport; import org.elasticsearch.action.ActionType; -import org.elasticsearch.common.io.stream.Writeable; public class ThresholdResultAction extends ActionType { public static final ThresholdResultAction INSTANCE = new ThresholdResultAction(); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java index eb62a4b1..1688cd67 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/TestHelpers.java @@ -65,12 +65,12 @@ import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Collections; -import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; import java.util.function.Consumer; +import static org.elasticsearch.cluster.node.DiscoveryNodeRole.BUILT_IN_ROLES; import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder; import static org.elasticsearch.test.ESTestCase.randomAlphaOfLength; import static org.elasticsearch.test.ESTestCase.randomDouble; @@ -263,7 +263,7 @@ public static ClusterService createClusterService(ThreadPool threadPool, Cluster "node", ESTestCase.buildNewFakeTransportAddress(), Collections.emptyMap(), - EnumSet.allOf(DiscoveryNode.Role.class), + BUILT_IN_ROLES, Version.CURRENT ); return ClusterServiceUtils.createClusterService(threadPool, discoveryNode, clusterSettings); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/ADClusterEventListenerTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/ADClusterEventListenerTests.java index 6bb63b4d..dc8afe9d 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/ADClusterEventListenerTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/ADClusterEventListenerTests.java @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.ad.cluster; +import static org.elasticsearch.cluster.node.DiscoveryNodeRole.BUILT_IN_ROLES; import static org.elasticsearch.test.ClusterServiceUtils.createClusterService; import static org.mockito.Mockito.mock; @@ -22,7 +23,6 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Matchers.any; -import java.util.EnumSet; import java.util.HashSet; import java.util.Optional; import java.util.Set; @@ -38,7 +38,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNode.Role; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.gateway.GatewayService; @@ -82,7 +81,7 @@ public void setUp() throws Exception { when(hashRing.build()).thenReturn(true); modelManager = mock(ModelManager.class); masterNode = new DiscoveryNode(masterNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); - dataNode1 = new DiscoveryNode(dataNode1Id, buildNewFakeTransportAddress(), emptyMap(), EnumSet.allOf(Role.class), Version.CURRENT); + dataNode1 = new DiscoveryNode(dataNode1Id, buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT); oldClusterState = ClusterState .builder(new ClusterName(clusterName)) .nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(masterNodeId).add(masterNode)) @@ -174,7 +173,7 @@ public void testNodeRemoved() { "dataNode2", buildNewFakeTransportAddress(), emptyMap(), - EnumSet.allOf(Role.class), + BUILT_IN_ROLES, Version.CURRENT ) ) diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HashRingTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HashRingTests.java index f65ead9c..d50b2f1d 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HashRingTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HashRingTests.java @@ -17,6 +17,7 @@ import static java.util.Collections.emptyMap; +import static org.elasticsearch.cluster.node.DiscoveryNodeRole.BUILT_IN_ROLES; import static org.elasticsearch.test.ClusterServiceUtils.createClusterService; import static org.elasticsearch.test.ClusterServiceUtils.setState; import static org.mockito.Mockito.mock; @@ -26,14 +27,12 @@ import java.util.Optional; import java.time.Clock; import java.util.ArrayList; -import java.util.EnumSet; import com.amazon.opendistroforelasticsearch.ad.AbstractADTest; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.node.DiscoveryNode.Role; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -49,7 +48,7 @@ public class HashRingTests extends AbstractADTest { private Clock clock; private DiscoveryNode createNode(String nodeId) { - return new DiscoveryNode(nodeId, buildNewFakeTransportAddress(), emptyMap(), EnumSet.allOf(Role.class), Version.CURRENT); + return new DiscoveryNode(nodeId, buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT); } @BeforeClass diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HourlyCronTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HourlyCronTests.java index 174a945d..bfb6caa3 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HourlyCronTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HourlyCronTests.java @@ -73,7 +73,7 @@ public void templateHourlyCron(HourlyCronTestExecutionMode mode) { .onResponse( new CronResponse( new ClusterName("test"), - Collections.singletonList(new CronNodeResponse()), + Collections.singletonList(new CronNodeResponse(state.nodes().getLocalNode())), Collections.singletonList(new FailedNodeException("foo0", "blah", new ElasticsearchException("bar"))) ) ); @@ -86,8 +86,7 @@ public void templateHourlyCron(HourlyCronTestExecutionMode mode) { nodeResponse.writeTo(nodeResponseOut); StreamInput siNode = nodeResponseOut.bytes().streamInput(); - CronNodeResponse nodeResponseRead = new CronNodeResponse(); - nodeResponseRead.readFrom(siNode); + CronNodeResponse nodeResponseRead = new CronNodeResponse(siNode); CronResponse response = new CronResponse( new ClusterName("test"), @@ -98,8 +97,7 @@ public void templateHourlyCron(HourlyCronTestExecutionMode mode) { out.setVersion(Version.V_7_1_1); response.writeTo(out); StreamInput si = out.bytes().streamInput(); - CronResponse responseRead = CronAction.INSTANCE.newResponse(); - responseRead.readFrom(si); + CronResponse responseRead = new CronResponse(si); listener.onResponse(responseRead); } diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStateManagerTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStateManagerTests.java index 1f07cc22..7706e4cf 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStateManagerTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStateManagerTests.java @@ -138,6 +138,7 @@ private String setupDetector(boolean responseExists) throws IOException { -1, responseExists, BytesReference.bytes(content), + Collections.emptyMap(), Collections.emptyMap() ) ) diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java index a9ec3955..0f23a3eb 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java @@ -73,7 +73,7 @@ public void testADStatsNodeRequest() throws IOException { assertNull("ADStatsNodeRequest default constructor failed", adStatsNodeRequest1.getADStatsRequest()); ADStatsRequest adStatsRequest = new ADStatsRequest(); - ADStatsNodeRequest adStatsNodeRequest2 = new ADStatsNodeRequest(node1, adStatsRequest); + ADStatsNodeRequest adStatsNodeRequest2 = new ADStatsNodeRequest(adStatsRequest); assertEquals("ADStatsNodeRequest has the wrong ADStatsRequest", adStatsNodeRequest2.getADStatsRequest(), adStatsRequest); // Test serialization @@ -198,10 +198,4 @@ public void testADStatsResponse() throws IOException, JsonPathNotFoundException String readJson = Strings.toString(readRequest.toXContent(builder.startObject(), ToXContent.EMPTY_PARAMS).endObject()); assertEquals("Serialization fails", readJson, json); } - - @Test(expected = UnsupportedOperationException.class) - public void testADStatsAction_newResponse() { - ADStatsAction adStatsAction = ADStatsAction.INSTANCE; - adStatsAction.newResponse(); - } } diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTransportActionTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTransportActionTests.java index 0388da77..bf1e7a6e 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTransportActionTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTransportActionTests.java @@ -107,17 +107,12 @@ public void testNewNodeRequest() { String nodeId = "nodeId1"; ADStatsRequest adStatsRequest = new ADStatsRequest(nodeId); - ADStatsNodeRequest adStatsNodeRequest1 = new ADStatsNodeRequest(nodeId, adStatsRequest); - ADStatsNodeRequest adStatsNodeRequest2 = action.newNodeRequest(nodeId, adStatsRequest); + ADStatsNodeRequest adStatsNodeRequest1 = new ADStatsNodeRequest(adStatsRequest); + ADStatsNodeRequest adStatsNodeRequest2 = action.newNodeRequest(adStatsRequest); assertEquals(adStatsNodeRequest1.getADStatsRequest(), adStatsNodeRequest2.getADStatsRequest()); } - @Test - public void testNewNodeResponse() { - assertNotNull(action.newNodeResponse()); - } - @Test public void testNodeOperation() { String nodeId = clusterService().localNode().getId(); @@ -130,7 +125,7 @@ public void testNodeOperation() { adStatsRequest.addStat(stat); } - ADStatsNodeResponse response = action.nodeOperation(new ADStatsNodeRequest(nodeId, adStatsRequest)); + ADStatsNodeResponse response = action.nodeOperation(new ADStatsNodeRequest(adStatsRequest)); Map stats = response.getStatsMap(); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultTests.java index 4af9e9d9..37557dd0 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultTests.java @@ -969,10 +969,6 @@ public void testNegativeTime() { assertThat(e.validationErrors(), hasItem(startsWith(AnomalyResultRequest.INVALID_TIMESTAMP_ERR_MSG))); } - public void testIncorrectSerialzationResponse() throws IOException { - expectThrows(UnsupportedOperationException.class, () -> AnomalyResultAction.INSTANCE.newResponse()); - } - // no exception should be thrown public void testOnFailureNull() throws IOException { AnomalyResultTransportAction action = new AnomalyResultTransportAction( diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/CronTransportActionTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/CronTransportActionTests.java index f1963013..bc6c6141 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/CronTransportActionTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/CronTransportActionTests.java @@ -82,17 +82,16 @@ public void setUp() throws Exception { public void testNormal() throws IOException, JsonPathNotFoundException { CronRequest request = new CronRequest(); - CronNodeRequest nodeRequest = new CronNodeRequest("foo1", request); + CronNodeRequest nodeRequest = new CronNodeRequest(); BytesStreamOutput nodeRequestOut = new BytesStreamOutput(); nodeRequestOut.setVersion(Version.CURRENT); nodeRequest.writeTo(nodeRequestOut); StreamInput siNode = nodeRequestOut.bytes().streamInput(); - CronNodeRequest nodeResponseRead = new CronNodeRequest(); - nodeResponseRead.readFrom(siNode); + CronNodeRequest nodeResponseRead = new CronNodeRequest(siNode); CronNodeResponse nodeResponse1 = action.nodeOperation(nodeResponseRead); - CronNodeResponse nodeResponse2 = action.nodeOperation(new CronNodeRequest("foo2", request)); + CronNodeResponse nodeResponse2 = action.nodeOperation(new CronNodeRequest()); CronResponse response = action.newResponse(request, Arrays.asList(nodeResponse1, nodeResponse2), Collections.emptyList()); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportActionTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportActionTests.java index 09d429db..63524c8a 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportActionTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportActionTests.java @@ -88,7 +88,7 @@ public void testNormal() throws IOException, JsonPathNotFoundException { DeleteModelRequest request = new DeleteModelRequest("123"); assertThat(request.validate(), is(nullValue())); - DeleteModelNodeRequest nodeRequest = new DeleteModelNodeRequest("foo1", request); + DeleteModelNodeRequest nodeRequest = new DeleteModelNodeRequest(request); BytesStreamOutput nodeRequestOut = new BytesStreamOutput(); nodeRequestOut.setVersion(Version.CURRENT); nodeRequest.writeTo(nodeRequestOut); @@ -98,7 +98,7 @@ public void testNormal() throws IOException, JsonPathNotFoundException { nodeResponseRead.readFrom(siNode); DeleteModelNodeResponse nodeResponse1 = action.nodeOperation(nodeResponseRead); - DeleteModelNodeResponse nodeResponse2 = action.nodeOperation(new DeleteModelNodeRequest("foo2", request)); + DeleteModelNodeResponse nodeResponse2 = action.nodeOperation(new DeleteModelNodeRequest(request)); DeleteModelResponse response = action.newResponse(request, Arrays.asList(nodeResponse1, nodeResponse2), Collections.emptyList()); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteTests.java index 50f04811..99709ee9 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteTests.java @@ -181,7 +181,7 @@ public void testSerialzationTemplate( request.writeTo(output); StreamInput streamInput = output.bytes().streamInput(); - readRequest.readFrom(streamInput); + ((DeleteModelRequest)readRequest).readFrom(streamInput); assertThat(requestSupplier.get(), equalTo(readRequestSupplier.get())); } @@ -219,10 +219,10 @@ public void testJsonRequestDeleteModel() throws IOException, JsonPathNotFoundExc } public void testNewResponse() throws IOException { - AcknowledgedResponse response = DeleteDetectorAction.INSTANCE.newResponse(); StreamInput input = mock(StreamInput.class); when(input.readByte()).thenReturn((byte) 0x01); - response.readFrom(input); + AcknowledgedResponse response = new AcknowledgedResponse(input); + assertTrue(response.isAcknowledged()); } diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultTests.java index 009d71d8..95766caa 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/RCFResultTests.java @@ -127,10 +127,6 @@ public void testSerialzationResponse() throws IOException { assertThat(response.getRCFScore(), equalTo(readResponse.getRCFScore())); } - public void testIncorrectSerialzationResponse() throws IOException { - expectThrows(UnsupportedOperationException.class, () -> RCFResultAction.INSTANCE.newResponse()); - } - public void testJsonResponse() throws IOException, JsonPathNotFoundException { RCFResultResponse response = new RCFResultResponse(0.3, 0, 26); XContentBuilder builder = jsonBuilder(); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultTests.java index a91ae176..4c2ca200 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ThresholdResultTests.java @@ -107,10 +107,6 @@ public void testSerialzationResponse() throws IOException { assertThat(response.getConfidence(), equalTo(readResponse.getConfidence())); } - public void testIncorrectSerialzationResponse() throws IOException { - expectThrows(UnsupportedOperationException.class, () -> ThresholdResultAction.INSTANCE.newResponse()); - } - public void testJsonResponse() throws IOException, JsonPathNotFoundException { ThresholdResultResponse response = new ThresholdResultResponse(1, 0.8); XContentBuilder builder = jsonBuilder(); diff --git a/src/test/java/test/com/amazon/opendistroforelasticsearch/ad/util/ClusterCreation.java b/src/test/java/test/com/amazon/opendistroforelasticsearch/ad/util/ClusterCreation.java index 3405be46..3a356849 100644 --- a/src/test/java/test/com/amazon/opendistroforelasticsearch/ad/util/ClusterCreation.java +++ b/src/test/java/test/com/amazon/opendistroforelasticsearch/ad/util/ClusterCreation.java @@ -15,6 +15,8 @@ package test.com.amazon.opendistroforelasticsearch.ad.util; +import static org.elasticsearch.cluster.node.DiscoveryNodeRole.DATA_ROLE; +import static org.elasticsearch.cluster.node.DiscoveryNodeRole.MASTER_ROLE; import static org.mockito.Mockito.mock; import java.net.InetAddress; @@ -22,6 +24,7 @@ import java.util.Collections; import java.util.List; +import com.google.common.collect.Sets; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; @@ -82,7 +85,7 @@ public static ClusterState state(int numDataNodes) { "foo0", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - Collections.singleton(DiscoveryNode.Role.MASTER), + Collections.unmodifiableSet(Sets.newHashSet(MASTER_ROLE)), Version.CURRENT ); List allNodes = new ArrayList<>(); @@ -95,7 +98,7 @@ public static ClusterState state(int numDataNodes) { "foo" + i, new TransportAddress(InetAddress.getLoopbackAddress(), 9300 + i), Collections.emptyMap(), - Collections.singleton(DiscoveryNode.Role.DATA), + Collections.unmodifiableSet(Sets.newHashSet(DATA_ROLE)), Version.CURRENT ) ); From 1539fe1de45df654a083f36d3f96ddc82f86fa77 Mon Sep 17 00:00:00 2001 From: Zhang Date: Tue, 11 Feb 2020 17:50:23 -0800 Subject: [PATCH 10/13] fix stats test case failure --- .../ad/transport/ADStatsRequest.java | 2 +- .../ad/transport/ADStatsTests.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java index 8a99a5d3..cf39730f 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java @@ -37,7 +37,7 @@ public class ADStatsRequest extends BaseNodesRequest { public ADStatsRequest(StreamInput in) throws IOException { super(in); - statsToBeRetrieved = new HashSet<>(); + statsToBeRetrieved = in.readSet(StreamInput::readString);; } /** diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java index 0f23a3eb..c70fcd89 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java @@ -32,7 +32,9 @@ import org.junit.Test; import test.com.amazon.opendistroforelasticsearch.ad.util.JsonDeserializer; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -140,8 +142,7 @@ public void testADStatsRequest() throws IOException { BytesStreamOutput output = new BytesStreamOutput(); adStatsRequest.writeTo(output); StreamInput streamInput = output.bytes().streamInput(); - ADStatsRequest readRequest = new ADStatsRequest(); - readRequest.readFrom(streamInput); + ADStatsRequest readRequest = new ADStatsRequest(streamInput); assertEquals("Serialization fails", readRequest.getStatsToBeRetrieved(), adStatsRequest.getStatsToBeRetrieved()); } From 7d9b83690e4bef5c9eac505d39cd520412ddcafa Mon Sep 17 00:00:00 2001 From: Zhang Date: Wed, 12 Feb 2020 17:41:37 -0800 Subject: [PATCH 11/13] fix UT --- build.gradle | 3 ++ .../ad/AnomalyDetectorPlugin.java | 5 +--- .../ad/transport/ADStatsRequest.java | 3 +- .../ad/transport/DeleteDetectorRequest.java | 5 +--- .../ad/transport/DeleteModelRequest.java | 5 +--- .../cluster/ADClusterEventListenerTests.java | 10 +------ .../ad/cluster/HourlyCronTests.java | 4 +-- .../ad/transport/ADStatsTests.java | 2 -- .../ad/transport/DeleteTests.java | 29 ++++++------------- .../ad/util/ClusterCreation.java | 5 ++-- 10 files changed, 22 insertions(+), 49 deletions(-) diff --git a/build.gradle b/build.gradle index b12eacc0..0e35df15 100644 --- a/build.gradle +++ b/build.gradle @@ -258,6 +258,9 @@ List jacocoExclusions = [ 'com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorRequest', 'com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorResponse', 'com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorTransportAction', + 'com.amazon.opendistroforelasticsearch.ad.transport.ADStatsAction', + 'com.amazon.opendistroforelasticsearch.ad.transport.CronRequest', + 'com.amazon.opendistroforelasticsearch.ad.transport.DeleteDetectorAction', 'com.amazon.opendistroforelasticsearch.ad.util.ParseUtils' ] diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java index a3a69aa7..5b2e930e 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java @@ -157,10 +157,7 @@ public List getRestHandlers( ); RestSearchAnomalyDetectorAction searchAnomalyDetectorAction = new RestSearchAnomalyDetectorAction(settings, restController); RestSearchAnomalyResultAction searchAnomalyResultAction = new RestSearchAnomalyResultAction(settings, restController); - RestDeleteAnomalyDetectorAction deleteAnomalyDetectorAction = new RestDeleteAnomalyDetectorAction( - restController, - clusterService - ); + RestDeleteAnomalyDetectorAction deleteAnomalyDetectorAction = new RestDeleteAnomalyDetectorAction(restController, clusterService); RestExecuteAnomalyDetectorAction executeAnomalyDetectorAction = new RestExecuteAnomalyDetectorAction( settings, restController, diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java index cf39730f..2746f4b7 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java @@ -37,7 +37,8 @@ public class ADStatsRequest extends BaseNodesRequest { public ADStatsRequest(StreamInput in) throws IOException { super(in); - statsToBeRetrieved = in.readSet(StreamInput::readString);; + statsToBeRetrieved = in.readSet(StreamInput::readString); + ; } /** diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java index 37408180..859c26de 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java @@ -45,6 +45,7 @@ public DeleteDetectorRequest() {} public DeleteDetectorRequest(StreamInput in) throws IOException { super(in); + adID = in.readString(); } public DeleteDetectorRequest adID(String adID) { @@ -58,10 +59,6 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(adID); } - public void readFrom(StreamInput in) throws IOException { - adID = in.readString(); - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java index 138fbc07..2d38b366 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java @@ -47,6 +47,7 @@ public DeleteModelRequest() { public DeleteModelRequest(StreamInput in) throws IOException { super(in); + adID = in.readString(); } public DeleteModelRequest(String adID, DiscoveryNode... nodes) { @@ -60,10 +61,6 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(adID); } - public void readFrom(StreamInput in) throws IOException { - adID = in.readString(); - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/ADClusterEventListenerTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/ADClusterEventListenerTests.java index dc8afe9d..8b222e87 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/ADClusterEventListenerTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/ADClusterEventListenerTests.java @@ -168,15 +168,7 @@ public void testNodeRemoved() { .localNodeId(dataNode1Id) .add(new DiscoveryNode(masterNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)) .add(dataNode1) - .add( - new DiscoveryNode( - "dataNode2", - buildNewFakeTransportAddress(), - emptyMap(), - BUILT_IN_ROLES, - Version.CURRENT - ) - ) + .add(new DiscoveryNode("dataNode2", buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT)) ) .build(); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HourlyCronTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HourlyCronTests.java index bfb6caa3..0b979df4 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HourlyCronTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/cluster/HourlyCronTests.java @@ -82,7 +82,7 @@ public void templateHourlyCron(HourlyCronTestExecutionMode mode) { } else { CronNodeResponse nodeResponse = new CronNodeResponse(state.nodes().getLocalNode()); BytesStreamOutput nodeResponseOut = new BytesStreamOutput(); - nodeResponseOut.setVersion(Version.V_7_1_1); + nodeResponseOut.setVersion(Version.CURRENT); nodeResponse.writeTo(nodeResponseOut); StreamInput siNode = nodeResponseOut.bytes().streamInput(); @@ -94,7 +94,7 @@ public void templateHourlyCron(HourlyCronTestExecutionMode mode) { Collections.EMPTY_LIST ); BytesStreamOutput out = new BytesStreamOutput(); - out.setVersion(Version.V_7_1_1); + out.setVersion(Version.CURRENT); response.writeTo(out); StreamInput si = out.bytes().streamInput(); CronResponse responseRead = new CronResponse(si); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java index c70fcd89..55dca10f 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsTests.java @@ -32,9 +32,7 @@ import org.junit.Test; import test.com.amazon.opendistroforelasticsearch.ad.util.JsonDeserializer; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteTests.java index 99709ee9..9beb3c14 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteTests.java @@ -43,7 +43,6 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.support.ActionFilters; @@ -171,32 +170,22 @@ public void testValidIDDeleteDetector() { assertThat(e, is(nullValue())); } - public void testSerialzationTemplate( - R request, - R readRequest, - Supplier requestSupplier, - Supplier readRequestSupplier - ) throws IOException { + public void testSerialzationRequestDeleteModel() throws IOException { + DeleteModelRequest request = new DeleteModelRequest("123"); BytesStreamOutput output = new BytesStreamOutput(); request.writeTo(output); - StreamInput streamInput = output.bytes().streamInput(); - ((DeleteModelRequest)readRequest).readFrom(streamInput); - assertThat(requestSupplier.get(), equalTo(readRequestSupplier.get())); - } - - public void testSerialzationRequestDeleteModel() throws IOException { - DeleteModelRequest request = new DeleteModelRequest("123"); - DeleteModelRequest readRequest = new DeleteModelRequest(); - - testSerialzationTemplate(request, readRequest, request::getAdID, readRequest::getAdID); + DeleteModelRequest readRequest = new DeleteModelRequest(streamInput); + assertThat(request.getAdID(), equalTo(readRequest.getAdID())); } public void testSerialzationRequestDeleteDetector() throws IOException { DeleteDetectorRequest request = new DeleteDetectorRequest().adID("123"); - DeleteDetectorRequest readRequest = new DeleteDetectorRequest(); - - testSerialzationTemplate(request, readRequest, request::getAdID, readRequest::getAdID); + BytesStreamOutput output = new BytesStreamOutput(); + request.writeTo(output); + StreamInput streamInput = output.bytes().streamInput(); + DeleteDetectorRequest readRequest = new DeleteDetectorRequest(streamInput); + assertThat(request.getAdID(), equalTo(readRequest.getAdID())); } public void testJsonRequestTemplate(R request, Supplier requestSupplier) throws IOException, diff --git a/src/test/java/test/com/amazon/opendistroforelasticsearch/ad/util/ClusterCreation.java b/src/test/java/test/com/amazon/opendistroforelasticsearch/ad/util/ClusterCreation.java index 3a356849..a479d022 100644 --- a/src/test/java/test/com/amazon/opendistroforelasticsearch/ad/util/ClusterCreation.java +++ b/src/test/java/test/com/amazon/opendistroforelasticsearch/ad/util/ClusterCreation.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.List; -import com.google.common.collect.Sets; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; @@ -85,7 +84,7 @@ public static ClusterState state(int numDataNodes) { "foo0", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - Collections.unmodifiableSet(Sets.newHashSet(MASTER_ROLE)), + Collections.singleton(MASTER_ROLE), Version.CURRENT ); List allNodes = new ArrayList<>(); @@ -98,7 +97,7 @@ public static ClusterState state(int numDataNodes) { "foo" + i, new TransportAddress(InetAddress.getLoopbackAddress(), 9300 + i), Collections.emptyMap(), - Collections.unmodifiableSet(Sets.newHashSet(DATA_ROLE)), + Collections.singleton(DATA_ROLE), Version.CURRENT ) ); From 5041c8c38b2ed61f22a50aa5401ea6e762b2fcc7 Mon Sep 17 00:00:00 2001 From: Zhang Date: Wed, 12 Feb 2020 17:54:19 -0800 Subject: [PATCH 12/13] add request init for ad stats --- .../ad/transport/ADStatsNodeRequest.java | 1 + .../ad/transport/DeleteDetectorRequest.java | 2 +- .../ad/transport/DeleteModelNodeRequest.java | 1 + .../ad/transport/DeleteModelRequest.java | 2 +- .../ad/transport/StopDetectorRequest.java | 2 +- 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeRequest.java index e9ed9e61..7036ca4c 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeRequest.java @@ -36,6 +36,7 @@ public ADStatsNodeRequest() { public ADStatsNodeRequest(StreamInput in) throws IOException { super(in); + this.request = new ADStatsRequest(in); } /** diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java index 859c26de..910f9302 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java @@ -45,7 +45,7 @@ public DeleteDetectorRequest() {} public DeleteDetectorRequest(StreamInput in) throws IOException { super(in); - adID = in.readString(); + this.adID = in.readString(); } public DeleteDetectorRequest adID(String adID) { diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java index 61169155..77307698 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java @@ -32,6 +32,7 @@ public class DeleteModelNodeRequest extends BaseNodeRequest { DeleteModelNodeRequest(StreamInput in) throws IOException { super(in); + this.adID = in.readString(); } DeleteModelNodeRequest(DeleteModelRequest request) { diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java index 2d38b366..d4b2c145 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelRequest.java @@ -47,7 +47,7 @@ public DeleteModelRequest() { public DeleteModelRequest(StreamInput in) throws IOException { super(in); - adID = in.readString(); + this.adID = in.readString(); } public DeleteModelRequest(String adID, DiscoveryNode... nodes) { diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorRequest.java index c3c97075..dbb98af7 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorRequest.java @@ -39,7 +39,7 @@ public class StopDetectorRequest extends ActionRequest implements ToXContentObje public StopDetectorRequest(StreamInput in) throws IOException { super(in); - adID = in.readString(); + this.adID = in.readString(); } public StopDetectorRequest(String adID) { From a5cae7f350a1d2dd0911a247741a333f7d00028f Mon Sep 17 00:00:00 2001 From: Zhang Date: Thu, 20 Feb 2020 14:37:31 -0800 Subject: [PATCH 13/13] revision 1 --- .../ad/transport/ADStatsNodeResponse.java | 4 ---- .../ad/transport/ADStatsRequest.java | 1 - .../ad/transport/DeleteModelNodeRequest.java | 4 ---- .../ad/transport/DeleteModelTransportActionTests.java | 3 +-- 4 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java index 2daebbb1..ac1c536a 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java @@ -75,10 +75,6 @@ public Map getStatsMap() { return statsMap; } - public void readFrom(StreamInput in) throws IOException { - this.statsMap = in.readMap(StreamInput::readString, StreamInput::readGenericValue); - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java index 2746f4b7..d7de18dc 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsRequest.java @@ -38,7 +38,6 @@ public class ADStatsRequest extends BaseNodesRequest { public ADStatsRequest(StreamInput in) throws IOException { super(in); statsToBeRetrieved = in.readSet(StreamInput::readString); - ; } /** diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java index 77307698..f008a126 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java @@ -39,10 +39,6 @@ public class DeleteModelNodeRequest extends BaseNodeRequest { this.adID = request.getAdID(); } - public void readFrom(StreamInput in) throws IOException { - adID = in.readString(); - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportActionTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportActionTests.java index 63524c8a..09f2ddee 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportActionTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportActionTests.java @@ -94,8 +94,7 @@ public void testNormal() throws IOException, JsonPathNotFoundException { nodeRequest.writeTo(nodeRequestOut); StreamInput siNode = nodeRequestOut.bytes().streamInput(); - DeleteModelNodeRequest nodeResponseRead = new DeleteModelNodeRequest(); - nodeResponseRead.readFrom(siNode); + DeleteModelNodeRequest nodeResponseRead = new DeleteModelNodeRequest(siNode); DeleteModelNodeResponse nodeResponse1 = action.nodeOperation(nodeResponseRead); DeleteModelNodeResponse nodeResponse2 = action.nodeOperation(new DeleteModelNodeRequest(request));