diff --git a/build.gradle b/build.gradle index 22060d4c..0e35df15 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' @@ -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/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/AnomalyDetectorPlugin.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java index 49f03ff7..5b2e930e 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, @@ -157,18 +157,14 @@ public List getRestHandlers( ); RestSearchAnomalyDetectorAction searchAnomalyDetectorAction = new RestSearchAnomalyDetectorAction(settings, restController); RestSearchAnomalyResultAction searchAnomalyResultAction = new RestSearchAnomalyResultAction(settings, restController); - RestDeleteAnomalyDetectorAction deleteAnomalyDetectorAction = new RestDeleteAnomalyDetectorAction( - settings, - restController, - clusterService - ); + RestDeleteAnomalyDetectorAction deleteAnomalyDetectorAction = new RestDeleteAnomalyDetectorAction(restController, clusterService); RestExecuteAnomalyDetectorAction executeAnomalyDetectorAction = new RestExecuteAnomalyDetectorAction( settings, restController, 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 7b9bb23c..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; @@ -56,8 +55,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..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; @@ -55,8 +54,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..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; @@ -55,8 +54,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 { +public class ADStatsAction extends ActionType { public static final ADStatsAction INSTANCE = new ADStatsAction(); public static final String NAME = "cluster:admin/ad_stats_action"; @@ -30,16 +29,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/ADStatsNodeRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeRequest.java index 3a02ac66..7036ca4c 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,17 @@ public ADStatsNodeRequest() { super(); } + public ADStatsNodeRequest(StreamInput in) throws IOException { + super(in); + this.request = new ADStatsRequest(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 +57,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..ac1c536a 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/ADStatsNodeResponse.java @@ -34,8 +34,14 @@ 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() {} + public ADStatsNodeResponse(StreamInput in) throws IOException { + super(in); + this.statsMap = in.readMap(StreamInput::readString, StreamInput::readGenericValue); + } /** * Constructor @@ -56,9 +62,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,12 +75,6 @@ public Map getStatsMap() { return statsMap; } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - 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 4e3de416..d7de18dc 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 = in.readSet(StreamInput::readString); + } + /** * 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 { +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/AnomalyResultResponse.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultResponse.java index cf027dd4..2132b0c7 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultResponse.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/AnomalyResultResponse.java @@ -74,7 +74,6 @@ public double getConfidence() { @Override public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); out.writeDouble(anomalyGrade); out.writeDouble(confidence); out.writeVInt(features.size()); 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/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/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/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/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/DeleteDetectorRequest.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteDetectorRequest.java index cd3075f5..910f9302 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,13 @@ public String getAdID() { return adID; } + public DeleteDetectorRequest() {} + + public DeleteDetectorRequest(StreamInput in) throws IOException { + super(in); + this.adID = in.readString(); + } + public DeleteDetectorRequest adID(String adID) { this.adID = adID; return this; @@ -52,12 +59,6 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(adID); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - adID = in.readString(); - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; 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 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..a46a01c2 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelAction.java @@ -15,18 +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 - public DeleteModelResponse newResponse() { - return new DeleteModelResponse(); - } } 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..f008a126 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelNodeRequest.java @@ -30,15 +30,13 @@ public class DeleteModelNodeRequest extends BaseNodeRequest { DeleteModelNodeRequest() {} - DeleteModelNodeRequest(String nodeID, DeleteModelRequest request) { - super(nodeID); - this.adID = request.getAdID(); + DeleteModelNodeRequest(StreamInput in) throws IOException { + super(in); + this.adID = in.readString(); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - adID = in.readString(); + DeleteModelNodeRequest(DeleteModelRequest request) { + this.adID = request.getAdID(); } @Override 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..d4b2c145 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,12 @@ public String getAdID() { } public DeleteModelRequest() { - super(); + super((String[]) null); + } + + public DeleteModelRequest(StreamInput in) throws IOException { + super(in); + this.adID = in.readString(); } public DeleteModelRequest(String adID, DiscoveryNode... nodes) { @@ -56,12 +61,6 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(adID); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - adID = in.readString(); - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; 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 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/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/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/StopDetectorAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/StopDetectorAction.java index fffcd034..78615197 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,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 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/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) { 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); } 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..ee45a08c 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,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 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/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); } 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 ) { 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..8b222e87 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)) @@ -169,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(), - EnumSet.allOf(Role.class), - 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/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..0b979df4 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"))) ) ); @@ -82,12 +82,11 @@ 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(); - CronNodeResponse nodeResponseRead = new CronNodeResponse(); - nodeResponseRead.readFrom(siNode); + CronNodeResponse nodeResponseRead = new CronNodeResponse(siNode); CronResponse response = new CronResponse( new ClusterName("test"), @@ -95,11 +94,10 @@ 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 = 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..55dca10f 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 @@ -140,8 +140,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()); } @@ -198,10 +197,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..09f2ddee 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportActionTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/DeleteModelTransportActionTests.java @@ -88,17 +88,16 @@ 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); 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("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..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(); - 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, @@ -219,10 +208,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..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 @@ -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; @@ -82,7 +84,7 @@ public static ClusterState state(int numDataNodes) { "foo0", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - Collections.singleton(DiscoveryNode.Role.MASTER), + Collections.singleton(MASTER_ROLE), Version.CURRENT ); List allNodes = new ArrayList<>(); @@ -95,7 +97,7 @@ public static ClusterState state(int numDataNodes) { "foo" + i, new TransportAddress(InetAddress.getLoopbackAddress(), 9300 + i), Collections.emptyMap(), - Collections.singleton(DiscoveryNode.Role.DATA), + Collections.singleton(DATA_ROLE), Version.CURRENT ) );