From c7a188cb23d6e82789d7d04974441e417d1c3528 Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Thu, 31 Jan 2019 13:32:40 -0600 Subject: [PATCH] Adding ml_settings entry to HLRC and Docs for deprecation_info --- .../migration/DeprecationInfoResponse.java | 20 ++++++++++++--- .../org/elasticsearch/client/MigrationIT.java | 1 + .../MigrationClientDocumentationIT.java | 4 +++ .../DeprecationInfoResponseTests.java | 25 ++++++++++++++----- .../migration/get-deprecation-info.asciidoc | 1 + .../migration/apis/deprecation.asciidoc | 6 +++-- 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/DeprecationInfoResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/DeprecationInfoResponse.java index 05e4be37edcfa..6d2cf4507731f 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/DeprecationInfoResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/migration/DeprecationInfoResponse.java @@ -37,16 +37,19 @@ public class DeprecationInfoResponse { private static final ParseField CLUSTER_SETTINGS = new ParseField("cluster_settings"); private static final ParseField NODE_SETTINGS = new ParseField("node_settings"); private static final ParseField INDEX_SETTINGS = new ParseField("index_settings"); + private static final ParseField ML_SETTINGS = new ParseField("ml_settings"); private final List clusterSettingsIssues; private final List nodeSettingsIssues; private final Map> indexSettingsIssues; + private final List mlSettingsIssues; public DeprecationInfoResponse(List clusterSettingsIssues, List nodeSettingsIssues, - Map> indexSettingsIssues) { + Map> indexSettingsIssues, List mlSettingsIssues) { this.clusterSettingsIssues = Objects.requireNonNull(clusterSettingsIssues, "cluster settings issues cannot be null"); this.nodeSettingsIssues = Objects.requireNonNull(nodeSettingsIssues, "node settings issues cannot be null"); this.indexSettingsIssues = Objects.requireNonNull(indexSettingsIssues, "index settings issues cannot be null"); + this.mlSettingsIssues = Objects.requireNonNull(mlSettingsIssues, "ml settings issues cannot be null"); } public List getClusterSettingsIssues() { @@ -61,6 +64,10 @@ public Map> getIndexSettingsIssues() { return indexSettingsIssues; } + public List getMlSettingsIssues() { + return mlSettingsIssues; + } + private static List parseDeprecationIssues(XContentParser parser) throws IOException { List issues = new ArrayList<>(); XContentParser.Token token = null; @@ -76,6 +83,7 @@ public static DeprecationInfoResponse fromXContent(XContentParser parser) throws Map> indexSettings = new HashMap<>(); List clusterSettings = new ArrayList<>(); List nodeSettings = new ArrayList<>(); + List mlSettings = new ArrayList<>(); String fieldName = null; XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -85,6 +93,8 @@ public static DeprecationInfoResponse fromXContent(XContentParser parser) throws clusterSettings.addAll(parseDeprecationIssues(parser)); } else if (NODE_SETTINGS.getPreferredName().equals(fieldName)) { nodeSettings.addAll(parseDeprecationIssues(parser)); + } else if (ML_SETTINGS.getPreferredName().equals(fieldName)) { + mlSettings.addAll(parseDeprecationIssues(parser)); } else if (INDEX_SETTINGS.getPreferredName().equals(fieldName)) { // parse out the key/value pairs while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -96,7 +106,7 @@ public static DeprecationInfoResponse fromXContent(XContentParser parser) throws } } } - return new DeprecationInfoResponse(clusterSettings, nodeSettings, indexSettings); + return new DeprecationInfoResponse(clusterSettings, nodeSettings, indexSettings, mlSettings); } @Override @@ -106,17 +116,19 @@ public boolean equals(Object o) { DeprecationInfoResponse that = (DeprecationInfoResponse) o; return Objects.equals(clusterSettingsIssues, that.clusterSettingsIssues) && Objects.equals(nodeSettingsIssues, that.nodeSettingsIssues) && + Objects.equals(mlSettingsIssues, that.mlSettingsIssues) && Objects.equals(indexSettingsIssues, that.indexSettingsIssues); } @Override public int hashCode() { - return Objects.hash(clusterSettingsIssues, nodeSettingsIssues, indexSettingsIssues); + return Objects.hash(clusterSettingsIssues, nodeSettingsIssues, indexSettingsIssues, mlSettingsIssues); } @Override public String toString() { - return clusterSettingsIssues.toString() + ":" + nodeSettingsIssues.toString() + ":" + indexSettingsIssues.toString(); + return clusterSettingsIssues.toString() + ":" + nodeSettingsIssues.toString() + ":" + indexSettingsIssues.toString() + + ":" + mlSettingsIssues.toString(); } /** diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java index 09e3e6f1c848f..350659ae1449a 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/MigrationIT.java @@ -85,6 +85,7 @@ public void testGetDeprecationInfo() throws IOException { assertThat(response.getClusterSettingsIssues().size(), equalTo(0)); assertThat(response.getIndexSettingsIssues().size(), equalTo(0)); assertThat(response.getNodeSettingsIssues().size(), equalTo(0)); + assertThat(response.getMlSettingsIssues().size(), equalTo(0)); } /** diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java index 7b1e92c337e17..ca5e18c376b92 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationClientDocumentationIT.java @@ -182,6 +182,8 @@ public void testGetDeprecationInfo() throws IOException, InterruptedException { deprecationInfoResponse.getNodeSettingsIssues(); // <2> Map> indexIssues = deprecationInfoResponse.getIndexSettingsIssues(); // <3> + List mlIssues = + deprecationInfoResponse.getMlSettingsIssues(); // <4> // end::get-deprecation-info-response // tag::get-deprecation-info-execute-listener @@ -195,6 +197,8 @@ public void onResponse(DeprecationInfoResponse deprecationInfoResponse1) { // <1 deprecationInfoResponse.getNodeSettingsIssues(); Map> indexIssues = deprecationInfoResponse.getIndexSettingsIssues(); + List mlIssues = + deprecationInfoResponse.getMlSettingsIssues(); } @Override diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/migration/DeprecationInfoResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/migration/DeprecationInfoResponseTests.java index 054b800d6483c..052066e810634 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/migration/DeprecationInfoResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/migration/DeprecationInfoResponseTests.java @@ -65,6 +65,12 @@ private void toXContent(DeprecationInfoResponse response, XContentBuilder builde } } builder.endObject(); + + builder.startArray("ml_settings"); + for (DeprecationInfoResponse.DeprecationIssue issue : response.getMlSettingsIssues()) { + toXContent(issue, builder); + } + builder.endArray(); } builder.endObject(); } @@ -105,12 +111,14 @@ private List createRandomIssues(boolea } private DeprecationInfoResponse createInstance() { - return new DeprecationInfoResponse(createRandomIssues(true), createRandomIssues(true), createIndexSettingsIssues()); + return new DeprecationInfoResponse(createRandomIssues(true), createRandomIssues(true), createIndexSettingsIssues(), + createRandomIssues(true)); } private DeprecationInfoResponse copyInstance(DeprecationInfoResponse req) { return new DeprecationInfoResponse(new ArrayList<>(req.getClusterSettingsIssues()), - new ArrayList<>(req.getNodeSettingsIssues()), new HashMap<>(req.getIndexSettingsIssues())); + new ArrayList<>(req.getNodeSettingsIssues()), new HashMap<>(req.getIndexSettingsIssues()), + new ArrayList<>(req.getMlSettingsIssues())); } private DeprecationInfoResponse mutateInstance(DeprecationInfoResponse req) { @@ -128,16 +136,21 @@ public void testFromXContent() throws IOException { } public void testNullFailedIndices() { - NullPointerException exception = - expectThrows(NullPointerException.class, () -> new DeprecationInfoResponse(null, null, null)); + NullPointerException exception = expectThrows(NullPointerException.class, + () -> new DeprecationInfoResponse(null, null, null, null)); assertEquals("cluster settings issues cannot be null", exception.getMessage()); - exception = expectThrows(NullPointerException.class, () -> new DeprecationInfoResponse(Collections.emptyList(), null, null)); + exception = expectThrows(NullPointerException.class, + () -> new DeprecationInfoResponse(Collections.emptyList(), null, null, null)); assertEquals("node settings issues cannot be null", exception.getMessage()); exception = expectThrows(NullPointerException.class, - () -> new DeprecationInfoResponse(Collections.emptyList(), Collections.emptyList(), null)); + () -> new DeprecationInfoResponse(Collections.emptyList(), Collections.emptyList(), null, null)); assertEquals("index settings issues cannot be null", exception.getMessage()); + + exception = expectThrows(NullPointerException.class, + () -> new DeprecationInfoResponse(Collections.emptyList(), Collections.emptyList(), Collections.emptyMap(), null)); + assertEquals("ml settings issues cannot be null", exception.getMessage()); } public void testEqualsAndHashCode() { diff --git a/docs/java-rest/high-level/migration/get-deprecation-info.asciidoc b/docs/java-rest/high-level/migration/get-deprecation-info.asciidoc index f6e12e5746717..3cda1c2f503d6 100644 --- a/docs/java-rest/high-level/migration/get-deprecation-info.asciidoc +++ b/docs/java-rest/high-level/migration/get-deprecation-info.asciidoc @@ -33,3 +33,4 @@ include-tagged::{doc-tests-file}[{api}-response] <1> a List of Cluster deprecations <2> a List of Node deprecations <3> a Map of key IndexName, value List of deprecations for the index +<4> a list of Machine Learning related deprecations diff --git a/docs/reference/migration/apis/deprecation.asciidoc b/docs/reference/migration/apis/deprecation.asciidoc index 59ba1e97a2e9e..88de3f5d6e3fa 100644 --- a/docs/reference/migration/apis/deprecation.asciidoc +++ b/docs/reference/migration/apis/deprecation.asciidoc @@ -68,7 +68,8 @@ Example response: "details" : "This index is named [logs:apache], which contains the illegal character ':'." } ] - } + }, + "ml_settings" : [ ] } -------------------------------------------------- // NOTCONSOLE @@ -109,7 +110,8 @@ key. Similarly, any node-level warnings are found under `node_settings`. Since only a select subset of your nodes might incorporate these settings, it is important to read the `details` section for more information about which nodes are affected. Index warnings are sectioned off per index and can be filtered -using an index-pattern in the query. +using an index-pattern in the query. Machine Learning related deprecation +warnings can be found under the `ml_settings` key. The following example request shows only index-level deprecations of all `logstash-*` indices: