Search in sources :

Example 1 with NetworkResourceBuilder

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

the class NetworkResourceService method deleteResources.

public List<CloudResourceStatus> deleteResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, Network network, boolean cancellable) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    List<CloudResourceStatus> results = new ArrayList<>();
    List<NetworkResourceBuilder> builderChain = resourceBuilders.network(cloudContext.getPlatform());
    for (int i = builderChain.size() - 1; i >= 0; i--) {
        NetworkResourceBuilder builder = builderChain.get(i);
        List<CloudResource> specificResources = getResources(resources, builder.resourceType());
        for (CloudResource resource : specificResources) {
            if (resource.getStatus() == CommonStatus.CREATED) {
                CloudResource deletedResource = builder.delete(context, auth, resource, network);
                if (deletedResource != null) {
                    PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(deletedResource), context, cancellable);
                    List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
                    results.addAll(pollerResult);
                }
            }
            resourceNotifier.notifyDeletion(resource, cloudContext);
        }
    }
    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)

Example 2 with NetworkResourceBuilder

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

the class NetworkResourceService method update.

public List<CloudResourceStatus> update(ResourceBuilderContext context, AuthenticatedContext auth, Network network, Security security, Iterable<CloudResource> networkResources) throws Exception {
    List<CloudResourceStatus> results = new ArrayList<>();
    CloudContext cloudContext = auth.getCloudContext();
    for (NetworkResourceBuilder builder : resourceBuilders.network(cloudContext.getPlatform())) {
        CloudResource resource = getResources(networkResources, builder.resourceType()).get(0);
        CloudResourceStatus status = builder.update(context, auth, network, security, resource);
        if (status != null) {
            PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(status.getCloudResource()), context, true);
            List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
            results.addAll(pollerResult);
        }
    }
    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)

Example 3 with NetworkResourceBuilder

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

the class GroupResourceService method update.

public List<CloudResourceStatus> update(ResourceBuilderContext context, AuthenticatedContext auth, Network network, Security security, Collection<CloudResource> groupResources) throws Exception {
    List<CloudResourceStatus> results = new ArrayList<>();
    CloudContext cloudContext = auth.getCloudContext();
    for (NetworkResourceBuilder builder : resourceBuilders.network(cloudContext.getPlatform())) {
        List<CloudResource> resources = getResources(groupResources, builder.resourceType());
        for (CloudResource resource : resources) {
            CloudResourceStatus status = builder.update(context, auth, network, security, resource);
            if (status != null) {
                PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(status.getCloudResource()), context, true);
                List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
                results.addAll(pollerResult);
            }
        }
    }
    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)

Example 4 with NetworkResourceBuilder

use of com.sequenceiq.cloudbreak.cloud.template.NetworkResourceBuilder 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)4 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)4 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)4 NetworkResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.NetworkResourceBuilder)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 PollGroup (com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup)1 ResourceNotNeededException (com.sequenceiq.cloudbreak.cloud.template.ResourceNotNeededException)1