use of com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder in project cloudbreak by hortonworks.
the class CloudFailureHandler method doRollbackAndDecreaseNodeCount.
private void doRollbackAndDecreaseNodeCount(AuthenticatedContext auth, List<CloudResourceStatus> statuses, Collection<Long> ids, Group group, ResourceBuilderContext ctx, ResourceBuilders resourceBuilders, Boolean upscale) {
List<ComputeResourceBuilder> compute = resourceBuilders.compute(auth.getCloudContext().getPlatform());
Collection<Future<ResourceRequestResult<List<CloudResourceStatus>>>> futures = new ArrayList<>();
LOGGER.info(String.format("InstanceGroup %s node count decreased with one so the new node size is: %s", group.getName(), group.getInstancesSize()));
if (getRemovableInstanceTemplates(group, ids).size() <= 0 && !upscale) {
LOGGER.info("InstanceGroup node count lower than 1 which is incorrect so error will throw");
throwError(statuses);
} else {
for (int i = compute.size() - 1; i >= 0; i--) {
for (CloudResourceStatus cloudResourceStatus : statuses) {
try {
if (compute.get(i).resourceType().equals(cloudResourceStatus.getCloudResource().getType())) {
ResourceDeleteThread thread = createThread(ResourceDeleteThread.NAME, ctx, auth, cloudResourceStatus.getCloudResource(), compute.get(i), false);
Future<ResourceRequestResult<List<CloudResourceStatus>>> future = resourceBuilderExecutor.submit(thread);
futures.add(future);
for (Future<ResourceRequestResult<List<CloudResourceStatus>>> future1 : futures) {
future1.get();
}
futures.clear();
}
} catch (Exception e) {
LOGGER.info("Resource can not be deleted. Reason: {} ", e.getMessage());
}
}
}
}
}
use of com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder in project cloudbreak by hortonworks.
the class ComputeResourceService method stopStart.
private List<CloudVmInstanceStatus> stopStart(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, Iterable<CloudInstance> instances) {
List<CloudVmInstanceStatus> results = new ArrayList<>();
Collection<Future<ResourceRequestResult<List<CloudVmInstanceStatus>>>> futures = new ArrayList<>();
Platform platform = auth.getCloudContext().getPlatform();
List<ComputeResourceBuilder> builders = resourceBuilders.compute(platform);
if (!context.isBuild()) {
Collections.reverse(builders);
}
for (ComputeResourceBuilder builder : builders) {
List<CloudResource> resourceList = getResources(builder.resourceType(), resources);
for (CloudResource cloudResource : resourceList) {
CloudInstance instance = getCloudInstance(cloudResource, instances);
if (instance != null) {
ResourceStopStartThread thread = createThread(ResourceStopStartThread.NAME, context, auth, cloudResource, instance, builder);
Future<ResourceRequestResult<List<CloudVmInstanceStatus>>> future = resourceBuilderExecutor.submit(thread);
futures.add(future);
if (isRequestFull(futures.size(), context)) {
results.addAll(flatVmList(waitForRequests(futures).get(FutureResult.SUCCESS)));
}
} else {
break;
}
}
}
results.addAll(flatVmList(waitForRequests(futures).get(FutureResult.SUCCESS)));
return results;
}
use of com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder in project cloudbreak by hortonworks.
the class ComputeResourceService method deleteResources.
public List<CloudResourceStatus> deleteResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, boolean cancellable) {
List<CloudResourceStatus> results = new ArrayList<>();
Collection<Future<ResourceRequestResult<List<CloudResourceStatus>>>> futures = new ArrayList<>();
Platform platform = auth.getCloudContext().getPlatform();
List<ComputeResourceBuilder> builders = resourceBuilders.compute(platform);
int numberOfBuilders = builders.size();
for (int i = numberOfBuilders - 1; i >= 0; i--) {
ComputeResourceBuilder builder = builders.get(i);
List<CloudResource> resourceList = getResources(builder.resourceType(), resources);
for (CloudResource cloudResource : resourceList) {
ResourceDeleteThread thread = createThread(ResourceDeleteThread.NAME, context, auth, cloudResource, builder, cancellable);
Future<ResourceRequestResult<List<CloudResourceStatus>>> future = resourceBuilderExecutor.submit(thread);
futures.add(future);
if (isRequestFull(futures.size(), context)) {
results.addAll(flatList(waitForRequests(futures).get(FutureResult.SUCCESS)));
}
}
// wait for builder type to finish before starting the next one
results.addAll(flatList(waitForRequests(futures).get(FutureResult.SUCCESS)));
}
return results;
}
use of com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder 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);
}
Aggregations