mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-19 19:35:02 +00:00
Add clusterUUID to RestMainAction output (#20503)
Add clusterUUID to RestMainAction output GET / now returns the clusterUUID as well as part of its output for monitoring purposes
This commit is contained in:
parent
b03c807368
commit
37489c3274
@ -35,16 +35,18 @@ public class MainResponse extends ActionResponse implements ToXContent {
|
|||||||
private String nodeName;
|
private String nodeName;
|
||||||
private Version version;
|
private Version version;
|
||||||
private ClusterName clusterName;
|
private ClusterName clusterName;
|
||||||
|
private String clusterUuid;
|
||||||
private Build build;
|
private Build build;
|
||||||
private boolean available;
|
private boolean available;
|
||||||
|
|
||||||
MainResponse() {
|
MainResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MainResponse(String nodeName, Version version, ClusterName clusterName, Build build, boolean available) {
|
public MainResponse(String nodeName, Version version, ClusterName clusterName, String clusterUuid, Build build, boolean available) {
|
||||||
this.nodeName = nodeName;
|
this.nodeName = nodeName;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.clusterName = clusterName;
|
this.clusterName = clusterName;
|
||||||
|
this.clusterUuid = clusterUuid;
|
||||||
this.build = build;
|
this.build = build;
|
||||||
this.available = available;
|
this.available = available;
|
||||||
}
|
}
|
||||||
@ -61,6 +63,10 @@ public class MainResponse extends ActionResponse implements ToXContent {
|
|||||||
return clusterName;
|
return clusterName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getClusterUuid() {
|
||||||
|
return clusterUuid;
|
||||||
|
}
|
||||||
|
|
||||||
public Build getBuild() {
|
public Build getBuild() {
|
||||||
return build;
|
return build;
|
||||||
}
|
}
|
||||||
@ -75,6 +81,7 @@ public class MainResponse extends ActionResponse implements ToXContent {
|
|||||||
out.writeString(nodeName);
|
out.writeString(nodeName);
|
||||||
Version.writeVersion(version, out);
|
Version.writeVersion(version, out);
|
||||||
clusterName.writeTo(out);
|
clusterName.writeTo(out);
|
||||||
|
out.writeString(clusterUuid);
|
||||||
Build.writeBuild(build, out);
|
Build.writeBuild(build, out);
|
||||||
out.writeBoolean(available);
|
out.writeBoolean(available);
|
||||||
}
|
}
|
||||||
@ -85,6 +92,7 @@ public class MainResponse extends ActionResponse implements ToXContent {
|
|||||||
nodeName = in.readString();
|
nodeName = in.readString();
|
||||||
version = Version.readVersion(in);
|
version = Version.readVersion(in);
|
||||||
clusterName = new ClusterName(in);
|
clusterName = new ClusterName(in);
|
||||||
|
clusterUuid = in.readString();
|
||||||
build = Build.readBuild(in);
|
build = Build.readBuild(in);
|
||||||
available = in.readBoolean();
|
available = in.readBoolean();
|
||||||
}
|
}
|
||||||
@ -94,6 +102,7 @@ public class MainResponse extends ActionResponse implements ToXContent {
|
|||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field("name", nodeName);
|
builder.field("name", nodeName);
|
||||||
builder.field("cluster_name", clusterName.value());
|
builder.field("cluster_name", clusterName.value());
|
||||||
|
builder.field("cluster_uuid", clusterUuid);
|
||||||
builder.startObject("version")
|
builder.startObject("version")
|
||||||
.field("number", version.toString())
|
.field("number", version.toString())
|
||||||
.field("build_hash", build.shortHash())
|
.field("build_hash", build.shortHash())
|
||||||
|
@ -52,7 +52,7 @@ public class TransportMainAction extends HandledTransportAction<MainRequest, Mai
|
|||||||
assert Node.NODE_NAME_SETTING.exists(settings);
|
assert Node.NODE_NAME_SETTING.exists(settings);
|
||||||
final boolean available = clusterState.getBlocks().hasGlobalBlock(RestStatus.SERVICE_UNAVAILABLE) == false;
|
final boolean available = clusterState.getBlocks().hasGlobalBlock(RestStatus.SERVICE_UNAVAILABLE) == false;
|
||||||
listener.onResponse(
|
listener.onResponse(
|
||||||
new MainResponse(Node.NODE_NAME_SETTING.get(settings), Version.CURRENT, clusterState.getClusterName(), Build.CURRENT,
|
new MainResponse(Node.NODE_NAME_SETTING.get(settings), Version.CURRENT, clusterState.getClusterName(),
|
||||||
available));
|
clusterState.metaData().clusterUUID(), Build.CURRENT, available));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|||||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.io.stream.ByteBufferStreamInput;
|
|
||||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
@ -42,7 +41,6 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
@ -56,11 +54,12 @@ public class MainActionTests extends ESTestCase {
|
|||||||
public void testMainResponseSerialization() throws IOException {
|
public void testMainResponseSerialization() throws IOException {
|
||||||
final String nodeName = "node1";
|
final String nodeName = "node1";
|
||||||
final ClusterName clusterName = new ClusterName("cluster1");
|
final ClusterName clusterName = new ClusterName("cluster1");
|
||||||
|
final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
|
||||||
final boolean available = randomBoolean();
|
final boolean available = randomBoolean();
|
||||||
final Version version = Version.CURRENT;
|
final Version version = Version.CURRENT;
|
||||||
final Build build = Build.CURRENT;
|
final Build build = Build.CURRENT;
|
||||||
|
|
||||||
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, build, available);
|
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
|
||||||
BytesStreamOutput streamOutput = new BytesStreamOutput();
|
BytesStreamOutput streamOutput = new BytesStreamOutput();
|
||||||
mainResponse.writeTo(streamOutput);
|
mainResponse.writeTo(streamOutput);
|
||||||
final MainResponse serialized = new MainResponse();
|
final MainResponse serialized = new MainResponse();
|
||||||
@ -74,11 +73,21 @@ public class MainActionTests extends ESTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testMainResponseXContent() throws IOException {
|
public void testMainResponseXContent() throws IOException {
|
||||||
final MainResponse mainResponse = new MainResponse("node1", Version.CURRENT, new ClusterName("cluster1"), Build.CURRENT, false);
|
String clusterUUID = randomAsciiOfLengthBetween(10, 20);
|
||||||
final String expected = "{\"name\":\"node1\",\"cluster_name\":\"cluster1\",\"version\":{\"number\":\"" + Version.CURRENT.toString()
|
final MainResponse mainResponse = new MainResponse("node1", Version.CURRENT, new ClusterName("cluster1"), clusterUUID,
|
||||||
+ "\",\"build_hash\":\"" + Build.CURRENT.shortHash() + "\",\"build_date\":\"" + Build.CURRENT.date() + "\"," +
|
Build.CURRENT, false);
|
||||||
"\"build_snapshot\":" + Build.CURRENT.isSnapshot() + ",\"lucene_version\":\"" + Version.CURRENT.luceneVersion.toString() +
|
final String expected = "{" +
|
||||||
"\"},\"tagline\":\"You Know, for Search\"}";
|
"\"name\":\"node1\"," +
|
||||||
|
"\"cluster_name\":\"cluster1\"," +
|
||||||
|
"\"cluster_uuid\":\"" + clusterUUID + "\"," +
|
||||||
|
"\"version\":{" +
|
||||||
|
"\"number\":\"" + Version.CURRENT.toString() + "\"," +
|
||||||
|
"\"build_hash\":\"" + Build.CURRENT.shortHash() + "\"," +
|
||||||
|
"\"build_date\":\"" + Build.CURRENT.date() + "\"," +
|
||||||
|
"\"build_snapshot\":" + Build.CURRENT.isSnapshot() +
|
||||||
|
",\"lucene_version\":\"" + Version.CURRENT.luceneVersion.toString() +
|
||||||
|
"\"}," +
|
||||||
|
"\"tagline\":\"You Know, for Search\"}";
|
||||||
|
|
||||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||||
mainResponse.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
mainResponse.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
|
@ -30,8 +30,6 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.rest.RestRequest.Method;
|
|
||||||
import org.elasticsearch.rest.action.RestMainAction;
|
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.test.rest.FakeRestRequest;
|
import org.elasticsearch.test.rest.FakeRestRequest;
|
||||||
|
|
||||||
@ -45,12 +43,13 @@ public class RestMainActionTests extends ESTestCase {
|
|||||||
public void testHeadResponse() throws Exception {
|
public void testHeadResponse() throws Exception {
|
||||||
final String nodeName = "node1";
|
final String nodeName = "node1";
|
||||||
final ClusterName clusterName = new ClusterName("cluster1");
|
final ClusterName clusterName = new ClusterName("cluster1");
|
||||||
|
final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
|
||||||
final boolean available = randomBoolean();
|
final boolean available = randomBoolean();
|
||||||
final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
|
final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
|
||||||
final Version version = Version.CURRENT;
|
final Version version = Version.CURRENT;
|
||||||
final Build build = Build.CURRENT;
|
final Build build = Build.CURRENT;
|
||||||
|
|
||||||
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, build, available);
|
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
|
||||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||||
RestRequest restRequest = new FakeRestRequest() {
|
RestRequest restRequest = new FakeRestRequest() {
|
||||||
@Override
|
@Override
|
||||||
@ -70,13 +69,14 @@ public class RestMainActionTests extends ESTestCase {
|
|||||||
public void testGetResponse() throws Exception {
|
public void testGetResponse() throws Exception {
|
||||||
final String nodeName = "node1";
|
final String nodeName = "node1";
|
||||||
final ClusterName clusterName = new ClusterName("cluster1");
|
final ClusterName clusterName = new ClusterName("cluster1");
|
||||||
|
final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
|
||||||
final boolean available = randomBoolean();
|
final boolean available = randomBoolean();
|
||||||
final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
|
final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
|
||||||
final Version version = Version.CURRENT;
|
final Version version = Version.CURRENT;
|
||||||
final Build build = Build.CURRENT;
|
final Build build = Build.CURRENT;
|
||||||
final boolean prettyPrint = randomBoolean();
|
final boolean prettyPrint = randomBoolean();
|
||||||
|
|
||||||
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, build, available);
|
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
|
||||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
|
@ -391,6 +391,7 @@ This command should give you a JSON result:
|
|||||||
{
|
{
|
||||||
"name" : "Cp8oag6",
|
"name" : "Cp8oag6",
|
||||||
"cluster_name" : "elasticsearch",
|
"cluster_name" : "elasticsearch",
|
||||||
|
"cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
|
||||||
"version" : {
|
"version" : {
|
||||||
"number" : "{version}",
|
"number" : "{version}",
|
||||||
"build_hash" : "f27399d",
|
"build_hash" : "f27399d",
|
||||||
@ -403,6 +404,7 @@ This command should give you a JSON result:
|
|||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
// TESTRESPONSE[s/"name" : "Cp8oag6",/"name" : "$body.name",/]
|
// TESTRESPONSE[s/"name" : "Cp8oag6",/"name" : "$body.name",/]
|
||||||
// TESTRESPONSE[s/"cluster_name" : "elasticsearch",/"cluster_name" : "$body.cluster_name",/]
|
// TESTRESPONSE[s/"cluster_name" : "elasticsearch",/"cluster_name" : "$body.cluster_name",/]
|
||||||
|
// TESTRESPONSE[s/"cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",/"cluster_uuid" : "$body.cluster_uuid",/]
|
||||||
// TESTRESPONSE[s/"build_hash" : "f27399d",/"build_hash" : "$body.version.build_hash",/]
|
// TESTRESPONSE[s/"build_hash" : "f27399d",/"build_hash" : "$body.version.build_hash",/]
|
||||||
// TESTRESPONSE[s/"build_date" : "2016-03-30T09:51:41.449Z",/"build_date" : $body.version.build_date,/]
|
// TESTRESPONSE[s/"build_date" : "2016-03-30T09:51:41.449Z",/"build_date" : $body.version.build_date,/]
|
||||||
// TESTRESPONSE[s/"build_snapshot" : false,/"build_snapshot" : $body.version.build_snapshot,/]
|
// TESTRESPONSE[s/"build_snapshot" : false,/"build_snapshot" : $body.version.build_snapshot,/]
|
||||||
|
@ -16,6 +16,7 @@ which should give you a response something like this:
|
|||||||
{
|
{
|
||||||
"name" : "Cp8oag6",
|
"name" : "Cp8oag6",
|
||||||
"cluster_name" : "elasticsearch",
|
"cluster_name" : "elasticsearch",
|
||||||
|
"cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
|
||||||
"version" : {
|
"version" : {
|
||||||
"number" : "{version}",
|
"number" : "{version}",
|
||||||
"build_hash" : "f27399d",
|
"build_hash" : "f27399d",
|
||||||
@ -28,6 +29,7 @@ which should give you a response something like this:
|
|||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
// TESTRESPONSE[s/"name" : "Cp8oag6",/"name" : "$body.name",/]
|
// TESTRESPONSE[s/"name" : "Cp8oag6",/"name" : "$body.name",/]
|
||||||
// TESTRESPONSE[s/"cluster_name" : "elasticsearch",/"cluster_name" : "$body.cluster_name",/]
|
// TESTRESPONSE[s/"cluster_name" : "elasticsearch",/"cluster_name" : "$body.cluster_name",/]
|
||||||
|
// TESTRESPONSE[s/"cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",/"cluster_uuid" : "$body.cluster_uuid",/]
|
||||||
// TESTRESPONSE[s/"build_hash" : "f27399d",/"build_hash" : "$body.version.build_hash",/]
|
// TESTRESPONSE[s/"build_hash" : "f27399d",/"build_hash" : "$body.version.build_hash",/]
|
||||||
// TESTRESPONSE[s/"build_date" : "2016-03-30T09:51:41.449Z",/"build_date" : $body.version.build_date,/]
|
// TESTRESPONSE[s/"build_date" : "2016-03-30T09:51:41.449Z",/"build_date" : $body.version.build_date,/]
|
||||||
// TESTRESPONSE[s/"build_snapshot" : false,/"build_snapshot" : $body.version.build_snapshot,/]
|
// TESTRESPONSE[s/"build_snapshot" : false,/"build_snapshot" : $body.version.build_snapshot,/]
|
||||||
|
@ -294,6 +294,7 @@ final class RemoteResponseParsers {
|
|||||||
MAIN_ACTION_PARSER.declareInt((p, v) -> {}, new ParseField("status"));
|
MAIN_ACTION_PARSER.declareInt((p, v) -> {}, new ParseField("status"));
|
||||||
MAIN_ACTION_PARSER.declareString((p, v) -> {}, new ParseField("name"));
|
MAIN_ACTION_PARSER.declareString((p, v) -> {}, new ParseField("name"));
|
||||||
MAIN_ACTION_PARSER.declareString((p, v) -> {}, new ParseField("cluster_name"));
|
MAIN_ACTION_PARSER.declareString((p, v) -> {}, new ParseField("cluster_name"));
|
||||||
|
MAIN_ACTION_PARSER.declareString((p, v) -> {}, new ParseField("cluster_uuid"));
|
||||||
MAIN_ACTION_PARSER.declareString((p, v) -> {}, new ParseField("name"));
|
MAIN_ACTION_PARSER.declareString((p, v) -> {}, new ParseField("name"));
|
||||||
MAIN_ACTION_PARSER.declareString((p, v) -> {}, new ParseField("tagline"));
|
MAIN_ACTION_PARSER.declareString((p, v) -> {}, new ParseField("tagline"));
|
||||||
MAIN_ACTION_PARSER.declareObject(constructorArg(), VERSION_PARSER, new ParseField("version"));
|
MAIN_ACTION_PARSER.declareObject(constructorArg(), VERSION_PARSER, new ParseField("version"));
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
- do: {info: {}}
|
- do: {info: {}}
|
||||||
- is_true: name
|
- is_true: name
|
||||||
- is_true: cluster_name
|
- is_true: cluster_name
|
||||||
|
- is_true: cluster_uuid
|
||||||
- is_true: tagline
|
- is_true: tagline
|
||||||
- is_true: version
|
- is_true: version
|
||||||
- is_true: version.number
|
- is_true: version.number
|
||||||
|
Loading…
x
Reference in New Issue
Block a user