Search in sources :

Example 26 with JsonObject

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

the class ConfigUpdateProgressEvent method toJson.

@Override
public JsonObject toJson() {
    JsonObject json = super.toJson();
    json.add("totalChangeCount", totalChangeCount);
    json.add("appliedChangeCount", appliedChangeCount);
    json.add("configName", namespace.getConfigName());
    json.add("sectionName", namespace.getSectionName());
    return json;
}
Also used : JsonObject(com.hazelcast.internal.json.JsonObject)

Example 27 with JsonObject

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

the class HazelcastJsonUpsertTargetTest method test_set.

@Test
public void test_set() {
    UpsertTarget target = new HazelcastJsonUpsertTarget();
    UpsertInjector nullInjector = target.createInjector("null", QueryDataType.OBJECT);
    UpsertInjector objectInjector = target.createInjector("object", QueryDataType.OBJECT);
    UpsertInjector stringInjector = target.createInjector("string", QueryDataType.VARCHAR);
    UpsertInjector booleanInjector = target.createInjector("boolean", QueryDataType.BOOLEAN);
    UpsertInjector byteInjector = target.createInjector("byte", QueryDataType.TINYINT);
    UpsertInjector shortInjector = target.createInjector("short", QueryDataType.SMALLINT);
    UpsertInjector intInjector = target.createInjector("int", QueryDataType.INT);
    UpsertInjector longInjector = target.createInjector("long", QueryDataType.BIGINT);
    UpsertInjector floatInjector = target.createInjector("float", QueryDataType.REAL);
    UpsertInjector doubleInjector = target.createInjector("double", QueryDataType.DOUBLE);
    UpsertInjector decimalInjector = target.createInjector("decimal", QueryDataType.DECIMAL);
    UpsertInjector timeInjector = target.createInjector("time", QueryDataType.TIME);
    UpsertInjector dateInjector = target.createInjector("date", QueryDataType.DATE);
    UpsertInjector timestampInjector = target.createInjector("timestamp", QueryDataType.TIMESTAMP);
    UpsertInjector timestampTzInjector = target.createInjector("timestampTz", QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME);
    target.init();
    nullInjector.set(null);
    objectInjector.set(new JsonObject());
    stringInjector.set("string");
    booleanInjector.set(true);
    byteInjector.set((byte) 127);
    shortInjector.set((short) 32767);
    intInjector.set(2147483647);
    longInjector.set(9223372036854775807L);
    floatInjector.set(1234567890.1F);
    doubleInjector.set(123451234567890.1D);
    decimalInjector.set(new BigDecimal("9223372036854775.123"));
    timeInjector.set(LocalTime.of(12, 23, 34));
    dateInjector.set(LocalDate.of(2020, 9, 9));
    timestampInjector.set(LocalDateTime.of(2020, 9, 9, 12, 23, 34, 100_000_000));
    timestampTzInjector.set(OffsetDateTime.of(2020, 9, 9, 12, 23, 34, 200_000_000, UTC));
    Object hazelcastJson = target.conclude();
    assertThat(hazelcastJson).isEqualTo(new HazelcastJsonValue("{" + "\"null\":null" + ",\"object\":{}" + ",\"string\":\"string\"" + ",\"boolean\":true" + ",\"byte\":127" + ",\"short\":32767" + ",\"int\":2147483647" + ",\"long\":9223372036854775807" + ",\"float\":1.23456794E9" + ",\"double\":1.234512345678901E14" + ",\"decimal\":\"9223372036854775.123\"" + ",\"time\":\"12:23:34\"" + ",\"date\":\"2020-09-09\"" + ",\"timestamp\":\"2020-09-09T12:23:34.100\"" + ",\"timestampTz\":\"2020-09-09T12:23:34.200Z\"" + "}"));
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) JsonObject(com.hazelcast.internal.json.JsonObject) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 28 with JsonObject

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

the class AzureComputeApi method parsePrivateIpResponse.

private Map<String, AzureNetworkInterface> parsePrivateIpResponse(String response) {
    Map<String, AzureNetworkInterface> interfaces = new HashMap<>();
    for (JsonValue item : toJsonArray(Json.parse(response).asObject().get("value"))) {
        Set<Tag> tagList = new HashSet<>();
        JsonObject tags = toJsonObject(item.asObject().get("tags"));
        for (String key : tags.asObject().names()) {
            tagList.add(new Tag(key, tags.asObject().getString(key, null)));
        }
        JsonObject properties = item.asObject().get("properties").asObject();
        if (properties.get("virtualMachine") != null) {
            for (JsonValue ipConfiguration : toJsonArray(properties.get("ipConfigurations"))) {
                JsonObject ipProps = ipConfiguration.asObject().get("properties").asObject();
                String privateIp = ipProps.getString("privateIPAddress", null);
                String publicIpId = toJsonObject(ipProps.get("publicIPAddress")).getString("id", null);
                if (!isNullOrEmptyAfterTrim(privateIp)) {
                    interfaces.put(privateIp, new AzureNetworkInterface(privateIp, publicIpId, tagList));
                }
            }
        }
    }
    return interfaces;
}
Also used : HashMap(java.util.HashMap) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 29 with JsonObject

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

the class AwsEcsApi method createBodyDescribeTasks.

private String createBodyDescribeTasks(String cluster, List<String> taskArns) {
    JsonArray jsonArray = new JsonArray();
    taskArns.stream().map(Json::value).forEach(jsonArray::add);
    return new JsonObject().add("tasks", jsonArray).add("cluster", cluster).toString();
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 30 with JsonObject

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

the class AzureMetadataApi method fillMetadata.

private void fillMetadata() {
    if (metadata.isEmpty()) {
        String urlString = String.format("%s/metadata/instance/compute?api-version=%s", endpoint, API_VERSION);
        String response = callGet(urlString);
        JsonObject jsonObject = Json.parse(response).asObject();
        for (String property : jsonObject.names()) {
            if (jsonObject.get(property).isString()) {
                metadata.put(property, jsonObject.get(property).asString());
            }
        }
    }
}
Also used : 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