use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class TerminateStackHandler method accept.
@Override
public void accept(Event<TerminateStackRequest> terminateStackRequestEvent) {
LOGGER.info("Received event: {}", terminateStackRequestEvent);
TerminateStackRequest request = terminateStackRequestEvent.getData();
try {
CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
List<CloudResourceStatus> resourceStatus = connector.resources().terminate(ac, request.getCloudStack(), request.getCloudResources());
List<CloudResource> resources = ResourceLists.transform(resourceStatus);
TerminateStackResult result;
if (!resources.isEmpty()) {
PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, false);
ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(request.getCloudContext(), resourceStatus);
if (!task.completed(statePollerResult)) {
statePollerResult = syncPollingScheduler.schedule(task);
}
if (!statePollerResult.getStatus().equals(ResourceStatus.DELETED)) {
throw new CloudConnectorException("Stack could not be terminated, Resource(s) could not be deleted on the provider side.");
} else {
result = new TerminateStackResult(request);
}
} else {
result = new TerminateStackResult(request);
}
CloudCredentialStatus credentialStatus = connector.credentials().delete(ac);
if (CredentialStatus.FAILED == credentialStatus.getStatus()) {
if (credentialStatus.getException() != null) {
throw new CloudConnectorException(credentialStatus.getException());
}
throw new CloudConnectorException(credentialStatus.getStatusReason());
}
request.getResult().onNext(result);
LOGGER.info("TerminateStackHandler finished");
eventBus.notify(result.selector(), new Event<>(terminateStackRequestEvent.getHeaders(), result));
} catch (Exception e) {
LOGGER.error("Failed to handle TerminateStackRequest", e);
TerminateStackResult terminateStackResult = new TerminateStackResult("Stack termination failed.", e, request);
request.getResult().onNext(terminateStackResult);
eventBus.notify(terminateStackResult.selector(), new Event<>(terminateStackRequestEvent.getHeaders(), terminateStackResult));
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus 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.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class NetworkResourceService method deleteResources.
public List<CloudResourceStatus> deleteResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<CloudResource> resources, Network network, boolean cancellable) throws Exception {
CloudContext cloudContext = auth.getCloudContext();
List<CloudResourceStatus> results = new ArrayList<>();
List<NetworkResourceBuilder> builderChain = resourceBuilders.network(cloudContext.getPlatform());
for (int i = builderChain.size() - 1; i >= 0; i--) {
NetworkResourceBuilder 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;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.
the class NetworkResourceService method update.
public List<CloudResourceStatus> update(ResourceBuilderContext context, AuthenticatedContext auth, Network network, Security security, Iterable<CloudResource> networkResources) throws Exception {
List<CloudResourceStatus> results = new ArrayList<>();
CloudContext cloudContext = auth.getCloudContext();
for (NetworkResourceBuilder builder : resourceBuilders.network(cloudContext.getPlatform())) {
CloudResource resource = getResources(networkResources, builder.resourceType()).get(0);
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.CloudResourceStatus in project cloudbreak by hortonworks.
the class RemoveInstanceHandler method accept.
@Override
public void accept(Event<RemoveInstanceRequest> removeInstanceRequestEvent) {
RemoveInstanceRequest request = removeInstanceRequestEvent.getData();
RemoveInstanceResult result;
try {
CloudContext cloudContext = request.getCloudContext();
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
List<CloudResourceStatus> resourceStatus = connector.resources().downscale(ac, request.getCloudStack(), request.getCloudResources(), request.getInstances(), Collections.emptyMap());
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);
}
LOGGER.info("Instance remove successfully finished for {}", cloudContext);
result = new RemoveInstanceResult(new DownscaleStackResult(request, ResourceLists.transform(statePollerResult.getResults())), request);
} catch (Exception e) {
LOGGER.error("Failed to handle RemoveInstanceRequest.", e);
result = new RemoveInstanceResult(e.getMessage(), e, request);
}
eventBus.notify(result.selector(), new Event<>(removeInstanceRequestEvent.getHeaders(), result));
}
Aggregations