use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class AbstractResourceConnector method upscale.
@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources) {
CloudContext cloudContext = auth.getCloudContext();
Platform platform = cloudContext.getPlatform();
// context
ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), resources, true);
// network
context.addNetworkResources(networkResourceService.getNetworkResources(platform, resources));
Group scalingGroup = getScalingGroup(getGroup(stack.getGroups(), getGroupName(stack)));
// group
context.addGroupResources(scalingGroup.getName(), groupResourceService.getGroupResources(platform, resources));
// compute
return computeResourceService.buildResourcesForUpscale(context, auth, Collections.singletonList(scalingGroup), stack.getImage(), stack.getTags());
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class AbstractResourceConnector method downscale.
@Override
public List<CloudResourceStatus> downscale(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources, List<CloudInstance> vms, List<CloudResource> resourcesToRemove) {
CloudContext cloudContext = auth.getCloudContext();
Platform platform = cloudContext.getPlatform();
// context
ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), resources, false);
// compute
return computeResourceService.deleteResources(context, auth, resourcesToRemove, true);
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class StopStackHandler method accept.
@Override
public void accept(Event<StopInstancesRequest> event) {
LOGGER.info("Received event: {}", event);
StopInstancesRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
try {
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
List<CloudInstance> instances = request.getCloudInstances();
AuthenticatedContext authenticatedContext = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = connector.instances().stop(authenticatedContext, request.getResources(), instances);
PollTask<InstancesStatusResult> task = statusCheckFactory.newPollInstanceStateTask(authenticatedContext, instances, Sets.newHashSet(InstanceStatus.STOPPED, InstanceStatus.FAILED));
InstancesStatusResult statusResult = new InstancesStatusResult(cloudContext, cloudVmInstanceStatuses);
if (!task.completed(statusResult)) {
statusResult = syncPollingScheduler.schedule(task);
}
StopInstancesResult result = new StopInstancesResult(request, cloudContext, statusResult);
request.getResult().onNext(result);
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
} catch (Exception e) {
StopInstancesResult failure = new StopInstancesResult("Failed to stop stack", e, request);
request.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
}
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext 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.context.CloudContext 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));
}
}
Aggregations