Search in sources :

Example 1 with CloudAccessConfig

use of com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig in project cloudbreak by hortonworks.

the class AwsPlatformResources method accessConfigs.

@Override
public CloudAccessConfigs accessConfigs(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    String queryFailedMessage = "Could not get instance profile roles from Amazon: ";
    CloudAccessConfigs cloudAccessConfigs = new CloudAccessConfigs(new HashSet<>());
    AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
    AmazonIdentityManagement client = awsClient.createAmazonIdentityManagement(awsCredentialView);
    try {
        ListInstanceProfilesResult listRolesResult = client.listInstanceProfiles();
        for (InstanceProfile instanceProfile : listRolesResult.getInstanceProfiles()) {
            Map<String, Object> properties = new HashMap<>();
            properties.put("arn", instanceProfile.getArn());
            properties.put("creationDate", instanceProfile.getCreateDate().toString());
            if (!instanceProfile.getRoles().isEmpty()) {
                String roleName = instanceProfile.getRoles().get(0).getArn();
                properties.put("roleArn", Strings.isNullOrEmpty(roleName) ? instanceProfile.getArn() : roleName);
            }
            cloudAccessConfigs.getCloudAccessConfigs().add(new CloudAccessConfig(instanceProfile.getInstanceProfileName(), instanceProfile.getInstanceProfileId(), properties));
        }
    } catch (AmazonServiceException ase) {
        if (ase.getStatusCode() == UNAUTHORIZED) {
            String policyMessage = "Could not get instance profile roles because the user does not have enough permission.";
            LOGGER.info(policyMessage + ase);
            throw new CloudConnectorException(policyMessage, ase);
        } else {
            LOGGER.error(queryFailedMessage, ase);
            throw new CloudConnectorException(queryFailedMessage + ase.getMessage(), ase);
        }
    } catch (Exception e) {
        LOGGER.error(queryFailedMessage, e);
        throw new CloudConnectorException(queryFailedMessage + e.getMessage(), e);
    }
    return cloudAccessConfigs;
}
Also used : CloudAccessConfig(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig) HashMap(java.util.HashMap) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) IOException(java.io.IOException) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) InstanceProfile(com.amazonaws.services.identitymanagement.model.InstanceProfile) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonIdentityManagement(com.amazonaws.services.identitymanagement.AmazonIdentityManagement) ListInstanceProfilesResult(com.amazonaws.services.identitymanagement.model.ListInstanceProfilesResult)

Example 2 with CloudAccessConfig

use of com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig in project cloudbreak by hortonworks.

the class CloudAccessConfigsToPlatformAccessConfigsResponseConverter method convert.

@Override
public PlatformAccessConfigsResponse convert(CloudAccessConfigs source) {
    PlatformAccessConfigsResponse platformAccessConfigsResponse = new PlatformAccessConfigsResponse();
    Set<AccessConfigJson> result = new HashSet<>();
    for (CloudAccessConfig entry : source.getCloudAccessConfigs()) {
        AccessConfigJson actual = new AccessConfigJson(entry.getName(), entry.getId(), entry.getProperties());
        result.add(actual);
    }
    platformAccessConfigsResponse.setAccessConfigs(result);
    return platformAccessConfigsResponse;
}
Also used : CloudAccessConfig(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig) PlatformAccessConfigsResponse(com.sequenceiq.cloudbreak.api.model.PlatformAccessConfigsResponse) AccessConfigJson(com.sequenceiq.cloudbreak.api.model.AccessConfigJson) HashSet(java.util.HashSet)

Aggregations

CloudAccessConfig (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonIdentityManagement (com.amazonaws.services.identitymanagement.AmazonIdentityManagement)1 InstanceProfile (com.amazonaws.services.identitymanagement.model.InstanceProfile)1 ListInstanceProfilesResult (com.amazonaws.services.identitymanagement.model.ListInstanceProfilesResult)1 AccessConfigJson (com.sequenceiq.cloudbreak.api.model.AccessConfigJson)1 PlatformAccessConfigsResponse (com.sequenceiq.cloudbreak.api.model.PlatformAccessConfigsResponse)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1