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


Java RunInstancesRequest.setSecurityGroupIds方法代码示例

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


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

示例1: launchInstance

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */
@Override
public String launchInstance( CreateInstanceOptions options,
                              Identity identity )
{
    RunInstancesRequest request = new RunInstancesRequest();
    if ( options.getInstanceProfileName() != null )
    {
        request.setIamInstanceProfile( new IamInstanceProfileSpecification().withName( options.getInstanceProfileName() ) );
    }
    request.setSubnetId( options.getWorkerOptions().getSubnetId() );
    request.setSecurityGroupIds( options.getWorkerOptions().getSecurityGroupIds() );
    if ( options.getUserData() != null )
    {
        request.setUserData( Base64.encodeBase64String( options.getUserData().getBytes() ) );
    }
    request.withMinCount( 1 ).withMaxCount( 1 ).withImageId( config.getAgentAmiId() ).withInstanceType( InstanceType.T1Micro );
    request.setKeyName( options.getWorkerOptions().getKeyPairName() );
    request.setClientToken( "launch-ec2-worker-"
        + contextProvider.getActivityExecutionContext().getWorkflowExecution().getWorkflowId() );

    AmazonEC2 ec2 =
        ActivityUtils.createClient( AmazonEC2Client.class, identity );
    RunInstancesResult result = ec2.runInstances( request );
    return result.getReservation().getInstances().get( 0 ).getInstanceId();
}
 
开发者ID:jiaqi,项目名称:datamung,代码行数:29,代码来源:Ec2ActivitiesImpl.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: testLaunchNodesMultipleSecurityGroups

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入方法依赖的package包/类
@Test
// Test if multiple security groups can be passed when launching a node
public void testLaunchNodesMultipleSecurityGroups()  throws NodesCouldNotBeStartedException {
    MockAmazonEc2Client client = new MockAmazonEc2Client(null);
    RunInstancesResult runInstancesResult = new RunInstancesResult();
    Reservation reservation = new Reservation();
    reservation.setInstances(Arrays.asList(new Instance()));
    runInstancesResult.setReservation(reservation);
    client.setRunInstances(runInstancesResult);
    Properties properties = new Properties();
    String region = "east", uuid="uuid",browser="chrome",os=null;
    Integer threadCount = 5,maxSessions=5;
    MockManageVm manageEC2 = new MockManageVm(client,properties,region);
    String userData = "userData";
    String securityGroup="securityGroup1,securityGroup2,securityGroup3",subnetId="subnetId",keyName="keyName",linuxImage="linuxImage";
    String[] splitSecurityGroupdIds = securityGroup.split(",");
    List securityGroupIdsAryLst = new ArrayList();

    if (securityGroup != null) {
        for (int i = 0; i < splitSecurityGroupdIds.length; i++) {
            securityGroupIdsAryLst.add(splitSecurityGroupdIds[i]);
        }
    }
    properties.setProperty(region + "_security_group",securityGroup);
    properties.setProperty(region + "_subnet_id",subnetId);
    properties.setProperty(region + "_key_name", keyName);
    properties.setProperty(region + "_linux_node_ami", linuxImage);
    manageEC2.setUserData(userData);
    manageEC2.launchNodes(uuid,os,browser,null,threadCount,maxSessions);
    RunInstancesRequest request = client.getRunInstancesRequest();
    request.setSecurityGroupIds(securityGroupIdsAryLst);
    List<String> securityGroups = request.getSecurityGroupIds();
    List<String> expectedSecurityGroups = Arrays.asList("securityGroup1,securityGroup2,securityGroup3".split(","));
    Assert.assertTrue("Security groups should match all given security groups", securityGroups.containsAll(expectedSecurityGroups));

    List<String> invalidSecurityGroups = Arrays.asList("securityGroup1,securityGroup2,securityGroup7".split(","));
    Assert.assertFalse("Security groups should match only the set security groups", securityGroups.containsAll(invalidSecurityGroups));

    Assert.assertFalse("Security group should not be empty", request.getSecurityGroupIds().isEmpty());
    Assert.assertEquals("More than 1 security group should be set",3,securityGroups.size());
}
 
开发者ID:RetailMeNot,项目名称:SeleniumGridScaler,代码行数:42,代码来源:VmManagerTest.java

示例4: launchInstances

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入方法依赖的package包/类
private void launchInstances(List<VPNEndpoint> vpnEndpoints) throws Exception {

    ApplicationConfig appConfig = ApplicationConfig.getInstance();

    for (VPNEndpoint vpnEndpoint : vpnEndpoints) {
      Region region = vpnEndpoint.getRegion();
      ec2Client.setEndpoint(region.getEndpoint());

      // Get the AMI for the region
      String amiKey = "ami." + region.getRegionName();
      String amiId = appConfig.get(amiKey);
      if (amiId == null) {
        String msg = "Unable to find AMI in " + region.getRegionName();
        LOG.error(msg);
        throw new RuntimeException(msg);
      }

      // Get the security group for the instance
      String securityGroupId = vpnEndpoint.getSecurityGroupId();
      List<String> securityGroupIds = new ArrayList();
      securityGroupIds.add(securityGroupId);

      // Setup the instance request object
      LOG.debug("Setting up RunInstancesRequest for instance in " + vpnEndpoint.getVpc().getCidrBlock() + " - " + region.getEndpoint());
      RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
      runInstancesRequest.setMinCount(1);
      runInstancesRequest.setMaxCount(1);
      runInstancesRequest.setImageId(amiId);
      runInstancesRequest.setSecurityGroupIds(securityGroupIds);
      runInstancesRequest.setInstanceType(InstanceType.T1Micro); // TODO: Make this configurable
      runInstancesRequest.setSubnetId(vpnEndpoint.getSubnet().getSubnetId());
      runInstancesRequest.setUserData(generateCloudInitScript(vpnEndpoint, vpnEndpoints));
      //runInstancesRequest.setKeyName("amazon"); // TODO: Remove this or make this configurable

      // Launch the instance
      LOG.debug("Issuing runInstances with: " + runInstancesRequest);
      RunInstancesResult result = ec2Client.runInstances(runInstancesRequest);
      Reservation reservation = result.getReservation();
      Instance instance = reservation.getInstances().get(0);  // Should be just one
      vpnEndpoint.setInstance(instance);
      LOG.debug("Launched instance: " + instance);
    }
  }
 
开发者ID:vinayselvaraj,项目名称:vpc2vpc,代码行数:44,代码来源:CreateConnection.java


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