made destroying nodes synchornized due to session lock issues

This commit is contained in:
David Ribeiro Alves 2012-03-12 11:59:45 +00:00
parent 12a9b414e3
commit 91a0980537
4 changed files with 22 additions and 9 deletions

View File

@ -150,7 +150,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
}
@Override
public void destroyNode(String vmName) {
public synchronized void destroyNode(String vmName) {
IMachine machine = manager.get().getVBox().findMachine(vmName);
powerDownMachine(machine);
new UnregisterMachineIfExistsAndForceDeleteItsMedia().apply(machine);
@ -198,10 +198,10 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
private void powerDownMachine(IMachine machine) {
try {
if (machine.getState() == MachineState.PoweredOff){
logger.debug("vm was already powered down: ", machine.getName());
logger.debug("vm was already powered down: ", machine.getId());
return;
}
logger.debug("powering down vm: ", machine.getName());
logger.debug("powering down vm: ", machine.getId());
ISession machineSession = manager.get().openMachineSession(machine);
IProgress progress = machineSession.getConsole().powerDown();
progress.waitForCompletion(-1);

View File

@ -24,6 +24,7 @@ import java.util.List;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
@ -47,7 +48,7 @@ import com.google.inject.Inject;
/**
* CloneAndRegisterMachineFromIMachineIfNotAlreadyExists will take care of the followings: - cloning
* the master - register the clone machine -
* the master - register the clone machine.
*
* @author Andrea Turli
*/
@ -88,7 +89,7 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|| e.getMessage().contains("Could not find a registered machine with UUID {");
}
private synchronized IMachine cloneMachine(CloneSpec cloneSpec) {
private IMachine cloneMachine(CloneSpec cloneSpec) {
VmSpec vmSpec = cloneSpec.getVmSpec();
NetworkSpec networkSpec = cloneSpec.getNetworkSpec();
boolean isLinkedClone = cloneSpec.isLinked();

View File

@ -84,8 +84,13 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
this.imachineToNodeMetadata = imachineToNodeMetadata;
}
/**
* Creates a clone based on the {@link NodeSpec}. It is synchronized because it needs sole access
* to the master. Could be improved by locking on a master basis (would allow concurrent cloning
* as long as form different masters."
*/
@Override
public NodeAndInitialCredentials<IMachine> apply(NodeSpec nodeSpec) {
public synchronized NodeAndInitialCredentials<IMachine> apply(NodeSpec nodeSpec) {
checkNotNull(nodeSpec, "NodeSpec");
@ -102,6 +107,7 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
session.getConsole().deleteSnapshot(master.getMachine().getCurrentSnapshot().getId());
session.unlockMachine();
}
String masterNameWithoutPrefix = master.getSpec().getVmSpec().getVmName().replace(VIRTUALBOX_IMAGE_PREFIX, "");
String cloneName = VIRTUALBOX_NODE_PREFIX + masterNameWithoutPrefix + "-" + nodeSpec.getTag() + "-"

View File

@ -93,6 +93,12 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv),
runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init().call();
try {
// wait for a couple of seconds to make sure vbox has correctly started
Thread.sleep(2000L);
} catch (InterruptedException e) {
}
}
manager = managerForNode.apply(host);
manager.connect(provider.toASCIIString(), identity, credential);