From 5340e947d3b3c6c4f09cc655dccc90271bd98031 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 10 May 2012 17:19:29 -0700 Subject: [PATCH] while image can be null in templateBuilder, image will never be null in a template --- .../strategy/EC2CreateNodesInGroupThenAddToSet.java | 11 +---------- .../EC2CreateNodesInGroupThenAddToSetTest.java | 4 ++++ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java index af2f4d648f..a1f2dd27e4 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java @@ -133,17 +133,8 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen public Map> execute(String group, int count, Template template, Set goodNodes, Map badNodes, Multimap customizationResponses) { - // ensure we don't mutate the input template - Template mutableTemplate; - // ensure we don't mutate the input template, fromTemplate ignores imageId so - // build directly from imageId if we have it - if (template.getImage() != null && template.getImage().getId() != null) { - mutableTemplate = templateBuilderProvider.get().imageId(template.getImage().getId()).fromTemplate(template) + Template mutableTemplate = templateBuilderProvider.get().imageId(template.getImage().getId()).fromTemplate(template) .build(); - // otherwise build from generic parameters - } else { - mutableTemplate = templateBuilderProvider.get().fromTemplate(template).build(); - } Iterable ips = allocateElasticIpsInRegion(count, template); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSetTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSetTest.java index 6f89f7f057..400c954a57 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSetTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSetTest.java @@ -95,6 +95,7 @@ public class EC2CreateNodesInGroupThenAddToSetTest { strategy.autoAllocateElasticIps = true; // setup expectations + expect(templateBuilder.imageId(region + "/" + imageId)).andReturn(templateBuilder); expect(templateBuilder.fromTemplate(input.template)).andReturn(templateBuilder); expect(templateBuilder.build()).andReturn(input.template); expect(strategy.client.getInstanceServices()).andReturn(instanceClient).atLeastOnce(); @@ -105,6 +106,7 @@ public class EC2CreateNodesInGroupThenAddToSetTest { expect(input.template.getLocation()).andReturn(input.location).atLeastOnce(); expect(input.template.getImage()).andReturn(input.image).atLeastOnce(); + expect(input.image.getId()).andReturn(region + "/" + imageId).atLeastOnce(); expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce(); // differences when ip allocation @@ -202,6 +204,7 @@ public class EC2CreateNodesInGroupThenAddToSetTest { "reservationId"); // setup expectations + expect(templateBuilder.imageId(region + "/" + imageId)).andReturn(templateBuilder); expect(templateBuilder.fromTemplate(input.template)).andReturn(templateBuilder); expect(templateBuilder.build()).andReturn(input.template); expect(strategy.client.getInstanceServices()).andReturn(instanceClient).atLeastOnce(); @@ -210,6 +213,7 @@ public class EC2CreateNodesInGroupThenAddToSetTest { .execute(region, input.tag, input.template)).andReturn(ec2Options); expect(input.template.getLocation()).andReturn(input.location).atLeastOnce(); expect(input.template.getImage()).andReturn(input.image).atLeastOnce(); + expect(input.image.getId()).andReturn(region + "/" + imageId).atLeastOnce(); expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce(); expect(instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, ec2Options)).andReturn( Reservation.class.cast(reservation));