本文整理匯總了Java中com.amazonaws.services.ec2.model.DescribeInstancesRequest.withFilters方法的典型用法代碼示例。如果您正苦於以下問題:Java DescribeInstancesRequest.withFilters方法的具體用法?Java DescribeInstancesRequest.withFilters怎麽用?Java DescribeInstancesRequest.withFilters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.ec2.model.DescribeInstancesRequest
的用法示例。
在下文中一共展示了DescribeInstancesRequest.withFilters方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildDescribeInstancesRequest
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
private DescribeInstancesRequest buildDescribeInstancesRequest() {
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
.withFilters(
new Filter("instance-state-name").withValues("running", "pending")
);
for (Map.Entry<String, String> tagFilter : tags.entrySet()) {
// for a given tag key, OR relationship for multiple different values
describeInstancesRequest.withFilters(
new Filter("tag:" + tagFilter.getKey()).withValues(tagFilter.getValue())
);
}
if (!availabilityZones.isEmpty()) {
// OR relationship amongst multiple values of the availability-zone filter
describeInstancesRequest.withFilters(
new Filter("availability-zone").withValues(availabilityZones)
);
}
return describeInstancesRequest;
}
示例2: call
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public List<Instance> call() {
List<Instance> instances = new ArrayList<>();
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.withInstanceIds(this.instanceIds);
request.withFilters(this.filters);
// paginate through result as long as there is another response token
boolean moreResults = false;
do {
DescribeInstancesResult result = getClient().getApi().describeInstances(request);
instances.addAll(instances(result));
moreResults = result.getNextToken() != null && !result.getNextToken().equals("");
request.setNextToken(result.getNextToken());
} while (moreResults);
return instances;
}
示例3: doWork
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public void doWork() {
log.info("Running " + AutomationReaperTask.NAME);
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
Filter filter = new Filter("tag:LaunchSource");
filter.withValues("SeleniumGridScalerPlugin");
describeInstancesRequest.withFilters(filter);
List<Reservation> reservations = ec2.describeInstances(describeInstancesRequest);
for(Reservation reservation : reservations) {
for(Instance instance : reservation.getInstances()) {
// Look for orphaned nodes
Date threshold = AutomationUtils.modifyDate(new Date(),-30, Calendar.MINUTE);
String instanceId = instance.getInstanceId();
// If we found a node old enough AND we're not internally tracking it, this means this is an orphaned node and we should terminate it
if(threshold.after(instance.getLaunchTime()) && !AutomationContext.getContext().nodeExists(instanceId)) {
log.info("Terminating orphaned node: " + instanceId);
ec2.terminateInstance(instanceId);
}
}
}
}
示例4: describeReservations
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public List<AbstractResource<?>> describeReservations(Account account, Region region, DateTime dt, Ec2Filter... filters) {
AmazonEC2 ec2 = findClient(account, region);
DescribeInstancesRequest req = new DescribeInstancesRequest();
for (Ec2Filter filter : filters) {
Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues());
req.withFilters(f);
}
log.debug("start describing instances for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region);
DescribeInstancesResult res = ec2.describeInstances(req);
List<Map<String, Ec2InstanceAttribute>> attributes = new ArrayList<>();
for (Reservation r : res.getReservations()) {
Map<String, Ec2InstanceAttribute> attribute = new HashMap<>();
for (Instance i : r.getInstances()) {
Boolean terminationProtection = findTerminationProtection(account, region, i.getInstanceId());
String shutdownBehavior = findShutdownBehavior(account, region, i.getInstanceId());
String userData = findUserData(account, region, i.getInstanceId());
Ec2InstanceAttribute ia = new Ec2InstanceAttribute(terminationProtection, shutdownBehavior, userData);
attribute.put(i.getInstanceId(), ia);
}
attributes.add(attribute);
}
return converter.toEc2Reservations(res.getReservations(), attributes, account.getId(), region, dt);
}
示例5: getEC2InstanceIdsAssociatedWithVpcId
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
/**
* Get a list of all EC2 instance ids associated with a given VPC id.
*/
public static List<String> getEC2InstanceIdsAssociatedWithVpcId(AmazonEC2AsyncClient client, String vpcId) {
DescribeInstancesRequest req = new DescribeInstancesRequest();
if (vpcId != null) {
req.withFilters(new Filter(AWS_VPC_ID_FILTER, Collections.singletonList(vpcId)));
}
DescribeInstancesResult instancesResult = client.describeInstances(req);
return instancesResult == null ? Collections.emptyList()
: instancesResult.getReservations().get(0).getInstances().stream()
.map(instance -> instance.getInstanceId())
.collect(Collectors.toList());
}
示例6: listInstancesWithTags
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public Instances listInstancesWithTags(Tags tags)
{
Instances instances = new Instances ();
if (tags != null && !tags.isEmpty())
{
DescribeInstancesRequest request = new DescribeInstancesRequest();
for (org.excalibur.core.cloud.api.domain.Tag tag: tags)
{
if (!isNullOrEmpty(tag.getName()))
{
request.withFilters(new Filter().withName("tag-key").withValues(tag.getName()));
}
if (!isNullOrEmpty(tag.getValue()))
{
request.withFilters(new Filter().withName("tag-value").withValues(tag.getValue()));
}
}
instances = describeInstances(request);
}
return instances;
}
示例7: get
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public synchronized T get() {
try {
setMyRegion();
Map<String, ConnectionPoint> ipToHost = new HashMap<>();
DescribeInstancesRequest req = new DescribeInstancesRequest();
req.withFilters(filter);
DescribeInstancesResult res = client.describeInstances(req);
for (Reservation reservation : res.getReservations()) {
for (Instance instance : reservation.getInstances()) {
String privateIP = instance.getPrivateIpAddress();
if (privateIP != null) {
ConnectionPoint connectionPoint = new ConnectionPoint(privateIP, port);
ipToHost.put(privateIP, connectionPoint);
}
}
}
ArrayList<ConnectionPoint> currentHosts = new ArrayList<>(ipToHost.values());
logHostUpdate(previousHosts, currentHosts);
previousHosts = currentHosts;
return convertTo(previousHosts);
} catch (AmazonClientException ex) {
if (previousHosts == null) {
throw new RuntimeException(ex);
}
LOG.warn(
"Failed to get hosts for sg: {} in region: {}. Will use previously known hosts instead",
Arrays.toString(filter.getValues().toArray()),
region == null ? DEFAULT_REGION.toString() : region.toString()
);
return convertTo(previousHosts);
}
}