com.amazonaws.services.ec2.model.InstanceType Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.InstanceType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateInstance.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
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 reservation_id = run_response.getReservation().getInstances().get(0).getInstanceId(); 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", reservation_id, ami_id); }
Example #2
Source File: EC2ConnectorTest.java From jenkins-deployment-dashboard-plugin with MIT License | 5 votes |
@Test public void testGetEnvironmentFromInstance() throws Exception { final Date launchTime = new Date(); final Instance instance = new Instance().withInstanceId("instance").withInstanceType(InstanceType.C1Xlarge).withTags(new Tag(EC2Connector.DEFAULT_INSTANCE_NAME_TAG, "unknown")) .withState(new InstanceState().withName(InstanceStateName.Running)).withLaunchTime(launchTime).withPublicIpAddress("127.0.0.1"); ServerEnvironment serverEnv = Whitebox.<ServerEnvironment> invokeMethod(env, "getEnvironmentFromInstance", instance); assertThat(serverEnv, notNullValue()); assertThat(serverEnv.getInstanceId(), is("instance")); assertThat(serverEnv.getInstanceType(), is(InstanceType.C1Xlarge.toString())); assertThat(serverEnv.getType(), is(ENVIRONMENT_TYPES.TEST)); assertThat(serverEnv.getEnvironmentTag(), is("unknown")); assertThat(serverEnv.getState().getName(), is(InstanceStateName.Running.toString())); assertThat(serverEnv.getLaunchTime(), is(launchTime)); assertThat(serverEnv.getPublicIpAddress(), is("127.0.0.1")); }
Example #3
Source File: EC2ConnectorTest.java From jenkins-deployment-dashboard-plugin with MIT License | 5 votes |
@Test public void testGetEnvironmentFromInstanceProd() throws Exception { final Instance instance = new Instance().withInstanceId("instance").withInstanceType(InstanceType.C1Xlarge).withTags(new Tag(EC2Connector.DEFAULT_INSTANCE_NAME_TAG, EC2Connector.PROD_VALUE)); ServerEnvironment serverEnv = Whitebox.<ServerEnvironment> invokeMethod(env, "getEnvironmentFromInstance", instance); assertThat(serverEnv, notNullValue()); assertThat(serverEnv.getType(), is(ENVIRONMENT_TYPES.PRODUCTION)); }
Example #4
Source File: EC2ConnectorTest.java From jenkins-deployment-dashboard-plugin with MIT License | 5 votes |
@Test public void testGetEnvironmentFromInstanceStage() throws Exception { final Instance instance = new Instance().withInstanceId("instance").withInstanceType(InstanceType.C1Xlarge) .withTags(new Tag(EC2Connector.DEFAULT_INSTANCE_NAME_TAG, EC2Connector.STAGING_VALUE)); ServerEnvironment serverEnv = Whitebox.<ServerEnvironment> invokeMethod(env, "getEnvironmentFromInstance", instance); assertThat(serverEnv, notNullValue()); assertThat(serverEnv.getType(), is(ENVIRONMENT_TYPES.STAGING)); }
Example #5
Source File: EC2ConnectorTest.java From jenkins-deployment-dashboard-plugin with MIT License | 5 votes |
@Test public void testGetEnvironmentFromInstanceJenkins() throws Exception { final Instance instance = new Instance().withInstanceId("instance").withInstanceType(InstanceType.C1Xlarge) .withTags(new Tag(EC2Connector.DEFAULT_INSTANCE_NAME_TAG, EC2Connector.JENKINS_VALUE)); ServerEnvironment serverEnv = Whitebox.<ServerEnvironment> invokeMethod(env, "getEnvironmentFromInstance", instance); assertThat(serverEnv, notNullValue()); assertThat(serverEnv.getType(), is(ENVIRONMENT_TYPES.JENKINS)); }
Example #6
Source File: EC2ConnectorTest.java From jenkins-deployment-dashboard-plugin with MIT License | 5 votes |
@Test public void testGetEnvironmentFromInstanceTest() throws Exception { final Instance instance = new Instance().withInstanceId("instance").withInstanceType(InstanceType.C1Xlarge).withTags(new Tag(EC2Connector.DEFAULT_INSTANCE_NAME_TAG, EC2Connector.TEST_VALUE)); ServerEnvironment serverEnv = Whitebox.<ServerEnvironment> invokeMethod(env, "getEnvironmentFromInstance", instance); assertThat(serverEnv, notNullValue()); assertThat(serverEnv.getType(), is(ENVIRONMENT_TYPES.TEST)); }
Example #7
Source File: EC2ConnectorTest.java From jenkins-deployment-dashboard-plugin with MIT License | 5 votes |
@Test public void testGetEnvironmentFromInstanceVersion() throws Exception { final Instance instance = new Instance().withInstanceId("instance").withInstanceType(InstanceType.C1Xlarge).withTags(new Tag(EC2Connector.VERSION_TAG, "1.2.3")); ServerEnvironment serverEnv = Whitebox.<ServerEnvironment> invokeMethod(env, "getEnvironmentFromInstance", instance); assertThat(serverEnv, notNullValue()); assertThat(serverEnv.getVersion(), is("1.2.3")); }
Example #8
Source File: OpsWorksDeploymentTests.java From aws-ant-tasks with Apache License 2.0 | 5 votes |
private CreateInstanceTask readyInstanceTask() { CreateInstanceTask instanceTask = new CreateInstanceTask(); instanceTask.setProject(project); instanceTask.setInstanceType(InstanceType.M1Small.toString()); instanceTask.setAvailabilityZone(AVAILABILITY_ZONE); return instanceTask; }
Example #9
Source File: EC2CloudTest.java From configuration-as-code-plugin with MIT License | 4 votes |
@Test @ConfiguredWithReadme("ec2/README.md") public void configure_ec2_cloud() throws Exception { final AmazonEC2Cloud ec2Cloud = (AmazonEC2Cloud) Jenkins.get().getCloud("ec2-ec2"); assertNotNull(ec2Cloud); assertTrue(ec2Cloud.isUseInstanceProfileForCredentials()); assertThat(ec2Cloud.getPrivateKey().getPrivateKey(), is("ADMIN123")); final List<SlaveTemplate> templates = ec2Cloud.getTemplates(); assertThat(templates, hasSize(2)); SlaveTemplate slaveTemplate = templates.get(0); assertThat(slaveTemplate.getDisplayName(), containsString("Auto configured EC2 Agent Small")); assertFalse(slaveTemplate.getAssociatePublicIp()); assertFalse(slaveTemplate.isConnectBySSHProcess()); assertFalse(slaveTemplate.deleteRootOnTermination); assertFalse(slaveTemplate.ebsOptimized); assertFalse(slaveTemplate.monitoring); assertFalse(slaveTemplate.stopOnTerminate); assertFalse(slaveTemplate.getUseDedicatedTenancy()); assertFalse(slaveTemplate.useEphemeralDevices); assertThat(slaveTemplate.type, is(InstanceType.T2Small)); assertThat(slaveTemplate.getAmi(), equalTo("ami-0c6bb742864ffa3f3")); assertThat(slaveTemplate.getLabelString(), containsString("Small")); assertThat(slaveTemplate.getLabelSet(), is(notNullValue())); assertThat(slaveTemplate.remoteFS, equalTo("/home/ec2-user")); assertThat(slaveTemplate.getRemoteAdmin(), equalTo("ec2-user")); assertThat(slaveTemplate.zone, equalTo("us-east-1")); assertThat(slaveTemplate.getSecurityGroupString(), equalTo("some-group")); // fails here without mode specified assertTrue(ec2Cloud.canProvision(new LabelAtom("Small"))); // Checks that the AMI type is Unix and configured AMITypeData amiType = slaveTemplate.getAmiType(); assertTrue(amiType.isUnix()); assertTrue(amiType instanceof UnixData); UnixData unixData = (UnixData) amiType; assertThat(unixData.getRootCommandPrefix(), equalTo("sudo")); assertThat(unixData.getSlaveCommandPrefix(), equalTo("sudo -u jenkins")); assertThat(unixData.getSshPort(), equalTo("61120")); slaveTemplate = templates.get(1); assertThat(slaveTemplate.getDisplayName(), containsString("Auto configured EC2 Agent Large")); assertFalse(slaveTemplate.getAssociatePublicIp()); assertFalse(slaveTemplate.isConnectBySSHProcess()); assertFalse(slaveTemplate.deleteRootOnTermination); assertFalse(slaveTemplate.ebsOptimized); assertFalse(slaveTemplate.monitoring); assertFalse(slaveTemplate.stopOnTerminate); assertFalse(slaveTemplate.getUseDedicatedTenancy()); assertFalse(slaveTemplate.useEphemeralDevices); assertThat(slaveTemplate.type, is(InstanceType.T2Xlarge)); assertThat(slaveTemplate.getAmi(), equalTo("ami-0c6bb742864ffa3f3")); assertThat(slaveTemplate.getLabelString(), containsString("Large")); assertThat(slaveTemplate.getLabelSet(), is(notNullValue())); assertThat(slaveTemplate.remoteFS, equalTo("/home/ec2-user")); assertThat(slaveTemplate.getRemoteAdmin(), equalTo("ec2-user")); assertThat(slaveTemplate.zone, equalTo("us-east-1")); assertThat(slaveTemplate.getSecurityGroupString(), equalTo("some-group")); // fails here without mode specified assertTrue(ec2Cloud.canProvision(new LabelAtom("Large"))); // Checks that the AMI type is Unix and configured amiType = slaveTemplate.getAmiType(); assertTrue(amiType.isUnix()); assertTrue(amiType instanceof UnixData); unixData = (UnixData) amiType; assertThat(unixData.getRootCommandPrefix(), equalTo("sudo")); assertThat(unixData.getSlaveCommandPrefix(), equalTo("sudo -u jenkins")); assertThat(unixData.getSshPort(), equalTo("61120")); }
Example #10
Source File: AwsInstanceTypeDefinition.java From primecloud-controller with GNU General Public License v2.0 | 4 votes |
private static void initInstanceStoreCounts() { // http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html // 現行世代 // M3 addInstanceStoreCount(InstanceType.M3Medium, 1); addInstanceStoreCount(InstanceType.M3Large, 1); addInstanceStoreCount(InstanceType.M3Xlarge, 2); addInstanceStoreCount(InstanceType.M32xlarge, 2); // C3 addInstanceStoreCount(InstanceType.C3Large, 2); addInstanceStoreCount(InstanceType.C3Xlarge, 2); addInstanceStoreCount(InstanceType.C32xlarge, 2); addInstanceStoreCount(InstanceType.C34xlarge, 2); addInstanceStoreCount(InstanceType.C38xlarge, 2); // G2 addInstanceStoreCount(InstanceType.G22xlarge, 1); addInstanceStoreCount(InstanceType.G28xlarge, 2); // X1 addInstanceStoreCount(InstanceType.X116xlarge, 1); addInstanceStoreCount(InstanceType.X132xlarge, 2); // R3 addInstanceStoreCount(InstanceType.R3Large, 1); addInstanceStoreCount(InstanceType.R3Xlarge, 1); addInstanceStoreCount(InstanceType.R32xlarge, 1); addInstanceStoreCount(InstanceType.R34xlarge, 1); addInstanceStoreCount(InstanceType.R38xlarge, 2); // I2 addInstanceStoreCount(InstanceType.I2Xlarge, 1); addInstanceStoreCount(InstanceType.I22xlarge, 2); addInstanceStoreCount(InstanceType.I24xlarge, 4); addInstanceStoreCount(InstanceType.I28xlarge, 8); // D2 addInstanceStoreCount(InstanceType.D2Xlarge, 3); addInstanceStoreCount(InstanceType.D22xlarge, 6); addInstanceStoreCount(InstanceType.D24xlarge, 12); addInstanceStoreCount(InstanceType.D28xlarge, 24); // 旧世代 // M1 addInstanceStoreCount(InstanceType.M1Small, 1); addInstanceStoreCount(InstanceType.M1Medium, 1); addInstanceStoreCount(InstanceType.M1Large, 2); addInstanceStoreCount(InstanceType.M1Xlarge, 4); // M2 addInstanceStoreCount(InstanceType.M2Xlarge, 1); addInstanceStoreCount(InstanceType.M22xlarge, 1); addInstanceStoreCount(InstanceType.M24xlarge, 2); // C1 addInstanceStoreCount(InstanceType.C1Medium, 1); addInstanceStoreCount(InstanceType.C1Xlarge, 4); // CC2 addInstanceStoreCount(InstanceType.Cc28xlarge, 4); // CG1 addInstanceStoreCount(InstanceType.Cg14xlarge, 2); // CR1 addInstanceStoreCount(InstanceType.Cr18xlarge, 2); // HI1 addInstanceStoreCount(InstanceType.Hi14xlarge, 2); // HS1 addInstanceStoreCount(InstanceType.Hs18xlarge, 24); }
Example #11
Source File: AwsInstanceTypeDefinition.java From primecloud-controller with GNU General Public License v2.0 | 4 votes |
public static void addInstanceStoreCount(InstanceType instanceType, int count) { addInstanceStoreCount(instanceType.toString(), count); }
Example #12
Source File: EC2IntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testCreateInstance() throws Exception { AmazonEC2Client ec2Client = provider.getClient(); Assume.assumeNotNull("AWS client not null", ec2Client); assertNoStaleInstances(ec2Client, "before"); try { WildFlyCamelContext camelctx = new WildFlyCamelContext(); camelctx.getNamingContext().bind("ec2Client", ec2Client); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:createAndRun").to("aws-ec2://TestDomain?amazonEc2Client=#ec2Client&operation=createAndRunInstances"); from("direct:terminate").to("aws-ec2://TestDomain?amazonEc2Client=#ec2Client&operation=terminateInstances"); } }); camelctx.start(); try { // Create and run an instance Map<String, Object> headers = new HashMap<>(); headers.put(EC2Constants.IMAGE_ID, "ami-02ace471"); headers.put(EC2Constants.INSTANCE_TYPE, InstanceType.T2Micro); headers.put(EC2Constants.SUBNET_ID, EC2Utils.getSubnetId(ec2Client)); headers.put(EC2Constants.INSTANCE_MIN_COUNT, 1); headers.put(EC2Constants.INSTANCE_MAX_COUNT, 1); headers.put(EC2Constants.INSTANCES_TAGS, Arrays.asList(new Tag("Name", "wildfly-camel"))); ProducerTemplate template = camelctx.createProducerTemplate(); RunInstancesResult result1 = template.requestBodyAndHeaders("direct:createAndRun", null, headers, RunInstancesResult.class); String instanceId = result1.getReservation().getInstances().get(0).getInstanceId(); System.out.println("InstanceId: " + instanceId); // Terminate the instance headers = new HashMap<>(); headers.put(EC2Constants.INSTANCES_IDS, Collections.singleton(instanceId)); TerminateInstancesResult result2 = template.requestBodyAndHeaders("direct:terminate", null, headers, TerminateInstancesResult.class); Assert.assertEquals(instanceId, result2.getTerminatingInstances().get(0).getInstanceId()); } finally { camelctx.close(); } } finally { assertNoStaleInstances(ec2Client, "after"); } }