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()));
}
}
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);
}
}
Aggregations