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