Search in sources :

Example 16 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class AzureClient method getBlobContainer.

public CloudBlobContainer getBlobContainer(String resourceGroup, String storageName, String containerName) {
    LOGGER.debug("get blob container: RG={}, storageName={}, containerName={}", resourceGroup, storageName, containerName);
    List<StorageAccountKey> keys = getStorageAccountKeys(resourceGroup, storageName);
    String storageConnectionString = String.format("DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s", storageName, keys.get(0).value());
    try {
        CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
        CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
        return blobClient.getContainerReference(containerName);
    } catch (URISyntaxException e) {
        throw new CloudConnectorException("can't get blob container, URI is not valid", e);
    } catch (InvalidKeyException e) {
        throw new CloudConnectorException("can't get blob container, credentials in the connection string contain an invalid key", e);
    } catch (StorageException e) {
        throw new CloudConnectorException("can't get blob container, storage service error occurred", e);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) StorageAccountKey(com.microsoft.azure.management.storage.StorageAccountKey) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 17 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class AzureClient method getImageBlobUri.

public String getImageBlobUri(String resourceGroup, String storageName, String containerName, String sourceBlob) {
    CloudBlobContainer blobContainer = getBlobContainer(resourceGroup, storageName, containerName);
    String vhdName = sourceBlob.substring(sourceBlob.lastIndexOf('/') + 1);
    try {
        CloudPageBlob pageBlobReference = blobContainer.getPageBlobReference(vhdName);
        return pageBlobReference.getUri().toString();
    } catch (URISyntaxException e) {
        throw new CloudConnectorException("can't get image blob uri, URI is not valid", e);
    } catch (StorageException e) {
        throw new CloudConnectorException("can't get image blob uri, storage service error occurred", e);
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob)

Example 18 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class GcpProvisionSetup method prepareImage.

@Override
public void prepareImage(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) {
    CloudCredential credential = authenticatedContext.getCloudCredential();
    CloudContext cloudContext = authenticatedContext.getCloudContext();
    try {
        String projectId = getProjectId(credential);
        String imageName = image.getImageName();
        Compute compute = buildCompute(credential);
        ImageList list = compute.images().list(projectId).execute();
        if (!containsSpecificImage(list, imageName)) {
            Storage storage = buildStorage(credential, cloudContext.getName());
            Bucket bucket = new Bucket();
            bucket.setName(String.format("%s-%s-%d", projectId, cloudContext.getName(), cloudContext.getId()));
            bucket.setStorageClass("STANDARD");
            try {
                Buckets.Insert ins = storage.buckets().insert(projectId, bucket);
                ins.execute();
            } catch (GoogleJsonResponseException ex) {
                if (ex.getStatusCode() != HttpStatus.SC_CONFLICT) {
                    throw ex;
                }
            }
            String tarName = getTarName(imageName);
            Copy copy = storage.objects().copy(getBucket(imageName), tarName, bucket.getName(), tarName, new StorageObject());
            copy.execute();
            Image gcpApiImage = new Image();
            gcpApiImage.setName(getImageName(imageName));
            RawDisk rawDisk = new RawDisk();
            rawDisk.setSource(String.format("http://storage.googleapis.com/%s/%s", bucket.getName(), tarName));
            gcpApiImage.setRawDisk(rawDisk);
            Insert ins = compute.images().insert(projectId, gcpApiImage);
            ins.execute();
        }
    } catch (Exception e) {
        Long stackId = cloudContext.getId();
        String msg = String.format("Error occurred on %s stack during the setup: %s", stackId, e.getMessage());
        LOGGER.error(msg, e);
        throw new CloudConnectorException(msg, e);
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Image(com.google.api.services.compute.model.Image) Insert(com.google.api.services.compute.Compute.Images.Insert) Buckets(com.google.api.services.storage.Storage.Buckets) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException) ImageList(com.google.api.services.compute.model.ImageList) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Storage(com.google.api.services.storage.Storage) GcpStackUtil.buildStorage(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildStorage) GcpStackUtil.getBucket(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.getBucket) Bucket(com.google.api.services.storage.model.Bucket) Copy(com.google.api.services.storage.Storage.Objects.Copy) GcpStackUtil.buildCompute(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildCompute) Compute(com.google.api.services.compute.Compute) RawDisk(com.google.api.services.compute.model.Image.RawDisk)

Example 19 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class AbstractGcpResourceBuilder method checkError.

protected void checkError(Operation execute) {
    if (execute.getError() != null) {
        String msg = null;
        StringBuilder error = new StringBuilder();
        if (execute.getError().getErrors() != null) {
            for (Errors errors : execute.getError().getErrors()) {
                error.append(String.format("code: %s -> message: %s %s", errors.getCode(), errors.getMessage(), System.lineSeparator()));
            }
            msg = error.toString();
        }
        throw new CloudConnectorException(msg);
    }
}
Also used : Errors(com.google.api.services.compute.model.Operation.Error.Errors) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)

Example 20 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class OpenStackContextBuilder method contextInit.

@Override
public OpenStackContext contextInit(CloudContext cloudContext, AuthenticatedContext auth, Network network, List<CloudResource> resources, boolean build) {
    OpenStackContext openStackContext = new OpenStackContext(utils.getStackName(auth), cloudContext.getLocation(), PARALLEL_RESOURCE_REQUEST, build);
    if (openStackClient.isV2Keystone(auth)) {
        String v2TenantId = openStackClient.getV2TenantId(auth);
        openStackContext.putParameter(OpenStackConstants.TENANT_ID, v2TenantId);
    } else {
        throw new CloudConnectorException("In case on native openstack api only V2 keystone is supported");
    }
    if (resources != null) {
        for (CloudResource resource : resources) {
            switch(resource.getType()) {
                case OPENSTACK_SUBNET:
                    openStackContext.putParameter(OpenStackConstants.SUBNET_ID, resource.getReference());
                    break;
                case OPENSTACK_NETWORK:
                    openStackContext.putParameter(OpenStackConstants.NETWORK_ID, resource.getReference());
                    break;
                case OPENSTACK_SECURITY_GROUP:
                    openStackContext.addGroupResources(resource.getGroup(), Collections.singletonList(resource));
                    break;
                default:
                    LOGGER.debug("Resource is not used during context build: {}", resource);
            }
        }
    }
    openStackContext.putParameter(OpenStackConstants.FLOATING_IP_IDS, Collections.synchronizedList(new ArrayList<String>()));
    if (network != null) {
        openStackContext.putParameter(OpenStackConstants.PUBLIC_NET_ID, network.getStringParameter(OpenStackConstants.PUBLIC_NET_ID));
    }
    return openStackContext;
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)64 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)14 StorageException (com.microsoft.azure.storage.StorageException)11 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)9 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)9 AmazonServiceException (com.amazonaws.AmazonServiceException)8 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)8 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)8 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 URISyntaxException (java.net.URISyntaxException)7 ActionWentFailException (com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)6 HashMap (java.util.HashMap)6 CloudException (com.microsoft.azure.CloudException)5 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)5 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)4 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)3 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)3 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)3 Group (com.sequenceiq.cloudbreak.cloud.model.Group)3