Search in sources :

Example 1 with AliasActions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.

the class AliasActionsTests method testEmptyIndex.

public void testEmptyIndex() {
    Exception e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).index(null));
    assertEquals("[index] can't be empty string", e.getMessage());
    e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).index(""));
    assertEquals("[index] can't be empty string", e.getMessage());
    e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).indices((String[]) null));
    assertEquals("[indices] can't be empty", e.getMessage());
    e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).indices(new String[0]));
    assertEquals("[indices] can't be empty", e.getMessage());
    e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).indices("test", null));
    assertEquals("[indices] can't contain empty string", e.getMessage());
    e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(randomFrom(AliasActions.Type.values())).indices("test", ""));
    assertEquals("[indices] can't contain empty string", e.getMessage());
}
Also used : ParsingException(org.elasticsearch.common.ParsingException) IOException(java.io.IOException) AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)

Example 2 with AliasActions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.

the class AliasActionsTests method testParseRemoveIndex.

public void testParseRemoveIndex() throws IOException {
    String[] indices = randomBoolean() ? new String[] { randomAsciiOfLength(5) } : generateRandomStringArray(10, 5, false, false);
    XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
    b.startObject();
    {
        b.startObject("remove_index");
        {
            if (indices.length > 1 || randomBoolean()) {
                b.array("indices", indices);
            } else {
                b.field("index", indices[0]);
            }
        }
        b.endObject();
    }
    b.endObject();
    b = shuffleXContent(b);
    try (XContentParser parser = createParser(b)) {
        AliasActions action = AliasActions.PARSER.apply(parser, null);
        assertEquals(AliasActions.Type.REMOVE_INDEX, action.actionType());
        assertArrayEquals(indices, action.indices());
        assertThat(action.aliases(), arrayWithSize(0));
    }
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)

Example 3 with AliasActions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.

the class AliasActionsTests method testParseAddDefaultRouting.

public void testParseAddDefaultRouting() throws IOException {
    String index = randomAsciiOfLength(5);
    String alias = randomAsciiOfLength(5);
    Object searchRouting = randomRouting();
    Object indexRouting = randomRouting();
    XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
    b.startObject();
    {
        b.startObject("add");
        {
            b.field("index", index);
            b.field("alias", alias);
            if (randomBoolean()) {
                b.field("routing", searchRouting);
                b.field("index_routing", indexRouting);
            } else {
                b.field("search_routing", searchRouting);
                b.field("routing", indexRouting);
            }
        }
        b.endObject();
    }
    b.endObject();
    b = shuffleXContent(b);
    try (XContentParser parser = createParser(b)) {
        AliasActions action = AliasActions.PARSER.apply(parser, null);
        assertEquals(AliasActions.Type.ADD, action.actionType());
        assertThat(action.indices(), arrayContaining(index));
        assertThat(action.aliases(), arrayContaining(alias));
        assertEquals(searchRouting.toString(), action.searchRouting());
        assertEquals(indexRouting.toString(), action.indexRouting());
    }
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)

Example 4 with AliasActions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.

the class AliasActionsTests method testEmptyAlias.

public void testEmptyAlias() {
    AliasActions.Type type = randomValueOtherThan(AliasActions.Type.REMOVE_INDEX, () -> randomFrom(AliasActions.Type.values()));
    Exception e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).alias(null));
    assertEquals("[alias] can't be empty string", e.getMessage());
    e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).alias(""));
    assertEquals("[alias] can't be empty string", e.getMessage());
    e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases((String[]) null));
    assertEquals("[aliases] can't be empty", e.getMessage());
    e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases(new String[0]));
    assertEquals("[aliases] can't be empty", e.getMessage());
    e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases("test", null));
    assertEquals("[aliases] can't contain empty string", e.getMessage());
    e = expectThrows(IllegalArgumentException.class, () -> new AliasActions(type).aliases("test", ""));
    assertEquals("[aliases] can't contain empty string", e.getMessage());
}
Also used : AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions) ParsingException(org.elasticsearch.common.ParsingException) IOException(java.io.IOException)

Example 5 with AliasActions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions in project elasticsearch by elastic.

the class AliasActionsTests method testParseAdd.

public void testParseAdd() throws IOException {
    String[] indices = generateRandomStringArray(10, 5, false, false);
    String[] aliases = generateRandomStringArray(10, 5, false, false);
    Map<String, Object> filter = randomBoolean() ? randomMap(5) : null;
    Object searchRouting = randomBoolean() ? randomRouting() : null;
    Object indexRouting = randomBoolean() ? randomBoolean() ? searchRouting : randomRouting() : null;
    XContentBuilder b = XContentBuilder.builder(randomFrom(XContentType.values()).xContent());
    b.startObject();
    {
        b.startObject("add");
        {
            if (indices.length > 1 || randomBoolean()) {
                b.array("indices", indices);
            } else {
                b.field("index", indices[0]);
            }
            if (aliases.length > 1 || randomBoolean()) {
                b.array("aliases", aliases);
            } else {
                b.field("alias", aliases[0]);
            }
            if (filter != null) {
                b.field("filter", filter);
            }
            if (searchRouting != null) {
                if (searchRouting.equals(indexRouting)) {
                    b.field("routing", searchRouting);
                } else {
                    b.field("search_routing", searchRouting);
                }
            }
            if (indexRouting != null && false == indexRouting.equals(searchRouting)) {
                b.field("index_routing", indexRouting);
            }
        }
        b.endObject();
    }
    b.endObject();
    b = shuffleXContent(b, "filter");
    try (XContentParser parser = createParser(b)) {
        AliasActions action = AliasActions.PARSER.apply(parser, null);
        assertEquals(AliasActions.Type.ADD, action.actionType());
        assertThat(action.indices(), equalTo(indices));
        assertThat(action.aliases(), equalTo(aliases));
        if (filter == null || filter.isEmpty()) {
            assertNull(action.filter());
        } else {
            assertEquals(XContentFactory.contentBuilder(XContentType.JSON).map(filter).string(), action.filter());
        }
        assertEquals(Objects.toString(searchRouting, null), action.searchRouting());
        assertEquals(Objects.toString(indexRouting, null), action.indexRouting());
    }
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)

Aggregations

AliasActions (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)10 IOException (java.io.IOException)4 ParsingException (org.elasticsearch.common.ParsingException)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 XContentParser (org.elasticsearch.common.xcontent.XContentParser)4 IndicesAliasesRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)2 AliasActions (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ClusterStateUpdateResponse (org.elasticsearch.cluster.ack.ClusterStateUpdateResponse)1 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)1 AliasAction (org.elasticsearch.cluster.metadata.AliasAction)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1 StreamInput (org.elasticsearch.common.io.stream.StreamInput)1 AliasesNotFoundException (org.elasticsearch.rest.action.admin.indices.AliasesNotFoundException)1