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


Java RunInstancesRequest.withSubnetId方法代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.RunInstancesRequest.withSubnetId方法的典型用法代码示例。如果您正苦于以下问题:Java RunInstancesRequest.withSubnetId方法的具体用法?Java RunInstancesRequest.withSubnetId怎么用?Java RunInstancesRequest.withSubnetId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.ec2.model.RunInstancesRequest的用法示例。


在下文中一共展示了RunInstancesRequest.withSubnetId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createInstance

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入方法依赖的package包/类
private com.amazonaws.services.ec2.model.Instance createInstance(KeyPair keyPair, String sgId) throws Exception {
    RunInstancesRequest request = new RunInstancesRequest()
        .withKeyName(keyPair.remoteKeyPair.getKeyName())
        .withInstanceType(InstanceType.M4Large)
        .withImageId(resource.baseAMI.imageId())
        .withMinCount(1)
        .withMaxCount(1)
        .withSecurityGroupIds(sgId);

    if (bakeSubnet != null) request.withSubnetId(bakeSubnet.getSubnetId());

    return AWS.ec2.runInstances(request,
        tagHelper.name(resourceId),
        tagHelper.env(),
        tagHelper.resourceId(resourceId),
        tagHelper.type("ami"),
        tagHelper.amiImageId(resource.id())).get(0);
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:19,代码来源:BakeAMITask.java

示例2: launchNodes

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入方法依赖的package包/类
public List<Instance> launchNodes(final String amiId, final String instanceType, final int numberToStart,
        final String userData, final boolean terminateOnShutdown) throws NodesCouldNotBeStartedException {
    RunInstancesRequest runRequest = new RunInstancesRequest();
    runRequest.withImageId(amiId).withInstanceType(instanceType).withMinCount(numberToStart)
              .withMaxCount(numberToStart).withUserData(userData);
    if (terminateOnShutdown) {
        runRequest.withInstanceInitiatedShutdownBehavior("terminate");
    }

    log.info("Setting image id: " + runRequest.getImageId());
    log.info("Setting instance type: " + runRequest.getInstanceType());

    String subnetKey = awsProperties.getProperty(region + "_subnet_id");
    if (subnetKey != null) {
        log.info("Setting subnet: " + subnetKey);
        runRequest.withSubnetId(subnetKey);
    }

    String securityGroupKey = awsProperties.getProperty(region + "_security_group");
    if (securityGroupKey != null) {

        String[] splitSecurityGroupdIds = securityGroupKey.split(",");

        List securityGroupIdsAryLst = new ArrayList();
        for (int i = 0; i < splitSecurityGroupdIds.length; i++) {

            log.info("Setting security group(s): " + splitSecurityGroupdIds[i]);
            securityGroupIdsAryLst.add(splitSecurityGroupdIds[i]);
        }
        runRequest.setSecurityGroupIds(securityGroupIdsAryLst);
    }

    String keyName = awsProperties.getProperty(region + "_key_name");
    if (keyName != null) {
        log.info("Setting keyname:" + keyName);
        runRequest.withKeyName(keyName);
    }

    log.info("Sending run request to AWS...");

    RunInstancesResult runInstancesResult = getResults(runRequest, 0);
    log.info("Run request result returned.  Adding tags");

    // Tag the instances with the standard RMN AWS data
    List<Instance> instances = runInstancesResult.getReservation().getInstances();
    if (instances.size() == 0) {
        throw new NodesCouldNotBeStartedException(String.format(
                "Error starting up nodes -- count was zero and did not match expected count of %d", numberToStart));
    }

    associateTags(new Date().toString(), instances);
    return instances;
}
 
开发者ID:RetailMeNot,项目名称:SeleniumGridScaler,代码行数:54,代码来源:AwsVmManager.java

示例3: getResults

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入方法依赖的package包/类
/**
 * Attempts to run the {@link com.amazonaws.services.ec2.model.RunInstancesRequest RunInstancesRequest}, falling
 * back on alternative subnets if capacity is full in the current region.
 *
 * @param   request
 * @param   requestNumber
 *
 * @return
 *
 * @throws  NodesCouldNotBeStartedException
 */
private RunInstancesResult getResults(final RunInstancesRequest request, int requestNumber)
    throws NodesCouldNotBeStartedException {
    RunInstancesResult runInstancesResult;
    try {
        if(client == null){
            throw new RuntimeException("The client is not initialized");
        }
        runInstancesResult = client.runInstances(request);
    } catch (AmazonServiceException e) {

        // If there is insufficient capacity in this subnet / availability zone, then we want to try other
        // configured subnets
        if ("InsufficientInstanceCapacity".equals(e.getErrorCode())
                || "VolumeTypeNotAvailableInZone".equals(e.getErrorCode())) {
            log.error(String.format("Insufficient capacity in subnet [%s]: %s", request.getSubnetId(), e));
            requestNumber = requestNumber + 1;

            String fallBackSubnetId = awsProperties.getProperty(region + "_subnet_fallback_id_" + requestNumber);

            // Make sure and only try to recursively loop so as long as we have a valid fallback subnet id.  Logic
            // to also
            // prevent an accidental infinite loop
            if (fallBackSubnetId != null && requestNumber < 5) {
                log.info("Setting fallback subnet: " + fallBackSubnetId);

                // Modify the original request with the new subnet ID we're trying to fallback on
                request.withSubnetId(fallBackSubnetId);
            } else {
                throw new NodesCouldNotBeStartedException(
                    "Sufficient resources were not available in any of the availability zones");
            }

            return getResults(request, requestNumber);
        } else {

            // We got an error other than insufficient capacity, and should just throw it for the caller to handle
            throw e;
        }
    }

    return runInstancesResult;
}
 
开发者ID:RetailMeNot,项目名称:SeleniumGridScaler,代码行数:54,代码来源:AwsVmManager.java


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