From d102a897608c1e9e81db4e02f1fcebdf4974baa9 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Tue, 10 Mar 2015 17:31:30 -0700 Subject: [PATCH 1/2] Fix license on EC2AutoScalerSerdeTest. --- .../autoscaling/EC2AutoScalerSerdeTest.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerSerdeTest.java b/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerSerdeTest.java index 1e306773fb5..3b967326cfa 100644 --- a/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerSerdeTest.java +++ b/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerSerdeTest.java @@ -1,20 +1,20 @@ /* - * Druid - a distributed column store. - * Copyright (C) 2014 Metamarkets Group Inc. + * 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 * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * http://www.apache.org/licenses/LICENSE-2.0 * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * 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; From b810cdfe585774c02554a7a30bb9b066347384f7 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Tue, 10 Mar 2015 17:41:35 -0700 Subject: [PATCH 2/2] EC2AutoScaler: Allow setting "iamProfile". --- .../autoscaling/ec2/EC2AutoScaler.java | 1 + .../autoscaling/ec2/EC2IamProfileData.java | 97 +++++++++++++++++++ .../overlord/autoscaling/ec2/EC2NodeData.java | 16 ++- .../autoscaling/EC2AutoScalerSerdeTest.java | 38 ++++++-- .../autoscaling/EC2AutoScalerTest.java | 2 +- .../setup/WorkerBehaviorConfigTest.java | 3 +- 6 files changed, 146 insertions(+), 11 deletions(-) create mode 100644 indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2IamProfileData.java 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 d3d88b7d415..6663b7ea4c4 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 @@ -118,6 +118,7 @@ public class EC2AutoScaler implements AutoScaler .withPlacement(new Placement(envConfig.getAvailabilityZone())) .withKeyName(workerConfig.getKeyName()) .withSubnetId(workerConfig.getSubnetId()) + .withIamInstanceProfile(workerConfig.getIamProfile().toIamInstanceProfileSpecification()) .withUserData(userDataBase64) ); diff --git a/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2IamProfileData.java b/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2IamProfileData.java new file mode 100644 index 00000000000..647059078af --- /dev/null +++ b/indexing-service/src/main/java/io/druid/indexing/overlord/autoscaling/ec2/EC2IamProfileData.java @@ -0,0 +1,97 @@ +/* + * 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.amazonaws.services.ec2.model.IamInstanceProfileSpecification; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class EC2IamProfileData +{ + private final String name; + private final String arn; + + public EC2IamProfileData( + @JsonProperty("name") String name, + @JsonProperty("arn") String arn + ) + { + this.name = name; + this.arn = arn; + } + + @JsonProperty + public String getName() + { + return name; + } + + @JsonProperty + public String getArn() + { + return arn; + } + + public IamInstanceProfileSpecification toIamInstanceProfileSpecification() + { + final IamInstanceProfileSpecification spec = new IamInstanceProfileSpecification(); + spec.setName(name); + spec.setArn(arn); + return spec; + } + + @Override + public String toString() + { + return "EC2IamProfileData{" + + "name='" + name + '\'' + + ", arn='" + arn + '\'' + + '}'; + } + + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + EC2IamProfileData that = (EC2IamProfileData) o; + + if (arn != null ? !arn.equals(that.arn) : that.arn != null) { + return false; + } + if (name != null ? !name.equals(that.name) : that.name != null) { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (arn != null ? arn.hashCode() : 0); + return result; + } +} 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 7a2700efec7..d556dcad514 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 @@ -33,6 +33,7 @@ public class EC2NodeData private final List securityGroupIds; private final String keyName; private final String subnetId; + private final EC2IamProfileData iamProfile; @JsonCreator public EC2NodeData( @@ -42,7 +43,8 @@ public class EC2NodeData @JsonProperty("maxInstances") int maxInstances, @JsonProperty("securityGroupIds") List securityGroupIds, @JsonProperty("keyName") String keyName, - @JsonProperty("subnetId") String subnetId + @JsonProperty("subnetId") String subnetId, + @JsonProperty("iamProfile") EC2IamProfileData iamProfile ) { this.amiId = amiId; @@ -52,6 +54,7 @@ public class EC2NodeData this.securityGroupIds = securityGroupIds; this.keyName = keyName; this.subnetId = subnetId; + this.iamProfile = iamProfile; } @JsonProperty @@ -96,6 +99,12 @@ public class EC2NodeData return subnetId; } + @JsonProperty + public EC2IamProfileData getIamProfile() + { + return iamProfile; + } + @Override public String toString() { @@ -107,6 +116,7 @@ public class EC2NodeData ", securityGroupIds=" + securityGroupIds + ", keyName='" + keyName + '\'' + ", subnetId='" + subnetId + '\'' + + ", iamProfile=" + iamProfile + '}'; } @@ -131,6 +141,9 @@ public class EC2NodeData if (amiId != null ? !amiId.equals(that.amiId) : that.amiId != null) { return false; } + if (iamProfile != null ? !iamProfile.equals(that.iamProfile) : that.iamProfile != null) { + return false; + } if (instanceType != null ? !instanceType.equals(that.instanceType) : that.instanceType != null) { return false; } @@ -157,6 +170,7 @@ public class EC2NodeData result = 31 * result + (securityGroupIds != null ? securityGroupIds.hashCode() : 0); result = 31 * result + (keyName != null ? keyName.hashCode() : 0); result = 31 * result + (subnetId != null ? subnetId.hashCode() : 0); + result = 31 * result + (iamProfile != null ? iamProfile.hashCode() : 0); return result; } } diff --git a/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerSerdeTest.java b/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerSerdeTest.java index 3b967326cfa..c6687f7cc81 100644 --- a/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerSerdeTest.java +++ b/indexing-service/src/test/java/io/druid/indexing/overlord/autoscaling/EC2AutoScalerSerdeTest.java @@ -43,7 +43,8 @@ public class EC2AutoScalerSerdeTest + " \"maxInstances\" : 1,\n" + " \"minInstances\" : 1,\n" + " \"securityGroupIds\" : [\"kingsguard\"],\n" - + " \"subnetId\" : \"redkeep\"\n" + + " \"subnetId\" : \"redkeep\",\n" + + " \"iamProfile\" : {\"name\": \"foo\", \"arn\": \"bar\"}\n" + " },\n" + " \"userData\" : {\n" + " \"data\" : \"VERSION=:VERSION:\\n\"," @@ -74,7 +75,19 @@ public class EC2AutoScalerSerdeTest ); final EC2AutoScaler autoScaler = objectMapper.readValue(json, EC2AutoScaler.class); + verifyAutoScaler(autoScaler); + final EC2AutoScaler roundTripAutoScaler = objectMapper.readValue( + objectMapper.writeValueAsBytes(autoScaler), + EC2AutoScaler.class + ); + verifyAutoScaler(roundTripAutoScaler); + + Assert.assertEquals("Round trip equals", autoScaler, roundTripAutoScaler); + } + + private static void verifyAutoScaler(final EC2AutoScaler autoScaler) + { Assert.assertEquals(3, autoScaler.getMaxNumWorkers()); Assert.assertEquals(2, autoScaler.getMinNumWorkers()); Assert.assertEquals("westeros-east-1a", autoScaler.getEnvConfig().getAvailabilityZone()); @@ -90,6 +103,22 @@ public class EC2AutoScalerSerdeTest autoScaler.getEnvConfig().getNodeData().getSecurityGroupIds() ); Assert.assertEquals("redkeep", autoScaler.getEnvConfig().getNodeData().getSubnetId()); + Assert.assertEquals( + "foo", + autoScaler.getEnvConfig() + .getNodeData() + .getIamProfile() + .toIamInstanceProfileSpecification() + .getName() + ); + Assert.assertEquals( + "bar", + autoScaler.getEnvConfig() + .getNodeData() + .getIamProfile() + .toIamInstanceProfileSpecification() + .getArn() + ); // userData Assert.assertEquals( @@ -100,12 +129,5 @@ public class EC2AutoScalerSerdeTest Charsets.UTF_8 ) ); - - // Round trip. - Assert.assertEquals( - "Round trip", - autoScaler, - objectMapper.readValue(objectMapper.writeValueAsBytes(autoScaler), EC2AutoScaler.class) - ); } } 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 8b4e491bf4b..c67fecf8932 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"), + new EC2NodeData(AMI_ID, INSTANCE_ID, 1, 1, Lists.newArrayList(), "foo", "mySubnet", null), new GalaxyEC2UserData(new DefaultObjectMapper(), "env", "version", "type") ), amazonEC2Client, 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 50a9515835b..2fb9d780b02 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 @@ -55,7 +55,8 @@ public class WorkerBehaviorConfigTest 5, Arrays.asList("securityGroupIds"), "keyNames", - "subnetId" + "subnetId", + null ), new StringEC2UserData( "availZone",