use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilder method build.
public String build(ModelContext context) {
Map<String, Object> model = new HashMap<>();
Collection<AwsGroupView> awsGroupViews = new ArrayList<>();
Collection<AwsGroupView> awsGatewayGroupViews = new ArrayList<>();
int i = 0;
boolean multigw = context.stack.getGroups().stream().filter(g -> g.getType() == InstanceGroupType.GATEWAY).count() > 1;
for (Group group : context.stack.getGroups()) {
AwsInstanceView awsInstanceView = new AwsInstanceView(group.getReferenceInstanceConfiguration().getTemplate());
String snapshotId = context.snapshotId.get(group.getName());
AwsGroupView groupView = new AwsGroupView(group.getInstancesSize(), group.getType().name(), awsInstanceView.getFlavor(), group.getName(), awsInstanceView.getVolumes().size(), awsInstanceView.isEncryptedVolumes(), awsInstanceView.getVolumeSize(), awsInstanceView.getVolumeType(), awsInstanceView.getSpotPrice(), group.getSecurity().getRules(), group.getSecurity().getCloudSecurityId(), getSubnetIds(context.existingSubnetIds, i, group, multigw), awsInstanceView.isKmsEnabled(), awsInstanceView.getKmsKey(), snapshotId);
awsGroupViews.add(groupView);
if (group.getType() == InstanceGroupType.GATEWAY) {
awsGatewayGroupViews.add(groupView);
}
i++;
}
model.put("instanceGroups", awsGroupViews);
model.put("gatewayGroups", awsGatewayGroupViews);
model.put("existingVPC", context.existingVPC);
model.put("existingIGW", context.existingIGW);
model.put("existingSubnet", !isNullOrEmptyList(context.existingSubnetCidr));
model.put("enableInstanceProfile", context.enableInstanceProfile || context.instanceProfileAvailable);
model.put("existingRole", context.instanceProfileAvailable);
model.put("cbSubnet", (isNullOrEmptyList(context.existingSubnetCidr)) ? Lists.newArrayList(context.defaultSubnet) : context.existingSubnetCidr);
model.put("dedicatedInstances", areDedicatedInstancesRequested(context.stack));
model.put("availabilitySetNeeded", context.ac.getCloudContext().getLocation().getAvailabilityZone().value() != null);
model.put("mapPublicIpOnLaunch", context.mapPublicIpOnLaunch);
model.putAll(defaultCostTaggingService.prepareAllTagsForTemplate());
try {
String template = processTemplateIntoString(new Template("aws-template", context.template, freemarkerConfiguration), model);
return template.replaceAll("\\t|\\n| [\\s]+", "");
} catch (IOException | TemplateException e) {
throw new CloudConnectorException("Failed to process CloudFormation freemarker template", e);
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class ASGroupStatusCheckerTask method checkForSpotRequest.
private void checkForSpotRequest(Activity activity, AmazonEC2 amazonEC2Client) {
if (WAIT_FOR_SPOT_INSTANCES_STATUS_CODE.equals(activity.getStatusCode())) {
Pattern pattern = Pattern.compile(SPOT_ID_PATTERN);
Matcher matcher = pattern.matcher(activity.getStatusMessage());
if (matcher.find()) {
String spotId = matcher.group(0);
DescribeSpotInstanceRequestsResult spotResult = amazonEC2Client.describeSpotInstanceRequests(new DescribeSpotInstanceRequestsRequest().withSpotInstanceRequestIds(spotId));
Optional<SpotInstanceRequest> request = spotResult.getSpotInstanceRequests().stream().findFirst();
if (request.isPresent()) {
if (LOW_SPOT_PRICE_STATUS_CODE.equals(request.get().getStatus().getCode())) {
throw new CloudConnectorException(request.get().getStatus().getMessage());
}
}
}
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class AzureTemplateBuilder method build.
public String build(String stackName, String customImageId, AzureCredentialView armCredentialView, AzureStackView armStack, CloudContext cloudContext, CloudStack cloudStack) {
try {
String imageUrl = cloudStack.getImage().getImageName();
String imageName = imageUrl.substring(imageUrl.lastIndexOf('/') + 1);
Network network = cloudStack.getNetwork();
Map<String, Object> model = new HashMap<>();
AzureInstanceCredentialView azureInstanceCredentialView = new AzureInstanceCredentialView(cloudStack);
model.put("credential", azureInstanceCredentialView);
String rootDiskStorage = azureStorage.getImageStorageName(armCredentialView, cloudContext, cloudStack);
AzureSecurityView armSecurityView = new AzureSecurityView(cloudStack.getGroups());
// needed for pre 1.16.5 templates
model.put("existingSubnetName", azureUtils.getCustomSubnetIds(network).stream().findFirst().orElse(""));
model.put("customImageId", customImageId);
model.put("storage_account_name", rootDiskStorage);
model.put("image_storage_container_name", AzureStorage.IMAGES_CONTAINER);
model.put("storage_container_name", azureStorage.getDiskContainerName(cloudContext));
model.put("storage_vhd_name", imageName);
model.put("stackname", stackName);
model.put("region", cloudContext.getLocation().getRegion().value());
model.put("subnet1Prefix", network.getSubnet().getCidr());
model.put("groups", armStack.getGroups());
model.put("igs", armStack.getInstanceGroups());
model.put("securities", armSecurityView.getPorts());
model.put("securityGroups", armSecurityView.getSecurityGroupIds());
model.put("corecustomData", base64EncodedUserData(cloudStack.getImage().getUserDataByType(InstanceGroupType.CORE)));
model.put("gatewaycustomData", base64EncodedUserData(cloudStack.getImage().getUserDataByType(InstanceGroupType.GATEWAY)));
model.put("disablePasswordAuthentication", !azureInstanceCredentialView.passwordAuthenticationRequired());
model.put("existingVPC", azureUtils.isExistingNetwork(network));
model.put("resourceGroupName", azureUtils.getCustomResourceGroupName(network));
model.put("existingVNETName", azureUtils.getCustomNetworkId(network));
model.put("noPublicIp", azureUtils.isPrivateIp(network));
model.put("noFirewallRules", azureUtils.isNoSecurityGroups(network));
model.put("userDefinedTags", cloudStack.getTags());
model.putAll(defaultCostTaggingService.prepareAllTagsForTemplate());
String generatedTemplate = processTemplateIntoString(getTemplate(cloudStack), model);
LOGGER.debug("Generated Arm template: {}", generatedTemplate);
return generatedTemplate;
} catch (IOException | TemplateException e) {
throw new CloudConnectorException("Failed to process the Arm TemplateBuilder", e);
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class AzureClient method createContainerInStorage.
public void createContainerInStorage(String resourceGroup, String storageName, String containerName) {
LOGGER.debug("create container: RG={}, storageName={}, containerName={}", resourceGroup, storageName, containerName);
CloudBlobContainer container = getBlobContainer(resourceGroup, storageName, containerName);
try {
boolean created = container.createIfNotExists();
LOGGER.info("container created: " + created);
} catch (StorageException e) {
throw new CloudConnectorException("can't create container in storage, storage service error occurred", e);
}
setPublicPermissionOnContainer(resourceGroup, storageName, containerName);
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class AzureClient method deleteContainerInStorage.
public void deleteContainerInStorage(String resourceGroup, String storageName, String containerName) {
LOGGER.debug("delete container: RG={}, storageName={}, containerName={}", resourceGroup, storageName, containerName);
CloudBlobContainer container = getBlobContainer(resourceGroup, storageName, containerName);
try {
boolean existed = container.deleteIfExists();
LOGGER.info("is container existed: " + existed);
} catch (StorageException e) {
throw new CloudConnectorException("can't delete container in storage, storage service error occurred", e);
}
}
Aggregations