本文整理匯總了Java中com.amazonaws.services.ec2.model.DescribeInstancesRequest.withInstanceIds方法的典型用法代碼示例。如果您正苦於以下問題:Java DescribeInstancesRequest.withInstanceIds方法的具體用法?Java DescribeInstancesRequest.withInstanceIds怎麽用?Java DescribeInstancesRequest.withInstanceIds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.ec2.model.DescribeInstancesRequest
的用法示例。
在下文中一共展示了DescribeInstancesRequest.withInstanceIds方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: describeInstances
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
private void describeInstances(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
DescribeInstancesRequest request = new DescribeInstancesRequest();
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
request.withInstanceIds(instanceIds);
}
DescribeInstancesResult result;
try {
result = ec2Client.describeInstances(request);
} catch (AmazonServiceException ase) {
LOG.trace("Describe Instances command returned the error code {}", ase.getErrorCode());
throw ase;
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
示例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: checkTagsAws
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
protected static void checkTagsAws(Regions region, List<String> instanceIdList, Map<String, String> tagsToCheckMap) {
Map<String, String> extractedTagsToCheck = new HashMap<>();
List<Tag> extractedTags;
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(region).build();
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
describeInstancesRequest.withInstanceIds(instanceIdList);
DescribeInstancesResult describeInstancesResultAll = ec2.describeInstances(describeInstancesRequest);
List<Reservation> reservationsAll = describeInstancesResultAll.getReservations();
for (Reservation reservation : reservationsAll) {
for (Instance instance : reservation.getInstances()) {
extractedTags = instance.getTags();
Assert.assertNotNull(extractedTags);
for (Tag tag : extractedTags) {
extractedTagsToCheck.put(tag.getKey(), tag.getValue());
}
checkTags(tagsToCheckMap, extractedTagsToCheck);
extractedTags.clear();
}
}
}
示例4: waitForTransitionCompletion
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
public static void waitForTransitionCompletion(ServiceHost host,
List<InstanceStateChange> stateChangeList,
final String desiredState, AmazonEC2AsyncClient client,
BiConsumer<InstanceState, Exception> callback) {
InstanceStateChange stateChange = stateChangeList.get(0);
try {
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.withInstanceIds(stateChange.getInstanceId());
DescribeInstancesResult result = client.describeInstances(request);
Instance instance = result.getReservations()
.stream()
.flatMap(r -> r.getInstances().stream())
.filter(i -> i.getInstanceId()
.equalsIgnoreCase(stateChange.getInstanceId()))
.findFirst().orElseThrow(() -> new IllegalArgumentException(
String.format("%s instance not found", stateChange.getInstanceId())));
String state = instance.getState().getName();
if (state.equals(desiredState)) {
callback.accept(instance.getState(), null);
} else {
host.schedule(() -> waitForTransitionCompletion(host, stateChangeList, desiredState,
client, callback), 5, TimeUnit.SECONDS);
}
} catch (AmazonServiceException | IllegalArgumentException ase) {
callback.accept(null, ase);
}
}
示例5: getSingleEc2InstanceById
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
private Instance getSingleEc2InstanceById(String ec2InstanceId) {
DescribeInstancesRequest describeRequest = new DescribeInstancesRequest();
describeRequest.withInstanceIds(ec2InstanceId);
DescribeInstancesResult result = config.getAmazonEC2Client()
.describeInstances(describeRequest);
List<Reservation> reservations = result.getReservations();
List<Instance> instances = reservations.get(0).getInstances();
if (instances.size() == 0)
throw new RuntimeException(
"There is a problem, could not find an ec2 instance for id="
+ ec2InstanceId);
return instances.get(0);
}
示例6: getTurbineInstances
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
/**
* Convert from AWS ASG Instances to Turbine Instances
*
* @param asg
* @return list of Turbine Instances (not AWS Instances)
*/
private List<Instance> getTurbineInstances(AutoScalingGroup asg) {
String clusterName = asg.getTags()
.stream()
.filter(t -> t.getKey().equals(CLUSTER_TAG_KEY.get()))
.findAny()
.get().getValue();
List<com.amazonaws.services.autoscaling.model.Instance> awsInstances = asg.getInstances();
Collection<String> instanceIds = awsInstances.stream()
.map(com.amazonaws.services.autoscaling.model.Instance::getInstanceId)
.collect(Collectors.toSet());
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.withInstanceIds(instanceIds);
DescribeInstancesResult describeInstancesResult = ec2Client.describeInstances(request);
List<Reservation> reservations = describeInstancesResult.getReservations();
List<Instance> turbineInstances = new ArrayList<>();
// add all instances from each of the reservations - after converting to Turbine instance
reservations.stream()
.flatMap(r -> r.getInstances().stream())
.filter(i -> !Strings.isNullOrEmpty(i.getPublicDnsName()))
.map(i -> createTurbineInstance(clusterName, i))
.forEach(turbineInstances::add);
return turbineInstances;
}
示例7: run
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
@Override
public void run() {
log.info("AwsTagReporter thread initialized");
DescribeInstancesRequest request = new DescribeInstancesRequest();
Collection<String> instanceIds = new ArrayList<>();
for(Instance instance : instances) {
instanceIds.add(instance.getInstanceId());
}
request.withInstanceIds(instanceIds);
long startTime = System.currentTimeMillis();
boolean instancesFound = false;
do{
// Wait up to 10 seconds for the instances to exist with AWS
if(System.currentTimeMillis() > startTime + AwsTagReporter.TIMEOUT_IN_SECONDS) {
throw new RuntimeException("Error waiting for instances to exist to add tags");
}
try{
DescribeInstancesResult existingInstances = ec2Client.describeInstances(request);
if(existingInstances.getReservations().get(0).getInstances().size() == instances.size()) {
log.info("Correct instances were found to add tags to!");
instancesFound = true;
}
} catch(Throwable t) {
log.error("Error finding instances. Sleeping.");
try {
sleep();
} catch (InterruptedException e) {
log.error("Error sleeping for adding tags", e);
}
}
} while(!instancesFound);
associateTags(instances);
log.info("AwsTagReporter thread completed successfully");
}
示例8: getEC2Instances
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
/**
* Queries instances with given Ids on AWS
*
* @param instanceIds List of instance IDs
* @return
*/
protected Collection<com.amazonaws.services.ec2.model.Instance> getEC2Instances( Collection<String> instanceIds ) {
if( instanceIds == null || instanceIds.size() == 0 ) {
return new ArrayList<com.amazonaws.services.ec2.model.Instance>();
}
Collection<com.amazonaws.services.ec2.model.Instance> instances =
new LinkedList<com.amazonaws.services.ec2.model.Instance>();
DescribeInstancesRequest request = new DescribeInstancesRequest();
request = request.withInstanceIds( instanceIds );
DescribeInstancesResult result = null;
try {
result = client.describeInstances( request );
}
catch ( Exception e ) {
LOG.error( "Error while getting instance information from AWS.", e );
return Collections.EMPTY_LIST;
}
for ( Reservation reservation : result.getReservations() ) {
for ( com.amazonaws.services.ec2.model.Instance in : reservation.getInstances() ) {
instances.add( in );
}
}
return instances;
}
示例9: describeInstances
import com.amazonaws.services.ec2.model.DescribeInstancesRequest; //導入方法依賴的package包/類
/**
* Describe specified instances within aws-mock.
*
* @param instanceIDs
* a list of instance IDs to describe
* @return a list of specified instances
*/
public static List<Instance> describeInstances(final List<String> instanceIDs) {
// pass any credentials as aws-mock does not authenticate them at all
AWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);
// the mock endpoint for ec2 which runs on your computer
String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/";
amazonEC2Client.setEndpoint(ec2Endpoint);
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.withInstanceIds(instanceIDs);
DescribeInstancesResult response = amazonEC2Client.describeInstances(request);
List<Reservation> reservations = response.getReservations();
List<Instance> ret = new ArrayList<Instance>();
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
if (null != instances) {
for (Instance i : instances) {
ret.add(i);
}
}
}
return ret;
}