diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadata.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadata.java index f5d1957315..548126ade3 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadata.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadata.java @@ -165,7 +165,7 @@ public class ServerInZoneToNodeMetadata implements Function securityGroupCache; private final LoadingCache keyPairCache; private final NovaClient novaClient; - private final Provider templateBuilderProvider; @Inject protected ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet( @@ -80,13 +77,11 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT GroupNamingConvention.Factory namingConvention, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, - Provider templateBuilderProvider, AllocateAndAddFloatingIpToNode allocateAndAddFloatingIpToNode, LoadingCache securityGroupCache, LoadingCache keyPairCache, NovaClient novaClient) { super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor, customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory); - this.templateBuilderProvider = checkNotNull(templateBuilderProvider, "templateBuilderProvider"); this.securityGroupCache = checkNotNull(securityGroupCache, "securityGroupCache"); this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache"); this.allocateAndAddFloatingIpToNode = checkNotNull(allocateAndAddFloatingIpToNode, @@ -98,16 +93,7 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT public Map> execute(String group, int count, Template template, Set goodNodes, Map badNodes, Multimap customizationResponses) { - 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) - .build(); - // otherwise build from generic parameters - } else { - mutableTemplate = templateBuilderProvider.get().fromTemplate(template).build(); - } + Template mutableTemplate = template.clone(); NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(mutableTemplate.getOptions()); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java index 7a63d68604..00aa5ee1f9 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java @@ -26,8 +26,8 @@ import static com.google.common.base.Preconditions.checkState; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import javax.inject.Inject; @@ -40,8 +40,8 @@ import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.util.Preconditions2; import com.google.common.base.Objects; -import com.google.common.base.Optional; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; @@ -133,10 +133,18 @@ public class CreateServerOptions implements MapBinder { } protected ToStringHelper string() { - return toStringHelper("").add("keyName", keyName).add("securityGroupNames", securityGroupNames) - .add("metadata", metadata).add("personality", personality) - .add("adminPassPresent", adminPass != null) - .add("userData", userData == null ? null : new String(userData)); + ToStringHelper toString = Objects.toStringHelper("").omitNullValues(); + toString.add("keyName", keyName); + if (securityGroupNames.size() > 0) + toString.add("securityGroupNames", securityGroupNames); + if (metadata.size() > 0) + toString.add("metadata", metadata); + if (personality.size() > 0) + toString.add("personality", personality); + if (adminPass != null) + toString.add("adminPassPresent", true); + toString.add("userData", userData == null ? null : new String(userData)); + return toString; } @Override diff --git a/compute/src/main/java/org/jclouds/compute/callables/SudoAwareInitManager.java b/compute/src/main/java/org/jclouds/compute/callables/SudoAwareInitManager.java index e94df32e21..24c3fd0cf7 100644 --- a/compute/src/main/java/org/jclouds/compute/callables/SudoAwareInitManager.java +++ b/compute/src/main/java/org/jclouds/compute/callables/SudoAwareInitManager.java @@ -90,7 +90,7 @@ public class SudoAwareInitManager { String command = (runAsRoot && Predicates.in(ImmutableSet.of("start", "stop", "run")).apply(action)) ? execScriptAsRoot(action) : execScriptAsDefaultUser(action); returnVal = runCommand(command); - if ("status".equals(action)) + if (ImmutableSet.of("status", "stdout", "stderr").contains(action)) logger.trace("<< %s(%d)", action, returnVal.getExitStatus()); else if (computeLogger.isTraceEnabled()) computeLogger.trace("<< %s[%s]", action, returnVal); @@ -103,8 +103,8 @@ public class SudoAwareInitManager { String statement = String.format("[%s] as %s@%s", command.replace( node.getCredentials().getPassword() != null ? node.getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh .getUsername(), ssh.getHostAddress()); - if (command.endsWith("status")) - logger.trace(">> running " + statement); + if (command.endsWith("status") || command.endsWith("stdout") || command.endsWith("stderr")) + logger.trace(">> running %s", statement); else computeLogger.debug(">> running " + statement); ExecResponse returnVal = ssh.exec(command); diff --git a/compute/src/main/java/org/jclouds/compute/domain/Template.java b/compute/src/main/java/org/jclouds/compute/domain/Template.java index 9dd98c551d..5b6e873d29 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/Template.java +++ b/compute/src/main/java/org/jclouds/compute/domain/Template.java @@ -47,4 +47,11 @@ public interface Template extends Cloneable { * options for launching this template, like run scripts or inbound ports */ TemplateOptions getOptions(); + + /** + * clone this template + * + * @see Object#clone + */ + Template clone(); } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java index 00a1ac005d..e8d4155dfc 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java @@ -58,6 +58,8 @@ import org.jclouds.util.Lists2; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Supplier; @@ -726,7 +728,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { String message = format("no hardware profiles match params: %s", hardwarePredicate); throw throwNoSuchElementExceptionAfterLoggingHardwareIds(message, hardwaresThatAreCompatibleWithOurImages); } - logger.debug("<< matched hardware(%s)", hardware.getId()); + logger.trace("<< matched hardware(%s)", hardware.getId()); return hardware; } @@ -995,11 +997,40 @@ public class TemplateBuilderImpl implements TemplateBuilder { @Override public String toString() { - return "[biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName + ", imageDescription=" - + imageDescription + ", imageId=" + imageId + ", imagePredicate=" + imagePredicate + ", imageVersion=" + imageVersion + ", location=" + location - + ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName=" + osName - + ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch + ", os64Bit=" - + os64Bit + ", hardwareId=" + hardwareId + ", hypervisor=" + hypervisor + "]"; + return string().toString(); + } + + /** + * @since 1.5 + */ + protected ToStringHelper string() { + ToStringHelper toString = Objects.toStringHelper("").omitNullValues(); + if (biggest) + toString.add("biggest", biggest); + if (fastest) + toString.add("fastest", fastest); + toString.add("imageName", imageName); + toString.add("imageDescription", imageDescription); + toString.add("imageId", imageId); + toString.add("imagePredicate", imagePredicate); + toString.add("imageVersion", imageVersion); + if (location != null) + toString.add("locationId", location.getId()); + if (minCores >0) //TODO: make non-primitive + toString.add("minCores", minCores); + if (minRam >0) //TODO: make non-primitive + toString.add("minRam", minRam); + if (minRam >0) //TODO: make non-primitive + toString.add("minRam", minRam); + toString.add("osFamily", osFamily); + toString.add("osName", osName); + toString.add("osDescription", osDescription); + toString.add("osVersion", osVersion); + toString.add("osArch", osArch); + toString.add("os64Bit", os64Bit); + toString.add("hardwareId", hardwareId); + toString.add("hypervisor", hypervisor); + return toString; } @Override diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateImpl.java index ee5c0968d9..bc0eb8342d 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateImpl.java @@ -129,8 +129,8 @@ public class TemplateImpl implements Template { * {@inheritDoc} */ @Override - protected Object clone() throws CloneNotSupportedException { - return new TemplateImpl(image, size, location, options); + public Template clone() { + return new TemplateImpl(image, size, location, options.clone()); } } diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java index 04e676a778..92b07ac1af 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -338,9 +338,9 @@ public class BaseComputeService implements ComputeService { */ @Override public Set listNodes() { - logger.debug(">> listing nodes"); + logger.trace(">> listing nodes"); Set set = newLinkedHashSet(listNodesStrategy.listNodes()); - logger.debug("<< list(%d)", set.size()); + logger.trace("<< list(%d)", set.size()); return set; } @@ -350,9 +350,9 @@ public class BaseComputeService implements ComputeService { @Override public Set listNodesDetailsMatching(Predicate filter) { checkNotNull(filter, "filter"); - logger.debug(">> listing node details matching(%s)", filter); + logger.trace(">> listing node details matching(%s)", filter); Set set = newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(filter)); - logger.debug("<< list(%d)", set.size()); + logger.trace("<< list(%d)", set.size()); return set; } diff --git a/compute/src/main/java/org/jclouds/compute/options/RunScriptOptions.java b/compute/src/main/java/org/jclouds/compute/options/RunScriptOptions.java index 534b8b7c4f..a0ad298c11 100644 --- a/compute/src/main/java/org/jclouds/compute/options/RunScriptOptions.java +++ b/compute/src/main/java/org/jclouds/compute/options/RunScriptOptions.java @@ -455,11 +455,23 @@ public class RunScriptOptions { } protected ToStringHelper string() { - return Objects.toStringHelper("").add("loginUser", loginUser) - .add("loginPasswordPresent", (loginPassword != null)) - .add("loginPrivateKeyPresent", (loginPrivateKey != null)).add("authenticateSudo", authenticateSudo) - .add("port:seconds", port + ":" + seconds).add("taskName", taskName).add("runAsRoot", runAsRoot) - .add("blockOnComplete", blockOnComplete).add("wrapInInitScript", wrapInInitScript); + ToStringHelper toString = Objects.toStringHelper("").omitNullValues(); + toString.add("loginUser", loginUser); + if (loginPassword != null) + toString.add("loginPasswordPresent", true); + if (loginPrivateKey != null) + toString.add("loginPrivateKeyPresent", true); + toString.add("authenticateSudo", authenticateSudo); + if (port != -1 && seconds != -1) // TODO: not primitives + toString.add("blockOnPort:seconds", port + ":" + seconds); + toString.add("taskName", taskName); + if (!runAsRoot) + toString.add("runAsRoot", runAsRoot); + if (!blockOnComplete) + toString.add("blockOnComplete", blockOnComplete); + if (!wrapInInitScript) + toString.add("wrapInInitScript", wrapInInitScript); + return toString; } } diff --git a/compute/src/main/java/org/jclouds/compute/options/TemplateOptions.java b/compute/src/main/java/org/jclouds/compute/options/TemplateOptions.java index e9066f8ae8..ce41ef3bf3 100644 --- a/compute/src/main/java/org/jclouds/compute/options/TemplateOptions.java +++ b/compute/src/main/java/org/jclouds/compute/options/TemplateOptions.java @@ -317,7 +317,9 @@ public class TemplateOptions extends RunScriptOptions implements Cloneable { } - protected Set inboundPorts = ImmutableSet.of(22); + private final static Set DEFAULT_INBOUND_PORTS = ImmutableSet.of(22); + + protected Set inboundPorts = DEFAULT_INBOUND_PORTS; protected Statement script; @@ -352,11 +354,24 @@ public class TemplateOptions extends RunScriptOptions implements Cloneable { @Override public ToStringHelper string() { - return super.string().add("inboundPorts", inboundPorts).add("scriptPresent", script != null) - .add("publicKeyPresent", publicKey != null).add("privateKeyPresent", privateKey != null).add("tags", tags) - .add("blockUntilRunning", blockUntilRunning).add("tags", tags).add("userMetadata", userMetadata); + ToStringHelper toString = super.string(); + if (!DEFAULT_INBOUND_PORTS.equals(inboundPorts)) + toString.add("inboundPorts", inboundPorts); + if (script != null) + toString.add("scriptPresent", true); + if (publicKey != null) + toString.add("publicKeyPresent", true); + if (privateKey != null) + toString.add("privateKeyPresent", true); + if (!blockUntilRunning) + toString.add("blockUntilRunning", blockUntilRunning); + if (tags.size() != 0) + toString.add("tags", tags); + if (userMetadata.size() != 0) + toString.add("userMetadata", userMetadata); + return toString; } - + public int[] getInboundPorts() { return Ints.toArray(inboundPorts); } diff --git a/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java b/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java index 68b23d9cec..1f4bb92bc9 100644 --- a/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java +++ b/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java @@ -374,7 +374,7 @@ public class TemplateBuilderImplTest { // make sure big data is not in the exception message assertEquals( e.getMessage(), - "no hardware profiles support images matching params: [biggest=false, fastest=false, imageName=null, imageDescription=null, imageId=us-east-1/imageId, imagePredicate=null, imageVersion=null, location=[id=us-east-1, scope=REGION, description=us-east-1, parent=aws-ec2, iso3166Codes=[], metadata={}], minCores=0.0, minRam=0, osFamily=null, osName=null, osDescription=null, osVersion=null, osArch=null, os64Bit=false, hardwareId=null, hypervisor=null]"); + "no hardware profiles support images matching params: {imageId=us-east-1/imageId, locationId=us-east-1, os64Bit=false}"); verify(image); verify(os); verify(defaultTemplate); @@ -852,6 +852,8 @@ public class TemplateBuilderImplTest { TemplateBuilder templateBuilder = templateBuilderProvider.get().minRam(512).osFamily(OsFamily.UBUNTU) .hypervisorMatches("OpenVZ").osVersionMatches("1[10].[10][04]").os64Bit(true); + assertEquals(templateBuilder.toString(), "{minRam=512, minRam=512, osFamily=ubuntu, osVersion=1[10].[10][04], os64Bit=true, hypervisor=OpenVZ}"); + Template template = templateBuilder.build(); assertEquals(template.getHardware().getHypervisor(), "OpenVZ"); assertEquals(template.getImage().getId(), "Ubuntu 11.04 64-bit"); @@ -902,7 +904,9 @@ public class TemplateBuilderImplTest { }; TemplateBuilder templateBuilder = templateBuilderProvider.get().hardwareId("m1.small").imageId("us-east-2/ami-ffff"); - + + assertEquals(templateBuilder.toString(), "{imageId=us-east-2/ami-ffff, hardwareId=m1.small}"); + Template template = templateBuilder.build(); assertEquals(template.getLocation().getId(), "us-east-2"); diff --git a/compute/src/test/java/org/jclouds/compute/options/TemplateOptionsTest.java b/compute/src/test/java/org/jclouds/compute/options/TemplateOptionsTest.java index 1081d82028..486ad27726 100644 --- a/compute/src/test/java/org/jclouds/compute/options/TemplateOptionsTest.java +++ b/compute/src/test/java/org/jclouds/compute/options/TemplateOptionsTest.java @@ -45,6 +45,7 @@ public class TemplateOptionsTest { public void testinstallPrivateKey() throws IOException { TemplateOptions options = new TemplateOptions(); options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); + assertEquals(options.toString(), "{privateKeyPresent=true}"); assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); } @@ -75,6 +76,7 @@ public class TemplateOptionsTest { public void testauthorizePublicKey() throws IOException { TemplateOptions options = new TemplateOptions(); options.authorizePublicKey("ssh-rsa"); + assertEquals(options.toString(), "{publicKeyPresent=true}"); assertEquals(options.getPublicKey(), "ssh-rsa"); } @@ -105,6 +107,7 @@ public class TemplateOptionsTest { public void testblockOnPort() { TemplateOptions options = new TemplateOptions(); options.blockOnPort(22, 30); + assertEquals(options.toString(), "{blockOnPort:seconds=22:30}"); assertEquals(options.getPort(), 22); assertEquals(options.getSeconds(), 30); @@ -148,6 +151,7 @@ public class TemplateOptionsTest { @Test public void testinboundPortsStatic() { TemplateOptions options = inboundPorts(22, 30); + assertEquals(options.toString(), "{inboundPorts=[22, 30]}"); assertEquals(options.getInboundPorts()[0], 22); assertEquals(options.getInboundPorts()[1], 30); } @@ -155,6 +159,7 @@ public class TemplateOptionsTest { @Test public void testblockUntilRunningDefault() { TemplateOptions options = new TemplateOptions(); + assertEquals(options.toString(), "{}"); assertEquals(options.shouldBlockUntilRunning(), true); } @@ -162,6 +167,7 @@ public class TemplateOptionsTest { public void testblockUntilRunning() { TemplateOptions options = new TemplateOptions(); options.blockUntilRunning(false); + assertEquals(options.toString(), "{blockUntilRunning=false}"); assertEquals(options.shouldBlockUntilRunning(), false); } diff --git a/core/src/main/java/org/jclouds/events/handlers/DeadEventLoggingHandler.java b/core/src/main/java/org/jclouds/events/handlers/DeadEventLoggingHandler.java index 20f709c1c4..c4fbafa9cf 100644 --- a/core/src/main/java/org/jclouds/events/handlers/DeadEventLoggingHandler.java +++ b/core/src/main/java/org/jclouds/events/handlers/DeadEventLoggingHandler.java @@ -47,6 +47,6 @@ public class DeadEventLoggingHandler */ @Subscribe public final void handleDeadEvent(DeadEvent deadEvent) { - logger.warn("detected dead event %s", deadEvent.getEvent()); + logger.trace("detected dead event %s", deadEvent.getEvent()); } } diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/options/SDCTemplateOptions.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/options/SDCTemplateOptions.java index d4c6e134b4..da6d02df51 100644 --- a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/options/SDCTemplateOptions.java +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/options/SDCTemplateOptions.java @@ -81,7 +81,10 @@ public class SDCTemplateOptions extends TemplateOptions implements Cloneable { @Override public ToStringHelper string() { - return super.string().add("generateKey", generateKey); + ToStringHelper toString = super.string(); + if (generateKey) + toString.add("generateKey", generateKey); + return toString; } /** diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/strategy/ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/strategy/ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java index c81bebfa0b..06447564ed 100644 --- a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/strategy/ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/compute/strategy/ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java @@ -28,14 +28,12 @@ import java.util.concurrent.Future; import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Provider; import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.compute.config.CustomizationResponse; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; -import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.functions.GroupNamingConvention; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName; import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap; @@ -57,7 +55,6 @@ public class ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddTo CreateNodesWithGroupEncodedIntoNameThenAddToSet { private final LoadingCache keyCache; - private final Provider templateBuilderProvider; @Inject protected ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet( @@ -66,11 +63,9 @@ public class ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddTo GroupNamingConvention.Factory namingConvention, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, - Provider templateBuilderProvider, LoadingCache keyCache) { super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor, customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory); - this.templateBuilderProvider = checkNotNull(templateBuilderProvider, "templateBuilderProvider"); this.keyCache = checkNotNull(keyCache, "keyCache"); } @@ -78,17 +73,7 @@ public class ApplySDCTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddTo public Map> execute(String group, int count, Template template, Set goodNodes, Map badNodes, Multimap customizationResponses) { - 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) - .build(); - // otherwise build from generic parameters - } else { - mutableTemplate = templateBuilderProvider.get().fromTemplate(template).build(); - } + Template mutableTemplate = template.clone(); SDCTemplateOptions templateOptions = SDCTemplateOptions.class.cast(mutableTemplate.getOptions()); diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/options/CreateMachineOptions.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/options/CreateMachineOptions.java index ea985c4196..e0f52920e7 100644 --- a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/options/CreateMachineOptions.java +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/options/CreateMachineOptions.java @@ -19,7 +19,6 @@ package org.jclouds.joyent.sdc.v6_5.options; import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Map; @@ -30,6 +29,7 @@ import org.jclouds.util.Maps2; import com.google.common.base.Function; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; @@ -64,7 +64,11 @@ public class CreateMachineOptions extends BaseHttpRequestOptions { @Override public String toString() { - return toStringHelper("").add("name", name).add("package", name).add("metadata", metadata).toString(); + ToStringHelper toString = Objects.toStringHelper("").omitNullValues(); + toString.add("name", name).add("package", name); + if (metadata.size() > 0) + toString.add("metadata", metadata); + return toString.toString(); } @Override