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


Java RunInstancesRequest类代码示例

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


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

示例1: runInstance

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
private RunInstancesResult runInstance(String GROUP_NAME, String clustertype) {
	RunInstancesRequest runInstancesRequest = new RunInstancesRequest();

	runInstancesRequest.withImageId(ami)
	.withInstanceType(type)
	.withMinCount(1)
	.withMaxCount(1)
	.withKeyName(MY_KEY)
	.withSecurityGroups(GROUP_NAME);

	RunInstancesResult result = ec2.runInstances(runInstancesRequest);
	System.out.println(clustertype+" node reservation:"+result.getReservation().getInstances().get(0).getInstanceId());

	tagInstance(result.getReservation().getInstances().get(0).getInstanceId(),"Name",name+"-"+clustertype,ec2);

	return result;
}
 
开发者ID:spagnuolocarmine,项目名称:aws-cluster-toolkit,代码行数:18,代码来源:AwsClusterManager.java

示例2: testCreateInstanceUserData

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
@Test
public void testCreateInstanceUserData() throws Exception {
    String userData = "line1\nline2\n";
    String userDataBase64 = Base64.encodeBase64String(userData.getBytes());
    File myFile = createUserDataFile(userData);
    try {
        URL fileUrl = myFile.toURI().toURL();
        parameters.put(PropertyHandler.USERDATA_URL, new Setting(
                PropertyHandler.USERDATA_URL, fileUrl.toString()));
        ec2mock.createRunInstancesResult("instance2");
        ec2mock.createDescribeImagesResult("image1");
        ec2mock.createDescribeSubnetsResult("subnet-a77430d0");
        ec2mock.createDescribeSecurityGroupResult("subnet-a77430d0",
                "security_group1,security_group2");
        ec2mock.createDescribeInstancesResult("instance1", "ok", "1.2.3.4");
        Image image = ec2comm.resolveAMI("image1");

        ec2comm.createInstance(image);
        String result = ph.getAWSInstanceId();
        assertEquals("instance2", result);
        ArgumentCaptor<RunInstancesRequest> arg1 = ArgumentCaptor
                .forClass(RunInstancesRequest.class);
        verify(ec2).runInstances(arg1.capture());
        RunInstancesRequest rir = arg1.getValue();
        assertEquals(userDataBase64, rir.getUserData());
    } finally {
        myFile.delete();
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:30,代码来源:EC2CommunicationTest.java

示例3: testCreateInstanceSecurityGroupsMultiple

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
@Test
public void testCreateInstanceSecurityGroupsMultiple() throws Exception {
    parameters.put(PropertyHandler.SECURITY_GROUP_NAMES, new Setting(
            PropertyHandler.SECURITY_GROUP_NAMES,
            "security_group1, security_group2"));
    ec2mock.createRunInstancesResult("instance3");
    ec2mock.createDescribeImagesResult("image1");
    ec2mock.createDescribeSubnetsResult("subnet-a77430d0");
    ec2mock.createDescribeSecurityGroupResult("subnet-a77430d0",
            "security_group1,security_group2");
    ec2mock.createDescribeInstancesResult("instance1", "ok", "1.2.3.4");
    Image image = ec2comm.resolveAMI("image1");
    ec2comm.createInstance(image);
    String result = ph.getAWSInstanceId();
    assertEquals("instance3", result);

    ArgumentCaptor<RunInstancesRequest> arg1 = ArgumentCaptor
            .forClass(RunInstancesRequest.class);
    verify(ec2).runInstances(arg1.capture());
    RunInstancesRequest rir = arg1.getValue();
    // Network interfaces and an instance-level security groups may not be
    // specified on the same request..
    assertEquals(2, rir.getNetworkInterfaces().get(0).getGroups().size());
    // assertEquals("security_group1", rir.getSecurityGroups().get(0));
    // assertEquals("security_group2", rir.getSecurityGroups().get(1));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:27,代码来源:EC2CommunicationTest.java

示例4: provisionAWSVMWithEC2Client

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
/**
 * Method to directly provision instances on the AWS endpoint without the knowledge of the local
 * system. This is used to spawn instances and to test that the discovery of items not
 * provisioned by Xenon happens correctly.
 *
 * @throws Throwable
 */
public static List<String> provisionAWSVMWithEC2Client(AmazonEC2AsyncClient client,
        VerificationHost host, int numberOfInstance, String instanceType, String subnetId,
        String securityGroupId) throws Throwable {
    host.log("Provisioning %d instances on the AWS endpoint using the EC2 client.",
            numberOfInstance);

    RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
            .withSubnetId(subnetId)
            .withImageId(EC2_LINUX_AMI).withInstanceType(instanceType)
            .withMinCount(numberOfInstance).withMaxCount(numberOfInstance)
            .withSecurityGroupIds(securityGroupId);

    // handler invoked once the EC2 runInstancesAsync commands completes
    AWSRunInstancesAsyncHandler creationHandler = new AWSRunInstancesAsyncHandler(
            host);
    client.runInstancesAsync(runInstancesRequest, creationHandler);
    host.waitFor("Waiting for instanceIds to be retured from AWS", () -> {
        return checkInstanceIdsReturnedFromAWS(numberOfInstance, creationHandler.instanceIds);

    });

    return creationHandler.instanceIds;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:31,代码来源:TestAWSSetupUtils.java

示例5: provisionAWSEBSVMWithEC2Client

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
public static String provisionAWSEBSVMWithEC2Client(VerificationHost host, AmazonEC2Client client,
        String ami, String subnetId, String securityGroupId, BlockDeviceMapping blockDeviceMapping) {

    RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
            .withSubnetId(subnetId)
            .withImageId(ami)
            .withInstanceType(instanceType)
            .withMinCount(1).withMaxCount(1)
            .withSecurityGroupIds(securityGroupId)
            .withBlockDeviceMappings(blockDeviceMapping);

    // handler invoked once the EC2 runInstancesAsync commands completes
    RunInstancesResult result = null;
    try {
        result = client.runInstances(runInstancesRequest);
    } catch (Exception e) {
        host.log(Level.SEVERE, "Error encountered in provisioning machine on AWS",
                Utils.toString(e));
    }
    assertNotNull(result);
    assertNotNull(result.getReservation());
    assertNotNull(result.getReservation().getInstances());
    assertEquals(1, result.getReservation().getInstances().size());

    return result.getReservation().getInstances().get(0).getInstanceId();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:27,代码来源:TestAWSSetupUtils.java

示例6: runInstances

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
public List<Instance> runInstances(RunInstancesRequest request, Tag... tags) throws Exception {
    logger.info("create ec2 instance, request={}", request);

    RunInstancesResult result = new Runner<RunInstancesResult>()
        .maxAttempts(3)
        .retryInterval(Duration.ofSeconds(20))
        .retryOn(this::retryOnRunInstance)
        .run(() -> ec2.runInstances(request));

    Threads.sleepRoughly(Duration.ofSeconds(5)); // wait little bit to make sure instance is visible to tag service
    List<String> instanceIds = result.getReservation().getInstances().stream().map(Instance::getInstanceId).collect(Collectors.toList());

    CreateTagsRequest tagsRequest = new CreateTagsRequest()
        .withResources(instanceIds)
        .withTags(tags);

    createTags(tagsRequest);

    waitUntilRunning(instanceIds);

    return describeInstances(instanceIds);
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:23,代码来源:EC2.java

示例7: 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

示例8: handleException

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
protected AutoException handleException(AmazonServiceException exception, Method method, Object[] args) {
    Object request = null;
    if (method.getParameterTypes().length > 0) {
        request = args[0];
    }

    // UserDataにはパスワードが含まれているためマスクする
    if (request instanceof RunInstancesRequest) {
        ((RunInstancesRequest) request).setUserData(null);
    }

    String str = StringUtils.reflectToString(request);

    return new AutoException("EAWS-000003", exception, method.getName(), exception.getErrorCode(),
            exception.getMessage(), str);
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:17,代码来源:ExceptionHandleAwsClientWrapper.java

示例9: testLaunchNodes

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
@Test
// Happy path test flow for launching nodes
public void testLaunchNodes() 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="windows";
    Integer threadCount = 5,maxSessions=5;
    MockManageVm manageEC2 = new MockManageVm(client,properties,region);
    String userData = "userData";
    manageEC2.setUserData(userData);
    List<Instance> instances = manageEC2.launchNodes(uuid,os,browser,null,threadCount,maxSessions);
    RunInstancesRequest request = client.getRunInstancesRequest();
    Assert.assertEquals("Min count should match thread count requested", threadCount, request.getMinCount());
    Assert.assertEquals("Max count should match thread count requested", threadCount, request.getMaxCount());
    Assert.assertEquals("User data should match", userData, request.getUserData());
    Assert.assertTrue("No security group should be set", request.getSecurityGroupIds().isEmpty());
    Assert.assertNull("No subnet should be set", request.getSubnetId());
    Assert.assertNull("No key name should be set", request.getKeyName());
}
 
开发者ID:RetailMeNot,项目名称:SeleniumGridScaler,代码行数:25,代码来源:VmManagerTest.java

示例10: execute

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
@Override
public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) throws IOException {

    final RunInstancesRequest request = createOnDemandInstancesRequest(pool, execution);
    // TODO allow for more options (e.g. monitoring & termination protection etc.)

    LOG.info(">> Sending RunInstances request: {}", request);
    RunInstancesResult result = client.runInstances(request);
    LOG.info("<< Got RunInstances result: {}", result);

    // TODO tag instances: managed-by: Apache Provisionr, business-key: ID etc.

    execution.setVariable(ProcessVariables.RESERVATION_ID,
        result.getReservation().getReservationId());
    execution.setVariable(ProcessVariables.INSTANCE_IDS,
        collectInstanceIdsAsList(result.getReservation().getInstances()));
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:18,代码来源:RunOnDemandInstances.java

示例11: runInstances

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
/**
 * Run some new ec2 instances.
 *
 * @param imageId
 *            AMI for running new instances from
 * @param runCount
 *            count of instances to run
 * @return a list of started instances
 */
public static List<Instance> runInstances(final String imageId, final int runCount) {
    // 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);

    // instance type
    String instanceType = "m1.large";

    // run 10 instances
    RunInstancesRequest request = new RunInstancesRequest();
    final int minRunCount = runCount;
    final int maxRunCount = runCount;
    request.withImageId(imageId).withInstanceType(instanceType)
            .withMinCount(minRunCount).withMaxCount(maxRunCount);
    RunInstancesResult result = amazonEC2Client.runInstances(request);

    return result.getReservation().getInstances();
}
 
开发者ID:treelogic-swe,项目名称:aws-mock,代码行数:32,代码来源:RunInstancesExample.java

示例12: runInstances

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
/**
 * Run instances with a random AMI ID.
 *
 * @param type
 *            instance type
 * @param minCount
 *            minimum start up instance number
 * @param maxCount
 *            maximum start up instance number
 * @return a list of instances started.
 */
protected final List<Instance> runInstances(final InstanceType type,
        final int minCount, final int maxCount) {
    log.info("Run instances: type=" + type + ", minCount=" + minCount
            + ", maxCount=" + maxCount);
    RunInstancesRequest request = new RunInstancesRequest();

    String imageId = randomAMI();

    request.withImageId(imageId).withInstanceType(type.getName())
            .withMinCount(minCount).withMaxCount(maxCount);

    RunInstancesResult result = amazonEC2Client.runInstances(request);
  
    return result.getReservation().getInstances();
}
 
开发者ID:treelogic-swe,项目名称:aws-mock,代码行数:27,代码来源:BaseTest.java

示例13: 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

示例14: process_CREATION_REQUESTED

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
@Test
public void process_CREATION_REQUESTED() throws Exception {
    ph.setOperation(Operation.EC2_CREATION);
    ph.setState(FlowState.CREATION_REQUESTED);
    InstanceStatus result = ec2proc.process();
    assertFalse(result.isReady());
    assertEquals(FlowState.CREATING, ph.getState());

    verify(ec2).runInstances(any(RunInstancesRequest.class));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:11,代码来源:EC2ProcessorTest.java

示例15: testCreateInstance

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入依赖的package包/类
@Test
public void testCreateInstance() throws Exception {
    ec2mock.createRunInstancesResult("instance1");
    ec2mock.createDescribeImagesResult("image1");
    ec2mock.createDescribeSubnetsResult("subnet-a77430d0");
    ec2mock.createDescribeSecurityGroupResult("subnet-a77430d0",
            "security_group1,security_group2");
    ec2mock.createDescribeInstancesResult("instance1", "ok", "1.2.3.4");
    Image image = ec2comm.resolveAMI("image1");
    ec2comm.createInstance(image);
    String result = ph.getAWSInstanceId();
    assertEquals("instance1", result);
    ArgumentCaptor<RunInstancesRequest> arg1 = ArgumentCaptor
            .forClass(RunInstancesRequest.class);
    verify(ec2).runInstances(arg1.capture());
    RunInstancesRequest rir = arg1.getValue();
    assertEquals("image1", rir.getImageId());
    assertEquals("type1", rir.getInstanceType());
    assertEquals("key_pair", rir.getKeyName());
    assertEquals(1, rir.getMinCount().intValue());
    assertEquals(1, rir.getMaxCount().intValue());

    ArgumentCaptor<CreateTagsRequest> arg2 = ArgumentCaptor
            .forClass(CreateTagsRequest.class);
    verify(ec2).createTags(arg2.capture());
    CreateTagsRequest ctr = arg2.getValue();
    for (Tag t : ctr.getTags()) {
        if (t.getKey().equalsIgnoreCase("Name")) {
            assertEquals("name1", t.getValue());
        } else if (t.getKey().equalsIgnoreCase("SubscriptionId")) {
            assertEquals("subId", t.getValue());
        } else if (t.getKey().equalsIgnoreCase("OrganizationId")) {
            assertEquals("orgId", t.getValue());
        }
    }

    parameters.put("USERDATA_URL", new Setting("USERDATA_URL", "userdata"));

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:40,代码来源:EC2CommunicationTest.java


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