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.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<SshClient> runScriptRunning(RunScriptRunning stateRunning) {
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3,
protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
return new RetryablePredicate<CommandUsingClient>(Predicates.not(stateRunning), 600, 3,
TimeUnit.SECONDS);
}

View File

@ -34,23 +34,36 @@ import com.google.common.base.Predicate;
* @author Adrian Cole
*/
@Singleton
public class RunScriptRunning implements Predicate<SshClient> {
public class ScriptStatusReturnsZero implements
Predicate<ScriptStatusReturnsZero.CommandUsingClient> {
@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;
}
}

View File

@ -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<SshClient> runScriptNotRunning;
protected final Predicate<CommandUsingClient> runScriptNotRunning;
private final Predicate<InetSocketAddress> socketTester;
private final ExecutorService executor;
@ -88,7 +88,7 @@ public class ComputeUtils {
@Inject
public ComputeUtils(Predicate<InetSocketAddress> socketTester,
@Named("NOT_RUNNING") Predicate<SshClient> runScriptNotRunning,
@Named("NOT_RUNNING") Predicate<CommandUsingClient> 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<ExecResponse> {
private SshClient ssh;
protected final Predicate<SshClient> runScriptNotRunning;
protected final Predicate<CommandUsingClient> 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<SshClient> runScriptNotRunning,
RunScriptOnNode(@Named("NOT_RUNNING") Predicate<CommandUsingClient> 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<SshClient> runScriptNotRunning,
RunScriptOnNode(@Named("NOT_RUNNING") Predicate<CommandUsingClient> 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<String> getSupportedProviders() {
Properties properties = new Properties();
try {
properties.load(Resources.newInputStreamSupplier(
Resources.getResource("compute.properties")).getInput());
} catch (IOException e) {
throw new RuntimeException(e);
}
Set<Object> keys = properties.keySet();
public static Set<String> getSupportedProviders() {
Properties properties = new Properties();
try {
properties.load(Resources.newInputStreamSupplier(
Resources.getResource("compute.properties")).getInput());
} catch (IOException e) {
throw new RuntimeException(e);
}
Set<Object> keys = properties.keySet();
Set<String> providers = new HashSet<String>();
Set<String> providers = new HashSet<String>();
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;
}
}

View File

@ -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<SshClient> runScriptRunning(RunScriptRunning stateRunning) {
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3,
protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
return new RetryablePredicate<CommandUsingClient>(Predicates.not(stateRunning), 600, 3,
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.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<SshClient> runScriptRunning(RunScriptRunning stateRunning) {
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3,
protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
return new RetryablePredicate<CommandUsingClient>(Predicates.not(stateRunning), 600, 3,
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.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<SshClient> runScriptRunning(RunScriptRunning stateRunning) {
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3,
protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
return new RetryablePredicate<CommandUsingClient>(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.<String, String> of(), 1, from
.getRam(), from.getDiskSize(), ImmutableSet.<Architecture> of(
Architecture.X86_32, Architecture.X86_64)));
.getId()), null, ImmutableMap.<String, String> of(), 1, from.getRam(), from
.getDiskSize(), ImmutableSet.<Architecture> of(Architecture.X86_32,
Architecture.X86_64)));
} catch (NullPointerException e) {
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.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<SshClient> runScriptRunning(RunScriptRunning stateRunning) {
return new RetryablePredicate<SshClient>(Predicates.not(stateRunning), 600, 3,
protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning) {
return new RetryablePredicate<CommandUsingClient>(Predicates.not(stateRunning), 600, 3,
TimeUnit.SECONDS);
}