Search in sources :

Example 26 with CloudbreakServiceException

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);
    }
}
Also used : Completable(rx.Completable) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CompositeException(rx.exceptions.CompositeException) ArrayList(java.util.ArrayList) Retryable(org.springframework.retry.annotation.Retryable)

Example 27 with CloudbreakServiceException

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);
    }
}
Also used : StorageAccount(com.microsoft.azure.management.storage.StorageAccount) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StorageAccountParameters(com.sequenceiq.cloudbreak.cloud.azure.connector.resource.StorageAccountParameters)

Example 28 with CloudbreakServiceException

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);
        }
    }
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Response(javax.ws.rs.core.Response) Credential(com.sequenceiq.consumption.dto.Credential) WebApplicationException(javax.ws.rs.WebApplicationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) BadRequestException(javax.ws.rs.BadRequestException) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)

Example 29 with CloudbreakServiceException

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);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) Cipher(javax.crypto.Cipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException)

Example 30 with CloudbreakServiceException

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Aggregations

CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)142 Test (org.junit.jupiter.api.Test)25 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)24 List (java.util.List)20 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)18 IOException (java.io.IOException)18 Map (java.util.Map)18 ApiException (com.cloudera.api.swagger.client.ApiException)17 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)16 Collectors (java.util.stream.Collectors)15 Inject (javax.inject.Inject)15 Logger (org.slf4j.Logger)15 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)14 LoggerFactory (org.slf4j.LoggerFactory)14 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)13 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)12 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)12 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)12 Optional (java.util.Optional)12 Set (java.util.Set)12