/** * 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 */ @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); } } } }
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 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); } }
@Override public PlacementGroupCollection getPlacementGroups( DescribePlacementGroupsRequest request) { ResourceCollectionImpl result = service.getCollection("PlacementGroups", request); if (result == null) return null; return new PlacementGroupCollectionImpl(result); }
@Override public List<AbstractResource<?>> describePlacementGroups(Account account, Region region, DateTime dt, Ec2Filter... filters) { AmazonEC2 ec2 = findClient(account, region); DescribePlacementGroupsRequest req = new DescribePlacementGroupsRequest(); for (Ec2Filter filter : filters) { Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues()); req.withFilters(f); } log.debug("start describing placement groups for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region); DescribePlacementGroupsResult res = ec2.describePlacementGroups(req); return converter.toEc2PlacementGroups(res.getPlacementGroups(), account.getId(), region, dt); }
@Override public DescribePlacementGroupsResult describePlacementGroups(DescribePlacementGroupsRequest describePlacementGroupsRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
@Override public boolean load(DescribePlacementGroupsRequest request) { return load(request, null); }
@Override public boolean load(DescribePlacementGroupsRequest request, ResultCapture<DescribePlacementGroupsResult> extractor) { return resource.load(request, extractor); }
@Override public PlacementGroupCollection getPlacementGroups() { return getPlacementGroups((DescribePlacementGroupsRequest)null); }
/** * Retrieves the PlacementGroups collection referenced by this resource. */ PlacementGroupCollection getPlacementGroups(DescribePlacementGroupsRequest request);
/** * Makes a call to the service to load this resource's attributes if they * are not loaded yet. * The following request parameters will be populated from the data of this * <code>PlacementGroup</code> resource, and any conflicting parameter value * set in the request will be overridden: * <ul> * <li> * <b><code>GroupNames.0</code></b> * - mapped from the <code>Name</code> identifier. * </li> * </ul> * * <p> * * @return Returns {@code true} if the resource is not yet loaded when this * method was invoked, which indicates that a service call has been * made to retrieve the attributes. * @see DescribePlacementGroupsRequest */ boolean load(DescribePlacementGroupsRequest request);
/** * Makes a call to the service to load this resource's attributes if they * are not loaded yet, and use a ResultCapture to retrieve the low-level * client response * The following request parameters will be populated from the data of this * <code>PlacementGroup</code> resource, and any conflicting parameter value * set in the request will be overridden: * <ul> * <li> * <b><code>GroupNames.0</code></b> * - mapped from the <code>Name</code> identifier. * </li> * </ul> * * <p> * * @return Returns {@code true} if the resource is not yet loaded when this * method was invoked, which indicates that a service call has been * made to retrieve the attributes. * @see DescribePlacementGroupsRequest */ boolean load(DescribePlacementGroupsRequest request, ResultCapture<DescribePlacementGroupsResult> extractor);