Merge branch 'master' into fix/remove-requirefrom
Original commit: elastic/x-pack-elasticsearch@7bc1e240fc
This commit is contained in:
commit
4010067d35
|
@ -28,7 +28,7 @@ import java.util.Set;
|
|||
@SuppressForbidden(reason = "gradle is broken and tries to run me as a test")
|
||||
public final class MessyTestUtils {
|
||||
public static ScriptServiceProxy getScriptServiceProxy(ThreadPool tp) throws Exception {
|
||||
Settings settings = Settings.settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("script.inline", "true")
|
||||
.put("script.indexed", "true")
|
||||
.put("path.home", LuceneTestCase.createTempDir())
|
||||
|
|
|
@ -78,7 +78,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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();
|
||||
builder.startObject().endObject();
|
||||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||
|
@ -120,7 +120,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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());
|
||||
String script;
|
||||
switch (scriptType) {
|
||||
|
@ -146,7 +146,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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;
|
||||
String script = "return true";
|
||||
XContentBuilder builder = createConditionContent(script, "not_a_valid_lang", scriptType);
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
|
@ -68,7 +67,7 @@ public class TransformIT extends AbstractWatcherIntegrationTestCase {
|
|||
throw new RuntimeException(ex);
|
||||
}
|
||||
//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 {
|
||||
|
|
|
@ -56,7 +56,6 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
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.xcontent.XContentFactory.jsonBuilder;
|
||||
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
|
||||
return settingsBuilder().put(super.nodeSettings(nodeOrdinal))
|
||||
return Settings.builder().put(super.nodeSettings(nodeOrdinal))
|
||||
.put("path.conf", configPath).build();
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,6 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
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.xcontent.XContentFactory.jsonBuilder;
|
||||
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");
|
||||
}
|
||||
//Set path so ScriptService will pick up the test scripts
|
||||
return settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
// 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();
|
||||
|
@ -137,7 +136,7 @@ public class SearchTransformIT extends ESIntegTestCase {
|
|||
|
||||
@Override
|
||||
public Settings indexSettings() {
|
||||
return settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.indexSettings())
|
||||
|
||||
// we have to test this on an index that has at least 2 shards. Otherwise when searching indices with
|
||||
|
|
|
@ -71,8 +71,6 @@ compileTestJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-
|
|||
|
||||
ext.expansions = [
|
||||
'project.version': version,
|
||||
// Used in marvel index templates
|
||||
'monitoring.template.version': '1',
|
||||
// Used in watcher index templates
|
||||
'watcher.template.version': '1',
|
||||
]
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
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.terms.TermsAggregator;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class AbstractLicensesConsumerPluginIntegrationTestCase extends
|
|||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
// this setting is only used in tests
|
||||
.put("_trial_license_duration_in_seconds", trialLicenseDurationInSeconds)
|
||||
|
|
|
@ -34,7 +34,7 @@ public class LicensesPluginIntegrationTests extends AbstractLicensesIntegrationT
|
|||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
// this setting is only used in tests
|
||||
.put("_trial_license_duration_in_seconds", trialLicenseDurationInSeconds)
|
||||
|
|
|
@ -33,13 +33,13 @@ public class LicensesPluginsIntegrationTests extends AbstractLicensesIntegration
|
|||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.build();
|
||||
}
|
||||
|
||||
private Settings nodeSettingsWithConsumerPlugin(int trialLicenseDuration) {
|
||||
return Settings.settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(0))
|
||||
// this setting is only used in tests
|
||||
.put("_trial_license_duration_in_seconds", trialLicenseDuration)
|
||||
|
|
|
@ -25,7 +25,7 @@ import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
|
|||
public class LicensesServiceNodeTests extends AbstractLicensesIntegrationTestCase {
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
|
||||
.build();
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.elasticsearch.common.settings.Setting;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.SettingsModule;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
|
||||
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.boolSetting;
|
||||
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.timeSetting;
|
||||
|
||||
|
@ -121,13 +119,6 @@ public class MarvelSettings extends AbstractComponent {
|
|||
HISTORY_DURATION_MINIMUM, // minimum value
|
||||
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
|
||||
*/
|
||||
|
@ -147,7 +138,6 @@ public class MarvelSettings extends AbstractComponent {
|
|||
module.registerSetting(HISTORY_DURATION);
|
||||
module.registerSetting(EXPORTERS_SETTINGS);
|
||||
module.registerSetting(ENABLED);
|
||||
module.registerSetting(INDEX_TEMPLATE_VERSION);
|
||||
|
||||
module.registerSettingsFilter("xpack.monitoring.agent.exporters.*.auth.*");
|
||||
module.registerSettingsFilter("xpack.monitoring.agent.exporters.*.ssl.*");
|
||||
|
|
|
@ -5,103 +5,80 @@
|
|||
*/
|
||||
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.xcontent.XContentHelper;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class MarvelTemplateUtils {
|
||||
|
||||
static final String INDEX_TEMPLATE_FILE = "/monitoring-es.json";
|
||||
static final String INDEX_TEMPLATE_NAME_PREFIX = ".monitoring-es-";
|
||||
private static final String TEMPLATE_FILE = "/monitoring-%s.json";
|
||||
private static final String TEMPLATE_VERSION_PROPERTY = Pattern.quote("${monitoring.template.version}");
|
||||
|
||||
static final String DATA_TEMPLATE_FILE = "/monitoring-data.json";
|
||||
static final String DATA_TEMPLATE_NAME_PREFIX = ".monitoring-data-";
|
||||
|
||||
static final String PROPERTIES_FILE = "/monitoring.properties";
|
||||
static final String TEMPLATE_VERSION_PROPERTY = "template.version";
|
||||
|
||||
public static final Integer TEMPLATE_VERSION = loadTemplateVersion();
|
||||
/** Current version of es and data templates **/
|
||||
public static final Integer TEMPLATE_VERSION = 2;
|
||||
|
||||
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 {
|
||||
return load(INDEX_TEMPLATE_FILE);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("unable to load monitoring template", e);
|
||||
BytesReference source = load(resource);
|
||||
validate(source);
|
||||
|
||||
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() {
|
||||
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 {
|
||||
static BytesReference load(String name) throws IOException {
|
||||
try (InputStream is = MarvelTemplateUtils.class.getResourceAsStream(name)) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
Streams.copy(is, out);
|
||||
return out.toByteArray();
|
||||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
Streams.copy(is, out);
|
||||
return new BytesArray(out.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the current version of templates
|
||||
*
|
||||
* When executing tests in Intellij, the properties file might not be
|
||||
* resolved: try running 'gradle processResources' first.
|
||||
* Parses and validates that the source is not empty.
|
||||
*/
|
||||
static Integer loadTemplateVersion() {
|
||||
try (InputStream is = MarvelTemplateUtils.class.getResourceAsStream(PROPERTIES_FILE)) {
|
||||
Properties properties = new Properties();
|
||||
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) {
|
||||
throw new IllegalArgumentException("failed to parse monitoring template version");
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("failed to load monitoring template version");
|
||||
static void validate(BytesReference source) {
|
||||
if (source == null) {
|
||||
throw new ElasticsearchParseException("Monitoring template must not be null");
|
||||
}
|
||||
|
||||
try {
|
||||
XContentHelper.convertToMap(source, false).v2();
|
||||
} catch (NotXContentException e) {
|
||||
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);
|
||||
}
|
||||
|
||||
public static String indexTemplateName(Integer version) {
|
||||
return templateName(INDEX_TEMPLATE_NAME_PREFIX, 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);
|
||||
/**
|
||||
* Filters the source: replaces any template version property with the version number
|
||||
*/
|
||||
static String filter(BytesReference source, Integer version) {
|
||||
return Pattern.compile(TEMPLATE_VERSION_PROPERTY)
|
||||
.matcher(source.toUtf8())
|
||||
.replaceAll(String.valueOf(version));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.env.Environment;
|
|||
import org.elasticsearch.marvel.agent.exporter.ExportBulk;
|
||||
import org.elasticsearch.marvel.agent.exporter.ExportException;
|
||||
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.resolver.MonitoringIndexNameResolver;
|
||||
import org.elasticsearch.marvel.agent.resolver.ResolversRegistry;
|
||||
|
@ -47,6 +46,7 @@ import java.net.HttpURLConnection;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.AccessController;
|
||||
|
@ -55,6 +55,8 @@ import java.security.PrivilegedAction;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
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 supportedClusterVersion = false;
|
||||
|
||||
/**
|
||||
* Version number of built-in templates
|
||||
**/
|
||||
private final Integer templateVersion;
|
||||
|
||||
boolean keepAlive;
|
||||
final ConnectionKeepAliveWorker keepAliveWorker;
|
||||
Thread keepAliveThread;
|
||||
|
@ -145,14 +142,16 @@ public class HttpExporter extends Exporter {
|
|||
sslSocketFactory = createSSLSocketFactory(config.settings().getAsSettings(SSL_SETTING));
|
||||
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());
|
||||
logger.debug("initialized with hosts [{}], index prefix [{}], template version [{}]",
|
||||
Strings.arrayToCommaDelimitedString(hosts), MonitoringIndexNameResolver.PREFIX, templateVersion);
|
||||
// Checks that required templates are loaded
|
||||
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() {
|
||||
|
@ -424,24 +423,18 @@ public class HttpExporter extends Exporter {
|
|||
* @return true if template exists or was uploaded successfully.
|
||||
*/
|
||||
private boolean checkAndUploadIndexTemplate(final String host) {
|
||||
String templateName = MarvelTemplateUtils.indexTemplateName(templateVersion);
|
||||
boolean templateInstalled = hasTemplate(templateName, host);
|
||||
// List of distinct templates
|
||||
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:
|
||||
// Install the index template for timestamped indices first, so that other nodes can ship data
|
||||
if (!templateInstalled) {
|
||||
logger.debug("could not find existing monitoring template, installing a new one");
|
||||
if (!putTemplate(host, templateName, MarvelTemplateUtils.loadTimestampedIndexTemplate())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
for (Map.Entry<String, String> template : templates.entrySet()) {
|
||||
if (hasTemplate(template.getKey(), host) == false) {
|
||||
logger.debug("template [{}] not found", template.getKey());
|
||||
if (!putTemplate(host, template.getKey(), template.getValue())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
logger.debug("template [{}] found", template.getKey());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -481,7 +474,7 @@ public class HttpExporter extends Exporter {
|
|||
return false;
|
||||
}
|
||||
|
||||
boolean putTemplate(String host, String template, byte[] source) {
|
||||
boolean putTemplate(String host, String template, String source) {
|
||||
logger.debug("installing template [{}]", template);
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
|
@ -492,13 +485,13 @@ public class HttpExporter extends Exporter {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
logConnectionError("error adding the monitoring template [" + template + "] to [" + host + "]", connection);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.info("monitoring template [{}] updated to version [{}]", template, templateVersion);
|
||||
logger.info("monitoring template [{}] updated ", template);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
logger.error("failed to update monitoring template [{}] on host [{}]:\n{}", template, host, e.getMessage());
|
||||
|
|
|
@ -21,11 +21,11 @@ import org.elasticsearch.cluster.service.ClusterService;
|
|||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.gateway.GatewayService;
|
||||
import org.elasticsearch.marvel.agent.exporter.ExportBulk;
|
||||
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.resolver.MonitoringIndexNameResolver;
|
||||
import org.elasticsearch.marvel.agent.resolver.ResolversRegistry;
|
||||
|
@ -35,6 +35,7 @@ import org.joda.time.DateTime;
|
|||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
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);
|
||||
|
||||
/** Version number of built-in templates **/
|
||||
private final Integer templateVersion;
|
||||
|
||||
public LocalExporter(Exporter.Config config, MonitoringClientProxy client,
|
||||
ClusterService clusterService, CleanerService cleanerService) {
|
||||
super(TYPE, config);
|
||||
this.client = client;
|
||||
this.clusterService = clusterService;
|
||||
this.cleanerService = cleanerService;
|
||||
this.resolvers = new ResolversRegistry(config.settings());
|
||||
|
||||
// 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");
|
||||
// Checks that required templates are loaded
|
||||
for (MonitoringIndexNameResolver resolver : resolvers) {
|
||||
if (resolver.template() == null) {
|
||||
throw new IllegalStateException("unable to find built-in template " + resolver.templateName());
|
||||
}
|
||||
}
|
||||
|
||||
resolvers = new ResolversRegistry(config.settings());
|
||||
clusterService.add(this);
|
||||
cleanerService.add(this);
|
||||
}
|
||||
|
@ -117,21 +116,23 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
|||
return null;
|
||||
}
|
||||
|
||||
String templateName = MarvelTemplateUtils.indexTemplateName(templateVersion);
|
||||
boolean templateInstalled = hasTemplate(templateName, clusterState);
|
||||
// List of distinct templates
|
||||
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)
|
||||
// we'll be able to start this exporter. Otherwise, we'll just wait for a new cluster state.
|
||||
|
||||
// if this is not the master, we'll just look to see if the monitoring templates are installed.
|
||||
// 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) {
|
||||
// We only need to check the index template for timestamped indices
|
||||
if (templateInstalled == false) {
|
||||
// the template for timestamped indices is not yet installed in the given cluster state, we'll wait.
|
||||
logger.debug("monitoring index template does not exist, so service cannot start");
|
||||
return null;
|
||||
for (String template : templates.keySet()) {
|
||||
if (hasTemplate(template, clusterState) == false) {
|
||||
// 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", template);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("monitoring index template found, service can start");
|
||||
logger.debug("monitoring index templates are installed, service can start");
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -143,24 +144,18 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
|||
return null;
|
||||
}
|
||||
|
||||
// Install the index template for timestamped indices first, so that other nodes can ship data
|
||||
if (templateInstalled == false) {
|
||||
logger.debug("could not find existing monitoring template for timestamped indices, installing a new one");
|
||||
putTemplate(templateName, MarvelTemplateUtils.loadTimestampedIndexTemplate());
|
||||
// we'll get that template on the next cluster state update
|
||||
return null;
|
||||
// Check that each required template exist, installing it if needed
|
||||
for (Map.Entry<String, String> template : templates.entrySet()) {
|
||||
if (hasTemplate(template.getKey(), clusterState) == false) {
|
||||
logger.debug("template [{}] not found", template.getKey());
|
||||
putTemplate(template.getKey(), template.getValue());
|
||||
return null;
|
||||
} else {
|
||||
logger.debug("template [{}] found", template.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
// Install the index template for data index
|
||||
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");
|
||||
logger.debug("monitoring index templates are installed on master node, service can start");
|
||||
}
|
||||
|
||||
if (state.compareAndSet(State.INITIALIZED, State.RUNNING)) {
|
||||
|
@ -197,7 +192,7 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle
|
|||
return templates.size() > 0;
|
||||
}
|
||||
|
||||
void putTemplate(String template, byte[] source) {
|
||||
void putTemplate(String template, String source) {
|
||||
logger.debug("installing template [{}]",template);
|
||||
|
||||
PutIndexTemplateRequest request = new PutIndexTemplateRequest(template).source(source);
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.marvel.MonitoredSystem;
|
||||
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
|
||||
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
@ -23,6 +24,7 @@ import org.joda.time.format.DateTimeFormat;
|
|||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
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() {
|
||||
return version;
|
||||
}
|
||||
|
@ -145,6 +157,16 @@ public abstract class MonitoringIndexNameResolver<T extends MonitoringDoc> {
|
|||
public String indexPattern() {
|
||||
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;
|
||||
}
|
||||
|
||||
@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() {
|
||||
return system.getSystem();
|
||||
}
|
||||
|
|
|
@ -43,14 +43,17 @@ import static org.elasticsearch.marvel.MonitoredSystem.ES;
|
|||
|
||||
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<>();
|
||||
|
||||
public ResolversRegistry(Settings settings) {
|
||||
// register built-in defaults resolvers
|
||||
registerBuiltIn(ES, MarvelTemplateUtils.TEMPLATE_VERSION, settings);
|
||||
registerBuiltIn(ES, ES_TEMPLATE_VERSION, settings);
|
||||
|
||||
// register resolvers for external applications
|
||||
registerKibana(settings);
|
||||
// register resolvers for monitored systems
|
||||
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) {
|
||||
final MonitoringBulkResolver kibana = new MonitoringBulkResolver(MonitoredSystem.KIBANA, 0, settings);
|
||||
registrations.add(resolveByClassSystemVersion(MonitoringBulkDoc.class, MonitoredSystem.KIBANA, Version.CURRENT, kibana));
|
||||
private void registerMonitoredSystem(MonitoredSystem id, int version, Settings settings) {
|
||||
final MonitoringBulkResolver resolver = new MonitoringBulkResolver(id, version, settings);
|
||||
registrations.add(resolveByClassSystemVersion(MonitoringBulkDoc.class, id, Version.CURRENT, resolver));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
template.version=${monitoring.template.version}
|
|
@ -39,7 +39,7 @@ public class ClusterStateCollectorTests extends AbstractCollectorTestCase {
|
|||
|
||||
public void testClusterStateCollectorOneIndex() throws Exception {
|
||||
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_REPLICAS, 0)
|
||||
.build()));
|
||||
|
@ -65,7 +65,7 @@ public class ClusterStateCollectorTests extends AbstractCollectorTestCase {
|
|||
for (int i = 0; i < nbIndices; i++) {
|
||||
shardsPerIndex[i] = randomIntBetween(1, 5);
|
||||
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_REPLICAS, 0)
|
||||
.build()));
|
||||
|
|
|
@ -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_SHARDS;
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
|
@ -46,7 +45,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
|
|||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put(MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY.getKey(), activeOnly)
|
||||
.put(MarvelSettings.INDICES.getKey(), indexName)
|
||||
|
@ -66,7 +65,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
|
|||
assertThat(results, is(empty()));
|
||||
|
||||
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");
|
||||
final int numDocs = between(50, 150);
|
||||
|
@ -169,7 +168,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
|
|||
}
|
||||
|
||||
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));
|
||||
waitForNoBlocksOnNode(node);
|
||||
|
||||
|
@ -181,7 +180,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
try {
|
||||
|
@ -192,7 +191,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
try {
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.Collection;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
|
@ -52,7 +52,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
try {
|
||||
|
@ -63,7 +63,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
try {
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.hamcrest.Matchers.arrayWithSize;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -52,7 +52,7 @@ public class IndicesStatsCollectorTests extends AbstractCollectorTestCase {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
try {
|
||||
|
@ -63,7 +63,7 @@ public class IndicesStatsCollectorTests extends AbstractCollectorTestCase {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
try {
|
||||
|
|
|
@ -19,8 +19,6 @@ import java.io.IOException;
|
|||
import java.util.Map;
|
||||
|
||||
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.hamcrest.Matchers.notNullValue;
|
||||
|
||||
|
@ -58,8 +56,9 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
|
|||
doExporting();
|
||||
|
||||
logger.debug("--> templates does not exist: it should have been created in the current version");
|
||||
assertTemplateExist(indexTemplateName());
|
||||
assertTemplateExist(dataTemplateName());
|
||||
for (String template : monitoringTemplates().keySet()) {
|
||||
assertTemplateExist(template);
|
||||
}
|
||||
|
||||
doExporting();
|
||||
|
||||
|
@ -82,8 +81,9 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
|
|||
assertTemplateExist(indexTemplateName(version));
|
||||
|
||||
logger.debug("--> existing templates are old: new templates should be created");
|
||||
assertTemplateExist(indexTemplateName());
|
||||
assertTemplateExist(dataTemplateName());
|
||||
for (String template : monitoringTemplates().keySet()) {
|
||||
assertTemplateExist(template);
|
||||
}
|
||||
|
||||
doExporting();
|
||||
|
||||
|
@ -101,12 +101,13 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
|
|||
doExporting();
|
||||
|
||||
logger.debug("--> existing templates are up to date");
|
||||
assertTemplateExist(indexTemplateName());
|
||||
assertTemplateExist(dataTemplateName());
|
||||
for (String template : monitoringTemplates().keySet()) {
|
||||
assertTemplateExist(template);
|
||||
}
|
||||
|
||||
logger.debug("--> existing templates has the same version: they should not be changed");
|
||||
assertTemplateNotUpdated(indexTemplateName());
|
||||
assertTemplateNotUpdated(dataTemplateName());
|
||||
assertTemplateNotUpdated(indexTemplateName(currentVersion));
|
||||
assertTemplateNotUpdated(dataTemplateName(currentVersion));
|
||||
|
||||
doExporting();
|
||||
|
||||
|
@ -135,8 +136,9 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
|
|||
doExporting();
|
||||
|
||||
logger.debug("--> templates should exist in current version");
|
||||
assertTemplateExist(indexTemplateName());
|
||||
assertTemplateExist(dataTemplateName());
|
||||
for (String template : monitoringTemplates().keySet()) {
|
||||
assertTemplateExist(template);
|
||||
}
|
||||
|
||||
if (previousIndexTemplateExist) {
|
||||
logger.debug("--> index template should exist in version [{}]", previousIndexTemplateVersion);
|
||||
|
@ -167,6 +169,16 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
|
|||
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() {
|
||||
MockDataIndexNameResolver resolver = new MockDataIndexNameResolver(currentVersion);
|
||||
return resolver.index(null);
|
||||
|
@ -188,7 +200,6 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
|
|||
.startObject("settings")
|
||||
.field("index.number_of_shards", 1)
|
||||
.field("index.number_of_replicas", 1)
|
||||
.field(MarvelSettings.INDEX_TEMPLATE_VERSION.getKey(), String.valueOf(version))
|
||||
.endObject()
|
||||
.startObject("mappings")
|
||||
.startObject("_default_")
|
||||
|
|
|
@ -5,52 +5,100 @@
|
|||
*/
|
||||
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.hamcrest.Matcher;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
public class MarvelTemplateUtilsTests extends ESTestCase {
|
||||
|
||||
public void testLoadTimestampedIndexTemplate() {
|
||||
byte[] template = MarvelTemplateUtils.loadTimestampedIndexTemplate();
|
||||
assertNotNull(template);
|
||||
assertThat(template.length, greaterThan(0));
|
||||
}
|
||||
private static final String TEST_TEMPLATE = "/monitoring-test.json";
|
||||
|
||||
public void testLoadDataIndexTemplate() {
|
||||
byte[] template = MarvelTemplateUtils.loadDataIndexTemplate();
|
||||
assertNotNull(template);
|
||||
assertThat(template.length, greaterThan(0));
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
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 {
|
||||
String resource = randomFrom(MarvelTemplateUtils.INDEX_TEMPLATE_FILE, MarvelTemplateUtils.DATA_TEMPLATE_FILE);
|
||||
byte[] template = MarvelTemplateUtils.load(resource);
|
||||
assertNotNull(template);
|
||||
assertThat(template.length, greaterThan(0));
|
||||
BytesReference source = MarvelTemplateUtils.load(TEST_TEMPLATE);
|
||||
assertThat(source, notNullValue());
|
||||
assertThat(source.length(), greaterThan(0));
|
||||
}
|
||||
|
||||
public void testLoadTemplateVersion() {
|
||||
Integer version = MarvelTemplateUtils.loadTemplateVersion();
|
||||
assertNotNull(version);
|
||||
assertThat(version, greaterThan(0));
|
||||
assertThat(version, equalTo(MarvelTemplateUtils.TEMPLATE_VERSION));
|
||||
public void testValidateNullSource() {
|
||||
expectedException.expect(ElasticsearchParseException.class);
|
||||
expectedException.expectMessage("Monitoring template must not be null");
|
||||
MarvelTemplateUtils.validate(null);
|
||||
}
|
||||
|
||||
public void testIndexTemplateName() {
|
||||
assertThat(MarvelTemplateUtils.indexTemplateName(),
|
||||
equalTo(MarvelTemplateUtils.INDEX_TEMPLATE_NAME_PREFIX + MarvelTemplateUtils.TEMPLATE_VERSION));
|
||||
int version = randomIntBetween(1, 100);
|
||||
assertThat(MarvelTemplateUtils.indexTemplateName(version), equalTo(".monitoring-es-" + version));
|
||||
public void testValidateEmptySource() {
|
||||
expectedException.expect(ElasticsearchParseException.class);
|
||||
expectedException.expectMessage("Monitoring template must not be empty");
|
||||
MarvelTemplateUtils.validate(new BytesArray(""));
|
||||
}
|
||||
|
||||
public void testDataTemplateName() {
|
||||
assertThat(MarvelTemplateUtils.dataTemplateName(),
|
||||
equalTo(MarvelTemplateUtils.DATA_TEMPLATE_NAME_PREFIX + MarvelTemplateUtils.TEMPLATE_VERSION));
|
||||
int version = randomIntBetween(1, 100);
|
||||
assertThat(MarvelTemplateUtils.dataTemplateName(version), equalTo(".monitoring-data-" + version));
|
||||
public void testValidateInvalidSource() {
|
||||
expectedException.expect(ElasticsearchParseException.class);
|
||||
expectedException.expectMessage("Invalid monitoring template");
|
||||
MarvelTemplateUtils.validate(new BytesArray("{\"foo\": \"bar"));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.MarvelTemplateUtils;
|
||||
import org.elasticsearch.marvel.agent.exporter.MonitoringDoc;
|
||||
import org.elasticsearch.marvel.agent.resolver.bulk.MonitoringBulkResolver;
|
||||
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
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.emptySet;
|
||||
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.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
@ -64,9 +63,6 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
private int webPort;
|
||||
private MockWebServer webServer;
|
||||
|
||||
private static final byte[] TIMESTAMPED_TEMPLATE = MarvelTemplateUtils.loadTimestampedIndexTemplate();
|
||||
private static final byte[] DATA_TEMPLATE = MarvelTemplateUtils.loadDataIndexTemplate();
|
||||
|
||||
@Before
|
||||
public void startWebservice() throws Exception {
|
||||
for (webPort = 9250; webPort < 9300; webPort++) {
|
||||
|
@ -91,10 +87,10 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
|
||||
public void testExport() throws Exception {
|
||||
enqueueGetClusterVersionResponse(Version.CURRENT);
|
||||
enqueueResponse(404, "template for timestamped indices does not exist");
|
||||
enqueueResponse(201, "template for timestamped indices created");
|
||||
enqueueResponse(404, "template for data index does not exist");
|
||||
enqueueResponse(201, "template for data index created");
|
||||
for (String template : monitoringTemplates().keySet()) {
|
||||
enqueueResponse(404, "template [" + template + "] does not exist");
|
||||
enqueueResponse(201, "template [" + template + "] created");
|
||||
}
|
||||
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
|
||||
|
||||
Settings.Builder builder = Settings.builder()
|
||||
|
@ -109,29 +105,22 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
final int nbDocs = randomIntBetween(1, 25);
|
||||
export(newRandomMarvelDocs(nbDocs));
|
||||
|
||||
assertThat(webServer.getRequestCount(), equalTo(6));
|
||||
assertThat(webServer.getRequestCount(), equalTo(2 + monitoringTemplates().size() * 2));
|
||||
|
||||
RecordedRequest recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/"));
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName()));
|
||||
for (Map.Entry<String, String> template : monitoringTemplates().entrySet()) {
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName()));
|
||||
assertThat(recordedRequest.getBody().readByteArray(), equalTo(TIMESTAMPED_TEMPLATE));
|
||||
|
||||
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();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
|
||||
assertThat(recordedRequest.getBody().readUtf8(), equalTo(template.getValue()));
|
||||
}
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("POST"));
|
||||
|
@ -176,10 +165,10 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
logger.info("--> starting node");
|
||||
|
||||
enqueueGetClusterVersionResponse(Version.CURRENT);
|
||||
enqueueResponse(404, "template for timestamped indices does not exist");
|
||||
enqueueResponse(201, "template for timestamped indices created");
|
||||
enqueueResponse(404, "template for data index does not exist");
|
||||
enqueueResponse(201, "template for data index created");
|
||||
for (String template : monitoringTemplates().keySet()) {
|
||||
enqueueResponse(404, "template [" + template + "] does not exist");
|
||||
enqueueResponse(201, "template [" + template + "] created");
|
||||
}
|
||||
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
|
||||
|
||||
String agentNode = internalCluster().startNode(builder);
|
||||
|
@ -190,29 +179,22 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
export(Collections.singletonList(newRandomMarvelDoc()));
|
||||
|
||||
assertThat(exporter.supportedClusterVersion, is(true));
|
||||
assertThat(webServer.getRequestCount(), equalTo(6));
|
||||
assertThat(webServer.getRequestCount(), equalTo(2 + monitoringTemplates().size() * 2));
|
||||
|
||||
RecordedRequest recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/"));
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName()));
|
||||
for (Map.Entry<String, String> template : monitoringTemplates().entrySet()) {
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName()));
|
||||
assertThat(recordedRequest.getBody().readByteArray(), equalTo(TIMESTAMPED_TEMPLATE));
|
||||
|
||||
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();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
|
||||
assertThat(recordedRequest.getBody().readUtf8(), equalTo(template.getValue()));
|
||||
}
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("POST"));
|
||||
|
@ -246,32 +228,37 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
exporter = getExporter(agentNode);
|
||||
|
||||
enqueueGetClusterVersionResponse(secondWebServer, Version.CURRENT);
|
||||
enqueueResponse(secondWebServer, 404, "template for timestamped indices does not exist");
|
||||
enqueueResponse(secondWebServer, 201, "template for timestamped indices created");
|
||||
enqueueResponse(secondWebServer, 200, "template for data index exist");
|
||||
for (String template : monitoringTemplates().keySet()) {
|
||||
if (template.contains(MonitoringBulkResolver.Data.DATA)) {
|
||||
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\"}");
|
||||
|
||||
logger.info("--> exporting a second event");
|
||||
export(Collections.singletonList(newRandomMarvelDoc()));
|
||||
|
||||
assertThat(secondWebServer.getRequestCount(), equalTo(5));
|
||||
assertThat(secondWebServer.getRequestCount(), equalTo(2 + monitoringTemplates().size() * 2 - 1));
|
||||
|
||||
recordedRequest = secondWebServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/"));
|
||||
|
||||
recordedRequest = secondWebServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName()));
|
||||
for (Map.Entry<String, String> template : monitoringTemplates().entrySet()) {
|
||||
recordedRequest = secondWebServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
|
||||
|
||||
recordedRequest = secondWebServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName()));
|
||||
assertThat(recordedRequest.getBody().readByteArray(), equalTo(TIMESTAMPED_TEMPLATE));
|
||||
|
||||
recordedRequest = secondWebServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + dataTemplateName()));;
|
||||
if (template.getKey().contains(MonitoringBulkResolver.Data.DATA) == false) {
|
||||
recordedRequest = secondWebServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
|
||||
assertThat(recordedRequest.getBody().readUtf8(), equalTo(template.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
recordedRequest = secondWebServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("POST"));
|
||||
|
@ -325,10 +312,10 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
logger.info("--> exporting a first event");
|
||||
|
||||
enqueueGetClusterVersionResponse(Version.CURRENT);
|
||||
enqueueResponse(404, "template for timestamped indices does not exist");
|
||||
enqueueResponse(201, "template for timestamped indices created");
|
||||
enqueueResponse(404, "template for data index does not exist");
|
||||
enqueueResponse(201, "template for data index created");
|
||||
for (String template : monitoringTemplates().keySet()) {
|
||||
enqueueResponse(404, "template [" + template + "] does not exist");
|
||||
enqueueResponse(201, "template [" + template + "] created");
|
||||
}
|
||||
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
|
||||
|
||||
HttpExporter exporter = getExporter(agentNode);
|
||||
|
@ -336,29 +323,23 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
MonitoringDoc doc = newRandomMarvelDoc();
|
||||
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();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/"));
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName()));
|
||||
for (Map.Entry<String, String> template : monitoringTemplates().entrySet()) {
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName()));
|
||||
assertThat(recordedRequest.getBody().readByteArray(), equalTo(TIMESTAMPED_TEMPLATE));
|
||||
|
||||
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();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("PUT"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + template.getKey()));
|
||||
assertThat(recordedRequest.getBody().readUtf8(), equalTo(template.getValue()));
|
||||
}
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("POST"));
|
||||
|
@ -381,8 +362,9 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
logger.info("--> exporting a second event");
|
||||
|
||||
enqueueGetClusterVersionResponse(Version.CURRENT);
|
||||
enqueueResponse(200, "template for timestamped indices exist");
|
||||
enqueueResponse(200, "template for data index exist");
|
||||
for (String template : monitoringTemplates().keySet()) {
|
||||
enqueueResponse(200, "template [" + template + "] exist");
|
||||
}
|
||||
enqueueResponse(200, "{\"errors\": false, \"msg\": \"successful bulk request\"}");
|
||||
|
||||
doc = newRandomMarvelDoc();
|
||||
|
@ -391,19 +373,17 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
String expectedMarvelIndex = ".monitoring-es-" + MarvelTemplateUtils.TEMPLATE_VERSION + "-"
|
||||
+ DateTimeFormat.forPattern(newTimeFormat).withZoneUTC().print(doc.getTimestamp());
|
||||
|
||||
assertThat(webServer.getRequestCount(), equalTo(6 + 4));
|
||||
assertThat(webServer.getRequestCount(), equalTo(expectedRequests + 2 + monitoringTemplates().size()));
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/"));
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + indexTemplateName()));
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + dataTemplateName()));
|
||||
for (String template : monitoringTemplates().keySet()) {
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("GET"));
|
||||
assertThat(recordedRequest.getPath(), equalTo("/_template/" + template));
|
||||
}
|
||||
|
||||
recordedRequest = webServer.takeRequest();
|
||||
assertThat(recordedRequest.getMethod(), equalTo("POST"));
|
||||
|
|
|
@ -36,12 +36,9 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
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.hamcrest.Matchers.containsString;
|
||||
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)
|
||||
public class LocalExporterTests extends MarvelIntegTestCase {
|
||||
private final static AtomicLong timeStampGenerator = new AtomicLong();
|
||||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
|
@ -108,8 +104,7 @@ public class LocalExporterTests extends MarvelIntegTestCase {
|
|||
updateMarvelInterval(3L, TimeUnit.SECONDS);
|
||||
|
||||
// lets wait until the monitoring template will be installed
|
||||
waitForMarvelTemplate(indexTemplateName());
|
||||
waitForMarvelTemplate(dataTemplateName());
|
||||
waitForMarvelTemplates();
|
||||
}
|
||||
|
||||
public void testIndexTimestampFormat() throws Exception {
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.util.Arrays;
|
|||
|
||||
import static java.util.Collections.emptyMap;
|
||||
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.PREFIX;
|
||||
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")) {
|
||||
Settings settings = Settings.EMPTY;
|
||||
if (format != null) {
|
||||
settings = settingsBuilder()
|
||||
settings = Settings.builder()
|
||||
.put(MonitoringIndexNameResolver.Timestamped.INDEX_NAME_TIME_FORMAT_SETTING.getKey(), format)
|
||||
.build();
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class MonitoringBulkResolverTests extends MonitoringIndexNameResolverTest
|
|||
}
|
||||
|
||||
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.id(doc), nullValue());
|
||||
|
||||
|
|
|
@ -23,8 +23,6 @@ import org.junit.Before;
|
|||
import java.util.Map;
|
||||
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.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -119,8 +117,7 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
|
|||
assertThat(clusterStats, instanceOf(Map.class));
|
||||
assertThat(((Map) clusterStats).size(), greaterThan(0));
|
||||
|
||||
waitForMarvelTemplate(indexTemplateName());
|
||||
waitForMarvelTemplate(dataTemplateName());
|
||||
waitForMarvelTemplates();
|
||||
|
||||
logger.debug("--> check that the cluster_info is not indexed");
|
||||
securedFlush();
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.junit.After;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
|
@ -64,7 +63,7 @@ public class MultiNodesStatsTests extends MarvelIntegTestCase {
|
|||
n = randomIntBetween(1, 2);
|
||||
logger.debug("--> starting {} client only nodes", 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());
|
||||
clientNodes.get();
|
||||
nodes += n;
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.joda.time.DateTime;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
|
@ -41,7 +40,7 @@ public class LocalIndicesCleanerTests extends AbstractIndicesCleanerTestCase {
|
|||
@Override
|
||||
protected void createIndex(String name, DateTime creationDate) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,11 +11,12 @@ import org.elasticsearch.common.network.NetworkModule;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.marvel.MarvelSettings;
|
||||
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
|
||||
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.shield.InternalClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
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().prepareCreate(MONITORING_INDICES_PREFIX + "test"));
|
||||
|
||||
assertAccessIsAllowed(internalClient.admin().indices().preparePutTemplate("foo")
|
||||
.setSource(MarvelTemplateUtils.loadTimestampedIndexTemplate()));
|
||||
assertAccessIsAllowed(internalClient.admin().indices().preparePutTemplate("foo").setSource(randomTemplateSource()));
|
||||
assertAccessIsAllowed(internalClient.admin().indices().prepareGetTemplates("foo"));
|
||||
}
|
||||
|
||||
public void testAllowAllAccess() {
|
||||
InternalClient internalClient = internalCluster().getInstance(InternalClient.class);
|
||||
assertAcked(internalClient.admin().indices().preparePutTemplate("foo")
|
||||
.setSource(MarvelTemplateUtils.loadDataIndexTemplate()).get());
|
||||
assertAcked(internalClient.admin().indices().preparePutTemplate("foo").setSource(randomTemplateSource()).get());
|
||||
|
||||
assertAccessIsAllowed(internalClient.admin().indices().prepareDeleteTemplate("foo"));
|
||||
assertAccessIsAllowed(internalClient.admin().cluster().prepareGetRepositories());
|
||||
|
@ -83,5 +82,12 @@ public class MarvelInternalClientTests extends MarvelIntegTestCase {
|
|||
assertThat(e.status(), is(RestStatus.FORBIDDEN));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the source of a random monitoring template
|
||||
*/
|
||||
private String randomTemplateSource() {
|
||||
return randomFrom(new ArrayList<>(monitoringTemplates().values()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ import org.elasticsearch.index.IndexNotFoundException;
|
|||
import org.elasticsearch.marvel.MarvelSettings;
|
||||
import org.elasticsearch.marvel.MonitoredSystem;
|
||||
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.resolver.MonitoringIndexNameResolver;
|
||||
import org.elasticsearch.marvel.agent.resolver.ResolversRegistry;
|
||||
import org.elasticsearch.marvel.client.MonitoringClient;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.shield.authc.file.FileRealm;
|
||||
|
@ -57,6 +57,8 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
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.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
|
@ -164,10 +166,7 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase {
|
|||
|
||||
@Override
|
||||
protected Set<String> excludeTemplates() {
|
||||
Set<String> templates = new HashSet<>();
|
||||
templates.add(MarvelTemplateUtils.indexTemplateName());
|
||||
templates.add(MarvelTemplateUtils.dataTemplateName());
|
||||
return templates;
|
||||
return monitoringTemplates().keySet();
|
||||
}
|
||||
|
||||
@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) {
|
||||
boolean found = false;
|
||||
for (IndexTemplateMetaData template : client().admin().indices().prepareGetTemplates().get().getIndexTemplates()) {
|
||||
|
@ -294,6 +298,10 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase {
|
|||
}, 30, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
protected void waitForMarvelTemplates() throws Exception {
|
||||
assertBusy(() -> monitoringTemplates().keySet().forEach(this::assertTemplateInstalled), 30, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
protected void waitForMarvelIndices() throws Exception {
|
||||
awaitIndexExists(MONITORING_INDICES_PREFIX + "*");
|
||||
assertBusy(this::ensureMarvelIndicesYellow);
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"template": ".monitoring-data-${monitoring.template.version}",
|
||||
"mappings": {
|
||||
"type_1": {
|
||||
"_meta": {
|
||||
"template.version": "${monitoring.template.version}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -178,7 +178,7 @@ public class Security {
|
|||
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_SERVICE_TYPE_KEY, Security.NAME);
|
||||
settingsBuilder.put(NetworkModule.HTTP_TYPE_SETTING.getKey(), Security.NAME);
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
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.SUB_TREE;
|
||||
|
@ -75,7 +74,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
|
|||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
Path nodeFiles = createTempDir();
|
||||
return settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put(realmConfig.buildSettings())
|
||||
//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");
|
||||
}
|
||||
|
||||
return settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", store)
|
||||
.put("xpack.security.ssl.keystore.password", password)
|
||||
.put(ShieldNettyTransport.HOSTNAME_VERIFICATION_SETTING.getKey(), false)
|
||||
|
@ -174,7 +173,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
|
|||
enum RealmConfig {
|
||||
|
||||
AD(false, AD_ROLE_MAPPING,
|
||||
settingsBuilder()
|
||||
Settings.builder()
|
||||
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".type", ActiveDirectoryRealm.TYPE)
|
||||
.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")
|
||||
|
@ -183,7 +182,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
|
|||
.build()),
|
||||
|
||||
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 + ".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")
|
||||
|
@ -193,7 +192,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
|
|||
.build()),
|
||||
|
||||
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 + ".url", "ldaps://ad.test.elasticsearch.com:636")
|
||||
.putArray(SHIELD_AUTHC_REALMS_EXTERNAL + ".user_dn_templates",
|
||||
|
@ -201,7 +200,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
|
|||
.build()),
|
||||
|
||||
OLDAP(false, OLDAP_ROLE_MAPPING,
|
||||
settingsBuilder()
|
||||
Settings.builder()
|
||||
.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 + ".group_search.base_dn",
|
||||
|
@ -224,7 +223,7 @@ abstract public class AbstractAdLdapRealmTestCase extends ShieldIntegTestCase {
|
|||
}
|
||||
|
||||
public Settings buildSettings() {
|
||||
return settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".order", 1)
|
||||
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".hostname_verification", false)
|
||||
.put(SHIELD_AUTHC_REALMS_EXTERNAL + ".unmapped_groups_as_roles", mapGroupsAsRoles)
|
||||
|
|
|
@ -64,7 +64,7 @@ public class ShieldPluginEnabledDisabledTests extends ShieldIntegTestCase {
|
|||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
logger.info("******* shield is {}", enabled ? "enabled" : "disabled");
|
||||
return Settings.settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put(XPackPlugin.featureEnabledSetting(Security.NAME), enabled)
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
|
||||
|
@ -73,7 +73,7 @@ public class ShieldPluginEnabledDisabledTests extends ShieldIntegTestCase {
|
|||
|
||||
@Override
|
||||
protected Settings transportClientSettings() {
|
||||
return Settings.settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.transportClientSettings())
|
||||
.put(XPackPlugin.featureEnabledSetting(Security.NAME), enabled)
|
||||
.build();
|
||||
|
|
|
@ -43,7 +43,6 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.test.ShieldTestsUtils.assertAuthenticationException;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
@ -65,23 +64,23 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
@Before
|
||||
public void initializeSslSocketFactory() throws Exception {
|
||||
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.
|
||||
* 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.
|
||||
*/
|
||||
clientSSLService = new ClientSSLService(settingsBuilder()
|
||||
clientSSLService = new ClientSSLService(Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", keystore)
|
||||
.put("xpack.security.ssl.keystore.password", "changeit")
|
||||
.build());
|
||||
clientSSLService.setEnvironment(env);
|
||||
|
||||
globalSettings = settingsBuilder().put("path.home", createTempDir()).build();
|
||||
globalSettings = Settings.builder().put("path.home", createTempDir()).build();
|
||||
}
|
||||
|
||||
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("user_search.base_dn", "")
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
|
@ -101,7 +100,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
String groupSearchBase = "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("user_search.base_dn", userSearchBase)
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
|
@ -135,7 +134,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
String groupSearchBase = "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("user_search.base_dn", userSearchBase)
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
|
@ -174,7 +173,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
String groupSearchBase = "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("user_search.base_dn", userSearchBase)
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
|
@ -209,7 +208,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
String groupSearchBase = "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("user_search.base_dn", userSearchBase)
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
|
@ -248,7 +247,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
String groupSearchBase = "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("user_search.base_dn", userSearchBase)
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
|
@ -283,7 +282,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
String groupSearchBase = "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("user_search.base_dn", userSearchBase)
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
|
@ -321,7 +320,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
String groupSearchBase = "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("user_search.base_dn", userSearchBase)
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
|
@ -354,7 +353,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
public void testUserSearchWithActiveDirectory() throws Exception {
|
||||
String groupSearchBase = "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,
|
||||
groupSearchBase, LdapSearchScope.SUB_TREE))
|
||||
.put("user_search.base_dn", userSearchBase)
|
||||
|
@ -397,7 +396,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
public void testUserSearchwithBindUserOpenLDAP() throws Exception {
|
||||
String groupSearchBase = "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,
|
||||
LdapSearchScope.ONE_LEVEL))
|
||||
.put("user_search.base_dn", userSearchBase)
|
||||
|
@ -431,7 +430,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
public void testConnectionPoolDefaultSettings() throws Exception {
|
||||
String groupSearchBase = "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("user_search.base_dn", userSearchBase)
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
|
@ -457,7 +456,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
public void testConnectionPoolSettings() throws Exception {
|
||||
String groupSearchBase = "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("user_search.base_dn", userSearchBase)
|
||||
.put("bind_dn", "cn=Horatio Hornblower,ou=people,o=sevenSeas")
|
||||
|
@ -482,7 +481,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
public void testThatEmptyBindDNThrowsExceptionWithHealthCheckEnabled() throws Exception {
|
||||
String groupSearchBase = "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("user_search.base_dn", userSearchBase)
|
||||
.put("bind_password", "pass")
|
||||
|
@ -497,12 +496,12 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
public void testThatBindRequestReturnsSimpleBindRequest() {
|
||||
BindRequest request = LdapUserSearchSessionFactory.bindRequest(settingsBuilder()
|
||||
BindRequest request = LdapUserSearchSessionFactory.bindRequest(Settings.builder()
|
||||
.put("bind_password", "password")
|
||||
.put("bind_dn", "cn=ironman")
|
||||
.build());
|
||||
|
@ -515,7 +514,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
public void testThatLDAPServerConnectErrorDoesNotPreventNodeFromStarting() throws IOException {
|
||||
String groupSearchBase = "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,
|
||||
groupSearchBase, LdapSearchScope.SUB_TREE))
|
||||
.put("user_search.base_dn", userSearchBase)
|
||||
|
@ -526,7 +525,7 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase {
|
|||
.put("type", "ldap")
|
||||
.build();
|
||||
|
||||
Settings.Builder builder = settingsBuilder();
|
||||
Settings.Builder builder = Settings.builder();
|
||||
for (Map.Entry<String, String> entry : ldapSettings.getAsMap().entrySet()) {
|
||||
builder.put("xpack.security.authc.realms.ldap1." + entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.elasticsearch.shield.authc.RealmConfig;
|
|||
import org.elasticsearch.shield.authc.support.SecuredString;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
@ -29,7 +28,7 @@ public class SessionFactoryTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testConnectionFactoryReturnsCorrectLDAPConnectionOptions() {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(SessionFactory.TIMEOUT_TCP_CONNECTION_SETTING, "10ms")
|
||||
.put(SessionFactory.HOSTNAME_VERIFICATION_SETTING, "false")
|
||||
.put(SessionFactory.TIMEOUT_TCP_READ_SETTING, "20ms")
|
||||
|
@ -57,7 +56,7 @@ public class SessionFactoryTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -235,7 +235,7 @@ public class DnRoleMapperTests extends ESTestCase {
|
|||
|
||||
public void testYaml() throws Exception {
|
||||
Path file = getDataPath("role_mapping.yml");
|
||||
Settings ldapSettings = Settings.settingsBuilder()
|
||||
Settings ldapSettings = Settings.builder()
|
||||
.put(DnRoleMapper.ROLE_MAPPING_FILE_SETTING, file.toAbsolutePath())
|
||||
.build();
|
||||
RealmConfig config = new RealmConfig("ldap1", ldapSettings, settings);
|
||||
|
|
|
@ -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?
|
||||
|
||||
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_REPLICAS, 0));
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class ShieldLicenseeTests extends AbstractLicenseeTestCase {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
// starting the Licensee as a tribe node should not trigger it being registered
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -46,12 +45,12 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
@Before
|
||||
public void setup() throws Exception {
|
||||
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 {
|
||||
try {
|
||||
new ClientSSLService(settingsBuilder()
|
||||
new ClientSSLService(Settings.builder()
|
||||
.put("xpack.security.ssl.protocol", "non-existing")
|
||||
.put("xpack.security.ssl.keystore.path", testclientStore)
|
||||
.put("xpack.security.ssl.keystore.password", "testclient")
|
||||
|
@ -67,12 +66,12 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
public void testThatCustomTruststoreCanBeSpecified() throws Exception {
|
||||
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.password", "testclient")
|
||||
.build());
|
||||
|
||||
Settings.Builder settingsBuilder = settingsBuilder()
|
||||
Settings.Builder settingsBuilder = Settings.builder()
|
||||
.put("truststore.path", testnodeStore)
|
||||
.put("truststore.password", "testnode");
|
||||
|
||||
|
@ -84,7 +83,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testclient")
|
||||
.build());
|
||||
|
@ -97,7 +96,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
|
||||
public void testThatKeyStoreAndKeyCanHaveDifferentPasswords() throws Exception {
|
||||
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.password", "testnode")
|
||||
.put("xpack.security.ssl.keystore.key_password", "testnode1")
|
||||
|
@ -107,7 +106,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
public void testIncorrectKeyPasswordThrowsException() throws Exception {
|
||||
Path differentPasswordsStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode-different-passwords.jks");
|
||||
try {
|
||||
createClientSSLService(settingsBuilder()
|
||||
createClientSSLService(Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", differentPasswordsStore)
|
||||
.put("xpack.security.ssl.keystore.password", "testnode")
|
||||
.build()).createSSLEngine();
|
||||
|
@ -118,7 +117,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testclient")
|
||||
.build());
|
||||
|
@ -127,7 +126,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testclient")
|
||||
.build());
|
||||
|
@ -137,7 +136,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testclient")
|
||||
.put("xpack.security.ssl.session.cache_size", "300")
|
||||
|
@ -155,7 +154,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testclient")
|
||||
.build());
|
||||
|
@ -164,7 +163,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testclient")
|
||||
.build());
|
||||
|
@ -186,7 +185,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
|
||||
@Network
|
||||
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.password", "testclient")
|
||||
.build());
|
||||
|
@ -203,7 +202,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatTruststorePasswordIsRequired() throws Exception {
|
||||
ClientSSLService sslService = createClientSSLService(settingsBuilder()
|
||||
ClientSSLService sslService = createClientSSLService(Settings.builder()
|
||||
.put("xpack.security.ssl.truststore.path", testclientStore)
|
||||
.build());
|
||||
try {
|
||||
|
@ -215,7 +214,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatKeystorePasswordIsRequired() throws Exception {
|
||||
ClientSSLService sslService = createClientSSLService(settingsBuilder()
|
||||
ClientSSLService sslService = createClientSSLService(Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", testclientStore)
|
||||
.build());
|
||||
try {
|
||||
|
@ -230,7 +229,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
List<String> ciphers = new ArrayList<>(SSLSettings.Globals.DEFAULT_CIPHERS);
|
||||
ciphers.add("foo");
|
||||
ciphers.add("bar");
|
||||
ClientSSLService sslService = createClientSSLService(settingsBuilder()
|
||||
ClientSSLService sslService = createClientSSLService(Settings.builder()
|
||||
.putArray("xpack.security.ssl.ciphers", ciphers.toArray(new String[ciphers.size()]))
|
||||
.build());
|
||||
SSLEngine engine = sslService.createSSLEngine();
|
||||
|
@ -240,7 +239,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testInvalidCiphersOnlyThrowsException() throws Exception {
|
||||
ClientSSLService sslService = createClientSSLService(settingsBuilder()
|
||||
ClientSSLService sslService = createClientSSLService(Settings.builder()
|
||||
.putArray("xpack.security.ssl.ciphers", new String[] { "foo", "bar" })
|
||||
.build());
|
||||
try {
|
||||
|
@ -252,7 +251,7 @@ public class ClientSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testclient")
|
||||
.build());
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.elasticsearch.test.ESTestCase;
|
|||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
@ -34,7 +33,7 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatOnlyKeystoreInSettingsSetsTruststoreSettings() {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", "path")
|
||||
.put("xpack.security.ssl.keystore.password", "password")
|
||||
.build();
|
||||
|
@ -46,7 +45,7 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
assertThat(sslSettings.trustStorePassword, is(equalTo(sslSettings.keyStorePassword)));
|
||||
|
||||
// Pass settings in as profile settings
|
||||
settings = settingsBuilder()
|
||||
settings = Settings.builder()
|
||||
.put("keystore.path", "path")
|
||||
.put("keystore.password", "password")
|
||||
.build();
|
||||
|
@ -58,14 +57,14 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatKeystorePasswordIsDefaultKeyPassword() {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.password", "password")
|
||||
.build();
|
||||
// Pass settings in as component settings
|
||||
SSLSettings sslSettings = new SSLSettings(Settings.EMPTY, settings);
|
||||
assertThat(sslSettings.keyPassword, is(equalTo(sslSettings.keyStorePassword)));
|
||||
|
||||
settings = settingsBuilder()
|
||||
settings = Settings.builder()
|
||||
.put("keystore.password", "password")
|
||||
.build();
|
||||
// Pass settings in as profile settings
|
||||
|
@ -74,7 +73,7 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatKeyPasswordCanBeSet() {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.password", "password")
|
||||
.put("xpack.security.ssl.keystore.key_password", "key")
|
||||
.build();
|
||||
|
@ -84,7 +83,7 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
assertThat(sslSettings.keyPassword, is(equalTo("key")));
|
||||
|
||||
// Pass settings in as profile settings
|
||||
settings = settingsBuilder()
|
||||
settings = Settings.builder()
|
||||
.put("keystore.password", "password")
|
||||
.put("keystore.key_password", "key")
|
||||
.build();
|
||||
|
@ -94,7 +93,7 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatProfileSettingsOverrideServiceSettings() {
|
||||
Settings profileSettings = settingsBuilder()
|
||||
Settings profileSettings = Settings.builder()
|
||||
.put("keystore.path", "path")
|
||||
.put("keystore.password", "password")
|
||||
.put("keystore.key_password", "key")
|
||||
|
@ -107,7 +106,7 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
.put("session.cache_timeout", "10m")
|
||||
.build();
|
||||
|
||||
Settings serviceSettings = settingsBuilder()
|
||||
Settings serviceSettings = Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", "comp path")
|
||||
.put("xpack.security.ssl.keystore.password", "comp password")
|
||||
.put("xpack.security.ssl.keystore.key_password", "comp key")
|
||||
|
@ -143,9 +142,9 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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());
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder()
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", "path1").build());
|
||||
assertThat(sslSettings.equals(sslSettings1), is(equalTo(false)));
|
||||
assertThat(sslSettings1.equals(sslSettings), is(equalTo(false)));
|
||||
|
@ -154,9 +153,9 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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());
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder()
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
|
||||
.put("xpack.security.ssl.protocol", "tls").build());
|
||||
assertThat(sslSettings.equals(sslSettings1), is(equalTo(false)));
|
||||
assertThat(sslSettings1.equals(sslSettings), is(equalTo(false)));
|
||||
|
@ -165,9 +164,9 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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());
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder()
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
|
||||
.put("xpack.security.ssl.truststore.path", "/truststore").build());
|
||||
assertThat(sslSettings.equals(sslSettings1), is(equalTo(false)));
|
||||
assertThat(sslSettings1.equals(sslSettings), is(equalTo(false)));
|
||||
|
@ -182,25 +181,25 @@ public class SSLSettingsTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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());
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder()
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", "path1").build());
|
||||
assertThat(sslSettings.hashCode(), is(not(equalTo(sslSettings1.hashCode()))));
|
||||
}
|
||||
|
||||
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());
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder()
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
|
||||
.put("xpack.security.ssl.protocol", "tls").build());
|
||||
assertThat(sslSettings.hashCode(), is(not(equalTo(sslSettings1.hashCode()))));
|
||||
}
|
||||
|
||||
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());
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, settingsBuilder()
|
||||
SSLSettings sslSettings1 = new SSLSettings(Settings.EMPTY, Settings.builder()
|
||||
.put("xpack.security.ssl.truststore.path", "/truststore").build());
|
||||
assertThat(sslSettings.hashCode(), is(not(equalTo(sslSettings1.hashCode()))));
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -40,11 +39,11 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
@Before
|
||||
public void setup() throws Exception {
|
||||
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 {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("xpack.security.ssl.protocol", "non-existing")
|
||||
.put("xpack.security.ssl.keystore.path", testnodeStore)
|
||||
.put("xpack.security.ssl.keystore.password", "testnode")
|
||||
|
@ -62,13 +61,13 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
public void testThatCustomTruststoreCanBeSpecified() throws Exception {
|
||||
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.password", "testnode")
|
||||
.build();
|
||||
ServerSSLService sslService = new ServerSSLService(settings, env);
|
||||
|
||||
Settings.Builder settingsBuilder = settingsBuilder()
|
||||
Settings.Builder settingsBuilder = Settings.builder()
|
||||
.put("truststore.path", testClientStore)
|
||||
.put("truststore.password", "testclient");
|
||||
|
||||
|
@ -80,7 +79,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testnode")
|
||||
.build(), env);
|
||||
|
@ -93,7 +92,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
|
||||
public void testThatKeyStoreAndKeyCanHaveDifferentPasswords() throws Exception {
|
||||
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.password", "testnode")
|
||||
.put("xpack.security.ssl.keystore.key_password", "testnode1")
|
||||
|
@ -103,7 +102,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
public void testIncorrectKeyPasswordThrowsException() throws Exception {
|
||||
Path differentPasswordsStore = getDataPath("/org/elasticsearch/shield/transport/ssl/certs/simple/testnode-different-passwords.jks");
|
||||
try {
|
||||
new ServerSSLService(settingsBuilder()
|
||||
new ServerSSLService(Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", differentPasswordsStore)
|
||||
.put("xpack.security.ssl.keystore.password", "testnode")
|
||||
.build(), env).createSSLEngine();
|
||||
|
@ -114,7 +113,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testnode")
|
||||
.build(), env);
|
||||
|
@ -123,7 +122,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testnode")
|
||||
.build(), env);
|
||||
|
@ -133,7 +132,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testnode")
|
||||
.put("xpack.security.ssl.session.cache_size", "300")
|
||||
|
@ -155,7 +154,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testnode")
|
||||
.build(), env);
|
||||
|
@ -168,7 +167,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testnode")
|
||||
.put("xpack.security.ssl.truststore.path", testnodeStore)
|
||||
|
@ -182,7 +181,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatKeystorePasswordIsRequired() throws Exception {
|
||||
ServerSSLService sslService = new ServerSSLService(settingsBuilder()
|
||||
ServerSSLService sslService = new ServerSSLService(Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", testnodeStore)
|
||||
.build(), env);
|
||||
try {
|
||||
|
@ -197,7 +196,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
List<String> ciphers = new ArrayList<>(SSLSettings.Globals.DEFAULT_CIPHERS);
|
||||
ciphers.add("foo");
|
||||
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.password", "testnode")
|
||||
.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 {
|
||||
ServerSSLService sslService = new ServerSSLService(settingsBuilder()
|
||||
ServerSSLService sslService = new ServerSSLService(Settings.builder()
|
||||
.put("xpack.security.ssl.keystore.path", testnodeStore)
|
||||
.put("xpack.security.ssl.keystore.password", "testnode")
|
||||
.putArray("xpack.security.ssl.ciphers", new String[] { "foo", "bar" })
|
||||
|
@ -223,7 +222,7 @@ public class ServerSSLServiceTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.password", "testnode")
|
||||
.build(), env);
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.nio.file.Path;
|
|||
import java.util.Collections;
|
||||
|
||||
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.writeFile;
|
||||
import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore;
|
||||
|
@ -54,7 +53,7 @@ public class ServerTransportFilterIntegrationTests extends ShieldIntegTestCase {
|
|||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
Settings.Builder settingsBuilder = settingsBuilder();
|
||||
Settings.Builder settingsBuilder = Settings.builder();
|
||||
String randomClientPortRange = randomClientPort + "-" + (randomClientPort+100);
|
||||
|
||||
Path store;
|
||||
|
@ -93,7 +92,7 @@ public class ServerTransportFilterIntegrationTests extends ShieldIntegTestCase {
|
|||
String unicastHost = NetworkAddress.format(inetSocketAddress);
|
||||
|
||||
// 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("node.mode", "network")
|
||||
.put("node.name", "my-test-node")
|
||||
|
@ -119,7 +118,7 @@ public class ServerTransportFilterIntegrationTests extends ShieldIntegTestCase {
|
|||
Path folder = createFolder(createTempDir(), getClass().getSimpleName() + "-" + randomAsciiOfLength(10));
|
||||
|
||||
// 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.order", 0)
|
||||
.put("xpack.security.authc.realms.file.files.users", writeFile(folder, "users", configUsers()))
|
||||
|
|
|
@ -57,7 +57,7 @@ import static org.mockito.Mockito.when;
|
|||
public class TransportFilterTests extends ESIntegTestCase {
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put("node.mode", "network")
|
||||
.build();
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -82,7 +81,7 @@ public class IPFilterTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.deny", "10.0.0.0/8")
|
||||
.build();
|
||||
|
@ -95,7 +94,7 @@ public class IPFilterTests extends ESTestCase {
|
|||
public void testThatIpV6AddressesCanBeProcessed() throws Exception {
|
||||
// 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
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.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")
|
||||
.build();
|
||||
|
@ -109,7 +108,7 @@ public class IPFilterTests extends ESTestCase {
|
|||
|
||||
@Network // requires network for name resolution
|
||||
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.deny", "*.google.com")
|
||||
.build();
|
||||
|
@ -121,7 +120,7 @@ public class IPFilterTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatAnAllowAllAuthenticatorWorks() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("xpack.security.transport.filter.allow", "_all")
|
||||
.build();
|
||||
ipFilter = new IPFilter(settings, auditTrail, clusterSettings, licenseState);
|
||||
|
@ -131,7 +130,7 @@ public class IPFilterTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatProfilesAreSupported() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("xpack.security.transport.filter.allow", "localhost")
|
||||
.put("xpack.security.transport.filter.deny", "_all")
|
||||
.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 {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("xpack.security.transport.filter.allow", "10.0.0.1")
|
||||
.put("xpack.security.transport.filter.deny", "10.0.0.0/8")
|
||||
.build();
|
||||
|
@ -157,7 +156,7 @@ public class IPFilterTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testDefaultAllow() throws Exception {
|
||||
Settings settings = settingsBuilder().build();
|
||||
Settings settings = Settings.builder().build();
|
||||
ipFilter = new IPFilter(settings, auditTrail, clusterSettings, licenseState);
|
||||
ipFilter.setBoundTransportAddress(transport.boundAddress(), transport.profileBoundAddresses());
|
||||
assertAddressIsAllowed("10.0.0.1");
|
||||
|
@ -165,7 +164,7 @@ public class IPFilterTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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.deny", "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 {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("xpack.security.transport.filter.allow", "127.0.0.1")
|
||||
.put("xpack.security.transport.filter.deny", "10.0.0.0/8")
|
||||
.build();
|
||||
|
@ -199,10 +198,10 @@ public class IPFilterTests extends ESTestCase {
|
|||
|
||||
Settings settings;
|
||||
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();
|
||||
} 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.setBoundTransportAddress(transport.boundAddress(), transport.profileBoundAddresses());
|
||||
|
@ -215,7 +214,7 @@ public class IPFilterTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatAllAddressesAreAllowedWhenLicenseDisablesSecurity() {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("xpack.security.transport.filter.deny", "_all")
|
||||
.build();
|
||||
when(licenseState.securityEnabled()).thenReturn(false);
|
||||
|
|
|
@ -16,7 +16,6 @@ import java.net.InetAddress;
|
|||
import java.net.UnknownHostException;
|
||||
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.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
@ -36,7 +35,7 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
|
|||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
String randomClientPortRange = randomClientPort + "-" + (randomClientPort+100);
|
||||
return settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put(NetworkModule.HTTP_ENABLED.getKey(), httpEnabled)
|
||||
.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("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.deny", "127.0.0.8")
|
||||
.build();
|
||||
updateSettings(settings);
|
||||
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.deny", "127.0.0.8")
|
||||
.build();
|
||||
|
@ -68,7 +67,7 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
|
|||
assertConnectionRejected("default", "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.deny", "127.0.0.8")
|
||||
.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"));
|
||||
|
||||
// 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_HTTP_SETTING.getKey(), true)
|
||||
.build();
|
||||
|
@ -107,7 +106,7 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
|
|||
// now also disable for HTTP
|
||||
if (httpEnabled) {
|
||||
assertConnectionRejected(".http", "127.0.0.8");
|
||||
settings = settingsBuilder()
|
||||
settings = Settings.builder()
|
||||
.put(IPFilter.IP_FILTER_ENABLED_HTTP_SETTING.getKey(), false)
|
||||
.build();
|
||||
// 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
|
||||
public void testThatDisablingIpFilterWorksAsExpected() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("xpack.security.transport.filter.deny", "127.0.0.8")
|
||||
.build();
|
||||
updateSettings(settings);
|
||||
assertConnectionRejected("default", "127.0.0.8");
|
||||
|
||||
settings = settingsBuilder()
|
||||
settings = Settings.builder()
|
||||
.put(IPFilter.IP_FILTER_ENABLED_SETTING.getKey(), false)
|
||||
.build();
|
||||
updateSettings(settings);
|
||||
|
@ -133,13 +132,13 @@ public class IpFilteringUpdateTests extends ShieldIntegTestCase {
|
|||
}
|
||||
|
||||
public void testThatDisablingIpFilterForProfilesWorksAsExpected() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("transport.profiles.client.xpack.security.filter.deny", "127.0.0.8")
|
||||
.build();
|
||||
updateSettings(settings);
|
||||
assertConnectionRejected("client", "127.0.0.8");
|
||||
|
||||
settings = settingsBuilder()
|
||||
settings = Settings.builder()
|
||||
.put(IPFilter.IP_FILTER_ENABLED_SETTING.getKey(), false)
|
||||
.build();
|
||||
updateSettings(settings);
|
||||
|
|
|
@ -7,7 +7,6 @@ package org.elasticsearch.shield.transport.netty;
|
|||
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.SettingsFilter;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.shield.ssl.ServerSSLService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -47,7 +46,6 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.Future;
|
||||
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.instanceOf;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
@ -71,11 +69,11 @@ public class HandshakeWaitingHandlerTests extends ESTestCase {
|
|||
randomPort = randomIntBetween(49000, 65500);
|
||||
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.password", "testnode")
|
||||
.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);
|
||||
|
||||
sslContext = sslService.sslContext();
|
||||
|
|
|
@ -36,7 +36,7 @@ import java.net.SocketAddress;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -49,7 +49,7 @@ public class IPFilterNettyUpstreamHandlerTests extends ESTestCase {
|
|||
|
||||
@Before
|
||||
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.deny", "10.0.0.0/8")
|
||||
.build();
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.elasticsearch.transport.TransportSettings;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
public class IPHostnameVerificationTests extends ShieldIntegTestCase {
|
||||
|
@ -34,7 +33,7 @@ public class IPHostnameVerificationTests extends ShieldIntegTestCase {
|
|||
unicastAddresses[i] = address.replace("localhost", "127.0.0.1");
|
||||
}
|
||||
|
||||
Settings.Builder settingsBuilder = settingsBuilder()
|
||||
Settings.Builder settingsBuilder = Settings.builder()
|
||||
.put(settings)
|
||||
.putArray("discovery.zen.ping.unicast.hosts", unicastAddresses);
|
||||
|
||||
|
@ -60,7 +59,7 @@ public class IPHostnameVerificationTests extends ShieldIntegTestCase {
|
|||
|
||||
@Override
|
||||
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_RESOLVE_NAME_SETTING.getKey(), false)
|
||||
.put("xpack.security.ssl.keystore.path", keystore.toAbsolutePath())
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.junit.Before;
|
|||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
@ -33,11 +32,11 @@ public class ShieldNettyHttpServerTransportTests extends ESTestCase {
|
|||
@Before
|
||||
public void createSSLService() throws Exception {
|
||||
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.password", "testnode")
|
||||
.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);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.junit.Before;
|
|||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
@ -37,38 +36,38 @@ public class ShieldNettyTransportTests extends ESTestCase {
|
|||
@Before
|
||||
public void createSSLService() throws Exception {
|
||||
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.password", "testnode")
|
||||
.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);
|
||||
clientSSLService = new ClientSSLService(settings);
|
||||
clientSSLService.setEnvironment(env);
|
||||
}
|
||||
|
||||
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),
|
||||
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
|
||||
NettyMockUtil.setOpenChannelsHandlerToMock(transport);
|
||||
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());
|
||||
}
|
||||
|
||||
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),
|
||||
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
|
||||
NettyMockUtil.setOpenChannelsHandlerToMock(transport);
|
||||
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());
|
||||
}
|
||||
|
||||
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),
|
||||
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
|
||||
NettyMockUtil.setOpenChannelsHandlerToMock(transport);
|
||||
|
@ -77,7 +76,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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),
|
||||
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
|
||||
NettyMockUtil.setOpenChannelsHandlerToMock(transport);
|
||||
|
@ -88,7 +87,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
|
|||
|
||||
public void testRequiredClientAuth() throws Exception {
|
||||
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.CLIENT_AUTH_SETTING.getKey(), value).build();
|
||||
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 {
|
||||
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.CLIENT_AUTH_SETTING.getKey(), value).build();
|
||||
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 {
|
||||
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.CLIENT_AUTH_SETTING.getKey(), value).build();
|
||||
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 {
|
||||
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),
|
||||
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
|
||||
NettyMockUtil.setOpenChannelsHandlerToMock(transport);
|
||||
|
@ -139,7 +138,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
|
|||
|
||||
public void testProfileNoClientAuth() throws Exception {
|
||||
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),
|
||||
mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService, mock(NamedWriteableRegistry.class));
|
||||
NettyMockUtil.setOpenChannelsHandlerToMock(transport);
|
||||
|
@ -151,7 +150,7 @@ public class ShieldNettyTransportTests extends ESTestCase {
|
|||
|
||||
public void testProfileOptionalClientAuth() throws Exception {
|
||||
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),
|
||||
mock(NetworkService.class), mock(BigArrays.class), Version.CURRENT, null, serverSSLService, clientSSLService,
|
||||
mock(NamedWriteableRegistry.class));
|
||||
|
|
|
@ -19,7 +19,6 @@ import java.net.InetSocketAddress;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
@ -32,7 +31,7 @@ public class SslHostnameVerificationTests extends ShieldIntegTestCase {
|
|||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
Settings.Builder settingsBuilder = settingsBuilder().put(super.nodeSettings(nodeOrdinal));
|
||||
Settings.Builder settingsBuilder = Settings.builder().put(super.nodeSettings(nodeOrdinal));
|
||||
Path keystore;
|
||||
try {
|
||||
/*
|
||||
|
@ -72,7 +71,7 @@ public class SslHostnameVerificationTests extends ShieldIntegTestCase {
|
|||
assertThat(transportAddress, instanceOf(InetSocketTransportAddress.class));
|
||||
InetSocketAddress inetSocketAddress = ((InetSocketTransportAddress) transportAddress).address();
|
||||
|
||||
Settings settings = settingsBuilder().put(transportClientSettings())
|
||||
Settings settings = Settings.builder().put(transportClientSettings())
|
||||
.put(ShieldNettyTransport.HOSTNAME_VERIFICATION_SETTING.getKey(), true)
|
||||
.build();
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.io.IOException;
|
|||
import java.nio.file.Files;
|
||||
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.test.ShieldSettingsSource.getSSLSettingsForStore;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
@ -38,7 +37,7 @@ import static org.hamcrest.Matchers.containsString;
|
|||
public class SslClientAuthTests extends ShieldIntegTestCase {
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
// invert the require auth settings
|
||||
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
|
||||
|
@ -74,7 +73,7 @@ public class SslClientAuthTests extends ShieldIntegTestCase {
|
|||
}
|
||||
|
||||
public void testThatHttpWorksWithSslClientAuth() throws IOException {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(getSSLSettingsForStore("/org/elasticsearch/shield/transport/ssl/certs/simple/testclient.jks", "testclient"))
|
||||
.build();
|
||||
ClientSSLService sslService = new ClientSSLService(settings);
|
||||
|
@ -102,7 +101,7 @@ public class SslClientAuthTests extends ShieldIntegTestCase {
|
|||
throw new ElasticsearchException("store path doesn't exist");
|
||||
}
|
||||
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
|
||||
.put("xpack.security.ssl.keystore.path", store)
|
||||
.put("xpack.security.ssl.keystore.password", "testclient-client-profile")
|
||||
|
|
|
@ -37,7 +37,6 @@ import java.security.KeyStore;
|
|||
import java.security.SecureRandom;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
@ -46,7 +45,7 @@ import static org.hamcrest.Matchers.instanceOf;
|
|||
public class SslIntegrationTests extends ShieldIntegTestCase {
|
||||
@Override
|
||||
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(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
|
||||
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("node.name", "programmatic_transport_client")
|
||||
.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
|
||||
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("node.name", "programmatic_transport_client")
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.net.InetAddress;
|
|||
import java.nio.file.Files;
|
||||
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_USER_NAME;
|
||||
import static org.elasticsearch.test.ShieldSettingsSource.getSSLSettingsForStore;
|
||||
|
@ -64,7 +63,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
// client set up here
|
||||
.put("transport.profiles.client.port", randomClientPortRange)
|
||||
|
@ -88,7 +87,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
|
|||
}
|
||||
|
||||
private TransportClient createTransportClient(Settings additionalSettings) {
|
||||
Settings settings = settingsBuilder().put(transportClientSettings())
|
||||
Settings settings = Settings.builder().put(transportClientSettings())
|
||||
.put("node.name", "programmatic_transport_client")
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.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
|
||||
*/
|
||||
public void testThatTransportClientCanConnectToNoSslProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.build();
|
||||
|
@ -238,7 +237,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
|
|||
* as a non-ssl transport client cannot connect to a ssl profile
|
||||
*/
|
||||
public void testThatTransportClientCannotConnectToDefaultProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.build();
|
||||
|
@ -256,7 +255,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
|
|||
* as a non-ssl transport client cannot connect to a ssl profile
|
||||
*/
|
||||
public void testThatTransportClientCannotConnectToClientProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.build();
|
||||
|
@ -274,7 +273,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
|
|||
* as a non-ssl transport client cannot connect to a ssl profile
|
||||
*/
|
||||
public void testThatTransportClientCannotConnectToNoClientAuthProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.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
|
||||
*/
|
||||
public void testThatTransportClientWithOnlyTruststoreCanConnectToNoClientAuthProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
|
||||
|
@ -316,7 +315,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
|
|||
* the client has no certificate to present
|
||||
*/
|
||||
public void testThatTransportClientWithOnlyTruststoreCannotConnectToClientProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
|
||||
|
@ -340,7 +339,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
|
|||
* the client has no certificate to present
|
||||
*/
|
||||
public void testThatTransportClientWithOnlyTruststoreCannotConnectToDefaultProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
|
||||
|
@ -363,7 +362,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
|
|||
* SSL so the connection should never succeed
|
||||
*/
|
||||
public void testThatTransportClientWithOnlyTruststoreCannotConnectToNoSslProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.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
|
||||
*/
|
||||
public void testThatSSLTransportClientWithNoTruststoreCannotConnectToDefaultProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.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
|
||||
*/
|
||||
public void testThatSSLTransportClientWithNoTruststoreCannotConnectToClientProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.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
|
||||
*/
|
||||
public void testThatSSLTransportClientWithNoTruststoreCannotConnectToNoClientAuthProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
|
||||
|
@ -447,7 +446,7 @@ public class SslMultiPortTests extends ShieldIntegTestCase {
|
|||
* will not work
|
||||
*/
|
||||
public void testThatSSLTransportClientWithNoTruststoreCannotConnectToNoSslProfile() throws Exception {
|
||||
Settings settings = settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put(Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD)
|
||||
.put("cluster.name", internalCluster().getClusterName())
|
||||
.put(ShieldNettyTransport.SSL_SETTING.getKey(), true)
|
||||
|
|
|
@ -35,7 +35,6 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
|
||||
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.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||
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 static final Settings DEFAULT_SETTINGS = settingsBuilder()
|
||||
public static final Settings DEFAULT_SETTINGS = Settings.builder()
|
||||
.put("node.mode", "network")
|
||||
.build();
|
||||
|
||||
|
@ -120,7 +119,7 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ
|
|||
@Override
|
||||
public Settings nodeSettings(int 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)
|
||||
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false)
|
||||
|
@ -144,7 +143,7 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ
|
|||
|
||||
@Override
|
||||
public Settings transportClientSettings() {
|
||||
Settings.Builder builder = settingsBuilder().put(super.transportClientSettings())
|
||||
Settings.Builder builder = Settings.builder().put(super.transportClientSettings())
|
||||
.put(getClientSSLSettings());
|
||||
if (randomBoolean()) {
|
||||
builder.put(Security.USER_SETTING.getKey(),
|
||||
|
@ -247,7 +246,7 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ
|
|||
|
||||
final String sslEnabledSetting =
|
||||
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) {
|
||||
builder.put(ShieldNettyHttpServerTransport.SSL_SETTING.getKey(), false);
|
||||
|
|
|
@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.startsWith;
|
|||
public class ShieldServerTransportServiceTests extends ShieldIntegTestCase {
|
||||
@Override
|
||||
protected Settings transportClientSettings() {
|
||||
return Settings.settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.transportClientSettings())
|
||||
.put(Security.enabledSetting(), true)
|
||||
.build();
|
||||
|
|
|
@ -93,8 +93,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
|
||||
public class Watcher {
|
||||
|
||||
public static final String NAME = "watcher";
|
||||
|
@ -162,7 +160,7 @@ public class Watcher {
|
|||
if (enabled == false || transportClient) {
|
||||
return Settings.EMPTY;
|
||||
}
|
||||
Settings additionalSettings = settingsBuilder()
|
||||
Settings additionalSettings = Settings.builder()
|
||||
.put(HistoryModule.additionalSettings(settings))
|
||||
.build();
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.not;
|
|||
public class WatcherPluginDisableTests extends ESIntegTestCase {
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.settingsBuilder()
|
||||
return Settings.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false)
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class AlwaysConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParserValid() throws Exception {
|
||||
AlwaysConditionFactory factory = new AlwaysConditionFactory(Settings.settingsBuilder().build());
|
||||
AlwaysConditionFactory factory = new AlwaysConditionFactory(Settings.builder().build());
|
||||
XContentBuilder builder = jsonBuilder();
|
||||
builder.startObject();
|
||||
builder.endObject();
|
||||
|
@ -38,7 +38,7 @@ public class AlwaysConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParserInvalid() throws Exception {
|
||||
ConditionFactory factor = new AlwaysConditionFactory(Settings.settingsBuilder().build());
|
||||
ConditionFactory factor = new AlwaysConditionFactory(Settings.builder().build());
|
||||
XContentBuilder builder = jsonBuilder()
|
||||
.startObject()
|
||||
.field("foo", "bar")
|
||||
|
|
|
@ -27,7 +27,7 @@ public class NeverConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParserValid() throws Exception {
|
||||
NeverConditionFactory factory = new NeverConditionFactory(Settings.settingsBuilder().build());
|
||||
NeverConditionFactory factory = new NeverConditionFactory(Settings.builder().build());
|
||||
XContentBuilder builder = jsonBuilder();
|
||||
builder.startObject();
|
||||
builder.endObject();
|
||||
|
@ -40,7 +40,7 @@ public class NeverConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParserInvalid() throws Exception {
|
||||
ConditionFactory factory = new NeverConditionFactory(Settings.settingsBuilder().build());
|
||||
ConditionFactory factory = new NeverConditionFactory(Settings.builder().build());
|
||||
XContentBuilder builder = jsonBuilder();
|
||||
builder.startObject();
|
||||
builder.field("foo", "bar");
|
||||
|
|
|
@ -78,7 +78,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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();
|
||||
builder.startObject().endObject();
|
||||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||
|
@ -120,7 +120,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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());
|
||||
String script;
|
||||
switch (scriptType) {
|
||||
|
@ -146,7 +146,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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;
|
||||
String script = "return true";
|
||||
XContentBuilder builder = createConditionContent(script, "not_a_valid_lang", scriptType);
|
||||
|
|
|
@ -6,6 +6,12 @@
|
|||
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.SearchType;
|
||||
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.XContentType;
|
||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||
import org.elasticsearch.index.query.MatchAllQueryParser;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.query.QueryParser;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
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.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 org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.watcher.support.WatcherDateTimeUtils.formatDate;
|
||||
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);
|
||||
XContentParser parser = XContentHelper.createParser(builder.bytes());
|
||||
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
|
||||
QueryParser<MatchAllQueryBuilder> termQueryParser = MatchAllQueryBuilder::fromXContent;
|
||||
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);
|
||||
context.reset(parser);
|
||||
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());
|
||||
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
|
||||
QueryParser<MatchAllQueryBuilder> termQueryParser = MatchAllQueryBuilder::fromXContent;
|
||||
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);
|
||||
context.reset(parser);
|
||||
SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null, null);
|
||||
|
|
|
@ -238,7 +238,7 @@ public final class WatcherTestUtils {
|
|||
}
|
||||
|
||||
public static ScriptServiceProxy getScriptServiceProxy(ThreadPool tp) throws Exception {
|
||||
Settings settings = Settings.settingsBuilder()
|
||||
Settings settings = Settings.builder()
|
||||
.put("script.inline", "true")
|
||||
.put("script.indexed", "true")
|
||||
.put("path.home", createTempDir())
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.io.OutputStream;
|
|||
import java.nio.file.Files;
|
||||
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.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
|
@ -59,7 +58,7 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
throw new RuntimeException(ex);
|
||||
}
|
||||
//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 {
|
||||
|
|
|
@ -170,7 +170,7 @@ public class ScriptTransformTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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());
|
||||
String script;
|
||||
switch (scriptType) {
|
||||
|
@ -202,7 +202,7 @@ public class ScriptTransformTests extends ESTestCase {
|
|||
}
|
||||
|
||||
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());
|
||||
String script = "return true";
|
||||
XContentBuilder builder = jsonBuilder().startObject()
|
||||
|
|
|
@ -5,6 +5,14 @@
|
|||
*/
|
||||
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.common.bytes.BytesReference;
|
||||
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.XContentFactory;
|
||||
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.test.ESTestCase;
|
||||
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.auth.HttpAuthRegistry;
|
||||
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.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.support.secret.SecretService;
|
||||
import org.elasticsearch.watcher.support.text.TextTemplate;
|
||||
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
|
||||
|
@ -119,17 +127,10 @@ import org.joda.time.DateTime;
|
|||
import org.joda.time.DateTimeZone;
|
||||
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.singletonMap;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
|
||||
import static org.elasticsearch.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.watcher.test.WatcherTestUtils.matchAllRequest;
|
||||
import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -352,8 +353,9 @@ public class WatchTests extends ESTestCase {
|
|||
Map<String, InputFactory> parsers = new HashMap<>();
|
||||
switch (input.type()) {
|
||||
case SearchInput.TYPE:
|
||||
QueryParser<MatchAllQueryBuilder> termQueryParser = MatchAllQueryBuilder::fromXContent;
|
||||
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));
|
||||
return new InputRegistry(parsers);
|
||||
default:
|
||||
|
@ -419,8 +421,9 @@ public class WatchTests extends ESTestCase {
|
|||
}
|
||||
|
||||
private TransformRegistry transformRegistry() {
|
||||
QueryParser<MatchAllQueryBuilder> termQueryParser = MatchAllQueryBuilder::fromXContent;
|
||||
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<>();
|
||||
ChainTransformFactory parser = new ChainTransformFactory();
|
||||
factories.put(ChainTransform.TYPE, parser);
|
||||
|
|
Loading…
Reference in New Issue