Search in sources :

Example 1 with PollGroup

use of com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup in project cloudbreak by hortonworks.

the class ClusterBasedStatusCheckerTask method exitPolling.

@Override
public boolean exitPolling(T t) {
    try {
        Long stackId = t.getStack().getId();
        Long clusterId = t.getStack().getCluster().getId();
        PollGroup stackPollGroup = InMemoryStateStore.getStack(stackId);
        if (stackPollGroup == null || CANCELLED.equals(stackPollGroup)) {
            LOGGER.warn("Stack is getting terminated, polling is cancelled.");
            return true;
        }
        PollGroup clusterPollGroup = InMemoryStateStore.getCluster(clusterId);
        if (clusterPollGroup == null || CANCELLED.equals(clusterPollGroup)) {
            LOGGER.warn("Cluster is getting terminated, polling is cancelled.");
            return true;
        }
        return false;
    } catch (Exception ex) {
        LOGGER.error("Error occurred when check status checker exit criteria: ", ex);
        return true;
    }
}
Also used : PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup)

Example 2 with PollGroup

use of com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup in project cloudbreak by hortonworks.

the class GroupResourceService method buildResources.

public List<CloudResourceStatus> buildResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<Group> groups, Network network, Security security) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    List<CloudResourceStatus> results = new ArrayList<>();
    for (GroupResourceBuilder builder : resourceBuilders.group(cloudContext.getPlatform())) {
        PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
        if (pollGroup != null && CANCELLED.equals(pollGroup)) {
            break;
        }
        for (Group group : getOrderedCopy(groups)) {
            try {
                CloudResource buildableResource = builder.create(context, auth, group, network);
                createResource(auth, buildableResource);
                CloudResource resource = builder.build(context, auth, group, network, group.getSecurity(), buildableResource);
                updateResource(auth, resource);
                PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(resource), context, true);
                List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
                context.addGroupResources(group.getName(), Collections.singletonList(resource));
                results.addAll(pollerResult);
            } catch (ResourceNotNeededException e) {
                LOGGER.warn("Skipping resource creation: {}", e.getMessage());
            }
        }
    }
    return results;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GroupResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.GroupResourceBuilder) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) ResourceNotNeededException(com.sequenceiq.cloudbreak.cloud.template.ResourceNotNeededException)

Example 3 with PollGroup

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

Example 4 with PollGroup

use of com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup in project cloudbreak by hortonworks.

the class ResourceStopStartThread method call.

@Override
public ResourceRequestResult<List<CloudVmInstanceStatus>> call() throws Exception {
    LOGGER.info("{} compute resource {}", context.isBuild() ? "Starting" : "Stopping", resource);
    PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
    if (pollGroup != null && CANCELLED.equals(pollGroup)) {
        List<CloudVmInstanceStatus> result = createResult(InstanceStatus.UNKNOWN);
        return new ResourceRequestResult<>(FutureResult.SUCCESS, result);
    }
    CloudVmInstanceStatus status = context.isBuild() ? builder.start(context, auth, instance) : builder.stop(context, auth, instance);
    if (status != null) {
        PollTask<List<CloudVmInstanceStatus>> task = resourcePollTaskFactory.newPollComputeStatusTask(builder, auth, context, status.getCloudInstance());
        List<CloudVmInstanceStatus> pollResult = syncPollingScheduler.schedule(task);
        return new ResourceRequestResult<>(FutureResult.SUCCESS, pollResult);
    }
    return new ResourceRequestResult<>(FutureResult.SUCCESS, createResult(InstanceStatus.UNKNOWN));
}
Also used : CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) List(java.util.List) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup)

Example 5 with PollGroup

use of com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup in project cloudbreak by hortonworks.

the class NetworkResourceService method buildResources.

public List<CloudResourceStatus> buildResources(ResourceBuilderContext context, AuthenticatedContext auth, Network network, Security security) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    List<CloudResourceStatus> results = new ArrayList<>();
    for (NetworkResourceBuilder builder : resourceBuilders.network(cloudContext.getPlatform())) {
        PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
        if (pollGroup != null && CANCELLED.equals(pollGroup)) {
            break;
        }
        try {
            CloudResource buildableResource = builder.create(context, auth, network);
            createResource(auth, buildableResource);
            CloudResource resource = builder.build(context, auth, network, security, buildableResource);
            updateResource(auth, resource);
            PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(resource), context, true);
            List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
            results.addAll(pollerResult);
        } catch (ResourceNotNeededException e) {
            LOGGER.warn("Skipping resource creation: {}", e.getMessage());
        }
    }
    return results;
}
Also used : NetworkResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.NetworkResourceBuilder) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) ResourceNotNeededException(com.sequenceiq.cloudbreak.cloud.template.ResourceNotNeededException)

Aggregations

PollGroup (com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup)7 List (java.util.List)4 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)3 ArrayList (java.util.ArrayList)3 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 ResourceNotNeededException (com.sequenceiq.cloudbreak.cloud.template.ResourceNotNeededException)2 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)1 Group (com.sequenceiq.cloudbreak.cloud.model.Group)1 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)1 ComputeResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder)1 GroupResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.GroupResourceBuilder)1 NetworkResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.NetworkResourceBuilder)1