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));
}
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));
}
}
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));
}
}
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;
}
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;
}
Aggregations