diff --git a/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2AutoScaler.java b/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2AutoScaler.java index f4d84cfdd42..520c237b8a9 100644 --- a/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2AutoScaler.java +++ b/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2AutoScaler.java @@ -22,6 +22,7 @@ import com.amazonaws.services.ec2.model.DescribeInstancesRequest; import com.amazonaws.services.ec2.model.DescribeInstancesResult; import com.amazonaws.services.ec2.model.Filter; import com.amazonaws.services.ec2.model.Instance; +import com.amazonaws.services.ec2.model.InstanceNetworkInterfaceSpecification; import com.amazonaws.services.ec2.model.Placement; import com.amazonaws.services.ec2.model.Reservation; import com.amazonaws.services.ec2.model.RunInstancesRequest; @@ -123,6 +124,13 @@ public class EC2AutoScaler implements AutoScaler ? null : workerConfig.getIamProfile().toIamInstanceProfileSpecification() ) + .withNetworkInterfaces( + workerConfig.getAssociatePublicIpAddress() == null + ? null + : new InstanceNetworkInterfaceSpecification().withAssociatePublicIpAddress( + workerConfig.getAssociatePublicIpAddress() + ) + ) .withUserData(userDataBase64) ); diff --git a/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2NodeData.java b/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2NodeData.java index d556dcad514..59d7943d33e 100644 --- a/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2NodeData.java +++ b/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2NodeData.java @@ -34,6 +34,7 @@ public class EC2NodeData private final String keyName; private final String subnetId; private final EC2IamProfileData iamProfile; + private final Boolean associatePublicIpAddress; @JsonCreator public EC2NodeData( @@ -44,7 +45,8 @@ public class EC2NodeData @JsonProperty("securityGroupIds") List securityGroupIds, @JsonProperty("keyName") String keyName, @JsonProperty("subnetId") String subnetId, - @JsonProperty("iamProfile") EC2IamProfileData iamProfile + @JsonProperty("iamProfile") EC2IamProfileData iamProfile, + @JsonProperty("associatePublicIpAddress") Boolean associatePublicIpAddress ) { this.amiId = amiId; @@ -55,6 +57,7 @@ public class EC2NodeData this.keyName = keyName; this.subnetId = subnetId; this.iamProfile = iamProfile; + this.associatePublicIpAddress = associatePublicIpAddress; } @JsonProperty @@ -105,6 +108,12 @@ public class EC2NodeData return iamProfile; } + @JsonProperty + public Boolean getAssociatePublicIpAddress() + { + return associatePublicIpAddress; + } + @Override public String toString() { diff --git a/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerTest.java b/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerTest.java index c67fecf8932..2861fcfcb23 100644 --- a/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerTest.java +++ b/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerTest.java @@ -92,7 +92,7 @@ public class EC2AutoScalerTest 1, new EC2EnvironmentConfig( "us-east-1a", - new EC2NodeData(AMI_ID, INSTANCE_ID, 1, 1, Lists.newArrayList(), "foo", "mySubnet", null), + new EC2NodeData(AMI_ID, INSTANCE_ID, 1, 1, Lists.newArrayList(), "foo", "mySubnet", null, null), new GalaxyEC2UserData(new DefaultObjectMapper(), "env", "version", "type") ), amazonEC2Client, diff --git a/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/ec2/EC2NodeDataTest.java b/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/ec2/EC2NodeDataTest.java new file mode 100644 index 00000000000..78f788772e1 --- /dev/null +++ b/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/ec2/EC2NodeDataTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to Metamarkets Group Inc. (Metamarkets) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Metamarkets licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.druid.indexing.overlord.autoscaling.ec2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.druid.jackson.DefaultObjectMapper; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; + +public class EC2NodeDataTest +{ + @Test + public void testSerde() throws Exception + { + final ObjectMapper objectMapper = new DefaultObjectMapper(); + final String json = "{ \"amiId\" : \"abc123\", \"instanceType\" : \"k2.9xsmall\", \"minInstances\" : 1, \"maxInstances\" : 2," + + " \"securityGroupIds\" : [\"sg-abc321\"], \"keyName\" : \"opensesame\", \"subnetId\" : \"darknet2\"," + + " \"associatePublicIpAddress\" : true, \"iamProfile\" : { \"name\" : \"john\", \"arn\" : \"xxx:abc:1234/xyz\" } }"; + EC2NodeData nodeData = objectMapper.readValue(json, EC2NodeData.class); + + Assert.assertEquals("abc123", nodeData.getAmiId()); + Assert.assertEquals("k2.9xsmall", nodeData.getInstanceType()); + Assert.assertEquals(2, nodeData.getMaxInstances()); + Assert.assertEquals(1, nodeData.getMinInstances()); + Assert.assertEquals(Arrays.asList("sg-abc321"), nodeData.getSecurityGroupIds()); + Assert.assertEquals("opensesame", nodeData.getKeyName()); + Assert.assertEquals("darknet2", nodeData.getSubnetId()); + Assert.assertEquals("john", nodeData.getIamProfile().getName()); + Assert.assertEquals("xxx:abc:1234/xyz", nodeData.getIamProfile().getArn()); + Assert.assertEquals(true, nodeData.getAssociatePublicIpAddress()); + + EC2NodeData nodeData2 = objectMapper.readValue("{}", EC2NodeData.class); + // default is not always false, null has to be a valid value + Assert.assertNull(nodeData2.getAssociatePublicIpAddress()); + + // round trip + Assert.assertEquals( + nodeData, + objectMapper.readValue( + objectMapper.writeValueAsBytes(nodeData), + EC2NodeData.class + ) + ); + } +} diff --git a/indexing-service/src/test/java/io/druid/indexing/overlord/setup/WorkerBehaviorConfigTest.java b/indexing-service/src/test/java/io/druid/indexing/overlord/setup/WorkerBehaviorConfigTest.java index 2fb9d780b02..8970c5f6179 100644 --- a/indexing-service/src/test/java/io/druid/indexing/overlord/setup/WorkerBehaviorConfigTest.java +++ b/indexing-service/src/test/java/io/druid/indexing/overlord/setup/WorkerBehaviorConfigTest.java @@ -56,6 +56,7 @@ public class WorkerBehaviorConfigTest Arrays.asList("securityGroupIds"), "keyNames", "subnetId", + null, null ), new StringEC2UserData(