From a35a739c722615af46b9d8d85cc27e4487e7a283 Mon Sep 17 00:00:00 2001 From: Megha Sai Kavikondala Date: Mon, 1 Nov 2021 18:57:55 +0000 Subject: [PATCH 1/2] Made changes. Signed-off-by: Megha Sai Kavikondala --- .../opensearch/upgrades/TestSettingsIT.java | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/TestSettingsIT.java diff --git a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/TestSettingsIT.java b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/TestSettingsIT.java new file mode 100644 index 0000000000000..25069c3243f3d --- /dev/null +++ b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/TestSettingsIT.java @@ -0,0 +1,94 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +package org.opensearch.upgrades; + +import org.opensearch.action.admin.cluster.settings.ClusterGetSettingsResponse; +import org.opensearch.client.Request; +import org.opensearch.client.Response; +import org.opensearch.common.settings.Settings; +import org.opensearch.common.xcontent.json.JsonXContent; +import org.opensearch.common.Strings; +import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentParser; + +import java.io.IOException; +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.opensearch.transport.RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE; +import static org.opensearch.transport.SniffConnectionStrategy.REMOTE_CLUSTER_SEEDS; +import static org.opensearch.transport.SniffConnectionStrategy.REMOTE_CLUSTERS_PROXY; + +public class TestSettingsIT extends AbstractFullClusterRestartTestCase { + + public void testClusterSetting() throws IOException { + if (isRunningAgainstOldCluster()) { + final Request putSettingsRequest = new Request("PUT", "/_cluster/settings"); + try (XContentBuilder builder = jsonBuilder()) { + builder.startObject(); + { + builder.startObject("persistent"); + { + builder.field("search.remote.foo.skip_unavailable", true); + builder.field("search.remote.foo.seeds", Collections.singletonList("localhost:9200")); + builder.field("search.remote.foo.proxy", "localhost:9200"); + } + builder.endObject(); + } + builder.endObject(); + putSettingsRequest.setJsonEntity(Strings.toString(builder)); + } + client().performRequest(putSettingsRequest); + } + else{ + Request getSettingsRequest = new Request("GET", "/_cluster/settings"); + Response res = client().performRequest(getSettingsRequest); + try (XContentParser parser = createParser(JsonXContent.jsonXContent, res.getEntity().getContent())) { + final ClusterGetSettingsResponse clusterGetSettingsResponse = ClusterGetSettingsResponse.fromXContent(parser); + final Settings settings = clusterGetSettingsResponse.getPersistentSettings(); + assertTrue(REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").exists(settings)); + assertTrue(REMOTE_CLUSTER_SEEDS.getConcreteSettingForNamespace("foo").exists(settings)); + assertTrue(REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace("foo").exists(settings)); + + assertTrue(REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").get(settings)); + assertEquals(String.valueOf(REMOTE_CLUSTER_SEEDS.getConcreteSettingForNamespace("foo").get(settings)), + "[localhost:9200]"); + assertEquals(String.valueOf(REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace("foo").get(settings)), + "localhost:9200"); + } + } + + } +} From 0082131cee76128ee10ce1afa1bcc1a9a5e5668f Mon Sep 17 00:00:00 2001 From: Megha Sai Kavikondala Date: Fri, 5 Nov 2021 19:25:18 +0000 Subject: [PATCH 2/2] Signed-off-by: Megha Sai Kavikondala Changes made by deleting the TestSettingsIT file and adding new lines in FullClusterRestartSettingsUpgradeIT.java --- .../FullClusterRestartSettingsUpgradeIT.java | 13 ++- .../opensearch/upgrades/TestSettingsIT.java | 94 ------------------- 2 files changed, 12 insertions(+), 95 deletions(-) delete mode 100644 qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/TestSettingsIT.java diff --git a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartSettingsUpgradeIT.java b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartSettingsUpgradeIT.java index 5670c56597575..53b21fda8f890 100644 --- a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartSettingsUpgradeIT.java +++ b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/FullClusterRestartSettingsUpgradeIT.java @@ -51,6 +51,8 @@ import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder; import static org.opensearch.transport.RemoteClusterService.SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE; import static org.opensearch.transport.SniffConnectionStrategy.SEARCH_REMOTE_CLUSTERS_SEEDS; +import static org.opensearch.transport.SniffConnectionStrategy.SEARCH_REMOTE_CLUSTERS_PROXY; +import static org.opensearch.transport.SniffConnectionStrategy.REMOTE_CLUSTERS_PROXY; import static org.hamcrest.Matchers.equalTo; public class FullClusterRestartSettingsUpgradeIT extends AbstractFullClusterRestartTestCase { @@ -67,6 +69,7 @@ public void testRemoteClusterSettingsUpgraded() throws IOException { { builder.field("search.remote.foo.skip_unavailable", true); builder.field("search.remote.foo.seeds", Collections.singletonList("localhost:9200")); + builder.field("search.remote.foo.proxy", "localhost:9200"); } builder.endObject(); } @@ -87,11 +90,15 @@ public void testRemoteClusterSettingsUpgraded() throws IOException { assertThat( SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").get(settings), equalTo(Collections.singletonList("localhost:9200"))); + assertTrue(SEARCH_REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace("foo").exists(settings)); + assertEquals(String.valueOf(SEARCH_REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace("foo").get(settings)), + "localhost:9200"); } assertSettingDeprecationsAndWarnings(new Setting[]{ SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo"), - SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo")}); + SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo"), + SEARCH_REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace("foo")}); } else { final Request getSettingsRequest = new Request("GET", "/_cluster/settings"); final Response getSettingsResponse = client().performRequest(getSettingsRequest); @@ -109,6 +116,10 @@ public void testRemoteClusterSettingsUpgraded() throws IOException { assertThat( SniffConnectionStrategy.REMOTE_CLUSTER_SEEDS.getConcreteSettingForNamespace("foo").get(settings), equalTo(Collections.singletonList("localhost:9200"))); + assertFalse(SEARCH_REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace("foo").exists(settings)); + assertTrue(REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace("foo").exists(settings)); + assertEquals(String.valueOf(REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace("foo").get(settings)), + "localhost:9200"); } } } diff --git a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/TestSettingsIT.java b/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/TestSettingsIT.java deleted file mode 100644 index 25069c3243f3d..0000000000000 --- a/qa/full-cluster-restart/src/test/java/org/opensearch/upgrades/TestSettingsIT.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -package org.opensearch.upgrades; - -import org.opensearch.action.admin.cluster.settings.ClusterGetSettingsResponse; -import org.opensearch.client.Request; -import org.opensearch.client.Response; -import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.json.JsonXContent; -import org.opensearch.common.Strings; -import org.opensearch.common.xcontent.XContentBuilder; -import org.opensearch.common.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Collections; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.opensearch.transport.RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE; -import static org.opensearch.transport.SniffConnectionStrategy.REMOTE_CLUSTER_SEEDS; -import static org.opensearch.transport.SniffConnectionStrategy.REMOTE_CLUSTERS_PROXY; - -public class TestSettingsIT extends AbstractFullClusterRestartTestCase { - - public void testClusterSetting() throws IOException { - if (isRunningAgainstOldCluster()) { - final Request putSettingsRequest = new Request("PUT", "/_cluster/settings"); - try (XContentBuilder builder = jsonBuilder()) { - builder.startObject(); - { - builder.startObject("persistent"); - { - builder.field("search.remote.foo.skip_unavailable", true); - builder.field("search.remote.foo.seeds", Collections.singletonList("localhost:9200")); - builder.field("search.remote.foo.proxy", "localhost:9200"); - } - builder.endObject(); - } - builder.endObject(); - putSettingsRequest.setJsonEntity(Strings.toString(builder)); - } - client().performRequest(putSettingsRequest); - } - else{ - Request getSettingsRequest = new Request("GET", "/_cluster/settings"); - Response res = client().performRequest(getSettingsRequest); - try (XContentParser parser = createParser(JsonXContent.jsonXContent, res.getEntity().getContent())) { - final ClusterGetSettingsResponse clusterGetSettingsResponse = ClusterGetSettingsResponse.fromXContent(parser); - final Settings settings = clusterGetSettingsResponse.getPersistentSettings(); - assertTrue(REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").exists(settings)); - assertTrue(REMOTE_CLUSTER_SEEDS.getConcreteSettingForNamespace("foo").exists(settings)); - assertTrue(REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace("foo").exists(settings)); - - assertTrue(REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").get(settings)); - assertEquals(String.valueOf(REMOTE_CLUSTER_SEEDS.getConcreteSettingForNamespace("foo").get(settings)), - "[localhost:9200]"); - assertEquals(String.valueOf(REMOTE_CLUSTERS_PROXY.getConcreteSettingForNamespace("foo").get(settings)), - "localhost:9200"); - } - } - - } -}