use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class HazelcastCloudDiscoveryTest method testJsonResponseParse_withDifferentPortOnPrivateAddress.
@Test
public void testJsonResponseParse_withDifferentPortOnPrivateAddress() throws IOException {
JsonValue jsonResponse = Json.parse(" [{\"private-address\":\"100.96.5.1:5701\",\"public-address\":\"10.113.44.139:31115\"}," + "{\"private-address\":\"100.96.4.2:5701\",\"public-address\":\"10.113.44.130:31115\"} ]");
Map<Address, Address> privatePublicMap = HazelcastCloudDiscovery.parseJsonResponse(jsonResponse);
assertEquals(2, privatePublicMap.size());
assertEquals(new Address("10.113.44.139", 31115), privatePublicMap.get(new Address("100.96.5.1", 5701)));
assertEquals(new Address("10.113.44.130", 31115), privatePublicMap.get(new Address("100.96.4.2", 5701)));
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class ElasticCatClient method shards.
/**
* Returns list of shards for given indexes
*
* Only STARTED shards are returned.
*
* @param indices indexes to return shards for (wildcard format accepted)
*/
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public List<Shard> shards(String... indices) {
Map<String, String> idToAddress = nodes().stream().collect(toMap(Node::getId, Node::getHttpAddress));
try {
Request r = new Request("GET", "/_cat/shards/" + String.join(",", indices));
r.addParameter("format", "json");
r.addParameter("h", "id,index,shard,prirep,docs,state,ip,node");
Response res = withRetry(() -> client.performRequest(r), retries);
try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
JsonArray array = Json.parse(reader).asArray();
List<Shard> shards = new ArrayList<>(array.size());
for (JsonValue value : array) {
Optional<Shard> shard = convertToShard(value, idToAddress);
shard.ifPresent(shards::add);
}
LOG.log(FINE, "Shards " + shards);
return shards;
}
} catch (IOException e) {
throw new JetException("Could not get ES shards", e);
}
}
use of com.hazelcast.internal.json.JsonValue in project sonarqube by SonarSource.
the class InstalledActionTest method filter_by_plugin_type.
@Test
public void filter_by_plugin_type() throws IOException {
when(serverPluginRepository.getPlugins()).thenReturn(Arrays.asList(newInstalledPlugin(new PluginInfo("foo-external-1").setName("foo-external-1"), PluginType.EXTERNAL), newInstalledPlugin(new PluginInfo("foo-bundled-1").setName("foo-bundled-1"), PluginType.BUNDLED), newInstalledPlugin(new PluginInfo("foo-external-2").setName("foo-external-2"), PluginType.EXTERNAL)));
db.pluginDbTester().insertPlugin(p -> p.setKee("foo-external-1"), p -> p.setType(Type.EXTERNAL), p -> p.setUpdatedAt(100L));
db.pluginDbTester().insertPlugin(p -> p.setKee("foo-bundled-1"), p -> p.setType(Type.BUNDLED), p -> p.setUpdatedAt(101L));
db.pluginDbTester().insertPlugin(p -> p.setKee("foo-external-2"), p -> p.setType(Type.EXTERNAL), p -> p.setUpdatedAt(102L));
// no type param
String response = tester.newRequest().execute().getInput();
JsonArray jsonArray = Json.parse(response).asObject().get("plugins").asArray();
assertThat(jsonArray).hasSize(3);
assertThat(jsonArray).extracting(JsonValue::asObject).extracting(members -> members.get("key").asString()).containsExactlyInAnyOrder("foo-external-1", "foo-bundled-1", "foo-external-2");
// type param == BUNDLED
response = tester.newRequest().setParam("type", "BUNDLED").execute().getInput();
jsonArray = Json.parse(response).asObject().get("plugins").asArray();
assertThat(jsonArray).hasSize(1);
assertThat(jsonArray).extracting(JsonValue::asObject).extracting(members -> members.get("key").asString()).containsExactlyInAnyOrder("foo-bundled-1");
// type param == EXTERNAL
response = tester.newRequest().setParam("type", "EXTERNAL").execute().getInput();
jsonArray = Json.parse(response).asObject().get("plugins").asArray();
assertThat(jsonArray).hasSize(2);
assertThat(jsonArray).extracting(JsonValue::asObject).extracting(members -> members.get("key").asString()).containsExactlyInAnyOrder("foo-external-1", "foo-external-2");
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class HazelcastCloudDiscovery method parseJsonResponse.
static Map<Address, Address> parseJsonResponse(JsonValue jsonValue) throws IOException {
List<JsonValue> response = jsonValue.asArray().values();
Map<Address, Address> privateToPublicAddresses = new HashMap<Address, Address>();
for (JsonValue value : response) {
String privateAddress = value.asObject().get(PRIVATE_ADDRESS_PROPERTY).asString();
String publicAddress = value.asObject().get(PUBLIC_ADDRESS_PROPERTY).asString();
Address publicAddr = createAddress(publicAddress, -1);
// if it is not explicitly given, create the private address with public addresses port
Address privateAddr = createAddress(privateAddress, publicAddr.getPort());
privateToPublicAddresses.put(privateAddr, publicAddr);
}
return privateToPublicAddresses;
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class GcpComputeApi method zones.
List<String> zones(String project, String region, String accessToken) {
String url = String.format("%s/compute/v1/projects/%s/regions/%s?alt=json&fields=zones", endpoint, project, region);
String response = RestClient.create(url).withHeader("Authorization", String.format("OAuth %s", accessToken)).get().getBody();
JsonArray zoneUrls = toJsonArray(Json.parse(response).asObject().get("zones"));
List<String> zones = new ArrayList<>();
for (JsonValue value : zoneUrls) {
zones.add(lastPartOf(value.asString(), "/"));
}
return zones;
}
Aggregations