Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping IllegalArgumentException to SettingsException extend OpenSearchException in AbstractScopedSettings class #4792

Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Relax visibility of the HTTP_CHANNEL_KEY and HTTP_SERVER_CHANNEL_KEY to make it possible for the plugins to access associated Netty4HttpChannel / Netty4HttpServerChannel instance ([#4638](https://github.com/opensearch-project/OpenSearch/pull/4638))
- Use ReplicationFailedException instead of OpensearchException in ReplicationTarget ([#4725](https://github.com/opensearch-project/OpenSearch/pull/4725))
- Migrate client transports to Apache HttpClient / Core 5.x ([#4459](https://github.com/opensearch-project/OpenSearch/pull/4459))
- Refactored BalancedAllocator.Balancer to LocalShardsBalancer ([#4761](https://github.com/opensearch-project/OpenSearch/pull/4761))
- Fail weight update when decommission ongoing and fail decommission when attribute not weighed away ([#4839](https://github.com/opensearch-project/OpenSearch/pull/4839))
- Skip SymbolicLinkPreservingTarIT when running on Windows ([#5023](https://github.com/opensearch-project/OpenSearch/pull/5023))
- Mapping IllegalArgumentException to SettingsException extend OpenSearchException in AbstractScopedSettings class ([#4792](https://github.com/opensearch-project/OpenSearch/pull/4792))

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void testClusterUpdateSettingNonExistent() {
assertThat(exception.status(), equalTo(RestStatus.BAD_REQUEST));
assertThat(
exception.getMessage(),
equalTo("OpenSearch exception [type=illegal_argument_exception, reason=transient setting [" + setting + "], not recognized]")
equalTo("OpenSearch exception [type=settings_exception, reason=transient setting [" + setting + "], not recognized]")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1437,8 +1437,7 @@ public void testIndexPutSettings() throws IOException {
assertThat(
exception.getMessage(),
startsWith(
"OpenSearch exception [type=illegal_argument_exception, "
+ "reason=final index setting [index.number_of_shards], not updateable"
"OpenSearch exception [type=settings_exception, " + "reason=final index setting [index.number_of_shards], not updateable"
)
);
}
Expand Down Expand Up @@ -1475,7 +1474,7 @@ public void testIndexPutSettingNonExistent() throws IOException {
assertThat(
exception.getMessage(),
equalTo(
"OpenSearch exception [type=illegal_argument_exception, "
"OpenSearch exception [type=settings_exception, "
+ "reason=unknown setting [index.no_idea_what_you_are_talking_about] please check that any required plugins are installed, "
+ "or check the breaking changes documentation for removed settings]"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@

package org.opensearch.cluster.metadata;

import org.hamcrest.Matchers;
import org.opensearch.common.SuppressForbidden;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.test.OpenSearchTestCase;

import static org.opensearch.cluster.metadata.IndexMetadata.DEFAULT_NUMBER_OF_SHARDS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.index.IndexNotFoundException;
Expand Down Expand Up @@ -82,7 +83,7 @@ public void testCreationDateGivenFails() {
try {
prepareCreate("test").setSettings(Settings.builder().put(IndexMetadata.SETTING_CREATION_DATE, 4L)).get();
fail();
} catch (IllegalArgumentException ex) {
} catch (SettingsException ex) {
assertEquals(
"unknown setting [index.creation_date] please check that any required plugins are installed, or check the "
+ "breaking changes documentation for removed settings",
Expand Down Expand Up @@ -203,7 +204,7 @@ public void testUnknownSettingFails() {
try {
prepareCreate("test").setSettings(Settings.builder().put("index.unknown.value", "this must fail").build()).get();
fail("should have thrown an exception about the shard count");
} catch (IllegalArgumentException e) {
} catch (SettingsException e) {
assertEquals(
"unknown setting [index.unknown.value] please check that any required plugins are installed, or check the"
+ " breaking changes documentation for removed settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.unit.ByteSizeUnit;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.indices.recovery.RecoverySettings;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void testClusterNonExistingSettingsUpdate() {
try {
client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(key1, value1).build()).get();
fail("bogus value");
} catch (IllegalArgumentException ex) {
} catch (SettingsException ex) {
assertEquals("transient setting [no_idea_what_you_are_talking_about], not recognized", ex.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;

Expand Down Expand Up @@ -64,8 +65,8 @@ public void testUpdateInternalIndexSettingViaSettingsAPI() {
final GetSettingsResponse response = client().admin().indices().prepareGetSettings("test").get();
assertThat(response.getSetting("test", "index.internal"), equalTo("internal"));
// we can not update the setting via the update settings API
final IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
final SettingsException e = expectThrows(
SettingsException.class,
() -> client().admin()
.indices()
.prepareUpdateSettings("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.opensearch.common.ValidationException;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;

Expand Down Expand Up @@ -64,8 +65,8 @@ public void testSetPrivateIndexSettingOnCreate() {
public void testUpdatePrivateIndexSettingViaSettingsAPI() {
createIndex("test");
// we can not update the setting via the update settings API
final IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
final SettingsException e = expectThrows(
SettingsException.class,
() -> client().admin()
.indices()
.prepareUpdateSettings("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opensearch.common.Priority;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.index.IndexModule;
import org.opensearch.index.IndexService;
Expand Down Expand Up @@ -174,8 +175,8 @@ protected Settings nodeSettings(int nodeOrdinal) {
}

public void testUpdateDependentClusterSettings() {
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
SettingsException iae = expectThrows(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several places in this PR where the variable name "iae" no longer makes sense.

SettingsException.class,
() -> client().admin()
.cluster()
.prepareUpdateSettings()
Expand All @@ -185,7 +186,7 @@ public void testUpdateDependentClusterSettings() {
assertEquals("missing required setting [cluster.acc.test.user] for setting [cluster.acc.test.pw]", iae.getMessage());

iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.cluster()
.prepareUpdateSettings()
Expand All @@ -195,7 +196,7 @@ public void testUpdateDependentClusterSettings() {
assertEquals("missing required setting [cluster.acc.test.user] for setting [cluster.acc.test.pw]", iae.getMessage());

iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.cluster()
.prepareUpdateSettings()
Expand All @@ -212,7 +213,7 @@ public void testUpdateDependentClusterSettings() {
.setTransientSettings(Settings.builder().put("cluster.acc.test.pw", "asdf").put("cluster.acc.test.user", "asdf"))
.get();
iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.cluster()
.prepareUpdateSettings()
Expand All @@ -233,7 +234,7 @@ public void testUpdateDependentClusterSettings() {
.get();

iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.cluster()
.prepareUpdateSettings()
Expand All @@ -252,8 +253,8 @@ public void testUpdateDependentClusterSettings() {
}

public void testUpdateDependentIndexSettings() {
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
SettingsException iae = expectThrows(
SettingsException.class,
() -> prepareCreate("test", Settings.builder().put("index.acc.test.pw", "asdf")).get()
);
assertEquals("missing required setting [index.acc.test.user] for setting [index.acc.test.pw]", iae.getMessage());
Expand All @@ -266,7 +267,7 @@ public void testUpdateDependentIndexSettings() {
}

iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.indices()
.prepareUpdateSettings("test")
Expand Down Expand Up @@ -294,7 +295,7 @@ public void testUpdateDependentIndexSettings() {

// now try to remove it and make sure it fails
iae = expectThrows(
IllegalArgumentException.class,
SettingsException.class,
() -> client().admin()
.indices()
.prepareUpdateSettings("test")
Expand Down Expand Up @@ -480,8 +481,8 @@ public void testOpenCloseUpdateSettings() throws Exception {
assertThat(indexMetadata.getSettings().get("index.refresh_interval"), equalTo("1s"));
assertThat(indexMetadata.getSettings().get("index.fielddata.cache"), equalTo("none"));

IllegalArgumentException ex = expectThrows(
IllegalArgumentException.class,
SettingsException ex = expectThrows(
SettingsException.class,
() -> client().admin()
.indices()
.prepareUpdateSettings("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.opensearch.common.ParsingException;
import org.opensearch.common.bytes.BytesArray;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MapperParsingException;
Expand Down Expand Up @@ -494,8 +495,8 @@ public void testInvalidSettings() throws Exception {
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), empty());

IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
SettingsException e = expectThrows(
SettingsException.class,
() -> client().admin()
.indices()
.preparePutTemplate("template_1")
Expand Down
Loading