Merge pull request #425 from dralves/jclouds-vbox-nat-host-only-working-cluster-and-live-test

Jclouds vbox nat host only working cluster and live test
This commit is contained in:
Adrian Cole 2012-03-12 08:40:27 -07:00
commit c3660caea0
7 changed files with 38 additions and 18 deletions

View File

@ -27,8 +27,6 @@ import org.jclouds.byon.Node;
import org.jclouds.byon.config.CacheNodeStoreModule;
import org.jclouds.compute.StandaloneComputeServiceContextBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.concurrent.MoreExecutors;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
import com.google.common.base.Predicate;

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

@ -33,7 +33,6 @@ import javax.inject.Singleton;
import org.eclipse.jetty.server.Server;
import org.jclouds.byon.Node;
import org.jclouds.byon.config.CacheNodeStoreModule;
import org.jclouds.byon.functions.NodeToNodeMetadata;
import org.jclouds.byon.suppliers.SupplyFromProviderURIOrNodesProperty;
import org.jclouds.compute.ComputeServiceAdapter;
@ -49,7 +48,6 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
import org.jclouds.concurrent.SingleThreaded;
import org.jclouds.domain.Location;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
@ -105,7 +103,6 @@ import com.google.inject.TypeLiteral;
* @author Mattias Holmqvist, Andrea Turli
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SingleThreaded
public class VirtualBoxComputeServiceContextModule extends
ComputeServiceAdapterContextModule<Supplier, Supplier, IMachine, IMachine, Image, Location> {

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
*/

View File

@ -56,13 +56,13 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
// TODO parameterize
public static final int NODE_PORT_INIT = 3000;
// TODO parameterize
public static final String VMS_NETWORK = "33.33.33.";
// TODO parameterize
public static final String HOST_ONLY_IFACE_NAME = "vboxnet0";
// TODO parameterize
public static final boolean USE_LINKED = true;
@ -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);

View File

@ -26,35 +26,47 @@ import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.ssh.SshClient;
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxExperimentLiveTest")
public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest {
public class VirtualBoxExperimentLiveTest {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
ComputeServiceContext context;
@BeforeClass
public void setUp() {
context = new ComputeServiceContextFactory().createContext("virtualbox", "toor", "password",
ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule()));
}
@Test
public void testLaunchCluster() throws RunNodesException {
int numNodes = 4;
final String clusterName = "test-launch-cluster";
Set<? extends NodeMetadata> nodes = context.getComputeService().createNodesInGroup(clusterName,
numNodes);
Set<? extends NodeMetadata> nodes = context.getComputeService().createNodesInGroup(clusterName, numNodes);
assertEquals(numNodes, nodes.size(), "wrong number of nodes");
for (NodeMetadata node : nodes) {
logger.debug("Created Node: %s", node);