mirror of https://github.com/apache/druid.git
Merge pull request #1188 from gianm/iam
EC2AutoScaler: Allow setting "iamProfile".
This commit is contained in:
commit
909b8fd67f
|
@ -118,6 +118,7 @@ public class EC2AutoScaler implements AutoScaler<EC2EnvironmentConfig>
|
||||||
.withPlacement(new Placement(envConfig.getAvailabilityZone()))
|
.withPlacement(new Placement(envConfig.getAvailabilityZone()))
|
||||||
.withKeyName(workerConfig.getKeyName())
|
.withKeyName(workerConfig.getKeyName())
|
||||||
.withSubnetId(workerConfig.getSubnetId())
|
.withSubnetId(workerConfig.getSubnetId())
|
||||||
|
.withIamInstanceProfile(workerConfig.getIamProfile().toIamInstanceProfileSpecification())
|
||||||
.withUserData(userDataBase64)
|
.withUserData(userDataBase64)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,6 +33,7 @@ public class EC2NodeData
|
||||||
private final List<String> securityGroupIds;
|
private final List<String> securityGroupIds;
|
||||||
private final String keyName;
|
private final String keyName;
|
||||||
private final String subnetId;
|
private final String subnetId;
|
||||||
|
private final EC2IamProfileData iamProfile;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public EC2NodeData(
|
public EC2NodeData(
|
||||||
|
@ -42,7 +43,8 @@ public class EC2NodeData
|
||||||
@JsonProperty("maxInstances") int maxInstances,
|
@JsonProperty("maxInstances") int maxInstances,
|
||||||
@JsonProperty("securityGroupIds") List<String> securityGroupIds,
|
@JsonProperty("securityGroupIds") List<String> securityGroupIds,
|
||||||
@JsonProperty("keyName") String keyName,
|
@JsonProperty("keyName") String keyName,
|
||||||
@JsonProperty("subnetId") String subnetId
|
@JsonProperty("subnetId") String subnetId,
|
||||||
|
@JsonProperty("iamProfile") EC2IamProfileData iamProfile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.amiId = amiId;
|
this.amiId = amiId;
|
||||||
|
@ -52,6 +54,7 @@ public class EC2NodeData
|
||||||
this.securityGroupIds = securityGroupIds;
|
this.securityGroupIds = securityGroupIds;
|
||||||
this.keyName = keyName;
|
this.keyName = keyName;
|
||||||
this.subnetId = subnetId;
|
this.subnetId = subnetId;
|
||||||
|
this.iamProfile = iamProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
|
@ -96,6 +99,12 @@ public class EC2NodeData
|
||||||
return subnetId;
|
return subnetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public EC2IamProfileData getIamProfile()
|
||||||
|
{
|
||||||
|
return iamProfile;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
@ -107,6 +116,7 @@ public class EC2NodeData
|
||||||
", securityGroupIds=" + securityGroupIds +
|
", securityGroupIds=" + securityGroupIds +
|
||||||
", keyName='" + keyName + '\'' +
|
", keyName='" + keyName + '\'' +
|
||||||
", subnetId='" + subnetId + '\'' +
|
", subnetId='" + subnetId + '\'' +
|
||||||
|
", iamProfile=" + iamProfile +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +141,9 @@ public class EC2NodeData
|
||||||
if (amiId != null ? !amiId.equals(that.amiId) : that.amiId != null) {
|
if (amiId != null ? !amiId.equals(that.amiId) : that.amiId != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (iamProfile != null ? !iamProfile.equals(that.iamProfile) : that.iamProfile != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (instanceType != null ? !instanceType.equals(that.instanceType) : that.instanceType != null) {
|
if (instanceType != null ? !instanceType.equals(that.instanceType) : that.instanceType != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -157,6 +170,7 @@ public class EC2NodeData
|
||||||
result = 31 * result + (securityGroupIds != null ? securityGroupIds.hashCode() : 0);
|
result = 31 * result + (securityGroupIds != null ? securityGroupIds.hashCode() : 0);
|
||||||
result = 31 * result + (keyName != null ? keyName.hashCode() : 0);
|
result = 31 * result + (keyName != null ? keyName.hashCode() : 0);
|
||||||
result = 31 * result + (subnetId != null ? subnetId.hashCode() : 0);
|
result = 31 * result + (subnetId != null ? subnetId.hashCode() : 0);
|
||||||
|
result = 31 * result + (iamProfile != null ? iamProfile.hashCode() : 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
/*
|
/*
|
||||||
* Druid - a distributed column store.
|
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
|
||||||
* Copyright (C) 2014 Metamarkets Group Inc.
|
* 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
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* software distributed under the License is distributed on an
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* GNU General Public License for more details.
|
* KIND, either express or implied. See the License for the
|
||||||
*
|
* specific language governing permissions and limitations
|
||||||
* You should have received a copy of the GNU General Public License
|
* under the License.
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.druid.indexing.overlord.autoscaling;
|
package io.druid.indexing.overlord.autoscaling;
|
||||||
|
@ -43,7 +43,8 @@ public class EC2AutoScalerSerdeTest
|
||||||
+ " \"maxInstances\" : 1,\n"
|
+ " \"maxInstances\" : 1,\n"
|
||||||
+ " \"minInstances\" : 1,\n"
|
+ " \"minInstances\" : 1,\n"
|
||||||
+ " \"securityGroupIds\" : [\"kingsguard\"],\n"
|
+ " \"securityGroupIds\" : [\"kingsguard\"],\n"
|
||||||
+ " \"subnetId\" : \"redkeep\"\n"
|
+ " \"subnetId\" : \"redkeep\",\n"
|
||||||
|
+ " \"iamProfile\" : {\"name\": \"foo\", \"arn\": \"bar\"}\n"
|
||||||
+ " },\n"
|
+ " },\n"
|
||||||
+ " \"userData\" : {\n"
|
+ " \"userData\" : {\n"
|
||||||
+ " \"data\" : \"VERSION=:VERSION:\\n\","
|
+ " \"data\" : \"VERSION=:VERSION:\\n\","
|
||||||
|
@ -74,7 +75,19 @@ public class EC2AutoScalerSerdeTest
|
||||||
);
|
);
|
||||||
|
|
||||||
final EC2AutoScaler autoScaler = objectMapper.readValue(json, EC2AutoScaler.class);
|
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(3, autoScaler.getMaxNumWorkers());
|
||||||
Assert.assertEquals(2, autoScaler.getMinNumWorkers());
|
Assert.assertEquals(2, autoScaler.getMinNumWorkers());
|
||||||
Assert.assertEquals("westeros-east-1a", autoScaler.getEnvConfig().getAvailabilityZone());
|
Assert.assertEquals("westeros-east-1a", autoScaler.getEnvConfig().getAvailabilityZone());
|
||||||
|
@ -90,6 +103,22 @@ public class EC2AutoScalerSerdeTest
|
||||||
autoScaler.getEnvConfig().getNodeData().getSecurityGroupIds()
|
autoScaler.getEnvConfig().getNodeData().getSecurityGroupIds()
|
||||||
);
|
);
|
||||||
Assert.assertEquals("redkeep", autoScaler.getEnvConfig().getNodeData().getSubnetId());
|
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
|
// userData
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
|
@ -100,12 +129,5 @@ public class EC2AutoScalerSerdeTest
|
||||||
Charsets.UTF_8
|
Charsets.UTF_8
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Round trip.
|
|
||||||
Assert.assertEquals(
|
|
||||||
"Round trip",
|
|
||||||
autoScaler,
|
|
||||||
objectMapper.readValue(objectMapper.writeValueAsBytes(autoScaler), EC2AutoScaler.class)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class EC2AutoScalerTest
|
||||||
1,
|
1,
|
||||||
new EC2EnvironmentConfig(
|
new EC2EnvironmentConfig(
|
||||||
"us-east-1a",
|
"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")
|
new GalaxyEC2UserData(new DefaultObjectMapper(), "env", "version", "type")
|
||||||
),
|
),
|
||||||
amazonEC2Client,
|
amazonEC2Client,
|
||||||
|
|
|
@ -55,7 +55,8 @@ public class WorkerBehaviorConfigTest
|
||||||
5,
|
5,
|
||||||
Arrays.asList("securityGroupIds"),
|
Arrays.asList("securityGroupIds"),
|
||||||
"keyNames",
|
"keyNames",
|
||||||
"subnetId"
|
"subnetId",
|
||||||
|
null
|
||||||
),
|
),
|
||||||
new StringEC2UserData(
|
new StringEC2UserData(
|
||||||
"availZone",
|
"availZone",
|
||||||
|
|
Loading…
Reference in New Issue