本文整理匯總了Java中com.amazonaws.services.ec2.AmazonEC2.describeSpotInstanceRequests方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonEC2.describeSpotInstanceRequests方法的具體用法?Java AmazonEC2.describeSpotInstanceRequests怎麽用?Java AmazonEC2.describeSpotInstanceRequests使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.ec2.AmazonEC2
的用法示例。
在下文中一共展示了AmazonEC2.describeSpotInstanceRequests方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
@Override
public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) {
LOG.info(">> retrieving instance Ids from spot request Ids");
@SuppressWarnings("unchecked")
List<String> requestIds =
(List<String>) execution.getVariable(ProcessVariables.SPOT_INSTANCE_REQUEST_IDS);
DescribeSpotInstanceRequestsResult result = client.describeSpotInstanceRequests(
new DescribeSpotInstanceRequestsRequest().withSpotInstanceRequestIds(requestIds));
List<String> instanceIds = new ArrayList<String>();
for (SpotInstanceRequest spotRequest : result.getSpotInstanceRequests()) {
if (spotRequest.getInstanceId() != null) {
instanceIds.add(spotRequest.getInstanceId());
}
}
execution.setVariable(ProcessVariables.INSTANCE_IDS, instanceIds);
}
示例2: execute
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
@Override
public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) {
LOG.info(">> Checking if all spot requests match predicate {}", predicate);
@SuppressWarnings("unchecked")
List<String> requestIds = (List<String>) execution.getVariable(ProcessVariables.SPOT_INSTANCE_REQUEST_IDS);
checkNotNull(requestIds, "process variable '{}' not found", ProcessVariables.SPOT_INSTANCE_REQUEST_IDS);
DescribeSpotInstanceRequestsRequest describeRequest = new DescribeSpotInstanceRequestsRequest();
describeRequest.setSpotInstanceRequestIds(requestIds);
// Retrieve all of the requests we want to monitor.
DescribeSpotInstanceRequestsResult describeResult = client.describeSpotInstanceRequests(describeRequest);
List<SpotInstanceRequest> requests = describeResult.getSpotInstanceRequests();
if (Iterables.all(requests, predicate)) {
LOG.info(">> All {} requests match predicate {} ", requests, predicate);
execution.setVariable(resultVariable, true);
} else {
LOG.info("<< Not all requests {} match predicate {}", requests, predicate);
execution.setVariable(resultVariable, false);
}
}
示例3: shutdownInstances
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
public void shutdownInstances() {
AmazonEC2 ec2 = new AmazonEC2Client(getAwsCredentials());
ec2.setEndpoint(getOrCry("ec2endpoint"));
try {
// cancel spot request, so no new instances will be launched
DescribeSpotInstanceRequestsRequest describeRequest = new DescribeSpotInstanceRequestsRequest();
DescribeSpotInstanceRequestsResult describeResult = ec2
.describeSpotInstanceRequests(describeRequest);
List<SpotInstanceRequest> describeResponses = describeResult
.getSpotInstanceRequests();
List<String> spotRequestIds = new ArrayList<String>();
List<String> instanceIds = new ArrayList<String>();
for (SpotInstanceRequest describeResponse : describeResponses) {
spotRequestIds.add(describeResponse.getSpotInstanceRequestId());
if ("active".equals(describeResponse.getState())) {
instanceIds.add(describeResponse.getInstanceId());
}
}
ec2.cancelSpotInstanceRequests(new CancelSpotInstanceRequestsRequest()
.withSpotInstanceRequestIds(spotRequestIds));
log.info("Cancelled spot request");
if (instanceIds.size() > 0) {
ec2.terminateInstances(new TerminateInstancesRequest(
instanceIds));
log.info("Shut down " + instanceIds.size() + " instances");
}
} catch (Exception e) {
log.warn("Failed to shutdown instances - ", e);
}
}
示例4: describeSpotInstanceRequests
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
@Override
public List<AbstractResource<?>> describeSpotInstanceRequests(Account account, Region region, DateTime dt, Ec2Filter... filters) {
AmazonEC2 ec2 = findClient(account, region);
DescribeSpotInstanceRequestsRequest req = new DescribeSpotInstanceRequestsRequest();
for (Ec2Filter filter : filters) {
Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues());
req.withFilters(f);
}
log.debug("start describing spot instance requests for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region);
DescribeSpotInstanceRequestsResult res = ec2.describeSpotInstanceRequests(req);
return converter.toEc2SpotInstanceRequest(res.getSpotInstanceRequests(), account.getId(), region, dt);
}
示例5: execute
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
@Override
public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) throws IOException {
/* before sending a new request, we check to see if we already registered
a launch group with the process ID, if yes, we don't re-send the request */
final String businessKey = execution.getProcessBusinessKey();
/* we timeout if requests have already been sent - the activity is being retried. */
Optional<Object> alreadySent = Optional.fromNullable(
execution.getVariable(ProcessVariables.SPOT_INSTANCE_REQUEST_IDS));
if (alreadySent.isPresent()) {
DescribeSpotInstanceRequestsRequest describeRequest = new DescribeSpotInstanceRequestsRequest()
.withFilters(new Filter()
.withName("launch-group").withValues(businessKey)
.withName("state").withValues("open", "active"));
Stopwatch stopwatch = new Stopwatch().start();
while (stopwatch.elapsedTime(TimeUnit.MINUTES) < 2) {
DescribeSpotInstanceRequestsResult result = client.describeSpotInstanceRequests(describeRequest);
List<SpotInstanceRequest> pending = result.getSpotInstanceRequests();
if (pending.size() > 0) {
LOG.info("Not resending spot instance requests {} for businessKey: {}.", pending, businessKey);
execution.setVariable(ProcessVariables.SPOT_INSTANCE_REQUEST_IDS,
collectSpotInstanceRequestIds(pending));
return;
}
LOG.info("The describe call has not returned anything yet, waiting 20s and retrying.");
Uninterruptibles.sleepUninterruptibly(20, TimeUnit.SECONDS);
}
}
final RequestSpotInstancesRequest request = createSpotInstancesRequest(pool, execution);
execution.setVariable(ProcessVariables.SPOT_REQUESTS_SENT, true);
RequestSpotInstancesResult requestResult = client.requestSpotInstances(request);
List<String> spotInstanceRequestIds = collectSpotInstanceRequestIds(requestResult.getSpotInstanceRequests());
execution.setVariable(ProcessVariables.SPOT_INSTANCE_REQUEST_IDS, spotInstanceRequestIds);
}
示例6: checkSpotInstance
import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
@Parameters({"region", "hostGroupToCheck", "scalingAdjustment"})
@Test
public void checkSpotInstance(Regions region, String hostGroupToCheck, @Optional Integer scalingAdjustment) {
//GIVEN
Integer spotInstanceCount = 0;
IntegrationTestContext itContext = getItContext();
String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
StackV1Endpoint stackV1Endpoint = getCloudbreakClient().stackV1Endpoint();
StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
List<InstanceGroupResponse> instanceGroups = stackResponse.getInstanceGroups();
List<String> instanceIdList = new ArrayList<>();
List<String> hostGroupList = Arrays.asList(hostGroupToCheck.split(","));
for (InstanceGroupResponse instanceGroup : instanceGroups) {
if (hostGroupList.contains(instanceGroup.getGroup())) {
Set<InstanceMetaDataJson> instanceMetaData = instanceGroup.getMetadata();
for (InstanceMetaDataJson metaData : instanceMetaData) {
instanceIdList.add(metaData.getInstanceId());
}
}
}
//WHEN
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(region).build();
DescribeSpotInstanceRequestsResult describeSpotInstanceRequestsResult = ec2.describeSpotInstanceRequests();
List<SpotInstanceRequest> spotInstanceRequests = describeSpotInstanceRequestsResult.getSpotInstanceRequests();
//THEN
Assert.assertFalse(spotInstanceRequests.isEmpty());
List<String> spotInstanceIdList = new ArrayList<>();
for (SpotInstanceRequest request : spotInstanceRequests) {
spotInstanceIdList.add(request.getInstanceId());
}
for (String id : instanceIdList) {
Assert.assertTrue(spotInstanceIdList.contains(id));
if (spotInstanceIdList.contains(id)) {
spotInstanceCount += 1;
}
}
if (scalingAdjustment != null) {
Assert.assertNotNull(itContext.getContextParam(CloudbreakITContextConstants.INSTANCE_COUNT, List.class));
Integer instanceCountPrev = 0;
for (String hostGroup : hostGroupList) {
List<Map<String, Integer>> instanceList = itContext.getContextParam(CloudbreakITContextConstants.INSTANCE_COUNT, List.class);
Assert.assertTrue(instanceList.size() >= 2);
instanceCountPrev += instanceList.get(instanceList.size() - 2).get(hostGroup);
}
Assert.assertEquals(Integer.valueOf(instanceCountPrev + scalingAdjustment), spotInstanceCount);
}
}