Search in sources :

Example 51 with CloudConnectorException

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);
    }
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ArrayList(java.util.ArrayList) AwsInstanceView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceView) FreeMarkerTemplateUtils.processTemplateIntoString(com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils.processTemplateIntoString) IOException(java.io.IOException) Template(freemarker.template.Template) AwsGroupView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsGroupView)

Example 52 with CloudConnectorException

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());
                }
            }
        }
    }
}
Also used : DescribeSpotInstanceRequestsResult(com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsResult) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DescribeSpotInstanceRequestsRequest(com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsRequest) SpotInstanceRequest(com.amazonaws.services.ec2.model.SpotInstanceRequest)

Example 53 with CloudConnectorException

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);
    }
}
Also used : HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Network(com.sequenceiq.cloudbreak.cloud.model.Network) AzureInstanceCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureInstanceCredentialView) FreeMarkerTemplateUtils.processTemplateIntoString(com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils.processTemplateIntoString) IOException(java.io.IOException) AzureSecurityView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureSecurityView)

Example 54 with CloudConnectorException

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);
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) StorageException(com.microsoft.azure.storage.StorageException)

Example 55 with CloudConnectorException

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);
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) StorageException(com.microsoft.azure.storage.StorageException)

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