Search in sources :

Example 6 with Placement

use of com.amazonaws.services.ec2.model.Placement in project photon-model by vmware.

the class TestAWSEnumerationUtils method testGetComputeDescriptionKeyFromAWSInstance.

@Test
public void testGetComputeDescriptionKeyFromAWSInstance() throws Throwable {
    Map<String, ZoneData> zones = new HashMap<>();
    zones.put(AWS_ZONE_ID, ZoneData.build(AWS_REGION_ID, AWS_ZONE_ID, ""));
    Instance awsInstance = new Instance();
    awsInstance.setInstanceId(AWS_INSTANCE_ID);
    Placement placement = new Placement();
    placement.setAvailabilityZone(AWS_ZONE_ID);
    awsInstance.setPlacement(placement);
    String regionId = getRegionId(awsInstance);
    awsInstance.setInstanceType(AWS_INSTANCE_TYPE);
    awsInstance.setVpcId(AWS_VPC_ID);
    assertEquals(AWS_REGION_ID, regionId);
    InstanceDescKey computeDescriptionKey = getKeyForComputeDescriptionFromInstance(awsInstance, zones);
    assertEquals(AWS_COMPUTE_DESCRIPTION_KEY, computeDescriptionKey);
}
Also used : ZoneData(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.ZoneData) HashMap(java.util.HashMap) AWSEnumerationUtils.getKeyForComputeDescriptionFromInstance(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.getKeyForComputeDescriptionFromInstance) Instance(com.amazonaws.services.ec2.model.Instance) Placement(com.amazonaws.services.ec2.model.Placement) InstanceDescKey(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.InstanceDescKey) Test(org.junit.Test)

Example 7 with Placement

use of com.amazonaws.services.ec2.model.Placement in project druid by druid-io.

the class EC2AutoScaler method provision.

@Override
public AutoScalingData provision() {
    try {
        final EC2NodeData workerConfig = envConfig.getNodeData();
        final String userDataBase64;
        if (envConfig.getUserData() == null) {
            userDataBase64 = null;
        } else {
            if (config.getWorkerVersion() == null) {
                userDataBase64 = envConfig.getUserData().getUserDataBase64();
            } else {
                userDataBase64 = envConfig.getUserData().withVersion(config.getWorkerVersion()).getUserDataBase64();
            }
        }
        RunInstancesRequest request = new RunInstancesRequest(workerConfig.getAmiId(), workerConfig.getMinInstances(), workerConfig.getMaxInstances()).withInstanceType(workerConfig.getInstanceType()).withPlacement(new Placement(envConfig.getAvailabilityZone())).withKeyName(workerConfig.getKeyName()).withIamInstanceProfile(workerConfig.getIamProfile() == null ? null : workerConfig.getIamProfile().toIamInstanceProfileSpecification()).withUserData(userDataBase64);
        // leaving it null uses the EC2 default.
        if (workerConfig.getAssociatePublicIpAddress() != null) {
            request.withNetworkInterfaces(new InstanceNetworkInterfaceSpecification().withAssociatePublicIpAddress(workerConfig.getAssociatePublicIpAddress()).withSubnetId(workerConfig.getSubnetId()).withGroups(workerConfig.getSecurityGroupIds()).withDeviceIndex(0));
        } else {
            request.withSecurityGroupIds(workerConfig.getSecurityGroupIds()).withSubnetId(workerConfig.getSubnetId());
        }
        final RunInstancesResult result = amazonEC2Client.runInstances(request);
        final List<String> instanceIds = Lists.transform(result.getReservation().getInstances(), new Function<Instance, String>() {

            @Override
            public String apply(Instance input) {
                return input.getInstanceId();
            }
        });
        log.info("Created instances: %s", instanceIds);
        return new AutoScalingData(Lists.transform(result.getReservation().getInstances(), new Function<Instance, String>() {

            @Override
            public String apply(Instance input) {
                return input.getInstanceId();
            }
        }));
    } catch (Exception e) {
        log.error(e, "Unable to provision any EC2 instances.");
    }
    return null;
}
Also used : AutoScalingData(org.apache.druid.indexing.overlord.autoscaling.AutoScalingData) Instance(com.amazonaws.services.ec2.model.Instance) InstanceNetworkInterfaceSpecification(com.amazonaws.services.ec2.model.InstanceNetworkInterfaceSpecification) Function(com.google.common.base.Function) Placement(com.amazonaws.services.ec2.model.Placement) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) RunInstancesRequest(com.amazonaws.services.ec2.model.RunInstancesRequest)

Aggregations

Placement (com.amazonaws.services.ec2.model.Placement)5 Instance (com.amazonaws.services.ec2.model.Instance)4 RunInstancesRequest (com.amazonaws.services.ec2.model.RunInstancesRequest)4 RunInstancesResult (com.amazonaws.services.ec2.model.RunInstancesResult)4 AmazonServiceException (com.amazonaws.AmazonServiceException)3 InstanceBlockDeviceMapping (com.amazonaws.services.ec2.model.InstanceBlockDeviceMapping)2 InstanceNetworkInterfaceSpecification (com.amazonaws.services.ec2.model.InstanceNetworkInterfaceSpecification)2 Function (com.google.common.base.Function)2 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 BlockDeviceMapping (com.amazonaws.services.ec2.model.BlockDeviceMapping)1 DescribeImagesRequest (com.amazonaws.services.ec2.model.DescribeImagesRequest)1 DescribeImagesResult (com.amazonaws.services.ec2.model.DescribeImagesResult)1 DescribeVolumesRequest (com.amazonaws.services.ec2.model.DescribeVolumesRequest)1 DescribeVolumesResult (com.amazonaws.services.ec2.model.DescribeVolumesResult)1 EbsBlockDevice (com.amazonaws.services.ec2.model.EbsBlockDevice)1 GroupIdentifier (com.amazonaws.services.ec2.model.GroupIdentifier)1 Image (com.amazonaws.services.ec2.model.Image)1 InstanceNetworkInterface (com.amazonaws.services.ec2.model.InstanceNetworkInterface)1