Search in sources :

Example 31 with CloudResourceStatus

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

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

the class ResourceDeleteThread method call.

@Override
public ResourceRequestResult<List<CloudResourceStatus>> call() throws Exception {
    LOGGER.info("Deleting compute resource {}", resource);
    if (resource.getStatus() == CommonStatus.CREATED) {
        CloudResource deletedResource = builder.delete(context, auth, resource);
        if (deletedResource != null) {
            PollTask<List<CloudResourceStatus>> task = resourcePollTaskFactory.newPollResourceTask(builder, auth, Collections.singletonList(deletedResource), context, cancellable);
            List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
            deleteResource();
            return new ResourceRequestResult<>(FutureResult.SUCCESS, pollerResult);
        }
    }
    deleteResource();
    CloudResourceStatus status = new CloudResourceStatus(resource, ResourceStatus.DELETED);
    return new ResourceRequestResult<>(FutureResult.SUCCESS, Collections.singletonList(status));
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 33 with CloudResourceStatus

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

the class UpscaleStackHandler method accept.

@Override
public void accept(Event<UpscaleStackRequest> upscaleStackRequestEvent) {
    LOGGER.info("Received event: {}", upscaleStackRequestEvent);
    UpscaleStackRequest request = upscaleStackRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().upscale(ac, request.getCloudStack(), request.getResourceList());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        UpscaleStackResult result = ResourcesStatePollerResults.transformToUpscaleStackResult(statePollerResult, request);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(upscaleStackRequestEvent.getHeaders(), result));
        LOGGER.info("Upscale successfully finished for {}", cloudContext);
    } catch (Exception e) {
        UpscaleStackResult result = new UpscaleStackResult(e.getMessage(), e, request);
        request.getResult().onNext(result);
        eventBus.notify(CloudPlatformResult.failureSelector(UpscaleStackResult.class), new Event<>(upscaleStackRequestEvent.getHeaders(), result));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) UpscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackResult) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Event(reactor.bus.Event) UpscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Example 34 with CloudResourceStatus

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

the class LaunchStackHandler method accept.

@Override
public void accept(Event<LaunchStackRequest> launchStackRequestEvent) {
    LOGGER.info("Received event: {}", launchStackRequestEvent);
    LaunchStackRequest request = launchStackRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().launch(ac, request.getCloudStack(), persistenceNotifier, request.getAdjustmentType(), request.getThreshold());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        LaunchStackResult result = ResourcesStatePollerResults.transformToLaunchStackResult(request, statePollerResult);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(launchStackRequestEvent.getHeaders(), result));
        LOGGER.info("Launching the stack successfully finished for {}", cloudContext);
    } catch (Exception e) {
        LaunchStackResult failure = new LaunchStackResult(e, request);
        LOGGER.error("Error during launching the stack:", e);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(launchStackRequestEvent.getHeaders(), failure));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Event(reactor.bus.Event) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) LaunchStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackRequest)

Example 35 with CloudResourceStatus

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

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