List of usage examples for com.amazonaws.services.ec2.model DescribePlacementGroupsRequest DescribePlacementGroupsRequest
DescribePlacementGroupsRequest
From source file:com.cloudera.director.aws.ec2.EC2InstanceTemplateConfigurationValidator.java
License:Apache License
/** * Validates the configured placement group. * * @param client the EC2 client * @param configuration the configuration to be validated * @param accumulator the exception condition accumulator * @param localizationContext the localization context *//* ww w . j av a 2 s . c o m*/ @VisibleForTesting void checkPlacementGroup(AmazonEC2Client client, Configured configuration, PluginExceptionConditionAccumulator accumulator, LocalizationContext localizationContext) { String placementGroup = configuration.getConfigurationValue(PLACEMENT_GROUP, localizationContext); if (placementGroup != null) { LOG.info(">> Describing placement group '{}'", placementGroup); try { DescribePlacementGroupsResult result = client.describePlacementGroups( new DescribePlacementGroupsRequest().withGroupNames(placementGroup)); checkCount(accumulator, PLACEMENT_GROUP, localizationContext, "Placement group", result.getPlacementGroups()); } catch (AmazonServiceException e) { if (e.getErrorCode().startsWith(INVALID_PLACEMENT_GROUP_ID)) { addError(accumulator, PLACEMENT_GROUP, localizationContext, null, INVALID_PLACEMENT_GROUP_MSG, placementGroup); } else { throw Throwables.propagate(e); } } } }
From source file:org.excalibur.service.aws.ec2.EC2.java
License:Open Source License
public void createPlacementGroupsIfDoNotExist(org.excalibur.core.cloud.api.Placement... groups) { if (groups != null) { ListeningExecutorService executor = newListeningDynamicScalingThreadPool( String.format("create-groups-%s", credentials_.getRegion().getName())); List<Callable<Void>> tasks = newArrayList(); for (final org.excalibur.core.cloud.api.Placement placement : groups) { tasks.add(new Callable<Void>() { @Override/*from w w w. jav a 2 s . com*/ public Void call() throws Exception { if (placement != null && !isNullOrEmpty(placement.getGroupName())) { try { new AmazonEC2Client(awsCredentials_) .describePlacementGroups(new DescribePlacementGroupsRequest() .withGroupNames(placement.getGroupName())); } catch (AmazonClientException exception) { LOG.debug("The group {} is unknown! Provider message: {}", placement.getGroupName(), exception.getMessage()); ec2_.createPlacementGroup( new CreatePlacementGroupRequest().withGroupName(placement.getGroupName()) .withStrategy(PlacementStrategy.Cluster)); } } return null; } }); } invokeAllAndShutdownWhenFinish(tasks, executor); } }