Search in sources :

Example 1 with GetAliasesRequest

use of org.opensearch.action.admin.indices.alias.get.GetAliasesRequest in project OpenSearch by opensearch-project.

the class IndicesRequestConverters method getAlias.

static Request getAlias(GetAliasesRequest getAliasesRequest) {
    String[] indices = getAliasesRequest.indices() == null ? Strings.EMPTY_ARRAY : getAliasesRequest.indices();
    String[] aliases = getAliasesRequest.aliases() == null ? Strings.EMPTY_ARRAY : getAliasesRequest.aliases();
    String endpoint = RequestConverters.endpoint(indices, "_alias", aliases);
    Request request = new Request(HttpGet.METHOD_NAME, endpoint);
    RequestConverters.Params params = new RequestConverters.Params();
    params.withIndicesOptions(getAliasesRequest.indicesOptions());
    params.withLocal(getAliasesRequest.local());
    request.addParameters(params.asMap());
    return request;
}
Also used : UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) SimulateIndexTemplateRequest(org.opensearch.client.indices.SimulateIndexTemplateRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ComposableIndexTemplateExistRequest(org.opensearch.client.indices.ComposableIndexTemplateExistRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) GetComposableIndexTemplateRequest(org.opensearch.client.indices.GetComposableIndexTemplateRequest) DataStreamsStatsRequest(org.opensearch.client.indices.DataStreamsStatsRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) DeleteComposableIndexTemplateRequest(org.opensearch.client.indices.DeleteComposableIndexTemplateRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest)

Example 2 with GetAliasesRequest

use of org.opensearch.action.admin.indices.alias.get.GetAliasesRequest in project OpenSearch by opensearch-project.

the class IndicesRequestConvertersTests method testExistsAlias.

public void testExistsAlias() {
    GetAliasesRequest getAliasesRequest = new GetAliasesRequest();
    String[] indices = OpenSearchTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
    getAliasesRequest.indices(indices);
    // the HEAD endpoint requires at least an alias or an index
    boolean hasIndices = indices != null && indices.length > 0;
    String[] aliases;
    if (hasIndices) {
        aliases = OpenSearchTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
    } else {
        aliases = RequestConvertersTests.randomIndicesNames(1, 5);
    }
    getAliasesRequest.aliases(aliases);
    Map<String, String> expectedParams = new HashMap<>();
    RequestConvertersTests.setRandomLocal(getAliasesRequest::local, expectedParams);
    RequestConvertersTests.setRandomIndicesOptions(getAliasesRequest::indicesOptions, getAliasesRequest::indicesOptions, expectedParams);
    Request request = IndicesRequestConverters.existsAlias(getAliasesRequest);
    StringJoiner expectedEndpoint = new StringJoiner("/", "/", "");
    if (indices != null && indices.length > 0) {
        expectedEndpoint.add(String.join(",", indices));
    }
    expectedEndpoint.add("_alias");
    if (aliases != null && aliases.length > 0) {
        expectedEndpoint.add(String.join(",", aliases));
    }
    Assert.assertEquals(HttpHead.METHOD_NAME, request.getMethod());
    Assert.assertEquals(expectedEndpoint.toString(), request.getEndpoint());
    Assert.assertEquals(expectedParams, request.getParameters());
    Assert.assertNull(request.getEntity());
}
Also used : HashMap(java.util.HashMap) UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) StringJoiner(java.util.StringJoiner)

Example 3 with GetAliasesRequest

use of org.opensearch.action.admin.indices.alias.get.GetAliasesRequest in project OpenSearch by opensearch-project.

the class ValidateIndicesAliasesRequestIT method testSomeAllowed.

public void testSomeAllowed() {
    final Settings fooIndexSettings = Settings.builder().putList(IndicesAliasesPlugin.ALLOWED_ORIGINS_SETTING.getKey(), Collections.singletonList("foo_allowed")).build();
    createIndex("foo", fooIndexSettings);
    final Settings barIndexSettings = Settings.builder().putList(IndicesAliasesPlugin.ALLOWED_ORIGINS_SETTING.getKey(), Collections.singletonList("bar_allowed")).build();
    createIndex("bar", barIndexSettings);
    final String origin = randomFrom("foo_allowed", "bar_allowed");
    final IndicesAliasesRequest request = new IndicesAliasesRequest().origin(origin);
    request.addAliasAction(IndicesAliasesRequest.AliasActions.add().index("foo").alias("alias"));
    request.addAliasAction(IndicesAliasesRequest.AliasActions.add().index("bar").alias("alias"));
    final Exception e = expectThrows(IllegalStateException.class, () -> client().admin().indices().aliases(request).actionGet());
    final String index = "foo_allowed".equals(origin) ? "bar" : "foo";
    assertThat(e, hasToString(containsString("origin [" + origin + "] not allowed for index [" + index + "]")));
    final AliasesExistResponse response = client().admin().indices().aliasesExist(new GetAliasesRequest("alias")).actionGet();
    assertFalse(response.exists());
}
Also used : AliasesExistResponse(org.opensearch.action.admin.indices.alias.exists.AliasesExistResponse) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings)

Example 4 with GetAliasesRequest

use of org.opensearch.action.admin.indices.alias.get.GetAliasesRequest in project OpenSearch by opensearch-project.

the class ValidateIndicesAliasesRequestIT method testAllowed.

public void testAllowed() {
    final Settings settings = Settings.builder().putList(IndicesAliasesPlugin.ALLOWED_ORIGINS_SETTING.getKey(), Collections.singletonList("allowed")).build();
    createIndex("index", settings);
    final IndicesAliasesRequest request = new IndicesAliasesRequest().origin("allowed");
    request.addAliasAction(IndicesAliasesRequest.AliasActions.add().index("index").alias("alias"));
    assertAcked(client().admin().indices().aliases(request).actionGet());
    final GetAliasesResponse response = client().admin().indices().getAliases(new GetAliasesRequest("alias")).actionGet();
    assertThat(response.getAliases().keys().size(), equalTo(1));
    assertThat(response.getAliases().keys().iterator().next().value, equalTo("index"));
    final List<AliasMetadata> aliasMetadata = response.getAliases().get("index");
    assertThat(aliasMetadata, hasSize(1));
    assertThat(aliasMetadata.get(0).alias(), equalTo("alias"));
}
Also used : AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) GetAliasesResponse(org.opensearch.action.admin.indices.alias.get.GetAliasesResponse) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) Settings(org.opensearch.common.settings.Settings)

Example 5 with GetAliasesRequest

use of org.opensearch.action.admin.indices.alias.get.GetAliasesRequest in project OpenSearch by opensearch-project.

the class MetadataTests method testFindAliasWithExclusionAndOverride.

public void testFindAliasWithExclusionAndOverride() {
    Metadata metadata = Metadata.builder().put(IndexMetadata.builder("index").settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)).numberOfShards(1).numberOfReplicas(0).putAlias(AliasMetadata.builder("aa").build()).putAlias(AliasMetadata.builder("ab").build()).putAlias(AliasMetadata.builder("bb").build())).build();
    List<AliasMetadata> aliases = metadata.findAliases(new GetAliasesRequest().aliases("a*", "-*b", "b*"), new String[] { "index" }).get("index");
    assertThat(aliases.size(), equalTo(2));
    assertThat(aliases.get(0).alias(), equalTo("aa"));
    assertThat(aliases.get(1).alias(), equalTo("bb"));
}
Also used : CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

GetAliasesRequest (org.opensearch.action.admin.indices.alias.get.GetAliasesRequest)14 IndicesAliasesRequest (org.opensearch.action.admin.indices.alias.IndicesAliasesRequest)7 ClearIndicesCacheRequest (org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)6 DeleteIndexRequest (org.opensearch.action.admin.indices.delete.DeleteIndexRequest)6 FlushRequest (org.opensearch.action.admin.indices.flush.FlushRequest)6 ForceMergeRequest (org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest)6 OpenIndexRequest (org.opensearch.action.admin.indices.open.OpenIndexRequest)6 RefreshRequest (org.opensearch.action.admin.indices.refresh.RefreshRequest)6 GetSettingsRequest (org.opensearch.action.admin.indices.settings.get.GetSettingsRequest)6 UpdateSettingsRequest (org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest)6 DeleteIndexTemplateRequest (org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)6 ValidateQueryRequest (org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest)6 AnalyzeRequest (org.opensearch.client.indices.AnalyzeRequest)6 CloseIndexRequest (org.opensearch.client.indices.CloseIndexRequest)6 CreateDataStreamRequest (org.opensearch.client.indices.CreateDataStreamRequest)6 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)6 DeleteAliasRequest (org.opensearch.client.indices.DeleteAliasRequest)6 DeleteDataStreamRequest (org.opensearch.client.indices.DeleteDataStreamRequest)6 GetDataStreamRequest (org.opensearch.client.indices.GetDataStreamRequest)6 GetFieldMappingsRequest (org.opensearch.client.indices.GetFieldMappingsRequest)6