REST API does not expose node-master status, closes #203.

This commit is contained in:
kimchy 2010-06-02 17:04:43 +03:00
parent 6c8f49c37d
commit b2f90a2133
3 changed files with 24 additions and 3 deletions

View File

@ -20,6 +20,7 @@
package org.elasticsearch.action.admin.cluster.state;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.util.io.stream.StreamInput;
import org.elasticsearch.util.io.stream.StreamOutput;
@ -31,12 +32,15 @@ import java.io.IOException;
*/
public class ClusterStateResponse implements ActionResponse {
private ClusterName clusterName;
private ClusterState clusterState;
ClusterStateResponse() {
}
ClusterStateResponse(ClusterState clusterState) {
ClusterStateResponse(ClusterName clusterName, ClusterState clusterState) {
this.clusterName = clusterName;
this.clusterState = clusterState;
}
@ -48,11 +52,21 @@ public class ClusterStateResponse implements ActionResponse {
return state();
}
public ClusterName clusterName() {
return this.clusterName;
}
public ClusterName getClusterName() {
return clusterName();
}
@Override public void readFrom(StreamInput in) throws IOException {
clusterName = ClusterName.readClusterName(in);
clusterState = ClusterState.Builder.readFrom(in, null, null);
}
@Override public void writeTo(StreamOutput out) throws IOException {
clusterName.writeTo(out);
ClusterState.Builder.writeTo(clusterState, out);
}
}

View File

@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.cluster.state;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@ -33,8 +34,12 @@ import org.elasticsearch.util.settings.Settings;
*/
public class TransportClusterStateAction extends TransportMasterNodeOperationAction<ClusterStateRequest, ClusterStateResponse> {
@Inject public TransportClusterStateAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool) {
private final ClusterName clusterName;
@Inject public TransportClusterStateAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool,
ClusterName clusterName) {
super(settings, transportService, clusterService, threadPool);
this.clusterName = clusterName;
}
@Override protected String transportAction() {
@ -50,6 +55,6 @@ public class TransportClusterStateAction extends TransportMasterNodeOperationAct
}
@Override protected ClusterStateResponse masterOperation(ClusterStateRequest request) throws ElasticSearchException {
return new ClusterStateResponse(clusterService.state());
return new ClusterStateResponse(clusterName, clusterService.state());
}
}

View File

@ -63,6 +63,8 @@ public class RestClusterStateAction extends BaseRestHandler {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject();
builder.field("cluster_name", response.clusterName().value());
// nodes
builder.startObject("nodes");
builder.field("_master", state.nodes().masterNodeId());