Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the cluster name to the "/" endpoint #7524

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rest-api-spec/test/info/10_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- do: {info: {}}
- match: {status: 200}
- is_true: name
- is_true: cluster_name
- is_true: tagline
- is_true: version
- is_true: version.number
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
Expand All @@ -41,13 +42,15 @@
public class RestMainAction extends BaseRestHandler {

private final Version version;
private final ClusterName clusterName;

@Inject
public RestMainAction(Settings settings, Version version, Client client, RestController controller) {
public RestMainAction(Settings settings, Version version, Client client, RestController controller, ClusterName clusterName) {
super(settings, client);
this.version = version;
controller.registerHandler(GET, "/", this);
controller.registerHandler(HEAD, "/", this);
this.clusterName = clusterName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlikely to matter, but you should put this assignment above the handler registration since it hands out a reference to an incomplete object that could cause trouble.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Pushed another commit with this changed.

}

@Override
Expand Down Expand Up @@ -80,6 +83,7 @@ public RestResponse buildResponse(ClusterStateResponse response) throws Exceptio
if (settings.get("name") != null) {
builder.field("name", settings.get("name"));
}
builder.field("cluster_name", clusterName.value());
builder.startObject("version")
.field("number", version.number())
.field("build_hash", Build.CURRENT.hash())
Expand Down