Search in sources :

Example 1 with SystemIndexDescriptor

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

the class MetadataCreateIndexService method validateDotIndex.

/**
 * Validates (if this index has a dot-prefixed name) whether it follows the rules for dot-prefixed indices.
 * @param index The name of the index in question
 * @param isHidden Whether or not this is a hidden index
 */
public boolean validateDotIndex(String index, @Nullable Boolean isHidden) {
    boolean isSystem = false;
    if (index.charAt(0) == '.') {
        SystemIndexDescriptor matchingDescriptor = systemIndices.findMatchingDescriptor(index);
        if (matchingDescriptor != null) {
            logger.trace("index [{}] is a system index because it matches index pattern [{}] with description [{}]", index, matchingDescriptor.getIndexPattern(), matchingDescriptor.getDescription());
            isSystem = true;
        } else if (isHidden) {
            logger.trace("index [{}] is a hidden index", index);
        } else {
            DEPRECATION_LOGGER.deprecate("index_name_starts_with_dot", "index name [{}] starts with a dot '.', in the next major version, index names " + "starting with a dot are reserved for hidden indices and system indices", index);
        }
    }
    return isSystem;
}
Also used : SystemIndexDescriptor(org.opensearch.indices.SystemIndexDescriptor)

Example 2 with SystemIndexDescriptor

use of org.opensearch.indices.SystemIndexDescriptor 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 SystemIndexDescriptor

use of org.opensearch.indices.SystemIndexDescriptor 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)

Example 4 with SystemIndexDescriptor

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

the class TransportBulkActionTests method testIncludesSystem.

public void testIncludesSystem() {
    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(org.opensearch.common.collect.Map.of("plugin", org.opensearch.common.collect.List.of(new SystemIndexDescriptor(".test", ""))));
    List<String> onlySystem = org.opensearch.common.collect.List.of(".foo", ".bar");
    assertTrue(bulkAction.includesSystem(buildBulkRequest(onlySystem), indicesLookup, systemIndices));
    onlySystem = org.opensearch.common.collect.List.of(".foo", ".bar", ".test");
    assertTrue(bulkAction.includesSystem(buildBulkRequest(onlySystem), indicesLookup, systemIndices));
    List<String> nonSystem = org.opensearch.common.collect.List.of("foo", "bar");
    assertFalse(bulkAction.includesSystem(buildBulkRequest(nonSystem), indicesLookup, systemIndices));
    List<String> mixed = org.opensearch.common.collect.List.of(".foo", ".test", "other");
    assertTrue(bulkAction.includesSystem(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 5 with SystemIndexDescriptor

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

the class MetadataCreateIndexServiceTests method testValidateDotIndex.

public void testValidateDotIndex() {
    List<SystemIndexDescriptor> systemIndexDescriptors = new ArrayList<>();
    systemIndexDescriptors.add(new SystemIndexDescriptor(".test", "test"));
    systemIndexDescriptors.add(new SystemIndexDescriptor(".test3", "test"));
    systemIndexDescriptors.add(new SystemIndexDescriptor(".pattern-test*", "test-1"));
    withTemporaryClusterService(((clusterService, threadPool) -> {
        MetadataCreateIndexService checkerService = new MetadataCreateIndexService(Settings.EMPTY, clusterService, null, null, null, createTestShardLimitService(randomIntBetween(1, 1000), clusterService), null, null, threadPool, null, new SystemIndices(Collections.singletonMap("foo", systemIndexDescriptors)), false);
        // Check deprecations
        assertFalse(checkerService.validateDotIndex(".test2", false));
        assertWarnings("index name [.test2] starts with a dot '.', in the next major version, index " + "names starting with a dot are reserved for hidden indices and system indices");
        // Check non-system hidden indices don't trigger a warning
        assertFalse(checkerService.validateDotIndex(".test2", true));
        // Check NO deprecation warnings if we give the index name
        assertTrue(checkerService.validateDotIndex(".test", false));
        assertTrue(checkerService.validateDotIndex(".test3", false));
        // Check that patterns with wildcards work
        assertTrue(checkerService.validateDotIndex(".pattern-test", false));
        assertTrue(checkerService.validateDotIndex(".pattern-test-with-suffix", false));
        assertTrue(checkerService.validateDotIndex(".pattern-test-other-suffix", false));
    }));
}
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) SystemIndexDescriptor(org.opensearch.indices.SystemIndexDescriptor) ArrayList(java.util.ArrayList) SystemIndices(org.opensearch.indices.SystemIndices)

Aggregations

SystemIndexDescriptor (org.opensearch.indices.SystemIndexDescriptor)5 SystemIndices (org.opensearch.indices.SystemIndices)4 Settings (org.opensearch.common.settings.Settings)3 List (java.util.List)2 TreeMap (java.util.TreeMap)2 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singleton (java.util.Collections.singleton)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1