use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class AbstractResourceConnector method launch.
@Override
public List<CloudResourceStatus> launch(AuthenticatedContext auth, CloudStack stack, PersistenceNotifier notifier, AdjustmentType adjustmentType, Long threshold) throws Exception {
CloudContext cloudContext = auth.getCloudContext();
Platform platform = cloudContext.getPlatform();
// context
ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), null, true);
// network
List<CloudResourceStatus> cloudResourceStatuses = networkResourceService.buildResources(context, auth, stack.getNetwork(), stack.getCloudSecurity());
context.addNetworkResources(getCloudResources(cloudResourceStatuses));
// group
List<CloudResourceStatus> groupStatuses = groupResourceService.buildResources(context, auth, stack.getGroups(), stack.getNetwork(), stack.getCloudSecurity());
cloudResourceStatuses.addAll(groupStatuses);
// compute
List<CloudResourceStatus> computeStatuses = computeResourceService.buildResourcesForLaunch(context, auth, stack.getGroups(), stack.getImage(), stack.getTags(), adjustmentType, threshold);
cloudResourceStatuses.addAll(computeStatuses);
return cloudResourceStatuses;
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class ServiceProviderSetupAdapter method checkImage.
public ImageStatusResult checkImage(Stack stack) throws Exception {
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
Image image = imageService.getImage(stack.getId());
CheckImageRequest<CheckImageResult> checkImageRequest = new CheckImageRequest<>(cloudContext, cloudCredential, cloudStackConverter.convert(stack), image);
LOGGER.info("Triggering event: {}", checkImageRequest);
eventBus.notify(checkImageRequest.selector(), eventFactory.createEvent(checkImageRequest));
try {
CheckImageResult res = checkImageRequest.await();
LOGGER.info("Result: {}", res);
if (res.getErrorDetails() != null) {
LOGGER.error("Failed to check image state", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return new ImageStatusResult(res.getImageStatus(), res.getStatusProgressValue());
} catch (InterruptedException e) {
LOGGER.error("Error while executing check image", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class UnhealthyInstancesFinalizer method finalizeUnhealthyInstances.
public Set<String> finalizeUnhealthyInstances(Stack stack, Iterable<InstanceMetaData> candidateUnhealthyInstances) {
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
List<CloudInstance> cloudInstances = cloudInstanceConverter.convert(candidateUnhealthyInstances);
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses(cloudCredential, cloudContext, cloudInstances);
Map<String, CloudVmInstanceStatus> cloudVmInstanceStatusesById = new HashMap<>();
cloudVmInstanceStatuses.forEach(c -> cloudVmInstanceStatusesById.put(c.getCloudInstance().getInstanceId(), c));
Set<String> unhealthyInstances = new HashSet<>();
for (InstanceMetaData i : candidateUnhealthyInstances) {
CloudVmInstanceStatus instanceStatus = cloudVmInstanceStatusesById.get(i.getInstanceId());
if ((instanceStatus == null) || (instanceStatus.getStatus().equals(InstanceStatus.TERMINATED))) {
unhealthyInstances.add(i.getInstanceId());
}
}
return unhealthyInstances;
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class AbstractStackCreationAction method createFlowContext.
@Override
protected StackContext createFlowContext(String flowId, StateContext<StackCreationState, StackCreationEvent> stateContext, P payload) {
Stack stack = stackService.getByIdWithLists(payload.getStackId());
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
CloudStack cloudStack = cloudStackConverter.convert(stack);
return new StackContext(flowId, stack, cloudContext, cloudCredential, cloudStack);
}
use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.
the class StackParameterService method getStackParams.
public List<StackParamValidation> getStackParams(String name, Credential credential) {
LOGGER.debug("Get stack params");
if (credential != null) {
CloudContext cloudContext = new CloudContext(null, name, credential.cloudPlatform(), credential.getOwner());
GetStackParamValidationRequest getStackParamValidationRequest = new GetStackParamValidationRequest(cloudContext);
eventBus.notify(getStackParamValidationRequest.selector(), eventFactory.createEvent(getStackParamValidationRequest));
try {
GetStackParamValidationResult res = getStackParamValidationRequest.await();
LOGGER.info("Get stack params result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
LOGGER.error("Failed to get stack params", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return res.getStackParamValidations();
} catch (InterruptedException e) {
LOGGER.error("Error while getting the stack params", e);
throw new OperationException(e);
}
} else {
return Collections.emptyList();
}
}
Aggregations