Search in sources :

Example 21 with CloudCredential

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);
    }
}
Also used : TerminateStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackResult) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) TerminateStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 22 with CloudCredential

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);
    }
}
Also used : GetPlatformTemplateResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest)

Example 23 with CloudCredential

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;
}
Also used : CredentialVerificationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest) CredentialVerificationResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException)

Example 24 with CloudCredential

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);
    }
}
Also used : CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 25 with CloudCredential

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;
}
Also used : StackValidationRequest(com.sequenceiq.cloudbreak.api.model.StackValidationRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) StackValidation(com.sequenceiq.cloudbreak.domain.StackValidation) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Aggregations

CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)47 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)27 Location (com.sequenceiq.cloudbreak.cloud.model.Location)18 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)9 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)9 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)8 Stack (com.sequenceiq.cloudbreak.domain.Stack)8 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)7 HashSet (java.util.HashSet)7 Compute (com.google.api.services.compute.Compute)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)6 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)6 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)5 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)5 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)4 Strings (com.google.common.base.Strings)3