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;
}
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));
}
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");
}
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));
}
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));
}));
}
Aggregations