Issue 236: parameterize out runscript name

This commit is contained in:
Adrian Cole 2010-04-30 14:17:36 -07:00
parent 139b5fe312
commit e8b77d2765
7 changed files with 77 additions and 64 deletions

View File

@ -65,7 +65,8 @@ import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.GetNodesOptions; 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.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
@ -78,7 +79,6 @@ import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.ssh.SshClient;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -208,8 +208,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Provides @Provides
@Singleton @Singleton
@Named("NOT_RUNNING") @Named("NOT_RUNNING")
protected Predicate<SshClient> runScriptRunning(RunScriptRunning stateRunning) { protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3, return new RetryablePredicate<CommandUsingClient>(Predicates.not(stateRunning), 600, 3,
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }

View File

@ -34,23 +34,36 @@ import com.google.common.base.Predicate;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class RunScriptRunning implements Predicate<SshClient> { public class ScriptStatusReturnsZero implements
Predicate<ScriptStatusReturnsZero.CommandUsingClient> {
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
public boolean apply(SshClient ssh) { @Override
logger.trace("looking for runscript state on %s@%s", ssh.getUsername(), ssh.getHostAddress()); public boolean apply(CommandUsingClient commandUsingClient) {
ExecResponse response = refresh(ssh); 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) while (response.getExitCode() == -1)
response = refresh(ssh); response = refresh(commandUsingClient);
logger.trace("%s@%s: looking for exit code 0: currently: %s", ssh.getUsername(), ssh logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client
.getHostAddress(), response.getExitCode()); .getUsername(), commandUsingClient.client.getHostAddress(), response.getExitCode());
return 0 == response.getExitCode(); return 0 == response.getExitCode();
} }
private ExecResponse refresh(SshClient ssh) { private ExecResponse refresh(CommandUsingClient commandUsingClient) {
return ssh.exec("./runscript.sh status"); 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;
} }
} }

View File

@ -47,6 +47,7 @@ import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.concurrent.ConcurrentUtils; import org.jclouds.concurrent.ConcurrentUtils;
import org.jclouds.domain.Credentials; 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.common.util.concurrent.ListenableFuture;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -80,7 +80,7 @@ public class ComputeUtils {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@Inject(optional = true) @Inject(optional = true)
private SshClient.Factory sshFactory; private SshClient.Factory sshFactory;
protected final Predicate<SshClient> runScriptNotRunning; protected final Predicate<CommandUsingClient> runScriptNotRunning;
private final Predicate<InetSocketAddress> socketTester; private final Predicate<InetSocketAddress> socketTester;
private final ExecutorService executor; private final ExecutorService executor;
@ -88,7 +88,7 @@ public class ComputeUtils {
@Inject @Inject
public ComputeUtils(Predicate<InetSocketAddress> socketTester, public ComputeUtils(Predicate<InetSocketAddress> socketTester,
@Named("NOT_RUNNING") Predicate<SshClient> runScriptNotRunning, @Named("NOT_RUNNING") Predicate<CommandUsingClient> runScriptNotRunning,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.socketTester = socketTester; this.socketTester = socketTester;
this.runScriptNotRunning = runScriptNotRunning; this.runScriptNotRunning = runScriptNotRunning;
@ -245,14 +245,14 @@ public class ComputeUtils {
public static class RunScriptOnNode implements SshCallable<ExecResponse> { public static class RunScriptOnNode implements SshCallable<ExecResponse> {
private SshClient ssh; private SshClient ssh;
protected final Predicate<SshClient> runScriptNotRunning; protected final Predicate<CommandUsingClient> runScriptNotRunning;
private final NodeMetadata node; private final NodeMetadata node;
private final String scriptName; private final String scriptName;
private final byte[] script; private final byte[] script;
private final boolean runAsRoot; private final boolean runAsRoot;
private Logger logger = Logger.NULL; private Logger logger = Logger.NULL;
RunScriptOnNode(@Named("NOT_RUNNING") Predicate<SshClient> runScriptNotRunning, RunScriptOnNode(@Named("NOT_RUNNING") Predicate<CommandUsingClient> runScriptNotRunning,
NodeMetadata node, String scriptName, byte[] script) { NodeMetadata node, String scriptName, byte[] script) {
this.runScriptNotRunning = runScriptNotRunning; this.runScriptNotRunning = runScriptNotRunning;
this.node = checkNotNull(node, "node"); this.node = checkNotNull(node, "node");
@ -264,7 +264,7 @@ public class ComputeUtils {
this.runAsRoot = true; this.runAsRoot = true;
} }
RunScriptOnNode(@Named("NOT_RUNNING") Predicate<SshClient> runScriptNotRunning, RunScriptOnNode(@Named("NOT_RUNNING") Predicate<CommandUsingClient> runScriptNotRunning,
NodeMetadata node, String scriptName, byte[] script, boolean runAsRoot) { NodeMetadata node, String scriptName, byte[] script, boolean runAsRoot) {
this.runScriptNotRunning = runScriptNotRunning; this.runScriptNotRunning = runScriptNotRunning;
this.node = checkNotNull(node, "node"); this.node = checkNotNull(node, "node");
@ -286,7 +286,7 @@ public class ComputeUtils {
returnVal = runScriptAsRoot(); returnVal = runScriptAsRoot();
else else
returnVal = runScriptAsDefaultUser(); returnVal = runScriptAsDefaultUser();
runScriptNotRunning.apply(ssh); runScriptNotRunning.apply(new CommandUsingClient("./" + scriptName + " status", ssh));
logger.debug("<< complete(%d)", returnVal.getExitCode()); logger.debug("<< complete(%d)", returnVal.getExitCode());
return returnVal; return returnVal;
} }
@ -400,30 +400,29 @@ public class ComputeUtils {
} }
/** /**
* Gets a set of supported providers. Idea stolen from pallets (supported-clouds). * Gets a set of supported providers. Idea stolen from pallets (supported-clouds). Uses
* Uses compute.properties to populate the set. * compute.properties to populate the set.
* *
* XXX: Pass in extra properties to support ones that aren't in compute.properties * XXX: Pass in extra properties to support ones that aren't in compute.properties
*/ */
public static Set<String> getSupportedProviders() { public static Set<String> getSupportedProviders() {
Properties properties = new Properties(); Properties properties = new Properties();
try { try {
properties.load(Resources.newInputStreamSupplier( properties.load(Resources.newInputStreamSupplier(
Resources.getResource("compute.properties")).getInput()); Resources.getResource("compute.properties")).getInput());
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
Set<Object> keys = properties.keySet(); Set<Object> keys = properties.keySet();
Set<String> providers = new HashSet<String>(); Set<String> providers = new HashSet<String>();
for (Object key : keys) { for (Object key : keys) {
String keyString = key.toString(); String keyString = key.toString();
if (keyString.endsWith(".contextbuilder")) { if (keyString.endsWith(".contextbuilder")) {
providers.add(keyString.substring(0, keyString.length() providers.add(keyString.substring(0, keyString.length() - ".contextbuilder".length()));
- ".contextbuilder".length())); }
} }
} return providers;
return providers; }
}
} }

View File

@ -49,7 +49,8 @@ import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.GetNodesOptions; 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.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
@ -74,7 +75,6 @@ import org.jclouds.gogrid.util.GoGridUtils;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.ssh.SshClient;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -267,8 +267,8 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
@Provides @Provides
@Singleton @Singleton
@Named("NOT_RUNNING") @Named("NOT_RUNNING")
protected Predicate<SshClient> runScriptRunning(RunScriptRunning stateRunning) { protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3, return new RetryablePredicate<CommandUsingClient>(Predicates.not(stateRunning), 600, 3,
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }

View File

@ -54,7 +54,8 @@ import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.GetNodesOptions; 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.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.compute.strategy.DestroyNodeStrategy; 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.config.RackspaceLocationsModule;
import org.jclouds.rackspace.reference.RackspaceConstants; import org.jclouds.rackspace.reference.RackspaceConstants;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.ssh.SshClient;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -277,8 +277,8 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
@Provides @Provides
@Singleton @Singleton
@Named("NOT_RUNNING") @Named("NOT_RUNNING")
protected Predicate<SshClient> runScriptRunning(RunScriptRunning stateRunning) { protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3, return new RetryablePredicate<CommandUsingClient>(Predicates.not(stateRunning), 600, 3,
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }

View File

@ -55,7 +55,8 @@ import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.GetNodesOptions; 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.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.compute.strategy.DestroyNodeStrategy; 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.PricingPlan;
import org.jclouds.rimuhosting.miro.domain.Server; import org.jclouds.rimuhosting.miro.domain.Server;
import org.jclouds.rimuhosting.miro.domain.internal.RunningState; import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
import org.jclouds.ssh.SshClient;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -275,7 +275,8 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
@Override @Override
public NodeMetadata apply(Server from) { 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]+", ""); String tag = from.getName().replaceAll("-[0-9]+", "");
Credentials creds = null; Credentials creds = null;
NodeState state = runningStateToNodeState.get(from.getState()); NodeState state = runningStateToNodeState.get(from.getState());
@ -320,8 +321,8 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
@Provides @Provides
@Singleton @Singleton
@Named("NOT_RUNNING") @Named("NOT_RUNNING")
protected Predicate<SshClient> runScriptRunning(RunScriptRunning stateRunning) { protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3, return new RetryablePredicate<CommandUsingClient>(Predicates.not(stateRunning), 600, 3,
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }
@ -378,9 +379,9 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
for (final PricingPlan from : sync.getPricingPlanList()) { for (final PricingPlan from : sync.getPricingPlanList()) {
try { try {
sizes.add(new SizeImpl(from.getId(), from.getId(), locations.get(from.getDataCenter() sizes.add(new SizeImpl(from.getId(), from.getId(), locations.get(from.getDataCenter()
.getId()), null, ImmutableMap.<String, String> of(), 1, from .getId()), null, ImmutableMap.<String, String> of(), 1, from.getRam(), from
.getRam(), from.getDiskSize(), ImmutableSet.<Architecture> of( .getDiskSize(), ImmutableSet.<Architecture> of(Architecture.X86_32,
Architecture.X86_32, Architecture.X86_64))); Architecture.X86_64)));
} catch (NullPointerException e) { } catch (NullPointerException e) {
holder.logger.warn("datacenter not present in " + from.getId()); holder.logger.warn("datacenter not present in " + from.getId());
} }

View File

@ -55,7 +55,8 @@ import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl; import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.GetNodesOptions; 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.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
@ -72,7 +73,6 @@ import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.ssh.SshClient;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
@ -286,8 +286,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
@Provides @Provides
@Singleton @Singleton
@Named("NOT_RUNNING") @Named("NOT_RUNNING")
protected Predicate<SshClient> runScriptRunning(RunScriptRunning stateRunning) { protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3, return new RetryablePredicate<CommandUsingClient>(Predicates.not(stateRunning), 600, 3,
TimeUnit.SECONDS); TimeUnit.SECONDS);
} }