mirror of https://github.com/apache/jclouds.git
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:
commit
c3660caea0
|
@ -27,8 +27,6 @@ import org.jclouds.byon.Node;
|
||||||
import org.jclouds.byon.config.CacheNodeStoreModule;
|
import org.jclouds.byon.config.CacheNodeStoreModule;
|
||||||
import org.jclouds.compute.StandaloneComputeServiceContextBuilder;
|
import org.jclouds.compute.StandaloneComputeServiceContextBuilder;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.concurrent.MoreExecutors;
|
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
|
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
|
|
@ -150,7 +150,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(String vmName) {
|
public synchronized void destroyNode(String vmName) {
|
||||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
||||||
powerDownMachine(machine);
|
powerDownMachine(machine);
|
||||||
new UnregisterMachineIfExistsAndForceDeleteItsMedia().apply(machine);
|
new UnregisterMachineIfExistsAndForceDeleteItsMedia().apply(machine);
|
||||||
|
@ -198,10 +198,10 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
private void powerDownMachine(IMachine machine) {
|
private void powerDownMachine(IMachine machine) {
|
||||||
try {
|
try {
|
||||||
if (machine.getState() == MachineState.PoweredOff){
|
if (machine.getState() == MachineState.PoweredOff){
|
||||||
logger.debug("vm was already powered down: ", machine.getName());
|
logger.debug("vm was already powered down: ", machine.getId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug("powering down vm: ", machine.getName());
|
logger.debug("powering down vm: ", machine.getId());
|
||||||
ISession machineSession = manager.get().openMachineSession(machine);
|
ISession machineSession = manager.get().openMachineSession(machine);
|
||||||
IProgress progress = machineSession.getConsole().powerDown();
|
IProgress progress = machineSession.getConsole().powerDown();
|
||||||
progress.waitForCompletion(-1);
|
progress.waitForCompletion(-1);
|
||||||
|
|
|
@ -33,7 +33,6 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.jclouds.byon.Node;
|
import org.jclouds.byon.Node;
|
||||||
import org.jclouds.byon.config.CacheNodeStoreModule;
|
|
||||||
import org.jclouds.byon.functions.NodeToNodeMetadata;
|
import org.jclouds.byon.functions.NodeToNodeMetadata;
|
||||||
import org.jclouds.byon.suppliers.SupplyFromProviderURIOrNodesProperty;
|
import org.jclouds.byon.suppliers.SupplyFromProviderURIOrNodesProperty;
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
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.OsFamily;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
import org.jclouds.concurrent.SingleThreaded;
|
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.functions.IdentityFunction;
|
import org.jclouds.functions.IdentityFunction;
|
||||||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||||
|
@ -105,7 +103,6 @@ import com.google.inject.TypeLiteral;
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @author Mattias Holmqvist, Andrea Turli
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
@SingleThreaded
|
|
||||||
public class VirtualBoxComputeServiceContextModule extends
|
public class VirtualBoxComputeServiceContextModule extends
|
||||||
ComputeServiceAdapterContextModule<Supplier, Supplier, IMachine, IMachine, Image, Location> {
|
ComputeServiceAdapterContextModule<Supplier, Supplier, IMachine, IMachine, Image, Location> {
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
@ -47,7 +48,7 @@ import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CloneAndRegisterMachineFromIMachineIfNotAlreadyExists will take care of the followings: - cloning
|
* CloneAndRegisterMachineFromIMachineIfNotAlreadyExists will take care of the followings: - cloning
|
||||||
* the master - register the clone machine -
|
* the master - register the clone machine.
|
||||||
*
|
*
|
||||||
* @author Andrea Turli
|
* @author Andrea Turli
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -84,8 +84,13 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
|
||||||
this.imachineToNodeMetadata = imachineToNodeMetadata;
|
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
|
@Override
|
||||||
public NodeAndInitialCredentials<IMachine> apply(NodeSpec nodeSpec) {
|
public synchronized NodeAndInitialCredentials<IMachine> apply(NodeSpec nodeSpec) {
|
||||||
|
|
||||||
checkNotNull(nodeSpec, "NodeSpec");
|
checkNotNull(nodeSpec, "NodeSpec");
|
||||||
|
|
||||||
|
@ -102,6 +107,7 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
|
||||||
session.getConsole().deleteSnapshot(master.getMachine().getCurrentSnapshot().getId());
|
session.getConsole().deleteSnapshot(master.getMachine().getCurrentSnapshot().getId());
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
}
|
}
|
||||||
|
|
||||||
String masterNameWithoutPrefix = master.getSpec().getVmSpec().getVmName().replace(VIRTUALBOX_IMAGE_PREFIX, "");
|
String masterNameWithoutPrefix = master.getSpec().getVmSpec().getVmName().replace(VIRTUALBOX_IMAGE_PREFIX, "");
|
||||||
|
|
||||||
String cloneName = VIRTUALBOX_NODE_PREFIX + masterNameWithoutPrefix + "-" + nodeSpec.getTag() + "-"
|
String cloneName = VIRTUALBOX_NODE_PREFIX + masterNameWithoutPrefix + "-" + nodeSpec.getTag() + "-"
|
||||||
|
|
|
@ -93,6 +93,12 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
|
||||||
|
|
||||||
runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv),
|
runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv),
|
||||||
runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init().call();
|
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 = managerForNode.apply(host);
|
||||||
manager.connect(provider.toASCIIString(), identity, credential);
|
manager.connect(provider.toASCIIString(), identity, credential);
|
||||||
|
|
|
@ -26,35 +26,47 @@ import java.util.Set;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||||
import org.jclouds.compute.RunNodesException;
|
import org.jclouds.compute.RunNodesException;
|
||||||
import org.jclouds.compute.domain.ExecResponse;
|
import org.jclouds.compute.domain.ExecResponse;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||||
import org.jclouds.ssh.SshClient;
|
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 org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxExperimentLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxExperimentLiveTest")
|
||||||
public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest {
|
public class VirtualBoxExperimentLiveTest {
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
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
|
@Test
|
||||||
public void testLaunchCluster() throws RunNodesException {
|
public void testLaunchCluster() throws RunNodesException {
|
||||||
int numNodes = 4;
|
int numNodes = 4;
|
||||||
final String clusterName = "test-launch-cluster";
|
final String clusterName = "test-launch-cluster";
|
||||||
Set<? extends NodeMetadata> nodes = context.getComputeService().createNodesInGroup(clusterName,
|
Set<? extends NodeMetadata> nodes = context.getComputeService().createNodesInGroup(clusterName, numNodes);
|
||||||
numNodes);
|
|
||||||
assertEquals(numNodes, nodes.size(), "wrong number of nodes");
|
assertEquals(numNodes, nodes.size(), "wrong number of nodes");
|
||||||
for (NodeMetadata node : nodes) {
|
for (NodeMetadata node : nodes) {
|
||||||
logger.debug("Created Node: %s", node);
|
logger.debug("Created Node: %s", node);
|
||||||
|
|
Loading…
Reference in New Issue