Search in sources :

Example 11 with CloudConnectorException

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

the class AzureResourceGroupValidator method validate.

@Override
public void validate(AuthenticatedContext ac, CloudStack cloudStack) {
    AzureClient client = ac.getParameter(AzureClient.class);
    String resourceGroupName = azureUtils.getResourceGroupName(ac.getCloudContext());
    boolean exists = client.resourceGroupExists(resourceGroupName);
    if (exists) {
        throw new CloudConnectorException(String.format("Resource group is already exists with the given name: %s", resourceGroupName));
    }
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)

Example 12 with CloudConnectorException

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

the class AzureSetup method prepareImage.

@Override
public void prepareImage(AuthenticatedContext ac, CloudStack stack, Image image) {
    LOGGER.info("prepare image: {}", image);
    String imageResourceGroupName = armStorage.getImageResourceGroupName(ac.getCloudContext(), stack);
    String region = ac.getCloudContext().getLocation().getRegion().value();
    AzureClient client = ac.getParameter(AzureClient.class);
    try {
        copyVhdImageIfNecessary(ac, stack, image, imageResourceGroupName, region, client);
    } catch (Exception ex) {
        LOGGER.error("Could not create image with the specified parameters", ex);
        throw new CloudConnectorException("Image creation failed because " + image.getImageName() + " does not exist or Cloudbreak could not reach.", ex);
    }
    LOGGER.debug("prepare image has been executed");
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) URISyntaxException(java.net.URISyntaxException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) StorageException(com.microsoft.azure.storage.StorageException) UnknownHostException(java.net.UnknownHostException) InvalidKeyException(java.security.InvalidKeyException)

Example 13 with CloudConnectorException

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

the class AzureSetup method validateWasbFileSystem.

private void validateWasbFileSystem(FileSystem fileSystem, String fileSystemType) throws URISyntaxException, InvalidKeyException, StorageException {
    String accountName = fileSystem.getParameter(FileSystemConfiguration.ACCOUNT_NAME, String.class);
    String accountKey = fileSystem.getParameter(FileSystemConfiguration.ACCOUNT_KEY, String.class);
    String connectionString = "DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey;
    CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString);
    CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
    CloudBlobContainer containerReference = blobClient.getContainerReference(TEST_CONTAINER + System.nanoTime());
    try {
        containerReference.createIfNotExists();
        containerReference.delete();
    } catch (StorageException e) {
        if (e.getCause() instanceof UnknownHostException) {
            throw new CloudConnectorException("The provided account does not belong to a valid storage account");
        }
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) UnknownHostException(java.net.UnknownHostException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) StorageException(com.microsoft.azure.storage.StorageException)

Example 14 with CloudConnectorException

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

the class AzureUtils method validateSubnetRules.

public void validateSubnetRules(AzureClient client, Network network) {
    if (isExistingNetwork(network)) {
        String resourceGroupName = getCustomResourceGroupName(network);
        String networkId = getCustomNetworkId(network);
        Collection<String> subnetIds = getCustomSubnetIds(network);
        for (String subnetId : subnetIds) {
            try {
                Subnet subnet = client.getSubnetProperties(resourceGroupName, networkId, subnetId);
                if (subnet == null) {
                    throw new CloudConnectorException(String.format("Subnet [%s] does not found with resourceGroupName [%s] and network [%s]", subnetId, resourceGroupName, networkId));
                }
                NetworkSecurityGroup networkSecurityGroup = subnet.getNetworkSecurityGroup();
                if (networkSecurityGroup != null) {
                    validateSecurityGroup(client, networkSecurityGroup);
                }
            } catch (RuntimeException e) {
                throw new CloudConnectorException("Subnet validation failed, cause: " + e.getMessage(), e);
            }
        }
    }
}
Also used : NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Subnet(com.microsoft.azure.management.network.Subnet)

Example 15 with CloudConnectorException

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

the class AzureUtils method validateSecurityGroup.

private void validateSecurityGroup(AzureClient client, HasId networkSecurityGroup) {
    String securityGroupId = networkSecurityGroup.id();
    String[] parts = securityGroupId.split("/");
    if (parts.length != ID_SEGMENTS) {
        LOGGER.info("Cannot get the security group's properties, id: {}", securityGroupId);
        return;
    }
    try {
        NetworkSecurityGroup securityGroup = client.getSecurityGroupProperties(parts[RG_PART], parts[SEC_GROUP_PART]);
        LOGGER.info("Retrieved security group properties: {}", securityGroup);
        Map<String, NetworkSecurityRule> securityRules = securityGroup.securityRules();
        boolean port22Found = false;
        boolean port443Found = false;
        for (NetworkSecurityRule securityRule : securityRules.values()) {
            if (isValidInboundRule(securityRule)) {
                String destinationPortRange = securityRule.destinationPortRange();
                if ("*".equals(destinationPortRange)) {
                    return;
                }
                String[] range = destinationPortRange.split("-");
                port443Found = port443Found || isPortFound(PORT_443, range);
                port22Found = port22Found || isPortFound(PORT_22, range);
                if (port22Found && port443Found) {
                    return;
                }
            }
        }
    } catch (RuntimeException e) {
        throw new CloudConnectorException("Validating security group failed.", e);
    }
    throw new CloudConnectorException("The specified subnet's security group does not allow traffic for port 22 and/or 443");
}
Also used : NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) NetworkSecurityRule(com.microsoft.azure.management.network.NetworkSecurityRule)

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