use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class GcpAuthenticator method createBody.
private String createBody(String privateKeyPath, long currentTimeMs) throws Exception {
JsonObject privateKeyJson = Json.parse(new InputStreamReader(new FileInputStream(privateKeyPath), StandardCharsets.UTF_8)).asObject();
String privateKey = privateKeyJson.get("private_key").asString();
String clientEmail = privateKeyJson.get("client_email").asString();
String headerBase64 = base64encodeUrlSafe(header());
String claimSetBase64 = base64encodeUrlSafe(claimSet(clientEmail, currentTimeMs));
String signatureBase64 = sign(headerBase64, claimSetBase64, privateKey);
return body(headerBase64, claimSetBase64, signatureBase64);
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class HttpPostCommandProcessor method handleAddWanConfig.
/**
* Broadcasts a new {@link WanReplicationConfig} to all members. The config is defined
* by an encoded JSON as a first parameter of the HTTP command.
*
* @param cmd the HTTP command
*/
private void handleAddWanConfig(HttpPostCommand cmd) throws Throwable {
String[] params = decodeParamsAndAuthenticate(cmd, 3);
String wanConfigJson = params[2];
WanReplicationConfigDTO dto = new WanReplicationConfigDTO(new WanReplicationConfig());
dto.fromJson(Json.parse(wanConfigJson).asObject());
AddWanConfigResult result = getNode().getNodeEngine().getWanReplicationService().addWanReplicationConfig(dto.getConfig());
JsonObject res = response(SUCCESS, "message", "WAN configuration added.");
res.add("addedPublisherIds", Json.array(result.getAddedPublisherIds().toArray(new String[] {})));
res.add("ignoredPublisherIds", Json.array(result.getIgnoredPublisherIds().toArray(new String[] {})));
prepareResponse(cmd, res);
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class HttpPostCommandProcessor method handleChangeClusterState.
private void handleChangeClusterState(HttpPostCommand cmd) throws Throwable {
String[] params = decodeParamsAndAuthenticate(cmd, 3);
ClusterService clusterService = getNode().getClusterService();
ClusterState state = ClusterState.valueOf(upperCaseInternal(params[2]));
if (!state.equals(clusterService.getClusterState())) {
clusterService.changeClusterState(state);
JsonObject res = response(SUCCESS, "state", state.toString().toLowerCase(StringUtil.LOCALE_INTERNAL));
prepareResponse(cmd, res);
} else {
JsonObject res = response(FAIL, "state", state.toString().toLowerCase(StringUtil.LOCALE_INTERNAL));
prepareResponse(cmd, res);
}
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class HttpPostCommandProcessor method handleChangeClusterVersion.
private void handleChangeClusterVersion(HttpPostCommand cmd) throws Throwable {
String[] params = decodeParamsAndAuthenticate(cmd, 3);
ClusterService clusterService = getNode().getClusterService();
Version version = Version.of(params[2]);
clusterService.changeClusterVersion(version);
JsonObject rsp = response(SUCCESS, "version", clusterService.getClusterVersion().toString());
prepareResponse(cmd, rsp);
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class HttpGetCommandProcessor method handleHealthcheck.
private void handleHealthcheck(HttpGetCommand command, String uri) {
Node node = textCommandService.getNode();
NodeState nodeState = node.getState();
ClusterServiceImpl clusterService = node.getClusterService();
ClusterState clusterState = clusterService.getClusterState();
int clusterSize = clusterService.getMembers().size();
InternalPartitionService partitionService = node.getPartitionService();
long migrationQueueSize = partitionService.getMigrationQueueSize();
String healthParameter = uri.substring(URI_HEALTH_URL.length());
if (healthParameter.equals(HEALTH_PATH_PARAM_NODE_STATE)) {
if (NodeState.SHUT_DOWN.equals(nodeState)) {
command.send503();
} else {
prepareResponse(command, Json.value(nodeState.toString()));
}
} else if (healthParameter.equals(HEALTH_PATH_PARAM_CLUSTER_STATE)) {
prepareResponse(command, Json.value(clusterState.toString()));
} else if (healthParameter.equals(HEALTH_PATH_PARAM_CLUSTER_SAFE)) {
if (isClusterSafe()) {
command.send200();
} else {
command.send503();
}
} else if (healthParameter.equals(HEALTH_PATH_PARAM_MIGRATION_QUEUE_SIZE)) {
prepareResponse(command, Json.value(migrationQueueSize));
} else if (healthParameter.equals(HEALTH_PATH_PARAM_CLUSTER_SIZE)) {
prepareResponse(command, Json.value(clusterSize));
} else if (healthParameter.isEmpty()) {
JsonObject response = new JsonObject().add("nodeState", nodeState.toString()).add("clusterState", clusterState.toString()).add("clusterSafe", isClusterSafe()).add("migrationQueueSize", migrationQueueSize).add("clusterSize", clusterSize);
prepareResponse(command, response);
} else {
command.send400();
}
}
Aggregations