Search in sources :

Example 11 with Builder

use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.

the class ElectionSchedulerFactoryTests method testRetriesOnCorrectSchedule.

public void testRetriesOnCorrectSchedule() {
    final Builder settingsBuilder = Settings.builder();
    final long initialTimeoutMillis;
    if (randomBoolean()) {
        initialTimeoutMillis = randomLongBetween(1, 10000);
        settingsBuilder.put(ELECTION_INITIAL_TIMEOUT_SETTING.getKey(), initialTimeoutMillis + "ms");
    } else {
        initialTimeoutMillis = ELECTION_INITIAL_TIMEOUT_SETTING.get(Settings.EMPTY).millis();
    }
    if (randomBoolean()) {
        settingsBuilder.put(ELECTION_BACK_OFF_TIME_SETTING.getKey(), randomLongBetween(1, 60000) + "ms");
    }
    if (ELECTION_MAX_TIMEOUT_SETTING.get(Settings.EMPTY).millis() < initialTimeoutMillis || randomBoolean()) {
        settingsBuilder.put(ELECTION_MAX_TIMEOUT_SETTING.getKey(), randomLongBetween(Math.max(200, initialTimeoutMillis), 180000) + "ms");
    }
    final long electionDurationMillis;
    if (randomBoolean()) {
        electionDurationMillis = randomLongBetween(1, 300000);
        settingsBuilder.put(ELECTION_DURATION_SETTING.getKey(), electionDurationMillis + "ms");
    } else {
        electionDurationMillis = ELECTION_DURATION_SETTING.get(Settings.EMPTY).millis();
    }
    final Settings settings = settingsBuilder.put(NODE_NAME_SETTING.getKey(), "node").build();
    final long initialTimeout = ELECTION_INITIAL_TIMEOUT_SETTING.get(settings).millis();
    final long backOffTime = ELECTION_BACK_OFF_TIME_SETTING.get(settings).millis();
    final long maxTimeout = ELECTION_MAX_TIMEOUT_SETTING.get(settings).millis();
    final long duration = ELECTION_DURATION_SETTING.get(settings).millis();
    final DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
    final ElectionSchedulerFactory electionSchedulerFactory = new ElectionSchedulerFactory(settings, random(), deterministicTaskQueue.getThreadPool());
    assertElectionSchedule(deterministicTaskQueue, electionSchedulerFactory, initialTimeout, backOffTime, maxTimeout, duration);
    // do it again to show that the max is reset when the scheduler is restarted
    assertElectionSchedule(deterministicTaskQueue, electionSchedulerFactory, initialTimeout, backOffTime, maxTimeout, duration);
}
Also used : Builder(org.opensearch.common.settings.Settings.Builder) Settings(org.opensearch.common.settings.Settings)

Example 12 with Builder

use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.

the class FollowersCheckerTests method testPreferClusterManagerNodes.

public void testPreferClusterManagerNodes() {
    List<DiscoveryNode> nodes = randomNodes(10);
    DiscoveryNodes.Builder discoNodesBuilder = DiscoveryNodes.builder();
    nodes.forEach(dn -> discoNodesBuilder.add(dn));
    DiscoveryNodes discoveryNodes = discoNodesBuilder.localNodeId(nodes.get(0).getId()).build();
    CapturingTransport capturingTransport = new CapturingTransport();
    final Settings settings = Settings.builder().put(NODE_NAME_SETTING.getKey(), nodes.get(0).getName()).build();
    final DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(settings, random());
    TransportService transportService = capturingTransport.createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> nodes.get(0), null, emptySet());
    final FollowersChecker followersChecker = new FollowersChecker(Settings.EMPTY, transportService, fcr -> {
        assert false : fcr;
    }, (node, reason) -> {
        assert false : node;
    }, () -> new StatusInfo(HEALTHY, "healthy-info"));
    followersChecker.setCurrentNodes(discoveryNodes);
    List<DiscoveryNode> followerTargets = Stream.of(capturingTransport.getCapturedRequestsAndClear()).map(cr -> cr.node).collect(Collectors.toList());
    List<DiscoveryNode> sortedFollowerTargets = new ArrayList<>(followerTargets);
    Collections.sort(sortedFollowerTargets, Comparator.comparing(n -> n.isMasterNode() == false));
    assertEquals(sortedFollowerTargets, followerTargets);
}
Also used : FOLLOWER_CHECK_INTERVAL_SETTING(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_INTERVAL_SETTING) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) FOLLOWER_CHECK_TIMEOUT_SETTING(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_TIMEOUT_SETTING) HANDSHAKE_ACTION_NAME(org.opensearch.transport.TransportService.HANDSHAKE_ACTION_NAME) Matchers.not(org.hamcrest.Matchers.not) Version(org.opensearch.Version) OpenSearchException(org.opensearch.OpenSearchException) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) EqualsHashCodeTestUtils(org.opensearch.test.EqualsHashCodeTestUtils) UNHEALTHY(org.opensearch.monitor.StatusInfo.Status.UNHEALTHY) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) NodeHealthService(org.opensearch.monitor.NodeHealthService) Set(java.util.Set) HEALTHY(org.opensearch.monitor.StatusInfo.Status.HEALTHY) Settings(org.opensearch.common.settings.Settings) TransportResponse(org.opensearch.transport.TransportResponse) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) FOLLOWER_CHECK_ACTION_NAME(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_ACTION_NAME) StatusInfo(org.opensearch.monitor.StatusInfo) ConnectTransportException(org.opensearch.transport.ConnectTransportException) FOLLOWER_CHECK_RETRY_COUNT_SETTING(org.opensearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_RETRY_COUNT_SETTING) Builder(org.opensearch.common.settings.Settings.Builder) TransportException(org.opensearch.transport.TransportException) Names(org.opensearch.threadpool.ThreadPool.Names) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MockTransport(org.opensearch.test.transport.MockTransport) StreamInput(org.opensearch.common.io.stream.StreamInput) Empty(org.opensearch.transport.TransportResponse.Empty) Matchers.empty(org.hamcrest.Matchers.empty) TransportRequest(org.opensearch.transport.TransportRequest) Collections.emptySet(java.util.Collections.emptySet) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) FollowerCheckRequest(org.opensearch.cluster.coordination.FollowersChecker.FollowerCheckRequest) NODE_NAME_SETTING(org.opensearch.node.Node.NODE_NAME_SETTING) ClusterName(org.opensearch.cluster.ClusterName) Mode(org.opensearch.cluster.coordination.Coordinator.Mode) CopyFunction(org.opensearch.test.EqualsHashCodeTestUtils.CopyFunction) Comparator(java.util.Comparator) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportService(org.opensearch.transport.TransportService) StatusInfo(org.opensearch.monitor.StatusInfo) CapturingTransport(org.opensearch.test.transport.CapturingTransport) ArrayList(java.util.ArrayList) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) Settings(org.opensearch.common.settings.Settings)

Example 13 with Builder

use of org.opensearch.common.settings.Settings.Builder in project security by opensearch-project.

the class DisabledCategoriesTest method invalidRestCategoryConfigurationTest.

@Test
public void invalidRestCategoryConfigurationTest() {
    thrown.expect(IllegalArgumentException.class);
    Builder settingsBuilder = Settings.builder();
    settingsBuilder.put("plugins.security.audit.type", TestAuditlogImpl.class.getName());
    settingsBuilder.put(ConfigConstants.OPENDISTRO_SECURITY_AUDIT_CONFIG_DISABLED_REST_CATEGORIES, "nonexistent");
    AuditTestUtils.createAuditLog(settingsBuilder.build(), null, null, AbstractSecurityUnitTest.MOCK_POOL, null, cs);
}
Also used : Builder(org.opensearch.common.settings.Settings.Builder) TestAuditlogImpl(org.opensearch.security.auditlog.integration.TestAuditlogImpl) Test(org.junit.Test) AbstractSecurityUnitTest(org.opensearch.security.test.AbstractSecurityUnitTest)

Example 14 with Builder

use of org.opensearch.common.settings.Settings.Builder in project security by opensearch-project.

the class DisabledCategoriesTest method checkCategoriesDisabled.

/*@After
	public void restoreOut() {
		System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
	}*/
protected void checkCategoriesDisabled(AuditCategory... disabledCategories) throws Exception {
    List<String> categoryNames = new LinkedList<>();
    for (AuditCategory category : disabledCategories) {
        categoryNames.add(category.name().toLowerCase());
    }
    String disabledCategoriesString = Joiner.on(",").join(categoryNames);
    Builder settingsBuilder = Settings.builder();
    settingsBuilder.put("plugins.security.audit.type", TestAuditlogImpl.class.getName());
    settingsBuilder.put(ConfigConstants.OPENDISTRO_SECURITY_AUDIT_CONFIG_DISABLED_TRANSPORT_CATEGORIES, disabledCategoriesString);
    settingsBuilder.put(ConfigConstants.OPENDISTRO_SECURITY_AUDIT_CONFIG_DISABLED_REST_CATEGORIES, disabledCategoriesString);
    // we use the debug output, no OpenSearch client is needed. Also, we
    // do not need to close.
    AbstractAuditLog auditLog = AuditTestUtils.createAuditLog(settingsBuilder.build(), null, null, AbstractSecurityUnitTest.MOCK_POOL, null, cs);
    logAll(auditLog);
    auditLog.close();
    String result = TestAuditlogImpl.sb.toString();
    List<AuditCategory> allButDisablesCategories = new LinkedList<>(Arrays.asList(AuditCategory.values()));
    allButDisablesCategories.removeAll(Arrays.asList(disabledCategories));
    System.out.println(result + "###" + disabledCategoriesString);
    Assert.assertFalse(categoriesPresentInLog(result, disabledCategories));
    Assert.assertTrue(categoriesPresentInLog(result, filterComplianceCategories(allButDisablesCategories.toArray(new AuditCategory[] {}))));
}
Also used : Builder(org.opensearch.common.settings.Settings.Builder) TestAuditlogImpl(org.opensearch.security.auditlog.integration.TestAuditlogImpl) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LinkedList(java.util.LinkedList)

Example 15 with Builder

use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.

the class StopTokenFilterTests method testPositionIncrementSetting.

public void testPositionIncrementSetting() throws IOException {
    Builder builder = Settings.builder().put("index.analysis.filter.my_stop.type", "stop").put("index.analysis.filter.my_stop.enable_position_increments", false);
    if (random().nextBoolean()) {
        builder.put("index.analysis.filter.my_stop.version", "5.0");
    }
    builder.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString());
    Settings settings = builder.build();
    try {
        AnalysisTestsHelper.createTestAnalysisFromSettings(settings);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("enable_position_increments is not supported anymore"));
    }
}
Also used : Builder(org.opensearch.common.settings.Settings.Builder) Settings(org.opensearch.common.settings.Settings)

Aggregations

Builder (org.opensearch.common.settings.Settings.Builder)35 Settings (org.opensearch.common.settings.Settings)11 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)9 SearchRequestBuilder (org.opensearch.action.search.SearchRequestBuilder)7 QueryBuilder (org.opensearch.index.query.QueryBuilder)7 IndexRequestBuilder (org.opensearch.action.index.IndexRequestBuilder)6 SearchResponse (org.opensearch.action.search.SearchResponse)6 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)6 XContentFactory.jsonBuilder (org.opensearch.common.xcontent.XContentFactory.jsonBuilder)6 QueryRescorerBuilder (org.opensearch.search.rescore.QueryRescorerBuilder)5 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 OpenSearchException (org.opensearch.OpenSearchException)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3