Search in sources :

Example 1 with Settings

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

the class ClusterClientIT method testClusterGetSettings.

public void testClusterGetSettings() throws IOException {
    final String transientSettingKey = RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
    final int transientSettingValue = 10;
    final String persistentSettingKey = EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey();
    final String persistentSettingValue = EnableAllocationDecider.Allocation.NONE.name();
    Settings transientSettings = Settings.builder().put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES).build();
    Settings persistentSettings = Settings.builder().put(persistentSettingKey, persistentSettingValue).build();
    clusterUpdateSettings(persistentSettings, transientSettings);
    ClusterGetSettingsRequest request = new ClusterGetSettingsRequest();
    ClusterGetSettingsResponse response = execute(request, highLevelClient().cluster()::getSettings, highLevelClient().cluster()::getSettingsAsync);
    assertEquals(persistentSettings, response.getPersistentSettings());
    assertEquals(transientSettings, response.getTransientSettings());
    assertEquals(0, response.getDefaultSettings().size());
}
Also used : ClusterGetSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterGetSettingsResponse) ClusterGetSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) Settings(org.opensearch.common.settings.Settings)

Example 2 with Settings

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

the class IndicesClientIT method testGetSettingsWithDefaultsFiltered.

public void testGetSettingsWithDefaultsFiltered() throws IOException {
    String indexName = "get_settings_index";
    Settings basicSettings = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build();
    createIndex(indexName, basicSettings);
    GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices(indexName).names("index.refresh_interval").includeDefaults(true);
    GetSettingsResponse getSettingsResponse = execute(getSettingsRequest, highLevelClient().indices()::getSettings, highLevelClient().indices()::getSettingsAsync);
    assertNull(getSettingsResponse.getSetting(indexName, "index.number_of_replicas"));
    assertNull(getSettingsResponse.getSetting(indexName, "index.number_of_shards"));
    assertEquals(0, getSettingsResponse.getIndexToSettings().get("get_settings_index").size());
    assertEquals(1, getSettingsResponse.getIndexToDefaultSettings().get("get_settings_index").size());
}
Also used : GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 3 with Settings

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

the class IndicesClientIT method testSplit.

@SuppressWarnings("unchecked")
public void testSplit() throws IOException {
    createIndex("source", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).put("index.number_of_routing_shards", 4).build());
    updateIndexSettings("source", Settings.builder().put("index.blocks.write", true));
    ResizeRequest resizeRequest = new ResizeRequest("target", "source");
    resizeRequest.setResizeType(ResizeType.SPLIT);
    Settings targetSettings = Settings.builder().put("index.number_of_shards", 4).put("index.number_of_replicas", 0).build();
    resizeRequest.setTargetIndex(new org.opensearch.action.admin.indices.create.CreateIndexRequest("target").settings(targetSettings).alias(new Alias("alias")));
    ResizeResponse resizeResponse = execute(resizeRequest, highLevelClient().indices()::split, highLevelClient().indices()::splitAsync);
    assertTrue(resizeResponse.isAcknowledged());
    assertTrue(resizeResponse.isShardsAcknowledged());
    Map<String, Object> getIndexResponse = getAsMap("target");
    Map<String, Object> indexSettings = (Map<String, Object>) XContentMapValues.extractValue("target.settings.index", getIndexResponse);
    assertNotNull(indexSettings);
    assertEquals("4", indexSettings.get("number_of_shards"));
    assertEquals("0", indexSettings.get("number_of_replicas"));
    Map<String, Object> aliasData = (Map<String, Object>) XContentMapValues.extractValue("target.aliases.alias", getIndexResponse);
    assertNotNull(aliasData);
}
Also used : ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) Alias(org.opensearch.action.admin.indices.alias.Alias) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) HashMap(java.util.HashMap) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 4 with Settings

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

the class IndicesClientIT method testGetSettings.

public void testGetSettings() throws IOException {
    String indexName = "get_settings_index";
    Settings basicSettings = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build();
    createIndex(indexName, basicSettings);
    GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices(indexName);
    GetSettingsResponse getSettingsResponse = execute(getSettingsRequest, highLevelClient().indices()::getSettings, highLevelClient().indices()::getSettingsAsync);
    assertNull(getSettingsResponse.getSetting(indexName, "index.refresh_interval"));
    assertEquals("1", getSettingsResponse.getSetting(indexName, "index.number_of_shards"));
    updateIndexSettings(indexName, Settings.builder().put("refresh_interval", "30s"));
    GetSettingsResponse updatedResponse = execute(getSettingsRequest, highLevelClient().indices()::getSettings, highLevelClient().indices()::getSettingsAsync);
    assertEquals("30s", updatedResponse.getSetting(indexName, "index.refresh_interval"));
}
Also used : GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 5 with Settings

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

the class IndicesClientIT method testSimulateIndexTemplate.

public void testSimulateIndexTemplate() throws Exception {
    String templateName = "my-template";
    Settings settings = Settings.builder().put("index.number_of_shards", 1).build();
    CompressedXContent mappings = new CompressedXContent("{\"properties\":{\"host_name\":{\"type\":\"keyword\"}}}");
    AliasMetadata alias = AliasMetadata.builder("alias").writeIndex(true).build();
    Template template = new Template(settings, mappings, org.opensearch.common.collect.Map.of("alias", alias));
    List<String> pattern = org.opensearch.common.collect.List.of("pattern");
    ComposableIndexTemplate indexTemplate = new ComposableIndexTemplate(pattern, template, Collections.emptyList(), 1L, 1L, new HashMap<>(), null);
    PutComposableIndexTemplateRequest putComposableIndexTemplateRequest = new PutComposableIndexTemplateRequest().name(templateName).create(true).indexTemplate(indexTemplate);
    AcknowledgedResponse response = execute(putComposableIndexTemplateRequest, highLevelClient().indices()::putIndexTemplate, highLevelClient().indices()::putIndexTemplateAsync);
    assertThat(response.isAcknowledged(), equalTo(true));
    SimulateIndexTemplateRequest simulateIndexTemplateRequest = new SimulateIndexTemplateRequest("pattern");
    AliasMetadata simulationAlias = AliasMetadata.builder("simulation-alias").writeIndex(true).build();
    ComposableIndexTemplate simulationTemplate = new ComposableIndexTemplate(pattern, new Template(null, null, org.opensearch.common.collect.Map.of("simulation-alias", simulationAlias)), Collections.emptyList(), 2L, 1L, new HashMap<>(), null);
    PutComposableIndexTemplateRequest newIndexTemplateReq = new PutComposableIndexTemplateRequest().name("used-for-simulation").create(true).indexTemplate(indexTemplate);
    newIndexTemplateReq.indexTemplate(simulationTemplate);
    simulateIndexTemplateRequest.indexTemplateV2Request(newIndexTemplateReq);
    SimulateIndexTemplateResponse simulateResponse = execute(simulateIndexTemplateRequest, highLevelClient().indices()::simulateIndexTemplate, highLevelClient().indices()::simulateIndexTemplateAsync);
    Map<String, AliasMetadata> aliases = simulateResponse.resolvedTemplate().aliases();
    assertThat(aliases, is(notNullValue()));
    assertThat("the template we provided for the simulation has a higher priority than the one in the system", aliases.get("simulation-alias"), is(notNullValue()));
    assertThat(aliases.get("simulation-alias").getAlias(), is("simulation-alias"));
    assertThat("existing template overlaps the higher priority template we provided for the simulation", simulateResponse.overlappingTemplates().get("my-template").get(0), is("pattern"));
}
Also used : ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) Template(org.opensearch.cluster.metadata.Template) SimulateIndexTemplateRequest(org.opensearch.client.indices.SimulateIndexTemplateRequest) CompressedXContent(org.opensearch.common.compress.CompressedXContent) SimulateIndexTemplateResponse(org.opensearch.client.indices.SimulateIndexTemplateResponse) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Aggregations

Settings (org.opensearch.common.settings.Settings)1293 IndexSettings (org.opensearch.index.IndexSettings)304 Matchers.containsString (org.hamcrest.Matchers.containsString)221 ClusterSettings (org.opensearch.common.settings.ClusterSettings)196 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)158 ClusterState (org.opensearch.cluster.ClusterState)150 IOException (java.io.IOException)127 ArrayList (java.util.ArrayList)127 Version (org.opensearch.Version)122 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)121 List (java.util.List)108 Index (org.opensearch.index.Index)106 Path (java.nio.file.Path)104 Map (java.util.Map)97 HashMap (java.util.HashMap)95 HashSet (java.util.HashSet)86 ShardId (org.opensearch.index.shard.ShardId)86 IndexScopedSettings (org.opensearch.common.settings.IndexScopedSettings)83 Environment (org.opensearch.env.Environment)82 ShardRouting (org.opensearch.cluster.routing.ShardRouting)71