Merge branch 'master' into fix/remove-requirefrom

Original commit: elastic/x-pack-elasticsearch@7bc1e240fc
This commit is contained in:
Joe Fleming 2016-04-08 10:05:23 -07:00
commit 4010067d35
71 changed files with 647 additions and 572 deletions

View File

@ -28,7 +28,7 @@ import java.util.Set;
@SuppressForbidden(reason = "gradle is broken and tries to run me as a test") @SuppressForbidden(reason = "gradle is broken and tries to run me as a test")
public final class MessyTestUtils { public final class MessyTestUtils {
public static ScriptServiceProxy getScriptServiceProxy(ThreadPool tp) throws Exception { public static ScriptServiceProxy getScriptServiceProxy(ThreadPool tp) throws Exception {
Settings settings = Settings.settingsBuilder() Settings settings = Settings.builder()
.put("script.inline", "true") .put("script.inline", "true")
.put("script.indexed", "true") .put("script.indexed", "true")
.put("path.home", LuceneTestCase.createTempDir()) .put("path.home", LuceneTestCase.createTempDir())

View File

@ -78,7 +78,7 @@ public class ScriptConditionTests extends ESTestCase {
} }
public void testParserValid() throws Exception { public void testParserValid() throws Exception {
ScriptConditionFactory factory = new ScriptConditionFactory(Settings.settingsBuilder().build(), getScriptServiceProxy(tp)); ScriptConditionFactory factory = new ScriptConditionFactory(Settings.builder().build(), getScriptServiceProxy(tp));
XContentBuilder builder = createConditionContent("ctx.payload.hits.total > 1", null, ScriptType.INLINE); XContentBuilder builder = createConditionContent("ctx.payload.hits.total > 1", null, ScriptType.INLINE);
@ -105,7 +105,7 @@ public class ScriptConditionTests extends ESTestCase {
} }
public void testParserInvalid() throws Exception { public void testParserInvalid() throws Exception {
ScriptConditionFactory factory = new ScriptConditionFactory(Settings.settingsBuilder().build(), getScriptServiceProxy(tp)); ScriptConditionFactory factory = new ScriptConditionFactory(Settings.builder().build(), getScriptServiceProxy(tp));
XContentBuilder builder = XContentFactory.jsonBuilder(); XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject().endObject(); builder.startObject().endObject();
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes()); XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
@ -120,7 +120,7 @@ public class ScriptConditionTests extends ESTestCase {
} }
public void testScriptConditionParserBadScript() throws Exception { public void testScriptConditionParserBadScript() throws Exception {
ScriptConditionFactory conditionParser = new ScriptConditionFactory(Settings.settingsBuilder().build(), getScriptServiceProxy(tp)); ScriptConditionFactory conditionParser = new ScriptConditionFactory(Settings.builder().build(), getScriptServiceProxy(tp));
ScriptType scriptType = randomFrom(ScriptType.values()); ScriptType scriptType = randomFrom(ScriptType.values());
String script; String script;
switch (scriptType) { switch (scriptType) {
@ -146,7 +146,7 @@ public class ScriptConditionTests extends ESTestCase {
} }
public void testScriptConditionParser_badLang() throws Exception { public void testScriptConditionParser_badLang() throws Exception {
ScriptConditionFactory conditionParser = new ScriptConditionFactory(Settings.settingsBuilder().build(), getScriptServiceProxy(tp)); ScriptConditionFactory conditionParser = new ScriptConditionFactory(Settings.builder().build(), getScriptServiceProxy(tp));
ScriptType scriptType = ScriptType.INLINE; ScriptType scriptType = ScriptType.INLINE;
String script = "return true"; String script = "return true";
XContentBuilder builder = createConditionContent(script, "not_a_valid_lang", scriptType); XContentBuilder builder = createConditionContent(script, "not_a_valid_lang", scriptType);

View File

@ -24,7 +24,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
@ -68,7 +67,7 @@ public class TransformIT extends AbstractWatcherIntegrationTestCase {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
//Set path so ScriptService will pick up the test scripts //Set path so ScriptService will pick up the test scripts
return settingsBuilder().put(super.nodeSettings(nodeOrdinal)).put("path.conf", configDir.toString()).build(); return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put("path.conf", configDir.toString()).build();
} }
public void testScriptTransform() throws Exception { public void testScriptTransform() throws Exception {

View File

@ -56,7 +56,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
@ -110,7 +109,7 @@ public class SearchInputIT extends ESIntegTestCase {
//Set path so ScriptService will pick up the test scripts //Set path so ScriptService will pick up the test scripts
return settingsBuilder().put(super.nodeSettings(nodeOrdinal)) return Settings.builder().put(super.nodeSettings(nodeOrdinal))
.put("path.conf", configPath).build(); .put("path.conf", configPath).build();
} }

View File

@ -65,7 +65,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
@ -122,7 +121,7 @@ public class SearchTransformIT extends ESIntegTestCase {
throw new RuntimeException("failed to copy mustache template"); throw new RuntimeException("failed to copy mustache template");
} }
//Set path so ScriptService will pick up the test scripts //Set path so ScriptService will pick up the test scripts
return settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
// we're not extending from the base watcher test case, so we should prevent the watcher plugin from being loaded // we're not extending from the base watcher test case, so we should prevent the watcher plugin from being loaded
.put("path.conf", configPath).build(); .put("path.conf", configPath).build();
@ -137,7 +136,7 @@ public class SearchTransformIT extends ESIntegTestCase {
@Override @Override
public Settings indexSettings() { public Settings indexSettings() {
return settingsBuilder() return Settings.builder()
.put(super.indexSettings()) .put(super.indexSettings())
// we have to test this on an index that has at least 2 shards. Otherwise when searching indices with // we have to test this on an index that has at least 2 shards. Otherwise when searching indices with

View File

@ -71,8 +71,6 @@ compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-
ext.expansions = [ ext.expansions = [
'project.version': version, 'project.version': version,
// Used in marvel index templates
'monitoring.template.version': '1',
// Used in watcher index templates // Used in watcher index templates
'watcher.template.version': '1', 'watcher.template.version': '1',
] ]

View File

@ -16,7 +16,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregatorBuilder;
import org.elasticsearch.search.aggregations.bucket.sampler.SamplerParser;
import org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms; import org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregator; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregator;

View File

@ -42,7 +42,7 @@ public abstract class AbstractLicensesConsumerPluginIntegrationTestCase extends
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
// this setting is only used in tests // this setting is only used in tests
.put("_trial_license_duration_in_seconds", trialLicenseDurationInSeconds) .put("_trial_license_duration_in_seconds", trialLicenseDurationInSeconds)

View File

@ -34,7 +34,7 @@ public class LicensesPluginIntegrationTests extends AbstractLicensesIntegrationT
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
// this setting is only used in tests // this setting is only used in tests
.put("_trial_license_duration_in_seconds", trialLicenseDurationInSeconds) .put("_trial_license_duration_in_seconds", trialLicenseDurationInSeconds)

View File

@ -33,13 +33,13 @@ public class LicensesPluginsIntegrationTests extends AbstractLicensesIntegration
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.build(); .build();
} }
private Settings nodeSettingsWithConsumerPlugin(int trialLicenseDuration) { private Settings nodeSettingsWithConsumerPlugin(int trialLicenseDuration) {
return Settings.settingsBuilder() return Settings.builder()
.put(super.nodeSettings(0)) .put(super.nodeSettings(0))
// this setting is only used in tests // this setting is only used in tests
.put("_trial_license_duration_in_seconds", trialLicenseDuration) .put("_trial_license_duration_in_seconds", trialLicenseDuration)

View File

@ -25,7 +25,7 @@ import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
public class LicensesServiceNodeTests extends AbstractLicensesIntegrationTestCase { public class LicensesServiceNodeTests extends AbstractLicensesIntegrationTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true) .put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build(); .build();

View File

@ -13,7 +13,6 @@ import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import java.util.Collections; import java.util.Collections;
@ -23,7 +22,6 @@ import java.util.function.Function;
import static org.elasticsearch.common.settings.Setting.Property; import static org.elasticsearch.common.settings.Setting.Property;
import static org.elasticsearch.common.settings.Setting.boolSetting; import static org.elasticsearch.common.settings.Setting.boolSetting;
import static org.elasticsearch.common.settings.Setting.groupSetting; import static org.elasticsearch.common.settings.Setting.groupSetting;
import static org.elasticsearch.common.settings.Setting.intSetting;
import static org.elasticsearch.common.settings.Setting.listSetting; import static org.elasticsearch.common.settings.Setting.listSetting;
import static org.elasticsearch.common.settings.Setting.timeSetting; import static org.elasticsearch.common.settings.Setting.timeSetting;
@ -121,13 +119,6 @@ public class MarvelSettings extends AbstractComponent {
HISTORY_DURATION_MINIMUM, // minimum value HISTORY_DURATION_MINIMUM, // minimum value
Property.Dynamic, Property.NodeScope); Property.Dynamic, Property.NodeScope);
/**
* The index setting that holds the template version
*/
public static final Setting<Integer> INDEX_TEMPLATE_VERSION =
intSetting("index.xpack.monitoring.template.version", MarvelTemplateUtils.TEMPLATE_VERSION,
Property.Dynamic, Property.IndexScope);
/** /**
* Settings/Options per configured exporter * Settings/Options per configured exporter
*/ */
@ -147,7 +138,6 @@ public class MarvelSettings extends AbstractComponent {
module.registerSetting(HISTORY_DURATION); module.registerSetting(HISTORY_DURATION);
module.registerSetting(EXPORTERS_SETTINGS); module.registerSetting(EXPORTERS_SETTINGS);
module.registerSetting(ENABLED); module.registerSetting(ENABLED);
module.registerSetting(INDEX_TEMPLATE_VERSION);
module.registerSettingsFilter("xpack.monitoring.agent.exporters.*.auth.*"); module.registerSettingsFilter("xpack.monitoring.agent.exporters.*.auth.*");
module.registerSettingsFilter("xpack.monitoring.agent.exporters.*.ssl.*"); module.registerSettingsFilter("xpack.monitoring.agent.exporters.*.ssl.*");

View File

@ -5,103 +5,80 @@
*/ */
package org.elasticsearch.marvel.agent.exporter; package org.elasticsearch.marvel.agent.exporter;
import org.elasticsearch.common.Strings; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.compress.NotXContentException;
import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.xcontent.XContentHelper;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.Locale;
import java.util.regex.Pattern;
public final class MarvelTemplateUtils { public final class MarvelTemplateUtils {
static final String INDEX_TEMPLATE_FILE = "/monitoring-es.json"; private static final String TEMPLATE_FILE = "/monitoring-%s.json";
static final String INDEX_TEMPLATE_NAME_PREFIX = ".monitoring-es-"; private static final String TEMPLATE_VERSION_PROPERTY = Pattern.quote("${monitoring.template.version}");
static final String DATA_TEMPLATE_FILE = "/monitoring-data.json"; /** Current version of es and data templates **/
static final String DATA_TEMPLATE_NAME_PREFIX = ".monitoring-data-"; public static final Integer TEMPLATE_VERSION = 2;
static final String PROPERTIES_FILE = "/monitoring.properties";
static final String TEMPLATE_VERSION_PROPERTY = "template.version";
public static final Integer TEMPLATE_VERSION = loadTemplateVersion();
private MarvelTemplateUtils() { private MarvelTemplateUtils() {
} }
/** /**
* Loads the default template for the timestamped indices * Loads a built-in template and returns its source.
*/ */
public static byte[] loadTimestampedIndexTemplate() { public static String loadTemplate(String id, Integer version) {
String resource = String.format(Locale.ROOT, TEMPLATE_FILE, id);
try { try {
return load(INDEX_TEMPLATE_FILE); BytesReference source = load(resource);
} catch (IOException e) { validate(source);
throw new IllegalStateException("unable to load monitoring template", e);
return filter(source, version);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to load monitoring template [" + resource + "]", e);
} }
} }
/** /**
* Loads the default template for the data index * Loads a resource from the classpath and returns it as a {@link BytesReference}
*/ */
public static byte[] loadDataIndexTemplate() { static BytesReference load(String name) throws IOException {
try {
return load(DATA_TEMPLATE_FILE);
} catch (IOException e) {
throw new IllegalStateException("unable to load monitoring data template", e);
}
}
/**
* Loads a resource with a given name and returns it as a byte array.
*/
static byte[] load(String name) throws IOException {
try (InputStream is = MarvelTemplateUtils.class.getResourceAsStream(name)) { try (InputStream is = MarvelTemplateUtils.class.getResourceAsStream(name)) {
ByteArrayOutputStream out = new ByteArrayOutputStream(); try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
Streams.copy(is, out); Streams.copy(is, out);
return out.toByteArray(); return new BytesArray(out.toByteArray());
}
} }
} }
/** /**
* Loads the current version of templates * Parses and validates that the source is not empty.
*
* When executing tests in Intellij, the properties file might not be
* resolved: try running 'gradle processResources' first.
*/ */
static Integer loadTemplateVersion() { static void validate(BytesReference source) {
try (InputStream is = MarvelTemplateUtils.class.getResourceAsStream(PROPERTIES_FILE)) { if (source == null) {
Properties properties = new Properties(); throw new ElasticsearchParseException("Monitoring template must not be null");
properties.load(is);
String version = properties.getProperty(TEMPLATE_VERSION_PROPERTY);
if (Strings.hasLength(version)) {
return Integer.parseInt(version);
} }
throw new IllegalArgumentException("no monitoring template version found");
} catch (NumberFormatException e) { try {
throw new IllegalArgumentException("failed to parse monitoring template version"); XContentHelper.convertToMap(source, false).v2();
} catch (IOException e) { } catch (NotXContentException e) {
throw new IllegalArgumentException("failed to load monitoring template version"); throw new ElasticsearchParseException("Monitoring template must not be empty");
} catch (Exception e) {
throw new ElasticsearchParseException("Invalid monitoring template", e);
} }
} }
public static String indexTemplateName() { /**
return indexTemplateName(TEMPLATE_VERSION); * Filters the source: replaces any template version property with the version number
} */
static String filter(BytesReference source, Integer version) {
public static String indexTemplateName(Integer version) { return Pattern.compile(TEMPLATE_VERSION_PROPERTY)
return templateName(INDEX_TEMPLATE_NAME_PREFIX, version); .matcher(source.toUtf8())
} .replaceAll(String.valueOf(version));
public static String dataTemplateName() {
return dataTemplateName(TEMPLATE_VERSION);
}
public static String dataTemplateName(Integer version) {
return templateName(DATA_TEMPLATE_NAME_PREFIX, version);
}
static String templateName(String prefix, Integer version) {
assert version != null && version >= 0 : "version must be not null and greater or equal to zero";
return prefix + String.valueOf(version);
} }
} }

View File

@ -25,7 +25,6 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.marvel.agent.exporter.ExportBulk; import org.elasticsearch.marvel.agent.exporter.ExportBulk;
import org.elasticsearch.marvel.agent.exporter.ExportException; import org.elasticsearch.marvel.agent.exporter.ExportException;
import org.elasticsearch.marvel.agent.exporter.Exporter; import org.elasticsearch.marvel.agent.exporter.Exporter;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
import org.elasticsearch.marvel.agent.resolver.ResolversRegistry; import org.elasticsearch.marvel.agent.resolver.ResolversRegistry;
@ -47,6 +46,7 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.AccessController; import java.security.AccessController;
@ -55,6 +55,8 @@ import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/** /**
* *
@ -107,11 +109,6 @@ public class HttpExporter extends Exporter {
volatile boolean checkedAndUploadedIndexTemplate = false; volatile boolean checkedAndUploadedIndexTemplate = false;
volatile boolean supportedClusterVersion = false; volatile boolean supportedClusterVersion = false;
/**
* Version number of built-in templates
**/
private final Integer templateVersion;
boolean keepAlive; boolean keepAlive;
final ConnectionKeepAliveWorker keepAliveWorker; final ConnectionKeepAliveWorker keepAliveWorker;
Thread keepAliveThread; Thread keepAliveThread;
@ -145,14 +142,16 @@ public class HttpExporter extends Exporter {
sslSocketFactory = createSSLSocketFactory(config.settings().getAsSettings(SSL_SETTING)); sslSocketFactory = createSSLSocketFactory(config.settings().getAsSettings(SSL_SETTING));
hostnameVerification = config.settings().getAsBoolean(SSL_HOSTNAME_VERIFICATION_SETTING, true); hostnameVerification = config.settings().getAsBoolean(SSL_HOSTNAME_VERIFICATION_SETTING, true);
// Loads the current version number of built-in templates
templateVersion = MarvelTemplateUtils.TEMPLATE_VERSION;
if (templateVersion == null) {
throw new IllegalStateException("unable to find built-in template version");
}
resolvers = new ResolversRegistry(config.settings()); resolvers = new ResolversRegistry(config.settings());
logger.debug("initialized with hosts [{}], index prefix [{}], template version [{}]", // Checks that required templates are loaded
Strings.arrayToCommaDelimitedString(hosts), MonitoringIndexNameResolver.PREFIX, templateVersion); for (MonitoringIndexNameResolver resolver : resolvers) {
if (resolver.template() == null) {
throw new IllegalStateException("unable to find built-in template " + resolver.templateName());
}
}
logger.debug("initialized with hosts [{}], index prefix [{}]",
Strings.arrayToCommaDelimitedString(hosts), MonitoringIndexNameResolver.PREFIX);
} }
ResolversRegistry getResolvers() { ResolversRegistry getResolvers() {
@ -424,24 +423,18 @@ public class HttpExporter extends Exporter {
* @return true if template exists or was uploaded successfully. * @return true if template exists or was uploaded successfully.
*/ */
private boolean checkAndUploadIndexTemplate(final String host) { private boolean checkAndUploadIndexTemplate(final String host) {
String templateName = MarvelTemplateUtils.indexTemplateName(templateVersion); // List of distinct templates
boolean templateInstalled = hasTemplate(templateName, host); Map<String, String> templates = StreamSupport.stream(new ResolversRegistry(Settings.EMPTY).spliterator(), false)
.collect(Collectors.toMap(MonitoringIndexNameResolver::templateName, MonitoringIndexNameResolver::template, (a, b) -> a));
// Works like LocalExporter on master: for (Map.Entry<String, String> template : templates.entrySet()) {
// Install the index template for timestamped indices first, so that other nodes can ship data if (hasTemplate(template.getKey(), host) == false) {
if (!templateInstalled) { logger.debug("template [{}] not found", template.getKey());
logger.debug("could not find existing monitoring template, installing a new one"); if (!putTemplate(host, template.getKey(), template.getValue())) {
if (!putTemplate(host, templateName, MarvelTemplateUtils.loadTimestampedIndexTemplate())) {
return false; return false;
} }
} } else {
logger.debug("template [{}] found", template.getKey());
// Install the index template for data index
templateName = MarvelTemplateUtils.dataTemplateName(templateVersion);
if (!hasTemplate(templateName, host)) {
logger.debug("could not find existing monitoring template for data index, installing a new one");
if (!putTemplate(host, templateName, MarvelTemplateUtils.loadDataIndexTemplate())) {
return false;
} }
} }
return true; return true;
@ -481,7 +474,7 @@ public class HttpExporter extends Exporter {
return false; return false;
} }
boolean putTemplate(String host, String template, byte[] source) { boolean putTemplate(String host, String template, String source) {
logger.debug("installing template [{}]", template); logger.debug("installing template [{}]", template);
HttpURLConnection connection = null; HttpURLConnection connection = null;
try { try {
@ -492,13 +485,13 @@ public class HttpExporter extends Exporter {
} }
// Uploads the template and closes the outputstream // Uploads the template and closes the outputstream
Streams.copy(source, connection.getOutputStream()); Streams.copy(source.getBytes(StandardCharsets.UTF_8), connection.getOutputStream());
if (connection.getResponseCode() != 200 && connection.getResponseCode() != 201) { if (connection.getResponseCode() != 200 && connection.getResponseCode() != 201) {
logConnectionError("error adding the monitoring template [" + template + "] to [" + host + "]", connection); logConnectionError("error adding the monitoring template [" + template + "] to [" + host + "]", connection);
return false; return false;
} }
logger.info("monitoring template [{}] updated to version [{}]", template, templateVersion); logger.info("monitoring template [{}] updated ", template);
return true; return true;
} catch (IOException e) { } catch (IOException e) {
logger.error("failed to update monitoring template [{}] on host [{}]:\n{}", template, host, e.getMessage()); logger.error("failed to update monitoring template [{}] on host [{}]:\n{}", template, host, e.getMessage());

View File

@ -21,11 +21,11 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.marvel.agent.exporter.ExportBulk; import org.elasticsearch.marvel.agent.exporter.ExportBulk;
import org.elasticsearch.marvel.agent.exporter.Exporter; import org.elasticsearch.marvel.agent.exporter.Exporter;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
import org.elasticsearch.marvel.agent.resolver.ResolversRegistry; import org.elasticsearch.marvel.agent.resolver.ResolversRegistry;
@ -35,6 +35,7 @@ import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -56,23 +57,21 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
private final AtomicReference<State> state = new AtomicReference<>(State.INITIALIZED); private final AtomicReference<State> state = new AtomicReference<>(State.INITIALIZED);
/** Version number of built-in templates **/
private final Integer templateVersion;
public LocalExporter(Exporter.Config config, MonitoringClientProxy client, public LocalExporter(Exporter.Config config, MonitoringClientProxy client,
ClusterService clusterService, CleanerService cleanerService) { ClusterService clusterService, CleanerService cleanerService) {
super(TYPE, config); super(TYPE, config);
this.client = client; this.client = client;
this.clusterService = clusterService; this.clusterService = clusterService;
this.cleanerService = cleanerService; this.cleanerService = cleanerService;
this.resolvers = new ResolversRegistry(config.settings());
// Loads the current version number of built-in templates // Checks that required templates are loaded
templateVersion = MarvelTemplateUtils.TEMPLATE_VERSION; for (MonitoringIndexNameResolver resolver : resolvers) {
if (templateVersion == null) { if (resolver.template() == null) {
throw new IllegalStateException("unable to find built-in template version"); throw new IllegalStateException("unable to find built-in template " + resolver.templateName());
}
} }
resolvers = new ResolversRegistry(config.settings());
clusterService.add(this); clusterService.add(this);
cleanerService.add(this); cleanerService.add(this);
} }
@ -117,21 +116,23 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
return null; return null;
} }
String templateName = MarvelTemplateUtils.indexTemplateName(templateVersion); // List of distinct templates
boolean templateInstalled = hasTemplate(templateName, clusterState); Map<String, String> templates = StreamSupport.stream(new ResolversRegistry(Settings.EMPTY).spliterator(), false)
.collect(Collectors.toMap(MonitoringIndexNameResolver::templateName, MonitoringIndexNameResolver::template, (a, b) -> a));
// if this is not the master, we'll just look to see if the monitoring timestamped template is already
// installed and if so, if it has a compatible version. If it is (installed and compatible) // if this is not the master, we'll just look to see if the monitoring templates are installed.
// we'll be able to start this exporter. Otherwise, we'll just wait for a new cluster state. // If they all are, we'll be able to start this exporter. Otherwise, we'll just wait for a new cluster state.
if (clusterService.state().nodes().isLocalNodeElectedMaster() == false) { if (clusterService.state().nodes().isLocalNodeElectedMaster() == false) {
// We only need to check the index template for timestamped indices for (String template : templates.keySet()) {
if (templateInstalled == false) { if (hasTemplate(template, clusterState) == false) {
// the template for timestamped indices is not yet installed in the given cluster state, we'll wait. // the required template is not yet installed in the given cluster state, we'll wait.
logger.debug("monitoring index template does not exist, so service cannot start"); logger.debug("monitoring index template [{}] does not exist, so service cannot start", template);
return null; return null;
} }
}
logger.debug("monitoring index template found, service can start"); logger.debug("monitoring index templates are installed, service can start");
} else { } else {
@ -143,24 +144,18 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
return null; return null;
} }
// Install the index template for timestamped indices first, so that other nodes can ship data // Check that each required template exist, installing it if needed
if (templateInstalled == false) { for (Map.Entry<String, String> template : templates.entrySet()) {
logger.debug("could not find existing monitoring template for timestamped indices, installing a new one"); if (hasTemplate(template.getKey(), clusterState) == false) {
putTemplate(templateName, MarvelTemplateUtils.loadTimestampedIndexTemplate()); logger.debug("template [{}] not found", template.getKey());
// we'll get that template on the next cluster state update putTemplate(template.getKey(), template.getValue());
return null; return null;
} else {
logger.debug("template [{}] found", template.getKey());
}
} }
// Install the index template for data index logger.debug("monitoring index templates are installed on master node, service can start");
templateName = MarvelTemplateUtils.dataTemplateName(templateVersion);
if (hasTemplate(templateName, clusterState) == false) {
logger.debug("could not find existing monitoring template for data index, installing a new one");
putTemplate(templateName, MarvelTemplateUtils.loadDataIndexTemplate());
// we'll get that template on the next cluster state update
return null;
}
logger.debug("monitoring index template found on master node, service can start");
} }
if (state.compareAndSet(State.INITIALIZED, State.RUNNING)) { if (state.compareAndSet(State.INITIALIZED, State.RUNNING)) {
@ -197,7 +192,7 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
return templates.size() > 0; return templates.size() > 0;
} }
void putTemplate(String template, byte[] source) { void putTemplate(String template, String source) {
logger.debug("installing template [{}]",template); logger.debug("installing template [{}]",template);
PutIndexTemplateRequest request = new PutIndexTemplateRequest(template).source(source); PutIndexTemplateRequest request = new PutIndexTemplateRequest(template).source(source);

View File

@ -16,6 +16,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
@ -23,6 +24,7 @@ import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormatter;
import java.io.IOException; import java.io.IOException;
import java.util.Locale;
import java.util.function.Function; import java.util.function.Function;
/** /**
@ -100,6 +102,16 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
} }
} }
/**
* @return the template name that is required by the resolver.
*/
public abstract String templateName();
/**
* @return the template source required by the resolver
*/
public abstract String template();
int getVersion() { int getVersion() {
return version; return version;
} }
@ -145,6 +157,16 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
public String indexPattern() { public String indexPattern() {
return index; return index;
} }
@Override
public String templateName() {
return String.format(Locale.ROOT, "%s-%s-%d", PREFIX, DATA, getVersion());
}
@Override
public String template() {
return MarvelTemplateUtils.loadTemplate(DATA, getVersion());
}
} }
/** /**
@ -188,6 +210,16 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
return null; return null;
} }
@Override
public String templateName() {
return String.format(Locale.ROOT, "%s-%s-%d", PREFIX, getId(), getVersion());
}
@Override
public String template() {
return MarvelTemplateUtils.loadTemplate(getId(), getVersion());
}
String getId() { String getId() {
return system.getSystem(); return system.getSystem();
} }

View File

@ -43,14 +43,17 @@ import static org.elasticsearch.marvel.MonitoredSystem.ES;
public class ResolversRegistry implements Iterable<MonitoringIndexNameResolver> { public class ResolversRegistry implements Iterable<MonitoringIndexNameResolver> {
private static final int ES_TEMPLATE_VERSION = MarvelTemplateUtils.TEMPLATE_VERSION;
private static final int KIBANA_TEMPLATE_VERSION = MarvelTemplateUtils.TEMPLATE_VERSION;
private final List<Registration> registrations = new ArrayList<>(); private final List<Registration> registrations = new ArrayList<>();
public ResolversRegistry(Settings settings) { public ResolversRegistry(Settings settings) {
// register built-in defaults resolvers // register built-in defaults resolvers
registerBuiltIn(ES, MarvelTemplateUtils.TEMPLATE_VERSION, settings); registerBuiltIn(ES, ES_TEMPLATE_VERSION, settings);
// register resolvers for external applications // register resolvers for monitored systems
registerKibana(settings); registerMonitoredSystem(MonitoredSystem.KIBANA, KIBANA_TEMPLATE_VERSION, settings);
} }
/** /**
@ -70,11 +73,11 @@ public class ResolversRegistry implements Iterable<MonitoringIndexNameResolver>
} }
/** /**
* Registers resolvers for Kibana * Registers resolvers for monitored systems
*/ */
private void registerKibana(Settings settings) { private void registerMonitoredSystem(MonitoredSystem id, int version, Settings settings) {
final MonitoringBulkResolver kibana = new MonitoringBulkResolver(MonitoredSystem.KIBANA, 0, settings); final MonitoringBulkResolver resolver = new MonitoringBulkResolver(id, version, settings);
registrations.add(resolveByClassSystemVersion(MonitoringBulkDoc.class, MonitoredSystem.KIBANA, Version.CURRENT, kibana)); registrations.add(resolveByClassSystemVersion(MonitoringBulkDoc.class, id, Version.CURRENT, resolver));
} }
/** /**

View File

@ -0,0 +1,57 @@
{
"template": ".monitoring-kibana-${monitoring.template.version}-*",
"settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 1,
"index.codec": "best_compression"
},
"mappings": {
"_default_": {
"_all": {
"enabled": false
},
"properties": {
"cluster_uuid": {
"type": "keyword"
},
"timestamp": {
"type": "date",
"format": "date_time"
},
"source_node": {
"properties": {
"uuid": {
"type": "keyword"
},
"host": {
"type": "keyword"
},
"transport_address": {
"type": "keyword"
},
"ip": {
"type": "keyword"
},
"name": {
"type": "keyword"
},
"attributes": {
"dynamic": true,
"properties": {
"data": {
"type": "boolean"
},
"master": {
"type": "boolean"
},
"client": {
"type": "boolean"
}
}
}
}
}
}
}
}
}

View File

@ -1 +0,0 @@
template.version=${monitoring.template.version}

View File

@ -39,7 +39,7 @@ public class ClusterStateCollectorTests extends AbstractCollectorTestCase {
public void testClusterStateCollectorOneIndex() throws Exception { public void testClusterStateCollectorOneIndex() throws Exception {
int nbShards = randomIntBetween(1, 5); int nbShards = randomIntBetween(1, 5);
assertAcked(prepareCreate("test").setSettings(Settings.settingsBuilder() assertAcked(prepareCreate("test").setSettings(Settings.builder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, nbShards) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, nbShards)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.build())); .build()));
@ -65,7 +65,7 @@ public class ClusterStateCollectorTests extends AbstractCollectorTestCase {
for (int i = 0; i < nbIndices; i++) { for (int i = 0; i < nbIndices; i++) {
shardsPerIndex[i] = randomIntBetween(1, 5); shardsPerIndex[i] = randomIntBetween(1, 5);
nbShards += shardsPerIndex[i]; nbShards += shardsPerIndex[i];
assertAcked(prepareCreate("test-" + i).setSettings(Settings.settingsBuilder() assertAcked(prepareCreate("test-" + i).setSettings(Settings.builder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, shardsPerIndex[i]) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, shardsPerIndex[i])
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.build())); .build()));

View File

@ -26,7 +26,6 @@ import java.util.Map;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.anyOf;
@ -46,7 +45,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), activeOnly) .put(MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), activeOnly)
.put(MarvelSettings.INDICES.getKey(), indexName) .put(MarvelSettings.INDICES.getKey(), indexName)
@ -66,7 +65,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
assertThat(results, is(empty())); assertThat(results, is(empty()));
logger.info("--> create index [{}] on node [{}]", indexName, node1); logger.info("--> create index [{}] on node [{}]", indexName, node1);
assertAcked(prepareCreate(indexName, 1, settingsBuilder().put(SETTING_NUMBER_OF_SHARDS, 3).put(SETTING_NUMBER_OF_REPLICAS, 1))); assertAcked(prepareCreate(indexName, 1, Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 3).put(SETTING_NUMBER_OF_REPLICAS, 1)));
logger.info("--> indexing sample data"); logger.info("--> indexing sample data");
final int numDocs = between(50, 150); final int numDocs = between(50, 150);
@ -169,7 +168,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
} }
public void testEmptyCluster() throws Exception { public void testEmptyCluster() throws Exception {
final String node = internalCluster().startNode(settingsBuilder().put(MarvelSettings.INDICES.getKey(), final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(),
Strings.EMPTY_ARRAY)); Strings.EMPTY_ARRAY));
waitForNoBlocksOnNode(node); waitForNoBlocksOnNode(node);
@ -181,7 +180,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
} }
public void testEmptyClusterAllIndices() throws Exception { public void testEmptyClusterAllIndices() throws Exception {
final String node = internalCluster().startNode(settingsBuilder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL)); final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL));
waitForNoBlocksOnNode(node); waitForNoBlocksOnNode(node);
try { try {
@ -192,7 +191,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
} }
public void testEmptyClusterMissingIndex() throws Exception { public void testEmptyClusterMissingIndex() throws Exception {
final String node = internalCluster().startNode(settingsBuilder().put(MarvelSettings.INDICES.getKey(), "unknown")); final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), "unknown"));
waitForNoBlocksOnNode(node); waitForNoBlocksOnNode(node);
try { try {

View File

@ -22,7 +22,7 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
@ -52,7 +52,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
} }
public void testEmptyClusterAllIndices() throws Exception { public void testEmptyClusterAllIndices() throws Exception {
final String node = internalCluster().startNode(settingsBuilder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL)); final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL));
waitForNoBlocksOnNode(node); waitForNoBlocksOnNode(node);
try { try {
@ -63,7 +63,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
} }
public void testEmptyClusterMissingIndex() throws Exception { public void testEmptyClusterMissingIndex() throws Exception {
final String node = internalCluster().startNode(settingsBuilder().put(MarvelSettings.INDICES.getKey(), "unknown")); final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), "unknown"));
waitForNoBlocksOnNode(node); waitForNoBlocksOnNode(node);
try { try {

View File

@ -23,7 +23,7 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -52,7 +52,7 @@ public class IndicesStatsCollectorTests extends AbstractCollectorTestCase {
} }
public void testEmptyClusterAllIndices() throws Exception { public void testEmptyClusterAllIndices() throws Exception {
final String node = internalCluster().startNode(settingsBuilder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL)); final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), MetaData.ALL));
waitForNoBlocksOnNode(node); waitForNoBlocksOnNode(node);
try { try {
@ -63,7 +63,7 @@ public class IndicesStatsCollectorTests extends AbstractCollectorTestCase {
} }
public void testEmptyClusterMissingIndex() throws Exception { public void testEmptyClusterMissingIndex() throws Exception {
final String node = internalCluster().startNode(settingsBuilder().put(MarvelSettings.INDICES.getKey(), "unknown")); final String node = internalCluster().startNode(Settings.builder().put(MarvelSettings.INDICES.getKey(), "unknown"));
waitForNoBlocksOnNode(node); waitForNoBlocksOnNode(node);
try { try {

View File

@ -19,8 +19,6 @@ import java.io.IOException;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils.dataTemplateName;
import static org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils.indexTemplateName;
import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
@ -58,8 +56,9 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
doExporting(); doExporting();
logger.debug("--> templates does not exist: it should have been created in the current version"); logger.debug("--> templates does not exist: it should have been created in the current version");
assertTemplateExist(indexTemplateName()); for (String template : monitoringTemplates().keySet()) {
assertTemplateExist(dataTemplateName()); assertTemplateExist(template);
}
doExporting(); doExporting();
@ -82,8 +81,9 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
assertTemplateExist(indexTemplateName(version)); assertTemplateExist(indexTemplateName(version));
logger.debug("--> existing templates are old: new templates should be created"); logger.debug("--> existing templates are old: new templates should be created");
assertTemplateExist(indexTemplateName()); for (String template : monitoringTemplates().keySet()) {
assertTemplateExist(dataTemplateName()); assertTemplateExist(template);
}
doExporting(); doExporting();
@ -101,12 +101,13 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
doExporting(); doExporting();
logger.debug("--> existing templates are up to date"); logger.debug("--> existing templates are up to date");
assertTemplateExist(indexTemplateName()); for (String template : monitoringTemplates().keySet()) {
assertTemplateExist(dataTemplateName()); assertTemplateExist(template);
}
logger.debug("--> existing templates has the same version: they should not be changed"); logger.debug("--> existing templates has the same version: they should not be changed");
assertTemplateNotUpdated(indexTemplateName()); assertTemplateNotUpdated(indexTemplateName(currentVersion));
assertTemplateNotUpdated(dataTemplateName()); assertTemplateNotUpdated(dataTemplateName(currentVersion));
doExporting(); doExporting();
@ -135,8 +136,9 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
doExporting(); doExporting();
logger.debug("--> templates should exist in current version"); logger.debug("--> templates should exist in current version");
assertTemplateExist(indexTemplateName()); for (String template : monitoringTemplates().keySet()) {
assertTemplateExist(dataTemplateName()); assertTemplateExist(template);
}
if (previousIndexTemplateExist) { if (previousIndexTemplateExist) {
logger.debug("--> index template should exist in version [{}]", previousIndexTemplateVersion); logger.debug("--> index template should exist in version [{}]", previousIndexTemplateVersion);
@ -167,6 +169,16 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
exporters.export(collector.collect()); exporters.export(collector.collect());
} }
private String dataTemplateName(Integer version) {
MockDataIndexNameResolver resolver = new MockDataIndexNameResolver(version);
return resolver.templateName();
}
private String indexTemplateName(Integer version) {
MockTimestampedIndexNameResolver resolver = new MockTimestampedIndexNameResolver(MonitoredSystem.ES, version, exporterSettings());
return resolver.templateName();
}
private String currentDataIndexName() { private String currentDataIndexName() {
MockDataIndexNameResolver resolver = new MockDataIndexNameResolver(currentVersion); MockDataIndexNameResolver resolver = new MockDataIndexNameResolver(currentVersion);
return resolver.index(null); return resolver.index(null);
@ -188,7 +200,6 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
.startObject("settings") .startObject("settings")
.field("index.number_of_shards", 1) .field("index.number_of_shards", 1)
.field("index.number_of_replicas", 1) .field("index.number_of_replicas", 1)
.field(MarvelSettings.INDEX_TEMPLATE_VERSION.getKey(), String.valueOf(version))
.endObject() .endObject()
.startObject("mappings") .startObject("mappings")
.startObject("_default_") .startObject("_default_")

View File

@ -5,52 +5,100 @@
*/ */
package org.elasticsearch.marvel.agent.exporter; package org.elasticsearch.marvel.agent.exporter;
import org.apache.lucene.util.Constants;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.hamcrest.Matcher;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import java.io.IOException; import java.io.IOException;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.notNullValue;
public class MarvelTemplateUtilsTests extends ESTestCase { public class MarvelTemplateUtilsTests extends ESTestCase {
public void testLoadTimestampedIndexTemplate() { private static final String TEST_TEMPLATE = "/monitoring-test.json";
byte[] template = MarvelTemplateUtils.loadTimestampedIndexTemplate();
assertNotNull(template);
assertThat(template.length, greaterThan(0));
}
public void testLoadDataIndexTemplate() { @Rule
byte[] template = MarvelTemplateUtils.loadDataIndexTemplate(); public ExpectedException expectedException = ExpectedException.none();
assertNotNull(template);
assertThat(template.length, greaterThan(0)); public void testLoadTemplate() throws IOException {
final int version = randomIntBetween(0, 10_000);
String source = MarvelTemplateUtils.loadTemplate("test", version);
assertThat(source, notNullValue());
assertThat(source.length(), greaterThan(0));
assertTemplate(source, equalTo("{\n" +
" \"template\": \".monitoring-data-" + version + "\",\n" +
" \"mappings\": {\n" +
" \"type_1\": {\n" +
" \"_meta\": {\n" +
" \"template.version\": \"" + version + "\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}"));
} }
public void testLoad() throws IOException { public void testLoad() throws IOException {
String resource = randomFrom(MarvelTemplateUtils.INDEX_TEMPLATE_FILE, MarvelTemplateUtils.DATA_TEMPLATE_FILE); BytesReference source = MarvelTemplateUtils.load(TEST_TEMPLATE);
byte[] template = MarvelTemplateUtils.load(resource); assertThat(source, notNullValue());
assertNotNull(template); assertThat(source.length(), greaterThan(0));
assertThat(template.length, greaterThan(0));
} }
public void testLoadTemplateVersion() { public void testValidateNullSource() {
Integer version = MarvelTemplateUtils.loadTemplateVersion(); expectedException.expect(ElasticsearchParseException.class);
assertNotNull(version); expectedException.expectMessage("Monitoring template must not be null");
assertThat(version, greaterThan(0)); MarvelTemplateUtils.validate(null);
assertThat(version, equalTo(MarvelTemplateUtils.TEMPLATE_VERSION));
} }
public void testIndexTemplateName() { public void testValidateEmptySource() {
assertThat(MarvelTemplateUtils.indexTemplateName(), expectedException.expect(ElasticsearchParseException.class);
equalTo(MarvelTemplateUtils.INDEX_TEMPLATE_NAME_PREFIX + MarvelTemplateUtils.TEMPLATE_VERSION)); expectedException.expectMessage("Monitoring template must not be empty");
int version = randomIntBetween(1, 100); MarvelTemplateUtils.validate(new BytesArray(""));
assertThat(MarvelTemplateUtils.indexTemplateName(version), equalTo(".monitoring-es-" + version));
} }
public void testDataTemplateName() { public void testValidateInvalidSource() {
assertThat(MarvelTemplateUtils.dataTemplateName(), expectedException.expect(ElasticsearchParseException.class);
equalTo(MarvelTemplateUtils.DATA_TEMPLATE_NAME_PREFIX + MarvelTemplateUtils.TEMPLATE_VERSION)); expectedException.expectMessage("Invalid monitoring template");
int version = randomIntBetween(1, 100); MarvelTemplateUtils.validate(new BytesArray("{\"foo\": \"bar"));
assertThat(MarvelTemplateUtils.dataTemplateName(version), equalTo(".monitoring-data-" + version)); }
public void testValidate() {
try {
MarvelTemplateUtils.validate(MarvelTemplateUtils.load(TEST_TEMPLATE));
} catch (Exception e) {
fail("failed to validate test template: " + e.getMessage());
} }
} }
public void testFilter() {
assertTemplate(MarvelTemplateUtils.filter(new BytesArray("${monitoring.template.version}"), 0), equalTo("0"));
assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"test-${monitoring.template.version}\"}"), 1),
equalTo("{\"template\": \"test-1\"}"));
assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"${monitoring.template.version}-test\"}"), 2),
equalTo("{\"template\": \"2-test\"}"));
assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"template\": \"test-${monitoring.template.version}-test\"}"), 3),
equalTo("{\"template\": \"test-3-test\"}"));
final int version = randomIntBetween(0, 100);
assertTemplate(MarvelTemplateUtils.filter(new BytesArray("{\"foo-${monitoring.template.version}\": " +
"\"bar-${monitoring.template.version}\"}"), version),
equalTo("{\"foo-" + version + "\": \"bar-" + version + "\"}"));
}
public static void assertTemplate(String actual, Matcher<? super String> matcher) {
if (Constants.WINDOWS) {
// translate Windows line endings (\r\n) to standard ones (\n)
actual = Strings.replace(actual, System.lineSeparator(), "\n");
}
assertThat(actual, matcher);
}
}

View File

@ -31,6 +31,7 @@ import org.elasticsearch.marvel.agent.collector.indices.IndexRecoveryMonitoringD
import org.elasticsearch.marvel.agent.exporter.Exporters; import org.elasticsearch.marvel.agent.exporter.Exporters;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.bulk.MonitoringBulkResolver;
import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.Scope; import org.elasticsearch.test.ESIntegTestCase.Scope;
@ -50,8 +51,6 @@ import java.util.Map;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet; import static java.util.Collections.emptySet;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils.dataTemplateName;
import static org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils.indexTemplateName;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
@ -64,9 +63,6 @@ public class HttpExporterTests extends MarvelIntegTestCase {
private int webPort; private int webPort;
private MockWebServer webServer; private MockWebServer webServer;
private static final byte[] TIMESTAMPED_TEMPLATE = MarvelTemplateUtils.loadTimestampedIndexTemplate();
private static final byte[] DATA_TEMPLATE = MarvelTemplateUtils.loadDataIndexTemplate();
@Before @Before
public void startWebservice() throws Exception { public void startWebservice() throws Exception {
for (webPort = 9250; webPort < 9300; webPort++) { for (webPort = 9250; webPort < 9300; webPort++) {
@ -91,10 +87,10 @@ public class HttpExporterTests extends MarvelIntegTestCase {
public void testExport() throws Exception { public void testExport() throws Exception {
enqueueGetClusterVersionResponse(Version.CURRENT); enqueueGetClusterVersionResponse(Version.CURRENT);
enqueueResponse(404, "template for timestamped indices does not exist"); for (String template : monitoringTemplates().keySet()) {
enqueueResponse(201, "template for timestamped indices created"); enqueueResponse(404, "template [" + template + "] does not exist");
enqueueResponse(404, "template for data index does not exist"); enqueueResponse(201, "template [" + template + "] created");
enqueueResponse(201, "template for data index created"); }
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}"); enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
Settings.Builder builder = Settings.builder() Settings.Builder builder = Settings.builder()
@ -109,29 +105,22 @@ public class HttpExporterTests extends MarvelIntegTestCase {
final int nbDocs = randomIntBetween(1, 25); final int nbDocs = randomIntBetween(1, 25);
export(newRandomMarvelDocs(nbDocs)); export(newRandomMarvelDocs(nbDocs));
assertThat(webServer.getRequestCount(), equalTo(6)); assertThat(webServer.getRequestCount(), equalTo(2 + monitoringTemplates().size() * 2));
RecordedRequest recordedRequest = webServer.takeRequest(); RecordedRequest recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET")); assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/")); assertThat(recordedRequest.getPath(), equalTo("/"));
for (Map.Entry<String, String> template : monitoringTemplates().entrySet()) {
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET")); assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName())); assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("PUT")); assertThat(recordedRequest.getMethod(), equalTo("PUT"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName())); assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
assertThat(recordedRequest.getBody().readByteArray(), equalTo(TIMESTAMPED_TEMPLATE)); assertThat(recordedRequest.getBody().readUtf8(), equalTo(template.getValue()));
}
recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + dataTemplateName()));
recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + dataTemplateName()));
assertThat(recordedRequest.getBody().readByteArray(), equalTo(DATA_TEMPLATE));
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("POST")); assertThat(recordedRequest.getMethod(), equalTo("POST"));
@ -176,10 +165,10 @@ public class HttpExporterTests extends MarvelIntegTestCase {
logger.info("--> starting node"); logger.info("--> starting node");
enqueueGetClusterVersionResponse(Version.CURRENT); enqueueGetClusterVersionResponse(Version.CURRENT);
enqueueResponse(404, "template for timestamped indices does not exist"); for (String template : monitoringTemplates().keySet()) {
enqueueResponse(201, "template for timestamped indices created"); enqueueResponse(404, "template [" + template + "] does not exist");
enqueueResponse(404, "template for data index does not exist"); enqueueResponse(201, "template [" + template + "] created");
enqueueResponse(201, "template for data index created"); }
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}"); enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
String agentNode = internalCluster().startNode(builder); String agentNode = internalCluster().startNode(builder);
@ -190,29 +179,22 @@ public class HttpExporterTests extends MarvelIntegTestCase {
export(Collections.singletonList(newRandomMarvelDoc())); export(Collections.singletonList(newRandomMarvelDoc()));
assertThat(exporter.supportedClusterVersion, is(true)); assertThat(exporter.supportedClusterVersion, is(true));
assertThat(webServer.getRequestCount(), equalTo(6)); assertThat(webServer.getRequestCount(), equalTo(2 + monitoringTemplates().size() * 2));
RecordedRequest recordedRequest = webServer.takeRequest(); RecordedRequest recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET")); assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/")); assertThat(recordedRequest.getPath(), equalTo("/"));
for (Map.Entry<String, String> template : monitoringTemplates().entrySet()) {
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET")); assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName())); assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("PUT")); assertThat(recordedRequest.getMethod(), equalTo("PUT"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName())); assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
assertThat(recordedRequest.getBody().readByteArray(), equalTo(TIMESTAMPED_TEMPLATE)); assertThat(recordedRequest.getBody().readUtf8(), equalTo(template.getValue()));
}
recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + dataTemplateName()));
recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + dataTemplateName()));
assertThat(recordedRequest.getBody().readByteArray(), equalTo(DATA_TEMPLATE));
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("POST")); assertThat(recordedRequest.getMethod(), equalTo("POST"));
@ -246,32 +228,37 @@ public class HttpExporterTests extends MarvelIntegTestCase {
exporter = getExporter(agentNode); exporter = getExporter(agentNode);
enqueueGetClusterVersionResponse(secondWebServer, Version.CURRENT); enqueueGetClusterVersionResponse(secondWebServer, Version.CURRENT);
enqueueResponse(secondWebServer, 404, "template for timestamped indices does not exist"); for (String template : monitoringTemplates().keySet()) {
enqueueResponse(secondWebServer, 201, "template for timestamped indices created"); if (template.contains(MonitoringBulkResolver.Data.DATA)) {
enqueueResponse(secondWebServer, 200, "template for data index exist"); enqueueResponse(secondWebServer, 200, "template [" + template + "] exist");
} else {
enqueueResponse(secondWebServer, 404, "template [" + template + "] does not exist");
enqueueResponse(secondWebServer, 201, "template [" + template + "] created");
}
}
enqueueResponse(secondWebServer, 200, "{\"errors\": false, \"msg\": \"successful bulk request\"}"); enqueueResponse(secondWebServer, 200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
logger.info("--> exporting a second event"); logger.info("--> exporting a second event");
export(Collections.singletonList(newRandomMarvelDoc())); export(Collections.singletonList(newRandomMarvelDoc()));
assertThat(secondWebServer.getRequestCount(), equalTo(5)); assertThat(secondWebServer.getRequestCount(), equalTo(2 + monitoringTemplates().size() * 2 - 1));
recordedRequest = secondWebServer.takeRequest(); recordedRequest = secondWebServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET")); assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/")); assertThat(recordedRequest.getPath(), equalTo("/"));
for (Map.Entry<String, String> template : monitoringTemplates().entrySet()) {
recordedRequest = secondWebServer.takeRequest(); recordedRequest = secondWebServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET")); assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName())); assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
if (template.getKey().contains(MonitoringBulkResolver.Data.DATA) == false) {
recordedRequest = secondWebServer.takeRequest(); recordedRequest = secondWebServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("PUT")); assertThat(recordedRequest.getMethod(), equalTo("PUT"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName())); assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
assertThat(recordedRequest.getBody().readByteArray(), equalTo(TIMESTAMPED_TEMPLATE)); assertThat(recordedRequest.getBody().readUtf8(), equalTo(template.getValue()));
}
recordedRequest = secondWebServer.takeRequest(); }
assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + dataTemplateName()));;
recordedRequest = secondWebServer.takeRequest(); recordedRequest = secondWebServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("POST")); assertThat(recordedRequest.getMethod(), equalTo("POST"));
@ -325,10 +312,10 @@ public class HttpExporterTests extends MarvelIntegTestCase {
logger.info("--> exporting a first event"); logger.info("--> exporting a first event");
enqueueGetClusterVersionResponse(Version.CURRENT); enqueueGetClusterVersionResponse(Version.CURRENT);
enqueueResponse(404, "template for timestamped indices does not exist"); for (String template : monitoringTemplates().keySet()) {
enqueueResponse(201, "template for timestamped indices created"); enqueueResponse(404, "template [" + template + "] does not exist");
enqueueResponse(404, "template for data index does not exist"); enqueueResponse(201, "template [" + template + "] created");
enqueueResponse(201, "template for data index created"); }
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}"); enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
HttpExporter exporter = getExporter(agentNode); HttpExporter exporter = getExporter(agentNode);
@ -336,29 +323,23 @@ public class HttpExporterTests extends MarvelIntegTestCase {
MonitoringDoc doc = newRandomMarvelDoc(); MonitoringDoc doc = newRandomMarvelDoc();
export(Collections.singletonList(doc)); export(Collections.singletonList(doc));
assertThat(webServer.getRequestCount(), equalTo(6)); final int expectedRequests = 2 + monitoringTemplates().size() * 2;
assertThat(webServer.getRequestCount(), equalTo(expectedRequests));
RecordedRequest recordedRequest = webServer.takeRequest(); RecordedRequest recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET")); assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/")); assertThat(recordedRequest.getPath(), equalTo("/"));
for (Map.Entry<String, String> template : monitoringTemplates().entrySet()) {
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET")); assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName())); assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("PUT")); assertThat(recordedRequest.getMethod(), equalTo("PUT"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName())); assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
assertThat(recordedRequest.getBody().readByteArray(), equalTo(TIMESTAMPED_TEMPLATE)); assertThat(recordedRequest.getBody().readUtf8(), equalTo(template.getValue()));
}
recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + dataTemplateName()));
recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + dataTemplateName()));
assertThat(recordedRequest.getBody().readByteArray(), equalTo(DATA_TEMPLATE));
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("POST")); assertThat(recordedRequest.getMethod(), equalTo("POST"));
@ -381,8 +362,9 @@ public class HttpExporterTests extends MarvelIntegTestCase {
logger.info("--> exporting a second event"); logger.info("--> exporting a second event");
enqueueGetClusterVersionResponse(Version.CURRENT); enqueueGetClusterVersionResponse(Version.CURRENT);
enqueueResponse(200, "template for timestamped indices exist"); for (String template : monitoringTemplates().keySet()) {
enqueueResponse(200, "template for data index exist"); enqueueResponse(200, "template [" + template + "] exist");
}
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}"); enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
doc = newRandomMarvelDoc(); doc = newRandomMarvelDoc();
@ -391,19 +373,17 @@ public class HttpExporterTests extends MarvelIntegTestCase {
String expectedMarvelIndex = ".monitoring-es-" + MarvelTemplateUtils.TEMPLATE_VERSION + "-" String expectedMarvelIndex = ".monitoring-es-" + MarvelTemplateUtils.TEMPLATE_VERSION + "-"
+ DateTimeFormat.forPattern(newTimeFormat).withZoneUTC().print(doc.getTimestamp()); + DateTimeFormat.forPattern(newTimeFormat).withZoneUTC().print(doc.getTimestamp());
assertThat(webServer.getRequestCount(), equalTo(6 + 4)); assertThat(webServer.getRequestCount(), equalTo(expectedRequests + 2 + monitoringTemplates().size()));
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET")); assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/")); assertThat(recordedRequest.getPath(), equalTo("/"));
for (String template : monitoringTemplates().keySet()) {
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET")); assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName())); assertThat(recordedRequest.getPath(), equalTo("/_template/" + template));
}
recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("GET"));
assertThat(recordedRequest.getPath(), equalTo("/_template/" + dataTemplateName()));
recordedRequest = webServer.takeRequest(); recordedRequest = webServer.takeRequest();
assertThat(recordedRequest.getMethod(), equalTo("POST")); assertThat(recordedRequest.getMethod(), equalTo("POST"));

View File

@ -36,12 +36,9 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet; import static java.util.Collections.emptySet;
import static org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils.dataTemplateName;
import static org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils.indexTemplateName;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -51,7 +48,6 @@ import static org.hamcrest.Matchers.notNullValue;
@ClusterScope(scope = Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0) @ClusterScope(scope = Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0)
public class LocalExporterTests extends MarvelIntegTestCase { public class LocalExporterTests extends MarvelIntegTestCase {
private final static AtomicLong timeStampGenerator = new AtomicLong();
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
@ -108,8 +104,7 @@ public class LocalExporterTests extends MarvelIntegTestCase {
updateMarvelInterval(3L, TimeUnit.SECONDS); updateMarvelInterval(3L, TimeUnit.SECONDS);
// lets wait until the monitoring template will be installed // lets wait until the monitoring template will be installed
waitForMarvelTemplate(indexTemplateName()); waitForMarvelTemplates();
waitForMarvelTemplate(dataTemplateName());
} }
public void testIndexTimestampFormat() throws Exception { public void testIndexTimestampFormat() throws Exception {

View File

@ -20,7 +20,6 @@ import java.util.Arrays;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet; import static java.util.Collections.emptySet;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver.DELIMITER; import static org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver.DELIMITER;
import static org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver.PREFIX; import static org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver.PREFIX;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -68,7 +67,7 @@ public class TimestampedResolverTests extends MonitoringIndexNameResolverTestCas
for (String format : Arrays.asList("YYYY", "YYYY.MM", "YYYY.MM.dd", "YYYY.MM.dd-HH", "YYYY.MM.dd-HH.mm", "YYYY.MM.dd-HH.mm.SS")) { for (String format : Arrays.asList("YYYY", "YYYY.MM", "YYYY.MM.dd", "YYYY.MM.dd-HH", "YYYY.MM.dd-HH.mm", "YYYY.MM.dd-HH.mm.SS")) {
Settings settings = Settings.EMPTY; Settings settings = Settings.EMPTY;
if (format != null) { if (format != null) {
settings = settingsBuilder() settings = Settings.builder()
.put(MonitoringIndexNameResolver.Timestamped.INDEX_NAME_TIME_FORMAT_SETTING.getKey(), format) .put(MonitoringIndexNameResolver.Timestamped.INDEX_NAME_TIME_FORMAT_SETTING.getKey(), format)
.build(); .build();
} }

View File

@ -56,7 +56,7 @@ public class MonitoringBulkResolverTests extends MonitoringIndexNameResolverTest
} }
MonitoringBulkResolver resolver = newResolver(); MonitoringBulkResolver resolver = newResolver();
assertThat(resolver.index(doc), equalTo(".monitoring-kibana-0-2015.07.22")); assertThat(resolver.index(doc), equalTo(".monitoring-kibana-2-2015.07.22"));
assertThat(resolver.type(doc), equalTo(doc.getType())); assertThat(resolver.type(doc), equalTo(doc.getType()));
assertThat(resolver.id(doc), nullValue()); assertThat(resolver.id(doc), nullValue());

View File

@ -23,8 +23,6 @@ import org.junit.Before;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils.dataTemplateName;
import static org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils.indexTemplateName;
import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -119,8 +117,7 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
assertThat(clusterStats, instanceOf(Map.class)); assertThat(clusterStats, instanceOf(Map.class));
assertThat(((Map) clusterStats).size(), greaterThan(0)); assertThat(((Map) clusterStats).size(), greaterThan(0));
waitForMarvelTemplate(indexTemplateName()); waitForMarvelTemplates();
waitForMarvelTemplate(dataTemplateName());
logger.debug("--> check that the cluster_info is not indexed"); logger.debug("--> check that the cluster_info is not indexed");
securedFlush(); securedFlush();

View File

@ -22,7 +22,6 @@ import org.junit.After;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@ -64,7 +63,7 @@ public class MultiNodesStatsTests extends MarvelIntegTestCase {
n = randomIntBetween(1, 2); n = randomIntBetween(1, 2);
logger.debug("--> starting {} client only nodes", n); logger.debug("--> starting {} client only nodes", n);
InternalTestCluster.Async<List<String>> clientNodes = internalCluster().startNodesAsync(n, InternalTestCluster.Async<List<String>> clientNodes = internalCluster().startNodesAsync(n,
settingsBuilder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), false) Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), false)
.put(Node.NODE_INGEST_SETTING.getKey(), false).build()); .put(Node.NODE_INGEST_SETTING.getKey(), false).build());
clientNodes.get(); clientNodes.get();
nodes += n; nodes += n;

View File

@ -17,7 +17,6 @@ import org.joda.time.DateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -41,7 +40,7 @@ public class LocalIndicesCleanerTests extends AbstractIndicesCleanerTestCase {
@Override @Override
protected void createIndex(String name, DateTime creationDate) { protected void createIndex(String name, DateTime creationDate) {
assertAcked(prepareCreate(name) assertAcked(prepareCreate(name)
.setSettings(settingsBuilder().put(IndexMetaData.SETTING_CREATION_DATE, creationDate.getMillis()).build())); .setSettings(Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, creationDate.getMillis()).build()));
ensureYellow(name); ensureYellow(name);
} }

View File

@ -11,11 +11,12 @@ import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.marvel.MarvelSettings; import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.shield.InternalClient; import org.elasticsearch.shield.InternalClient;
import java.util.ArrayList;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -48,15 +49,13 @@ public class MarvelInternalClientTests extends MarvelIntegTestCase {
assertAccessIsAllowed(internalClient.admin().indices().prepareDelete(MONITORING_INDICES_PREFIX + "*")); assertAccessIsAllowed(internalClient.admin().indices().prepareDelete(MONITORING_INDICES_PREFIX + "*"));
assertAccessIsAllowed(internalClient.admin().indices().prepareCreate(MONITORING_INDICES_PREFIX + "test")); assertAccessIsAllowed(internalClient.admin().indices().prepareCreate(MONITORING_INDICES_PREFIX + "test"));
assertAccessIsAllowed(internalClient.admin().indices().preparePutTemplate("foo") assertAccessIsAllowed(internalClient.admin().indices().preparePutTemplate("foo").setSource(randomTemplateSource()));
.setSource(MarvelTemplateUtils.loadTimestampedIndexTemplate()));
assertAccessIsAllowed(internalClient.admin().indices().prepareGetTemplates("foo")); assertAccessIsAllowed(internalClient.admin().indices().prepareGetTemplates("foo"));
} }
public void testAllowAllAccess() { public void testAllowAllAccess() {
InternalClient internalClient = internalCluster().getInstance(InternalClient.class); InternalClient internalClient = internalCluster().getInstance(InternalClient.class);
assertAcked(internalClient.admin().indices().preparePutTemplate("foo") assertAcked(internalClient.admin().indices().preparePutTemplate("foo").setSource(randomTemplateSource()).get());
.setSource(MarvelTemplateUtils.loadDataIndexTemplate()).get());
assertAccessIsAllowed(internalClient.admin().indices().prepareDeleteTemplate("foo")); assertAccessIsAllowed(internalClient.admin().indices().prepareDeleteTemplate("foo"));
assertAccessIsAllowed(internalClient.admin().cluster().prepareGetRepositories()); assertAccessIsAllowed(internalClient.admin().cluster().prepareGetRepositories());
@ -83,5 +82,12 @@ public class MarvelInternalClientTests extends MarvelIntegTestCase {
assertThat(e.status(), is(RestStatus.FORBIDDEN)); assertThat(e.status(), is(RestStatus.FORBIDDEN));
} }
} }
/**
* @return the source of a random monitoring template
*/
private String randomTemplateSource() {
return randomFrom(new ArrayList<>(monitoringTemplates().values()));
}
} }

View File

@ -20,9 +20,9 @@ import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.marvel.MarvelSettings; import org.elasticsearch.marvel.MarvelSettings;
import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.MonitoredSystem;
import org.elasticsearch.marvel.agent.AgentService; import org.elasticsearch.marvel.agent.AgentService;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver;
import org.elasticsearch.marvel.agent.resolver.ResolversRegistry;
import org.elasticsearch.marvel.client.MonitoringClient; import org.elasticsearch.marvel.client.MonitoringClient;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.shield.authc.file.FileRealm; import org.elasticsearch.shield.authc.file.FileRealm;
@ -57,6 +57,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
@ -164,10 +166,7 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase {
@Override @Override
protected Set<String> excludeTemplates() { protected Set<String> excludeTemplates() {
Set<String> templates = new HashSet<>(); return monitoringTemplates().keySet();
templates.add(MarvelTemplateUtils.indexTemplateName());
templates.add(MarvelTemplateUtils.dataTemplateName());
return templates;
} }
@Before @Before
@ -275,6 +274,11 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase {
} }
} }
protected Map<String, String> monitoringTemplates() {
return StreamSupport.stream(new ResolversRegistry(Settings.EMPTY).spliterator(), false)
.collect(Collectors.toMap(MonitoringIndexNameResolver::templateName, MonitoringIndexNameResolver::template, (a, b) -> a));
}
protected void assertTemplateInstalled(String name) { protected void assertTemplateInstalled(String name) {
boolean found = false; boolean found = false;
for (IndexTemplateMetaData template : client().admin().indices().prepareGetTemplates().get().getIndexTemplates()) { for (IndexTemplateMetaData template : client().admin().indices().prepareGetTemplates().get().getIndexTemplates()) {
@ -294,6 +298,10 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase {
}, 30, TimeUnit.SECONDS); }, 30, TimeUnit.SECONDS);
} }
protected void waitForMarvelTemplates() throws Exception {
assertBusy(() -> monitoringTemplates().keySet().forEach(this::assertTemplateInstalled), 30, TimeUnit.SECONDS);
}
protected void waitForMarvelIndices() throws Exception { protected void waitForMarvelIndices() throws Exception {
awaitIndexExists(MONITORING_INDICES_PREFIX + "*"); awaitIndexExists(MONITORING_INDICES_PREFIX + "*");
assertBusy(this::ensureMarvelIndicesYellow); assertBusy(this::ensureMarvelIndicesYellow);

View File

@ -0,0 +1,10 @@
{
"template": ".monitoring-data-${monitoring.template.version}",
"mappings": {
"type_1": {
"_meta": {
"template.version": "${monitoring.template.version}"
}
}
}
}

View File

@ -178,7 +178,7 @@ public class Security {
return Settings.EMPTY; return Settings.EMPTY;
} }
Settings.Builder settingsBuilder = Settings.settingsBuilder(); Settings.Builder settingsBuilder = Settings.builder();
settingsBuilder.put(NetworkModule.TRANSPORT_TYPE_KEY, Security.NAME); settingsBuilder.put(NetworkModule.TRANSPORT_TYPE_KEY, Security.NAME);
settingsBuilder.put(NetworkModule.TRANSPORT_SERVICE_TYPE_KEY, Security.NAME); settingsBuilder.put(NetworkModule.TRANSPORT_SERVICE_TYPE_KEY, Security.NAME);
settingsBuilder.put(NetworkModule.HTTP_TYPE_SETTING.getKey(), Security.NAME); settingsBuilder.put(NetworkModule.HTTP_TYPE_SETTING.getKey(), Security.NAME);

View File

@ -26,7 +26,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collections; import java.util.Collections;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.shield.authc.ldap.support.LdapSearchScope.ONE_LEVEL; import static org.elasticsearch.shield.authc.ldap.support.LdapSearchScope.ONE_LEVEL;
import static org.elasticsearch.shield.authc.ldap.support.LdapSearchScope.SUB_TREE; import static org.elasticsearch.shield.authc.ldap.support.LdapSearchScope.SUB_TREE;
@ -75,7 +74,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
Path nodeFiles = createTempDir(); Path nodeFiles = createTempDir();
return settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(realmConfig.buildSettings()) .put(realmConfig.buildSettings())
//we need ssl to the LDAP server //we need ssl to the LDAP server
@ -160,7 +159,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
throw new ElasticsearchException("store path [" + store + "] doesn't exist"); throw new ElasticsearchException("store path [" + store + "] doesn't exist");
} }
return settingsBuilder() return Settings.builder()
.put("xpack.security.ssl.keystore.path", store) .put("xpack.security.ssl.keystore.path", store)
.put("xpack.security.ssl.keystore.password", password) .put("xpack.security.ssl.keystore.password", password)
.put(ShieldNettyTransport.HOSTNAME_VERIFICATION_SETTING.getKey(), false) .put(ShieldNettyTransport.HOSTNAME_VERIFICATION_SETTING.getKey(), false)
@ -174,7 +173,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
enum RealmConfig { enum RealmConfig {
AD(false, AD_ROLE_MAPPING, AD(false, AD_ROLE_MAPPING,
settingsBuilder() Settings.builder()
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".type", ActiveDirectoryRealm.TYPE) .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".type", ActiveDirectoryRealm.TYPE)
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".domain_name", "ad.test.elasticsearch.com") .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".domain_name", "ad.test.elasticsearch.com")
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".group_search.base_dn", "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com") .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".group_search.base_dn", "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com")
@ -183,7 +182,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
.build()), .build()),
AD_LDAP_GROUPS_FROM_SEARCH(true, AD_ROLE_MAPPING, AD_LDAP_GROUPS_FROM_SEARCH(true, AD_ROLE_MAPPING,
settingsBuilder() Settings.builder()
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".type", LdapRealm.TYPE) .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".type", LdapRealm.TYPE)
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".url", "ldaps://ad.test.elasticsearch.com:636") .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".url", "ldaps://ad.test.elasticsearch.com:636")
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".group_search.base_dn", "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com") .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".group_search.base_dn", "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com")
@ -193,7 +192,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
.build()), .build()),
AD_LDAP_GROUPS_FROM_ATTRIBUTE(true, AD_ROLE_MAPPING, AD_LDAP_GROUPS_FROM_ATTRIBUTE(true, AD_ROLE_MAPPING,
settingsBuilder() Settings.builder()
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".type", LdapRealm.TYPE) .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".type", LdapRealm.TYPE)
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".url", "ldaps://ad.test.elasticsearch.com:636") .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".url", "ldaps://ad.test.elasticsearch.com:636")
.putArray(SHIELD_AUTHC_REALMS_EXTERNAL + ".user_dn_templates", .putArray(SHIELD_AUTHC_REALMS_EXTERNAL + ".user_dn_templates",
@ -201,7 +200,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
.build()), .build()),
OLDAP(false, OLDAP_ROLE_MAPPING, OLDAP(false, OLDAP_ROLE_MAPPING,
settingsBuilder() Settings.builder()
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".type", LdapRealm.TYPE) .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".type", LdapRealm.TYPE)
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".url", "ldaps://54.200.235.244:636") .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".url", "ldaps://54.200.235.244:636")
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".group_search.base_dn", .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".group_search.base_dn",
@ -224,7 +223,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
} }
public Settings buildSettings() { public Settings buildSettings() {
return settingsBuilder() return Settings.builder()
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".order", 1) .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".order", 1)
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".hostname_verification", false) .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".hostname_verification", false)
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".unmapped_groups_as_roles", mapGroupsAsRoles) .put(SHIELD_AUTHC_REALMS_EXTERNAL + ".unmapped_groups_as_roles", mapGroupsAsRoles)

View File

@ -64,7 +64,7 @@ public class ShieldPluginEnabledDisabledTests extends ShieldIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
logger.info("******* shield is {}", enabled ? "enabled" : "disabled"); logger.info("******* shield is {}", enabled ? "enabled" : "disabled");
return Settings.settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(XPackPlugin.featureEnabledSetting(Security.NAME), enabled) .put(XPackPlugin.featureEnabledSetting(Security.NAME), enabled)
.put(NetworkModule.HTTP_ENABLED.getKey(), true) .put(NetworkModule.HTTP_ENABLED.getKey(), true)
@ -73,7 +73,7 @@ public class ShieldPluginEnabledDisabledTests extends ShieldIntegTestCase {
@Override @Override
protected Settings transportClientSettings() { protected Settings transportClientSettings() {
return Settings.settingsBuilder() return Settings.builder()
.put(super.transportClientSettings()) .put(super.transportClientSettings())
.put(XPackPlugin.featureEnabledSetting(Security.NAME), enabled) .put(XPackPlugin.featureEnabledSetting(Security.NAME), enabled)
.build(); .build();

View File

@ -43,7 +43,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.ShieldTestsUtils.assertAuthenticationException; import static org.elasticsearch.test.ShieldTestsUtils.assertAuthenticationException;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
@ -65,23 +64,23 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
@Before @Before
public void initializeSslSocketFactory() throws Exception { public void initializeSslSocketFactory() throws Exception {
Path keystore = getDataPath("support/ldaptrust.jks"); Path keystore = getDataPath("support/ldaptrust.jks");
Environment env = new Environment(settingsBuilder().put("path.home", createTempDir()).build()); Environment env = new Environment(Settings.builder().put("path.home", createTempDir()).build());
/* /*
* Prior to each test we reinitialize the socket factory with a new SSLService so that we get a new SSLContext. * Prior to each test we reinitialize the socket factory with a new SSLService so that we get a new SSLContext.
* If we re-use a SSLContext, previously connected sessions can get re-established which breaks hostname * If we re-use a SSLContext, previously connected sessions can get re-established which breaks hostname
* verification tests since a re-established connection does not perform hostname verification. * verification tests since a re-established connection does not perform hostname verification.
*/ */
clientSSLService = new ClientSSLService(settingsBuilder() clientSSLService = new ClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", keystore) .put("xpack.security.ssl.keystore.path", keystore)
.put("xpack.security.ssl.keystore.password", "changeit") .put("xpack.security.ssl.keystore.password", "changeit")
.build()); .build());
clientSSLService.setEnvironment(env); clientSSLService.setEnvironment(env);
globalSettings = settingsBuilder().put("path.home", createTempDir()).build(); globalSettings = Settings.builder().put("path.home", createTempDir()).build();
} }
public void testSupportsUnauthenticatedSessions() throws Exception { public void testSupportsUnauthenticatedSessions() throws Exception {
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, "", LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, "", LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", "") .put("user_search.base_dn", "")
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas") .put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
@ -101,7 +100,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
String groupSearchBase = "o=sevenSeas"; String groupSearchBase = "o=sevenSeas";
String userSearchBase = "o=sevenSeas"; String userSearchBase = "o=sevenSeas";
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas") .put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
@ -135,7 +134,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
String groupSearchBase = "o=sevenSeas"; String groupSearchBase = "o=sevenSeas";
String userSearchBase = "o=sevenSeas"; String userSearchBase = "o=sevenSeas";
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas") .put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
@ -174,7 +173,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
String groupSearchBase = "o=sevenSeas"; String groupSearchBase = "o=sevenSeas";
String userSearchBase = "cn=William Bush,ou=people,o=sevenSeas"; String userSearchBase = "cn=William Bush,ou=people,o=sevenSeas";
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas") .put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
@ -209,7 +208,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
String groupSearchBase = "o=sevenSeas"; String groupSearchBase = "o=sevenSeas";
String userSearchBase = "o=sevenSeas"; String userSearchBase = "o=sevenSeas";
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas") .put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
@ -248,7 +247,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
String groupSearchBase = "o=sevenSeas"; String groupSearchBase = "o=sevenSeas";
String userSearchBase = "ou=people,o=sevenSeas"; String userSearchBase = "ou=people,o=sevenSeas";
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas") .put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
@ -283,7 +282,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
String groupSearchBase = "o=sevenSeas"; String groupSearchBase = "o=sevenSeas";
String userSearchBase = "o=sevenSeas"; String userSearchBase = "o=sevenSeas";
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas") .put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
@ -321,7 +320,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
String groupSearchBase = "o=sevenSeas"; String groupSearchBase = "o=sevenSeas";
String userSearchBase = "o=sevenSeas"; String userSearchBase = "o=sevenSeas";
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas") .put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
@ -354,7 +353,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
public void testUserSearchWithActiveDirectory() throws Exception { public void testUserSearchWithActiveDirectory() throws Exception {
String groupSearchBase = "DC=ad,DC=test,DC=elasticsearch,DC=com"; String groupSearchBase = "DC=ad,DC=test,DC=elasticsearch,DC=com";
String userSearchBase = "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com"; String userSearchBase = "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com";
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(LdapTestCase.buildLdapSettings(new String[] { ActiveDirectorySessionFactoryTests.AD_LDAP_URL }, Strings.EMPTY_ARRAY, .put(LdapTestCase.buildLdapSettings(new String[] { ActiveDirectorySessionFactoryTests.AD_LDAP_URL }, Strings.EMPTY_ARRAY,
groupSearchBase, LdapSearchScope.SUB_TREE)) groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
@ -397,7 +396,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
public void testUserSearchwithBindUserOpenLDAP() throws Exception { public void testUserSearchwithBindUserOpenLDAP() throws Exception {
String groupSearchBase = "ou=people,dc=oldap,dc=test,dc=elasticsearch,dc=com"; String groupSearchBase = "ou=people,dc=oldap,dc=test,dc=elasticsearch,dc=com";
String userSearchBase = "ou=people,dc=oldap,dc=test,dc=elasticsearch,dc=com"; String userSearchBase = "ou=people,dc=oldap,dc=test,dc=elasticsearch,dc=com";
RealmConfig config = new RealmConfig("oldap-test", settingsBuilder() RealmConfig config = new RealmConfig("oldap-test", Settings.builder()
.put(LdapTestCase.buildLdapSettings(new String[] { OpenLdapTests.OPEN_LDAP_URL }, Strings.EMPTY_ARRAY, groupSearchBase, .put(LdapTestCase.buildLdapSettings(new String[] { OpenLdapTests.OPEN_LDAP_URL }, Strings.EMPTY_ARRAY, groupSearchBase,
LdapSearchScope.ONE_LEVEL)) LdapSearchScope.ONE_LEVEL))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
@ -431,7 +430,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
public void testConnectionPoolDefaultSettings() throws Exception { public void testConnectionPoolDefaultSettings() throws Exception {
String groupSearchBase = "o=sevenSeas"; String groupSearchBase = "o=sevenSeas";
String userSearchBase = "o=sevenSeas"; String userSearchBase = "o=sevenSeas";
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas") .put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
@ -457,7 +456,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
public void testConnectionPoolSettings() throws Exception { public void testConnectionPoolSettings() throws Exception {
String groupSearchBase = "o=sevenSeas"; String groupSearchBase = "o=sevenSeas";
String userSearchBase = "o=sevenSeas"; String userSearchBase = "o=sevenSeas";
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas") .put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
@ -482,7 +481,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
public void testThatEmptyBindDNThrowsExceptionWithHealthCheckEnabled() throws Exception { public void testThatEmptyBindDNThrowsExceptionWithHealthCheckEnabled() throws Exception {
String groupSearchBase = "o=sevenSeas"; String groupSearchBase = "o=sevenSeas";
String userSearchBase = "o=sevenSeas"; String userSearchBase = "o=sevenSeas";
RealmConfig config = new RealmConfig("ldap_realm", settingsBuilder() RealmConfig config = new RealmConfig("ldap_realm", Settings.builder()
.put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE)) .put(buildLdapSettings(ldapUrls(), Strings.EMPTY_ARRAY, groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
.put("bind_password", "pass") .put("bind_password", "pass")
@ -497,12 +496,12 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
} }
public void testEmptyBindDNReturnsNullBindRequest() { public void testEmptyBindDNReturnsNullBindRequest() {
BindRequest request = LdapUserSearchSessionFactory.bindRequest(settingsBuilder().put("bind_password", "password").build()); BindRequest request = LdapUserSearchSessionFactory.bindRequest(Settings.builder().put("bind_password", "password").build());
assertThat(request, is(nullValue())); assertThat(request, is(nullValue()));
} }
public void testThatBindRequestReturnsSimpleBindRequest() { public void testThatBindRequestReturnsSimpleBindRequest() {
BindRequest request = LdapUserSearchSessionFactory.bindRequest(settingsBuilder() BindRequest request = LdapUserSearchSessionFactory.bindRequest(Settings.builder()
.put("bind_password", "password") .put("bind_password", "password")
.put("bind_dn", "cn=ironman") .put("bind_dn", "cn=ironman")
.build()); .build());
@ -515,7 +514,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
public void testThatLDAPServerConnectErrorDoesNotPreventNodeFromStarting() throws IOException { public void testThatLDAPServerConnectErrorDoesNotPreventNodeFromStarting() throws IOException {
String groupSearchBase = "DC=ad,DC=test,DC=elasticsearch,DC=com"; String groupSearchBase = "DC=ad,DC=test,DC=elasticsearch,DC=com";
String userSearchBase = "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com"; String userSearchBase = "CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com";
Settings ldapSettings = settingsBuilder() Settings ldapSettings = Settings.builder()
.put(LdapTestCase.buildLdapSettings(new String[] { "ldaps://elastic.co:636" }, Strings.EMPTY_ARRAY, .put(LdapTestCase.buildLdapSettings(new String[] { "ldaps://elastic.co:636" }, Strings.EMPTY_ARRAY,
groupSearchBase, LdapSearchScope.SUB_TREE)) groupSearchBase, LdapSearchScope.SUB_TREE))
.put("user_search.base_dn", userSearchBase) .put("user_search.base_dn", userSearchBase)
@ -526,7 +525,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
.put("type", "ldap") .put("type", "ldap")
.build(); .build();
Settings.Builder builder = settingsBuilder(); Settings.Builder builder = Settings.builder();
for (Map.Entry<String, String> entry : ldapSettings.getAsMap().entrySet()) { for (Map.Entry<String, String> entry : ldapSettings.getAsMap().entrySet()) {
builder.put("xpack.security.authc.realms.ldap1." + entry.getKey(), entry.getValue()); builder.put("xpack.security.authc.realms.ldap1." + entry.getKey(), entry.getValue());
} }

View File

@ -13,7 +13,6 @@ import org.elasticsearch.shield.authc.RealmConfig;
import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.authc.support.SecuredString;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -29,7 +28,7 @@ public class SessionFactoryTests extends ESTestCase {
} }
public void testConnectionFactoryReturnsCorrectLDAPConnectionOptions() { public void testConnectionFactoryReturnsCorrectLDAPConnectionOptions() {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(SessionFactory.TIMEOUT_TCP_CONNECTION_SETTING, "10ms") .put(SessionFactory.TIMEOUT_TCP_CONNECTION_SETTING, "10ms")
.put(SessionFactory.HOSTNAME_VERIFICATION_SETTING, "false") .put(SessionFactory.HOSTNAME_VERIFICATION_SETTING, "false")
.put(SessionFactory.TIMEOUT_TCP_READ_SETTING, "20ms") .put(SessionFactory.TIMEOUT_TCP_READ_SETTING, "20ms")
@ -57,7 +56,7 @@ public class SessionFactoryTests extends ESTestCase {
} }
private SessionFactory createSessionFactory() { private SessionFactory createSessionFactory() {
Settings global = settingsBuilder().put("path.home", createTempDir()).build(); Settings global = Settings.builder().put("path.home", createTempDir()).build();
return new SessionFactory(new RealmConfig("_name", Settings.builder().put("url", "ldap://localhost:389").build(), global), null) { return new SessionFactory(new RealmConfig("_name", Settings.builder().put("url", "ldap://localhost:389").build(), global), null) {
@Override @Override

View File

@ -235,7 +235,7 @@ public class DnRoleMapperTests extends ESTestCase {
public void testYaml() throws Exception { public void testYaml() throws Exception {
Path file = getDataPath("role_mapping.yml"); Path file = getDataPath("role_mapping.yml");
Settings ldapSettings = Settings.settingsBuilder() Settings ldapSettings = Settings.builder()
.put(DnRoleMapper.ROLE_MAPPING_FILE_SETTING, file.toAbsolutePath()) .put(DnRoleMapper.ROLE_MAPPING_FILE_SETTING, file.toAbsolutePath())
.build(); .build();
RealmConfig config = new RealmConfig("ldap1", ldapSettings, settings); RealmConfig config = new RealmConfig("ldap1", ldapSettings, settings);

View File

@ -843,7 +843,7 @@ public class DefaultIndicesResolverTests extends ESTestCase {
// TODO with the removal of DeleteByQuery is there another way to test resolving a write action? // TODO with the removal of DeleteByQuery is there another way to test resolving a write action?
private static IndexMetaData.Builder indexBuilder(String index) { private static IndexMetaData.Builder indexBuilder(String index) {
return IndexMetaData.builder(index).settings(Settings.settingsBuilder() return IndexMetaData.builder(index).settings(Settings.builder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
} }

View File

@ -36,7 +36,7 @@ public class ShieldLicenseeTests extends AbstractLicenseeTestCase {
} }
public void testDoesNotStartWithTribeNode() { public void testDoesNotStartWithTribeNode() {
Settings settings = Settings.settingsBuilder().put("tribe.fake.cluster.name", "notchecked").build(); Settings settings = Settings.builder().put("tribe.fake.cluster.name", "notchecked").build();
ShieldLicensee licensee = new ShieldLicensee(settings, registry, shieldState); ShieldLicensee licensee = new ShieldLicensee(settings, registry, shieldState);
// starting the Licensee as a tribe node should not trigger it being registered // starting the Licensee as a tribe node should not trigger it being registered

View File

@ -27,7 +27,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -46,12 +45,12 @@ public class ClientSSLServiceTests extends ESTestCase {
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
testclientStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testclient.jks"); testclientStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testclient.jks");
env = randomBoolean() ? new Environment(settingsBuilder().put("path.home", createTempDir()).build()) : null; env = randomBoolean() ? new Environment(Settings.builder().put("path.home", createTempDir()).build()) : null;
} }
public void testThatInvalidProtocolThrowsException() throws Exception { public void testThatInvalidProtocolThrowsException() throws Exception {
try { try {
new ClientSSLService(settingsBuilder() new ClientSSLService(Settings.builder()
.put("xpack.security.ssl.protocol", "non-existing") .put("xpack.security.ssl.protocol", "non-existing")
.put("xpack.security.ssl.keystore.path", testclientStore) .put("xpack.security.ssl.keystore.path", testclientStore)
.put("xpack.security.ssl.keystore.password", "testclient") .put("xpack.security.ssl.keystore.password", "testclient")
@ -67,12 +66,12 @@ public class ClientSSLServiceTests extends ESTestCase {
public void testThatCustomTruststoreCanBeSpecified() throws Exception { public void testThatCustomTruststoreCanBeSpecified() throws Exception {
Path testnodeStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks"); Path testnodeStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks");
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testclientStore) .put("xpack.security.ssl.keystore.path", testclientStore)
.put("xpack.security.ssl.keystore.password", "testclient") .put("xpack.security.ssl.keystore.password", "testclient")
.build()); .build());
Settings.Builder settingsBuilder = settingsBuilder() Settings.Builder settingsBuilder = Settings.builder()
.put("truststore.path", testnodeStore) .put("truststore.path", testnodeStore)
.put("truststore.password", "testnode"); .put("truststore.password", "testnode");
@ -84,7 +83,7 @@ public class ClientSSLServiceTests extends ESTestCase {
} }
public void testThatSslContextCachingWorks() throws Exception { public void testThatSslContextCachingWorks() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testclientStore) .put("xpack.security.ssl.keystore.path", testclientStore)
.put("xpack.security.ssl.keystore.password", "testclient") .put("xpack.security.ssl.keystore.password", "testclient")
.build()); .build());
@ -97,7 +96,7 @@ public class ClientSSLServiceTests extends ESTestCase {
public void testThatKeyStoreAndKeyCanHaveDifferentPasswords() throws Exception { public void testThatKeyStoreAndKeyCanHaveDifferentPasswords() throws Exception {
Path differentPasswordsStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode-different-passwords.jks"); Path differentPasswordsStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode-different-passwords.jks");
createClientSSLService(settingsBuilder() createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", differentPasswordsStore) .put("xpack.security.ssl.keystore.path", differentPasswordsStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.put("xpack.security.ssl.keystore.key_password", "testnode1") .put("xpack.security.ssl.keystore.key_password", "testnode1")
@ -107,7 +106,7 @@ public class ClientSSLServiceTests extends ESTestCase {
public void testIncorrectKeyPasswordThrowsException() throws Exception { public void testIncorrectKeyPasswordThrowsException() throws Exception {
Path differentPasswordsStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode-different-passwords.jks"); Path differentPasswordsStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode-different-passwords.jks");
try { try {
createClientSSLService(settingsBuilder() createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", differentPasswordsStore) .put("xpack.security.ssl.keystore.path", differentPasswordsStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.build()).createSSLEngine(); .build()).createSSLEngine();
@ -118,7 +117,7 @@ public class ClientSSLServiceTests extends ESTestCase {
} }
public void testThatSSLv3IsNotEnabled() throws Exception { public void testThatSSLv3IsNotEnabled() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testclientStore) .put("xpack.security.ssl.keystore.path", testclientStore)
.put("xpack.security.ssl.keystore.password", "testclient") .put("xpack.security.ssl.keystore.password", "testclient")
.build()); .build());
@ -127,7 +126,7 @@ public class ClientSSLServiceTests extends ESTestCase {
} }
public void testThatSSLSessionCacheHasDefaultLimits() throws Exception { public void testThatSSLSessionCacheHasDefaultLimits() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testclientStore) .put("xpack.security.ssl.keystore.path", testclientStore)
.put("xpack.security.ssl.keystore.password", "testclient") .put("xpack.security.ssl.keystore.password", "testclient")
.build()); .build());
@ -137,7 +136,7 @@ public class ClientSSLServiceTests extends ESTestCase {
} }
public void testThatSettingSSLSessionCacheLimitsWorks() throws Exception { public void testThatSettingSSLSessionCacheLimitsWorks() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testclientStore) .put("xpack.security.ssl.keystore.path", testclientStore)
.put("xpack.security.ssl.keystore.password", "testclient") .put("xpack.security.ssl.keystore.password", "testclient")
.put("xpack.security.ssl.session.cache_size", "300") .put("xpack.security.ssl.session.cache_size", "300")
@ -155,7 +154,7 @@ public class ClientSSLServiceTests extends ESTestCase {
} }
public void testThatCreateSSLEngineWithOnlyTruststoreWorks() throws Exception { public void testThatCreateSSLEngineWithOnlyTruststoreWorks() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.truststore.path", testclientStore) .put("xpack.security.ssl.truststore.path", testclientStore)
.put("xpack.security.ssl.truststore.password", "testclient") .put("xpack.security.ssl.truststore.password", "testclient")
.build()); .build());
@ -164,7 +163,7 @@ public class ClientSSLServiceTests extends ESTestCase {
} }
public void testThatCreateSSLEngineWithOnlyKeystoreWorks() throws Exception { public void testThatCreateSSLEngineWithOnlyKeystoreWorks() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testclientStore) .put("xpack.security.ssl.keystore.path", testclientStore)
.put("xpack.security.ssl.keystore.password", "testclient") .put("xpack.security.ssl.keystore.password", "testclient")
.build()); .build());
@ -186,7 +185,7 @@ public class ClientSSLServiceTests extends ESTestCase {
@Network @Network
public void testThatSSLContextWithKeystoreDoesNotTrustAllPublicCAs() throws Exception { public void testThatSSLContextWithKeystoreDoesNotTrustAllPublicCAs() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testclientStore) .put("xpack.security.ssl.keystore.path", testclientStore)
.put("xpack.security.ssl.keystore.password", "testclient") .put("xpack.security.ssl.keystore.password", "testclient")
.build()); .build());
@ -203,7 +202,7 @@ public class ClientSSLServiceTests extends ESTestCase {
} }
public void testThatTruststorePasswordIsRequired() throws Exception { public void testThatTruststorePasswordIsRequired() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.truststore.path", testclientStore) .put("xpack.security.ssl.truststore.path", testclientStore)
.build()); .build());
try { try {
@ -215,7 +214,7 @@ public class ClientSSLServiceTests extends ESTestCase {
} }
public void testThatKeystorePasswordIsRequired() throws Exception { public void testThatKeystorePasswordIsRequired() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testclientStore) .put("xpack.security.ssl.keystore.path", testclientStore)
.build()); .build());
try { try {
@ -230,7 +229,7 @@ public class ClientSSLServiceTests extends ESTestCase {
List<String> ciphers = new ArrayList<>(SSLSettings.Globals.DEFAULT_CIPHERS); List<String> ciphers = new ArrayList<>(SSLSettings.Globals.DEFAULT_CIPHERS);
ciphers.add("foo"); ciphers.add("foo");
ciphers.add("bar"); ciphers.add("bar");
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.putArray("xpack.security.ssl.ciphers", ciphers.toArray(new String[ciphers.size()])) .putArray("xpack.security.ssl.ciphers", ciphers.toArray(new String[ciphers.size()]))
.build()); .build());
SSLEngine engine = sslService.createSSLEngine(); SSLEngine engine = sslService.createSSLEngine();
@ -240,7 +239,7 @@ public class ClientSSLServiceTests extends ESTestCase {
} }
public void testInvalidCiphersOnlyThrowsException() throws Exception { public void testInvalidCiphersOnlyThrowsException() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.putArray("xpack.security.ssl.ciphers", new String[] { "foo", "bar" }) .putArray("xpack.security.ssl.ciphers", new String[] { "foo", "bar" })
.build()); .build());
try { try {
@ -252,7 +251,7 @@ public class ClientSSLServiceTests extends ESTestCase {
} }
public void testThatSSLSocketFactoryHasProperCiphersAndProtocols() throws Exception { public void testThatSSLSocketFactoryHasProperCiphersAndProtocols() throws Exception {
ClientSSLService sslService = createClientSSLService(settingsBuilder() ClientSSLService sslService = createClientSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testclientStore) .put("xpack.security.ssl.keystore.path", testclientStore)
.put("xpack.security.ssl.keystore.password", "testclient") .put("xpack.security.ssl.keystore.password", "testclient")
.build()); .build());

View File

@ -12,7 +12,6 @@ import org.elasticsearch.test.ESTestCase;
import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.TrustManagerFactory;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
@ -34,7 +33,7 @@ public class SSLSettingsTests extends ESTestCase {
} }
public void testThatOnlyKeystoreInSettingsSetsTruststoreSettings() { public void testThatOnlyKeystoreInSettingsSetsTruststoreSettings() {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.ssl.keystore.path", "path") .put("xpack.security.ssl.keystore.path", "path")
.put("xpack.security.ssl.keystore.password", "password") .put("xpack.security.ssl.keystore.password", "password")
.build(); .build();
@ -46,7 +45,7 @@ public class SSLSettingsTests extends ESTestCase {
assertThat(sslSettings.trustStorePassword, is(equalTo(sslSettings.keyStorePassword))); assertThat(sslSettings.trustStorePassword, is(equalTo(sslSettings.keyStorePassword)));
// Pass settings in as profile settings // Pass settings in as profile settings
settings = settingsBuilder() settings = Settings.builder()
.put("keystore.path", "path") .put("keystore.path", "path")
.put("keystore.password", "password") .put("keystore.password", "password")
.build(); .build();
@ -58,14 +57,14 @@ public class SSLSettingsTests extends ESTestCase {
} }
public void testThatKeystorePasswordIsDefaultKeyPassword() { public void testThatKeystorePasswordIsDefaultKeyPassword() {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.ssl.keystore.password", "password") .put("xpack.security.ssl.keystore.password", "password")
.build(); .build();
// Pass settings in as component settings // Pass settings in as component settings
SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, settings); SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, settings);
assertThat(sslSettings.keyPassword, is(equalTo(sslSettings.keyStorePassword))); assertThat(sslSettings.keyPassword, is(equalTo(sslSettings.keyStorePassword)));
settings = settingsBuilder() settings = Settings.builder()
.put("keystore.password", "password") .put("keystore.password", "password")
.build(); .build();
// Pass settings in as profile settings // Pass settings in as profile settings
@ -74,7 +73,7 @@ public class SSLSettingsTests extends ESTestCase {
} }
public void testThatKeyPasswordCanBeSet() { public void testThatKeyPasswordCanBeSet() {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.ssl.keystore.password", "password") .put("xpack.security.ssl.keystore.password", "password")
.put("xpack.security.ssl.keystore.key_password", "key") .put("xpack.security.ssl.keystore.key_password", "key")
.build(); .build();
@ -84,7 +83,7 @@ public class SSLSettingsTests extends ESTestCase {
assertThat(sslSettings.keyPassword, is(equalTo("key"))); assertThat(sslSettings.keyPassword, is(equalTo("key")));
// Pass settings in as profile settings // Pass settings in as profile settings
settings = settingsBuilder() settings = Settings.builder()
.put("keystore.password", "password") .put("keystore.password", "password")
.put("keystore.key_password", "key") .put("keystore.key_password", "key")
.build(); .build();
@ -94,7 +93,7 @@ public class SSLSettingsTests extends ESTestCase {
} }
public void testThatProfileSettingsOverrideServiceSettings() { public void testThatProfileSettingsOverrideServiceSettings() {
Settings profileSettings = settingsBuilder() Settings profileSettings = Settings.builder()
.put("keystore.path", "path") .put("keystore.path", "path")
.put("keystore.password", "password") .put("keystore.password", "password")
.put("keystore.key_password", "key") .put("keystore.key_password", "key")
@ -107,7 +106,7 @@ public class SSLSettingsTests extends ESTestCase {
.put("session.cache_timeout", "10m") .put("session.cache_timeout", "10m")
.build(); .build();
Settings serviceSettings = settingsBuilder() Settings serviceSettings = Settings.builder()
.put("xpack.security.ssl.keystore.path", "comp path") .put("xpack.security.ssl.keystore.path", "comp path")
.put("xpack.security.ssl.keystore.password", "comp password") .put("xpack.security.ssl.keystore.password", "comp password")
.put("xpack.security.ssl.keystore.key_password", "comp key") .put("xpack.security.ssl.keystore.key_password", "comp key")
@ -143,9 +142,9 @@ public class SSLSettingsTests extends ESTestCase {
} }
public void testThatSettingsWithDifferentKeystoresAreNotEqual() { public void testThatSettingsWithDifferentKeystoresAreNotEqual() {
SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.keystore.path", "path").build()); .put("xpack.security.ssl.keystore.path", "path").build());
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.keystore.path", "path1").build()); .put("xpack.security.ssl.keystore.path", "path1").build());
assertThat(sslSettings.equals(sslSettings1), is(equalTo(false))); assertThat(sslSettings.equals(sslSettings1), is(equalTo(false)));
assertThat(sslSettings1.equals(sslSettings), is(equalTo(false))); assertThat(sslSettings1.equals(sslSettings), is(equalTo(false)));
@ -154,9 +153,9 @@ public class SSLSettingsTests extends ESTestCase {
} }
public void testThatSettingsWithDifferentProtocolsAreNotEqual() { public void testThatSettingsWithDifferentProtocolsAreNotEqual() {
SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.protocol", "ssl").build()); .put("xpack.security.ssl.protocol", "ssl").build());
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.protocol", "tls").build()); .put("xpack.security.ssl.protocol", "tls").build());
assertThat(sslSettings.equals(sslSettings1), is(equalTo(false))); assertThat(sslSettings.equals(sslSettings1), is(equalTo(false)));
assertThat(sslSettings1.equals(sslSettings), is(equalTo(false))); assertThat(sslSettings1.equals(sslSettings), is(equalTo(false)));
@ -165,9 +164,9 @@ public class SSLSettingsTests extends ESTestCase {
} }
public void testThatSettingsWithDifferentTruststoresAreNotEqual() { public void testThatSettingsWithDifferentTruststoresAreNotEqual() {
SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.truststore.path", "/trust").build()); .put("xpack.security.ssl.truststore.path", "/trust").build());
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.truststore.path", "/truststore").build()); .put("xpack.security.ssl.truststore.path", "/truststore").build());
assertThat(sslSettings.equals(sslSettings1), is(equalTo(false))); assertThat(sslSettings.equals(sslSettings1), is(equalTo(false)));
assertThat(sslSettings1.equals(sslSettings), is(equalTo(false))); assertThat(sslSettings1.equals(sslSettings), is(equalTo(false)));
@ -182,25 +181,25 @@ public class SSLSettingsTests extends ESTestCase {
} }
public void testThatSettingsWithDifferentKeystoresHaveDifferentHashCode() { public void testThatSettingsWithDifferentKeystoresHaveDifferentHashCode() {
SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.keystore.path", "path").build()); .put("xpack.security.ssl.keystore.path", "path").build());
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.keystore.path", "path1").build()); .put("xpack.security.ssl.keystore.path", "path1").build());
assertThat(sslSettings.hashCode(), is(not(equalTo(sslSettings1.hashCode())))); assertThat(sslSettings.hashCode(), is(not(equalTo(sslSettings1.hashCode()))));
} }
public void testThatSettingsWithDifferentProtocolsHaveDifferentHashCode() { public void testThatSettingsWithDifferentProtocolsHaveDifferentHashCode() {
SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.protocol", "ssl").build()); .put("xpack.security.ssl.protocol", "ssl").build());
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.protocol", "tls").build()); .put("xpack.security.ssl.protocol", "tls").build());
assertThat(sslSettings.hashCode(), is(not(equalTo(sslSettings1.hashCode())))); assertThat(sslSettings.hashCode(), is(not(equalTo(sslSettings1.hashCode()))));
} }
public void testThatSettingsWithDifferentTruststoresHaveDifferentHashCode() { public void testThatSettingsWithDifferentTruststoresHaveDifferentHashCode() {
SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.truststore.path", "/trust").build()); .put("xpack.security.ssl.truststore.path", "/trust").build());
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder() SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
.put("xpack.security.ssl.truststore.path", "/truststore").build()); .put("xpack.security.ssl.truststore.path", "/truststore").build());
assertThat(sslSettings.hashCode(), is(not(equalTo(sslSettings1.hashCode())))); assertThat(sslSettings.hashCode(), is(not(equalTo(sslSettings1.hashCode()))));
} }

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -40,11 +39,11 @@ public class ServerSSLServiceTests extends ESTestCase {
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
testnodeStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks"); testnodeStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks");
env = new Environment(settingsBuilder().put("path.home", createTempDir()).build()); env = new Environment(Settings.builder().put("path.home", createTempDir()).build());
} }
public void testThatInvalidProtocolThrowsException() throws Exception { public void testThatInvalidProtocolThrowsException() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.ssl.protocol", "non-existing") .put("xpack.security.ssl.protocol", "non-existing")
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
@ -62,13 +61,13 @@ public class ServerSSLServiceTests extends ESTestCase {
public void testThatCustomTruststoreCanBeSpecified() throws Exception { public void testThatCustomTruststoreCanBeSpecified() throws Exception {
Path testClientStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testclient.jks"); Path testClientStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testclient.jks");
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.build(); .build();
ServerSSLService sslService = new ServerSSLService(settings, env); ServerSSLService sslService = new ServerSSLService(settings, env);
Settings.Builder settingsBuilder = settingsBuilder() Settings.Builder settingsBuilder = Settings.builder()
.put("truststore.path", testClientStore) .put("truststore.path", testClientStore)
.put("truststore.password", "testclient"); .put("truststore.password", "testclient");
@ -80,7 +79,7 @@ public class ServerSSLServiceTests extends ESTestCase {
} }
public void testThatSslContextCachingWorks() throws Exception { public void testThatSslContextCachingWorks() throws Exception {
ServerSSLService sslService = new ServerSSLService(settingsBuilder() ServerSSLService sslService = new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.build(), env); .build(), env);
@ -93,7 +92,7 @@ public class ServerSSLServiceTests extends ESTestCase {
public void testThatKeyStoreAndKeyCanHaveDifferentPasswords() throws Exception { public void testThatKeyStoreAndKeyCanHaveDifferentPasswords() throws Exception {
Path differentPasswordsStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode-different-passwords.jks"); Path differentPasswordsStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode-different-passwords.jks");
new ServerSSLService(settingsBuilder() new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", differentPasswordsStore) .put("xpack.security.ssl.keystore.path", differentPasswordsStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.put("xpack.security.ssl.keystore.key_password", "testnode1") .put("xpack.security.ssl.keystore.key_password", "testnode1")
@ -103,7 +102,7 @@ public class ServerSSLServiceTests extends ESTestCase {
public void testIncorrectKeyPasswordThrowsException() throws Exception { public void testIncorrectKeyPasswordThrowsException() throws Exception {
Path differentPasswordsStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode-different-passwords.jks"); Path differentPasswordsStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode-different-passwords.jks");
try { try {
new ServerSSLService(settingsBuilder() new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", differentPasswordsStore) .put("xpack.security.ssl.keystore.path", differentPasswordsStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.build(), env).createSSLEngine(); .build(), env).createSSLEngine();
@ -114,7 +113,7 @@ public class ServerSSLServiceTests extends ESTestCase {
} }
public void testThatSSLv3IsNotEnabled() throws Exception { public void testThatSSLv3IsNotEnabled() throws Exception {
ServerSSLService sslService = new ServerSSLService(settingsBuilder() ServerSSLService sslService = new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.build(), env); .build(), env);
@ -123,7 +122,7 @@ public class ServerSSLServiceTests extends ESTestCase {
} }
public void testThatSSLSessionCacheHasDefaultLimits() throws Exception { public void testThatSSLSessionCacheHasDefaultLimits() throws Exception {
ServerSSLService sslService = new ServerSSLService(settingsBuilder() ServerSSLService sslService = new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.build(), env); .build(), env);
@ -133,7 +132,7 @@ public class ServerSSLServiceTests extends ESTestCase {
} }
public void testThatSettingSSLSessionCacheLimitsWorks() throws Exception { public void testThatSettingSSLSessionCacheLimitsWorks() throws Exception {
ServerSSLService sslService = new ServerSSLService(settingsBuilder() ServerSSLService sslService = new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.put("xpack.security.ssl.session.cache_size", "300") .put("xpack.security.ssl.session.cache_size", "300")
@ -155,7 +154,7 @@ public class ServerSSLServiceTests extends ESTestCase {
} }
public void testThatCreateSSLEngineWithOnlyTruststoreDoesNotWork() throws Exception { public void testThatCreateSSLEngineWithOnlyTruststoreDoesNotWork() throws Exception {
ServerSSLService sslService = new ServerSSLService(settingsBuilder() ServerSSLService sslService = new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.truststore.path", testnodeStore) .put("xpack.security.ssl.truststore.path", testnodeStore)
.put("xpack.security.ssl.truststore.password", "testnode") .put("xpack.security.ssl.truststore.password", "testnode")
.build(), env); .build(), env);
@ -168,7 +167,7 @@ public class ServerSSLServiceTests extends ESTestCase {
} }
public void testThatTruststorePasswordIsRequired() throws Exception { public void testThatTruststorePasswordIsRequired() throws Exception {
ServerSSLService sslService = new ServerSSLService(settingsBuilder() ServerSSLService sslService = new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.put("xpack.security.ssl.truststore.path", testnodeStore) .put("xpack.security.ssl.truststore.path", testnodeStore)
@ -182,7 +181,7 @@ public class ServerSSLServiceTests extends ESTestCase {
} }
public void testThatKeystorePasswordIsRequired() throws Exception { public void testThatKeystorePasswordIsRequired() throws Exception {
ServerSSLService sslService = new ServerSSLService(settingsBuilder() ServerSSLService sslService = new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.build(), env); .build(), env);
try { try {
@ -197,7 +196,7 @@ public class ServerSSLServiceTests extends ESTestCase {
List<String> ciphers = new ArrayList<>(SSLSettings.Globals.DEFAULT_CIPHERS); List<String> ciphers = new ArrayList<>(SSLSettings.Globals.DEFAULT_CIPHERS);
ciphers.add("foo"); ciphers.add("foo");
ciphers.add("bar"); ciphers.add("bar");
ServerSSLService sslService = new ServerSSLService(settingsBuilder() ServerSSLService sslService = new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.putArray("xpack.security.ssl.ciphers", ciphers.toArray(new String[ciphers.size()])) .putArray("xpack.security.ssl.ciphers", ciphers.toArray(new String[ciphers.size()]))
@ -209,7 +208,7 @@ public class ServerSSLServiceTests extends ESTestCase {
} }
public void testInvalidCiphersOnlyThrowsException() throws Exception { public void testInvalidCiphersOnlyThrowsException() throws Exception {
ServerSSLService sslService = new ServerSSLService(settingsBuilder() ServerSSLService sslService = new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.putArray("xpack.security.ssl.ciphers", new String[] { "foo", "bar" }) .putArray("xpack.security.ssl.ciphers", new String[] { "foo", "bar" })
@ -223,7 +222,7 @@ public class ServerSSLServiceTests extends ESTestCase {
} }
public void testThatSSLSocketFactoryHasProperCiphersAndProtocols() throws Exception { public void testThatSSLSocketFactoryHasProperCiphersAndProtocols() throws Exception {
ServerSSLService sslService = new ServerSSLService(settingsBuilder() ServerSSLService sslService = new ServerSSLService(Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.build(), env); .build(), env);

View File

@ -32,7 +32,6 @@ import java.nio.file.Path;
import java.util.Collections; import java.util.Collections;
import static java.util.Collections.singletonMap; import static java.util.Collections.singletonMap;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.shield.test.ShieldTestUtils.createFolder; import static org.elasticsearch.shield.test.ShieldTestUtils.createFolder;
import static org.elasticsearch.shield.test.ShieldTestUtils.writeFile; import static org.elasticsearch.shield.test.ShieldTestUtils.writeFile;
import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore; import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore;
@ -54,7 +53,7 @@ public class ServerTransportFilterIntegrationTests extends ShieldIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder settingsBuilder = settingsBuilder(); Settings.Builder settingsBuilder = Settings.builder();
String randomClientPortRange = randomClientPort + "-" + (randomClientPort+100); String randomClientPortRange = randomClientPort + "-" + (randomClientPort+100);
Path store; Path store;
@ -93,7 +92,7 @@ public class ServerTransportFilterIntegrationTests extends ShieldIntegTestCase {
String unicastHost = NetworkAddress.format(inetSocketAddress); String unicastHost = NetworkAddress.format(inetSocketAddress);
// test that starting up a node works // test that starting up a node works
Settings nodeSettings = settingsBuilder() Settings nodeSettings = Settings.builder()
.put(getSSLSettingsForStore("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks", "testnode")) .put(getSSLSettingsForStore("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks", "testnode"))
.put("node.mode", "network") .put("node.mode", "network")
.put("node.name", "my-test-node") .put("node.name", "my-test-node")
@ -119,7 +118,7 @@ public class ServerTransportFilterIntegrationTests extends ShieldIntegTestCase {
Path folder = createFolder(createTempDir(), getClass().getSimpleName() + "-" + randomAsciiOfLength(10)); Path folder = createFolder(createTempDir(), getClass().getSimpleName() + "-" + randomAsciiOfLength(10));
// test that starting up a node works // test that starting up a node works
Settings nodeSettings = settingsBuilder() Settings nodeSettings = Settings.builder()
.put("xpack.security.authc.realms.file.type", FileRealm.TYPE) .put("xpack.security.authc.realms.file.type", FileRealm.TYPE)
.put("xpack.security.authc.realms.file.order", 0) .put("xpack.security.authc.realms.file.order", 0)
.put("xpack.security.authc.realms.file.files.users", writeFile(folder, "users", configUsers())) .put("xpack.security.authc.realms.file.files.users", writeFile(folder, "users", configUsers()))

View File

@ -57,7 +57,7 @@ import static org.mockito.Mockito.when;
public class TransportFilterTests extends ESIntegTestCase { public class TransportFilterTests extends ESIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.settingsBuilder() return Settings.builder()
.put("node.mode", "network") .put("node.mode", "network")
.build(); .build();
} }

View File

@ -32,7 +32,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -82,7 +81,7 @@ public class IPFilterTests extends ESTestCase {
} }
public void testThatIpV4AddressesCanBeProcessed() throws Exception { public void testThatIpV4AddressesCanBeProcessed() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.allow", "127.0.0.1") .put("xpack.security.transport.filter.allow", "127.0.0.1")
.put("xpack.security.transport.filter.deny", "10.0.0.0/8") .put("xpack.security.transport.filter.deny", "10.0.0.0/8")
.build(); .build();
@ -95,7 +94,7 @@ public class IPFilterTests extends ESTestCase {
public void testThatIpV6AddressesCanBeProcessed() throws Exception { public void testThatIpV6AddressesCanBeProcessed() throws Exception {
// you have to use the shortest possible notation in order to match, so // you have to use the shortest possible notation in order to match, so
// 1234:0db8:85a3:0000:0000:8a2e:0370:7334 becomes 1234:db8:85a3:0:0:8a2e:370:7334 // 1234:0db8:85a3:0000:0000:8a2e:0370:7334 becomes 1234:db8:85a3:0:0:8a2e:370:7334
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.allow", "2001:0db8:1234::/48") .put("xpack.security.transport.filter.allow", "2001:0db8:1234::/48")
.putArray("xpack.security.transport.filter.deny", "1234:db8:85a3:0:0:8a2e:370:7334", "4321:db8:1234::/48") .putArray("xpack.security.transport.filter.deny", "1234:db8:85a3:0:0:8a2e:370:7334", "4321:db8:1234::/48")
.build(); .build();
@ -109,7 +108,7 @@ public class IPFilterTests extends ESTestCase {
@Network // requires network for name resolution @Network // requires network for name resolution
public void testThatHostnamesCanBeProcessed() throws Exception { public void testThatHostnamesCanBeProcessed() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.allow", "127.0.0.1") .put("xpack.security.transport.filter.allow", "127.0.0.1")
.put("xpack.security.transport.filter.deny", "*.google.com") .put("xpack.security.transport.filter.deny", "*.google.com")
.build(); .build();
@ -121,7 +120,7 @@ public class IPFilterTests extends ESTestCase {
} }
public void testThatAnAllowAllAuthenticatorWorks() throws Exception { public void testThatAnAllowAllAuthenticatorWorks() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.allow", "_all") .put("xpack.security.transport.filter.allow", "_all")
.build(); .build();
ipFilter = new IPFilter(settings, auditTrail, clusterSettings, licenseState); ipFilter = new IPFilter(settings, auditTrail, clusterSettings, licenseState);
@ -131,7 +130,7 @@ public class IPFilterTests extends ESTestCase {
} }
public void testThatProfilesAreSupported() throws Exception { public void testThatProfilesAreSupported() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.allow", "localhost") .put("xpack.security.transport.filter.allow", "localhost")
.put("xpack.security.transport.filter.deny", "_all") .put("xpack.security.transport.filter.deny", "_all")
.put("transport.profiles.client.xpack.security.filter.allow", "192.168.0.1") .put("transport.profiles.client.xpack.security.filter.allow", "192.168.0.1")
@ -146,7 +145,7 @@ public class IPFilterTests extends ESTestCase {
} }
public void testThatAllowWinsOverDeny() throws Exception { public void testThatAllowWinsOverDeny() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.allow", "10.0.0.1") .put("xpack.security.transport.filter.allow", "10.0.0.1")
.put("xpack.security.transport.filter.deny", "10.0.0.0/8") .put("xpack.security.transport.filter.deny", "10.0.0.0/8")
.build(); .build();
@ -157,7 +156,7 @@ public class IPFilterTests extends ESTestCase {
} }
public void testDefaultAllow() throws Exception { public void testDefaultAllow() throws Exception {
Settings settings = settingsBuilder().build(); Settings settings = Settings.builder().build();
ipFilter = new IPFilter(settings, auditTrail, clusterSettings, licenseState); ipFilter = new IPFilter(settings, auditTrail, clusterSettings, licenseState);
ipFilter.setBoundTransportAddress(transport.boundAddress(), transport.profileBoundAddresses()); ipFilter.setBoundTransportAddress(transport.boundAddress(), transport.profileBoundAddresses());
assertAddressIsAllowed("10.0.0.1"); assertAddressIsAllowed("10.0.0.1");
@ -165,7 +164,7 @@ public class IPFilterTests extends ESTestCase {
} }
public void testThatHttpWorks() throws Exception { public void testThatHttpWorks() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.allow", "127.0.0.1") .put("xpack.security.transport.filter.allow", "127.0.0.1")
.put("xpack.security.transport.filter.deny", "10.0.0.0/8") .put("xpack.security.transport.filter.deny", "10.0.0.0/8")
.put("xpack.security.http.filter.allow", "10.0.0.0/8") .put("xpack.security.http.filter.allow", "10.0.0.0/8")
@ -179,7 +178,7 @@ public class IPFilterTests extends ESTestCase {
} }
public void testThatHttpFallsbackToDefault() throws Exception { public void testThatHttpFallsbackToDefault() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.allow", "127.0.0.1") .put("xpack.security.transport.filter.allow", "127.0.0.1")
.put("xpack.security.transport.filter.deny", "10.0.0.0/8") .put("xpack.security.transport.filter.deny", "10.0.0.0/8")
.build(); .build();
@ -199,10 +198,10 @@ public class IPFilterTests extends ESTestCase {
Settings settings; Settings settings;
if (randomBoolean()) { if (randomBoolean()) {
settings = settingsBuilder().putArray("xpack.security.transport.filter.deny", settings = Settings.builder().putArray("xpack.security.transport.filter.deny",
addressStrings.toArray(new String[addressStrings.size()])).build(); addressStrings.toArray(new String[addressStrings.size()])).build();
} else { } else {
settings = settingsBuilder().put("xpack.security.transport.filter.deny", "_all").build(); settings = Settings.builder().put("xpack.security.transport.filter.deny", "_all").build();
} }
ipFilter = new IPFilter(settings, auditTrail, clusterSettings, licenseState); ipFilter = new IPFilter(settings, auditTrail, clusterSettings, licenseState);
ipFilter.setBoundTransportAddress(transport.boundAddress(), transport.profileBoundAddresses()); ipFilter.setBoundTransportAddress(transport.boundAddress(), transport.profileBoundAddresses());
@ -215,7 +214,7 @@ public class IPFilterTests extends ESTestCase {
} }
public void testThatAllAddressesAreAllowedWhenLicenseDisablesSecurity() { public void testThatAllAddressesAreAllowedWhenLicenseDisablesSecurity() {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.deny", "_all") .put("xpack.security.transport.filter.deny", "_all")
.build(); .build();
when(licenseState.securityEnabled()).thenReturn(false); when(licenseState.securityEnabled()).thenReturn(false);

View File

@ -16,7 +16,6 @@ import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Locale; import java.util.Locale;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -36,7 +35,7 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
String randomClientPortRange = randomClientPort + "-" + (randomClientPort+100); String randomClientPortRange = randomClientPort + "-" + (randomClientPort+100);
return settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), httpEnabled) .put(NetworkModule.HTTP_ENABLED.getKey(), httpEnabled)
.put("xpack.security.transport.filter.deny", "127.0.0.200") .put("xpack.security.transport.filter.deny", "127.0.0.200")
@ -53,14 +52,14 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
assertConnectionAccepted(".http", "127.0.0.8"); assertConnectionAccepted(".http", "127.0.0.8");
assertConnectionAccepted("client", "127.0.0.8"); assertConnectionAccepted("client", "127.0.0.8");
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.allow", "127.0.0.1") .put("xpack.security.transport.filter.allow", "127.0.0.1")
.put("xpack.security.transport.filter.deny", "127.0.0.8") .put("xpack.security.transport.filter.deny", "127.0.0.8")
.build(); .build();
updateSettings(settings); updateSettings(settings);
assertConnectionRejected("default", "127.0.0.8"); assertConnectionRejected("default", "127.0.0.8");
settings = settingsBuilder() settings = Settings.builder()
.putArray("xpack.security.http.filter.allow", "127.0.0.1") .putArray("xpack.security.http.filter.allow", "127.0.0.1")
.putArray("xpack.security.http.filter.deny", "127.0.0.8") .putArray("xpack.security.http.filter.deny", "127.0.0.8")
.build(); .build();
@ -68,7 +67,7 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
assertConnectionRejected("default", "127.0.0.8"); assertConnectionRejected("default", "127.0.0.8");
assertConnectionRejected(".http", "127.0.0.8"); assertConnectionRejected(".http", "127.0.0.8");
settings = settingsBuilder() settings = Settings.builder()
.put("transport.profiles.client.xpack.security.filter.allow", "127.0.0.1") .put("transport.profiles.client.xpack.security.filter.allow", "127.0.0.1")
.put("transport.profiles.client.xpack.security.filter.deny", "127.0.0.8") .put("transport.profiles.client.xpack.security.filter.deny", "127.0.0.8")
.build(); .build();
@ -87,7 +86,7 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
assertThat(clusterState.metaData().settings().get("transport.profiles.client.xpack.security.filter.deny"), is("127.0.0.8")); assertThat(clusterState.metaData().settings().get("transport.profiles.client.xpack.security.filter.deny"), is("127.0.0.8"));
// now disable ip filtering dynamically and make sure nothing is rejected // now disable ip filtering dynamically and make sure nothing is rejected
settings = settingsBuilder() settings = Settings.builder()
.put(IPFilter.IP_FILTER_ENABLED_SETTING.getKey(), false) .put(IPFilter.IP_FILTER_ENABLED_SETTING.getKey(), false)
.put(IPFilter.IP_FILTER_ENABLED_HTTP_SETTING.getKey(), true) .put(IPFilter.IP_FILTER_ENABLED_HTTP_SETTING.getKey(), true)
.build(); .build();
@ -107,7 +106,7 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
// now also disable for HTTP // now also disable for HTTP
if (httpEnabled) { if (httpEnabled) {
assertConnectionRejected(".http", "127.0.0.8"); assertConnectionRejected(".http", "127.0.0.8");
settings = settingsBuilder() settings = Settings.builder()
.put(IPFilter.IP_FILTER_ENABLED_HTTP_SETTING.getKey(), false) .put(IPFilter.IP_FILTER_ENABLED_HTTP_SETTING.getKey(), false)
.build(); .build();
// as we permanently switch between persistent and transient settings, just set both here to make sure we overwrite // as we permanently switch between persistent and transient settings, just set both here to make sure we overwrite
@ -119,13 +118,13 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
// issue #762, occured because in the above test we use HTTP and transport // issue #762, occured because in the above test we use HTTP and transport
public void testThatDisablingIpFilterWorksAsExpected() throws Exception { public void testThatDisablingIpFilterWorksAsExpected() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.deny", "127.0.0.8") .put("xpack.security.transport.filter.deny", "127.0.0.8")
.build(); .build();
updateSettings(settings); updateSettings(settings);
assertConnectionRejected("default", "127.0.0.8"); assertConnectionRejected("default", "127.0.0.8");
settings = settingsBuilder() settings = Settings.builder()
.put(IPFilter.IP_FILTER_ENABLED_SETTING.getKey(), false) .put(IPFilter.IP_FILTER_ENABLED_SETTING.getKey(), false)
.build(); .build();
updateSettings(settings); updateSettings(settings);
@ -133,13 +132,13 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
} }
public void testThatDisablingIpFilterForProfilesWorksAsExpected() throws Exception { public void testThatDisablingIpFilterForProfilesWorksAsExpected() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("transport.profiles.client.xpack.security.filter.deny", "127.0.0.8") .put("transport.profiles.client.xpack.security.filter.deny", "127.0.0.8")
.build(); .build();
updateSettings(settings); updateSettings(settings);
assertConnectionRejected("client", "127.0.0.8"); assertConnectionRejected("client", "127.0.0.8");
settings = settingsBuilder() settings = Settings.builder()
.put(IPFilter.IP_FILTER_ENABLED_SETTING.getKey(), false) .put(IPFilter.IP_FILTER_ENABLED_SETTING.getKey(), false)
.build(); .build();
updateSettings(settings); updateSettings(settings);

View File

@ -7,7 +7,6 @@ package org.elasticsearch.shield.transport.netty;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.shield.ssl.ServerSSLService; import org.elasticsearch.shield.ssl.ServerSSLService;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
@ -47,7 +46,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
@ -71,11 +69,11 @@ public class HandshakeWaitingHandlerTests extends ESTestCase {
randomPort = randomIntBetween(49000, 65500); randomPort = randomIntBetween(49000, 65500);
iterations = randomIntBetween(10, 100); iterations = randomIntBetween(10, 100);
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.ssl.keystore.path", getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks")) .put("xpack.security.ssl.keystore.path", getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks"))
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.build(); .build();
Environment env = new Environment(settingsBuilder().put("path.home", createTempDir()).build()); Environment env = new Environment(Settings.builder().put("path.home", createTempDir()).build());
ServerSSLService sslService = new ServerSSLService(settings, env); ServerSSLService sslService = new ServerSSLService(settings, env);
sslContext = sslService.sslContext(); sslContext = sslService.sslContext();

View File

@ -36,7 +36,7 @@ import java.net.SocketAddress;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -49,7 +49,7 @@ public class IPFilterNettyUpstreamHandlerTests extends ESTestCase {
@Before @Before
public void init() throws Exception { public void init() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.transport.filter.allow", "127.0.0.1") .put("xpack.security.transport.filter.allow", "127.0.0.1")
.put("xpack.security.transport.filter.deny", "10.0.0.0/8") .put("xpack.security.transport.filter.deny", "10.0.0.0/8")
.build(); .build();

View File

@ -13,7 +13,6 @@ import org.elasticsearch.transport.TransportSettings;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
public class IPHostnameVerificationTests extends ShieldIntegTestCase { public class IPHostnameVerificationTests extends ShieldIntegTestCase {
@ -34,7 +33,7 @@ public class IPHostnameVerificationTests extends ShieldIntegTestCase {
unicastAddresses[i] = address.replace("localhost", "127.0.0.1"); unicastAddresses[i] = address.replace("localhost", "127.0.0.1");
} }
Settings.Builder settingsBuilder = settingsBuilder() Settings.Builder settingsBuilder = Settings.builder()
.put(settings) .put(settings)
.putArray("discovery.zen.ping.unicast.hosts", unicastAddresses); .putArray("discovery.zen.ping.unicast.hosts", unicastAddresses);
@ -60,7 +59,7 @@ public class IPHostnameVerificationTests extends ShieldIntegTestCase {
@Override @Override
protected Settings transportClientSettings() { protected Settings transportClientSettings() {
return settingsBuilder().put(super.transportClientSettings()) return Settings.builder().put(super.transportClientSettings())
.put(ShieldNettyTransport.HOSTNAME_VERIFICATION_SETTING.getKey(), true) .put(ShieldNettyTransport.HOSTNAME_VERIFICATION_SETTING.getKey(), true)
.put(ShieldNettyTransport.HOSTNAME_VERIFICATION_RESOLVE_NAME_SETTING.getKey(), false) .put(ShieldNettyTransport.HOSTNAME_VERIFICATION_RESOLVE_NAME_SETTING.getKey(), false)
.put("xpack.security.ssl.keystore.path", keystore.toAbsolutePath()) .put("xpack.security.ssl.keystore.path", keystore.toAbsolutePath())

View File

@ -22,7 +22,6 @@ import org.junit.Before;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Locale; import java.util.Locale;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -33,11 +32,11 @@ public class ShieldNettyHttpServerTransportTests extends ESTestCase {
@Before @Before
public void createSSLService() throws Exception { public void createSSLService() throws Exception {
Path testnodeStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks"); Path testnodeStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks");
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.build(); .build();
Environment env = new Environment(settingsBuilder().put("path.home", createTempDir()).build()); Environment env = new Environment(Settings.builder().put("path.home", createTempDir()).build());
serverSSLService = new ServerSSLService(settings, env); serverSSLService = new ServerSSLService(settings, env);
} }

View File

@ -24,7 +24,6 @@ import org.junit.Before;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Locale; import java.util.Locale;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
@ -37,38 +36,38 @@ public class ShieldNettyTransportTests extends ESTestCase {
@Before @Before
public void createSSLService() throws Exception { public void createSSLService() throws Exception {
Path testnodeStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks"); Path testnodeStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode.jks");
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put("xpack.security.ssl.keystore.path", testnodeStore) .put("xpack.security.ssl.keystore.path", testnodeStore)
.put("xpack.security.ssl.keystore.password", "testnode") .put("xpack.security.ssl.keystore.password", "testnode")
.build(); .build();
Environment env = new Environment(settingsBuilder().put("path.home", createTempDir()).build()); Environment env = new Environment(Settings.builder().put("path.home", createTempDir()).build());
serverSSLService = new ServerSSLService(settings, env); serverSSLService = new ServerSSLService(settings, env);
clientSSLService = new ClientSSLService(settings); clientSSLService = new ClientSSLService(settings);
clientSSLService.setEnvironment(env); clientSSLService.setEnvironment(env);
} }
public void testThatSSLCanBeDisabledByProfile() throws Exception { public void testThatSSLCanBeDisabledByProfile() throws Exception {
Settings settings = settingsBuilder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build(); Settings settings = Settings.builder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build();
ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class), ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class),
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class)); mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
NettyMockUtil.setOpenChannelsHandlerToMock(transport); NettyMockUtil.setOpenChannelsHandlerToMock(transport);
ChannelPipelineFactory factory = transport.configureServerChannelPipelineFactory("client", ChannelPipelineFactory factory = transport.configureServerChannelPipelineFactory("client",
settingsBuilder().put("xpack.security.ssl", false).build()); Settings.builder().put("xpack.security.ssl", false).build());
assertThat(factory.getPipeline().get(SslHandler.class), nullValue()); assertThat(factory.getPipeline().get(SslHandler.class), nullValue());
} }
public void testThatSSLCanBeEnabledByProfile() throws Exception { public void testThatSSLCanBeEnabledByProfile() throws Exception {
Settings settings = settingsBuilder().put(ShieldNettyTransport.SSL_SETTING.getKey(), false).build(); Settings settings = Settings.builder().put(ShieldNettyTransport.SSL_SETTING.getKey(), false).build();
ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class), ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class),
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class)); mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
NettyMockUtil.setOpenChannelsHandlerToMock(transport); NettyMockUtil.setOpenChannelsHandlerToMock(transport);
ChannelPipelineFactory factory = transport.configureServerChannelPipelineFactory("client", ChannelPipelineFactory factory = transport.configureServerChannelPipelineFactory("client",
settingsBuilder().put("xpack.security.ssl", true).build()); Settings.builder().put("xpack.security.ssl", true).build());
assertThat(factory.getPipeline().get(SslHandler.class), notNullValue()); assertThat(factory.getPipeline().get(SslHandler.class), notNullValue());
} }
public void testThatProfileTakesDefaultSSLSetting() throws Exception { public void testThatProfileTakesDefaultSSLSetting() throws Exception {
Settings settings = settingsBuilder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build(); Settings settings = Settings.builder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build();
ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class), ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class),
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class)); mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
NettyMockUtil.setOpenChannelsHandlerToMock(transport); NettyMockUtil.setOpenChannelsHandlerToMock(transport);
@ -77,7 +76,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
} }
public void testDefaultClientAuth() throws Exception { public void testDefaultClientAuth() throws Exception {
Settings settings = settingsBuilder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build(); Settings settings = Settings.builder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build();
ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class), ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class),
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class)); mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
NettyMockUtil.setOpenChannelsHandlerToMock(transport); NettyMockUtil.setOpenChannelsHandlerToMock(transport);
@ -88,7 +87,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
public void testRequiredClientAuth() throws Exception { public void testRequiredClientAuth() throws Exception {
String value = randomFrom(SSLClientAuth.REQUIRED.name(), SSLClientAuth.REQUIRED.name().toLowerCase(Locale.ROOT), "true"); String value = randomFrom(SSLClientAuth.REQUIRED.name(), SSLClientAuth.REQUIRED.name().toLowerCase(Locale.ROOT), "true");
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
.put(ShieldNettyTransport.CLIENT_AUTH_SETTING.getKey(), value).build(); .put(ShieldNettyTransport.CLIENT_AUTH_SETTING.getKey(), value).build();
ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class), ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class),
@ -101,7 +100,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
public void testNoClientAuth() throws Exception { public void testNoClientAuth() throws Exception {
String value = randomFrom(SSLClientAuth.NO.name(), "false", "FALSE", SSLClientAuth.NO.name().toLowerCase(Locale.ROOT)); String value = randomFrom(SSLClientAuth.NO.name(), "false", "FALSE", SSLClientAuth.NO.name().toLowerCase(Locale.ROOT));
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
.put(ShieldNettyTransport.CLIENT_AUTH_SETTING.getKey(), value).build(); .put(ShieldNettyTransport.CLIENT_AUTH_SETTING.getKey(), value).build();
ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class), ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class),
@ -114,7 +113,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
public void testOptionalClientAuth() throws Exception { public void testOptionalClientAuth() throws Exception {
String value = randomFrom(SSLClientAuth.OPTIONAL.name(), SSLClientAuth.OPTIONAL.name().toLowerCase(Locale.ROOT)); String value = randomFrom(SSLClientAuth.OPTIONAL.name(), SSLClientAuth.OPTIONAL.name().toLowerCase(Locale.ROOT));
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
.put(ShieldNettyTransport.CLIENT_AUTH_SETTING.getKey(), value).build(); .put(ShieldNettyTransport.CLIENT_AUTH_SETTING.getKey(), value).build();
ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class), ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class),
@ -127,7 +126,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
public void testProfileRequiredClientAuth() throws Exception { public void testProfileRequiredClientAuth() throws Exception {
String value = randomFrom(SSLClientAuth.REQUIRED.name(), SSLClientAuth.REQUIRED.name().toLowerCase(Locale.ROOT), "true", "TRUE"); String value = randomFrom(SSLClientAuth.REQUIRED.name(), SSLClientAuth.REQUIRED.name().toLowerCase(Locale.ROOT), "true", "TRUE");
Settings settings = settingsBuilder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build(); Settings settings = Settings.builder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build();
ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class), ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class),
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class)); mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
NettyMockUtil.setOpenChannelsHandlerToMock(transport); NettyMockUtil.setOpenChannelsHandlerToMock(transport);
@ -139,7 +138,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
public void testProfileNoClientAuth() throws Exception { public void testProfileNoClientAuth() throws Exception {
String value = randomFrom(SSLClientAuth.NO.name(), "false", "FALSE", SSLClientAuth.NO.name().toLowerCase(Locale.ROOT)); String value = randomFrom(SSLClientAuth.NO.name(), "false", "FALSE", SSLClientAuth.NO.name().toLowerCase(Locale.ROOT));
Settings settings = settingsBuilder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build(); Settings settings = Settings.builder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build();
ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class), ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), mock(NetworkService.class),
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class)); mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
NettyMockUtil.setOpenChannelsHandlerToMock(transport); NettyMockUtil.setOpenChannelsHandlerToMock(transport);
@ -151,7 +150,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
public void testProfileOptionalClientAuth() throws Exception { public void testProfileOptionalClientAuth() throws Exception {
String value = randomFrom(SSLClientAuth.OPTIONAL.name(), SSLClientAuth.OPTIONAL.name().toLowerCase(Locale.ROOT)); String value = randomFrom(SSLClientAuth.OPTIONAL.name(), SSLClientAuth.OPTIONAL.name().toLowerCase(Locale.ROOT));
Settings settings = settingsBuilder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build(); Settings settings = Settings.builder().put(ShieldNettyTransport.SSL_SETTING.getKey(), true).build();
ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class), ShieldNettyTransport transport = new ShieldNettyTransport(settings, mock(ThreadPool.class),
mock(NetworkService.class), mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NetworkService.class), mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService,
mock(NamedWriteableRegistry.class)); mock(NamedWriteableRegistry.class));

View File

@ -19,7 +19,6 @@ import java.net.InetSocketAddress;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
@ -32,7 +31,7 @@ public class SslHostnameVerificationTests extends ShieldIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder settingsBuilder = settingsBuilder().put(super.nodeSettings(nodeOrdinal)); Settings.Builder settingsBuilder = Settings.builder().put(super.nodeSettings(nodeOrdinal));
Path keystore; Path keystore;
try { try {
/* /*
@ -72,7 +71,7 @@ public class SslHostnameVerificationTests extends ShieldIntegTestCase {
assertThat(transportAddress, instanceOf(InetSocketTransportAddress.class)); assertThat(transportAddress, instanceOf(InetSocketTransportAddress.class));
InetSocketAddress inetSocketAddress = ((InetSocketTransportAddress) transportAddress).address(); InetSocketAddress inetSocketAddress = ((InetSocketTransportAddress) transportAddress).address();
Settings settings = settingsBuilder().put(transportClientSettings()) Settings settings = Settings.builder().put(transportClientSettings())
.put(ShieldNettyTransport.HOSTNAME_VERIFICATION_SETTING.getKey(), true) .put(ShieldNettyTransport.HOSTNAME_VERIFICATION_SETTING.getKey(), true)
.build(); .build();

View File

@ -30,7 +30,6 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore; import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
@ -38,7 +37,7 @@ import static org.hamcrest.Matchers.containsString;
public class SslClientAuthTests extends ShieldIntegTestCase { public class SslClientAuthTests extends ShieldIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
// invert the require auth settings // invert the require auth settings
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
@ -74,7 +73,7 @@ public class SslClientAuthTests extends ShieldIntegTestCase {
} }
public void testThatHttpWorksWithSslClientAuth() throws IOException { public void testThatHttpWorksWithSslClientAuth() throws IOException {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(getSSLSettingsForStore("/org/elasticsearch/shield/transport/ssl/certs/simple/testclient.jks", "testclient")) .put(getSSLSettingsForStore("/org/elasticsearch/shield/transport/ssl/certs/simple/testclient.jks", "testclient"))
.build(); .build();
ClientSSLService sslService = new ClientSSLService(settings); ClientSSLService sslService = new ClientSSLService(settings);
@ -102,7 +101,7 @@ public class SslClientAuthTests extends ShieldIntegTestCase {
throw new ElasticsearchException("store path doesn't exist"); throw new ElasticsearchException("store path doesn't exist");
} }
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
.put("xpack.security.ssl.keystore.path", store) .put("xpack.security.ssl.keystore.path", store)
.put("xpack.security.ssl.keystore.password", "testclient-client-profile") .put("xpack.security.ssl.keystore.password", "testclient-client-profile")

View File

@ -37,7 +37,6 @@ import java.security.KeyStore;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Locale; import java.util.Locale;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore; import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
@ -46,7 +45,7 @@ import static org.hamcrest.Matchers.instanceOf;
public class SslIntegrationTests extends ShieldIntegTestCase { public class SslIntegrationTests extends ShieldIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return settingsBuilder().put(super.nodeSettings(nodeOrdinal)) return Settings.builder().put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true) .put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put(ShieldNettyHttpServerTransport.SSL_SETTING.getKey(), true).build(); .put(ShieldNettyHttpServerTransport.SSL_SETTING.getKey(), true).build();
} }
@ -58,7 +57,7 @@ public class SslIntegrationTests extends ShieldIntegTestCase {
// no SSL exception as this is the exception is returned when connecting // no SSL exception as this is the exception is returned when connecting
public void testThatUnconfiguredCiphersAreRejected() { public void testThatUnconfiguredCiphersAreRejected() {
try (TransportClient transportClient = TransportClient.builder().addPlugin(XPackPlugin.class).settings(settingsBuilder() try (TransportClient transportClient = TransportClient.builder().addPlugin(XPackPlugin.class).settings(Settings.builder()
.put(transportClientSettings()) .put(transportClientSettings())
.put("node.name", "programmatic_transport_client") .put("node.name", "programmatic_transport_client")
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
@ -77,7 +76,7 @@ public class SslIntegrationTests extends ShieldIntegTestCase {
// no SSL exception as this is the exception is returned when connecting // no SSL exception as this is the exception is returned when connecting
public void testThatTransportClientUsingSSLv3ProtocolIsRejected() { public void testThatTransportClientUsingSSLv3ProtocolIsRejected() {
try(TransportClient transportClient = TransportClient.builder().addPlugin(XPackPlugin.class).settings(settingsBuilder() try(TransportClient transportClient = TransportClient.builder().addPlugin(XPackPlugin.class).settings(Settings.builder()
.put(transportClientSettings()) .put(transportClientSettings())
.put("node.name", "programmatic_transport_client") .put("node.name", "programmatic_transport_client")
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())

View File

@ -21,7 +21,6 @@ import java.net.InetAddress;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.ShieldSettingsSource.DEFAULT_PASSWORD; import static org.elasticsearch.test.ShieldSettingsSource.DEFAULT_PASSWORD;
import static org.elasticsearch.test.ShieldSettingsSource.DEFAULT_USER_NAME; import static org.elasticsearch.test.ShieldSettingsSource.DEFAULT_USER_NAME;
import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore; import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore;
@ -64,7 +63,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
// client set up here // client set up here
.put("transport.profiles.client.port", randomClientPortRange) .put("transport.profiles.client.port", randomClientPortRange)
@ -88,7 +87,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
} }
private TransportClient createTransportClient(Settings additionalSettings) { private TransportClient createTransportClient(Settings additionalSettings) {
Settings settings = settingsBuilder().put(transportClientSettings()) Settings settings = Settings.builder().put(transportClientSettings())
.put("node.name", "programmatic_transport_client") .put("node.name", "programmatic_transport_client")
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.put(additionalSettings) .put(additionalSettings)
@ -223,7 +222,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* Uses a transport client with SSL disabled. This test connects to the no_ssl profile, which should always succeed * Uses a transport client with SSL disabled. This test connects to the no_ssl profile, which should always succeed
*/ */
public void testThatTransportClientCanConnectToNoSslProfile() throws Exception { public void testThatTransportClientCanConnectToNoSslProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.build(); .build();
@ -238,7 +237,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* as a non-ssl transport client cannot connect to a ssl profile * as a non-ssl transport client cannot connect to a ssl profile
*/ */
public void testThatTransportClientCannotConnectToDefaultProfile() throws Exception { public void testThatTransportClientCannotConnectToDefaultProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.build(); .build();
@ -256,7 +255,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* as a non-ssl transport client cannot connect to a ssl profile * as a non-ssl transport client cannot connect to a ssl profile
*/ */
public void testThatTransportClientCannotConnectToClientProfile() throws Exception { public void testThatTransportClientCannotConnectToClientProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.build(); .build();
@ -274,7 +273,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* as a non-ssl transport client cannot connect to a ssl profile * as a non-ssl transport client cannot connect to a ssl profile
*/ */
public void testThatTransportClientCannotConnectToNoClientAuthProfile() throws Exception { public void testThatTransportClientCannotConnectToNoClientAuthProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.build(); .build();
@ -294,7 +293,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* the testnode certificate and does not require to present a certificate, so this connection should always succeed * the testnode certificate and does not require to present a certificate, so this connection should always succeed
*/ */
public void testThatTransportClientWithOnlyTruststoreCanConnectToNoClientAuthProfile() throws Exception { public void testThatTransportClientWithOnlyTruststoreCanConnectToNoClientAuthProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
@ -316,7 +315,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* the client has no certificate to present * the client has no certificate to present
*/ */
public void testThatTransportClientWithOnlyTruststoreCannotConnectToClientProfile() throws Exception { public void testThatTransportClientWithOnlyTruststoreCannotConnectToClientProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
@ -340,7 +339,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* the client has no certificate to present * the client has no certificate to present
*/ */
public void testThatTransportClientWithOnlyTruststoreCannotConnectToDefaultProfile() throws Exception { public void testThatTransportClientWithOnlyTruststoreCannotConnectToDefaultProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
@ -363,7 +362,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* SSL so the connection should never succeed * SSL so the connection should never succeed
*/ */
public void testThatTransportClientWithOnlyTruststoreCannotConnectToNoSslProfile() throws Exception { public void testThatTransportClientWithOnlyTruststoreCannotConnectToNoSslProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
@ -386,7 +385,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* will never be trusted by the default truststore so the connection should always fail * will never be trusted by the default truststore so the connection should always fail
*/ */
public void testThatSSLTransportClientWithNoTruststoreCannotConnectToDefaultProfile() throws Exception { public void testThatSSLTransportClientWithNoTruststoreCannotConnectToDefaultProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
@ -406,7 +405,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* will never be trusted by the default truststore so the connection should always fail * will never be trusted by the default truststore so the connection should always fail
*/ */
public void testThatSSLTransportClientWithNoTruststoreCannotConnectToClientProfile() throws Exception { public void testThatSSLTransportClientWithNoTruststoreCannotConnectToClientProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
@ -426,7 +425,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* will never be trusted by the default truststore so the connection should always fail * will never be trusted by the default truststore so the connection should always fail
*/ */
public void testThatSSLTransportClientWithNoTruststoreCannotConnectToNoClientAuthProfile() throws Exception { public void testThatSSLTransportClientWithNoTruststoreCannotConnectToNoClientAuthProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
@ -447,7 +446,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
* will not work * will not work
*/ */
public void testThatSSLTransportClientWithNoTruststoreCannotConnectToNoSslProfile() throws Exception { public void testThatSSLTransportClientWithNoTruststoreCannotConnectToNoSslProfile() throws Exception {
Settings settings = settingsBuilder() Settings settings = Settings.builder()
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD) .put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
.put("cluster.name", internalCluster().getClusterName()) .put("cluster.name", internalCluster().getClusterName())
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true) .put(ShieldNettyTransport.SSL_SETTING.getKey(), true)

View File

@ -35,7 +35,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.test.ESTestCase.randomFrom; import static org.elasticsearch.test.ESTestCase.randomFrom;
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.elasticsearch.shield.test.ShieldTestUtils.writeFile; import static org.elasticsearch.shield.test.ShieldTestUtils.writeFile;
@ -48,7 +47,7 @@ import static org.elasticsearch.shield.test.ShieldTestUtils.writeFile;
*/ */
public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZen { public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZen {
public static final Settings DEFAULT_SETTINGS = settingsBuilder() public static final Settings DEFAULT_SETTINGS = Settings.builder()
.put("node.mode", "network") .put("node.mode", "network")
.build(); .build();
@ -120,7 +119,7 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ
@Override @Override
public Settings nodeSettings(int nodeOrdinal) { public Settings nodeSettings(int nodeOrdinal) {
Path folder = ShieldTestUtils.createFolder(parentFolder, subfolderPrefix + "-" + nodeOrdinal); Path folder = ShieldTestUtils.createFolder(parentFolder, subfolderPrefix + "-" + nodeOrdinal);
Settings.Builder builder = settingsBuilder().put(super.nodeSettings(nodeOrdinal)) Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal))
//TODO: for now isolate shield tests from watcher & monitoring (randomize this later) //TODO: for now isolate shield tests from watcher & monitoring (randomize this later)
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false) .put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false)
@ -144,7 +143,7 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ
@Override @Override
public Settings transportClientSettings() { public Settings transportClientSettings() {
Settings.Builder builder = settingsBuilder().put(super.transportClientSettings()) Settings.Builder builder = Settings.builder().put(super.transportClientSettings())
.put(getClientSSLSettings()); .put(getClientSSLSettings());
if (randomBoolean()) { if (randomBoolean()) {
builder.put(Security.USER_SETTING.getKey(), builder.put(Security.USER_SETTING.getKey(),
@ -247,7 +246,7 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ
final String sslEnabledSetting = final String sslEnabledSetting =
randomFrom(ShieldNettyTransport.SSL_SETTING.getKey(), ShieldNettyTransport.DEPRECATED_SSL_SETTING.getKey()); randomFrom(ShieldNettyTransport.SSL_SETTING.getKey(), ShieldNettyTransport.DEPRECATED_SSL_SETTING.getKey());
Settings.Builder builder = settingsBuilder().put(sslEnabledSetting, sslTransportEnabled); Settings.Builder builder = Settings.builder().put(sslEnabledSetting, sslTransportEnabled);
if (transportClient == false) { if (transportClient == false) {
builder.put(ShieldNettyHttpServerTransport.SSL_SETTING.getKey(), false); builder.put(ShieldNettyHttpServerTransport.SSL_SETTING.getKey(), false);

View File

@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.startsWith;
public class ShieldServerTransportServiceTests extends ShieldIntegTestCase { public class ShieldServerTransportServiceTests extends ShieldIntegTestCase {
@Override @Override
protected Settings transportClientSettings() { protected Settings transportClientSettings() {
return Settings.settingsBuilder() return Settings.builder()
.put(super.transportClientSettings()) .put(super.transportClientSettings())
.put(Security.enabledSetting(), true) .put(Security.enabledSetting(), true)
.build(); .build();

View File

@ -93,8 +93,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
public class Watcher { public class Watcher {
public static final String NAME = "watcher"; public static final String NAME = "watcher";
@ -162,7 +160,7 @@ public class Watcher {
if (enabled == false || transportClient) { if (enabled == false || transportClient) {
return Settings.EMPTY; return Settings.EMPTY;
} }
Settings additionalSettings = settingsBuilder() Settings additionalSettings = Settings.builder()
.put(HistoryModule.additionalSettings(settings)) .put(HistoryModule.additionalSettings(settings))
.build(); .build();

View File

@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.not;
public class WatcherPluginDisableTests extends ESIntegTestCase { public class WatcherPluginDisableTests extends ESIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.settingsBuilder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false) .put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false)

View File

@ -26,7 +26,7 @@ public class AlwaysConditionTests extends ESTestCase {
} }
public void testParserValid() throws Exception { public void testParserValid() throws Exception {
AlwaysConditionFactory factory = new AlwaysConditionFactory(Settings.settingsBuilder().build()); AlwaysConditionFactory factory = new AlwaysConditionFactory(Settings.builder().build());
XContentBuilder builder = jsonBuilder(); XContentBuilder builder = jsonBuilder();
builder.startObject(); builder.startObject();
builder.endObject(); builder.endObject();
@ -38,7 +38,7 @@ public class AlwaysConditionTests extends ESTestCase {
} }
public void testParserInvalid() throws Exception { public void testParserInvalid() throws Exception {
ConditionFactory factor = new AlwaysConditionFactory(Settings.settingsBuilder().build()); ConditionFactory factor = new AlwaysConditionFactory(Settings.builder().build());
XContentBuilder builder = jsonBuilder() XContentBuilder builder = jsonBuilder()
.startObject() .startObject()
.field("foo", "bar") .field("foo", "bar")

View File

@ -27,7 +27,7 @@ public class NeverConditionTests extends ESTestCase {
} }
public void testParserValid() throws Exception { public void testParserValid() throws Exception {
NeverConditionFactory factory = new NeverConditionFactory(Settings.settingsBuilder().build()); NeverConditionFactory factory = new NeverConditionFactory(Settings.builder().build());
XContentBuilder builder = jsonBuilder(); XContentBuilder builder = jsonBuilder();
builder.startObject(); builder.startObject();
builder.endObject(); builder.endObject();
@ -40,7 +40,7 @@ public class NeverConditionTests extends ESTestCase {
} }
public void testParserInvalid() throws Exception { public void testParserInvalid() throws Exception {
ConditionFactory factory = new NeverConditionFactory(Settings.settingsBuilder().build()); ConditionFactory factory = new NeverConditionFactory(Settings.builder().build());
XContentBuilder builder = jsonBuilder(); XContentBuilder builder = jsonBuilder();
builder.startObject(); builder.startObject();
builder.field("foo", "bar"); builder.field("foo", "bar");

View File

@ -78,7 +78,7 @@ public class ScriptConditionTests extends ESTestCase {
} }
public void testParserValid() throws Exception { public void testParserValid() throws Exception {
ScriptConditionFactory factory = new ScriptConditionFactory(Settings.settingsBuilder().build(), getScriptServiceProxy(tp)); ScriptConditionFactory factory = new ScriptConditionFactory(Settings.builder().build(), getScriptServiceProxy(tp));
XContentBuilder builder = createConditionContent("ctx.payload.hits.total > 1", null, ScriptType.INLINE); XContentBuilder builder = createConditionContent("ctx.payload.hits.total > 1", null, ScriptType.INLINE);
@ -105,7 +105,7 @@ public class ScriptConditionTests extends ESTestCase {
} }
public void testParserInvalid() throws Exception { public void testParserInvalid() throws Exception {
ScriptConditionFactory factory = new ScriptConditionFactory(Settings.settingsBuilder().build(), getScriptServiceProxy(tp)); ScriptConditionFactory factory = new ScriptConditionFactory(Settings.builder().build(), getScriptServiceProxy(tp));
XContentBuilder builder = XContentFactory.jsonBuilder(); XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject().endObject(); builder.startObject().endObject();
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes()); XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
@ -120,7 +120,7 @@ public class ScriptConditionTests extends ESTestCase {
} }
public void testScriptConditionParserBadScript() throws Exception { public void testScriptConditionParserBadScript() throws Exception {
ScriptConditionFactory conditionParser = new ScriptConditionFactory(Settings.settingsBuilder().build(), getScriptServiceProxy(tp)); ScriptConditionFactory conditionParser = new ScriptConditionFactory(Settings.builder().build(), getScriptServiceProxy(tp));
ScriptType scriptType = randomFrom(ScriptType.values()); ScriptType scriptType = randomFrom(ScriptType.values());
String script; String script;
switch (scriptType) { switch (scriptType) {
@ -146,7 +146,7 @@ public class ScriptConditionTests extends ESTestCase {
} }
public void testScriptConditionParser_badLang() throws Exception { public void testScriptConditionParser_badLang() throws Exception {
ScriptConditionFactory conditionParser = new ScriptConditionFactory(Settings.settingsBuilder().build(), getScriptServiceProxy(tp)); ScriptConditionFactory conditionParser = new ScriptConditionFactory(Settings.builder().build(), getScriptServiceProxy(tp));
ScriptType scriptType = ScriptType.INLINE; ScriptType scriptType = ScriptType.INLINE;
String script = "return true"; String script = "return true";
XContentBuilder builder = createConditionContent(script, "not_a_valid_lang", scriptType); XContentBuilder builder = createConditionContent(script, "not_a_valid_lang", scriptType);

View File

@ -6,6 +6,12 @@
package org.elasticsearch.watcher.support; package org.elasticsearch.watcher.support;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.IndicesOptions;
@ -20,9 +26,9 @@ import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.MatchAllQueryParser;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryParser;
import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.script.ScriptService.ScriptType;
import org.elasticsearch.script.Template; import org.elasticsearch.script.Template;
@ -33,13 +39,8 @@ import org.elasticsearch.watcher.support.clock.SystemClock;
import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.support.text.TextTemplate;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import static java.util.Collections.singletonMap; import static java.util.Collections.singletonMap;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.watcher.support.WatcherDateTimeUtils.formatDate; import static org.elasticsearch.watcher.support.WatcherDateTimeUtils.formatDate;
import static org.elasticsearch.watcher.support.WatcherUtils.DEFAULT_INDICES_OPTIONS; import static org.elasticsearch.watcher.support.WatcherUtils.DEFAULT_INDICES_OPTIONS;
@ -135,8 +136,9 @@ public class WatcherUtilsTests extends ESTestCase {
builder = WatcherUtils.writeSearchRequest(expectedRequest, builder, ToXContent.EMPTY_PARAMS); builder = WatcherUtils.writeSearchRequest(expectedRequest, builder, ToXContent.EMPTY_PARAMS);
XContentParser parser = XContentHelper.createParser(builder.bytes()); XContentParser parser = XContentHelper.createParser(builder.bytes());
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT)); assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
QueryParser<MatchAllQueryBuilder> termQueryParser = MatchAllQueryBuilder::fromXContent;
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY,
singletonMap(MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryParser.QUERY_NAME_FIELD, new MatchAllQueryParser()))); singletonMap(MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryBuilder.QUERY_NAME_FIELD, termQueryParser)));
QueryParseContext context = new QueryParseContext(registry); QueryParseContext context = new QueryParseContext(registry);
context.reset(parser); context.reset(parser);
SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null, null); SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null, null);
@ -224,8 +226,9 @@ public class WatcherUtilsTests extends ESTestCase {
XContentParser parser = XContentHelper.createParser(builder.bytes()); XContentParser parser = XContentHelper.createParser(builder.bytes());
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT)); assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
QueryParser<MatchAllQueryBuilder> termQueryParser = MatchAllQueryBuilder::fromXContent;
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY,
singletonMap(MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryParser.QUERY_NAME_FIELD, new MatchAllQueryParser()))); singletonMap(MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryBuilder.QUERY_NAME_FIELD, termQueryParser)));
QueryParseContext context = new QueryParseContext(registry); QueryParseContext context = new QueryParseContext(registry);
context.reset(parser); context.reset(parser);
SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null, null); SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null, null);

View File

@ -238,7 +238,7 @@ public final class WatcherTestUtils {
} }
public static ScriptServiceProxy getScriptServiceProxy(ThreadPool tp) throws Exception { public static ScriptServiceProxy getScriptServiceProxy(ThreadPool tp) throws Exception {
Settings settings = Settings.settingsBuilder() Settings settings = Settings.builder()
.put("script.inline", "true") .put("script.inline", "true")
.put("script.indexed", "true") .put("script.indexed", "true")
.put("path.home", createTempDir()) .put("path.home", createTempDir())

View File

@ -22,7 +22,6 @@ import java.io.OutputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
@ -59,7 +58,7 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
//Set path so ScriptService will pick up the test scripts //Set path so ScriptService will pick up the test scripts
return settingsBuilder().put(super.nodeSettings(nodeOrdinal)).put("path.conf", configDir.toString()).build(); return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put("path.conf", configDir.toString()).build();
} }
public void testScriptTransform() throws Exception { public void testScriptTransform() throws Exception {

View File

@ -170,7 +170,7 @@ public class ScriptTransformTests extends ESTestCase {
} }
public void testScriptConditionParserBadScript() throws Exception { public void testScriptConditionParserBadScript() throws Exception {
ScriptTransformFactory transformFactory = new ScriptTransformFactory(Settings.settingsBuilder().build(), getScriptServiceProxy(tp)); ScriptTransformFactory transformFactory = new ScriptTransformFactory(Settings.builder().build(), getScriptServiceProxy(tp));
ScriptType scriptType = randomFrom(ScriptType.values()); ScriptType scriptType = randomFrom(ScriptType.values());
String script; String script;
switch (scriptType) { switch (scriptType) {
@ -202,7 +202,7 @@ public class ScriptTransformTests extends ESTestCase {
} }
public void testScriptConditionParserBadLang() throws Exception { public void testScriptConditionParserBadLang() throws Exception {
ScriptTransformFactory transformFactory = new ScriptTransformFactory(Settings.settingsBuilder().build(), getScriptServiceProxy(tp)); ScriptTransformFactory transformFactory = new ScriptTransformFactory(Settings.builder().build(), getScriptServiceProxy(tp));
ScriptType scriptType = randomFrom(ScriptType.values()); ScriptType scriptType = randomFrom(ScriptType.values());
String script = "return true"; String script = "return true";
XContentBuilder builder = jsonBuilder().startObject() XContentBuilder builder = jsonBuilder().startObject()

View File

@ -5,6 +5,14 @@
*/ */
package org.elasticsearch.watcher.watch; package org.elasticsearch.watcher.watch;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.collect.Tuple;
@ -15,7 +23,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.MatchAllQueryParser; import org.elasticsearch.index.query.QueryParser;
import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.watcher.actions.ActionFactory; import org.elasticsearch.watcher.actions.ActionFactory;
@ -78,8 +86,8 @@ import org.elasticsearch.watcher.support.http.HttpMethod;
import org.elasticsearch.watcher.support.http.HttpRequestTemplate; import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry; import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry;
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory; import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory;
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
import org.elasticsearch.watcher.support.secret.SecretService; import org.elasticsearch.watcher.support.secret.SecretService;
import org.elasticsearch.watcher.support.text.TextTemplate; import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine; import org.elasticsearch.watcher.support.text.TextTemplateEngine;
@ -119,17 +127,10 @@ import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.junit.Before; import org.junit.Before;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.util.Collections.singleton; import static java.util.Collections.singleton;
import static java.util.Collections.singletonMap; import static java.util.Collections.singletonMap;
import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.watcher.input.InputBuilders.searchInput; import static org.elasticsearch.watcher.input.InputBuilders.searchInput;
import static org.elasticsearch.watcher.test.WatcherTestUtils.matchAllRequest; import static org.elasticsearch.watcher.test.WatcherTestUtils.matchAllRequest;
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule; import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
@ -352,8 +353,9 @@ public class WatchTests extends ESTestCase {
Map<String, InputFactory> parsers = new HashMap<>(); Map<String, InputFactory> parsers = new HashMap<>();
switch (input.type()) { switch (input.type()) {
case SearchInput.TYPE: case SearchInput.TYPE:
QueryParser<MatchAllQueryBuilder> termQueryParser = MatchAllQueryBuilder::fromXContent;
IndicesQueriesRegistry queryRegistry = new IndicesQueriesRegistry(Settings.EMPTY, singletonMap( IndicesQueriesRegistry queryRegistry = new IndicesQueriesRegistry(Settings.EMPTY, singletonMap(
MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryParser.QUERY_NAME_FIELD, new MatchAllQueryParser()))); MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryBuilder.QUERY_NAME_FIELD, termQueryParser)));
parsers.put(SearchInput.TYPE, new SearchInputFactory(settings, client, queryRegistry, null, null)); parsers.put(SearchInput.TYPE, new SearchInputFactory(settings, client, queryRegistry, null, null));
return new InputRegistry(parsers); return new InputRegistry(parsers);
default: default:
@ -419,8 +421,9 @@ public class WatchTests extends ESTestCase {
} }
private TransformRegistry transformRegistry() { private TransformRegistry transformRegistry() {
QueryParser<MatchAllQueryBuilder> termQueryParser = MatchAllQueryBuilder::fromXContent;
IndicesQueriesRegistry queryRegistry = new IndicesQueriesRegistry(Settings.EMPTY, IndicesQueriesRegistry queryRegistry = new IndicesQueriesRegistry(Settings.EMPTY,
singletonMap(MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryParser.QUERY_NAME_FIELD, new MatchAllQueryParser()))); singletonMap(MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryBuilder.QUERY_NAME_FIELD, termQueryParser)));
Map<String, TransformFactory> factories = new HashMap<>(); Map<String, TransformFactory> factories = new HashMap<>();
ChainTransformFactory parser = new ChainTransformFactory(); ChainTransformFactory parser = new ChainTransformFactory();
factories.put(ChainTransform.TYPE, parser); factories.put(ChainTransform.TYPE, parser);