Search in sources :

Example 31 with OperationException

use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.

the class ServiceProviderConnectorAdapter method waitGetTemplate.

public String waitGetTemplate(GetPlatformTemplateRequest getPlatformTemplateRequest) {
    try {
        GetPlatformTemplateResult res = getPlatformTemplateRequest.await();
        LOGGER.debug("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: " + getPlatformTemplateRequest.getCloudContext(), e);
        throw new OperationException(e);
    }
}
Also used : GetPlatformTemplateResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 32 with OperationException

use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.

the class ServiceProviderConnectorAdapter method checkAndGetPlatformVariant.

public Variant checkAndGetPlatformVariant(Stack stack) {
    LOGGER.debug("Get platform variant for: {}", stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    Credential credential = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> credentialClientService.getByEnvironmentCrn(stack.getEnvironmentCrn()));
    CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(Crn.safeFromString(credential.getCrn()).getAccountId()).withGovCloud(credential.isGovCloud()).build();
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    CheckPlatformVariantRequest checkPlatformVariantRequest = new CheckPlatformVariantRequest(cloudContext, cloudCredential);
    eventBus.notify(checkPlatformVariantRequest.selector(), eventFactory.createEvent(checkPlatformVariantRequest));
    try {
        CheckPlatformVariantResult res = checkPlatformVariantRequest.await();
        LOGGER.debug("Platform variant result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.error("Failed to get platform variant", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return res.getDefaultPlatformVariant();
    } catch (InterruptedException e) {
        LOGGER.error("Error while getting the platform variant: " + cloudContext, e);
        throw new OperationException(e);
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) CheckPlatformVariantRequest(com.sequenceiq.cloudbreak.cloud.event.platform.CheckPlatformVariantRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CheckPlatformVariantResult(com.sequenceiq.cloudbreak.cloud.event.platform.CheckPlatformVariantResult) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 33 with OperationException

use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.

the class ServiceProviderCredentialAdapter method verifyByServices.

public CDPServicePolicyVerification verifyByServices(Credential credential, String accountId, List<String> services, Map<String, String> experiencePrerequisites) {
    credential = credentialPrerequisiteService.decorateCredential(credential);
    CloudContext cloudContext = CloudContext.Builder.builder().withId(credential.getId()).withName(credential.getName()).withCrn(credential.getResourceCrn()).withPlatform(credential.getCloudPlatform()).withVariant(credential.getCloudPlatform()).withUserName(TEMP_USER_ID).withAccountId(accountId).build();
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    CDPServicePolicyVerificationRequest request = requestProvider.getCDPServicePolicyVerificationRequest(cloudContext, cloudCredential, services, experiencePrerequisites);
    LOGGER.debug("Triggering event: {}", request);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        CDPServicePolicyVerificationResult res = request.await();
        LOGGER.debug("Result: {}", res);
        if (res.getStatus() != EventStatus.OK) {
            String message = FAILED_POLICY_VERIFICATION_MESSAGE;
            LOGGER.info(message, res.getErrorDetails());
            throw new CDPServicePolicyVerificationException(message + res.getErrorDetails(), res.getErrorDetails());
        }
        CDPServicePolicyVerificationResponses cdpServicePolicyVerificationResponses = res.getCdpServicePolicyVerificationResponses();
        return new CDPServicePolicyVerification(cdpServicePolicyVerificationResponses.getResults());
    } catch (InterruptedException e) {
        LOGGER.error("Error while executing credential verification", e);
        throw new OperationException(e);
    }
}
Also used : CDPServicePolicyVerificationResult(com.sequenceiq.cloudbreak.cloud.event.credential.CDPServicePolicyVerificationResult) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CDPServicePolicyVerificationException(com.sequenceiq.cloudbreak.cloud.event.credential.CDPServicePolicyVerificationException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CDPServicePolicyVerificationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CDPServicePolicyVerificationRequest) CDPServicePolicyVerificationResponses(com.sequenceiq.cloudbreak.cloud.model.CDPServicePolicyVerificationResponses) CDPServicePolicyVerification(com.sequenceiq.environment.environment.verification.CDPServicePolicyVerification) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 34 with OperationException

use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.

the class ServiceProviderCredentialAdapter method interactiveLogin.

public Map<String, String> interactiveLogin(Credential credential, String accountId) {
    CloudContext cloudContext = CloudContext.Builder.builder().withId(credential.getId()).withName(credential.getName()).withCrn(credential.getResourceCrn()).withPlatform(credential.getCloudPlatform()).withVariant(credential.getCloudPlatform()).withAccountId(accountId).build();
    ExtendedCloudCredential cloudCredential = extendedCloudCredentialConverter.convert(credential);
    LOGGER.debug("Requesting interactive login cloudPlatform {}.", credential.getCloudPlatform());
    InteractiveLoginRequest request = requestProvider.getInteractiveLoginRequest(cloudContext, cloudCredential);
    LOGGER.debug("Triggering event: {}", request);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        InteractiveLoginResult res = request.await();
        String message = "Interactive login Failed: ";
        LOGGER.debug("Result: {}", res);
        if (res.getStatus() != EventStatus.OK) {
            LOGGER.info(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(javax.ws.rs.BadRequestException) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 35 with OperationException

use of com.sequenceiq.cloudbreak.service.OperationException in project cloudbreak by hortonworks.

the class ServiceProviderCredentialAdapter method initCodeGrantFlow.

public Credential initCodeGrantFlow(Credential credential, String accountId) {
    CloudContext cloudContext = CloudContext.Builder.builder().withId(credential.getId()).withName(credential.getName()).withCrn(credential.getResourceCrn()).withPlatform(credential.getCloudPlatform()).withVariant(credential.getCloudPlatform()).withAccountId(accountId).build();
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    LOGGER.debug("Requesting code grant flow cloudPlatform {}.", credential.getCloudPlatform());
    InitCodeGrantFlowRequest request = requestProvider.getInitCodeGrantFlowRequest(cloudContext, cloudCredential);
    LOGGER.info("Triggering event: {}", request);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        InitCodeGrantFlowResponse res = request.await();
        LOGGER.info("Result: {}", res);
        if (res.getStatus() != EventStatus.OK) {
            String message = "Authorization code grant based credential creation couldn't be initialized: ";
            LOGGER.error(message, res.getErrorDetails());
            throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
        }
        Map<String, String> codeGrantFlowInitParams = res.getCodeGrantFlowInitParams();
        addCodeGrantFlowInitAttributesToCredential(credential, codeGrantFlowInitParams);
        return credential;
    } catch (InterruptedException e) {
        LOGGER.error("Error while executing initialization of authorization code grant based credential creation:", e);
        throw new OperationException(e);
    }
}
Also used : InitCodeGrantFlowResponse(com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowResponse) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(javax.ws.rs.BadRequestException) InitCodeGrantFlowRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowRequest) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Aggregations

OperationException (com.sequenceiq.cloudbreak.service.OperationException)47 Retryable (org.springframework.retry.annotation.Retryable)19 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)16 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)11 Location (com.sequenceiq.cloudbreak.cloud.model.Location)6 GetPlatformTemplateResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult)5 Credential (com.sequenceiq.cloudbreak.dto.credential.Credential)5 BadRequestException (javax.ws.rs.BadRequestException)5 PlatformParameterRequest (com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterRequest)4 PlatformParameterResult (com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterResult)4 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)3 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)3 EventStatus (com.sequenceiq.cloudbreak.cloud.event.model.EventStatus)3 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)3 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3