Search in sources :

Example 46 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class ServiceProviderConnectorAdapter method getPlatformParameters.

public PlatformParameters getPlatformParameters(Stack stack) {
    LOGGER.debug("Get platform parameters for: {}", 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());
    PlatformParameterRequest parameterRequest = new PlatformParameterRequest(cloudContext, cloudCredential);
    eventBus.notify(parameterRequest.selector(), eventFactory.createEvent(parameterRequest));
    try {
        PlatformParameterResult res = parameterRequest.await();
        LOGGER.info("Platform parameter result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.error("Failed to get platform parameters", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return res.getPlatformParameters();
    } catch (InterruptedException e) {
        LOGGER.error("Error while getting platform parameters: " + cloudContext, e);
        throw new OperationException(e);
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) PlatformParameterRequest(com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterRequest) PlatformParameterResult(com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterResult) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 47 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext 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 48 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext 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 49 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class ServiceProviderCredentialAdapter method interactiveLogin.

public Map<String, String> interactiveLogin(Credential credential) {
    CloudContext cloudContext = new CloudContext(credential.getId(), credential.getName(), credential.cloudPlatform(), credential.getOwner());
    ExtendedCloudCredential cloudCredential = extendedCloudCredentialConverter.convert(credential);
    InteractiveLoginRequest request = new InteractiveLoginRequest(cloudContext, cloudCredential);
    LOGGER.info("Triggering event: {}", request);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        InteractiveLoginResult res = request.await();
        String message = "Interactive login Failed: ";
        LOGGER.info("Result: {}", res);
        if (res.getStatus() != EventStatus.OK) {
            LOGGER.error(message, res.getErrorDetails());
            throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
        }
        return res.getParameters();
    } catch (InterruptedException e) {
        LOGGER.error("Error while executing credential verification", e);
        throw new OperationException(e);
    }
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) InteractiveLoginResult(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginResult) InteractiveLoginRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException)

Example 50 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext 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)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)100 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)43 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)34 Test (org.junit.Test)34 Group (com.sequenceiq.cloudbreak.cloud.model.Group)33 HashMap (java.util.HashMap)33 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)32 Location (com.sequenceiq.cloudbreak.cloud.model.Location)31 Network (com.sequenceiq.cloudbreak.cloud.model.Network)31 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)31 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)25 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)20 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)19 Matchers.containsString (org.hamcrest.Matchers.containsString)18 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)16 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)15 ArrayList (java.util.ArrayList)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)14 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14