Search in sources :

Example 1 with CredentialExperiencePolicyResult

use of com.sequenceiq.cloudbreak.cloud.event.credential.CredentialExperiencePolicyResult in project cloudbreak by hortonworks.

the class CredentialExperiencePolicyHandler method accept.

@Override
public void accept(Event<CredentialExperiencePolicyRequest> credentialExperiencePolicyRequestEvent) {
    LOGGER.debug("Received event: {}", credentialExperiencePolicyRequestEvent);
    CredentialExperiencePolicyRequest request = credentialExperiencePolicyRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        LOGGER.info("Gathering credential experience policies for platform: '{}'", cloudContext.getPlatform());
        EnvironmentExperienceDto dto = new EnvironmentExperienceDto.Builder().withCloudPlatform(cloudContext.getPlatform().value()).withAccountId(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString()).build();
        Map<String, String> policies = experienceConnectorService.collectExperiencePoliciesForCredentialCreation(dto);
        CredentialExperiencePolicyResult credentialExperiencePolicyResult = new CredentialExperiencePolicyResult(request.getResourceId(), policies);
        request.getResult().onNext(credentialExperiencePolicyResult);
        LOGGER.debug("Credential prerequisites have been collected successfully for platform: '{}'!", cloudContext.getPlatform().value());
    } catch (RuntimeException e) {
        request.getResult().onNext(new CredentialExperiencePolicyResult(e.getMessage(), e, request.getResourceId()));
    }
}
Also used : EnvironmentExperienceDto(com.sequenceiq.environment.environment.dto.EnvironmentExperienceDto) CredentialExperiencePolicyRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialExperiencePolicyRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CredentialExperiencePolicyResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialExperiencePolicyResult)

Example 2 with CredentialExperiencePolicyResult

use of com.sequenceiq.cloudbreak.cloud.event.credential.CredentialExperiencePolicyResult in project cloudbreak by hortonworks.

the class CredentialPrerequisiteService method getExperiencePrerequisites.

public Map<String, String> getExperiencePrerequisites(String cloudPlatform) {
    CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(cloudPlatform).withWorkspaceId(TEMP_WORKSPACE_ID).build();
    CredentialExperiencePolicyRequest request = new CredentialExperiencePolicyRequest(cloudContext);
    LOGGER.debug("Triggering event: {}", request);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    String message = String.format("Failed to get experience policies for platform '%s': ", cloudPlatform);
    try {
        CredentialExperiencePolicyResult res = request.await();
        LOGGER.debug("Result: {}", res);
        if (res.getStatus() != EventStatus.OK) {
            LOGGER.warn(message, res.getErrorDetails());
            throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
        }
        return res.getPolicies();
    } catch (InterruptedException e) {
        LOGGER.error(message, e);
        throw new CredentialOperationException(e);
    }
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CredentialExperiencePolicyRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialExperiencePolicyRequest) CredentialOperationException(com.sequenceiq.environment.credential.exception.CredentialOperationException) BadRequestException(javax.ws.rs.BadRequestException) CredentialExperiencePolicyResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialExperiencePolicyResult)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 CredentialExperiencePolicyRequest (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialExperiencePolicyRequest)2 CredentialExperiencePolicyResult (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialExperiencePolicyResult)2 CredentialOperationException (com.sequenceiq.environment.credential.exception.CredentialOperationException)1 EnvironmentExperienceDto (com.sequenceiq.environment.environment.dto.EnvironmentExperienceDto)1 BadRequestException (javax.ws.rs.BadRequestException)1