Search in sources :

Example 6 with JsonObject

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

the class NodeStateImpl method fromJson.

@SuppressWarnings({ "checkstyle:npathcomplexity" })
@Override
public void fromJson(JsonObject json) {
    String jsonClusterState = getString(json, "clusterState", null);
    if (jsonClusterState != null) {
        clusterState = ClusterState.valueOf(jsonClusterState);
    }
    String jsonNodeState = getString(json, "nodeState", null);
    if (jsonNodeState != null) {
        nodeState = com.hazelcast.instance.impl.NodeState.valueOf(jsonNodeState);
    }
    String jsonClusterVersion = getString(json, "clusterVersion", null);
    if (jsonClusterVersion != null) {
        clusterVersion = Version.of(jsonClusterVersion);
    }
    String jsonNodeVersion = getString(json, "memberVersion", null);
    if (jsonNodeState != null) {
        memberVersion = MemberVersion.of(jsonNodeVersion);
    }
    weakSecretsConfigs = new HashMap<String, List<String>>();
    JsonValue jsonWeakConfigs = json.get("weakConfigs");
    if (jsonWeakConfigs != null) {
        JsonObject weakConfigsJsObj = jsonWeakConfigs.asObject();
        for (JsonObject.Member member : weakConfigsJsObj) {
            List<String> weaknesses = new ArrayList<String>();
            for (JsonValue value : member.getValue().asArray()) {
                weaknesses.add(value.asString());
            }
            weakSecretsConfigs.put(member.getName(), weaknesses);
        }
    }
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) ArrayList(java.util.ArrayList) JsonObject(com.hazelcast.internal.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) JsonUtil.getString(com.hazelcast.internal.util.JsonUtil.getString)

Example 7 with JsonObject

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

the class LocalWanPublisherStatsImpl method toJson.

@Override
public JsonObject toJson() {
    JsonObject root = new JsonObject();
    root.add("isConnected", connected);
    root.add("state", state.name());
    return root;
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject)

Example 8 with JsonObject

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

the class KubernetesApiEndpointSlicesProvider method extractNodes.

@Override
public Map<EndpointAddress, String> extractNodes(JsonObject jsonObject, List<EndpointAddress> privateAddresses) {
    Map<EndpointAddress, String> result = new HashMap<>();
    Set<EndpointAddress> left = new HashSet<>(privateAddresses);
    for (JsonValue item : toJsonArray(jsonObject.get("items"))) {
        List<Integer> ports = new ArrayList<>();
        for (JsonValue port : toJsonArray(item.asObject().get("ports"))) {
            ports.add(port.asObject().get("port").asInt());
        }
        for (JsonValue endpoint : toJsonArray(item.asObject().get("endpoints"))) {
            JsonObject endpointObject = endpoint.asObject();
            String nodeName = convertToString(endpointObject.get("nodeName"));
            Map<EndpointAddress, String> nodes = extractNodes(endpointObject.get("addresses"), ports, nodeName);
            for (Map.Entry<EndpointAddress, String> nodeEntry : nodes.entrySet()) {
                EndpointAddress address = nodeEntry.getKey();
                if (privateAddresses.contains(address)) {
                    result.put(address, nodes.get(address));
                    left.remove(address);
                }
            }
        }
    }
    if (!left.isEmpty()) {
        // At least one Hazelcast Member POD does not have 'nodeName' assigned.
        throw noNodeNameAssignedException(left);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) JsonValue(com.hazelcast.internal.json.JsonValue) ArrayList(java.util.ArrayList) JsonObject(com.hazelcast.internal.json.JsonObject) KubernetesApiProvider.convertToString(com.hazelcast.kubernetes.KubernetesApiProvider.convertToString) HashMap(java.util.HashMap) Map(java.util.Map) EndpointAddress(com.hazelcast.kubernetes.KubernetesClient.EndpointAddress) HashSet(java.util.HashSet)

Example 9 with JsonObject

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

the class KubernetesClient method extractZone.

private static String extractZone(JsonObject nodeJson) {
    JsonObject labels = nodeJson.get("metadata").asObject().get("labels").asObject();
    List<String> zoneLabels = asList("topology.kubernetes.io/zone", "failure-domain.kubernetes.io/zone", "failure-domain.beta.kubernetes.io/zone");
    for (String zoneLabel : zoneLabels) {
        JsonValue zone = labels.get(zoneLabel);
        if (zone != null) {
            return toString(zone);
        }
    }
    return null;
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 10 with JsonObject

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

the class KubernetesClient method extractLoadBalancerAddress.

private static String extractLoadBalancerAddress(JsonObject serviceResponse) {
    JsonObject ingress = serviceResponse.get("status").asObject().get("loadBalancer").asObject().get("ingress").asArray().get(0).asObject();
    JsonValue address = ingress.get("ip");
    if (address == null) {
        address = ingress.get("hostname");
    }
    return address.asString();
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) 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