Search in sources :

Example 51 with JsonValue

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

the class PermissionConfigDTO method fromJson.

@Override
public void fromJson(JsonObject json) {
    permissionConfig = new PermissionConfig();
    permissionConfig.setType(PermissionConfig.PermissionType.getType(json.getString("permissionType", null)));
    permissionConfig.setName(json.get("name").asString());
    permissionConfig.setPrincipal(json.getString("principal", "*"));
    JsonValue endpointsVal = json.get("endpoints");
    if (endpointsVal != null) {
        Set<String> endpoints = new HashSet<>();
        for (JsonValue endpoint : endpointsVal.asArray().values()) {
            endpoints.add(endpoint.asString());
        }
        permissionConfig.setEndpoints(endpoints);
    }
    JsonValue actionsVal = json.get("actions");
    if (actionsVal != null) {
        Set<String> actions = new HashSet<>();
        for (JsonValue action : actionsVal.asArray().values()) {
            actions.add(action.asString());
        }
        permissionConfig.setActions(actions);
    }
}
Also used : PermissionConfig(com.hazelcast.config.PermissionConfig) JsonValue(com.hazelcast.internal.json.JsonValue) HashSet(java.util.HashSet)

Example 52 with JsonValue

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

the class WanConsumerConfigDTO method fromJson.

@Override
public void fromJson(JsonObject json) {
    config = new WanConsumerConfig();
    JsonValue persistWanReplicatedData = json.get("persistWanReplicatedData");
    if (persistWanReplicatedData != null && !persistWanReplicatedData.isNull()) {
        config.setPersistWanReplicatedData(persistWanReplicatedData.asBoolean());
    }
    JsonValue className = json.get("className");
    if (className != null && !className.isNull()) {
        config.setClassName(className.asString());
    }
    config.setProperties(fromJsonObject((JsonObject) json.get("properties")));
}
Also used : WanConsumerConfig(com.hazelcast.config.WanConsumerConfig) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) JsonUtil.fromJsonObject(com.hazelcast.internal.util.JsonUtil.fromJsonObject) JsonUtil.toJsonObject(com.hazelcast.internal.util.JsonUtil.toJsonObject)

Example 53 with JsonValue

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

the class WanBatchPublisherConfigDTO method deserializeAliasedDiscoveryConfig.

/**
 * Deserializes the aliased discovery config nested under the {@code tag} in the provided JSON.
 *
 * @param json the JSON object containing the serialized config
 * @param tag  the tag under which the config is nested
 * @return the deserialized config or {@code null} if the serialized config
 * was missing in the JSON object
 */
private AliasedDiscoveryConfig deserializeAliasedDiscoveryConfig(JsonObject json, String tag) {
    JsonValue configJson = json.get(tag);
    if (configJson != null && !configJson.isNull()) {
        AliasedDiscoveryConfigDTO dto = new AliasedDiscoveryConfigDTO(tag);
        dto.fromJson(configJson.asObject());
        return dto.getConfig();
    }
    return null;
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue)

Example 54 with JsonValue

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

the class WanBatchPublisherConfigDTO method fromJson.

@Override
@SuppressWarnings({ "checkstyle:methodlength", "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity" })
public void fromJson(JsonObject json) {
    config = new WanBatchPublisherConfig();
    consumeIfExists(json, "clusterName", v -> config.setClusterName(v.asString()));
    consumeIfExists(json, "publisherId", v -> config.setPublisherId(v.asString()));
    consumeIfExists(json, "batchSize", v -> config.setBatchSize(v.asInt()));
    consumeIfExists(json, "batchMaxDelayMillis", v -> config.setBatchMaxDelayMillis(v.asInt()));
    consumeIfExists(json, "responseTimeoutMillis", v -> config.setResponseTimeoutMillis(v.asInt()));
    consumeIfExists(json, "acknowledgeType", v -> config.setAcknowledgeType(WanAcknowledgeType.getById(v.asInt())));
    consumeIfExists(json, "initialPublisherState", v -> config.setInitialPublisherState(WanPublisherState.getByType((byte) v.asInt())));
    consumeIfExists(json, "snapshotEnabled", v -> config.setSnapshotEnabled(v.asBoolean()));
    consumeIfExists(json, "idleMaxParkNs", v -> config.setIdleMaxParkNs(v.asLong()));
    consumeIfExists(json, "idleMinParkNs", v -> config.setIdleMinParkNs(v.asLong()));
    consumeIfExists(json, "maxConcurrentInvocations", v -> config.setMaxConcurrentInvocations(v.asInt()));
    consumeIfExists(json, "discoveryPeriodSeconds", v -> config.setDiscoveryPeriodSeconds(v.asInt()));
    consumeIfExists(json, "useEndpointPrivateAddress", v -> config.setUseEndpointPrivateAddress(v.asBoolean()));
    consumeIfExists(json, "queueFullBehavior", v -> config.setQueueFullBehavior(WanQueueFullBehavior.getByType(v.asInt())));
    consumeIfExists(json, "maxTargetEndpoints", v -> config.setMaxTargetEndpoints(v.asInt()));
    consumeIfExists(json, "queueCapacity", v -> config.setQueueCapacity(v.asInt()));
    consumeIfExists(json, "targetEndpoints", v -> config.setTargetEndpoints(v.asString()));
    AwsConfig awsConfig = (AwsConfig) this.deserializeAliasedDiscoveryConfig(json, "aws");
    if (awsConfig != null) {
        config.setAwsConfig(awsConfig);
    }
    GcpConfig gcpConfig = (GcpConfig) this.deserializeAliasedDiscoveryConfig(json, "gcp");
    if (gcpConfig != null) {
        config.setGcpConfig(gcpConfig);
    }
    AzureConfig azureConfig = (AzureConfig) this.deserializeAliasedDiscoveryConfig(json, "azure");
    if (azureConfig != null) {
        config.setAzureConfig(azureConfig);
    }
    KubernetesConfig kubernetesConfig = (KubernetesConfig) this.deserializeAliasedDiscoveryConfig(json, "kubernetes");
    if (kubernetesConfig != null) {
        config.setKubernetesConfig(kubernetesConfig);
    }
    EurekaConfig eurekaConfig = (EurekaConfig) this.deserializeAliasedDiscoveryConfig(json, "eureka");
    if (eurekaConfig != null) {
        config.setEurekaConfig(eurekaConfig);
    }
    JsonValue discoveryJson = json.get("discovery");
    if (discoveryJson != null && !discoveryJson.isNull()) {
        DiscoveryConfigDTO discoveryDTO = new DiscoveryConfigDTO();
        discoveryDTO.fromJson(discoveryJson.asObject());
        config.setDiscoveryConfig(discoveryDTO.getConfig());
    }
    JsonValue syncJson = json.get("sync");
    if (syncJson != null && !syncJson.isNull()) {
        WanSyncConfigDTO syncDTO = new WanSyncConfigDTO();
        syncDTO.fromJson(syncJson.asObject());
        config.setSyncConfig(syncDTO.getConfig());
    }
    consumeIfExists(json, "endpoint", v -> config.setEndpoint(v.asString()));
    config.setProperties(fromJsonObject((JsonObject) json.get("properties")));
}
Also used : WanBatchPublisherConfig(com.hazelcast.config.WanBatchPublisherConfig) EurekaConfig(com.hazelcast.config.EurekaConfig) AwsConfig(com.hazelcast.config.AwsConfig) AzureConfig(com.hazelcast.config.AzureConfig) KubernetesConfig(com.hazelcast.config.KubernetesConfig) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) JsonUtil.fromJsonObject(com.hazelcast.internal.util.JsonUtil.fromJsonObject) JsonUtil.toJsonObject(com.hazelcast.internal.util.JsonUtil.toJsonObject) GcpConfig(com.hazelcast.config.GcpConfig)

Example 55 with JsonValue

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

the class WanReplicationConfigDTO method fromJson.

@Override
public void fromJson(JsonObject json) {
    config = new WanReplicationConfig();
    JsonValue name = json.get("name");
    if (name != null) {
        config.setName(name.asString());
    }
    JsonValue batchPublishers = json.get("batchPublishers");
    if (batchPublishers != null && !batchPublishers.isNull()) {
        for (JsonValue jsonValue : batchPublishers.asArray()) {
            WanBatchPublisherConfigDTO dto = new WanBatchPublisherConfigDTO();
            dto.fromJson(jsonValue.asObject());
            config.addBatchReplicationPublisherConfig(dto.getConfig());
        }
    }
    JsonValue customPublishers = json.get("customPublishers");
    if (customPublishers != null && !customPublishers.isNull()) {
        for (JsonValue jsonValue : customPublishers.asArray()) {
            CustomWanPublisherConfigDTO dto = new CustomWanPublisherConfigDTO();
            dto.fromJson(jsonValue.asObject());
            config.addCustomPublisherConfig(dto.getConfig());
        }
    }
    JsonValue consumer = json.get("consumer");
    if (consumer != null && !consumer.isNull()) {
        WanConsumerConfigDTO consumerDTO = new WanConsumerConfigDTO();
        consumerDTO.fromJson(consumer.asObject());
        config.setConsumerConfig(consumerDTO.getConfig());
    }
}
Also used : WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) JsonValue(com.hazelcast.internal.json.JsonValue)

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