Search in sources :

Example 31 with IndexNameExpressionResolver

use of org.opensearch.cluster.metadata.IndexNameExpressionResolver in project OpenSearch by opensearch-project.

the class GetDataStreamsRequestTests method testGetNonexistentDataStream.

public void testGetNonexistentDataStream() {
    final String dataStreamName = "my-data-stream";
    ClusterState cs = ClusterState.builder(new ClusterName("_name")).build();
    GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[] { dataStreamName });
    IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req));
    assertThat(e.getMessage(), containsString("no such index [" + dataStreamName + "]"));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) Request(org.opensearch.action.admin.indices.datastream.GetDataStreamAction.Request) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterName(org.opensearch.cluster.ClusterName) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) Request(org.opensearch.action.admin.indices.datastream.GetDataStreamAction.Request) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver)

Example 32 with IndexNameExpressionResolver

use of org.opensearch.cluster.metadata.IndexNameExpressionResolver in project OpenSearch by opensearch-project.

the class GetDataStreamsRequestTests method testGetDataStream.

public void testGetDataStream() {
    final String dataStreamName = "my-data-stream";
    ClusterState cs = getClusterStateWithDataStreams(org.opensearch.common.collect.List.of(new Tuple<>(dataStreamName, 1)), org.opensearch.common.collect.List.of());
    GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[] { dataStreamName });
    List<DataStream> dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
    assertThat(dataStreams.size(), equalTo(1));
    assertThat(dataStreams.get(0).getName(), equalTo(dataStreamName));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) DataStream(org.opensearch.cluster.metadata.DataStream) Request(org.opensearch.action.admin.indices.datastream.GetDataStreamAction.Request) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Request(org.opensearch.action.admin.indices.datastream.GetDataStreamAction.Request) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Tuple(org.opensearch.common.collect.Tuple)

Example 33 with IndexNameExpressionResolver

use of org.opensearch.cluster.metadata.IndexNameExpressionResolver in project OpenSearch by opensearch-project.

the class GetDataStreamsRequestTests method testGetDataStreamsWithoutWildcards.

public void testGetDataStreamsWithoutWildcards() {
    final String[] dataStreamNames = { "my-data-stream", "another-data-stream" };
    ClusterState cs = getClusterStateWithDataStreams(org.opensearch.common.collect.List.of(new Tuple<>(dataStreamNames[0], 1), new Tuple<>(dataStreamNames[1], 1)), org.opensearch.common.collect.List.of());
    GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[] { dataStreamNames[0], dataStreamNames[1] });
    List<DataStream> dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
    assertThat(dataStreams.size(), equalTo(2));
    assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1]));
    assertThat(dataStreams.get(1).getName(), equalTo(dataStreamNames[0]));
    req = new GetDataStreamAction.Request(new String[] { dataStreamNames[1] });
    dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
    assertThat(dataStreams.size(), equalTo(1));
    assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1]));
    req = new GetDataStreamAction.Request(new String[] { dataStreamNames[0] });
    dataStreams = GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req);
    assertThat(dataStreams.size(), equalTo(1));
    assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[0]));
    GetDataStreamAction.Request req2 = new GetDataStreamAction.Request(new String[] { "foo" });
    IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> GetDataStreamAction.TransportAction.getDataStreams(cs, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req2));
    assertThat(e.getMessage(), containsString("no such index [foo]"));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) DataStream(org.opensearch.cluster.metadata.DataStream) Request(org.opensearch.action.admin.indices.datastream.GetDataStreamAction.Request) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) Request(org.opensearch.action.admin.indices.datastream.GetDataStreamAction.Request) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Tuple(org.opensearch.common.collect.Tuple)

Example 34 with IndexNameExpressionResolver

use of org.opensearch.cluster.metadata.IndexNameExpressionResolver in project OpenSearch by opensearch-project.

the class IndexModuleTests method testWrapperIsBound.

public void testWrapperIsBound() throws IOException {
    final MockEngineFactory engineFactory = new MockEngineFactory(AssertingDirectoryReader.class);
    IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, engineFactory, new EngineConfigFactory(indexSettings), Collections.emptyMap(), () -> true, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), Collections.emptyMap());
    module.setReaderWrapper(s -> new Wrapper());
    IndexService indexService = newIndexService(module);
    assertTrue(indexService.getReaderWrapper() instanceof Wrapper);
    assertSame(indexService.getEngineFactory(), module.getEngineFactory());
    indexService.close("simon says", false);
}
Also used : MockEngineFactory(org.opensearch.test.engine.MockEngineFactory) EngineConfigFactory(org.opensearch.index.engine.EngineConfigFactory) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver)

Example 35 with IndexNameExpressionResolver

use of org.opensearch.cluster.metadata.IndexNameExpressionResolver in project OpenSearch by opensearch-project.

the class TransportAddVotingConfigExclusionsActionTests method setupForTest.

@Before
public void setupForTest() {
    final MockTransport transport = new MockTransport();
    transportService = transport.createTransportService(Settings.EMPTY, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundTransportAddress -> localNode, null, emptySet());
    final Settings.Builder nodeSettingsBuilder = Settings.builder();
    if (randomBoolean()) {
        staticMaximum = between(5, 15);
        nodeSettingsBuilder.put(MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.getKey(), staticMaximum);
    } else {
        staticMaximum = MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.get(Settings.EMPTY);
    }
    final Settings nodeSettings = nodeSettingsBuilder.build();
    clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    new TransportAddVotingConfigExclusionsAction(nodeSettings, clusterSettings, transportService, clusterService, threadPool, new ActionFilters(emptySet()), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)));
    // registers action
    transportService.start();
    transportService.acceptIncomingRequests();
    final VotingConfiguration allNodesConfig = VotingConfiguration.of(localNode, otherNode1, otherNode2);
    setState(clusterService, builder(new ClusterName("cluster")).nodes(new Builder().add(localNode).add(otherNode1).add(otherNode2).add(otherDataNode).localNodeId(localNode.getId()).masterNodeId(localNode.getId())).metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().lastAcceptedConfiguration(allNodesConfig).lastCommittedConfiguration(allNodesConfig).build())));
    clusterStateObserver = new ClusterStateObserver(clusterService, null, logger, threadPool.getThreadContext());
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) Metadata(org.opensearch.cluster.metadata.Metadata) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Strings(org.opensearch.common.Strings) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Collections.singleton(java.util.Collections.singleton) AfterClass(org.junit.AfterClass) TimeValue(org.opensearch.common.unit.TimeValue) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) TransportException(org.opensearch.transport.TransportException) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) BeforeClass(org.junit.BeforeClass) ThreadPool(org.opensearch.threadpool.ThreadPool) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING(org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction.MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) MockTransport(org.opensearch.test.transport.MockTransport) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) SetOnce(org.apache.lucene.util.SetOnce) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Collections.emptySet(java.util.Collections.emptySet) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) IOException(java.io.IOException) ClusterState.builder(org.opensearch.cluster.ClusterState.builder) Listener(org.opensearch.cluster.ClusterStateObserver.Listener) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ClusterService(org.opensearch.cluster.service.ClusterService) ClusterName(org.opensearch.cluster.ClusterName) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ActionFilters(org.opensearch.action.support.ActionFilters) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) MockTransport(org.opensearch.test.transport.MockTransport) ClusterName(org.opensearch.cluster.ClusterName) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before)

Aggregations

IndexNameExpressionResolver (org.opensearch.cluster.metadata.IndexNameExpressionResolver)39 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)26 ClusterState (org.opensearch.cluster.ClusterState)20 Matchers.containsString (org.hamcrest.Matchers.containsString)18 Settings (org.opensearch.common.settings.Settings)15 ThreadPool (org.opensearch.threadpool.ThreadPool)14 ClusterService (org.opensearch.cluster.service.ClusterService)11 Metadata (org.opensearch.cluster.metadata.Metadata)10 Tuple (org.opensearch.common.collect.Tuple)10 IOException (java.io.IOException)9 Before (org.junit.Before)9 ClusterName (org.opensearch.cluster.ClusterName)9 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)9 TestThreadPool (org.opensearch.threadpool.TestThreadPool)8 ActionListener (org.opensearch.action.ActionListener)7 ActionFilters (org.opensearch.action.support.ActionFilters)7 ClusterSettings (org.opensearch.common.settings.ClusterSettings)7 Index (org.opensearch.index.Index)7 TransportService (org.opensearch.transport.TransportService)7 HashSet (java.util.HashSet)5