Search in sources :

Example 61 with CloudResource

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

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

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

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

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

the class GroupResourceService method deleteResources.

public List<CloudResourceStatus> deleteResources(ResourceBuilderContext context, AuthenticatedContext auth, Collection<CloudResource> resources, Network network, boolean cancellable) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    List<CloudResourceStatus> results = new ArrayList<>();
    List<GroupResourceBuilder> builderChain = resourceBuilders.group(cloudContext.getPlatform());
    for (int i = builderChain.size() - 1; i >= 0; i--) {
        GroupResourceBuilder 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 : 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)

Aggregations

CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)79 ArrayList (java.util.ArrayList)33 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)29 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)20 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)17 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)16 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)13 List (java.util.List)11 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)9 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)8 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)8 Location (com.sequenceiq.cloudbreak.cloud.model.Location)8 Group (com.sequenceiq.cloudbreak.cloud.model.Group)7 Operation (com.google.api.services.compute.model.Operation)6 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)6 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)6 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)6 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)6 Map (java.util.Map)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5