use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class AzureStorageAccountBuilderService method buildStorageAccount.
public StorageAccount buildStorageAccount(AzureClient client, StorageAccountParameters storageAccountParameters) {
String resourceGroupName = storageAccountParameters.getResourceGroupName();
String storageAccountName = storageAccountParameters.getStorageAccountName();
try {
String template = azureStorageAccountTemplateBuilder.build(storageAccountParameters);
ResourceStatus templateDeploymentStatus = client.getTemplateDeploymentStatus(resourceGroupName, storageAccountName);
LOGGER.debug("Template deployment status retrieved: {}.", templateDeploymentStatus);
if (templateDeploymentStatus.isPermanent()) {
LOGGER.debug("Creating template deployment.");
String parameters = new Json(Map.of()).getValue();
Deployment templateDeployment = client.createTemplateDeployment(resourceGroupName, storageAccountName, template, parameters);
LOGGER.debug("Created template deployment for storage account: {}", templateDeployment.exportTemplate().template());
}
return client.getStorageAccountByGroup(resourceGroupName, storageAccountName);
} catch (CloudException e) {
throw azureUtils.convertToCloudConnectorException(e, "Storage account creation");
} catch (Exception e) {
String message = String.format("Could not create storage account %s in resource group %s%s", storageAccountName, resourceGroupName, getDeniedPolicyReasonIfApplicable(e));
LOGGER.warn(message, e);
throw new CloudConnectorException(message);
}
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityService method processHostCertsBatchResponse.
private void processHostCertsBatchResponse(ApiClient client, ApiBatchResponse apiBatchResponse) {
if (apiBatchResponse != null && apiBatchResponse.getSuccess() != null && apiBatchResponse.getItems() != null && apiBatchResponse.getSuccess()) {
List<BigDecimal> ids = apiBatchResponse.getItems().stream().map(bre -> new Json((String) bre.getResponse()).getSilent(ApiCommand.class).getId()).collect(Collectors.toList());
ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCommandList(stack, client, ids, "Rotate host certificates");
if (pollingResult.isExited()) {
throw new CancellationException("Cluster was terminated during rotation of host certificates");
} else if (pollingResult.isTimeout()) {
throw new ClouderaManagerOperationFailedException("Timeout while Cloudera Manager rotates the host certificates.");
}
} else {
throw new ClouderaManagerOperationFailedException("Host certificates rotation batch operation failed: " + apiBatchResponse);
}
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class ResourceAttributeUtil method getTypedAttributes.
public <T> Optional<T> getTypedAttributes(Resource resource) {
Json attributes = resource.getAttributes();
Optional<T> ret = Optional.empty();
try {
if (Objects.nonNull(attributes.getValue())) {
Map<String, Object> map = attributes.get(Map.class);
String clss = map.getOrDefault(CloudResource.ATTRIBUTE_TYPE, VolumeSetAttributes.class.getCanonicalName()).toString();
Class<T> attributeType = (Class<T>) Class.forName(clss);
ret = Optional.ofNullable(attributes.get(attributeType));
}
} catch (IOException e) {
throw new CloudbreakServiceException("Failed to parse attributes to type: " + attributes, e);
} catch (ClassNotFoundException e) {
LOGGER.debug("Cannot parse class: {}", e.getMessage());
}
return ret;
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class JaxRSUtil method transformErrorMessage.
private static String transformErrorMessage(String textResponse) {
try {
Json jsonResponse = new Json(textResponse);
Map<String, Object> mapResponse = jsonResponse.getMap();
Integer status = (Integer) mapResponse.get("status");
String code = (String) mapResponse.get("code");
if (status != null && StringUtils.isNotEmpty(code)) {
return ERROR_MESSAGE_MAP.getOrDefault(generateErrorMessageMapKey(status, code), textResponse);
} else {
return textResponse;
}
} catch (RuntimeException ex) {
return textResponse;
}
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class ClusterV4RequestToClusterConverterTest method testConvertClouderaManagerRequestWithNullRepo.
@Test
public void testConvertClouderaManagerRequestWithNullRepo() {
ClusterV4Request request = new ClusterV4Request();
request.setBlueprintName(BLUEPRINT);
blueprint.setStackType(StackType.CDH.name());
when(blueprintService.getByNameForWorkspaceAndLoadDefaultsIfNecessary(eq(BLUEPRINT), any())).thenReturn(blueprint);
ClouderaManagerV4Request cm = new ClouderaManagerV4Request();
ClouderaManagerProductV4Request cdp = new ClouderaManagerProductV4Request();
cdp.setName("cdp");
cdp.setParcel("cdp.parcel");
cdp.setVersion("cdp.version");
cdp.setCsd(List.of("cdp.csd"));
ClouderaManagerProductV4Request cdf = new ClouderaManagerProductV4Request();
cdf.setName("cdf");
cdf.setParcel("cdf.parcel");
cdf.setVersion("cdf.version");
cdf.setCsd(List.of("cdf.csd"));
List<ClouderaManagerProductV4Request> products = List.of(cdp, cdf);
cm.setProducts(products);
request.setCm(cm);
Cluster cluster = underTest.convert(request);
assertFalse(cluster.getComponents().isEmpty());
assertEquals(2, cluster.getComponents().size());
assertAll(cluster.getComponents().stream().map(component -> () -> assertEquals(ComponentType.CDH_PRODUCT_DETAILS, component.getComponentType())));
List<Json> cdps = cluster.getComponents().stream().map(ClusterComponent::getAttributes).filter(attr -> attr.getValue().contains("cdp")).collect(Collectors.toList());
Json cdpJson = new Json(cdp);
assertAll(() -> assertEquals(1, cdps.size()), () -> assertEquals(cdpJson, cdps.iterator().next()));
List<Json> cdfs = cluster.getComponents().stream().map(ClusterComponent::getAttributes).filter(attr -> attr.getValue().contains("cdf")).collect(Collectors.toList());
Json cdfJson = new Json(cdf);
assertAll(() -> assertEquals(1, cdfs.size()), () -> assertEquals(cdfJson, cdfs.iterator().next()));
}
Aggregations