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);
}
});
}
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);
}
});
}
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);
}
});
}
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);
}
});
}
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);
}
Aggregations