Search in sources :

Example 1 with JsonValue

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

the class MemberStateImpl method fromJson.

@Override
@SuppressWarnings({ "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity", "checkstyle:methodlength" })
public void fromJson(JsonObject json) {
    address = getString(json, "address");
    String uuidString = getString(json, "uuid", null);
    uuid = uuidString != null ? UUID.fromString(uuidString) : null;
    String cpMemberUuidString = getString(json, "cpMemberUuid", null);
    cpMemberUuid = cpMemberUuidString != null ? UUID.fromString(cpMemberUuidString) : null;
    name = getString(json, "name", null);
    JsonArray jsonEndpoints = getArray(json, "endpoints");
    endpoints = new HashMap<>();
    for (JsonValue obj : jsonEndpoints) {
        JsonObject endpoint = obj.asObject();
        String id = endpoint.getString("id", null);
        ProtocolType type = ProtocolType.valueOf(endpoint.getString("protocol", "MEMBER"));
        JsonValue addr = endpoint.get("address");
        String host = addr.asObject().getString("host", "");
        int port = addr.asObject().getInt("port", 0);
        EndpointQualifier qualifier = EndpointQualifier.resolve(type, id);
        Address address = null;
        try {
            address = new Address(host, port);
        } catch (UnknownHostException e) {
            // ignore
            ignore(e);
        }
        endpoints.put(qualifier, address);
    }
    mapsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "mapStats")) {
        mapsWithStats.add(next.getName());
    }
    multiMapsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "multiMapStats")) {
        multiMapsWithStats.add(next.getName());
    }
    replicatedMapsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "replicatedMapStats")) {
        replicatedMapsWithStats.add(next.getName());
    }
    queuesWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "queueStats")) {
        queuesWithStats.add(next.getName());
    }
    topicsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "topicStats")) {
        topicsWithStats.add(next.getName());
    }
    reliableTopicsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "reliableTopicStats")) {
        reliableTopicsWithStats.add(next.getName());
    }
    pnCountersWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "pnCounterStats")) {
        pnCountersWithStats.add(next.getName());
    }
    executorsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "executorStats")) {
        executorsWithStats.add(next.getName());
    }
    scheduledExecutorsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "scheduledExecutorStats")) {
        scheduledExecutorsWithStats.add(next.getName());
    }
    durableExecutorsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "durableExecutorStats")) {
        durableExecutorsWithStats.add(next.getName());
    }
    cachesWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "cacheStats")) {
        cachesWithStats.add(next.getName());
    }
    flakeIdGeneratorsWithStats = new HashSet<>();
    for (JsonObject.Member next : getObject(json, "flakeIdStats")) {
        flakeIdGeneratorsWithStats.add(next.getName());
    }
    for (JsonObject.Member next : getObject(json, "wanStats", new JsonObject())) {
        putDeserializedIfSerializable(wanStats, next.getName(), next.getValue().asObject(), new LocalWanStatsImpl());
    }
    JsonArray jsonClients = getArray(json, "clients");
    clients = new ArrayList<>();
    for (JsonValue jsonClient : jsonClients) {
        final ClientEndPointDTO client = new ClientEndPointDTO();
        client.fromJson(jsonClient.asObject());
        clients.add(client);
    }
    JsonObject jsonOperationStats = getObject(json, "operationStats", null);
    if (jsonOperationStats != null) {
        operationStats = readJsonIfDeserializable(jsonOperationStats, operationStats);
    }
    JsonObject jsonMemberPartitionState = getObject(json, "memberPartitionState", null);
    if (jsonMemberPartitionState != null) {
        memberPartitionState = new MemberPartitionStateImpl();
        memberPartitionState.fromJson(jsonMemberPartitionState);
    }
    JsonObject jsonNodeState = getObject(json, "nodeState", null);
    if (jsonNodeState != null) {
        nodeState = new NodeStateImpl();
        nodeState.fromJson(jsonNodeState);
    }
    JsonObject jsonHotRestartState = getObject(json, "hotRestartState", null);
    if (jsonHotRestartState != null) {
        hotRestartState = new HotRestartStateImpl();
        hotRestartState.fromJson(jsonHotRestartState);
    }
    JsonObject jsonClusterHotRestartStatus = getObject(json, "clusterHotRestartStatus", null);
    if (jsonClusterHotRestartStatus != null) {
        clusterHotRestartStatus = new ClusterHotRestartStatusDTO();
        clusterHotRestartStatus.fromJson(jsonClusterHotRestartStatus);
    }
    clientStats = new HashMap<>();
    for (JsonObject.Member next : getObject(json, "clientStats")) {
        clientStats.put(UUID.fromString(next.getName()), next.getValue().asString());
    }
}
Also used : Address(com.hazelcast.cluster.Address) UnknownHostException(java.net.UnknownHostException) ClientEndPointDTO(com.hazelcast.internal.management.dto.ClientEndPointDTO) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) JsonUtil.getString(com.hazelcast.internal.util.JsonUtil.getString) JsonArray(com.hazelcast.internal.json.JsonArray) ProtocolType(com.hazelcast.instance.ProtocolType) ClusterHotRestartStatusDTO(com.hazelcast.internal.management.dto.ClusterHotRestartStatusDTO)

Example 2 with JsonValue

use of com.hazelcast.internal.json.JsonValue 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 3 with JsonValue

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

the class MemberPartitionStateImpl method fromJson.

@Override
public void fromJson(JsonObject json) {
    final JsonArray jsonPartitions = getArray(json, "partitions");
    for (JsonValue jsonPartition : jsonPartitions) {
        partitions.add(jsonPartition.asInt());
    }
    memberStateSafe = getBoolean(json, "memberStateSafe");
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonValue(com.hazelcast.internal.json.JsonValue)

Example 4 with JsonValue

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

the class KubernetesApiEndpointProvider method extractServices.

public Map<EndpointAddress, String> extractServices(JsonObject endpointsListJson, List<EndpointAddress> privateAddresses) {
    Map<EndpointAddress, String> result = new HashMap<>();
    Set<EndpointAddress> left = new HashSet<>(privateAddresses);
    for (JsonValue item : toJsonArray(endpointsListJson.get("items"))) {
        String service = convertToString(item.asObject().get("metadata").asObject().get("name"));
        List<Endpoint> endpoints = parseEndpoints(item);
        // Service must point to exactly one endpoint address, otherwise the public IP would be ambiguous.
        if (endpoints.size() == 1) {
            EndpointAddress address = endpoints.get(0).getPrivateAddress();
            if (privateAddresses.contains(address)) {
                // If multiple services match the pod, then match service and pod names
                if (!result.containsKey(address) || service.equals(extractTargetRefName(item))) {
                    result.put(address, service);
                }
                left.remove(address);
            }
        }
    }
    if (!left.isEmpty()) {
        // At least one Hazelcast Member POD does not have a corresponding service.
        throw noCorrespondingServicesException(left);
    }
    return result;
}
Also used : Endpoint(com.hazelcast.kubernetes.KubernetesClient.Endpoint) HashMap(java.util.HashMap) JsonValue(com.hazelcast.internal.json.JsonValue) KubernetesApiProvider.convertToString(com.hazelcast.kubernetes.KubernetesApiProvider.convertToString) EndpointAddress(com.hazelcast.kubernetes.KubernetesClient.EndpointAddress) HashSet(java.util.HashSet)

Example 5 with JsonValue

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

the class KubernetesApiEndpointProvider method extractNodes.

private Map<EndpointAddress, String> extractNodes(JsonValue addressesJson, List<Integer> ports) {
    Map<EndpointAddress, String> result = new HashMap<>();
    for (JsonValue address : toJsonArray(addressesJson)) {
        String ip = address.asObject().get("ip").asString();
        String nodeName = KubernetesApiProvider.convertToString(address.asObject().get("nodeName"));
        for (Integer port : ports) {
            result.put(new EndpointAddress(ip, port), nodeName);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) JsonValue(com.hazelcast.internal.json.JsonValue) KubernetesApiProvider.convertToString(com.hazelcast.kubernetes.KubernetesApiProvider.convertToString) EndpointAddress(com.hazelcast.kubernetes.KubernetesClient.EndpointAddress)

Aggregations

JsonValue (com.hazelcast.internal.json.JsonValue)85 Test (org.junit.Test)36 JsonObject (com.hazelcast.internal.json.JsonObject)35 QuickTest (com.hazelcast.test.annotation.QuickTest)30 JsonArray (com.hazelcast.internal.json.JsonArray)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)25 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)20 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 KubernetesApiProvider.convertToString (com.hazelcast.kubernetes.KubernetesApiProvider.convertToString)6 EndpointAddress (com.hazelcast.kubernetes.KubernetesClient.EndpointAddress)6 HashSet (java.util.HashSet)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)5 SlowTest (com.hazelcast.test.annotation.SlowTest)5 Address (com.hazelcast.cluster.Address)4 CPMember (com.hazelcast.cp.CPMember)4 IOException (java.io.IOException)4 JsonUtil.fromJsonObject (com.hazelcast.internal.util.JsonUtil.fromJsonObject)3 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)3