Search in sources :

Example 1 with ResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.ResourceStatus in project cloudbreak by hortonworks.

the class AzureUtils method getTemplateStatus.

public CloudResourceStatus getTemplateStatus(CloudResource resource, Deployment templateDeployment, AzureClient access, String stackName) {
    String status = templateDeployment.provisioningState();
    LOGGER.info("Azure stack status of: {}  is: {}", resource.getName(), status);
    ResourceStatus resourceStatus = AzureStackStatus.mapResourceStatus(status);
    CloudResourceStatus armResourceStatus = null;
    if (ResourceStatus.FAILED.equals(resourceStatus)) {
        LOGGER.debug("Cloud resource status: {}", resourceStatus);
        try {
            // TODO: discuss with Doktorics why this is needed
            DeploymentOperations templateDeploymentOperations = access.getTemplateDeploymentOperations(stackName, stackName);
            for (DeploymentOperation deploymentOperation : templateDeploymentOperations.list()) {
                if ("Failed".equals(deploymentOperation.provisioningState())) {
                    String statusMessage = (String) deploymentOperation.statusMessage();
                    armResourceStatus = new CloudResourceStatus(resource, AzureStackStatus.mapResourceStatus(status), statusMessage);
                    break;
                }
            }
        } catch (RuntimeException e) {
            armResourceStatus = new CloudResourceStatus(resource, AzureStackStatus.mapResourceStatus(status), e.getMessage());
        }
    } else {
        LOGGER.debug("Cloud resource status: {}", resourceStatus);
        armResourceStatus = new CloudResourceStatus(resource, AzureStackStatus.mapResourceStatus(status));
    }
    return armResourceStatus;
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DeploymentOperation(com.microsoft.azure.management.resources.DeploymentOperation) DeploymentOperations(com.microsoft.azure.management.resources.DeploymentOperations)

Example 2 with ResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.ResourceStatus in project cloudbreak by hortonworks.

the class AbstractOpenStackResourceBuilder method checkResources.

protected List<CloudResourceStatus> checkResources(ResourceType type, OpenStackContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
    List<CloudResourceStatus> result = new ArrayList<>();
    for (CloudResource resource : resources) {
        LOGGER.info("Check {} resource: {}", type, resource);
        try {
            boolean finished = checkStatus(context, auth, resource);
            ResourceStatus successStatus = context.isBuild() ? ResourceStatus.CREATED : ResourceStatus.DELETED;
            result.add(new CloudResourceStatus(resource, finished ? successStatus : ResourceStatus.IN_PROGRESS));
            if (finished) {
                if (successStatus == ResourceStatus.CREATED) {
                    LOGGER.info("Creation of {} was successful", resource);
                } else {
                    LOGGER.info("Deletion of {} was successful", resource);
                }
            }
        } catch (OS4JException ex) {
            throw new OpenStackResourceException("Error during status check", type, resource.getName(), ex);
        }
    }
    return result;
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) OS4JException(org.openstack4j.api.exceptions.OS4JException)

Example 3 with ResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.ResourceStatus in project cloudbreak by hortonworks.

the class ResourceStatusLists method aggregate.

public static CloudResourceStatus aggregate(Iterable<CloudResourceStatus> cloudResourceStatuses) {
    ResourceStatus status = null;
    StringBuilder statusReason = new StringBuilder();
    for (CloudResourceStatus crs : cloudResourceStatuses) {
        ResourceStatus currentStatus = crs.getStatus();
        if (status == null) {
            status = currentStatus;
        }
        switch(currentStatus) {
            case FAILED:
                status = currentStatus;
                statusReason.append(crs.getStatusReason()).append('\n');
                break;
            default:
                if (currentStatus.isTransient()) {
                    status = currentStatus;
                }
        }
    }
    if (status == null) {
        status = ResourceStatus.FAILED;
        statusReason.append("Resources does not have any state");
    }
    return new CloudResourceStatus(null, status, statusReason.toString());
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)

Example 4 with ResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.ResourceStatus in project cloudbreak by hortonworks.

the class AbstractGcpResourceBuilder method checkResources.

protected List<CloudResourceStatus> checkResources(ResourceType type, GcpContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
    List<CloudResourceStatus> result = new ArrayList<>();
    for (CloudResource resource : resources) {
        LOGGER.info("Check {} resource: {}", type, resource);
        try {
            Operation operation = check(context, resource);
            boolean finished = operation == null || GcpStackUtil.isOperationFinished(operation);
            ResourceStatus successStatus = context.isBuild() ? ResourceStatus.CREATED : ResourceStatus.DELETED;
            result.add(new CloudResourceStatus(resource, finished ? successStatus : ResourceStatus.IN_PROGRESS));
            if (finished) {
                if (successStatus == ResourceStatus.CREATED) {
                    LOGGER.info("Creation of {} was successful", resource);
                } else {
                    LOGGER.info("Deletion of {} was successful", resource);
                }
            }
        } catch (Exception e) {
            CloudContext cloudContext = auth.getCloudContext();
            throw new GcpResourceException("Error during status check", type, cloudContext.getName(), cloudContext.getId(), resource.getName(), e);
        }
    }
    return result;
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Operation(com.google.api.services.compute.model.Operation) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException)

Aggregations

CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)4 ResourceStatus (com.sequenceiq.cloudbreak.cloud.model.ResourceStatus)4 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 ArrayList (java.util.ArrayList)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 Operation (com.google.api.services.compute.model.Operation)1 DeploymentOperation (com.microsoft.azure.management.resources.DeploymentOperation)1 DeploymentOperations (com.microsoft.azure.management.resources.DeploymentOperations)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 IOException (java.io.IOException)1 OS4JException (org.openstack4j.api.exceptions.OS4JException)1