use of com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential in project cloudbreak by hortonworks.
the class CloudParameterService method getVmTypesV2.
public CloudVmTypes getVmTypesV2(Credential credential, String region, String variant, Map<String, String> filters) {
LOGGER.debug("Get platform vmtypes");
ExtendedCloudCredential cloudCredential = credentialToExtendedCloudCredentialConverter.convert(credential);
GetPlatformVmTypesRequest getPlatformVmTypesRequest = new GetPlatformVmTypesRequest(cloudCredential, cloudCredential, variant, region, filters);
eventBus.notify(getPlatformVmTypesRequest.selector(), Event.wrap(getPlatformVmTypesRequest));
try {
GetPlatformVmTypesResult res = getPlatformVmTypesRequest.await();
LOGGER.info("Platform vmtypes result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
LOGGER.error("Failed to get platform vmtypes", res.getErrorDetails());
throw new GetCloudParameterException("Failed to VM types for the cloud provider", res.getErrorDetails());
}
return res.getCloudVmTypes();
} catch (InterruptedException e) {
LOGGER.error("Error while getting the platform vmtypes", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential in project cloudbreak by hortonworks.
the class AzureInteractiveLoginStatusCheckerTask method doCall.
@Override
protected Boolean doCall() {
Response response = createPollingRequest();
if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
String tokenResponseString = response.readEntity(String.class);
try {
String refreshToken = new ObjectMapper().readTree(tokenResponseString).get("refresh_token").asText();
LOGGER.info("Access token received");
ExtendedCloudCredential extendedCloudCredential = armInteractiveLoginStatusCheckerContext.getExtendedCloudCredential();
AzureCredentialView armCredentialView = new AzureCredentialView(extendedCloudCredential);
try {
String graphApiAccessToken = createResourceToken(refreshToken, armCredentialView.getTenantId(), GRAPH_WINDOWS);
String managementApiToken = createResourceToken(refreshToken, armCredentialView.getTenantId(), MANAGEMENT_CORE_WINDOWS);
subscriptionChecker.checkSubscription(armCredentialView.getSubscriptionId(), managementApiToken);
tenantChecker.checkTenant(armCredentialView.getTenantId(), managementApiToken);
String secretKey = UUID.randomUUID().toString();
String appId = applicationCreator.createApplication(graphApiAccessToken, armCredentialView.getTenantId(), secretKey);
sendStatusMessage(extendedCloudCredential, "Cloudbreak application created");
ServicePrincipalInner sp = principalCreator.createServicePrincipal(graphApiAccessToken, appId, armCredentialView.getTenantId());
String principalObjectId = sp.objectId();
String notification = new StringBuilder("Principal created for application!").append(" Name: ").append(sp.displayName()).append(", AppId: ").append(sp.appId()).toString();
sendStatusMessage(extendedCloudCredential, notification);
String roleName = armCredentialView.getRoleName();
String roleType = armCredentialView.getRoleType();
String roleId = azureRoleManager.handleRoleOperations(managementApiToken, armCredentialView.getSubscriptionId(), roleName, roleType);
azureRoleManager.assignRole(managementApiToken, armCredentialView.getSubscriptionId(), roleId, principalObjectId);
sendStatusMessage(extendedCloudCredential, "Role assigned for principal");
extendedCloudCredential.putParameter("accessKey", appId);
extendedCloudCredential.putParameter("secretKey", secretKey);
extendedCloudCredential.putParameter("spDisplayName", sp.displayName());
armInteractiveLoginStatusCheckerContext.getCredentialNotifier().createCredential(getAuthenticatedContext().getCloudContext(), extendedCloudCredential);
} catch (InteractiveLoginException | InteractiveLoginUnrecoverableException e) {
LOGGER.error("Interactive login failed", e);
sendErrorStatusMessage(extendedCloudCredential, e.getMessage());
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
return true;
} else {
LOGGER.info("Polling request failed this time, status code {}, response: {}", response.getStatus(), response.readEntity(String.class));
return false;
}
}
use of com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential in project cloudbreak by hortonworks.
the class InteractiveCredentialCreationHandler method accept.
@Override
public void accept(Event<InteractiveCredentialCreationRequest> interactiveCredentialCreationRequestEvent) {
InteractiveCredentialCreationRequest interactiveCredentialCreationRequest = interactiveCredentialCreationRequestEvent.getData();
ExtendedCloudCredential extendedCloudCredential = interactiveCredentialCreationRequest.getExtendedCloudCredential();
Credential credential = extendedCloudCredentialToCredentialConverter.convert(extendedCloudCredential);
try {
credentialService.createWithRetry(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), credential);
} catch (DuplicateKeyValueException e) {
sendErrorNotification(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), extendedCloudCredential.getCloudPlatform(), DuplicatedKeyValueExceptionMapper.errorMessage(e));
} catch (BadRequestException e) {
sendErrorNotification(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), extendedCloudCredential.getCloudPlatform(), e.getMessage());
}
}
Aggregations