diff --git a/core/src/main/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoader.java b/core/src/main/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoader.java deleted file mode 100644 index 7192afa3ac3..00000000000 --- a/core/src/main/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoader.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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. - */ - -package org.elasticsearch.common.settings.loader; - -import org.apache.lucene.util.IOUtils; -import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.io.FastStringReader; -import org.elasticsearch.common.io.stream.StreamInput; - -import java.io.Closeable; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.function.Supplier; - -/** - * Settings loader that loads (parses) the settings in a properties format. - */ -public class PropertiesSettingsLoader implements SettingsLoader { - - @Override - public Map load(String source) throws IOException { - return load(() -> new FastStringReader(source), (reader, props) -> props.load(reader)); - } - - @Override - public Map load(byte[] source) throws IOException { - return load(() -> StreamInput.wrap(source), (inStream, props) -> props.load(inStream)); - } - - private Map load( - Supplier supplier, - IOExceptionThrowingBiConsumer properties - ) throws IOException { - T t = null; - try { - t = supplier.get(); - final Properties props = new NoDuplicatesProperties(); - properties.accept(t, props); - final Map result = new HashMap<>(); - for (Map.Entry entry : props.entrySet()) { - result.put((String) entry.getKey(), (String) entry.getValue()); - } - return result; - } finally { - IOUtils.closeWhileHandlingException(t); - } - } - - @FunctionalInterface - private interface IOExceptionThrowingBiConsumer { - void accept(T t, U u) throws IOException; - } - - class NoDuplicatesProperties extends Properties { - @Override - public synchronized Object put(Object key, Object value) { - final Object previousValue = super.put(key, value); - if (previousValue != null) { - throw new ElasticsearchParseException( - "duplicate settings key [{}] found, previous value [{}], current value [{}]", - key, - previousValue, - value - ); - } - return previousValue; - } - } -} diff --git a/core/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java b/core/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java index 5bf9916ee0e..5f2da22c5f2 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java +++ b/core/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java @@ -48,11 +48,8 @@ public final class SettingsLoaderFactory { return new JsonSettingsLoader(false); } else if (resourceName.endsWith(".yml") || resourceName.endsWith(".yaml")) { return new YamlSettingsLoader(false); - } else if (resourceName.endsWith(".properties")) { - return new PropertiesSettingsLoader(); } else { - // lets default to the json one - return new JsonSettingsLoader(false); + throw new IllegalArgumentException("unable to detect content type from resource name [" + resourceName + "]"); } } @@ -72,11 +69,11 @@ public final class SettingsLoaderFactory { public static SettingsLoader loaderFromSource(String source) { if (source.indexOf('{') != -1 && source.indexOf('}') != -1) { return new JsonSettingsLoader(true); - } - if (source.indexOf(':') != -1) { + } else if (source.indexOf(':') != -1) { return new YamlSettingsLoader(true); + } else { + throw new IllegalArgumentException("unable to detect content type from source [" + source + "]"); } - return new PropertiesSettingsLoader(); } } diff --git a/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java b/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java index 3ee704c42aa..246e3cf60c4 100644 --- a/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java +++ b/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java @@ -51,7 +51,7 @@ import static org.elasticsearch.common.Strings.cleanPath; */ public class InternalSettingsPreparer { - private static final String[] ALLOWED_SUFFIXES = {".yml", ".yaml", ".json", ".properties"}; + private static final String[] ALLOWED_SUFFIXES = {".yml", ".yaml", ".json"}; static final String PROPERTY_DEFAULTS_PREFIX = "default."; static final Predicate PROPERTY_DEFAULTS_PREDICATE = key -> key.startsWith(PROPERTY_DEFAULTS_PREFIX); diff --git a/core/src/test/java/org/elasticsearch/common/logging/LoggingConfigurationTests.java b/core/src/test/java/org/elasticsearch/common/logging/LoggingConfigurationTests.java index fabace237b2..581a9599365 100644 --- a/core/src/test/java/org/elasticsearch/common/logging/LoggingConfigurationTests.java +++ b/core/src/test/java/org/elasticsearch/common/logging/LoggingConfigurationTests.java @@ -95,23 +95,6 @@ public class LoggingConfigurationTests extends ESTestCase { assertThat(logSettings.get("json"), is("foo")); } - public void testResolvePropertiesLoggingConfig() throws Exception { - Path tmpDir = createTempDir(); - Path loggingConf = tmpDir.resolve(loggingConfiguration("properties")); - Files.write(loggingConf, "key: value".getBytes(StandardCharsets.UTF_8)); - Environment environment = new Environment( - Settings.builder() - .put(Environment.PATH_CONF_SETTING.getKey(), tmpDir.toAbsolutePath()) - .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) - .build()); - - Settings.Builder builder = Settings.builder(); - LogConfigurator.resolveConfig(environment, builder); - - Settings logSettings = builder.build(); - assertThat(logSettings.get("key"), is("value")); - } - public void testResolveYamlLoggingConfig() throws Exception { Path tmpDir = createTempDir(); Path loggingConf1 = tmpDir.resolve(loggingConfiguration("yml")); diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoaderTests.java deleted file mode 100644 index c13ae7cc68b..00000000000 --- a/core/src/test/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoaderTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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. - */ - -package org.elasticsearch.common.settings.loader; - -import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.test.ESTestCase; -import org.junit.Before; - -import java.io.IOException; -import java.nio.charset.Charset; - -public class PropertiesSettingsLoaderTests extends ESTestCase { - - private PropertiesSettingsLoader loader; - - @Before - public void setUp() throws Exception { - super.setUp(); - loader = new PropertiesSettingsLoader(); - } - - public void testDuplicateKeyFromStringThrowsException() throws IOException { - final ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> loader.load("foo=bar\nfoo=baz")); - assertEquals(e.getMessage(), "duplicate settings key [foo] found, previous value [bar], current value [baz]"); - } - - public void testDuplicateKeysFromBytesThrowsException() throws IOException { - final ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> loader.load("foo=bar\nfoo=baz".getBytes(Charset.defaultCharset())) - ); - assertEquals(e.getMessage(), "duplicate settings key [foo] found, previous value [bar], current value [baz]"); - } - - public void testThatNoDuplicatesPropertiesDoesNotAcceptNullValues() { - final PropertiesSettingsLoader.NoDuplicatesProperties properties = loader.new NoDuplicatesProperties(); - expectThrows(NullPointerException.class, () -> properties.put("key", null)); - } - -} diff --git a/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java b/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java index 49046bae009..3758715cbac 100644 --- a/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java +++ b/core/src/test/java/org/elasticsearch/search/preference/SearchPreferenceIT.java @@ -98,7 +98,7 @@ public class SearchPreferenceIT extends ESIntegTestCase { } public void testSimplePreference() throws Exception { - client().admin().indices().prepareCreate("test").setSettings("number_of_replicas=1").get(); + client().admin().indices().prepareCreate("test").setSettings("{\"number_of_replicas\": 1}").get(); ensureGreen(); client().prepareIndex("test", "type1").setSource("field1", "value1").execute().actionGet(); @@ -131,7 +131,7 @@ public class SearchPreferenceIT extends ESIntegTestCase { } public void testReplicaPreference() throws Exception { - client().admin().indices().prepareCreate("test").setSettings("number_of_replicas=0").get(); + client().admin().indices().prepareCreate("test").setSettings("{\"number_of_replicas\": 0}").get(); ensureGreen(); client().prepareIndex("test", "type1").setSource("field1", "value1").execute().actionGet(); @@ -147,7 +147,7 @@ public class SearchPreferenceIT extends ESIntegTestCase { SearchResponse resp = client().prepareSearch().setQuery(matchAllQuery()).setPreference("_replica_first").execute().actionGet(); assertThat(resp.getHits().totalHits(), equalTo(1L)); - client().admin().indices().prepareUpdateSettings("test").setSettings("number_of_replicas=1").get(); + client().admin().indices().prepareUpdateSettings("test").setSettings("{\"number_of_replicas\": 1}").get(); ensureGreen("test"); resp = client().prepareSearch().setQuery(matchAllQuery()).setPreference("_replica").execute().actionGet(); diff --git a/docs/reference/migration/migrate_5_0/java.asciidoc b/docs/reference/migration/migrate_5_0/java.asciidoc index 7d3a21b3197..90dc8b02f62 100644 --- a/docs/reference/migration/migrate_5_0/java.asciidoc +++ b/docs/reference/migration/migrate_5_0/java.asciidoc @@ -312,6 +312,11 @@ Removed the `getMemoryAvailable` method from `OsStats`, which could be previousl are now three options (NONE, IMMEDIATE, and WAIT_FOR). `setRefresh(IMMEDIATE)` has the same behavior as `setRefresh(true)` used to have. See `setRefreshPolicy`'s javadoc for more. +==== Remove properties support + +Some Java APIs (e.g., `IndicesAdminClient#setSettings`) would support Java properties syntax +(line-delimited key=value pairs). This support has been removed. + === Render Search Template Java API has been removed The Render Search Template Java API including `RenderSearchTemplateAction`, `RenderSearchTemplateRequest` and @@ -319,3 +324,4 @@ The Render Search Template Java API including `RenderSearchTemplateAction`, `Ren This Search Template API is now included in the `lang-mustache` module and the `simulate` flag must be set on the `SearchTemplateRequest` object. + diff --git a/docs/reference/migration/migrate_5_0/rest.asciidoc b/docs/reference/migration/migrate_5_0/rest.asciidoc index a9f70d2caae..9d135c4d5bf 100644 --- a/docs/reference/migration/migrate_5_0/rest.asciidoc +++ b/docs/reference/migration/migrate_5_0/rest.asciidoc @@ -74,3 +74,8 @@ The `PUT /_scripts/{lang}/{id}/_create` endpoint that previously allowed to crea The `PUT /_search/template/{id}/_create` endpoint that previously allowed to create indexed template has been removed. Indexed templates have been replaced by <>. + +==== Remove properties support + +Some REST endpoints (e.g., cluster update index settings) supported detecting content in the Java +properties format (line-delimited key=value pairs). This support has been removed. diff --git a/docs/reference/migration/migrate_5_0/settings.asciidoc b/docs/reference/migration/migrate_5_0/settings.asciidoc index 7bfa9dc875c..479b60aa48d 100644 --- a/docs/reference/migration/migrate_5_0/settings.asciidoc +++ b/docs/reference/migration/migrate_5_0/settings.asciidoc @@ -229,6 +229,11 @@ Elasticsearch could previously be configured on the command line by setting settings via `--name.of.setting value.of.setting`. This feature has been removed. Instead, use `-Ename.of.setting=value.of.setting`. +==== Remove support for .properties config files + +The Elasticsearch configuration and logging configuration can no longer be stored in the Java +properties file format (line-delimited key=value pairs with a `.properties` extension). + ==== Discovery Settings The `discovery.zen.minimum_master_node` must be set for nodes that have