Search in sources :

Example 1 with SystemIndices

use of org.opensearch.indices.SystemIndices in project OpenSearch by opensearch-project.

the class TransportBulkAction method doInternalExecute.

protected void doInternalExecute(Task task, BulkRequest bulkRequest, String executorName, ActionListener<BulkResponse> listener) {
    final long startTime = relativeTime();
    final AtomicArray<BulkItemResponse> responses = new AtomicArray<>(bulkRequest.requests.size());
    boolean hasIndexRequestsWithPipelines = false;
    final Metadata metadata = clusterService.state().getMetadata();
    final Version minNodeVersion = clusterService.state().getNodes().getMinNodeVersion();
    for (DocWriteRequest<?> actionRequest : bulkRequest.requests) {
        IndexRequest indexRequest = getIndexWriteRequest(actionRequest);
        if (indexRequest != null) {
            // Each index request needs to be evaluated, because this method also modifies the IndexRequest
            boolean indexRequestHasPipeline = IngestService.resolvePipelines(actionRequest, indexRequest, metadata);
            hasIndexRequestsWithPipelines |= indexRequestHasPipeline;
        }
        if (actionRequest instanceof IndexRequest) {
            IndexRequest ir = (IndexRequest) actionRequest;
            ir.checkAutoIdWithOpTypeCreateSupportedByVersion(minNodeVersion);
            if (ir.getAutoGeneratedTimestamp() != IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP) {
                throw new IllegalArgumentException("autoGeneratedTimestamp should not be set externally");
            }
        }
    }
    if (hasIndexRequestsWithPipelines) {
        // this path is never taken.
        try {
            if (Assertions.ENABLED) {
                final boolean arePipelinesResolved = bulkRequest.requests().stream().map(TransportBulkAction::getIndexWriteRequest).filter(Objects::nonNull).allMatch(IndexRequest::isPipelineResolved);
                assert arePipelinesResolved : bulkRequest;
            }
            if (clusterService.localNode().isIngestNode()) {
                processBulkIndexIngestRequest(task, bulkRequest, executorName, listener);
            } else {
                ingestForwarder.forwardIngestRequest(BulkAction.INSTANCE, bulkRequest, listener);
            }
        } catch (Exception e) {
            listener.onFailure(e);
        }
        return;
    }
    final boolean includesSystem = includesSystem(bulkRequest, clusterService.state().metadata().getIndicesLookup(), systemIndices);
    if (includesSystem || needToCheck()) {
        // Attempt to create all the indices that we're going to need during the bulk before we start.
        // Step 1: collect all the indices in the request
        final Map<String, Boolean> indices = bulkRequest.requests.stream().filter(request -> request.opType() != DocWriteRequest.OpType.DELETE || request.versionType() == VersionType.EXTERNAL || request.versionType() == VersionType.EXTERNAL_GTE).collect(Collectors.toMap(DocWriteRequest::index, DocWriteRequest::isRequireAlias, (v1, v2) -> v1 || v2));
        /* Step 2: filter that to indices that don't exist and we can create. At the same time build a map of indices we can't create
             * that we'll use when we try to run the requests. */
        final Map<String, IndexNotFoundException> indicesThatCannotBeCreated = new HashMap<>();
        Set<String> autoCreateIndices = new HashSet<>();
        ClusterState state = clusterService.state();
        for (Map.Entry<String, Boolean> indexAndFlag : indices.entrySet()) {
            boolean shouldAutoCreate;
            final String index = indexAndFlag.getKey();
            try {
                shouldAutoCreate = shouldAutoCreate(index, state);
            } catch (IndexNotFoundException e) {
                shouldAutoCreate = false;
                indicesThatCannotBeCreated.put(index, e);
            }
            // We should only auto create if we are not requiring it to be an alias
            if (shouldAutoCreate && (indexAndFlag.getValue() == false)) {
                autoCreateIndices.add(index);
            }
        }
        // Step 3: create all the indices that are missing, if there are any missing. start the bulk after all the creates come back.
        if (autoCreateIndices.isEmpty()) {
            executeBulk(task, bulkRequest, startTime, listener, responses, indicesThatCannotBeCreated);
        } else {
            final AtomicInteger counter = new AtomicInteger(autoCreateIndices.size());
            for (String index : autoCreateIndices) {
                createIndex(index, bulkRequest.timeout(), minNodeVersion, new ActionListener<CreateIndexResponse>() {

                    @Override
                    public void onResponse(CreateIndexResponse result) {
                        if (counter.decrementAndGet() == 0) {
                            threadPool.executor(executorName).execute(new ActionRunnable<BulkResponse>(listener) {

                                @Override
                                protected void doRun() {
                                    executeBulk(task, bulkRequest, startTime, listener, responses, indicesThatCannotBeCreated);
                                }
                            });
                        }
                    }

                    @Override
                    public void onFailure(Exception e) {
                        if (!(ExceptionsHelper.unwrapCause(e) instanceof ResourceAlreadyExistsException)) {
                            // fail all requests involving this index, if create didn't work
                            for (int i = 0; i < bulkRequest.requests.size(); i++) {
                                DocWriteRequest<?> request = bulkRequest.requests.get(i);
                                if (request != null && setResponseFailureIfIndexMatches(responses, i, request, index, e)) {
                                    bulkRequest.requests.set(i, null);
                                }
                            }
                        }
                        if (counter.decrementAndGet() == 0) {
                            final ActionListener<BulkResponse> wrappedListener = ActionListener.wrap(listener::onResponse, inner -> {
                                inner.addSuppressed(e);
                                listener.onFailure(inner);
                            });
                            threadPool.executor(executorName).execute(new ActionRunnable<BulkResponse>(wrappedListener) {

                                @Override
                                protected void doRun() {
                                    executeBulk(task, bulkRequest, startTime, wrappedListener, responses, indicesThatCannotBeCreated);
                                }

                                @Override
                                public void onRejection(Exception rejectedException) {
                                    rejectedException.addSuppressed(e);
                                    super.onRejection(rejectedException);
                                }
                            });
                        }
                    }
                });
            }
        }
    } else {
        executeBulk(task, bulkRequest, startTime, listener, responses, emptyMap());
    }
}
Also used : SequenceNumbers(org.opensearch.index.seqno.SequenceNumbers) IndexAbstraction(org.opensearch.cluster.metadata.IndexAbstraction) Metadata(org.opensearch.cluster.metadata.Metadata) LongSupplier(java.util.function.LongSupplier) DataStream(org.opensearch.cluster.metadata.DataStream) Version(org.opensearch.Version) TransportUpdateAction(org.opensearch.action.update.TransportUpdateAction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Assertions(org.opensearch.Assertions) Map(java.util.Map) NodeClosedException(org.opensearch.node.NodeClosedException) AutoCreateAction(org.opensearch.action.admin.indices.create.AutoCreateAction) Inject(org.opensearch.common.inject.Inject) ActionListener(org.opensearch.action.ActionListener) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) CreateIndexRequest(org.opensearch.action.admin.indices.create.CreateIndexRequest) TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) Index(org.opensearch.index.Index) IndexingPressureService(org.opensearch.index.IndexingPressureService) OpenSearchParseException(org.opensearch.OpenSearchParseException) ExceptionsHelper(org.opensearch.ExceptionsHelper) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) Set(java.util.Set) Task(org.opensearch.tasks.Task) TransportService(org.opensearch.transport.TransportService) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ActionFilters(org.opensearch.action.support.ActionFilters) VersionType(org.opensearch.index.VersionType) List(java.util.List) Logger(org.apache.logging.log4j.Logger) SparseFixedBitSet(org.apache.lucene.util.SparseFixedBitSet) EXCLUDED_DATA_STREAMS_KEY(org.opensearch.cluster.metadata.IndexNameExpressionResolver.EXCLUDED_DATA_STREAMS_KEY) ResourceAlreadyExistsException(org.opensearch.ResourceAlreadyExistsException) DocWriteResponse(org.opensearch.action.DocWriteResponse) UpdateRequest(org.opensearch.action.update.UpdateRequest) SortedMap(java.util.SortedMap) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) MappingMetadata(org.opensearch.cluster.metadata.MappingMetadata) HandledTransportAction(org.opensearch.action.support.HandledTransportAction) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ActionRunnable(org.opensearch.action.ActionRunnable) UpdateResponse(org.opensearch.action.update.UpdateResponse) ThreadPool(org.opensearch.threadpool.ThreadPool) RoutingMissingException(org.opensearch.action.RoutingMissingException) DocWriteRequest(org.opensearch.action.DocWriteRequest) HashMap(java.util.HashMap) Releasable(org.opensearch.common.lease.Releasable) ArrayList(java.util.ArrayList) AutoCreateIndex(org.opensearch.action.support.AutoCreateIndex) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) UNASSIGNED_SEQ_NO(org.opensearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO) LegacyESVersion(org.opensearch.LegacyESVersion) IndexClosedException(org.opensearch.indices.IndexClosedException) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) Collections.emptyMap(java.util.Collections.emptyMap) IngestService(org.opensearch.ingest.IngestService) Iterator(java.util.Iterator) IngestActionForwarder(org.opensearch.action.ingest.IngestActionForwarder) ClusterBlockLevel(org.opensearch.cluster.block.ClusterBlockLevel) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) UNASSIGNED_PRIMARY_TERM(org.opensearch.index.seqno.SequenceNumbers.UNASSIGNED_PRIMARY_TERM) ShardId(org.opensearch.index.shard.ShardId) TimeUnit(java.util.concurrent.TimeUnit) SystemIndices(org.opensearch.indices.SystemIndices) AtomicArray(org.opensearch.common.util.concurrent.AtomicArray) ClusterService(org.opensearch.cluster.service.ClusterService) IndexRequest(org.opensearch.action.index.IndexRequest) LogManager(org.apache.logging.log4j.LogManager) AtomicArray(org.opensearch.common.util.concurrent.AtomicArray) ActionRunnable(org.opensearch.action.ActionRunnable) HashMap(java.util.HashMap) Metadata(org.opensearch.cluster.metadata.Metadata) MappingMetadata(org.opensearch.cluster.metadata.MappingMetadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) CreateIndexRequest(org.opensearch.action.admin.indices.create.CreateIndexRequest) IndexRequest(org.opensearch.action.index.IndexRequest) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) ResourceAlreadyExistsException(org.opensearch.ResourceAlreadyExistsException) NodeClosedException(org.opensearch.node.NodeClosedException) OpenSearchParseException(org.opensearch.OpenSearchParseException) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) ResourceAlreadyExistsException(org.opensearch.ResourceAlreadyExistsException) RoutingMissingException(org.opensearch.action.RoutingMissingException) IndexClosedException(org.opensearch.indices.IndexClosedException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ActionListener(org.opensearch.action.ActionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) DocWriteRequest(org.opensearch.action.DocWriteRequest) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap)

Example 2 with SystemIndices

use of org.opensearch.indices.SystemIndices in project OpenSearch by opensearch-project.

the class TransportBulkActionTests method testOnlySystem.

public void testOnlySystem() {
    SortedMap<String, IndexAbstraction> indicesLookup = new TreeMap<>();
    Settings settings = Settings.builder().put("index.version.created", Version.CURRENT).build();
    indicesLookup.put(".foo", new Index(IndexMetadata.builder(".foo").settings(settings).system(true).numberOfShards(1).numberOfReplicas(0).build()));
    indicesLookup.put(".bar", new Index(IndexMetadata.builder(".bar").settings(settings).system(true).numberOfShards(1).numberOfReplicas(0).build()));
    SystemIndices systemIndices = new SystemIndices(singletonMap("plugin", singletonList(new SystemIndexDescriptor(".test", ""))));
    List<String> onlySystem = Arrays.asList(".foo", ".bar");
    assertTrue(bulkAction.isOnlySystem(buildBulkRequest(onlySystem), indicesLookup, systemIndices));
    onlySystem = Arrays.asList(".foo", ".bar", ".test");
    assertTrue(bulkAction.isOnlySystem(buildBulkRequest(onlySystem), indicesLookup, systemIndices));
    List<String> nonSystem = Arrays.asList("foo", "bar");
    assertFalse(bulkAction.isOnlySystem(buildBulkRequest(nonSystem), indicesLookup, systemIndices));
    List<String> mixed = Arrays.asList(".foo", ".test", "other");
    assertFalse(bulkAction.isOnlySystem(buildBulkRequest(mixed), indicesLookup, systemIndices));
}
Also used : IndexAbstraction(org.opensearch.cluster.metadata.IndexAbstraction) SystemIndexDescriptor(org.opensearch.indices.SystemIndexDescriptor) Index(org.opensearch.cluster.metadata.IndexAbstraction.Index) AutoCreateIndex(org.opensearch.action.support.AutoCreateIndex) TreeMap(java.util.TreeMap) SystemIndices(org.opensearch.indices.SystemIndices) Settings(org.opensearch.common.settings.Settings)

Example 3 with SystemIndices

use of org.opensearch.indices.SystemIndices in project OpenSearch by opensearch-project.

the class TransportBulkActionIndicesThatCannotBeCreatedTests method indicesThatCannotBeCreatedTestCase.

private void indicesThatCannotBeCreatedTestCase(Set<String> expected, BulkRequest bulkRequest, Function<String, Boolean> shouldAutoCreate) {
    ClusterService clusterService = mock(ClusterService.class);
    ClusterState state = mock(ClusterState.class);
    when(state.getMetadata()).thenReturn(Metadata.EMPTY_METADATA);
    when(state.metadata()).thenReturn(Metadata.EMPTY_METADATA);
    when(clusterService.state()).thenReturn(state);
    DiscoveryNodes discoveryNodes = mock(DiscoveryNodes.class);
    when(state.getNodes()).thenReturn(discoveryNodes);
    when(discoveryNodes.getMinNodeVersion()).thenReturn(VersionUtils.randomCompatibleVersion(random(), Version.CURRENT));
    DiscoveryNode localNode = mock(DiscoveryNode.class);
    when(clusterService.localNode()).thenReturn(localNode);
    when(localNode.isIngestNode()).thenReturn(randomBoolean());
    final ThreadPool threadPool = mock(ThreadPool.class);
    final ExecutorService direct = OpenSearchExecutors.newDirectExecutorService();
    when(threadPool.executor(anyString())).thenReturn(direct);
    TransportBulkAction action = new TransportBulkAction(threadPool, mock(TransportService.class), clusterService, null, null, null, mock(ActionFilters.class), null, null, new IndexingPressureService(Settings.EMPTY, new ClusterService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null)), new SystemIndices(emptyMap())) {

        @Override
        void executeBulk(Task task, BulkRequest bulkRequest, long startTimeNanos, ActionListener<BulkResponse> listener, AtomicArray<BulkItemResponse> responses, Map<String, IndexNotFoundException> indicesThatCannotBeCreated) {
            assertEquals(expected, indicesThatCannotBeCreated.keySet());
        }

        @Override
        boolean needToCheck() {
            // Use "null" to mean "no indices can be created so don't bother checking"
            return null != shouldAutoCreate;
        }

        @Override
        boolean shouldAutoCreate(String index, ClusterState state) {
            return shouldAutoCreate.apply(index);
        }

        @Override
        void createIndex(String index, TimeValue timeout, Version minNodeVersion, ActionListener<CreateIndexResponse> listener) {
            // If we try to create an index just immediately assume it worked
            listener.onResponse(new CreateIndexResponse(true, true, index) {
            });
        }
    };
    action.doExecute(null, bulkRequest, null);
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) IndexingPressureService(org.opensearch.index.IndexingPressureService) Task(org.opensearch.tasks.Task) AtomicArray(org.opensearch.common.util.concurrent.AtomicArray) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ThreadPool(org.opensearch.threadpool.ThreadPool) ActionFilters(org.opensearch.action.support.ActionFilters) Mockito.anyString(org.mockito.Mockito.anyString) ClusterService(org.opensearch.cluster.service.ClusterService) ActionListener(org.opensearch.action.ActionListener) TransportService(org.opensearch.transport.TransportService) Version(org.opensearch.Version) ExecutorService(java.util.concurrent.ExecutorService) SystemIndices(org.opensearch.indices.SystemIndices) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) TimeValue(org.opensearch.common.unit.TimeValue)

Example 4 with SystemIndices

use of org.opensearch.indices.SystemIndices in project OpenSearch by opensearch-project.

the class MetadataCreateIndexServiceTests method testIndexLifecycleNameSetting.

public void testIndexLifecycleNameSetting() {
    // see: https://github.com/opensearch-project/OpenSearch/issues/1019
    final Settings ilnSetting = Settings.builder().put("index.lifecycle.name", "dummy").build();
    withTemporaryClusterService(((clusterService, threadPool) -> {
        MetadataCreateIndexService checkerService = new MetadataCreateIndexService(Settings.EMPTY, clusterService, null, null, null, createTestShardLimitService(randomIntBetween(1, 1000), clusterService), new Environment(Settings.builder().put("path.home", "dummy").build(), null), new IndexScopedSettings(ilnSetting, Collections.emptySet()), threadPool, null, new SystemIndices(Collections.emptyMap()), true);
        final List<String> validationErrors = checkerService.getIndexSettingsValidationErrors(ilnSetting, true);
        assertThat(validationErrors.size(), is(1));
        assertThat(validationErrors.get(0), is("expected [index.lifecycle.name] to be private but it was not"));
    }));
}
Also used : ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) Arrays(java.util.Arrays) MetadataCreateIndexService.resolveAndValidateAliases(org.opensearch.cluster.metadata.MetadataCreateIndexService.resolveAndValidateAliases) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService) TestThreadPool(org.opensearch.threadpool.TestThreadPool) INDEX_NUMBER_OF_SHARDS_SETTING(org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING) Version(org.opensearch.Version) MetadataCreateIndexService.getIndexNumberOfRoutingShards(org.opensearch.cluster.metadata.MetadataCreateIndexService.getIndexNumberOfRoutingShards) Matchers.hasValue(org.hamcrest.Matchers.hasValue) INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING(org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING) Strings(org.opensearch.common.Strings) Collections.singletonList(java.util.Collections.singletonList) INDEX_SOFT_DELETES_SETTING(org.opensearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING) Alias(org.opensearch.action.admin.indices.alias.Alias) OpenSearchAllocationTestCase(org.opensearch.cluster.OpenSearchAllocationTestCase) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) IndexModule(org.opensearch.index.IndexModule) AllocationDeciders(org.opensearch.cluster.routing.allocation.decider.AllocationDeciders) TimeValue(org.opensearch.common.unit.TimeValue) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Index(org.opensearch.index.Index) MetadataCreateIndexService.parseV1Mappings(org.opensearch.cluster.metadata.MetadataCreateIndexService.parseV1Mappings) ExceptionsHelper(org.opensearch.ExceptionsHelper) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Stream(java.util.stream.Stream) SystemIndexDescriptor(org.opensearch.indices.SystemIndexDescriptor) Matchers.is(org.hamcrest.Matchers.is) Matchers.endsWith(org.hamcrest.Matchers.endsWith) MetadataCreateIndexService.aggregateIndexSettings(org.opensearch.cluster.metadata.MetadataCreateIndexService.aggregateIndexSettings) ThreadPool(org.opensearch.threadpool.ThreadPool) ArrayList(java.util.ArrayList) ClusterState(org.opensearch.cluster.ClusterState) LegacyESVersion(org.opensearch.LegacyESVersion) VersionUtils(org.opensearch.test.VersionUtils) INDEX_READ_ONLY_BLOCK(org.opensearch.cluster.metadata.IndexMetadata.INDEX_READ_ONLY_BLOCK) BiConsumer(java.util.function.BiConsumer) ClusterBlocks(org.opensearch.cluster.block.ClusterBlocks) TestGatewayAllocator(org.opensearch.test.gateway.TestGatewayAllocator) Before(org.junit.Before) Environment(org.opensearch.env.Environment) IOException(java.io.IOException) SystemIndices(org.opensearch.indices.SystemIndices) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ClusterService(org.opensearch.cluster.service.ClusterService) RoutingTable(org.opensearch.cluster.routing.RoutingTable) SETTING_NUMBER_OF_SHARDS(org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS) CreateIndexClusterStateUpdateRequest(org.opensearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest) InvalidAliasNameException(org.opensearch.indices.InvalidAliasNameException) SETTING_VERSION_CREATED(org.opensearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED) BiFunction(java.util.function.BiFunction) Matchers.hasKey(org.hamcrest.Matchers.hasKey) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MapperService(org.opensearch.index.mapper.MapperService) Collections.singleton(java.util.Collections.singleton) XContentFactory(org.opensearch.common.xcontent.XContentFactory) BalancedShardsAllocator(org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) SETTING_NUMBER_OF_REPLICAS(org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS) Collections.emptyList(java.util.Collections.emptyList) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Collection(java.util.Collection) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MetadataCreateIndexService.clusterStateCreateIndex(org.opensearch.cluster.metadata.MetadataCreateIndexService.clusterStateCreateIndex) SETTING_READ_ONLY(org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY) InvalidIndexNameException(org.opensearch.indices.InvalidIndexNameException) List(java.util.List) ShardLimitValidatorTests.createTestShardLimitService(org.opensearch.indices.ShardLimitValidatorTests.createTestShardLimitService) Matchers.equalTo(org.hamcrest.Matchers.equalTo) EmptyClusterInfoService(org.opensearch.cluster.EmptyClusterInfoService) IndexSettings(org.opensearch.index.IndexSettings) QueryShardContext(org.opensearch.index.query.QueryShardContext) ResourceAlreadyExistsException(org.opensearch.ResourceAlreadyExistsException) BigArrays(org.opensearch.common.util.BigArrays) ClusterServiceUtils(org.opensearch.test.ClusterServiceUtils) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) CompressedXContent(org.opensearch.common.compress.CompressedXContent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) ResizeType(org.opensearch.action.admin.indices.shrink.ResizeType) Setting(org.opensearch.common.settings.Setting) ShardLimitValidator(org.opensearch.indices.ShardLimitValidator) MaxRetryAllocationDecider(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) Matchers(org.hamcrest.Matchers) Consumer(java.util.function.Consumer) EmptySnapshotsInfoService(org.opensearch.snapshots.EmptySnapshotsInfoService) ClusterName(org.opensearch.cluster.ClusterName) Comparator(java.util.Comparator) Collections(java.util.Collections) MetadataCreateIndexService.buildIndexMetadata(org.opensearch.cluster.metadata.MetadataCreateIndexService.buildIndexMetadata) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) Environment(org.opensearch.env.Environment) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) SystemIndices(org.opensearch.indices.SystemIndices) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) Settings(org.opensearch.common.settings.Settings) MetadataCreateIndexService.aggregateIndexSettings(org.opensearch.cluster.metadata.MetadataCreateIndexService.aggregateIndexSettings) IndexSettings(org.opensearch.index.IndexSettings)

Example 5 with SystemIndices

use of org.opensearch.indices.SystemIndices in project OpenSearch by opensearch-project.

the class TransportGetAliasesActionTests method testDeprecationWarningEmittedWhenRequestingNonExistingAliasInSystemPattern.

public void testDeprecationWarningEmittedWhenRequestingNonExistingAliasInSystemPattern() {
    ClusterState state = systemIndexTestClusterState();
    SystemIndices systemIndices = new SystemIndices(Collections.singletonMap(this.getTestName(), Collections.singletonList(new SystemIndexDescriptor(".y", "an index that doesn't exist"))));
    GetAliasesRequest request = new GetAliasesRequest(".y");
    ImmutableOpenMap<String, List<AliasMetadata>> aliases = ImmutableOpenMap.<String, List<AliasMetadata>>builder().build();
    final String[] concreteIndices = {};
    assertEquals(state.metadata().findAliases(request, concreteIndices), aliases);
    ImmutableOpenMap<String, List<AliasMetadata>> result = TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, false, systemIndices);
    assertThat(result.size(), equalTo(0));
    assertWarnings("this request accesses aliases with names reserved for system indices: [.y], but in a future major version, direct" + "access to system indices and their aliases will not be allowed");
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) SystemIndexDescriptor(org.opensearch.indices.SystemIndexDescriptor) List(java.util.List) SystemIndices(org.opensearch.indices.SystemIndices)

Aggregations

SystemIndices (org.opensearch.indices.SystemIndices)17 ClusterService (org.opensearch.cluster.service.ClusterService)11 Index (org.opensearch.index.Index)9 ThreadPool (org.opensearch.threadpool.ThreadPool)9 ClusterState (org.opensearch.cluster.ClusterState)8 Settings (org.opensearch.common.settings.Settings)7 Environment (org.opensearch.env.Environment)7 IndicesService (org.opensearch.indices.IndicesService)7 Collections.emptyMap (java.util.Collections.emptyMap)6 ActionFilters (org.opensearch.action.support.ActionFilters)6 IndexingPressureService (org.opensearch.index.IndexingPressureService)6 TestThreadPool (org.opensearch.threadpool.TestThreadPool)6 ActionListener (org.opensearch.action.ActionListener)5 IndexAbstraction (org.opensearch.cluster.metadata.IndexAbstraction)5 IOException (java.io.IOException)4 Collections (java.util.Collections)4 HashSet (java.util.HashSet)4 ClusterName (org.opensearch.cluster.ClusterName)4 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)4 IndexNameExpressionResolver (org.opensearch.cluster.metadata.IndexNameExpressionResolver)4