From d896bbc232bc1304894be72fdc805b6028b67e70 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Wed, 21 Aug 2019 07:40:07 -0700 Subject: [PATCH 1/2] Add is_write_index column to cat.aliases (#44772) Aliases have had the option to set `is_write_index` since 6.4, but the cat.aliases action was never updated. --- docs/reference/cat/alias.asciidoc | 10 +- .../test/cat.aliases/10_basic.yml | 189 +++++++++++++++++- .../rest/action/cat/RestAliasAction.java | 3 + 3 files changed, 196 insertions(+), 6 deletions(-) diff --git a/docs/reference/cat/alias.asciidoc b/docs/reference/cat/alias.asciidoc index 619374504c070..dc385a91e032c 100644 --- a/docs/reference/cat/alias.asciidoc +++ b/docs/reference/cat/alias.asciidoc @@ -79,11 +79,11 @@ The API returns the following response: [source,txt] -------------------------------------------------- -alias index filter routing.index routing.search -alias1 test1 - - - -alias2 test1 * - - -alias3 test1 - 1 1 -alias4 test1 - 2 1,2 +alias index filter routing.index routing.search is_write_index +alias1 test1 - - - - +alias2 test1 * - - - +alias3 test1 - 1 1 - +alias4 test1 - 2 1,2 - -------------------------------------------------- // TESTRESPONSE[s/[*]/[*]/ non_json] diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yml index bdcee7af1bcb6..bb96c5d24f376 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yml @@ -1,6 +1,34 @@ + --- "Help": + - skip: + version: " - 7.99.99" + reason: "is_write_index is shown in cat.aliases starting version 8.0" + + - do: + cat.aliases: + help: true + + - match: + $body: | + /^ alias .+ \n + index .+ \n + filter .+ \n + routing.index .+ \n + routing.search .+ \n + is_write_index .+ \n + $/ + +--- +"Help (pre 8.0)": + - skip: + version: "8.0.0 - " + features: node_selector + reason: "is_write_index is shown in cat.aliases starting version 8.0" + - do: + node_selector: + version: " - 7.99.99" cat.aliases: help: true @@ -26,6 +54,9 @@ --- "Simple alias": + - skip: + version: " - 7.99.99" + reason: "is_write_index is shown in cat.aliases starting version 8.0" - do: indices.create: @@ -47,10 +78,45 @@ - \s+ - \s+ - \s+ + - \s+ $/ +--- +"Simple alias (pre 8.0)": + - skip: + version: "8.0.0 - " + features: node_selector + reason: "is_write_index is shown in cat.aliases starting version 8.0" + + - do: + indices.create: + index: test + + - do: + indices.put_alias: + index: test + name: test_alias + + - do: + node_selector: + version: " - 7.99.99" + cat.aliases: {} + + - match: + $body: | + /^ + test_alias \s+ + test \s+ + - \s+ + - \s+ + - \s+ + $/ + --- "Complex alias": + - skip: + version: " - 7.99.99" + reason: "is_write_index is shown in cat.aliases starting version 8.0" - do: indices.create: @@ -68,6 +134,7 @@ body: index_routing: ir search_routing: "sr1,sr2" + is_write_index: true filter: term: foo: bar @@ -82,8 +149,50 @@ [*] \s+ ir \s+ sr1,sr2 \s+ + true \s+ $/ +--- +"Complex alias (pre 8.0)": + - skip: + version: "8.0.0 - " + features: node_selector + reason: "is_write_index is shown in cat.aliases starting version 8.0" + + - do: + indices.create: + index: test + body: + mappings: + properties: + foo: + type: text + + - do: + indices.put_alias: + index: test + name: test_alias + body: + index_routing: ir + search_routing: "sr1,sr2" + filter: + term: + foo: bar + - do: + node_selector: + version: " - 7.99.99" + cat.aliases: {} + + - match: + $body: | + /^ + test_alias \s+ + test \s+ + [*] \s+ + ir \s+ + sr1,sr2 \s+ + $/ + --- "Alias name": @@ -169,6 +278,9 @@ --- "Column headers": + - skip: + version: " - 7.99.99" + reason: "is_write_index is shown in cat.aliases starting version 8.0" - do: indices.create: @@ -189,15 +301,53 @@ index \s+ filter \s+ routing.index \s+ - routing.search + routing.search \s+ + is_write_index \n test_1 \s+ test \s+ - \s+ - \s+ - \s+ + - \s+ $/ +--- +"Column headers (pre 8.0)": + - skip: + version: "8.0.0 - " + features: node_selector + reason: "is_write_index is shown in cat.aliases starting version 8.0" + + - do: + indices.create: + index: test + + - do: + indices.put_alias: + index: test + name: test_1 + + - do: + node_selector: + version: " - 7.99.99" + cat.aliases: + v: true + + - match: + $body: | + /^ alias \s+ + index \s+ + filter \s+ + routing.index \s+ + routing.search + \n + test_1 \s+ + test \s+ + - \s+ + - \s+ + - \s+ + $/ --- "Select columns": @@ -232,6 +382,9 @@ --- "Alias against closed index": + - skip: + version: " - 7.99.99" + reason: "is_write_index is shown in cat.aliases starting version 8.0" - do: indices.create: @@ -255,8 +408,42 @@ - \s+ - \s+ - \s+ + - \s+ $/ +--- +"Alias against closed index (pre 8.0)": + - skip: + version: "8.0.0 - " + features: node_selector + reason: "is_write_index is shown in cat.aliases starting version 8.0" + + - do: + indices.create: + index: test_index + body: + aliases: + test_alias: {} + + - do: + indices.close: + index: test_index + + - do: + node_selector: + version: " - 7.99.99" + cat.aliases: {} + + - match: + $body: | + /^ + test_alias \s+ + test_index \s+ + - \s+ + - \s+ + - \s+ + $/ + --- "Alias sorting": diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java index b46ad80e338ee..4fd43becf431b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java @@ -77,6 +77,7 @@ protected Table getTableWithHeader(RestRequest request) { table.addCell("filter", "alias:f,fi;desc:filter"); table.addCell("routing.index", "alias:ri,routingIndex;desc:index routing"); table.addCell("routing.search", "alias:rs,routingSearch;desc:search routing"); + table.addCell("is_write_index", "alias:w,isWriteIndex;desc:write index"); table.endHeaders(); return table; } @@ -95,6 +96,8 @@ private Table buildTable(RestRequest request, GetAliasesResponse response) { table.addCell(indexRouting); String searchRouting = Strings.hasLength(aliasMetaData.searchRouting()) ? aliasMetaData.searchRouting() : "-"; table.addCell(searchRouting); + String isWriteIndex = aliasMetaData.writeIndex() == null ? "-" : aliasMetaData.writeIndex().toString(); + table.addCell(isWriteIndex); table.endRow(); } } From 5612e1be596daf7898973a1285f12cd92a13f08c Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Wed, 21 Aug 2019 07:59:50 -0700 Subject: [PATCH 2/2] correct version bounds to 7.4 --- .../test/cat.aliases/10_basic.yml | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yml index bb96c5d24f376..5669206ee87ad 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yml @@ -2,8 +2,8 @@ --- "Help": - skip: - version: " - 7.99.99" - reason: "is_write_index is shown in cat.aliases starting version 8.0" + version: " - 7.3.99" + reason: "is_write_index is shown in cat.aliases starting version 7.4.0" - do: cat.aliases: @@ -20,15 +20,15 @@ $/ --- -"Help (pre 8.0)": +"Help (pre 7.4.0)": - skip: - version: "8.0.0 - " + version: "7.4.0 - " features: node_selector - reason: "is_write_index is shown in cat.aliases starting version 8.0" + reason: "is_write_index is shown in cat.aliases starting version 7.4.0" - do: node_selector: - version: " - 7.99.99" + version: " - 7.3.99" cat.aliases: help: true @@ -55,8 +55,8 @@ --- "Simple alias": - skip: - version: " - 7.99.99" - reason: "is_write_index is shown in cat.aliases starting version 8.0" + version: " - 7.3.99" + reason: "is_write_index is shown in cat.aliases starting version 7.4.0" - do: indices.create: @@ -82,11 +82,11 @@ $/ --- -"Simple alias (pre 8.0)": +"Simple alias (pre 7.4.0)": - skip: - version: "8.0.0 - " + version: "7.4.0 - " features: node_selector - reason: "is_write_index is shown in cat.aliases starting version 8.0" + reason: "is_write_index is shown in cat.aliases starting version 7.4.0" - do: indices.create: @@ -99,7 +99,7 @@ - do: node_selector: - version: " - 7.99.99" + version: " - 7.3.99" cat.aliases: {} - match: @@ -115,8 +115,8 @@ --- "Complex alias": - skip: - version: " - 7.99.99" - reason: "is_write_index is shown in cat.aliases starting version 8.0" + version: " - 7.3.99" + reason: "is_write_index is shown in cat.aliases starting version 7.4.0" - do: indices.create: @@ -153,11 +153,11 @@ $/ --- -"Complex alias (pre 8.0)": +"Complex alias (pre 7.4.0)": - skip: - version: "8.0.0 - " + version: "7.4.0 - " features: node_selector - reason: "is_write_index is shown in cat.aliases starting version 8.0" + reason: "is_write_index is shown in cat.aliases starting version 7.4.0" - do: indices.create: @@ -180,7 +180,7 @@ foo: bar - do: node_selector: - version: " - 7.99.99" + version: " - 7.3.99" cat.aliases: {} - match: @@ -279,8 +279,8 @@ --- "Column headers": - skip: - version: " - 7.99.99" - reason: "is_write_index is shown in cat.aliases starting version 8.0" + version: " - 7.3.99" + reason: "is_write_index is shown in cat.aliases starting version 7.4.0" - do: indices.create: @@ -313,11 +313,11 @@ $/ --- -"Column headers (pre 8.0)": +"Column headers (pre 7.4.0)": - skip: - version: "8.0.0 - " + version: "7.4.0 - " features: node_selector - reason: "is_write_index is shown in cat.aliases starting version 8.0" + reason: "is_write_index is shown in cat.aliases starting version 7.4.0" - do: indices.create: @@ -330,7 +330,7 @@ - do: node_selector: - version: " - 7.99.99" + version: " - 7.3.99" cat.aliases: v: true @@ -383,8 +383,8 @@ --- "Alias against closed index": - skip: - version: " - 7.99.99" - reason: "is_write_index is shown in cat.aliases starting version 8.0" + version: " - 7.3.99" + reason: "is_write_index is shown in cat.aliases starting version 7.4.0" - do: indices.create: @@ -412,11 +412,11 @@ $/ --- -"Alias against closed index (pre 8.0)": +"Alias against closed index (pre 7.4.0)": - skip: - version: "8.0.0 - " + version: "7.4.0 - " features: node_selector - reason: "is_write_index is shown in cat.aliases starting version 8.0" + reason: "is_write_index is shown in cat.aliases starting version 7.4.0" - do: indices.create: @@ -431,7 +431,7 @@ - do: node_selector: - version: " - 7.99.99" + version: " - 7.3.99" cat.aliases: {} - match: