Search in sources :

Example 1 with ResourceNotNeededException

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

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

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