diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java index 5a882ff28f..b8cc124a41 100644 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java +++ b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java @@ -45,7 +45,7 @@ public class CloudSigmaComputeServiceLiveTest extends BaseComputeServiceLiveTest // cloudsigma does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceLiveTest.java index a112d37849..e34a7836d1 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceLiveTest.java @@ -45,7 +45,7 @@ public class CloudStackComputeServiceLiveTest extends BaseComputeServiceLiveTest // cloudstack does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java index f8ae751245..4d51a91cda 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java @@ -87,7 +87,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { // normal ec2 does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } diff --git a/compute/src/main/java/org/jclouds/compute/ComputeService.java b/compute/src/main/java/org/jclouds/compute/ComputeService.java index 617f1c77c3..64c771c5a3 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeService.java @@ -349,6 +349,9 @@ public interface ComputeService { * @see org.jclouds.compute.predicates.NodePredicates#runningInGroup(String) * @see org.jclouds.scriptbuilder.domain.Statements */ + @Beta + ListenableFuture submitScriptOnNode(String id, String runScript, RunScriptOptions options); + @Beta ListenableFuture submitScriptOnNode(String id, Statement runScript, RunScriptOptions options); @@ -377,4 +380,5 @@ public interface ComputeService { @Beta Optional getImageExtension(); + } 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 f3a76b1062..5c4eedba47 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -512,7 +512,7 @@ public class BaseComputeService implements ComputeService { @Override public Map runScriptOnNodesMatching(Predicate filter, String runScript) throws RunScriptOnNodesException { - return runScriptOnNodesMatching(filter, Statements.exec(checkNotNull(runScript, "runScript"))); + return runScriptOnNodesMatching(filter, Statements.literal(checkNotNull(runScript, "runScript"))); } /** @@ -527,7 +527,7 @@ public class BaseComputeService implements ComputeService { @Override public Map runScriptOnNodesMatching(Predicate filter, String runScript, RunScriptOptions options) throws RunScriptOnNodesException { - return runScriptOnNodesMatching(filter, Statements.exec(checkNotNull(runScript, "runScript")), options); + return runScriptOnNodesMatching(filter, Statements.literal(checkNotNull(runScript, "runScript")), options); } /** @@ -585,7 +585,7 @@ public class BaseComputeService implements ComputeService { */ @Override public ExecResponse runScriptOnNode(String id, String runScript, RunScriptOptions options) { - return runScriptOnNode(id, Statements.exec(checkNotNull(runScript, "runScript")), options); + return runScriptOnNode(id, Statements.literal(checkNotNull(runScript, "runScript")), options); } /** @@ -614,6 +614,14 @@ public class BaseComputeService implements ComputeService { return response; } + /** + * {@inheritDoc} + */ + @Override + public ListenableFuture submitScriptOnNode(String id, String runScript, RunScriptOptions options) { + return submitScriptOnNode(id, Statements.literal(checkNotNull(runScript, "runScript")), options); + } + /** * {@inheritDoc} */ diff --git a/compute/src/test/java/org/jclouds/compute/JettyStatements.java b/compute/src/test/java/org/jclouds/compute/JettyStatements.java index 1a629e5547..1be3590143 100644 --- a/compute/src/test/java/org/jclouds/compute/JettyStatements.java +++ b/compute/src/test/java/org/jclouds/compute/JettyStatements.java @@ -20,6 +20,7 @@ package org.jclouds.compute; import static org.jclouds.scriptbuilder.domain.Statements.exec; import static org.jclouds.scriptbuilder.domain.Statements.extractTargzAndFlattenIntoDirectory; +import static org.jclouds.scriptbuilder.domain.Statements.literal; import java.net.URI; @@ -35,7 +36,7 @@ import org.jclouds.scriptbuilder.statements.login.AdminAccess; public class JettyStatements { public static final URI JETTY_URL = URI.create(System.getProperty("test.jetty-url",// - "http://download.eclipse.org/jetty/8.1.5.v20120716/dist/jetty-distribution-8.1.5.v20120716.tar.gz")); + "http://download.eclipse.org/jetty/8.1.8.v20121106/dist/jetty-distribution-8.1.8.v20121106.tar.gz")); public static final String JETTY_HOME = "/usr/local/jetty"; @@ -56,19 +57,20 @@ public class JettyStatements { private static Statement authorizePortInIpTables() { return new StatementList( - exec("iptables -I INPUT 1 -p tcp --dport " + port + " -j ACCEPT"), - exec("iptables-save")); + exec("iptables -I INPUT 1 -p tcp --dport " + port + " -j ACCEPT"), + exec("iptables-save")); } public static Statement start() { return new StatementList( - exec("cd " + JETTY_HOME), - exec("./bin/jetty.sh start")); + literal("cd " + JETTY_HOME), + literal("nohup java -jar start.jar jetty.port=" + port + " > start.out 2> start.err < /dev/null &"), + literal("test $? && sleep 1")); // in case it is slow starting the proc } public static Statement stop() { return new StatementList( - exec("cd " + JETTY_HOME), - exec("./bin/jetty.sh stop")); + literal("cd " + JETTY_HOME), + literal("./bin/jetty.sh stop")); } } diff --git a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java index e88c178d79..3973b005d4 100644 --- a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java @@ -319,8 +319,13 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes expect(clientNew.exec("java -fullversion\n")).andReturn(EXEC_GOOD); clientNew.disconnect(); + String startJetty = new StringBuilder() + .append("cd /usr/local/jetty").append('\n') + .append("nohup java -jar start.jar jetty.port=8080 > start.out 2> start.err < /dev/null &").append('\n') + .append("test $? && sleep 1").append('\n').toString(); + clientNew.connect(); - expect(clientNew.exec("cd /usr/local/jetty\n./bin/jetty.sh start\n")).andReturn(EXEC_GOOD); + expect(clientNew.exec(startJetty)).andReturn(EXEC_GOOD); clientNew.disconnect(); clientNew.connect(); @@ -328,7 +333,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes clientNew.disconnect(); clientNew.connect(); - expect(clientNew.exec("cd /usr/local/jetty\n./bin/jetty.sh start\n")).andReturn(EXEC_GOOD); + expect(clientNew.exec(startJetty)).andReturn(EXEC_GOOD); clientNew.disconnect(); } catch (IOException e) { diff --git a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java index 3174c01039..2386636e0f 100644 --- a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java @@ -103,6 +103,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.google.common.net.HostAndPort; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -225,7 +226,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte assert good.credential != null : nodes; for (Entry response : client.runScriptOnNodesMatching( - runningInGroup(group), Statements.exec("hostname"), + runningInGroup(group), "hostname", wrapInInitScript(false).runAsRoot(false).overrideLoginCredentials(good)).entrySet()) { checkResponseEqualsHostname(response.getValue(), response.getKey()); } @@ -289,7 +290,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte @Test(enabled = false) public void weCanCancelTasks(NodeMetadata node) throws InterruptedException, ExecutionException { - ListenableFuture future = client.submitScriptOnNode(node.getId(), Statements.exec("sleep 300"), + ListenableFuture future = client.submitScriptOnNode(node.getId(), "sleep 300", nameTask("sleeper").runAsRoot(false)); ExecResponse response = null; try { @@ -297,11 +298,11 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte fail(node.getId() + ": " + response); } catch (TimeoutException e) { assert !future.isDone(); - response = client.runScriptOnNode(node.getId(), Statements.exec("/tmp/init-sleeper status"), + response = client.runScriptOnNode(node.getId(), "/tmp/init-sleeper status", wrapInInitScript(false).runAsRoot(false)); assert !response.getOutput().trim().equals("") : node.getId() + ": " + response; future.cancel(true); - response = client.runScriptOnNode(node.getId(), Statements.exec("/tmp/init-sleeper status"), + response = client.runScriptOnNode(node.getId(), "/tmp/init-sleeper status", wrapInInitScript(false).runAsRoot(false)); assert response.getOutput().trim().equals("") : node.getId() + ": " + response; try { @@ -508,9 +509,9 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte checkOsMatchesTemplate(metadata); assert (metadata.getStatus() == Status.RUNNING) : metadata; // due to DHCP the addresses can actually change in-between runs. - assertEquals(metadata.getPrivateAddresses().size(), node.getPrivateAddresses().size(), String.format( + assertEquals(metadata.getPrivateAddresses().size(), node.getPrivateAddresses().size(), format( "[%s] didn't match: [%s]", metadata.getPrivateAddresses(), node.getPrivateAddresses().size())); - assertEquals(metadata.getPublicAddresses().size(), node.getPublicAddresses().size(), String.format( + assertEquals(metadata.getPublicAddresses().size(), node.getPublicAddresses().size(), format( "[%s] didn't match: [%s]", metadata.getPublicAddresses(), node.getPublicAddresses().size())); } assertNodeZero(metadataMap.values()); @@ -602,7 +603,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte @Override public String toString() { - return String.format("[backgroundProcessMilliseconds=%s, socketOpenMilliseconds=%s]", + return format("[backgroundProcessMilliseconds=%s, socketOpenMilliseconds=%s]", backgroundProcessMilliseconds, socketOpenMilliseconds); } } @@ -618,7 +619,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte try { socket = openSocketFinder.findOpenSocketOnNode(node, 8080, 60, TimeUnit.SECONDS); } catch (NoSuchElementException e) { - throw new NoSuchElementException(String.format("%s%n%s%s", e.getMessage(), exec.getOutput(), exec.getError())); + throw new NoSuchElementException(format("%s%n%s%s", e.getMessage(), exec.getOutput(), exec.getError())); } stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS); @@ -647,7 +648,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte protected void createAndRunAServiceInGroup(String group) throws RunNodesException { // note that some cloud providers do not support mixed case tag names - ImmutableMap userMetadata = ImmutableMap. of("name", group); + ImmutableMap userMetadata = ImmutableMap. of("test", group); ImmutableSet tags = ImmutableSet. of(group); Stopwatch watch = new Stopwatch().start(); @@ -657,7 +658,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte final String nodeId = node.getId(); - checkUserMetadataInNodeEquals(node, userMetadata); + checkUserMetadataContains(node, userMetadata); checkTagsInNodeEquals(node, tags); getAnonymousLogger().info( @@ -691,13 +692,13 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte return client.runScriptOnNode(nodeId, command, runAsRoot(false).wrapInInitScript(false)).getOutput().trim(); } - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { - assert node.getUserMetadata().equals(userMetadata) : String.format("node userMetadata did not match %s %s", - userMetadata, node); + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { + Map missing = Maps.difference(node.getUserMetadata(), userMetadata).entriesOnlyOnRight(); + assert missing.isEmpty() : format("node userMetadata did not contain %s %s", missing, node); } protected void checkTagsInNodeEquals(NodeMetadata node, ImmutableSet tags) { - assert node.getTags().equals(tags) : String.format("node tags did not match %s %s", tags, node); + assert node.getTags().equals(tags) : format("node tags did not match %s %s", tags, node); } public void testListImages() throws Exception { diff --git a/compute/src/test/resources/initscript_with_jetty.sh b/compute/src/test/resources/initscript_with_jetty.sh index 741ec9458e..4f0227dd4f 100644 --- a/compute/src/test/resources/initscript_with_jetty.sh +++ b/compute/src/test/resources/initscript_with_jetty.sh @@ -222,7 +222,7 @@ END_OF_JCLOUDS_SCRIPT iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT iptables-save mkdir /tmp/$$ - curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.eclipse.org/jetty/8.1.5.v20120716/dist/jetty-distribution-8.1.5.v20120716.tar.gz |(mkdir -p /tmp/$$ &&cd /tmp/$$ &&tar -xpzf -) + curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.eclipse.org/jetty/8.1.8.v20121106/dist/jetty-distribution-8.1.8.v20121106.tar.gz |(mkdir -p /tmp/$$ &&cd /tmp/$$ &&tar -xpzf -) mkdir -p /usr/local/jetty mv /tmp/$$/*/* /usr/local/jetty rm -rf /tmp/$$ diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java index 0c67c1ec99..1c14de89be 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java @@ -112,7 +112,7 @@ public abstract class AbiquoComputeServiceLiveTest extends BaseComputeServiceLiv // Abiquo does not support metadata @Override - protected void checkUserMetadataInNodeEquals(final NodeMetadata node, final ImmutableMap userMetadata) { + protected void checkUserMetadataContains(final NodeMetadata node, final ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } diff --git a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPBaseComputeServiceLiveTest.java b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPBaseComputeServiceLiveTest.java index bd5c377168..cc9db44afe 100644 --- a/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPBaseComputeServiceLiveTest.java +++ b/labs/fgcp/src/test/java/org/jclouds/fujitsu/fgcp/compute/config/FGCPBaseComputeServiceLiveTest.java @@ -55,7 +55,7 @@ public abstract class FGCPBaseComputeServiceLiveTest extends // fgcp does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().isEmpty() : String.format( "node userMetadata not empty: %s %s", node, node.getUserMetadata()); diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCComputeServiceLiveTestDisabled.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCComputeServiceLiveTestDisabled.java index d2fddffa66..9f9ae26362 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCComputeServiceLiveTestDisabled.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/compute/VPDCComputeServiceLiveTestDisabled.java @@ -51,7 +51,7 @@ public class VPDCComputeServiceLiveTestDisabled extends BaseComputeServiceLiveTe // savvis does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } diff --git a/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/SmartOSManagerComputeServiceLiveTest.java b/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/SmartOSManagerComputeServiceLiveTest.java index 8cbc3377e0..3b2d17e7e6 100644 --- a/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/SmartOSManagerComputeServiceLiveTest.java +++ b/labs/smartos-ssh/src/test/java/org/jclouds/smartos/compute/SmartOSManagerComputeServiceLiveTest.java @@ -51,7 +51,7 @@ public class SmartOSManagerComputeServiceLiveTest extends BaseComputeServiceLive // smartos-ssh does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } 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 5422ad9950..410fb95a03 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 @@ -79,7 +79,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { // aws-ec2 supports userMetadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(userMetadata) : String.format("node userMetadata did not match %s %s", userMetadata, node); } @@ -102,11 +102,12 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { Date before = new Date(); - ImmutableMap userMetadata = ImmutableMap. of("Name", group); + ImmutableMap userMetadata = ImmutableMap. of("test", 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(); + template.getOptions().tags(tags); template.getOptions().userMetadata(userMetadata); template.getOptions().as(AWSEC2TemplateOptions.class).enableMonitoring(); template.getOptions().as(AWSEC2TemplateOptions.class).spotPrice(0.3f); @@ -139,7 +140,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { // Name metadata should turn into node.name assertEquals(first.getName(), group); - checkUserMetadataInNodeEquals(first, userMetadata); + checkUserMetadataContains(first, userMetadata); checkTagsInNodeEquals(first, tags); assert first.getCredentials() != null : first; diff --git a/providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java b/providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java index d71b9386f2..5bdfefefa3 100644 --- a/providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java +++ b/providers/glesys/src/test/java/org/jclouds/glesys/compute/GleSYSComputeServiceLiveTest.java @@ -48,6 +48,6 @@ public class GleSYSComputeServiceLiveTest extends BaseComputeServiceLiveTest { // GleSYS does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { } } diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java index 7cdffe2114..94cc5f5866 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java @@ -60,7 +60,7 @@ public class GoGridComputeServiceLiveTest extends BaseComputeServiceLiveTest { // gogrid does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java index 8a848c1fa1..7c3e87c437 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceLiveTest.java @@ -47,7 +47,7 @@ public class SoftLayerComputeServiceLiveTest extends BaseComputeServiceLiveTest // softlayer does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java index 56d0728b32..9f9ab67efe 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/compute/TerremarkECloudComputeServiceLiveTest.java @@ -69,7 +69,7 @@ public class TerremarkECloudComputeServiceLiveTest extends BaseComputeServiceLiv // terremark does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } diff --git a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java index b80402df27..e6f4d1e74b 100644 --- a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java +++ b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/trmk/vcloudexpress/compute/TerremarkVCloudExpressComputeServiceLiveTest.java @@ -71,7 +71,7 @@ public class TerremarkVCloudExpressComputeServiceLiveTest extends BaseComputeSer // terremark does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); } diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/LiteralStatement.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/LiteralStatement.java new file mode 100644 index 0000000000..15e0bc0b9b --- /dev/null +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/LiteralStatement.java @@ -0,0 +1,69 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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 org.jclouds.scriptbuilder.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; + +/** + * Statement used in a shell script without modifications apart from a trailing newline. + * + * @author Adrian Cole + */ +public class LiteralStatement implements Statement { + + private String statement; + + public LiteralStatement(String statement) { + this.statement = checkNotNull(statement, "statement"); + } + + public String render(OsFamily family) { + return statement + ShellToken.LF.to(family); + } + + @Override + public Iterable functionDependencies(OsFamily family) { + return ImmutableList.of(); + } + + @Override + public int hashCode() { + return Objects.hashCode(statement); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof LiteralStatement)) + return false; + LiteralStatement other = LiteralStatement.class.cast(obj); + return Objects.equal(statement, other.statement); + } + + @Override + public String toString() { + return statement + "{lf}"; + } +} diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/Statements.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/Statements.java index ea63c9adac..1746568510 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/Statements.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/Statements.java @@ -148,6 +148,13 @@ public class Statements { return new InterpretableStatement(portableStatements); } + /** + * sends statement only appending a newline + */ + public static Statement literal(String literalStatement) { + return new LiteralStatement(literalStatement); + } + /** * interprets and adds a newline to the statement */ diff --git a/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceLiveTest.java b/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceLiveTest.java index 1d1fc7c376..c96bbf8884 100644 --- a/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceLiveTest.java +++ b/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceLiveTest.java @@ -57,7 +57,7 @@ public class ServerManagerComputeServiceLiveTest extends BaseComputeServiceLiveT // servermanager does not support metadata @Override - protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap userMetadata) { + protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap userMetadata) { assert node.getUserMetadata().equals(ImmutableMap. of()) : String.format( "node userMetadata did not match %s %s", userMetadata, node); }