Search in sources :

Example 1 with CredentialPrerequisitesResult

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

the class CredentialPrerequisiteService method getCloudbreakPrerequisites.

public CredentialPrerequisitesResponse getCloudbreakPrerequisites(String cloudPlatform, String deploymentAddress, CredentialType type) {
    CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(cloudPlatform).withWorkspaceId(TEMP_WORKSPACE_ID).build();
    CredentialPrerequisitesRequest request = new CredentialPrerequisitesRequest(cloudContext, userPreferencesService.getExternalIdForCurrentUser(), userPreferencesService.getAuditExternalIdForCurrentUser(), deploymentAddress, type);
    LOGGER.debug("Triggering event: {}", request);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    String message = String.format("Failed to get prerequisites for platform '%s': ", cloudPlatform);
    try {
        CredentialPrerequisitesResult res = request.await();
        LOGGER.debug("Result: {}", res);
        if (res.getStatus() != EventStatus.OK) {
            LOGGER.info(message, res.getErrorDetails());
            throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
        }
        return res.getCredentialPrerequisitesResponse();
    } catch (InterruptedException e) {
        LOGGER.error(message, e);
        throw new OperationException(e);
    }
}
Also used : CredentialPrerequisitesRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(javax.ws.rs.BadRequestException) CredentialPrerequisitesResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesResult) CredentialOperationException(com.sequenceiq.environment.credential.exception.CredentialOperationException) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 2 with CredentialPrerequisitesResult

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

the class CredentialPrerequisiteService method getCloudbreakPrerequisites.

public CredentialPrerequisitesResponse getCloudbreakPrerequisites(String cloudPlatform, boolean govCloud, String deploymentAddress, CredentialType type) {
    CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(cloudPlatform).withGovCloud(govCloud).withWorkspaceId(TEMP_WORKSPACE_ID).build();
    CredentialPrerequisitesRequest request = new CredentialPrerequisitesRequest(cloudContext, userPreferencesService.getExternalIdForCurrentUser(), userPreferencesService.getAuditExternalIdForCurrentUser(), deploymentAddress, type);
    LOGGER.debug("Triggering event: {}", request);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    String message = String.format("Failed to get prerequisites for platform '%s': ", cloudPlatform);
    try {
        CredentialPrerequisitesResult res = request.await();
        LOGGER.debug("Result: {}", res);
        if (res.getStatus() != EventStatus.OK) {
            LOGGER.info(message, res.getErrorDetails());
            throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
        }
        return res.getCredentialPrerequisitesResponse();
    } catch (InterruptedException e) {
        LOGGER.error(message, e);
        throw new OperationException(e);
    }
}
Also used : CredentialPrerequisitesRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(javax.ws.rs.BadRequestException) CredentialPrerequisitesResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesResult) CredentialOperationException(com.sequenceiq.environment.credential.exception.CredentialOperationException) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 3 with CredentialPrerequisitesResult

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

the class CredentialPrerequisitesHandler method accept.

@Override
public void accept(Event<CredentialPrerequisitesRequest> credentialPrerequisitesRequestEvent) {
    LOGGER.debug("Received event: {}", credentialPrerequisitesRequestEvent);
    CredentialPrerequisitesRequest request = credentialPrerequisitesRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        LOGGER.info("Gathering credential prerequisites for platform: '{}'", cloudContext.getPlatform());
        CloudConnector<?> connector = cloudPlatformConnectors.getDefault(cloudContext.getPlatform());
        CredentialPrerequisitesResponse result = connector.credentials().getPrerequisites(cloudContext, request.getExternalId(), request.getAuditExternalId(), request.getDeploymentAddress(), request.getType());
        CredentialPrerequisitesResult credentialPrerequisitesResult = new CredentialPrerequisitesResult(request.getResourceId(), result);
        request.getResult().onNext(credentialPrerequisitesResult);
        LOGGER.debug("Credential prerequisites have been collected successfully for platform: '{}'!", cloudContext.getPlatform().value());
    } catch (RuntimeException e) {
        request.getResult().onNext(new CredentialPrerequisitesResult(e.getMessage(), e, request.getResourceId()));
    }
}
Also used : CredentialPrerequisitesRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) CredentialPrerequisitesResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesResult)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)3 CredentialPrerequisitesRequest (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesRequest)3 CredentialPrerequisitesResult (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialPrerequisitesResult)3 OperationException (com.sequenceiq.cloudbreak.service.OperationException)2 CredentialOperationException (com.sequenceiq.environment.credential.exception.CredentialOperationException)2 BadRequestException (javax.ws.rs.BadRequestException)2 CredentialPrerequisitesResponse (com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse)1