Remove support for properties

This commit removes support for properties syntax and config files:
 - removed support for elasticsearch.properties
 - removed support for logging.properties
 - removed support for properties content detection in REST APIs
 - removed support for properties content detection in Java API

Relates #19398
This commit is contained in:
Jason Tedor 2016-07-12 17:55:18 -04:00 committed by GitHub
parent eba69ffade
commit ce5a382c69
9 changed files with 24 additions and 173 deletions

View File

@ -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<String, String> load(String source) throws IOException {
return load(() -> new FastStringReader(source), (reader, props) -> props.load(reader));
}
@Override
public Map<String, String> load(byte[] source) throws IOException {
return load(() -> StreamInput.wrap(source), (inStream, props) -> props.load(inStream));
}
private <T extends Closeable> Map<String, String> load(
Supplier<T> supplier,
IOExceptionThrowingBiConsumer<T, Properties> properties
) throws IOException {
T t = null;
try {
t = supplier.get();
final Properties props = new NoDuplicatesProperties();
properties.accept(t, props);
final Map<String, String> 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<T, U> {
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;
}
}
}

View File

@ -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();
}
}

View File

@ -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<String> PROPERTY_DEFAULTS_PREDICATE = key -> key.startsWith(PROPERTY_DEFAULTS_PREFIX);

View File

@ -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"));

View File

@ -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));
}
}

View File

@ -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();

View File

@ -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.

View File

@ -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 <<pre-registered-templates, Pre-registered templates>>.
==== 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.

View File

@ -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