Merge pull request #1188 from gianm/iam

EC2AutoScaler: Allow setting "iamProfile".
This commit is contained in:
Xavier Léauté 2015-03-10 17:48:25 -07:00
commit 909b8fd67f
6 changed files with 160 additions and 25 deletions

View File

@ -118,6 +118,7 @@ public class EC2AutoScaler implements AutoScaler<EC2EnvironmentConfig>
.withPlacement(new Placement(envConfig.getAvailabilityZone()))
.withKeyName(workerConfig.getKeyName())
.withSubnetId(workerConfig.getSubnetId())
.withIamInstanceProfile(workerConfig.getIamProfile().toIamInstanceProfileSpecification())
.withUserData(userDataBase64)
);

View File

@ -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;
}
}

View File

@ -33,6 +33,7 @@ public class EC2NodeData
private final List<String> 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<String> 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;
}
}

View File

@ -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;
@ -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)
);
}
}

View File

@ -92,7 +92,7 @@ public class EC2AutoScalerTest
1,
new EC2EnvironmentConfig(
"us-east-1a",
new EC2NodeData(AMI_ID, INSTANCE_ID, 1, 1, Lists.<String>newArrayList(), "foo", "mySubnet"),
new EC2NodeData(AMI_ID, INSTANCE_ID, 1, 1, Lists.<String>newArrayList(), "foo", "mySubnet", null),
new GalaxyEC2UserData(new DefaultObjectMapper(), "env", "version", "type")
),
amazonEC2Client,

View File

@ -55,7 +55,8 @@ public class WorkerBehaviorConfigTest
5,
Arrays.asList("securityGroupIds"),
"keyNames",
"subnetId"
"subnetId",
null
),
new StringEC2UserData(
"availZone",