use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class StackCreationService method removeFailedMetadata.
private List<CloudResourceStatus> removeFailedMetadata(Long stackId, Iterable<CloudResourceStatus> statuses, Group group) {
Map<Long, CloudResourceStatus> failedResources = new HashMap<>();
Set<Long> groupPrivateIds = getPrivateIds(group);
for (CloudResourceStatus status : statuses) {
Long privateId = status.getPrivateId();
if (privateId != null && status.isFailed() && !failedResources.containsKey(privateId) && groupPrivateIds.contains(privateId)) {
failedResources.put(privateId, status);
instanceMetadataService.deleteInstanceRequest(stackId, privateId);
}
}
return new ArrayList<>(failedResources.values());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class AbstractGcpResourceBuilder method checkResources.
protected List<CloudResourceStatus> checkResources(ResourceType type, GcpContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
List<CloudResourceStatus> result = new ArrayList<>();
for (CloudResource resource : resources) {
LOGGER.info("Check {} resource: {}", type, resource);
try {
Operation operation = check(context, resource);
boolean finished = operation == null || GcpStackUtil.isOperationFinished(operation);
ResourceStatus successStatus = context.isBuild() ? ResourceStatus.CREATED : ResourceStatus.DELETED;
result.add(new CloudResourceStatus(resource, finished ? successStatus : ResourceStatus.IN_PROGRESS));
if (finished) {
if (successStatus == ResourceStatus.CREATED) {
LOGGER.info("Creation of {} was successful", resource);
} else {
LOGGER.info("Deletion of {} was successful", resource);
}
}
} catch (Exception e) {
CloudContext cloudContext = auth.getCloudContext();
throw new GcpResourceException("Error during status check", type, cloudContext.getName(), cloudContext.getId(), resource.getName(), e);
}
}
return result;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class AbstractResourceConnector method terminate.
@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext auth, CloudStack stack, List<CloudResource> cloudResources) throws Exception {
CloudContext cloudContext = auth.getCloudContext();
Platform platform = cloudContext.getPlatform();
// context
ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), cloudResources, false);
// compute
List<CloudResourceStatus> cloudResourceStatuses = computeResourceService.deleteResources(context, auth, cloudResources, false);
// group
List<CloudResourceStatus> groupStatuses = groupResourceService.deleteResources(context, auth, cloudResources, stack.getNetwork(), false);
cloudResourceStatuses.addAll(groupStatuses);
// network
List<CloudResourceStatus> networkStatuses = networkResourceService.deleteResources(context, auth, cloudResources, stack.getNetwork(), false);
cloudResourceStatuses.addAll(networkStatuses);
return cloudResourceStatuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus 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.model.CloudResourceStatus 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;
}
Aggregations