use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method deleteStack.
public void deleteStack(Stack stack, Credential credential) {
LOGGER.debug("Assembling terminate stack event for stack: {}", 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());
List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
CloudStack cloudStack = cloudStackConverter.convert(stack);
TerminateStackRequest<TerminateStackResult> terminateRequest = new TerminateStackRequest<>(cloudContext, cloudStack, cloudCredential, resources);
LOGGER.info("Triggering terminate stack event: {}", terminateRequest);
eventBus.notify(terminateRequest.selector(), eventFactory.createEvent(terminateRequest));
try {
TerminateStackResult res = terminateRequest.await();
LOGGER.info("Terminate stack result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
if (res.getErrorDetails() != null) {
LOGGER.error("Failed to terminate the stack", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
throw new OperationException(format("Failed to terminate the stack: %s due to %s", cloudContext, res.getStatusReason()));
}
} catch (InterruptedException e) {
LOGGER.error("Error while terminating the stack", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method getTemplate.
public String getTemplate(Stack 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());
GetPlatformTemplateRequest getPlatformTemplateRequest = new GetPlatformTemplateRequest(cloudContext, cloudCredential);
eventBus.notify(getPlatformTemplateRequest.selector(), eventFactory.createEvent(getPlatformTemplateRequest));
try {
GetPlatformTemplateResult res = getPlatformTemplateRequest.await();
LOGGER.info("Get template result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
LOGGER.error("Failed to get template", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return res.getTemplate();
} catch (InterruptedException e) {
LOGGER.error("Error while getting template: " + cloudContext, e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class ServiceProviderCredentialAdapter method init.
public Credential init(Credential credential) {
CloudContext cloudContext = new CloudContext(credential.getId(), credential.getName(), credential.cloudPlatform(), credential.getOwner());
CloudCredential cloudCredential = credentialConverter.convert(credential);
CredentialVerificationRequest request = new CredentialVerificationRequest(cloudContext, cloudCredential);
LOGGER.info("Triggering event: {}", request);
eventBus.notify(request.selector(), eventFactory.createEvent(request));
try {
CredentialVerificationResult res = request.await();
String message = "Failed to verify the credential: ";
LOGGER.info("Result: {}", res);
if (res.getStatus() != EventStatus.OK) {
LOGGER.error(message, res.getErrorDetails());
throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
}
if (CredentialStatus.FAILED.equals(res.getCloudCredentialStatus().getStatus())) {
throw new BadRequestException(message + res.getCloudCredentialStatus().getStatusReason(), res.getCloudCredentialStatus().getException());
}
CloudCredential cloudCredentialResponse = res.getCloudCredentialStatus().getCloudCredential();
mergeSmartSenseAttributeIfExists(credential, cloudCredentialResponse);
} catch (InterruptedException e) {
LOGGER.error("Error while executing credential verification", e);
throw new OperationException(e);
}
return credential;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class ServiceProviderMetadataAdapter method collectMetadata.
public List<CloudVmMetaDataStatus> collectMetadata(Stack 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());
List<CloudInstance> cloudInstances = cloudStackConverter.buildInstances(stack);
List<CloudResource> cloudResources = cloudResourceConverter.convert(stack.getResources());
CollectMetadataRequest cmr = new CollectMetadataRequest(cloudContext, cloudCredential, cloudResources, cloudInstances);
LOGGER.info("Triggering event: {}", cmr);
eventBus.notify(CloudPlatformRequest.selector(CollectMetadataRequest.class), eventFactory.createEvent(cmr));
try {
CollectMetadataResult res = cmr.await();
LOGGER.info("Result: {}", res);
if (res.getErrorDetails() != null) {
LOGGER.error("Failed to collect metadata", res.getErrorDetails());
return Collections.emptyList();
}
return res.getResults();
} catch (InterruptedException e) {
LOGGER.error(format("Error while executing collectMetadata, stack: %s", cloudContext), e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class StackCreatorService method createStack.
public StackResponse createStack(IdentityUser user, StackRequest stackRequest, boolean publicInAccount) throws Exception {
stackRequest.setAccount(user.getAccount());
stackRequest.setOwner(user.getUserId());
stackRequest.setOwnerEmail(user.getUsername());
long start = System.currentTimeMillis();
Stack stack = conversionService.convert(stackRequest, Stack.class);
String stackName = stack.getName();
LOGGER.info("Stack request converted to stack in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
MDCBuilder.buildMdcContext(stack);
start = System.currentTimeMillis();
stack = stackSensitiveDataPropagator.propagate(stackRequest.getCredentialSource(), stack, user);
LOGGER.info("Stack propagated with sensitive data in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
stack = stackDecorator.decorate(stack, stackRequest, user);
LOGGER.info("Stack object has been decorated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
stack.setPublicInAccount(publicInAccount);
start = System.currentTimeMillis();
validateAccountPreferences(stack, user);
LOGGER.info("Account preferences has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
if (stack.getOrchestrator() != null && stack.getOrchestrator().getApiEndpoint() != null) {
stackService.validateOrchestrator(stack.getOrchestrator());
}
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
templateValidator.validateTemplateRequest(stack.getCredential(), instanceGroup.getTemplate(), stack.getRegion(), stack.getAvailabilityZone(), stack.getPlatformVariant());
}
Blueprint blueprint = null;
if (stackRequest.getClusterRequest() != null) {
start = System.currentTimeMillis();
StackValidationRequest stackValidationRequest = conversionService.convert(stackRequest, StackValidationRequest.class);
LOGGER.info("Stack validation request has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
StackValidation stackValidation = conversionService.convert(stackValidationRequest, StackValidation.class);
LOGGER.info("Stack validation object has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
blueprint = stackValidation.getBlueprint();
start = System.currentTimeMillis();
stackService.validateStack(stackValidation, stackRequest.getClusterRequest().getValidateBlueprint());
LOGGER.info("Stack has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(stack.getCredential());
start = System.currentTimeMillis();
fileSystemValidator.validateFileSystem(stackValidationRequest.getPlatform(), cloudCredential, stackValidationRequest.getFileSystem());
LOGGER.info("Filesystem has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
clusterCreationService.validate(stackRequest.getClusterRequest(), cloudCredential, stack, user);
LOGGER.info("Cluster has been validated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
}
start = System.currentTimeMillis();
stack = stackService.create(user, stack, stackRequest.getImageCatalog(), Optional.ofNullable(stackRequest.getImageId()), Optional.ofNullable(blueprint));
LOGGER.info("Stack object and its dependencies has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
createClusterIfNeed(user, stackRequest, stack, stackName, blueprint);
start = System.currentTimeMillis();
StackResponse response = conversionService.convert(stack, StackResponse.class);
LOGGER.info("Stack response has been created in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
flowManager.triggerProvisioning(stack.getId());
LOGGER.info("Stack provision triggered in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
return response;
}
Aggregations