use of com.amazonaws.services.identitymanagement.model.ListInstanceProfilesRequest in project cloudbreak by hortonworks.
the class AwsPlatformResources method getAccessConfigByInstanceProfile.
private Set<CloudAccessConfig> getAccessConfigByInstanceProfile(AmazonIdentityManagementClient client) {
LOGGER.info("Get all Instance profiles from Amazon");
String queryFailedMessage = "Could not get instance profiles from Amazon: ";
try {
boolean finished = false;
String marker = null;
Set<InstanceProfile> instanceProfiles = new LinkedHashSet<>();
while (!finished) {
ListInstanceProfilesRequest listInstanceProfilesRequest = new ListInstanceProfilesRequest();
listInstanceProfilesRequest.setMaxItems(fetchMaxItems);
if (isNotEmpty(marker)) {
listInstanceProfilesRequest.setMarker(marker);
}
LOGGER.debug("About to fetch instance profiles...");
ListInstanceProfilesResult listInstanceProfilesResult = client.listInstanceProfiles(listInstanceProfilesRequest);
List<InstanceProfile> fetchedInstanceProfiles = listInstanceProfilesResult.getInstanceProfiles();
instanceProfiles.addAll(fetchedInstanceProfiles);
if (listInstanceProfilesResult.isTruncated()) {
marker = listInstanceProfilesResult.getMarker();
} else {
finished = true;
}
}
LOGGER.debug("The total of {} instance profile(s) has fetched.", instanceProfiles.size());
return instanceProfiles.stream().map(this::instanceProfileToCloudAccessConfig).collect(Collectors.toSet());
} catch (AmazonServiceException ase) {
if (ase.getStatusCode() == UNAUTHORIZED) {
LOGGER.error("Could not get instance profiles because the user does not have enough permission.", ase);
throw new CloudUnauthorizedException(ase.getMessage(), ase);
} else {
LOGGER.info(queryFailedMessage, ase);
throw new CloudConnectorException(ase.getMessage(), ase);
}
} catch (Exception e) {
LOGGER.warn(queryFailedMessage, e);
throw new CloudConnectorException(queryFailedMessage + e.getMessage(), e);
}
}
Aggregations