Search in sources :

Example 31 with JsonObject

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

Example 32 with JsonObject

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);
}
Also used : WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) WanReplicationConfigDTO(com.hazelcast.internal.management.dto.WanReplicationConfigDTO) AddWanConfigResult(com.hazelcast.wan.impl.AddWanConfigResult) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 33 with JsonObject

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

Example 34 with JsonObject

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

Example 35 with JsonObject

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();
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) NodeState(com.hazelcast.instance.impl.NodeState) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.impl.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) 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