本文整理匯總了Java中com.amazonaws.services.ec2.model.Reservation.setInstances方法的典型用法代碼示例。如果您正苦於以下問題:Java Reservation.setInstances方法的具體用法?Java Reservation.setInstances怎麽用?Java Reservation.setInstances使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.ec2.model.Reservation
的用法示例。
在下文中一共展示了Reservation.setInstances方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testLaunchNodes
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的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());
}
示例2: testTagsAssociated
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
public void testTagsAssociated() {
MockAmazonEc2Client client = new MockAmazonEc2Client(null);
Collection<Instance> instances = Arrays.asList(new Instance());
DescribeInstancesResult describeInstancesResult = new DescribeInstancesResult();
Reservation reservation = new Reservation();
describeInstancesResult.setReservations(Arrays.asList(reservation));
reservation.setInstances(instances);
client.setDescribeInstances(describeInstancesResult);
Properties properties = new Properties();
properties.setProperty("tagAccounting","key,value");
properties.setProperty("function_tag","foo2");
properties.setProperty("product_tag","foo3");
AwsTagReporter reporter = new AwsTagReporter("testUuid",client,instances,properties);
reporter.run();
}
示例3: testExceptionCaught
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
public void testExceptionCaught() {
MockAmazonEc2Client client = new MockAmazonEc2Client(null);
Collection<Instance> instances = Arrays.asList(new Instance());
DescribeInstancesResult describeInstancesResult = new DescribeInstancesResult();
Reservation reservation = new Reservation();
describeInstancesResult.setReservations(Arrays.asList(reservation));
reservation.setInstances(instances);
client.setDescribeInstances(describeInstancesResult);
Properties properties = new Properties();
properties.setProperty("tagAccounting","key");
properties.setProperty("function_tag","foo2");
properties.setProperty("product_tag","foo3");
AwsTagReporter reporter = new AwsTagReporter("testUuid",client,instances,properties);
reporter.run();
}
示例4: testClientThrowsErrors
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
public void testClientThrowsErrors() {
MockAmazonEc2Client client = new MockAmazonEc2Client(null);
client.setDescribeInstancesToThrowError();
Collection<Instance> instances = Arrays.asList(new Instance());
DescribeInstancesResult describeInstancesResult = new DescribeInstancesResult();
Reservation reservation = new Reservation();
describeInstancesResult.setReservations(Arrays.asList(reservation));
reservation.setInstances(instances);
client.setDescribeInstances(describeInstancesResult);
Properties properties = new Properties();
properties.setProperty("accounting_tag","foo");
properties.setProperty("function_tag","foo2");
properties.setProperty("product_tag","foo3");
AwsTagReporter reporter = new AwsTagReporter("testUuid",client,instances,properties) {
@Override
void sleep() throws InterruptedException {
// do nothing
}
};
reporter.run();
}
示例5: testSleepThrowsErrors
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
public void testSleepThrowsErrors() {
MockAmazonEc2Client client = new MockAmazonEc2Client(null);
client.setDescribeInstancesToThrowError();
Collection<Instance> instances = Arrays.asList(new Instance());
DescribeInstancesResult describeInstancesResult = new DescribeInstancesResult();
Reservation reservation = new Reservation();
describeInstancesResult.setReservations(Arrays.asList(reservation));
reservation.setInstances(instances);
client.setDescribeInstances(describeInstancesResult);
Properties properties = new Properties();
properties.setProperty("accounting_tag","foo");
properties.setProperty("function_tag","foo2");
properties.setProperty("product_tag","foo3");
AwsTagReporter reporter = new AwsTagReporter("testUuid",client,instances,properties) {
@Override
void sleep() throws InterruptedException {
throw new InterruptedException();
}
};
reporter.run();
}
示例6: testThreadTimesOut
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test()
public void testThreadTimesOut() {
MockAmazonEc2Client client = new MockAmazonEc2Client(null);
Collection<Instance> instances = Arrays.asList(new Instance());
DescribeInstancesResult describeInstancesResult = new DescribeInstancesResult();
Reservation reservation = new Reservation();
describeInstancesResult.setReservations(Arrays.asList(reservation));
// Make count mismatch
reservation.setInstances(Arrays.asList(new Instance(),new Instance()));
client.setDescribeInstances(describeInstancesResult);
Properties properties = new Properties();
properties.setProperty("accounting_tag","foo");
properties.setProperty("function_tag","foo2");
properties.setProperty("product_tag","foo3");
AwsTagReporter reporter = new AwsTagReporter("testUuid",client,instances,properties);
AwsTagReporter.TIMEOUT_IN_SECONDS = 1;
try{
reporter.run();
} catch(RuntimeException e) {
Assert.assertEquals("Error waiting for instances to exist to add tags",e.getMessage());
return;
}
Assert.fail("Exception should have been thrown since tags were never filed");
}
示例7: testNoShutdownNodeTracked
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
// Tests that a node that is being tracked internally is not shut down
public void testNoShutdownNodeTracked() {
MockVmManager ec2 = new MockVmManager();
Reservation reservation = new Reservation();
Instance instance = new Instance();
String instanceId = "foo";
AutomationContext.getContext().addNode(new AutomationDynamicNode("faky",instanceId,null,null,new Date(),1));
instance.setInstanceId(instanceId);
instance.setLaunchTime(AutomationUtils.modifyDate(new Date(),-5,Calendar.HOUR));
reservation.setInstances(Arrays.asList(instance));
ec2.setReservations(Arrays.asList(reservation));
AutomationReaperTask task = new AutomationReaperTask(null,ec2);
task.run();
Assert.assertFalse("Node should NOT be terminated as it was tracked internally", ec2.isTerminated());
}
示例8: convertObject
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Override
protected Reservation convertObject(ReservationDescription from) {
Reservation to = new Reservation();
to.setReservationId(from.getReservationId());
to.setOwnerId(from.getOwner());
to.setRequesterId(from.getRequestId());
to.setGroupNames(from.getGroups());
to.setInstances(new InstanceConverter().convert(from.getInstances()));
return to;
}
示例9: testLaunchNodesOptionalFieldsSet
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
// Test the optional fields for launching a node are indeed optional
public void testLaunchNodesOptionalFieldsSet() 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=null;
Integer threadCount = 5,maxSessions=5;
MockManageVm manageEC2 = new MockManageVm(client,properties,region);
String userData = "userData";
String securityGroup="securityGroup",subnetId="subnetId",keyName="keyName",linuxImage="linuxImage";
properties.setProperty(region + "_security_group",securityGroup);
properties.setProperty(region + "_subnet_id",subnetId);
properties.setProperty(region + "_key_name", keyName);
properties.setProperty(region + "_linux_node_ami", linuxImage);
manageEC2.setUserData(userData);
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.assertEquals("Image id should match",linuxImage,request.getImageId());
List<String> securityGroups = request.getSecurityGroupIds();
Assert.assertEquals("Only one security group should be set",1,securityGroups.size());
Assert.assertEquals("Only one security group should be set", securityGroup, securityGroups.get(0));
Assert.assertEquals("Subnet ids should match", subnetId, request.getSubnetId());
Assert.assertEquals("Key names should match", keyName, request.getKeyName());
}
示例10: testLaunchNodesIe
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
// Test launching an IE node works correctly
public void testLaunchNodesIe() 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="internet explorer",os=null;
Integer threadCount = 5,maxSessions=5;
MockManageVm manageEC2 = new MockManageVm(client,properties,region);
String userData = "userData";
String securityGroup="securityGroup",subnetId="subnetId",keyName="keyName",windowsImage="windowsImage";
properties.setProperty(region + "_security_group",securityGroup);
properties.setProperty(region + "_subnet_id",subnetId);
properties.setProperty(region + "_key_name", keyName);
properties.setProperty(region + "_windows_node_ami", windowsImage);
manageEC2.setUserData(userData);
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.assertEquals("Image id should match",windowsImage,request.getImageId());
List<String> securityGroups = request.getSecurityGroupIds();
Assert.assertEquals("Only one security group should be set",1,securityGroups.size());
Assert.assertEquals("Only one security group should be set", securityGroup, securityGroups.get(0));
Assert.assertEquals("Subnet ids should match", subnetId, request.getSubnetId());
Assert.assertEquals("Key names should match", keyName, request.getKeyName());
}
示例11: testLaunchNodesBadOs
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
// Test if a bad OS is specified, it is handled correctly
public void testLaunchNodesBadOs() 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="badOs";
Integer threadCount = 5,maxSessions=5;
MockManageVm manageEC2 = new MockManageVm(client,properties,region);
String userData = "userData";
String securityGroup="securityGroup",subnetId="subnetId",keyName="keyName",windowsImage="windowsImage";
properties.setProperty(region + "_security_group",securityGroup);
properties.setProperty(region + "_subnet_id", subnetId);
properties.setProperty(region + "_key_name", keyName);
properties.setProperty(region + "_windows_node_ami", windowsImage);
manageEC2.setUserData(userData);
try{
manageEC2.launchNodes(uuid,os,browser,null,threadCount,maxSessions);
} catch(RuntimeException e) {
Assert.assertTrue("Failure message should be correct",e.getMessage().contains(os));
return;
}
Assert.fail("Call should fail due to invalid OS");
}
示例12: testSubnetNoFallBack
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
// Tests that if no fallback subnets are specified, the correct exception is thrown
public void testSubnetNoFallBack() throws NodesCouldNotBeStartedException {
MockAmazonEc2Client client = new MockAmazonEc2Client(null);
AmazonServiceException exception = new AmazonServiceException("message");
exception.setErrorCode("InsufficientInstanceCapacity");
client.setThrowDescribeInstancesError(exception);
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="linux";
Integer threadCount = 5,maxSessions=5;
MockManageVm manageEC2 = new MockManageVm(client,properties,region);
String userData = "userData";
String securityGroup="securityGroup",subnetId="subnetId",keyName="keyName",windowsImage="windowsImage";
properties.setProperty(region + "_security_group",securityGroup);
properties.setProperty(region + "_subnet_id", subnetId);
properties.setProperty(region + "_key_name", keyName);
properties.setProperty(region + "_windows_node_ami", windowsImage);
manageEC2.setUserData(userData);
try{
manageEC2.launchNodes(uuid,os,browser,null,threadCount,maxSessions);
} catch(NodesCouldNotBeStartedException e) {
Assert.assertTrue("Failure message should be correct",e.getMessage().contains("Sufficient resources were not available in any of the availability zones"));
return;
}
Assert.fail("Call should fail due to insufficient resources");
}
示例13: testSubnetFallsBackSuccessfully
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
// Test that if a fallback subnet is specified, that the request for new nodes will fallback successfully and nodes will be spun up
public void testSubnetFallsBackSuccessfully() throws NodesCouldNotBeStartedException {
MockAmazonEc2Client client = new MockAmazonEc2Client(null);
AmazonServiceException exception = new AmazonServiceException("message");
exception.setErrorCode("InsufficientInstanceCapacity");
client.setThrowDescribeInstancesError(exception);
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="linux";
Integer threadCount = 5,maxSessions=5;
MockManageVm manageEC2 = new MockManageVm(client,properties,region);
String userData = "userData";
String securityGroup="securityGroup",subnetId="subnetId",keyName="keyName",windowsImage="windowsImage",fallBackSubnet="fallback";
properties.setProperty(region + "_security_group",securityGroup);
properties.setProperty(region + "_subnet_id", subnetId);
properties.setProperty(region + "_subnet_fallback_id_1", fallBackSubnet);
properties.setProperty(region + "_key_name", keyName);
properties.setProperty(region + "_windows_node_ami", windowsImage);
manageEC2.setUserData(userData);
List<Instance> instances = manageEC2.launchNodes(uuid,os,browser,null,threadCount,maxSessions);
System.out.print("");
}
示例14: testSubnetFallBackUnknownError
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
// Tests that if the client fails for an error other than insufficient capacity, subnet fallback logic is not performed
public void testSubnetFallBackUnknownError() throws NodesCouldNotBeStartedException {
MockAmazonEc2Client client = new MockAmazonEc2Client(null);
AmazonServiceException exception = new AmazonServiceException("message");
client.setThrowDescribeInstancesError(exception);
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="linux";
Integer threadCount = 5,maxSessions=5;
MockManageVm manageEC2 = new MockManageVm(client,properties,region);
String userData = "userData";
String securityGroup="securityGroup",subnetId="subnetId",keyName="keyName",windowsImage="windowsImage";
properties.setProperty(region + "_security_group",securityGroup);
properties.setProperty(region + "_subnet_id", subnetId);
properties.setProperty(region + "_key_name", keyName);
properties.setProperty(region + "_windows_node_ami", windowsImage);
manageEC2.setUserData(userData);
try{
manageEC2.launchNodes(uuid,os,browser,null,threadCount,maxSessions);
} catch(AmazonServiceException e) {
Assert.assertEquals("Exception should be the same",exception,e);
return;
}
Assert.fail("Call should fail due to other AWS error");
}
示例15: testSubnetInfiniteLoop
import com.amazonaws.services.ec2.model.Reservation; //導入方法依賴的package包/類
@Test
// Tests that the built in guard against an infinite loop in the fallback recursive logic has a working safeguard
public void testSubnetInfiniteLoop() throws NodesCouldNotBeStartedException {
MockAmazonEc2Client client = new MockAmazonEc2Client(null);
client.setThrowExceptionsInRunInstancesIndefinitely();
AmazonServiceException exception = new AmazonServiceException("message");
exception.setErrorCode("InsufficientInstanceCapacity");
client.setThrowDescribeInstancesError(exception);
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="linux";
Integer threadCount = 5,maxSessions=5;
MockManageVm manageEC2 = new MockManageVm(client,properties,region);
String userData = "userData";
String securityGroup="securityGroup",subnetId="subnetId",keyName="keyName",windowsImage="windowsImage";
properties.setProperty(region + "_security_group",securityGroup);
properties.setProperty(region + "_subnet_id", subnetId);
properties.setProperty(region + "_subnet_fallback_id_1", "foo");
properties.setProperty(region + "_subnet_fallback_id_2", "foo");
properties.setProperty(region + "_subnet_fallback_id_3", "foo");
properties.setProperty(region + "_subnet_fallback_id_4", "foo");
properties.setProperty(region + "_subnet_fallback_id_5", "foo");
properties.setProperty(region + "_subnet_fallback_id_6", "foo");
properties.setProperty(region + "_key_name", keyName);
properties.setProperty(region + "_windows_node_ami", windowsImage);
manageEC2.setUserData(userData);
try{
manageEC2.launchNodes(uuid,os,browser,null,threadCount,maxSessions);
} catch(NodesCouldNotBeStartedException e) {
Assert.assertTrue("Failure message should be correct",e.getMessage().contains("Sufficient resources were not available in any of the availability zones"));
return;
}
Assert.fail("Call should fail due to insufficient resources");
}