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