Search in sources :

Example 26 with CloudResourceStatus

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

the class StackCreationService method removeFailedMetadata.

private List<CloudResourceStatus> removeFailedMetadata(Long stackId, Iterable<CloudResourceStatus> statuses, Group group) {
    Map<Long, CloudResourceStatus> failedResources = new HashMap<>();
    Set<Long> groupPrivateIds = getPrivateIds(group);
    for (CloudResourceStatus status : statuses) {
        Long privateId = status.getPrivateId();
        if (privateId != null && status.isFailed() && !failedResources.containsKey(privateId) && groupPrivateIds.contains(privateId)) {
            failedResources.put(privateId, status);
            instanceMetadataService.deleteInstanceRequest(stackId, privateId);
        }
    }
    return new ArrayList<>(failedResources.values());
}
Also used : HashMap(java.util.HashMap) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList)

Example 27 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus 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)

Example 28 with CloudResourceStatus

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

the class AbstractResourceConnector method terminate.

@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext auth, CloudStack stack, List<CloudResource> cloudResources) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    Platform platform = cloudContext.getPlatform();
    // context
    ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), cloudResources, false);
    // compute
    List<CloudResourceStatus> cloudResourceStatuses = computeResourceService.deleteResources(context, auth, cloudResources, false);
    // group
    List<CloudResourceStatus> groupStatuses = groupResourceService.deleteResources(context, auth, cloudResources, stack.getNetwork(), false);
    cloudResourceStatuses.addAll(groupStatuses);
    // network
    List<CloudResourceStatus> networkStatuses = networkResourceService.deleteResources(context, auth, cloudResources, stack.getNetwork(), false);
    cloudResourceStatuses.addAll(networkStatuses);
    return cloudResourceStatuses;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)

Example 29 with CloudResourceStatus

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

the class CloudFailureHandler method doRollbackAndDecreaseNodeCount.

private void doRollbackAndDecreaseNodeCount(AuthenticatedContext auth, List<CloudResourceStatus> statuses, Collection<Long> ids, Group group, ResourceBuilderContext ctx, ResourceBuilders resourceBuilders, Boolean upscale) {
    List<ComputeResourceBuilder> compute = resourceBuilders.compute(auth.getCloudContext().getPlatform());
    Collection<Future<ResourceRequestResult<List<CloudResourceStatus>>>> futures = new ArrayList<>();
    LOGGER.info(String.format("InstanceGroup %s node count decreased with one so the new node size is: %s", group.getName(), group.getInstancesSize()));
    if (getRemovableInstanceTemplates(group, ids).size() <= 0 && !upscale) {
        LOGGER.info("InstanceGroup node count lower than 1 which is incorrect so error will throw");
        throwError(statuses);
    } else {
        for (int i = compute.size() - 1; i >= 0; i--) {
            for (CloudResourceStatus cloudResourceStatus : statuses) {
                try {
                    if (compute.get(i).resourceType().equals(cloudResourceStatus.getCloudResource().getType())) {
                        ResourceDeleteThread thread = createThread(ResourceDeleteThread.NAME, ctx, auth, cloudResourceStatus.getCloudResource(), compute.get(i), false);
                        Future<ResourceRequestResult<List<CloudResourceStatus>>> future = resourceBuilderExecutor.submit(thread);
                        futures.add(future);
                        for (Future<ResourceRequestResult<List<CloudResourceStatus>>> future1 : futures) {
                            future1.get();
                        }
                        futures.clear();
                    }
                } catch (Exception e) {
                    LOGGER.info("Resource can not be deleted. Reason: {} ", e.getMessage());
                }
            }
        }
    }
}
Also used : ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)

Example 30 with CloudResourceStatus

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

the class ComputeResourceService method deleteResources.

public List<CloudResourceStatus> deleteResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, boolean cancellable) {
    List<CloudResourceStatus> results = new ArrayList<>();
    Collection<Future<ResourceRequestResult<List<CloudResourceStatus>>>> futures = new ArrayList<>();
    Platform platform = auth.getCloudContext().getPlatform();
    List<ComputeResourceBuilder> builders = resourceBuilders.compute(platform);
    int numberOfBuilders = builders.size();
    for (int i = numberOfBuilders - 1; i >= 0; i--) {
        ComputeResourceBuilder builder = builders.get(i);
        List<CloudResource> resourceList = getResources(builder.resourceType(), resources);
        for (CloudResource cloudResource : resourceList) {
            ResourceDeleteThread thread = createThread(ResourceDeleteThread.NAME, context, auth, cloudResource, builder, cancellable);
            Future<ResourceRequestResult<List<CloudResourceStatus>>> future = resourceBuilderExecutor.submit(thread);
            futures.add(future);
            if (isRequestFull(futures.size(), context)) {
                results.addAll(flatList(waitForRequests(futures).get(FutureResult.SUCCESS)));
            }
        }
        // wait for builder type to finish before starting the next one
        results.addAll(flatList(waitForRequests(futures).get(FutureResult.SUCCESS)));
    }
    return results;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) ArrayList(java.util.ArrayList) ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)43 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)29 ArrayList (java.util.ArrayList)18 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)14 List (java.util.List)11 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)9 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5 ResourceStatus (com.sequenceiq.cloudbreak.cloud.model.ResourceStatus)5 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)5 Group (com.sequenceiq.cloudbreak.cloud.model.Group)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 NetworkResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.NetworkResourceBuilder)4 CloudException (com.microsoft.azure.CloudException)3 Deployment (com.microsoft.azure.management.resources.Deployment)3 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)3 ComputeResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder)3 ResourceBuilderContext (com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)3