本文整理汇总了Java中com.amazonaws.services.ec2.model.RunInstancesResult类的典型用法代码示例。如果您正苦于以下问题:Java RunInstancesResult类的具体用法?Java RunInstancesResult怎么用?Java RunInstancesResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RunInstancesResult类属于com.amazonaws.services.ec2.model包,在下文中一共展示了RunInstancesResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runInstance
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的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;
}
示例2: provisionAWSVMWithEC2Client
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的package包/类
public static String provisionAWSVMWithEC2Client(VerificationHost host, AmazonEC2Client client,
String ami, String subnetId, String securityGroupId) {
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
.withSubnetId(subnetId)
.withImageId(ami)
.withInstanceType(instanceType)
.withMinCount(1).withMaxCount(1)
.withSecurityGroupIds(securityGroupId);
// 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();
}
示例3: provisionAWSEBSVMWithEC2Client
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的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();
}
示例4: runInstances
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的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);
}
示例5: testLaunchNodes
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的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());
}
示例6: execute
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的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()));
}
示例7: runInstances
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的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();
}
示例8: runInstances
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的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();
}
示例9: launchInstance
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的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();
}
示例10: createRunInstancesResult
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的package包/类
public void createRunInstancesResult(String... instanceIds) {
Collection<Instance> instances = new ArrayList<Instance>();
for (int i = 0; i < instanceIds.length; i++) {
instances.add(new Instance().withInstanceId(instanceIds[i]));
}
Reservation reservation = new Reservation().withInstances(instances);
RunInstancesResult result = new RunInstancesResult()
.withReservation(reservation);
doReturn(result).when(ec2).runInstances(any(RunInstancesRequest.class));
}
示例11: startInstance
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的package包/类
public static InstanceObject startInstance(AmazonEC2 ec2)
{
RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
runInstancesRequest.withImageId("ami-f6ed6785")
.withMonitoring(true)
.withInstanceType("t2.micro")
.withMinCount(1)
.withMaxCount(1)
.withKeyName("CNV-lab-AWS")
.withSecurityGroups("CNV-ssh+http");
RunInstancesResult runInstancesResult = ec2.runInstances(runInstancesRequest);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
List<Reservation> reservations = describeInstancesResult.getReservations();
ArrayList<Instance> auxListOfInstances = new ArrayList<Instance>();
for (Reservation reservation : reservations) {
auxListOfInstances.addAll(reservation.getInstances());
}
InstanceObject instanceObject = null;
for (Instance instance : auxListOfInstances) {
if(instance.getInstanceId().equals(runInstancesResult.getReservation().getInstances().get(0).getInstanceId())) //id do load balancer, nao adicionamos este as instancias
instanceObject = new InstanceObject(instance);
}
//retornamos a instance criada
return instanceObject;
}
示例12: onSuccess
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的package包/类
@Override
public void onSuccess(RunInstancesRequest request, RunInstancesResult result) {
for (Instance i : result.getReservation().getInstances()) {
this.instanceIds.add(i.getInstanceId());
this.host.log("Successfully created instances on AWS endpoint %s",
i.getInstanceId());
}
}
示例13: main
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的package包/类
public static void main(String[] args)
{
final String USAGE =
"To run this example, supply an instance name and AMI image id\n" +
"Ex: CreateInstance <instance-name> <ami-image-id>\n";
if (args.length != 2) {
System.out.println(USAGE);
System.exit(1);
}
String name = args[0];
String ami_id = args[1];
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
RunInstancesRequest run_request = new RunInstancesRequest()
.withImageId(ami_id)
.withInstanceType(InstanceType.T1Micro)
.withMaxCount(1)
.withMinCount(1);
RunInstancesResult run_response = ec2.runInstances(run_request);
String instance_id = run_response.getReservation().getReservationId();
Tag tag = new Tag()
.withKey("Name")
.withValue(name);
CreateTagsRequest tag_request = new CreateTagsRequest()
.withTags(tag);
CreateTagsResult tag_response = ec2.createTags(tag_request);
System.out.printf(
"Successfully started EC2 instance %s based on AMI %s",
instance_id, ami_id);
}
示例14: startEC2Instance
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的package包/类
/**
* Given an AMI start an EC2 Instance.
*
* @param amiId
* to start
* @return the id of the running instance.
* @throws ServiceBrokerException
*/
public String startEC2Instance(String amiId) throws ServiceBrokerException {
RunInstancesResult instance = ec2Client
.runInstances(new RunInstancesRequest().withImageId(amiId)
.withInstanceType("m1.small").withMinCount(1)
.withMaxCount(1).withSubnetId(subnetId)
.withInstanceType(InstanceType.T2Micro));
String instanceId = getInstanceId(instance);
addElasticIp(instanceId);
log.info("Instance " + instanceId + " started successfully");
return instanceId;
}
示例15: call
import com.amazonaws.services.ec2.model.RunInstancesResult; //导入依赖的package包/类
@Override
public List<Instance> call() {
RunInstancesRequest request = new RunInstancesRequest();
request.withInstanceType(this.instanceTemplate.getInstanceType());
request.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());
request.withNetworkInterfaces(nic);
request.withKeyName(this.instanceTemplate.getKeyPair());
request.withIamInstanceProfile(
new IamInstanceProfileSpecification().withArn(this.instanceTemplate.getIamInstanceProfileARN()));
request.withUserData(this.instanceTemplate.getEncodedUserData());
request.withEbsOptimized(this.instanceTemplate.isEbsOptimized());
request.withMinCount(this.count).withMaxCount(this.count);
if (!this.instanceTemplate.getTags().isEmpty()) {
TagSpecification tagSpecifications = new TagSpecification().withResourceType(ResourceType.Instance);
tagSpecifications.withTags(tags());
request.withTagSpecifications(tagSpecifications);
}
RunInstancesResult result = getClient().getApi().runInstances(request);
List<Instance> launchedInstances = result.getReservation().getInstances();
List<String> instanceIds = launchedInstances.stream().map(Instance::getInstanceId).collect(Collectors.toList());
return awaitInstances(instanceIds);
}