use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class AzureUtils method deleteManagedDisks.
@Retryable(backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
public void deleteManagedDisks(AzureClient azureClient, String resourceGroupName, Collection<String> managedDiskNames) {
LOGGER.info("Deleting managed disks: {}", managedDiskNames);
List<Completable> deleteCompletables = new ArrayList<>();
List<String> failedToDeleteManagedDisks = new ArrayList<>();
try {
for (String resourceId : managedDiskNames) {
deleteCompletables.add(azureClient.deleteManagedDiskAsync(resourceGroupName, resourceId).doOnError(throwable -> {
LOGGER.error("Error happened on azure during managed disk deletion: {}", resourceId, throwable);
failedToDeleteManagedDisks.add(resourceId);
}).subscribeOn(Schedulers.io()));
}
Completable.mergeDelayError(deleteCompletables).await();
} catch (CompositeException e) {
LOGGER.error("Error(s) occured while waiting for managed disks deletion: [{}]", e.getExceptions().stream().map(Throwable::getMessage).collect(Collectors.joining()));
throw new CloudbreakServiceException("Can't delete every managed disk: " + failedToDeleteManagedDisks);
} catch (RuntimeException e) {
LOGGER.error("Error occured while waiting for managed disks deletion: {}", e.getMessage(), e);
throw new CloudbreakServiceException("Can't delete every managed disk: " + failedToDeleteManagedDisks);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class AzureStorage method createStorage.
public StorageAccount createStorage(AzureClient client, String osStorageName, AzureDiskType storageType, String storageGroup, String region, Boolean encrypted, Map<String, String> tags) throws CloudException {
Optional<StorageAccount> storageAccountOptional = findStorageAccount(client, osStorageName);
if (storageAccountOptional.isEmpty()) {
StorageAccountParameters storageAccountParameters = new StorageAccountParameters(storageGroup, osStorageName, region, skuTypeResolver.resolveFromAzureDiskType(storageType), encrypted, tags);
return azureStorageAccountBuilderService.buildStorageAccount(client, storageAccountParameters);
} else {
StorageAccount storageAccount = storageAccountOptional.get();
String errorMessage = String.format("Storage account creation is not possible " + "as there is already a storage account with name %s in the resource group %s " + "in your subscription and the name must be unique across Azure. " + "In order to proceed, please delete that storage account.", storageAccount.name(), storageAccount.resourceGroupName());
LOGGER.warn(errorMessage);
throw new CloudbreakServiceException(errorMessage);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class CredentialService method getCredentialByEnvCrn.
public Credential getCredentialByEnvCrn(String envCrn) {
try {
CredentialResponse credentialResponse = credentialEndpoint.getByEnvironmentCrn(envCrn);
SecretResponse secretResponse = credentialResponse.getAttributes();
String attributes = secretService.getByResponse(secretResponse);
return new Credential(credentialResponse.getCloudPlatform(), credentialResponse.getName(), attributes, credentialResponse.getCrn(), credentialResponse.getAccountId());
} catch (WebApplicationException e) {
try (Response response = e.getResponse()) {
if (Response.Status.NOT_FOUND.getStatusCode() == response.getStatus()) {
LOGGER.error("Credential not found by environment CRN: {}", envCrn, e);
throw new BadRequestException(String.format("Credential not found by environment CRN: %s", envCrn), e);
}
String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
LOGGER.error("Failed to get credential for environment CRN [{}]: {}", envCrn, errorMessage);
throw new CloudbreakServiceException(String.format("Failed to get credential: %s", errorMessage), e);
}
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class CustomGcpDiskEncryptionCreatorService method encrypt.
private byte[] encrypt(PublicKey publicKey, byte[] data) {
try {
Cipher cipher = Cipher.getInstance(RSA_CIPHER_TRANSFORMATION);
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
return cipher.doFinal(data);
} catch (NoSuchAlgorithmException e) {
LOGGER.error("Failed to encrypt provided key, with Google public key. [{}] algorithm not supported.", RSA_CIPHER_TRANSFORMATION);
throw new CloudbreakServiceException("RSA algorithm not supported.", e);
} catch (NoSuchPaddingException e) {
LOGGER.error("Failed to encrypt provided key, with Google public key. [{}] padding not supported.", RSA_CIPHER_TRANSFORMATION);
throw new CloudbreakServiceException("OAEPWithSHA-1AndMGF1Padding padding not supported.", e);
} catch (InvalidKeyException e) {
LOGGER.info("Failed to encrypt provided key, with Google public key. Public key invalid: [{}].", publicKey);
throw new CloudbreakServiceException("Invalid public key.", e);
} catch (IllegalBlockSizeException e) {
LOGGER.info("Failed to encrypt provided key, with Google public key. Illegal block size: [{}].", e.getMessage());
throw new CloudbreakServiceException("Failed to encrypt key: illegal block size.", e);
} catch (BadPaddingException e) {
LOGGER.info("Failed to encrypt provided key, with Google public key. Bad padding: [{}].", e.getMessage());
throw new CloudbreakServiceException("Failed to encrypt key: bad padding", e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.
the class CustomGcpDiskEncryptionCreatorService method readPublicKeyFromCertificate.
private PublicKey readPublicKeyFromCertificate(byte[] keyBytes) {
try {
CertificateFactory factory = CertificateFactory.getInstance(CERTIFICATE_ENCODING);
X509Certificate certificate = (X509Certificate) factory.generateCertificate(new ByteArrayInputStream(keyBytes));
return certificate.getPublicKey();
} catch (CertificateException e) {
throw new CloudbreakServiceException("Failed to get public key from certificate", e);
}
}
Aggregations