use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class DAG method toJson.
/**
* Returns a JSON representation of the DAG.
* <p>
* <strong>Note:</strong> the exact structure of the JSON is unspecified.
*
* @param defaultLocalParallelism the local parallelism that will be shown if neither overridden on the
* vertex nor the preferred parallelism is defined by meta-supplier
*/
@Nonnull
public JsonObject toJson(int defaultLocalParallelism) {
JsonObject dag = new JsonObject();
JsonArray vertices = new JsonArray();
for (Vertex v : this) {
JsonObject vertex = new JsonObject();
vertex.add("name", v.getName());
vertex.add("parallelism", v.determineLocalParallelism(defaultLocalParallelism));
vertices.add(vertex);
}
dag.add("vertices", vertices);
JsonArray edges = new JsonArray();
for (Edge e : this.edges) {
JsonObject edge = new JsonObject();
edge.add("from", e.getSourceName());
edge.add("fromOrdinal", e.getSourceOrdinal());
edge.add("to", e.getDestName());
edge.add("toOrdinal", e.getDestOrdinal());
edge.add("priority", e.getPriority());
edge.add("distributedTo", String.valueOf(e.getDistributedTo()));
edge.add("type", StringUtil.lowerCaseInternal(e.getRoutingPolicy().toString()));
edges.add(edge);
}
dag.add("edges", edges);
return dag;
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class ElasticCatClient method master.
/**
* Returns current master of the ES cluster
*/
public Master master() {
try {
Request r = new Request("GET", "/_cat/master");
r.addParameter("format", "json");
Response res = withRetry(() -> client.performRequest(r), retries);
try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
JsonArray array = Json.parse(reader).asArray();
JsonObject object = array.get(0).asObject();
return new Master(object.get("host").asString(), object.get("id").asString(), object.get("ip").asString(), object.get("node").asString());
}
} catch (IOException e) {
throw new JetException("Could not get ES cluster master", e);
}
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class ElasticCatClient method convertToShard.
private Optional<Shard> convertToShard(JsonValue value, Map<String, String> idToAddress) {
JsonObject object = value.asObject();
// TODO IndexShardState.STARTED but this is deeply inside elastic, should we mirror the enum?
if ("STARTED".equals(object.get("state").asString())) {
String id = object.get("id").asString();
Shard shard = new Shard(object.get("index").asString(), Integer.parseInt(object.get("shard").asString()), Prirep.valueOf(object.get("prirep").asString()), object.get("docs") != null ? Integer.parseInt(object.get("docs").asString()) : 0, object.get("state").asString(), object.get("ip").asString(), idToAddress.get(id), object.get("node").asString());
return of(shard);
} else {
return empty();
}
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class HttpGetCommandProcessor method handleGetCPGroupByName.
private void handleGetCPGroupByName(final HttpGetCommand command) {
String prefix = URI_CP_GROUPS_URL + "/";
String groupName = command.getURI().substring(prefix.length()).trim();
CompletionStage<CPGroup> f = getCpSubsystemManagementService().getCPGroup(groupName);
f.whenCompleteAsync((group, t) -> {
if (t == null) {
if (group != null) {
JsonObject json = new JsonObject();
json.add("id", toJson(group.id())).add("status", group.status().name());
JsonArray membersArr = new JsonArray();
for (CPMember member : group.members()) {
membersArr.add(toJson(member));
}
json.add("members", membersArr);
prepareResponse(command, json);
} else {
command.send404();
}
textCommandService.sendResponse(command);
} else {
command.send500();
textCommandService.sendResponse(command);
}
});
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class HttpGetCommandProcessor method handleGetClusterVersion.
private void handleGetClusterVersion(HttpGetCommand command) {
Node node = textCommandService.getNode();
ClusterService clusterService = node.getClusterService();
JsonObject response = new JsonObject().add("status", "success").add("version", clusterService.getClusterVersion().toString());
prepareResponse(command, response);
}
Aggregations