当前位置: 首页>>代码示例>>Java>>正文


Java AmazonEC2.describeSpotInstanceRequests方法代码示例

本文整理汇总了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);
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:20,代码来源:GetInstanceIdsFromSpotRequests.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:25,代码来源:AllSpotRequestsMatchPredicate.java

示例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);
	}
}
 
开发者ID:JulianEberius,项目名称:dwtc-extractor,代码行数:35,代码来源:Master.java

示例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);
}
 
开发者ID:veyronfei,项目名称:clouck,代码行数:16,代码来源:Ec2WrapperImpl.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:39,代码来源:RunSpotInstances.java

示例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);
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:57,代码来源:AwsCheckSpotInstance.java


注:本文中的com.amazonaws.services.ec2.AmazonEC2.describeSpotInstanceRequests方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。