use of com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup in project cloudbreak by hortonworks.
the class ClusterBasedStatusCheckerTask method exitPolling.
@Override
public boolean exitPolling(T t) {
try {
Long stackId = t.getStack().getId();
Long clusterId = t.getStack().getCluster().getId();
PollGroup stackPollGroup = InMemoryStateStore.getStack(stackId);
if (stackPollGroup == null || CANCELLED.equals(stackPollGroup)) {
LOGGER.warn("Stack is getting terminated, polling is cancelled.");
return true;
}
PollGroup clusterPollGroup = InMemoryStateStore.getCluster(clusterId);
if (clusterPollGroup == null || CANCELLED.equals(clusterPollGroup)) {
LOGGER.warn("Cluster is getting terminated, polling is cancelled.");
return true;
}
return false;
} catch (Exception ex) {
LOGGER.error("Error occurred when check status checker exit criteria: ", ex);
return true;
}
}
use of com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup in project cloudbreak by hortonworks.
the class GroupResourceService method buildResources.
public List<CloudResourceStatus> buildResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<Group> groups, Network network, Security security) throws Exception {
CloudContext cloudContext = auth.getCloudContext();
List<CloudResourceStatus> results = new ArrayList<>();
for (GroupResourceBuilder builder : resourceBuilders.group(cloudContext.getPlatform())) {
PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
if (pollGroup != null && CANCELLED.equals(pollGroup)) {
break;
}
for (Group group : getOrderedCopy(groups)) {
try {
CloudResource buildableResource = builder.create(context, auth, group, network);
createResource(auth, buildableResource);
CloudResource resource = builder.build(context, auth, group, network, group.getSecurity(), buildableResource);
updateResource(auth, resource);
PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(resource), context, true);
List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
context.addGroupResources(group.getName(), Collections.singletonList(resource));
results.addAll(pollerResult);
} catch (ResourceNotNeededException e) {
LOGGER.warn("Skipping resource creation: {}", e.getMessage());
}
}
}
return results;
}
use of com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup 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.scheduler.PollGroup in project cloudbreak by hortonworks.
the class ResourceStopStartThread method call.
@Override
public ResourceRequestResult<List<CloudVmInstanceStatus>> call() throws Exception {
LOGGER.info("{} compute resource {}", context.isBuild() ? "Starting" : "Stopping", resource);
PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
if (pollGroup != null && CANCELLED.equals(pollGroup)) {
List<CloudVmInstanceStatus> result = createResult(InstanceStatus.UNKNOWN);
return new ResourceRequestResult<>(FutureResult.SUCCESS, result);
}
CloudVmInstanceStatus status = context.isBuild() ? builder.start(context, auth, instance) : builder.stop(context, auth, instance);
if (status != null) {
PollTask<List<CloudVmInstanceStatus>> task = resourcePollTaskFactory.newPollComputeStatusTask(builder, auth, context, status.getCloudInstance());
List<CloudVmInstanceStatus> pollResult = syncPollingScheduler.schedule(task);
return new ResourceRequestResult<>(FutureResult.SUCCESS, pollResult);
}
return new ResourceRequestResult<>(FutureResult.SUCCESS, createResult(InstanceStatus.UNKNOWN));
}
use of com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup in project cloudbreak by hortonworks.
the class NetworkResourceService method buildResources.
public List<CloudResourceStatus> buildResources(ResourceBuilderContext context, AuthenticatedContext auth, Network network, Security security) throws Exception {
CloudContext cloudContext = auth.getCloudContext();
List<CloudResourceStatus> results = new ArrayList<>();
for (NetworkResourceBuilder builder : resourceBuilders.network(cloudContext.getPlatform())) {
PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
if (pollGroup != null && CANCELLED.equals(pollGroup)) {
break;
}
try {
CloudResource buildableResource = builder.create(context, auth, network);
createResource(auth, buildableResource);
CloudResource resource = builder.build(context, auth, network, security, buildableResource);
updateResource(auth, resource);
PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(resource), context, true);
List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
results.addAll(pollerResult);
} catch (ResourceNotNeededException e) {
LOGGER.warn("Skipping resource creation: {}", e.getMessage());
}
}
return results;
}
Aggregations