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);
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations