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