• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LaunchSpecification类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createSpotInstanceOffer

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
public List<SpotInstanceOfferResult> createSpotInstanceOffer(SpotInstanceOffer request)
{
    RequestSpotInstancesRequest spotRequest = new RequestSpotInstancesRequest(request.getOfferValue().toPlainString())
            .withValidFrom(request.getValidFrom())
            .withValidUntil(request.getValidUntil())
            .withType(SpotInstanceType.fromValue(request.getType().getName()))
            .withInstanceCount(request.getNumberOfInstances())
            .withLaunchSpecification(new LaunchSpecification()
                            .withInstanceType(request.getInstanceType().getName())
                            .withImageId(request.getImageId())
                            .withKeyName(request.getKeyName()));

    RequestSpotInstancesResult requestedSpotInstances = ec2_.requestSpotInstances(spotRequest);
    request.setStatus(new InstanceTemplateStatus().setStatus(Status.SUCCESS));

    return toSpotInstanceResults(request, requestedSpotInstances.getSpotInstanceRequests());
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:18,代码来源:EC2.java


示例2: placeSpotRequests

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
@Override
public List<SpotInstanceRequest> placeSpotRequests(double bidPrice, Ec2ProvisioningTemplate template, int count)
        throws AmazonClientException {
    List<SpotInstanceRequest> requests = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        String id = "sir-" + (System.currentTimeMillis() + count);
        SpotInstanceRequest request = new SpotInstanceRequest().withSpotInstanceRequestId(id)
                .withLaunchSpecification(new LaunchSpecification().withInstanceType(template.getInstanceType()))
                .withState(SpotInstanceState.Open).withSpotPrice(String.valueOf(bidPrice));

        if (!template.getTags().isEmpty()) {
            List<Tag> tags = new ArrayList<>();
            for (Entry<String, String> tag : template.getTags().entrySet()) {
                tags.add(new Tag(tag.getKey(), tag.getValue()));
            }
            request.withTags(tags);
        }
        this.spotRequests.put(id, request);
        requests.add(request);
    }
    return requests;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:23,代码来源:FakeSpotClient.java


示例3: notEqualLaunchSpecification

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
public boolean notEqualLaunchSpecification(LaunchSpecification oldLS, LaunchSpecification newLS) {
    if (notEqual(oldLS.getImageId(), newLS.getImageId())) return true;
    if (notEqual(oldLS.getKeyName(), newLS.getKeyName())) return true;
    if (notEqualCollection(oldLS.getAllSecurityGroups(), newLS.getAllSecurityGroups())) return true;
    if (notEqualCollection(oldLS.getSecurityGroups(), newLS.getSecurityGroups())) return true;
    if (notEqual(oldLS.getUserData(), newLS.getUserData())) return true;
    if (notEqual(oldLS.getAddressingType(), newLS.getAddressingType())) return true;
    if (notEqual(oldLS.getInstanceType(), newLS.getInstanceType())) return true;
    if (notEqual(oldLS.getPlacement(), newLS.getPlacement())) return true;
    if (notEqual(oldLS.getKernelId(), newLS.getKernelId())) return true;
    if (notEqual(oldLS.getRamdiskId(), newLS.getRamdiskId())) return true;
    if (notEqualCollection(oldLS.getBlockDeviceMappings(), newLS.getBlockDeviceMappings())) return true;
    if (notEqual(oldLS.getMonitoringEnabled(), newLS.getMonitoringEnabled())) return true;
    if (notEqual(oldLS.getSubnetId(), newLS.getSubnetId())) return true;
    if (notEqualInstanceNetworkInterfaceSpecifications(oldLS.getNetworkInterfaces(), newLS.getNetworkInterfaces())) return true;
    if (notEqual(oldLS.getIamInstanceProfile(), newLS.getIamInstanceProfile())) return true;
    if (notEqual(oldLS.getEbsOptimized(), newLS.getEbsOptimized())) return true;

    return false;
}
 
开发者ID:veyronfei,项目名称:clouck,代码行数:21,代码来源:Ec2SpotInstanceRequest.java


示例4: createInstances

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
public void createInstances(int count, double priceLimitDollars) {
	AmazonEC2 ec2 = new AmazonEC2Client(getAwsCredentials());
	ec2.setEndpoint(getOrCry("ec2endpoint"));

	log.info("Requesting " + count + " instances of type "
			+ getOrCry("ec2instancetype") + " with price limit of "
			+ priceLimitDollars + " US$");
	log.debug(startupScript);

	try {
		// our bid
		RequestSpotInstancesRequest runInstancesRequest = new RequestSpotInstancesRequest()
				.withSpotPrice(Double.toString(priceLimitDollars))
				.withInstanceCount(count).withType("persistent");

		// increase volume size
		// BlockDeviceMapping mapping = new BlockDeviceMapping()
		// .withDeviceName("/dev/sda1").withEbs(
		// new EbsBlockDevice().withVolumeSize(Integer
		// .parseInt(getOrCry("ec2disksize"))));

		// what we want
		LaunchSpecification workerSpec = new LaunchSpecification()
				.withInstanceType(getOrCry("ec2instancetype"))
				.withImageId(getOrCry("ec2ami"))
				.withKeyName(getOrCry("ec2keypair"))
				// .withBlockDeviceMappings(mapping)
				.withUserData(
						new String(Base64.encodeBase64(startupScript
								.getBytes())));

		runInstancesRequest.setLaunchSpecification(workerSpec);

		// place the request
		ec2.requestSpotInstances(runInstancesRequest);
		log.info("Request placed, now use 'monitor' to check how many instances are running. Use 'shutdown' to cancel the request and terminate the corresponding instances.");
	} catch (Exception e) {
		log.warn("Failed to start instances - ", e);
	}
}
 
开发者ID:JulianEberius,项目名称:dwtc-extractor,代码行数:41,代码来源:Master.java


示例5: launch

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
public List<String> launch(String workerAMI, String instanceType, int num,
		double price, List<String> securityGroups, String keyName, String userData, String charset) throws UnsupportedEncodingException {
	RequestSpotInstancesRequest requestRequest = new RequestSpotInstancesRequest();
	requestRequest.setSpotPrice(Double.toString(price));
	requestRequest.setInstanceCount(Integer.valueOf(num));

	LaunchSpecification launchSpecification = new LaunchSpecification();
	launchSpecification.setImageId(workerAMI);
	launchSpecification.setInstanceType(instanceType);
	launchSpecification.setSecurityGroups(securityGroups);
	launchSpecification.setUserData(new String(Base64.encode(userData.getBytes(charset))));
	launchSpecification.setKeyName(keyName); //for test
	
	requestRequest.setLaunchSpecification(launchSpecification);
	RequestSpotInstancesResult requestResult = ec2
			.requestSpotInstances(requestRequest);
	List<SpotInstanceRequest> requestResponses = requestResult
			.getSpotInstanceRequests();

	List<String> spotInstanceRequestIds = new ArrayList<String>();

	for (SpotInstanceRequest requestResponse : requestResponses) {
		System.out.println("Created Spot Request: "
				+ requestResponse.getSpotInstanceRequestId());
		spotInstanceRequestIds.add(requestResponse
				.getSpotInstanceRequestId());
	}
	return spotInstanceRequestIds;
}
 
开发者ID:cs553-cloud-computing,项目名称:amazon-cloudengine,代码行数:30,代码来源:EC2.java


示例6: main

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
public static void main(String[] args) {
    String region = "us-east-1";

    AWSCredentials credentials = new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey);

    AmazonEC2 api = AmazonEC2ClientBuilder.standard().withRegion(region)
            .withCredentials(new AWSStaticCredentialsProvider(credentials)).build();

    // no particular availability zone
    String availabilityZone = null;
    String instanceType = "t1.micro";
    String imageId = "ami-3cf8b154";
    List<String> securityGroups = Arrays.asList("webserver");
    String keyPair = "instancekey";

    String bootScript = Joiner.on("\n")
            .join(Arrays.asList("#!/bin/bash", "sudo apt-get update -qy", "sudo apt-get install -qy apache2"));
    int instanceCount = 50;
    String bidPrice = "0.001";

    SpotPlacement placement = new SpotPlacement().withAvailabilityZone(availabilityZone);
    LaunchSpecification launchSpec = new LaunchSpecification().withInstanceType(instanceType).withImageId(imageId)
            .withPlacement(placement).withSecurityGroups(securityGroups).withKeyName(keyPair)
            .withUserData(AmazonApiUtils.base64Encode(bootScript));
    RequestSpotInstancesRequest request = new RequestSpotInstancesRequest().withInstanceCount(instanceCount)
            .withType(SpotInstanceType.Persistent).withSpotPrice(bidPrice).withLaunchSpecification(launchSpec);
    RequestSpotInstancesResult result = api.requestSpotInstances(request);

    for (SpotInstanceRequest spotRequest : result.getSpotInstanceRequests()) {
        LOG.info("placed request: {}", spotRequest.getSpotInstanceRequestId());
    }
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:33,代码来源:PlaceMultiInstanceRequest.java


示例7: call

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
@Override
public List<SpotInstanceRequest> call() {
    LaunchSpecification spec = new LaunchSpecification();
    spec.withInstanceType(this.instanceTemplate.getInstanceType());
    spec.withImageId(this.instanceTemplate.getAmiId());

    InstanceNetworkInterfaceSpecification nic = new InstanceNetworkInterfaceSpecification();
    nic.withDeviceIndex(0);
    // select a subnet at random
    nic.withSubnetId(randomSubnet());
    nic.withAssociatePublicIpAddress(this.instanceTemplate.isAssignPublicIp());
    nic.withGroups(this.instanceTemplate.getSecurityGroupIds());
    spec.withNetworkInterfaces(nic);

    spec.withKeyName(this.instanceTemplate.getKeyPair());
    spec.withIamInstanceProfile(
            new IamInstanceProfileSpecification().withArn(this.instanceTemplate.getIamInstanceProfileARN()));
    spec.withUserData(this.instanceTemplate.getEncodedUserData());
    spec.withEbsOptimized(this.instanceTemplate.isEbsOptimized());

    RequestSpotInstancesRequest spotRequest = new RequestSpotInstancesRequest().withInstanceCount(this.count)
            .withType(SpotInstanceType.Persistent).withSpotPrice(this.bidPrice).withLaunchSpecification(spec);

    RequestSpotInstancesResult result = getClient().getApi().requestSpotInstances(spotRequest);
    List<String> spotRequestIds = result.getSpotInstanceRequests().stream()
            .map(SpotInstanceRequest::getSpotInstanceRequestId).collect(Collectors.toList());

    if (!this.instanceTemplate.getTags().isEmpty()) {
        tagRequests(spotRequestIds);
    }

    return awaitSpotRequests(spotRequestIds);
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:34,代码来源:PlaceSpotInstanceRequests.java


示例8: newRequestSpotInstanceRequest

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
/**
 * Builds a {@code RequestSpotInstancesRequest}.
 *
 * @return the {@code RequestSpotInstancesRequest}
 */
@VisibleForTesting
protected RequestSpotInstancesRequest newRequestSpotInstanceRequest(String virtualInstanceId) {

  String image = template.getImage();
  String type = template.getType();

  InstanceNetworkInterfaceSpecification network =
      getInstanceNetworkInterfaceSpecification(template);

  List<BlockDeviceMapping> deviceMappings = getBlockDeviceMappings(template);

  LaunchSpecification launchSpecification = new LaunchSpecification()
      .withImageId(image)
      .withInstanceType(type)
      .withNetworkInterfaces(network)
      .withBlockDeviceMappings(deviceMappings)
      .withEbsOptimized(template.isEbsOptimized());

  if (template.getIamProfileName().isPresent()) {
    launchSpecification.withIamInstanceProfile(new IamInstanceProfileSpecification()
        .withName(template.getIamProfileName().get()));
  }

  if (template.getKeyName().isPresent()) {
    launchSpecification.withKeyName(template.getKeyName().get());
  }

  SpotPlacement placement = null;
  if (template.getAvailabilityZone().isPresent()) {
    placement = new SpotPlacement().withAvailabilityZone(template.getAvailabilityZone().get());
  }
  if (template.getPlacementGroup().isPresent()) {
    placement = (placement == null) ?
        new SpotPlacement().withGroupName(template.getPlacementGroup().get())
        : placement.withGroupName(template.getPlacementGroup().get());
  }
  launchSpecification.withPlacement(placement);

  Optional<String> userData = template.getUserData();
  if (userData.isPresent()) {
    launchSpecification.withUserData(userData.get());
  }

  LOG.info(">> Spot instance request type: {}, image: {}", type, image);

  RequestSpotInstancesRequest request = new RequestSpotInstancesRequest()
      .withSpotPrice(template.getSpotBidUSDPerHour().get().toString())
      .withLaunchSpecification(launchSpecification)
      .withInstanceCount(1)
      .withClientToken(determineClientToken(virtualInstanceId, requestExpirationTime.getTime()))
      .withValidUntil(requestExpirationTime);

  Optional<Integer> blockDurationMinutes = template.getBlockDurationMinutes();
  if (blockDurationMinutes.isPresent()) {
    request.withBlockDurationMinutes(blockDurationMinutes.get());
  }

  return request;
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:65,代码来源:EC2Provider.java


示例9: spotRequest

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
public void spotRequest() {
		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();

		RequestSpotInstancesRequest requestRequest = new RequestSpotInstancesRequest();

		requestRequest.setSpotPrice(Double.valueOf(maxPrice).toString());
//		requestRequest.setInstanceCount(instances);
		requestRequest.setInstanceCount(instances - instancesSet.size());

		LaunchSpecification launchSpecification = new LaunchSpecification();
		launchSpecification.setImageId(ami);
		launchSpecification.setInstanceType(size);
		if (userData != null)
			launchSpecification.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);

		launchSpecification.setBlockDeviceMappings(blockList);

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

		launchSpecification.setKeyName(keyName);

		requestRequest.setLaunchSpecification(launchSpecification);

		RequestSpotInstancesResult requestResult = client
				.requestSpotInstances(requestRequest);

		List<SpotInstanceRequest> reqs = requestResult
				.getSpotInstanceRequests();
		for (SpotInstanceRequest req : reqs)
			instancesSet.add(new Instance(this, req.getInstanceId(), req
					.getSpotInstanceRequestId()));
	}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:52,代码来源:VirtualMachine.java


示例10: createRequest

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
private AmazonWebServiceRequest createRequest(Pool pool, DelegateExecution execution, boolean spot)
    throws IOException {
    final String businessKey = execution.getProcessBusinessKey();

    final String securityGroupName = SecurityGroups.formatNameFromBusinessKey(businessKey);
    final String keyPairName = KeyPairs.formatNameFromBusinessKey(businessKey);

    final String instanceType = pool.getHardware().getType();
    final String imageId = getImageIdFromPoolConfigurationOrQueryImageTable(
        pool, pool.getProvider(), instanceType);

    final String userData = Resources.toString(Resources.getResource(RunInstances.class,
        "/org/apache/provisionr/amazon/userdata.sh"), Charsets.UTF_8);

    List<BlockDevice> blockDevices = pool.getHardware().getBlockDevices();
    List<BlockDeviceMapping> blockDeviceMappings = Lists.newArrayList();
    if (blockDevices != null && blockDevices.size() > 0) {
        for (BlockDevice device : blockDevices) {
            blockDeviceMappings.add(new BlockDeviceMapping()
                .withDeviceName(device.getName())
                .withEbs(new EbsBlockDevice()
                    .withVolumeSize(device.getSize())
                    .withDeleteOnTermination(true)
                ));
        }
    }

    if (spot) {
        Calendar validUntil = Calendar.getInstance();
        validUntil.add(Calendar.MINUTE, 10);

        final String spotPrice = checkNotNull(pool.getProvider().getOption(ProviderOptions.SPOT_BID),
            "The bid for spot instances was not specified");

        LaunchSpecification ls = new LaunchSpecification()
            .withInstanceType(instanceType)
            .withKeyName(keyPairName)
            .withImageId(imageId)
            .withBlockDeviceMappings(blockDeviceMappings)
            .withSecurityGroups(Lists.newArrayList(securityGroupName))
            .withUserData(Base64.encodeBytes(userData.getBytes(Charsets.UTF_8)));

        return new RequestSpotInstancesRequest()
            .withSpotPrice(spotPrice)
            .withLaunchSpecification(ls)
            .withLaunchGroup(businessKey)
            .withInstanceCount(pool.getExpectedSize())
            .withType(SpotInstanceType.OneTime)
            .withValidUntil(validUntil.getTime());

    } else {
        return new RunInstancesRequest()
            .withClientToken(businessKey)
            .withSecurityGroups(securityGroupName)
            .withKeyName(keyPairName)
            .withInstanceType(instanceType)
            .withImageId(imageId)
            .withBlockDeviceMappings(blockDeviceMappings)
            .withMinCount(pool.getMinSize())
            .withMaxCount(pool.getExpectedSize())
            .withUserData(Base64.encodeBytes(userData.getBytes(Charsets.UTF_8)));
    }
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:64,代码来源:RunInstances.java


示例11: spotRequest

import com.amazonaws.services.ec2.model.LaunchSpecification; //导入依赖的package包/类
/**
 * Create a {@link SpotInstanceRequest} that may be associated with an
 * {@link Instance}.
 *
 * @param id
 * @param state
 * @param instanceId
 * @return
 */
public static SpotInstanceRequest spotRequest(String id, String state, String instanceId, Tag... tags) {
    return new SpotInstanceRequest().withSpotInstanceRequestId(id)
            .withLaunchSpecification(new LaunchSpecification().withInstanceType(InstanceType.M1Medium)
                    .withPlacement(new SpotPlacement("us-east-1b")))
            .withState(state).withInstanceId(instanceId).withTags(tags);
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:16,代码来源:SpotTestUtil.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Mark类代码示例发布时间:2022-05-23
下一篇:
Java DeferedCollection类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap