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