From a91a23f7458911ce2595ba0b5142c92c5d115c46 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 18 May 2012 19:57:29 -0700 Subject: [PATCH] aws-ec2 works with tags now --- .../functions/AWSRunningInstanceToNodeMetadata.java | 10 ++++------ .../strategy/AWSEC2CreateNodesInGroupThenAddToSet.java | 7 ++++--- .../aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java | 3 +++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java index 6bba366dc7..1532a6d470 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java @@ -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 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); } } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java index 04f83f6a19..fdfbcf8e72 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java @@ -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 createNodesInRegionAndZone(String region, String zone, String group, int count, Template template, RunInstancesOptions instanceOptions) { + Map 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); } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java index be76696d9c..660f878f55 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java @@ -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 userMetadata = ImmutableMap. of("Name", group); + ImmutableSet 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;