diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java index c70e0aac99..b771690469 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -65,7 +65,8 @@ import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.options.GetNodesOptions; -import org.jclouds.compute.predicates.RunScriptRunning; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; @@ -78,7 +79,6 @@ import org.jclouds.domain.internal.LocationImpl; import org.jclouds.logging.Logger; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; -import org.jclouds.ssh.SshClient; import org.jclouds.util.Jsr330; import com.google.common.base.Function; @@ -208,8 +208,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule { @Provides @Singleton @Named("NOT_RUNNING") - protected Predicate runScriptRunning(RunScriptRunning stateRunning) { - return new RetryablePredicate(Predicates.not(stateRunning), 600, 3, + protected Predicate runScriptRunning(ScriptStatusReturnsZero stateRunning) { + return new RetryablePredicate(Predicates.not(stateRunning), 600, 3, TimeUnit.SECONDS); } diff --git a/compute/src/main/java/org/jclouds/compute/predicates/RunScriptRunning.java b/compute/src/main/java/org/jclouds/compute/predicates/ScriptStatusReturnsZero.java similarity index 56% rename from compute/src/main/java/org/jclouds/compute/predicates/RunScriptRunning.java rename to compute/src/main/java/org/jclouds/compute/predicates/ScriptStatusReturnsZero.java index be6864b331..5b5084ae67 100644 --- a/compute/src/main/java/org/jclouds/compute/predicates/RunScriptRunning.java +++ b/compute/src/main/java/org/jclouds/compute/predicates/ScriptStatusReturnsZero.java @@ -34,23 +34,36 @@ import com.google.common.base.Predicate; * @author Adrian Cole */ @Singleton -public class RunScriptRunning implements Predicate { +public class ScriptStatusReturnsZero implements + Predicate { @Resource protected Logger logger = Logger.NULL; - public boolean apply(SshClient ssh) { - logger.trace("looking for runscript state on %s@%s", ssh.getUsername(), ssh.getHostAddress()); - ExecResponse response = refresh(ssh); + @Override + public boolean apply(CommandUsingClient commandUsingClient) { + logger.trace("looking for [%s] state on %s@%s", commandUsingClient.command, + commandUsingClient.client.getUsername(), commandUsingClient.client.getHostAddress()); + ExecResponse response = refresh(commandUsingClient); while (response.getExitCode() == -1) - response = refresh(ssh); - logger.trace("%s@%s: looking for exit code 0: currently: %s", ssh.getUsername(), ssh - .getHostAddress(), response.getExitCode()); + response = refresh(commandUsingClient); + logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client + .getUsername(), commandUsingClient.client.getHostAddress(), response.getExitCode()); return 0 == response.getExitCode(); - } - private ExecResponse refresh(SshClient ssh) { - return ssh.exec("./runscript.sh status"); + private ExecResponse refresh(CommandUsingClient commandUsingClient) { + return commandUsingClient.client.exec(commandUsingClient.command); + } + + public static class CommandUsingClient { + + public CommandUsingClient(String command, SshClient client) { + this.command = command; + this.client = client; + } + + private final String command; + private final SshClient client; } } diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java index 154ceff579..9aa58d07ff 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java @@ -47,6 +47,7 @@ import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.concurrent.ConcurrentUtils; import org.jclouds.domain.Credentials; @@ -69,7 +70,6 @@ import com.google.common.io.Resources; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; - /** * * @author Adrian Cole @@ -80,7 +80,7 @@ public class ComputeUtils { protected Logger logger = Logger.NULL; @Inject(optional = true) private SshClient.Factory sshFactory; - protected final Predicate runScriptNotRunning; + protected final Predicate runScriptNotRunning; private final Predicate socketTester; private final ExecutorService executor; @@ -88,7 +88,7 @@ public class ComputeUtils { @Inject public ComputeUtils(Predicate socketTester, - @Named("NOT_RUNNING") Predicate runScriptNotRunning, + @Named("NOT_RUNNING") Predicate runScriptNotRunning, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.socketTester = socketTester; this.runScriptNotRunning = runScriptNotRunning; @@ -245,14 +245,14 @@ public class ComputeUtils { public static class RunScriptOnNode implements SshCallable { private SshClient ssh; - protected final Predicate runScriptNotRunning; + protected final Predicate runScriptNotRunning; private final NodeMetadata node; private final String scriptName; private final byte[] script; private final boolean runAsRoot; private Logger logger = Logger.NULL; - RunScriptOnNode(@Named("NOT_RUNNING") Predicate runScriptNotRunning, + RunScriptOnNode(@Named("NOT_RUNNING") Predicate runScriptNotRunning, NodeMetadata node, String scriptName, byte[] script) { this.runScriptNotRunning = runScriptNotRunning; this.node = checkNotNull(node, "node"); @@ -264,7 +264,7 @@ public class ComputeUtils { this.runAsRoot = true; } - RunScriptOnNode(@Named("NOT_RUNNING") Predicate runScriptNotRunning, + RunScriptOnNode(@Named("NOT_RUNNING") Predicate runScriptNotRunning, NodeMetadata node, String scriptName, byte[] script, boolean runAsRoot) { this.runScriptNotRunning = runScriptNotRunning; this.node = checkNotNull(node, "node"); @@ -286,7 +286,7 @@ public class ComputeUtils { returnVal = runScriptAsRoot(); else returnVal = runScriptAsDefaultUser(); - runScriptNotRunning.apply(ssh); + runScriptNotRunning.apply(new CommandUsingClient("./" + scriptName + " status", ssh)); logger.debug("<< complete(%d)", returnVal.getExitCode()); return returnVal; } @@ -398,32 +398,31 @@ public class ComputeUtils { .getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), newCredentials); } - + /** - * Gets a set of supported providers. Idea stolen from pallets (supported-clouds). - * Uses compute.properties to populate the set. + * Gets a set of supported providers. Idea stolen from pallets (supported-clouds). Uses + * compute.properties to populate the set. * * XXX: Pass in extra properties to support ones that aren't in compute.properties */ - public static Set getSupportedProviders() { - Properties properties = new Properties(); - try { - properties.load(Resources.newInputStreamSupplier( - Resources.getResource("compute.properties")).getInput()); - } catch (IOException e) { - throw new RuntimeException(e); - } - Set keys = properties.keySet(); + public static Set getSupportedProviders() { + Properties properties = new Properties(); + try { + properties.load(Resources.newInputStreamSupplier( + Resources.getResource("compute.properties")).getInput()); + } catch (IOException e) { + throw new RuntimeException(e); + } + Set keys = properties.keySet(); - Set providers = new HashSet(); + Set providers = new HashSet(); - for (Object key : keys) { - String keyString = key.toString(); - if (keyString.endsWith(".contextbuilder")) { - providers.add(keyString.substring(0, keyString.length() - - ".contextbuilder".length())); - } - } - return providers; - } + for (Object key : keys) { + String keyString = key.toString(); + if (keyString.endsWith(".contextbuilder")) { + providers.add(keyString.substring(0, keyString.length() - ".contextbuilder".length())); + } + } + return providers; + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java index 1b0e16ac83..1f64f0cd0b 100755 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java @@ -49,7 +49,8 @@ import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.options.GetNodesOptions; -import org.jclouds.compute.predicates.RunScriptRunning; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy; @@ -74,7 +75,6 @@ import org.jclouds.gogrid.util.GoGridUtils; import org.jclouds.logging.Logger; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; -import org.jclouds.ssh.SshClient; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -267,8 +267,8 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule { @Provides @Singleton @Named("NOT_RUNNING") - protected Predicate runScriptRunning(RunScriptRunning stateRunning) { - return new RetryablePredicate(Predicates.not(stateRunning), 600, 3, + protected Predicate runScriptRunning(ScriptStatusReturnsZero stateRunning) { + return new RetryablePredicate(Predicates.not(stateRunning), 600, 3, TimeUnit.SECONDS); } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index b5edc3c78d..9b63a6a885 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -54,7 +54,8 @@ import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.options.GetNodesOptions; -import org.jclouds.compute.predicates.RunScriptRunning; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy; @@ -77,7 +78,6 @@ import org.jclouds.rackspace.cloudservers.options.ListOptions; import org.jclouds.rackspace.config.RackspaceLocationsModule; import org.jclouds.rackspace.reference.RackspaceConstants; import org.jclouds.rest.RestContext; -import org.jclouds.ssh.SshClient; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -277,8 +277,8 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext @Provides @Singleton @Named("NOT_RUNNING") - protected Predicate runScriptRunning(RunScriptRunning stateRunning) { - return new RetryablePredicate(Predicates.not(stateRunning), 600, 3, + protected Predicate runScriptRunning(ScriptStatusReturnsZero stateRunning) { + return new RetryablePredicate(Predicates.not(stateRunning), 600, 3, TimeUnit.SECONDS); } diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java index 5f0a23d658..c23b483385 100755 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java @@ -55,7 +55,8 @@ import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.options.GetNodesOptions; -import org.jclouds.compute.predicates.RunScriptRunning; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy; @@ -76,7 +77,6 @@ import org.jclouds.rimuhosting.miro.domain.NewServerResponse; import org.jclouds.rimuhosting.miro.domain.PricingPlan; import org.jclouds.rimuhosting.miro.domain.Server; import org.jclouds.rimuhosting.miro.domain.internal.RunningState; -import org.jclouds.ssh.SshClient; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -274,8 +274,9 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo @Override public NodeMetadata apply(Server from) { - - Location location = new LocationImpl(LocationScope.ZONE, from.getLocation().getId(), from.getLocation().getName(), null); + + Location location = new LocationImpl(LocationScope.ZONE, from.getLocation().getId(), from + .getLocation().getName(), null); String tag = from.getName().replaceAll("-[0-9]+", ""); Credentials creds = null; NodeState state = runningStateToNodeState.get(from.getState()); @@ -320,8 +321,8 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo @Provides @Singleton @Named("NOT_RUNNING") - protected Predicate runScriptRunning(RunScriptRunning stateRunning) { - return new RetryablePredicate(Predicates.not(stateRunning), 600, 3, + protected Predicate runScriptRunning(ScriptStatusReturnsZero stateRunning) { + return new RetryablePredicate(Predicates.not(stateRunning), 600, 3, TimeUnit.SECONDS); } @@ -378,9 +379,9 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo for (final PricingPlan from : sync.getPricingPlanList()) { try { sizes.add(new SizeImpl(from.getId(), from.getId(), locations.get(from.getDataCenter() - .getId()), null, ImmutableMap. of(), 1, from - .getRam(), from.getDiskSize(), ImmutableSet. of( - Architecture.X86_32, Architecture.X86_64))); + .getId()), null, ImmutableMap. of(), 1, from.getRam(), from + .getDiskSize(), ImmutableSet. of(Architecture.X86_32, + Architecture.X86_64))); } catch (NullPointerException e) { holder.logger.warn("datacenter not present in " + from.getId()); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index e8acca81c3..bc75f43a10 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -55,7 +55,8 @@ import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.options.GetNodesOptions; -import org.jclouds.compute.predicates.RunScriptRunning; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero; +import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy; @@ -72,7 +73,6 @@ import org.jclouds.domain.internal.LocationImpl; import org.jclouds.logging.Logger; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; -import org.jclouds.ssh.SshClient; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudMediaType; @@ -286,8 +286,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { @Provides @Singleton @Named("NOT_RUNNING") - protected Predicate runScriptRunning(RunScriptRunning stateRunning) { - return new RetryablePredicate(Predicates.not(stateRunning), 600, 3, + protected Predicate runScriptRunning(ScriptStatusReturnsZero stateRunning) { + return new RetryablePredicate(Predicates.not(stateRunning), 600, 3, TimeUnit.SECONDS); }