Search in sources :

Example 31 with JsonArray

use of com.hazelcast.internal.json.JsonArray 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 32 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class HttpGetCommandProcessor method handleGetCPGroupIds.

private void handleGetCPGroupIds(final HttpGetCommand command) {
    CompletionStage<Collection<CPGroupId>> f = getCpSubsystemManagementService().getCPGroupIds();
    f.whenCompleteAsync((groupIds, t) -> {
        if (t == null) {
            JsonArray arr = new JsonArray();
            for (CPGroupId groupId : groupIds) {
                arr.add(toJson(groupId));
            }
            prepareResponse(command, arr);
            textCommandService.sendResponse(command);
        } else {
            command.send500();
            textCommandService.sendResponse(command);
        }
    });
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) CPGroupId(com.hazelcast.cp.CPGroupId) Collection(java.util.Collection)

Example 33 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class HttpGetCommandProcessor method handleGetCPSessions.

private void handleGetCPSessions(final HttpGetCommand command) {
    String uri = command.getURI();
    String prefix = URI_CP_GROUPS_URL + "/";
    int i = uri.indexOf(URI_CP_SESSIONS_SUFFIX);
    String groupName = uri.substring(prefix.length(), i).trim();
    getCpSubsystem().getCPSessionManagementService().getAllSessions(groupName).whenCompleteAsync((sessions, t) -> {
        if (t == null) {
            JsonArray sessionsArr = new JsonArray();
            for (CPSession session : sessions) {
                sessionsArr.add(toJson(session));
            }
            prepareResponse(command, sessionsArr);
            textCommandService.sendResponse(command);
        } else {
            if (peel(t) instanceof IllegalArgumentException) {
                command.send404();
            } else {
                command.send500();
            }
            textCommandService.sendResponse(command);
        }
    });
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) CPSession(com.hazelcast.cp.session.CPSession)

Example 34 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class HttpGetCommandProcessor method handleGetCPMembers.

private void handleGetCPMembers(final HttpGetCommand command) {
    CompletionStage<Collection<CPMember>> f = getCpSubsystemManagementService().getCPMembers();
    f.whenCompleteAsync((cpMembers, t) -> {
        if (t == null) {
            JsonArray arr = new JsonArray();
            for (CPMember cpMember : cpMembers) {
                arr.add(toJson(cpMember));
            }
            prepareResponse(command, arr);
            textCommandService.sendResponse(command);
        } else {
            command.send500();
            textCommandService.sendResponse(command);
        }
    });
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) Collection(java.util.Collection) CPMember(com.hazelcast.cp.CPMember)

Example 35 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class HttpGetCommandProcessor method handleCluster.

/**
 * Sets the HTTP response to a string containing basic cluster information:
 * <ul>
 * <li>Member list</li>
 * <li>Client connection count</li>
 * <li>Connection count</li>
 * </ul>
 *
 * @param command the HTTP request
 */
private void handleCluster(HttpGetCommand command) {
    Node node = textCommandService.getNode();
    Server server = node.getServer();
    ClusterServiceImpl clusterService = node.getClusterService();
    JsonArray membersArray = new JsonArray();
    clusterService.getMembers().stream().map(m -> new JsonObject().add("address", m.getAddress().toString()).add("liteMember", m.isLiteMember()).add("localMember", m.localMember()).add("uuid", m.getUuid().toString()).add("memberVersion", m.getVersion().toString())).forEach(membersArray::add);
    ServerConnectionManager cm = server.getConnectionManager(CLIENT);
    int clientCount = cm == null ? 0 : cm.connectionCount(ServerConnection::isClient);
    JsonObject response = new JsonObject().add("members", membersArray).add("connectionCount", clientCount).add("allConnectionCount", server.connectionCount());
    prepareResponse(command, response);
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) Address(com.hazelcast.cluster.Address) LoggingServiceImpl(com.hazelcast.logging.impl.LoggingServiceImpl) ServerConnection(com.hazelcast.internal.server.ServerConnection) JsonArray(com.hazelcast.internal.json.JsonArray) Level(java.util.logging.Level) Json(com.hazelcast.internal.json.Json) ClusterService(com.hazelcast.internal.cluster.ClusterService) SC_500(com.hazelcast.internal.ascii.rest.HttpStatusCode.SC_500) CPGroup(com.hazelcast.cp.CPGroup) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) StringUtil.equalsIgnoreCase(com.hazelcast.internal.util.StringUtil.equalsIgnoreCase) CPSession(com.hazelcast.cp.session.CPSession) JsonObject(com.hazelcast.internal.json.JsonObject) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) CPGroupId(com.hazelcast.cp.CPGroupId) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) TextCommandService(com.hazelcast.internal.ascii.TextCommandService) StringUtil(com.hazelcast.internal.util.StringUtil) ExceptionUtil.peel(com.hazelcast.internal.util.ExceptionUtil.peel) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) Collection(java.util.Collection) Server(com.hazelcast.internal.server.Server) NodeState(com.hazelcast.instance.impl.NodeState) MAP(com.hazelcast.internal.ascii.rest.RestCallExecution.ObjectType.MAP) Node(com.hazelcast.instance.impl.Node) CLIENT(com.hazelcast.instance.EndpointQualifier.CLIENT) CompletionStage(java.util.concurrent.CompletionStage) CPMember(com.hazelcast.cp.CPMember) ClusterState(com.hazelcast.cluster.ClusterState) CPSubsystem(com.hazelcast.cp.CPSubsystem) QUEUE(com.hazelcast.internal.ascii.rest.RestCallExecution.ObjectType.QUEUE) Server(com.hazelcast.internal.server.Server) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) Node(com.hazelcast.instance.impl.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) JsonObject(com.hazelcast.internal.json.JsonObject)

Aggregations

JsonArray (com.hazelcast.internal.json.JsonArray)74 JsonObject (com.hazelcast.internal.json.JsonObject)42 Test (org.junit.Test)39 QuickTest (com.hazelcast.test.annotation.QuickTest)31 JsonValue (com.hazelcast.internal.json.JsonValue)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 CPMember (com.hazelcast.cp.CPMember)7 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)7 SlowTest (com.hazelcast.test.annotation.SlowTest)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)4 Address (com.hazelcast.cluster.Address)3 JetException (com.hazelcast.jet.JetException)3 InputStreamReader (java.io.InputStreamReader)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Request (org.elasticsearch.client.Request)3