Search in sources :

Example 1 with ComputeResourceBuilder

use of com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder 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 2 with ComputeResourceBuilder

use of com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder in project cloudbreak by hortonworks.

the class ComputeResourceService method stopStart.

private List<CloudVmInstanceStatus> stopStart(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, Iterable<CloudInstance> instances) {
    List<CloudVmInstanceStatus> results = new ArrayList<>();
    Collection<Future<ResourceRequestResult<List<CloudVmInstanceStatus>>>> futures = new ArrayList<>();
    Platform platform = auth.getCloudContext().getPlatform();
    List<ComputeResourceBuilder> builders = resourceBuilders.compute(platform);
    if (!context.isBuild()) {
        Collections.reverse(builders);
    }
    for (ComputeResourceBuilder builder : builders) {
        List<CloudResource> resourceList = getResources(builder.resourceType(), resources);
        for (CloudResource cloudResource : resourceList) {
            CloudInstance instance = getCloudInstance(cloudResource, instances);
            if (instance != null) {
                ResourceStopStartThread thread = createThread(ResourceStopStartThread.NAME, context, auth, cloudResource, instance, builder);
                Future<ResourceRequestResult<List<CloudVmInstanceStatus>>> future = resourceBuilderExecutor.submit(thread);
                futures.add(future);
                if (isRequestFull(futures.size(), context)) {
                    results.addAll(flatVmList(waitForRequests(futures).get(FutureResult.SUCCESS)));
                }
            } else {
                break;
            }
        }
    }
    results.addAll(flatVmList(waitForRequests(futures).get(FutureResult.SUCCESS)));
    return results;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 3 with ComputeResourceBuilder

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

Example 4 with ComputeResourceBuilder

use of com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder in project cloudbreak by hortonworks.

the class ResourceCreateThread method call.

@Override
public ResourceRequestResult<List<CloudResourceStatus>> call() {
    List<CloudResourceStatus> results = new ArrayList<>();
    Collection<CloudResource> buildableResources = new ArrayList<>();
    try {
        for (ComputeResourceBuilder builder : resourceBuilders.compute(auth.getCloudContext().getPlatform())) {
            LOGGER.info("Building {} resources of {} instance group", builder.resourceType(), group.getName());
            List<CloudResource> cloudResources = builder.create(context, privateId, auth, group, image);
            if (!cloudResources.isEmpty()) {
                buildableResources.addAll(cloudResources);
                createResource(auth, cloudResources);
                PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
                if (pollGroup != null && CANCELLED.equals(pollGroup)) {
                    throw new CancellationException(format("Building of %s has been cancelled", cloudResources));
                }
                List<CloudResource> resources = builder.build(context, privateId, auth, group, image, cloudResources, tags);
                updateResource(auth, resources);
                context.addComputeResources(privateId, resources);
                PollTask<List<CloudResourceStatus>> task = resourcePollTaskFactory.newPollResourceTask(builder, auth, resources, context, true);
                List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
                for (CloudResourceStatus resourceStatus : pollerResult) {
                    resourceStatus.setPrivateId(privateId);
                }
                results.addAll(pollerResult);
            }
        }
    } catch (CancellationException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.error("", e);
        results.clear();
        for (CloudResource buildableResource : buildableResources) {
            results.add(new CloudResourceStatus(buildableResource, ResourceStatus.FAILED, e.getMessage(), privateId));
        }
        return new ResourceRequestResult<>(FutureResult.FAILED, results);
    }
    return new ResourceRequestResult<>(FutureResult.SUCCESS, results);
}
Also used : ArrayList(java.util.ArrayList) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

ComputeResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)3 Future (java.util.concurrent.Future)3 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)1 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)1 PollGroup (com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup)1