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


Java RunInstancesRequest.setUserData方法代码示例

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


在下文中一共展示了RunInstancesRequest.setUserData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: runInstances

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入方法依赖的package包/类
public List<String> runInstances(int numberOfInstances) {
	if (numberOfInstances <= 0)
		return null;
	
	if (numberOfInstances > 20) {
		numberOfInstances = 20;
		logger.info("Can't run more than 20 instances.");
	}
		
	
       RunInstancesRequest request = new RunInstancesRequest(Configuration.EC2_IMAGE_ID, numberOfInstances, numberOfInstances);
       request.setInstanceType(Configuration.EC2_INSTANCE_TYPE);
       IamInstanceProfileSpecification prof = new IamInstanceProfileSpecification();
       prof.setName(Configuration.EC2_IAM_PROFILE); // security concerns
       request.setIamInstanceProfile(prof);
       request.setUserData(getStartupScript()); // base64
       request.setKeyName(Configuration.EC2_KEYPAIR_NAME);
       List<Instance> instances = _ec2.runInstances(request).getReservation().getInstances();
       
       List<Tag> tags = new ArrayList<Tag>();
       tags.add(new Tag(_tagKey, _defaultTag));
       tags.add(new Tag("Name", _ofType.toString().toLowerCase()));
       
       logger.info("Launch instances: " + instances);
       
       List<String> instancesID = new ArrayList<String>();
       for (Instance instance : instances) {
       	instancesID.add(instance.getInstanceId());
       }
       
       // tag the resources
	CreateTagsRequest tagreq = new CreateTagsRequest(instancesID, tags);
       _ec2.createTags(tagreq);
       
       return instancesID;
}
 
开发者ID:apelyos,项目名称:distributed-image-classification,代码行数:37,代码来源:NodesMgmt.java

示例3: prepareEC2RequestNode

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入方法依赖的package包/类
/**
 * Prepares the request.
 * @param targetProperties the target properties
 * @param userData the user data to pass
 * @return a request
 * @throws UnsupportedEncodingException
 */
private RunInstancesRequest prepareEC2RequestNode( Map<String,String> targetProperties, String userData )
throws UnsupportedEncodingException {

	RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
	String flavor = targetProperties.get(Ec2Constants.VM_INSTANCE_TYPE);
	if( Utils.isEmptyOrWhitespaces( flavor ))
		flavor = "t1.micro";

	runInstancesRequest.setInstanceType( flavor );
	runInstancesRequest.setImageId( targetProperties.get( Ec2Constants.AMI_VM_NODE ));

	runInstancesRequest.setMinCount( 1 );
	runInstancesRequest.setMaxCount( 1 );
	runInstancesRequest.setKeyName( targetProperties.get(Ec2Constants.SSH_KEY_NAME));

	String secGroup = targetProperties.get(Ec2Constants.SECURITY_GROUP_NAME);
	if( Utils.isEmptyOrWhitespaces(secGroup))
		secGroup = "default";

	runInstancesRequest.setSecurityGroups(Collections.singletonList(secGroup));

	String availabilityZone = targetProperties.get(Ec2Constants.AVAILABILITY_ZONE);
	if(! Utils.isEmptyOrWhitespaces(availabilityZone))
		runInstancesRequest.setPlacement(new Placement(availabilityZone));

	// The following part enables to transmit data to the VM.
	// When the VM is up, it will be able to read this data.
	String encodedUserData = new String( Base64.encodeBase64( userData.getBytes( StandardCharsets.UTF_8 )), "UTF-8" );
	runInstancesRequest.setUserData( encodedUserData );

	return runInstancesRequest;
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:40,代码来源:Ec2IaasHandler.java

示例4: onDemandRequest

import com.amazonaws.services.ec2.model.RunInstancesRequest; //导入方法依赖的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

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