use of com.hazelcast.internal.json.JsonObject in project sonarqube by SonarSource.
the class InstalledActionTest method empty_fields_are_not_serialized_to_json.
@Test
public void empty_fields_are_not_serialized_to_json() throws IOException {
when(serverPluginRepository.getPlugins()).thenReturn(singletonList(newInstalledPlugin(new PluginInfo("foo").setName(null).setDescription(null).setLicense(null).setOrganizationName(null).setOrganizationUrl(null).setImplementationBuild(null).setHomepageUrl(null).setIssueTrackerUrl(null))));
db.pluginDbTester().insertPlugin(p -> p.setKee("foo"), p -> p.setType(Type.EXTERNAL), p -> p.setUpdatedAt(100L));
String response = tester.newRequest().execute().getInput();
JsonObject json = Json.parse(response).asObject().get("plugins").asArray().get(0).asObject();
assertThat(json.get("key")).isNotNull();
assertThat(json.get("name")).isNotNull();
assertThat(json.get("description")).isNull();
assertThat(json.get("license")).isNull();
assertThat(json.get("organizationName")).isNull();
assertThat(json.get("organizationUrl")).isNull();
assertThat(json.get("homepageUrl")).isNull();
assertThat(json.get("issueTrackerUrl")).isNull();
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class AwsEcsApi method createBodyListTasks.
private String createBodyListTasks(String cluster) {
JsonObject body = new JsonObject();
body.add("cluster", cluster);
if (!StringUtil.isNullOrEmptyAfterTrim(awsConfig.getFamily())) {
body.add("family", awsConfig.getFamily());
}
if (!StringUtil.isNullOrEmptyAfterTrim(awsConfig.getServiceName())) {
body.add("serviceName", awsConfig.getServiceName());
}
return body.toString();
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class AwsMetadataApi method parseEcsMetadata.
private EcsMetadata parseEcsMetadata(String response) {
JsonObject metadata = Json.parse(response).asObject();
JsonObject labels = metadata.get("Labels").asObject();
String taskArn = labels.get("com.amazonaws.ecs.task-arn").asString();
String clusterArn = labels.get("com.amazonaws.ecs.cluster").asString();
return new EcsMetadata(taskArn, clusterArn);
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class KubernetesApiEndpointProvider method extractNodes.
public Map<EndpointAddress, String> extractNodes(JsonObject endpointsListJson, List<EndpointAddress> privateAddresses) {
Map<EndpointAddress, String> result = new HashMap<>();
Set<EndpointAddress> left = new HashSet<>(privateAddresses);
for (JsonValue item : toJsonArray(endpointsListJson.get("items"))) {
for (JsonValue subset : toJsonArray(item.asObject().get("subsets"))) {
JsonObject subsetObject = subset.asObject();
List<Integer> ports = new ArrayList<>();
for (JsonValue port : toJsonArray(subsetObject.get("ports"))) {
ports.add(port.asObject().get("port").asInt());
}
Map<EndpointAddress, String> nodes = new HashMap<>();
nodes.putAll(extractNodes(subsetObject.get("addresses"), ports));
nodes.putAll(extractNodes(subsetObject.get("notReadyAddresses"), ports));
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;
}
use of com.hazelcast.internal.json.JsonObject in project hazelcast by hazelcast.
the class KubernetesClient method enrichWithPublicAddresses.
/**
* Tries to add public addresses to the endpoints.
* <p>
* If it's not possible, then returns the input parameter.
* <p>
* Assigning public IPs must meet one of the following requirements:
* <ul>
* <li>Each POD must be exposed with a separate LoadBalancer service OR</li>
* <li>Each POD must be exposed with a separate NodePort service and Kubernetes nodes must have external IPs</li>
* </ul>
* <p>
* The algorithm to fetch public IPs is as follows:
* <ol>
* <li>Use Kubernetes API (/endpoints) to find dedicated services for each POD</li>
* <li>For each POD:
* <ol>
* <li>Use Kubernetes API (/services) to find the LoadBalancer External IP and Service Port</li>
* <li>If not found, then use Kubernetes API (/nodes) to find External IP of the Node</li>
* </ol>
* </li>
* </ol>
*/
private List<Endpoint> enrichWithPublicAddresses(List<Endpoint> endpoints) {
if (exposeExternallyMode == ExposeExternallyMode.DISABLED) {
return endpoints;
}
try {
String endpointsUrl = String.format(apiProvider.getEndpointsUrlString(), kubernetesMaster, namespace);
if (!StringUtil.isNullOrEmptyAfterTrim(servicePerPodLabelName) && !StringUtil.isNullOrEmptyAfterTrim(servicePerPodLabelValue)) {
endpointsUrl += String.format("?labelSelector=%s=%s", servicePerPodLabelName, servicePerPodLabelValue);
}
JsonObject endpointsJson = callGet(endpointsUrl);
List<EndpointAddress> privateAddresses = privateAddresses(endpoints);
Map<EndpointAddress, String> services = apiProvider.extractServices(endpointsJson, privateAddresses);
Map<EndpointAddress, String> nodes = apiProvider.extractNodes(endpointsJson, privateAddresses);
Map<EndpointAddress, String> publicIps = new HashMap<>();
Map<EndpointAddress, Integer> publicPorts = new HashMap<>();
Map<String, String> cachedNodePublicIps = new HashMap<>();
for (Map.Entry<EndpointAddress, String> serviceEntry : services.entrySet()) {
EndpointAddress privateAddress = serviceEntry.getKey();
String service = serviceEntry.getValue();
String serviceUrl = String.format("%s/api/v1/namespaces/%s/services/%s", kubernetesMaster, namespace, service);
JsonObject serviceJson = callGet(serviceUrl);
try {
String loadBalancerAddress = extractLoadBalancerAddress(serviceJson);
Integer servicePort = extractServicePort(serviceJson);
publicIps.put(privateAddress, loadBalancerAddress);
publicPorts.put(privateAddress, servicePort);
} catch (Exception e) {
// Load Balancer public IP cannot be found, try using NodePort.
Integer nodePort = extractNodePort(serviceJson);
String node = nodes.get(privateAddress);
String nodePublicAddress;
if (cachedNodePublicIps.containsKey(node)) {
nodePublicAddress = cachedNodePublicIps.get(node);
} else {
nodePublicAddress = externalAddressForNode(node);
cachedNodePublicIps.put(node, nodePublicAddress);
}
publicIps.put(privateAddress, nodePublicAddress);
publicPorts.put(privateAddress, nodePort);
}
}
return createEndpoints(endpoints, publicIps, publicPorts);
} catch (Exception e) {
if (exposeExternallyMode == ExposeExternallyMode.ENABLED) {
throw e;
}
// If expose-externally not set (exposeExternallyMode == ExposeExternallyMode.AUTO), silently ignore any exception
LOGGER.finest(e);
// Log warning only once.
if (!isNoPublicIpAlreadyLogged) {
LOGGER.warning("Cannot fetch public IPs of Hazelcast Member PODs, you won't be able to use Hazelcast Smart Client from " + "outside of the Kubernetes network");
isNoPublicIpAlreadyLogged = true;
}
return endpoints;
}
}
Aggregations