Search in sources :

Example 51 with JsonArray

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

the class NodeStateImpl method toJson.

@Override
public JsonObject toJson() {
    JsonObject root = new JsonObject();
    root.add("clusterState", clusterState.name());
    root.add("nodeState", nodeState.name());
    root.add("clusterVersion", clusterVersion.toString());
    root.add("memberVersion", memberVersion.toString());
    JsonObject weaknesses = new JsonObject();
    for (Map.Entry<String, List<String>> entry : weakSecretsConfigs.entrySet()) {
        JsonArray values = new JsonArray();
        for (String value : entry.getValue()) {
            values.add(value);
        }
        weaknesses.add(entry.getKey(), values);
    }
    root.add("weakConfigs", weaknesses);
    return root;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) JsonUtil.getString(com.hazelcast.internal.util.JsonUtil.getString) HashMap(java.util.HashMap) Map(java.util.Map)

Example 52 with JsonArray

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

the class MemberPartitionStateImpl method toJson.

@Override
public JsonObject toJson() {
    JsonObject root = new JsonObject();
    JsonArray partitionsArray = new JsonArray();
    for (Integer lsPartition : partitions) {
        partitionsArray.add(lsPartition);
    }
    root.add("partitions", partitionsArray);
    root.add("memberStateSafe", memberStateSafe);
    return root;
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 53 with JsonArray

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

the class RestCPSubsystemTest method test_getCPMembers.

@Test
public void test_getCPMembers() throws IOException {
    final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    waitUntilCPDiscoveryCompleted(instance1, instance2, instance3);
    ConnectionResponse response = new HTTPCommunicator(instance1).getCPMembers();
    CPMember cpMember1 = instance1.getCPSubsystem().getLocalCPMember();
    CPMember cpMember2 = instance2.getCPSubsystem().getLocalCPMember();
    CPMember cpMember3 = instance3.getCPSubsystem().getLocalCPMember();
    boolean cpMember1Found = false;
    boolean cpMember2Found = false;
    boolean cpMember3Found = false;
    JsonArray arr = (JsonArray) Json.parse(response.response);
    for (JsonValue val : arr) {
        JsonObject mem = (JsonObject) val;
        cpMember1Found |= cpMember1.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
        cpMember2Found |= cpMember2.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
        cpMember3Found |= cpMember3.getUuid().equals(UUID.fromString(mem.getString("uuid", "")));
    }
    assertTrue(cpMember1Found);
    assertTrue(cpMember2Found);
    assertTrue(cpMember3Found);
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) CPMember(com.hazelcast.cp.CPMember) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 54 with JsonArray

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

the class RestCPSubsystemTest method test_getCPSessions.

@Test
public void test_getCPSessions() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(config);
    instance1.getCPSubsystem().getLock("lock1").lock();
    instance1.getCPSubsystem().getLock("lock1").unlock();
    instance2.getCPSubsystem().getLock("lock1").lock();
    instance2.getCPSubsystem().getLock("lock1").unlock();
    instance3.getCPSubsystem().getLock("lock1").lock();
    instance3.getCPSubsystem().getLock("lock1").unlock();
    ConnectionResponse response = new HTTPCommunicator(instance1).getCPSessions(DEFAULT_GROUP_NAME);
    assertEquals(200, response.responseCode);
    JsonArray sessions = (JsonArray) Json.parse(response.response);
    assertEquals(3, sessions.size());
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 55 with JsonArray

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

the class RestCPSubsystemTest method test_getCPGroupIds.

@Test
public void test_getCPGroupIds() throws IOException {
    HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    Hazelcast.newHazelcastInstance(config);
    instance1.getCPSubsystem().getAtomicLong("long1").set(5);
    instance1.getCPSubsystem().getAtomicLong("long1@custom").set(5);
    HTTPCommunicator communicator = new HTTPCommunicator(instance1);
    ConnectionResponse response = communicator.getCPGroupIds();
    assertEquals(200, response.responseCode);
    JsonArray responseArr = (JsonArray) Json.parse(response.response);
    boolean metadataCPGroupExists = false;
    boolean defaultCPGroupExists = false;
    boolean customCPGroupExists = false;
    for (JsonValue val : responseArr) {
        JsonObject obj = (JsonObject) val;
        String name = obj.getString("name", "");
        if (CPGroup.DEFAULT_GROUP_NAME.equals(name)) {
            defaultCPGroupExists = true;
        } else if (METADATA_CP_GROUP_NAME.equals(name)) {
            metadataCPGroupExists = true;
        } else if ("custom".equals(name)) {
            customCPGroupExists = true;
        }
    }
    assertTrue(metadataCPGroupExists);
    assertTrue(defaultCPGroupExists);
    assertTrue(customCPGroupExists);
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

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