本文整理汇总了Java中com.amazonaws.services.ec2.model.RequestSpotInstancesResult类的典型用法代码示例。如果您正苦于以下问题:Java RequestSpotInstancesResult类的具体用法?Java RequestSpotInstancesResult怎么用?Java RequestSpotInstancesResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestSpotInstancesResult类属于com.amazonaws.services.ec2.model包,在下文中一共展示了RequestSpotInstancesResult类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createSpotInstanceOffer
import com.amazonaws.services.ec2.model.RequestSpotInstancesResult; //导入依赖的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: launch
import com.amazonaws.services.ec2.model.RequestSpotInstancesResult; //导入依赖的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
示例3: main
import com.amazonaws.services.ec2.model.RequestSpotInstancesResult; //导入依赖的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
示例4: call
import com.amazonaws.services.ec2.model.RequestSpotInstancesResult; //导入依赖的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
示例5: execute
import com.amazonaws.services.ec2.model.RequestSpotInstancesResult; //导入依赖的package包/类
@Override
public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) throws IOException {
/* before sending a new request, we check to see if we already registered
a launch group with the process ID, if yes, we don't re-send the request */
final String businessKey = execution.getProcessBusinessKey();
/* we timeout if requests have already been sent - the activity is being retried. */
Optional<Object> alreadySent = Optional.fromNullable(
execution.getVariable(ProcessVariables.SPOT_INSTANCE_REQUEST_IDS));
if (alreadySent.isPresent()) {
DescribeSpotInstanceRequestsRequest describeRequest = new DescribeSpotInstanceRequestsRequest()
.withFilters(new Filter()
.withName("launch-group").withValues(businessKey)
.withName("state").withValues("open", "active"));
Stopwatch stopwatch = new Stopwatch().start();
while (stopwatch.elapsedTime(TimeUnit.MINUTES) < 2) {
DescribeSpotInstanceRequestsResult result = client.describeSpotInstanceRequests(describeRequest);
List<SpotInstanceRequest> pending = result.getSpotInstanceRequests();
if (pending.size() > 0) {
LOG.info("Not resending spot instance requests {} for businessKey: {}.", pending, businessKey);
execution.setVariable(ProcessVariables.SPOT_INSTANCE_REQUEST_IDS,
collectSpotInstanceRequestIds(pending));
return;
}
LOG.info("The describe call has not returned anything yet, waiting 20s and retrying.");
Uninterruptibles.sleepUninterruptibly(20, TimeUnit.SECONDS);
}
}
final RequestSpotInstancesRequest request = createSpotInstancesRequest(pool, execution);
execution.setVariable(ProcessVariables.SPOT_REQUESTS_SENT, true);
RequestSpotInstancesResult requestResult = client.requestSpotInstances(request);
List<String> spotInstanceRequestIds = collectSpotInstanceRequestIds(requestResult.getSpotInstanceRequests());
execution.setVariable(ProcessVariables.SPOT_INSTANCE_REQUEST_IDS, spotInstanceRequestIds);
}
开发者ID:apache,项目名称:incubator-provisionr,代码行数:39,代码来源:RunSpotInstances.java
示例6: requestSpotInstances
import com.amazonaws.services.ec2.model.RequestSpotInstancesResult; //导入依赖的package包/类
@Override
public RequestSpotInstancesResult requestSpotInstances(RequestSpotInstancesRequest requestSpotInstancesRequest) throws AmazonServiceException, AmazonClientException {
throw new UnsupportedOperationException("Not supported in mock");
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AmazonEC2Mock.java
示例7: spotRequest
import com.amazonaws.services.ec2.model.RequestSpotInstancesResult; //导入依赖的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
注:本文中的com.amazonaws.services.ec2.model.RequestSpotInstancesResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论