Search in sources :

Example 76 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class OverrideNodeVersionCommandTests method createNodePaths.

@Before
public void createNodePaths() throws IOException {
    final Settings settings = buildEnvSettings(Settings.EMPTY);
    environment = TestEnvironment.newEnvironment(settings);
    try (NodeEnvironment nodeEnvironment = new NodeEnvironment(settings, environment)) {
        nodePaths = nodeEnvironment.nodeDataPaths();
        nodeId = nodeEnvironment.nodeId();
        try (PersistedClusterStateService.Writer writer = new PersistedClusterStateService(nodePaths, nodeId, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L).createWriter()) {
            writer.writeFullStateAndCommit(1L, ClusterState.builder(ClusterName.DEFAULT).metadata(Metadata.builder().persistentSettings(Settings.builder().put(Metadata.SETTING_READ_ONLY_SETTING.getKey(), true).build()).build()).build());
        }
    }
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) PersistedClusterStateService(org.opensearch.gateway.PersistedClusterStateService) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before)

Example 77 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class ClusterStateUpdatersTests method runUpgradeSettings.

private void runUpgradeSettings(final BiConsumer<Metadata.Builder, Settings> applySettingsToBuilder, final Function<Metadata, Settings> metadataSettings) {
    final Setting<String> oldSetting = Setting.simpleString("foo.old", Setting.Property.Dynamic, Setting.Property.NodeScope);
    final Setting<String> newSetting = Setting.simpleString("foo.new", Setting.Property.Dynamic, Setting.Property.NodeScope);
    final Set<Setting<?>> settingsSet = Stream.concat(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), Stream.of(oldSetting, newSetting)).collect(Collectors.toSet());
    final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, settingsSet, Collections.singleton(new SettingUpgrader<String>() {

        @Override
        public Setting<String> getSetting() {
            return oldSetting;
        }

        @Override
        public String getKey(final String key) {
            return "foo.new";
        }

        @Override
        public String getValue(final String value) {
            return "new." + value;
        }
    }));
    final ClusterService clusterService = new ClusterService(Settings.EMPTY, clusterSettings, null);
    final Metadata.Builder builder = Metadata.builder();
    final Settings settings = Settings.builder().put("foo.old", randomAlphaOfLength(8)).build();
    applySettingsToBuilder.accept(builder, settings);
    final ClusterState initialState = ClusterState.builder(clusterService.getClusterName()).metadata(builder.build()).build();
    final ClusterState state = upgradeAndArchiveUnknownOrInvalidSettings(initialState, clusterService.getClusterSettings());
    assertFalse(oldSetting.exists(metadataSettings.apply(state.metadata())));
    assertTrue(newSetting.exists(metadataSettings.apply(state.metadata())));
    assertThat(newSetting.get(metadataSettings.apply(state.metadata())), equalTo("new." + oldSetting.get(settings)));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ClusterService(org.opensearch.cluster.service.ClusterService) Setting(org.opensearch.common.settings.Setting) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) SettingUpgrader(org.opensearch.common.settings.SettingUpgrader) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) ClusterStateUpdaters.upgradeAndArchiveUnknownOrInvalidSettings(org.opensearch.gateway.ClusterStateUpdaters.upgradeAndArchiveUnknownOrInvalidSettings)

Example 78 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class RemoveCorruptedShardDataCommandTests method setup.

@Before
public void setup() throws IOException {
    shardId = new ShardId("index0", UUIDs.randomBase64UUID(), 0);
    final String nodeId = randomAlphaOfLength(10);
    routing = TestShardRouting.newShardRouting(shardId, nodeId, true, ShardRoutingState.INITIALIZING, RecoverySource.EmptyStoreRecoverySource.INSTANCE);
    final Path dataDir = createTempDir();
    environment = TestEnvironment.newEnvironment(Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), dataDir).putList(Environment.PATH_DATA_SETTING.getKey(), dataDir.toAbsolutePath().toString()).build());
    // create same directory structure as prod does
    final Path path = NodeEnvironment.resolveNodePath(dataDir, 0);
    Files.createDirectories(path);
    dataPaths = new Path[] { path };
    final Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(MergePolicyConfig.INDEX_MERGE_ENABLED, false).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetadata.SETTING_INDEX_UUID, shardId.getIndex().getUUID()).build();
    final NodeEnvironment.NodePath nodePath = new NodeEnvironment.NodePath(path);
    shardPath = new ShardPath(false, nodePath.resolve(shardId), nodePath.resolve(shardId), shardId);
    final IndexMetadata.Builder metadata = IndexMetadata.builder(routing.getIndexName()).settings(settings).primaryTerm(0, randomIntBetween(1, 100)).putMapping("{ \"properties\": {} }");
    indexMetadata = metadata.build();
    clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(Metadata.builder().put(indexMetadata, false).build()).build();
    try (NodeEnvironment.NodeLock lock = new NodeEnvironment.NodeLock(0, logger, environment, Files::exists)) {
        final Path[] dataPaths = Arrays.stream(lock.getNodePaths()).filter(Objects::nonNull).map(p -> p.path).toArray(Path[]::new);
        try (PersistedClusterStateService.Writer writer = new PersistedClusterStateService(dataPaths, nodeId, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L).createWriter()) {
            writer.writeFullStateAndCommit(1L, clusterState);
        }
    }
    indexShard = newStartedShard(p -> newShard(routing, shardPath, indexMetadata, null, null, new InternalEngineFactory(), new EngineConfigFactory(new IndexSettings(indexMetadata, settings)), () -> {
    }, RetentionLeaseSyncer.EMPTY, EMPTY_EVENT_LISTENER), true);
    translogPath = shardPath.resolveTranslog();
    indexPath = shardPath.resolveIndex();
}
Also used : Path(java.nio.file.Path) EngineException(org.opensearch.index.engine.EngineException) Arrays(java.util.Arrays) TranslogCorruptedException(org.opensearch.index.translog.TranslogCorruptedException) Matchers.either(org.hamcrest.Matchers.either) MockTerminal(org.opensearch.cli.MockTerminal) Metadata(org.opensearch.cluster.metadata.Metadata) TRUNCATE_CLEAN_TRANSLOG_FLAG(org.opensearch.index.shard.RemoveCorruptedShardDataCommand.TRUNCATE_CLEAN_TRANSLOG_FLAG) CheckedFunction(org.opensearch.common.CheckedFunction) Version(org.opensearch.Version) OpenSearchException(org.opensearch.OpenSearchException) BaseDirectoryWrapper(org.apache.lucene.tests.store.BaseDirectoryWrapper) Matcher(java.util.regex.Matcher) OptionParser(joptsimple.OptionParser) DummyShardLock(org.opensearch.test.DummyShardLock) Path(java.nio.file.Path) OptionSet(joptsimple.OptionSet) NodeEnvironment(org.opensearch.env.NodeEnvironment) Matchers.allOf(org.hamcrest.Matchers.allOf) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) Store(org.opensearch.index.store.Store) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Objects(java.util.Objects) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) EngineConfigFactory(org.opensearch.index.engine.EngineConfigFactory) Matchers.equalTo(org.hamcrest.Matchers.equalTo) IndexSettings(org.opensearch.index.IndexSettings) Matchers.is(org.hamcrest.Matchers.is) ShardRoutingHelper(org.opensearch.cluster.routing.ShardRoutingHelper) Pattern(java.util.regex.Pattern) BigArrays(org.opensearch.common.util.BigArrays) Matchers.containsString(org.hamcrest.Matchers.containsString) TestEnvironment(org.opensearch.env.TestEnvironment) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) RecoverySource(org.opensearch.cluster.routing.RecoverySource) PersistedClusterStateService(org.opensearch.gateway.PersistedClusterStateService) ClusterState(org.opensearch.cluster.ClusterState) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) UUIDs(org.opensearch.common.UUIDs) ClusterSettings(org.opensearch.common.settings.ClusterSettings) CorruptionUtils(org.opensearch.test.CorruptionUtils) Before(org.junit.Before) Environment(org.opensearch.env.Environment) InternalEngineFactory(org.opensearch.index.engine.InternalEngineFactory) Terminal(org.opensearch.cli.Terminal) Files(java.nio.file.Files) TestTranslog(org.opensearch.index.translog.TestTranslog) IOException(java.io.IOException) ShardRouting(org.opensearch.cluster.routing.ShardRouting) TestShardRouting(org.opensearch.cluster.routing.TestShardRouting) ClusterName(org.opensearch.cluster.ClusterName) MergePolicyConfig(org.opensearch.index.MergePolicyConfig) RetentionLeaseSyncer(org.opensearch.index.seqno.RetentionLeaseSyncer) ClusterSettings(org.opensearch.common.settings.ClusterSettings) NodeEnvironment(org.opensearch.env.NodeEnvironment) IndexSettings(org.opensearch.index.IndexSettings) Matchers.containsString(org.hamcrest.Matchers.containsString) EngineConfigFactory(org.opensearch.index.engine.EngineConfigFactory) InternalEngineFactory(org.opensearch.index.engine.InternalEngineFactory) Objects(java.util.Objects) PersistedClusterStateService(org.opensearch.gateway.PersistedClusterStateService) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) Files(java.nio.file.Files) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before)

Example 79 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class MockGatewayMetaState method start.

public void start(Settings settings, NodeEnvironment nodeEnvironment, NamedXContentRegistry xContentRegistry) {
    final TransportService transportService = mock(TransportService.class);
    when(transportService.getThreadPool()).thenReturn(mock(ThreadPool.class));
    final ClusterService clusterService = mock(ClusterService.class);
    when(clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    final MetaStateService metaStateService = mock(MetaStateService.class);
    try {
        when(metaStateService.loadFullState()).thenReturn(new Tuple<>(Manifest.empty(), Metadata.builder().build()));
    } catch (IOException e) {
        throw new AssertionError(e);
    }
    start(settings, transportService, clusterService, metaStateService, null, null, new PersistedClusterStateService(nodeEnvironment, xContentRegistry, bigArrays, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L));
}
Also used : ClusterService(org.opensearch.cluster.service.ClusterService) ClusterSettings(org.opensearch.common.settings.ClusterSettings) TransportService(org.opensearch.transport.TransportService) ThreadPool(org.opensearch.threadpool.ThreadPool) IOException(java.io.IOException)

Example 80 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class NoMasterBlockServiceTests method createService.

private void createService(Settings settings) {
    clusterSettings = new ClusterSettings(settings, BUILT_IN_CLUSTER_SETTINGS);
    noClusterManagerBlockService = new NoMasterBlockService(settings, clusterSettings);
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings)

Aggregations

ClusterSettings (org.opensearch.common.settings.ClusterSettings)224 Settings (org.opensearch.common.settings.Settings)140 ClusterState (org.opensearch.cluster.ClusterState)73 ClusterService (org.opensearch.cluster.service.ClusterService)68 HashSet (java.util.HashSet)46 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)39 Metadata (org.opensearch.cluster.metadata.Metadata)38 Matchers.containsString (org.hamcrest.Matchers.containsString)37 Before (org.junit.Before)33 ArrayList (java.util.ArrayList)32 ClusterName (org.opensearch.cluster.ClusterName)32 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)31 ThreadPool (org.opensearch.threadpool.ThreadPool)30 AtomicReference (java.util.concurrent.atomic.AtomicReference)26 RoutingTable (org.opensearch.cluster.routing.RoutingTable)26 TestThreadPool (org.opensearch.threadpool.TestThreadPool)26 Setting (org.opensearch.common.settings.Setting)23 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)23 ActionListener (org.opensearch.action.ActionListener)20 IOException (java.io.IOException)19