Merge pull request elastic/elasticsearch#1328 from s1monw/prepare_new_index_settings

Upgrade to new index settings infrastructure

Original commit: elastic/x-pack-elasticsearch@306fe5afbe
This commit is contained in:
Simon Willnauer 2016-01-19 12:43:17 +01:00
commit 7c0641afdb
14 changed files with 73 additions and 18 deletions

View File

@ -10,6 +10,7 @@ import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.marvel.agent.AgentService;
@ -35,6 +36,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
public class MarvelPlugin extends Plugin {
@ -42,6 +44,8 @@ public class MarvelPlugin extends Plugin {
public static final String NAME = "marvel";
public static final String ENABLED = NAME + ".enabled";
public static final Setting<String> INDEX_MARVEL_VERSION_SETTING = new Setting<>("index.marvel.plugin.version", "", Function.identity(), false, Setting.Scope.INDEX);
public static final Setting<String> INDEX_MARVEL_TEMPLATE_VERSION_SETTING = new Setting<>("index.marvel.template.version", "", Function.identity(), false, Setting.Scope.INDEX);
private final Settings settings;
private final boolean enabled;
@ -144,5 +148,7 @@ public class MarvelPlugin extends Plugin {
module.registerSetting(MarvelSettings.CLUSTER_STATE_TIMEOUT_SETTING);
module.registerSetting(MarvelSettings.CLUSTER_STATS_TIMEOUT_SETTING);
module.registerSetting(CleanerService.HISTORY_SETTING);
module.registerSetting(INDEX_MARVEL_VERSION_SETTING);
module.registerSetting(INDEX_MARVEL_TEMPLATE_VERSION_SETTING);
}
}

View File

@ -11,14 +11,26 @@ import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.marvel.agent.exporter.local.LocalExporter;
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
import org.elasticsearch.marvel.cleaner.AbstractIndicesCleanerTestCase;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.InternalSettingsPlugin;
import org.joda.time.DateTime;
import java.util.ArrayList;
import java.util.Collection;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
public class LocalIndicesCleanerTests extends AbstractIndicesCleanerTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
ArrayList<Class<? extends Plugin>> plugins = new ArrayList<>(super.nodePlugins());
plugins.add(InternalSettingsPlugin.class);
return plugins;
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()

View File

@ -25,6 +25,7 @@ import org.elasticsearch.shield.authc.support.SecuredString;
import org.elasticsearch.shield.crypto.InternalCryptoService;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.TestCluster;
import org.elasticsearch.test.store.MockFSIndexStore;
import org.elasticsearch.test.transport.AssertingLocalTransport;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.xpack.XPackPlugin;
@ -74,7 +75,6 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase {
//TODO: for now lets isolate marvel tests from watcher (randomize this later)
.put("watcher.enabled", false)
// we do this by default in core, but for marvel this isn't needed and only adds noise.
.put("index.store.mock.check_index_on_close", false);
@ -102,6 +102,7 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase {
Set<Class<? extends Plugin>> plugins = new HashSet<>(super.getMockPlugins());
plugins.remove(MockTransportService.TestPlugin.class); // shield has its own transport service
plugins.remove(AssertingLocalTransport.TestPlugin.class); // shield has its own transport
plugins.add(MockFSIndexStore.TestPlugin.class);
return plugins;
}
@ -397,7 +398,7 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase {
.put("shield.audit.enabled", auditLogsEnabled)
// Test framework sometimes randomily selects the 'index' or 'none' cache and that makes the
// validation in ShieldPlugin fail. Shield can only run with this query cache impl
.put(IndexModule.QUERY_CACHE_TYPE, ShieldPlugin.OPT_OUT_QUERY_CACHE);
.put(IndexModule.INDEX_QUERY_CACHE_TYPE_SETTING.getKey(), ShieldPlugin.OPT_OUT_QUERY_CACHE);
} catch (IOException ex) {
throw new RuntimeException("failed to build settings for shield", ex);
}

View File

@ -327,7 +327,7 @@ public class ShieldPlugin extends Plugin {
unauthorized users.
*/
private void addQueryCacheSettings(Settings.Builder settingsBuilder) {
settingsBuilder.put(IndexModule.QUERY_CACHE_TYPE, OPT_OUT_QUERY_CACHE);
settingsBuilder.put(IndexModule.INDEX_QUERY_CACHE_TYPE_SETTING.getKey(), OPT_OUT_QUERY_CACHE);
}
private static boolean isShieldMandatory(String[] existingMandatoryPlugins) {
@ -365,12 +365,12 @@ public class ShieldPlugin extends Plugin {
// in case this are node settings then the plugin additional settings have not been applied yet,
// so we use 'opt_out_cache' as default. So in that case we only fail if the node settings contain
// another cache impl than 'opt_out_cache'.
queryCacheImplementation = settings.get(IndexModule.QUERY_CACHE_TYPE, OPT_OUT_QUERY_CACHE);
queryCacheImplementation = settings.get(IndexModule.INDEX_QUERY_CACHE_TYPE_SETTING.getKey(), OPT_OUT_QUERY_CACHE);
} else {
queryCacheImplementation = settings.get(IndexModule.QUERY_CACHE_TYPE);
queryCacheImplementation = settings.get(IndexModule.INDEX_QUERY_CACHE_TYPE_SETTING.getKey());
}
if (OPT_OUT_QUERY_CACHE.equals(queryCacheImplementation) == false) {
throw new IllegalStateException("shield does not support a user specified query cache. remove the setting [" + IndexModule.QUERY_CACHE_TYPE + "] with value [" + queryCacheImplementation + "]");
throw new IllegalStateException("shield does not support a user specified query cache. remove the setting [" + IndexModule.INDEX_QUERY_CACHE_TYPE_SETTING.getKey() + "] with value [" + queryCacheImplementation + "]");
}
}
}

View File

@ -107,7 +107,7 @@ public class DocumentAndFieldLevelSecurityTests extends ShieldIntegTestCase {
public void testQueryCache() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test")
.setSettings(Settings.builder().put(IndexModule.QUERY_CACHE_EVERYTHING, true))
.setSettings(Settings.builder().put(IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING.getKey(), true))
.addMapping("type1", "field1", "type=string", "field2", "type=string")
);
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")

View File

@ -470,7 +470,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase {
public void testRequestCache() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test")
.setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED, true))
.setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true))
.addMapping("type1", "field1", "type=string", "field2", "type=string")
);
client().prepareIndex("test", "type1", "1").setSource("field1", "value1")

View File

@ -372,7 +372,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
public void testQueryCache() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test")
.setSettings(Settings.builder().put(IndexModule.QUERY_CACHE_EVERYTHING, true))
.setSettings(Settings.builder().put(IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING.getKey(), true))
.addMapping("type1", "field1", "type=string", "field2", "type=string")
);
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2")
@ -396,7 +396,7 @@ public class FieldLevelSecurityTests extends ShieldIntegTestCase {
public void testRequestCache() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test")
.setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED, true))
.setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true))
.addMapping("type1", "field1", "type=string", "field2", "type=string")
);
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2")

View File

@ -41,7 +41,7 @@ public class ShieldF {
settings.put("security.manager.enabled", "false");
// Disable Marvel to prevent cluster activity
settings.put("marvel.enabled", "false");
settings.put(IndexModule.QUERY_CACHE_TYPE, ShieldPlugin.OPT_OUT_QUERY_CACHE);
settings.put(IndexModule.INDEX_QUERY_CACHE_TYPE_SETTING.getKey(), ShieldPlugin.OPT_OUT_QUERY_CACHE);
settings.put("cluster.name", ShieldF.class.getSimpleName());
String homeDir = System.getProperty("es.path.home");

View File

@ -167,7 +167,7 @@ public class IndexAuditTrailTests extends ShieldIntegTestCase {
// For tests we forcefully configure Shield's custom query cache because the test framework randomizes the query cache impl,
// but if shield is disabled then we don't need to forcefully set the query cache
if (useShield == false) {
builder.remove(IndexModule.QUERY_CACHE_TYPE);
builder.remove(IndexModule.INDEX_QUERY_CACHE_TYPE_SETTING.getKey());
}
return builder.build();
}

View File

@ -156,7 +156,7 @@ public class FieldDataCacheWithFieldSubsetReaderTests extends ESTestCase {
.numberOfReplicas(0)
.creationDate(System.currentTimeMillis())
.build();
return new IndexSettings(indexMetaData, settings, Collections.emptyList());
return new IndexSettings(indexMetaData, settings);
}
private static class DummyAccountingFieldDataCache implements IndexFieldDataCache {

View File

@ -10,6 +10,7 @@ import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.shield.authc.support.SecuredString;
@ -110,7 +111,7 @@ public abstract class ShieldIntegTestCase extends ESIntegTestCase {
@Override
protected void before() throws Throwable {
Scope currentClusterScope = getCurrentClusterScope();
switch(currentClusterScope) {
switch (currentClusterScope) {
case SUITE:
if (customShieldSettingsSource == null) {
customShieldSettingsSource = new CustomShieldSettingsSource(sslTransportEnabled(), createTempDir(), currentClusterScope);
@ -176,6 +177,7 @@ public abstract class ShieldIntegTestCase extends ESIntegTestCase {
/**
* Allows for us to get the system key that is being used for the cluster
*
* @return the system key bytes
*/
protected byte[] systemKey() {
@ -301,4 +303,4 @@ public abstract class ShieldIntegTestCase extends ESIntegTestCase {
assertNoTimeout(clusterHealthResponse);
assertThat(clusterHealthResponse.getStatus(), is(ClusterHealthStatus.GREEN));
}
}
}

View File

@ -136,7 +136,7 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ
.put("shield.authz.store.files.roles", writeFile(folder, "roles.yml", configRoles()))
// Test framework sometimes randomily selects the 'index' or 'none' cache and that makes the
// validation in ShieldPlugin fail.
.put(IndexModule.QUERY_CACHE_TYPE, ShieldPlugin.OPT_OUT_QUERY_CACHE)
.put(IndexModule.INDEX_QUERY_CACHE_TYPE_SETTING.getKey(), ShieldPlugin.OPT_OUT_QUERY_CACHE)
.put(getNodeSSLSettings());
setUser(builder, nodeClientUsername(), nodeClientPassword());

View File

@ -6,11 +6,19 @@
package org.elasticsearch.watcher.support;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.watcher.WatcherModule;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Function;
import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
@ -20,6 +28,14 @@ import static org.hamcrest.core.Is.is;
*/
@ESIntegTestCase.ClusterScope(scope = TEST, numClientNodes = 0, transportClientRatio = 0, randomDynamicTemplates = false, numDataNodes = 1)
public class WatcherIndexTemplateRegistryTests extends AbstractWatcherIntegrationTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
ArrayList<Class<? extends Plugin>> plugins = new ArrayList<>(super.nodePlugins());
plugins.add(SettingTestPlugin.class);
return plugins;
}
public void testTemplates() throws Exception {
assertAcked(
client().admin().cluster().prepareUpdateSettings()
@ -55,4 +71,21 @@ public class WatcherIndexTemplateRegistryTests extends AbstractWatcherIntegratio
}
});
}
public static class SettingTestPlugin extends Plugin {
public String name() {
return "watcher-index-template-registry-settings-plugin";
}
@Override
public String description() {
return "installs a setting this test needs";
}
public static final Setting<String> KEY_1 = new Setting<>("index.key1", "", Function.identity(), false, Setting.Scope.INDEX);
public void onModule(SettingsModule module) {
module.registerSetting(KEY_1);
}
}
}

View File

@ -32,6 +32,7 @@ import org.elasticsearch.shield.crypto.InternalCryptoService;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.TestCluster;
import org.elasticsearch.test.store.MockFSIndexStore;
import org.elasticsearch.test.transport.AssertingLocalTransport;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.watcher.WatcherLifeCycleService;
@ -124,7 +125,6 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
//TODO: for now lets isolate watcher tests from marvel (randomize this later)
.put("marvel.enabled", false)
// we do this by default in core, but for watcher this isn't needed and only adds noise.
.put("index.store.mock.check_index_on_close", false)
.put("scroll.size", randomIntBetween(1, 100))
@ -147,6 +147,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
Set<Class<? extends Plugin>> plugins = new HashSet<>(super.getMockPlugins());
plugins.remove(MockTransportService.TestPlugin.class); // shield has its own transport service
plugins.remove(AssertingLocalTransport.TestPlugin.class); // shield has its own transport
plugins.add(MockFSIndexStore.TestPlugin.class); // we have to explicitly add it otherwise we will fail to set the check_index_on_close setting
return plugins;
}
@ -676,7 +677,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
.put("shield.audit.enabled", auditLogsEnabled)
// Test framework sometimes randomily selects the 'index' or 'none' cache and that makes the
// validation in ShieldPlugin fail. Shield can only run with this query cache impl
.put(IndexModule.QUERY_CACHE_TYPE, ShieldPlugin.OPT_OUT_QUERY_CACHE)
.put(IndexModule.INDEX_QUERY_CACHE_TYPE_SETTING.getKey(), ShieldPlugin.OPT_OUT_QUERY_CACHE)
.build();
} catch (IOException ex) {
throw new RuntimeException("failed to build settings for shield", ex);