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