Search in sources :

Example 81 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class FeatureAwareTests method testFeature.

public void testFeature() {
    final Version version = VersionUtils.randomVersion(random());
    final Version afterVersion = randomVersionBetween(random(), version, Version.CURRENT);
    final Custom custom = new RequiredFeatureCustom(version);
    // the feature is present
    final BytesStreamOutput out = new BytesStreamOutput();
    out.setVersion(afterVersion);
    assertTrue(custom.getRequiredFeature().isPresent());
    out.setFeatures(Collections.singleton(custom.getRequiredFeature().get()));
    assertTrue(FeatureAware.shouldSerialize(out, custom));
}
Also used : Version(org.opensearch.Version) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 82 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class ClusterStateTests method testSupersedes.

public void testSupersedes() {
    final Version version = Version.CURRENT;
    final DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), version);
    final DiscoveryNode node2 = new DiscoveryNode("node2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), version);
    final DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).add(node2).build();
    ClusterName name = ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY);
    ClusterState noMaster1 = ClusterState.builder(name).version(randomInt(5)).nodes(nodes).build();
    ClusterState noMaster2 = ClusterState.builder(name).version(randomInt(5)).nodes(nodes).build();
    ClusterState withMaster1a = ClusterState.builder(name).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes).masterNodeId(node1.getId())).build();
    ClusterState withMaster1b = ClusterState.builder(name).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes).masterNodeId(node1.getId())).build();
    ClusterState withMaster2 = ClusterState.builder(name).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes).masterNodeId(node2.getId())).build();
    // states with no master should never supersede anything
    assertFalse(noMaster1.supersedes(noMaster2));
    assertFalse(noMaster1.supersedes(withMaster1a));
    // states should never supersede states from another master
    assertFalse(withMaster1a.supersedes(withMaster2));
    assertFalse(withMaster1a.supersedes(noMaster1));
    // state from the same master compare by version
    assertThat(withMaster1a.supersedes(withMaster1b), equalTo(withMaster1a.version() > withMaster1b.version()));
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Version(org.opensearch.Version) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Example 83 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class MetadataCreateIndexServiceTests method testPrepareResizeIndexSettings.

public void testPrepareResizeIndexSettings() {
    final List<Version> versions = Arrays.asList(VersionUtils.randomVersion(random()), VersionUtils.randomVersion(random()));
    versions.sort(Comparator.comparingLong(l -> l.id));
    final Version version = versions.get(0);
    final Version upgraded = versions.get(1);
    final Settings.Builder indexSettingsBuilder = Settings.builder().put("index.version.created", version).put("index.version.upgraded", upgraded).put("index.similarity.default.type", "BM25").put("index.analysis.analyzer.default.tokenizer", "keyword").put("index.soft_deletes.enabled", "true");
    if (randomBoolean()) {
        indexSettingsBuilder.put("index.allocation.max_retries", randomIntBetween(1, 1000));
    }
    runPrepareResizeIndexSettingsTest(indexSettingsBuilder.build(), Settings.EMPTY, emptyList(), randomBoolean(), settings -> {
        assertThat("similarity settings must be copied", settings.get("index.similarity.default.type"), equalTo("BM25"));
        assertThat("analysis settings must be copied", settings.get("index.analysis.analyzer.default.tokenizer"), equalTo("keyword"));
        assertThat(settings.get("index.routing.allocation.initial_recovery._id"), equalTo("node1"));
        assertThat(settings.get("index.allocation.max_retries"), nullValue());
        assertThat(settings.getAsVersion("index.version.created", null), equalTo(version));
        assertThat(settings.getAsVersion("index.version.upgraded", null), equalTo(upgraded));
        assertThat(settings.get("index.soft_deletes.enabled"), equalTo("true"));
    });
}
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) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) 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 84 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class DiscoveryNodeFiltersTests method testIdOrNameMatch.

public void testIdOrNameMatch() {
    Settings settings = shuffleSettings(Settings.builder().put("xxx._id", "id1,blah").put("xxx.name", "blah,name2").build());
    DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings);
    final Version version = Version.CURRENT;
    DiscoveryNode node = new DiscoveryNode("name1", "id1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), version);
    assertThat(filters.match(node), equalTo(true));
    node = new DiscoveryNode("name2", "id2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), version);
    assertThat(filters.match(node), equalTo(true));
    node = new DiscoveryNode("name3", "id3", buildNewFakeTransportAddress(), emptyMap(), emptySet(), version);
    assertThat(filters.match(node), equalTo(false));
}
Also used : Version(org.opensearch.Version) Settings(org.opensearch.common.settings.Settings)

Example 85 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class MetadataIndexUpgradeServiceTests method testIsUpgraded.

public void testIsUpgraded() {
    MetadataIndexUpgradeService service = getMetadataIndexUpgradeService();
    IndexMetadata src = newIndexMeta("foo", Settings.builder().put("index.refresh_interval", "-200").build());
    assertFalse(service.isUpgraded(src));
    Version version = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), VersionUtils.getPreviousVersion());
    src = newIndexMeta("foo", Settings.builder().put(IndexMetadata.SETTING_VERSION_UPGRADED, version).build());
    assertFalse(service.isUpgraded(src));
    src = newIndexMeta("foo", Settings.builder().put(IndexMetadata.SETTING_VERSION_UPGRADED, Version.CURRENT).build());
    assertTrue(service.isUpgraded(src));
}
Also used : LegacyESVersion(org.opensearch.LegacyESVersion) Version(org.opensearch.Version)

Aggregations

Version (org.opensearch.Version)242 Settings (org.opensearch.common.settings.Settings)86 LegacyESVersion (org.opensearch.LegacyESVersion)84 ArrayList (java.util.ArrayList)59 IOException (java.io.IOException)54 List (java.util.List)54 Map (java.util.Map)50 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)42 Collections (java.util.Collections)39 HashMap (java.util.HashMap)38 ClusterState (org.opensearch.cluster.ClusterState)38 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)37 HashSet (java.util.HashSet)36 BytesReference (org.opensearch.common.bytes.BytesReference)36 TimeValue (org.opensearch.common.unit.TimeValue)36 Set (java.util.Set)35 Collectors (java.util.stream.Collectors)34 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)33 StreamInput (org.opensearch.common.io.stream.StreamInput)32 BytesArray (org.opensearch.common.bytes.BytesArray)30