Search in sources :

Example 11 with ExtendedCloudCredential

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);
    }
}
Also used : GetPlatformVmTypesResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformVmTypesResult) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) GetPlatformVmTypesRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformVmTypesRequest) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException)

Example 12 with ExtendedCloudCredential

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;
    }
}
Also used : Response(javax.ws.rs.core.Response) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) ServicePrincipalInner(com.microsoft.azure.management.graphrbac.implementation.ServicePrincipalInner) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 13 with ExtendedCloudCredential

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());
    }
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.cloudbreak.domain.Credential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) InteractiveCredentialCreationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationRequest) DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException)

Aggregations

ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)13 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)10 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 Credential (com.sequenceiq.cloudbreak.domain.Credential)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ServicePrincipalInner (com.microsoft.azure.management.graphrbac.implementation.ServicePrincipalInner)1 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 InteractiveCredentialCreationRequest (com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationRequest)1 InteractiveLoginRequest (com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginRequest)1 InteractiveLoginResult (com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginResult)1 GetPlatformCloudAccessConfigsRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformCloudAccessConfigsRequest)1 GetPlatformCloudAccessConfigsResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformCloudAccessConfigsResult)1 GetPlatformCloudGatewaysRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformCloudGatewaysRequest)1 GetPlatformCloudGatewaysResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformCloudGatewaysResult)1 GetPlatformCloudIpPoolsRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformCloudIpPoolsRequest)1 GetPlatformCloudIpPoolsResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformCloudIpPoolsResult)1 GetPlatformInstanceGroupParameterRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformInstanceGroupParameterRequest)1 GetPlatformInstanceGroupParameterResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformInstanceGroupParameterResult)1