Search in sources :

Example 76 with JsonObject

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;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 77 with JsonObject

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);
    }
}
Also used : Response(org.elasticsearch.client.Response) JsonArray(com.hazelcast.internal.json.JsonArray) InputStreamReader(java.io.InputStreamReader) Request(org.elasticsearch.client.Request) JsonObject(com.hazelcast.internal.json.JsonObject) IOException(java.io.IOException) JetException(com.hazelcast.jet.JetException)

Example 78 with JsonObject

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();
    }
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject)

Example 79 with JsonObject

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);
        }
    });
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) CPGroup(com.hazelcast.cp.CPGroup) JsonObject(com.hazelcast.internal.json.JsonObject) CPMember(com.hazelcast.cp.CPMember)

Example 80 with JsonObject

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);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Node(com.hazelcast.instance.impl.Node) JsonObject(com.hazelcast.internal.json.JsonObject)

Aggregations

JsonObject (com.hazelcast.internal.json.JsonObject)151 Test (org.junit.Test)56 JsonArray (com.hazelcast.internal.json.JsonArray)41 QuickTest (com.hazelcast.test.annotation.QuickTest)38 JsonValue (com.hazelcast.internal.json.JsonValue)34 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)26 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)23 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)10 SlowTest (com.hazelcast.test.annotation.SlowTest)9 HashMap (java.util.HashMap)8 CPMember (com.hazelcast.cp.CPMember)7 ArrayList (java.util.ArrayList)7 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 NavigableJsonInputAdapter (com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter)6 JsonUtil.fromJsonObject (com.hazelcast.internal.util.JsonUtil.fromJsonObject)5 JsonUtil.toJsonObject (com.hazelcast.internal.util.JsonUtil.toJsonObject)5 Map (java.util.Map)5 ClusterService (com.hazelcast.internal.cluster.ClusterService)4 Address (com.hazelcast.cluster.Address)3