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


Java RunInstancesResult.getReservation方法代码示例

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


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

示例1: onDemandRequest

import com.amazonaws.services.ec2.model.RunInstancesResult; //导入方法依赖的package包/类
public void onDemandRequest() {
		if (instances <= instancesSet.size()) {
			logger.info("No more instances will be launched because there are already enough.");
			return;
		}

		com.amazonaws.services.ec2.AmazonEC2 client = AmazonEC2.connect();

		RunInstancesRequest request = new RunInstancesRequest();

//		request.setMinCount(instances);
//		request.setMaxCount(instances);
		request.setMinCount(instances - instancesSet.size());
		request.setMaxCount(instances - instancesSet.size());
		request.setImageId(ami);
		request.setInstanceType(size);
		if (userData != null)
			request.setUserData(Base64.encodeAsString(userData
					.getBytes()));

		BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
		blockDeviceMapping.setDeviceName("/dev/sda1");

		EbsBlockDevice ebs = new EbsBlockDevice();
		ebs.setDeleteOnTermination(Boolean.TRUE);
		ebs.setVolumeSize(diskSize);
		blockDeviceMapping.setEbs(ebs);

		ArrayList<BlockDeviceMapping> blockList = new ArrayList<BlockDeviceMapping>();
		blockList.add(blockDeviceMapping);

		request.setBlockDeviceMappings(blockList);

		ArrayList<String> securityGroups = new ArrayList<String>();
		securityGroups.add(Configuration.SECURITY_GROUP_NAME);

		request.setSecurityGroups(securityGroups);
		request.setKeyName(keyName);

		RunInstancesResult requestResult = client.runInstances(request);

		Reservation reservation = requestResult.getReservation();
		reservation.getInstances();

		for (com.amazonaws.services.ec2.model.Instance i : reservation.getInstances())
			instancesSet.add(new Instance(this, i.getInstanceId(), null));
	}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:48,代码来源:VirtualMachine.java

示例2: launchEc2Instances

import com.amazonaws.services.ec2.model.RunInstancesResult; //导入方法依赖的package包/类
public List<Instance> launchEc2Instances(AmazonEC2Client ec2Client, Properties props) throws Exception {
	
	Integer totalExpectedWorkers = Integer.valueOf(props.getProperty("master.workers.total"));
	
	// disk size
	Collection<BlockDeviceMapping> blockDevices = new ArrayList<BlockDeviceMapping>();
	blockDevices.add(
			new BlockDeviceMapping()
				.withDeviceName(props.getProperty("master.workers.ec2.disk.deviceName"))
				.withEbs(new EbsBlockDevice()
						.withVolumeType(VolumeType.valueOf(props.getProperty("master.workers.ec2.disk.volumeType")))
						.withDeleteOnTermination(true)
					    .withVolumeSize(Integer.valueOf(props.getProperty("master.workers.ec2.disk.size.gigabytes")))));
	
	// create our run request for the total workers we expect
	RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
	runInstancesRequest.withImageId(props.getProperty("master.workers.ec2.ami.id"))
				        .withInstanceType(props.getProperty("master.workers.ec2.instanceType"))
				        .withMinCount(totalExpectedWorkers)
				        .withMaxCount(totalExpectedWorkers)
				        .withBlockDeviceMappings(blockDevices)
				        .withKeyName(props.getProperty("master.workers.ec2.keyName"))
				        .withSecurityGroupIds(props.getProperty("master.workers.ec2.securityGroupId"))
				        .withInstanceInitiatedShutdownBehavior(ShutdownBehavior.valueOf(props.getProperty("master.workers.ec2.shutdownBehavior")))
				        .withSubnetId(props.getProperty("master.workers.ec2.subnetId"))
				        .withUserData(Base64.encodeAsString(readFile(props.getProperty("master.workers.ec2.userDataFile")).getBytes()));
	
	// launch
	logger.debug("Launching " + totalExpectedWorkers + " EC2 instances, " +
						"it may take few minutes for workers to come up...: \n" +
						"\tamiId:" + runInstancesRequest.getImageId() +"\n"+
						"\tsecGrpId:" + runInstancesRequest.getSecurityGroupIds().get(0) +"\n"+
						"\tsubnetId:" + runInstancesRequest.getSubnetId() +"\n"+
						"\tinstanceType:" + runInstancesRequest.getInstanceType() +"\n"+
						"\tshutdownBehavior:" + runInstancesRequest.getInstanceInitiatedShutdownBehavior() +"\n"+
						"\tkeyName:" + runInstancesRequest.getKeyName() 
						);


	// as the instances come up, assuming the "userData" above launches the worker we will be good
	// they will auto register w/ us the master 
	RunInstancesResult result = ec2Client.runInstances(runInstancesRequest);
	Reservation reservation = result.getReservation();
	return reservation.getInstances();
}
 
开发者ID:bitsofinfo,项目名称:s3-bucket-loader,代码行数:46,代码来源:Ec2Util.java

示例3: launchInstances

import com.amazonaws.services.ec2.model.RunInstancesResult; //导入方法依赖的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.RunInstancesResult.getReservation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。