mirror of https://github.com/apache/jclouds.git
aws-ec2 works with tags now
This commit is contained in:
parent
991fe011b3
commit
a91a23f745
|
@ -18,9 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.compute.functions;
|
||||
|
||||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.collect.Maps.filterValues;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.addMetadataAndParseTagsFromValuesOfEmptyString;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -87,8 +85,8 @@ public class AWSRunningInstanceToNodeMetadata extends RunningInstanceToNodeMetad
|
|||
@Override
|
||||
protected NodeMetadataBuilder buildInstance(RunningInstance instance, NodeMetadataBuilder builder) {
|
||||
AWSRunningInstance awsInstance = AWSRunningInstance.class.cast(instance);
|
||||
Map<String, String> tags = awsInstance.getTags();
|
||||
return super.buildInstance(instance, builder).name(tags.get("Name")).tags(
|
||||
filterValues(tags, equalTo("")).keySet()).userMetadata(filterValues(tags, not(equalTo(""))));
|
||||
builder.name(awsInstance.getTags().get("Name"));
|
||||
addMetadataAndParseTagsFromValuesOfEmptyString(builder, awsInstance.getTags());
|
||||
return super.buildInstance(instance, builder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.aws.ec2.compute.strategy;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsValuesOfEmptyString;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
@ -100,6 +101,7 @@ public class AWSEC2CreateNodesInGroupThenAddToSet extends EC2CreateNodesInGroupT
|
|||
@Override
|
||||
protected Iterable<? extends RunningInstance> createNodesInRegionAndZone(String region, String zone, String group,
|
||||
int count, Template template, RunInstancesOptions instanceOptions) {
|
||||
Map<String, String> tags = metadataAndTagsAsValuesOfEmptyString(template.getOptions());
|
||||
Float spotPrice = getSpotPriceOrNull(template.getOptions());
|
||||
if (spotPrice != null) {
|
||||
LaunchSpecification spec = AWSRunInstancesOptions.class.cast(instanceOptions).getLaunchSpecificationBuilder()
|
||||
|
@ -108,12 +110,11 @@ public class AWSEC2CreateNodesInGroupThenAddToSet extends EC2CreateNodesInGroupT
|
|||
if (logger.isDebugEnabled())
|
||||
logger.debug(">> requesting %d spot instances region(%s) price(%f) spec(%s) options(%s)", count, region,
|
||||
spotPrice, spec, options);
|
||||
|
||||
return addTagsToInstancesInRegion(template.getOptions().getUserMetadata(), transform(client
|
||||
return addTagsToInstancesInRegion(tags, transform(client
|
||||
.getSpotInstanceServices().requestSpotInstancesInRegion(region, spotPrice, count, spec, options),
|
||||
spotConverter), region, group);
|
||||
} else {
|
||||
return addTagsToInstancesInRegion(template.getOptions().getUserMetadata(), super.createNodesInRegionAndZone(
|
||||
return addTagsToInstancesInRegion(tags, super.createNodesInRegionAndZone(
|
||||
region, zone, group, count, template, instanceOptions), region, group);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ import org.jclouds.scriptbuilder.domain.Statements;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
|
@ -100,6 +101,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
|
|||
Date before = new Date();
|
||||
|
||||
ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("Name", group);
|
||||
ImmutableSet<String> tags = ImmutableSet. of(group);
|
||||
|
||||
// note that if you change the location, you must also specify image parameters
|
||||
Template template = client.templateBuilder().locationId(region).osFamily(AMZN_LINUX).os64Bit(true).build();
|
||||
|
@ -136,6 +138,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
|
|||
assertEquals(first.getName(), group);
|
||||
|
||||
checkUserMetadataInNodeEquals(first, userMetadata);
|
||||
checkTagsInNodeEquals(first, tags);
|
||||
|
||||
assert first.getCredentials() != null : first;
|
||||
assert first.getCredentials().identity != null : first;
|
||||
|
|
Loading…
Reference in New Issue