Search in sources :

Example 6 with AzureClient

use of com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient in project cloudbreak by hortonworks.

the class AzureResourceConnector method collectResourcesToRemove.

@Override
public Map<String, Map<String, Object>> collectResourcesToRemove(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, List<CloudInstance> vms) {
    AzureClient client = ac.getParameter(AzureClient.class);
    AzureCredentialView azureCredentialView = new AzureCredentialView(ac.getCloudCredential());
    String stackName = azureUtils.getStackName(ac.getCloudContext());
    Map<String, Map<String, Object>> resp = new HashMap<>(vms.size());
    for (CloudInstance instance : vms) {
        resp.put(instance.getInstanceId(), collectInstanceResourcesToRemove(ac, stack, client, azureCredentialView, stackName, instance));
    }
    return resp;
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) HashMap(java.util.HashMap) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with AzureClient

use of com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient in project cloudbreak by hortonworks.

the class AzureResourceConnector method check.

@Override
public List<CloudResourceStatus> check(AuthenticatedContext authenticatedContext, List<CloudResource> resources) {
    List<CloudResourceStatus> result = new ArrayList<>();
    AzureClient client = authenticatedContext.getParameter(AzureClient.class);
    String stackName = azureUtils.getStackName(authenticatedContext.getCloudContext());
    for (CloudResource resource : resources) {
        switch(resource.getType()) {
            case ARM_TEMPLATE:
                LOGGER.info("Checking Azure group stack status of: {}", stackName);
                try {
                    CloudResourceStatus templateResourceStatus;
                    if (client.templateDeploymentExists(stackName, stackName)) {
                        Deployment resourceGroupDeployment = client.getTemplateDeployment(stackName, stackName);
                        templateResourceStatus = azureUtils.getTemplateStatus(resource, resourceGroupDeployment, client, stackName);
                    } else {
                        templateResourceStatus = new CloudResourceStatus(resource, ResourceStatus.DELETED);
                    }
                    result.add(templateResourceStatus);
                } catch (CloudException e) {
                    if (e.response().code() == AzureConstants.NOT_FOUND) {
                        result.add(new CloudResourceStatus(resource, ResourceStatus.DELETED));
                    } else {
                        throw new CloudConnectorException(e.body().message(), e);
                    }
                } catch (RuntimeException e) {
                    throw new CloudConnectorException(String.format("Invalid resource exception: %s", e.getMessage()), e);
                }
                break;
            case AZURE_NETWORK:
            case AZURE_SUBNET:
                break;
            default:
                throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
        }
    }
    return result;
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList) Deployment(com.microsoft.azure.management.resources.Deployment) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudException(com.microsoft.azure.CloudException)

Example 8 with AzureClient

use of com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient 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 9 with AzureClient

use of com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient 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 10 with AzureClient

use of com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient in project cloudbreak by hortonworks.

the class AzureSubnetValidator method validate.

@Override
public void validate(AuthenticatedContext ac, CloudStack cloudStack) {
    AzureClient client = ac.getParameter(AzureClient.class);
    azureUtils.validateSubnetRules(client, cloudStack.getNetwork());
}
Also used : AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)

Aggregations

AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)20 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)9 ArrayList (java.util.ArrayList)8 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)6 HashMap (java.util.HashMap)6 CloudException (com.microsoft.azure.CloudException)5 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)5 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)4 Cacheable (org.springframework.cache.annotation.Cacheable)4 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)3 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)3 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Region (com.sequenceiq.cloudbreak.cloud.model.Region)3 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)3 VmTypeMetaBuilder (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder)3 VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)3 ActionWentFailException (com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)3 List (java.util.List)3 Strings (com.google.common.base.Strings)2