mirror of https://github.com/apache/jclouds.git
commented mastersloadingcache and nodecreator
This commit is contained in:
parent
78d85fc960
commit
6967743044
|
@ -20,6 +20,7 @@ package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.call;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -28,6 +29,9 @@ import javax.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.domain.ExecResponse;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.options.RunScriptOptions;
|
||||||
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.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
|
@ -40,13 +44,13 @@ import org.jclouds.virtualbox.util.MachineController;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.LockType;
|
import org.virtualbox_4_1.LockType;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.util.concurrent.Futures;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -56,7 +60,6 @@ public class CreateAndInstallVm implements Function<MasterSpec, IMachine> {
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
private final Supplier<VirtualBoxManager> manager;
|
|
||||||
private final CreateAndRegisterMachineFromIsoIfNotAlreadyExists createAndRegisterMachineFromIsoIfNotAlreadyExists;
|
private final CreateAndRegisterMachineFromIsoIfNotAlreadyExists createAndRegisterMachineFromIsoIfNotAlreadyExists;
|
||||||
private final GuestAdditionsInstaller guestAdditionsInstaller;
|
private final GuestAdditionsInstaller guestAdditionsInstaller;
|
||||||
private final Predicate<SshClient> sshResponds;
|
private final Predicate<SshClient> sshResponds;
|
||||||
|
@ -69,7 +72,6 @@ public class CreateAndInstallVm implements Function<MasterSpec, IMachine> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public CreateAndInstallVm(
|
public CreateAndInstallVm(
|
||||||
Supplier<VirtualBoxManager> manager,
|
|
||||||
CreateAndRegisterMachineFromIsoIfNotAlreadyExists CreateAndRegisterMachineFromIsoIfNotAlreadyExists,
|
CreateAndRegisterMachineFromIsoIfNotAlreadyExists CreateAndRegisterMachineFromIsoIfNotAlreadyExists,
|
||||||
GuestAdditionsInstaller guestAdditionsInstaller,
|
GuestAdditionsInstaller guestAdditionsInstaller,
|
||||||
IMachineToNodeMetadata imachineToNodeMetadata,
|
IMachineToNodeMetadata imachineToNodeMetadata,
|
||||||
|
@ -77,7 +79,6 @@ public class CreateAndInstallVm implements Function<MasterSpec, IMachine> {
|
||||||
Function<IMachine, SshClient> sshClientForIMachine,
|
Function<IMachine, SshClient> sshClientForIMachine,
|
||||||
MachineUtils machineUtils,
|
MachineUtils machineUtils,
|
||||||
@Preconfiguration LoadingCache<IsoSpec, URI> preConfiguration, MachineController machineController) {
|
@Preconfiguration LoadingCache<IsoSpec, URI> preConfiguration, MachineController machineController) {
|
||||||
this.manager = manager;
|
|
||||||
this.createAndRegisterMachineFromIsoIfNotAlreadyExists = CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
|
this.createAndRegisterMachineFromIsoIfNotAlreadyExists = CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
|
||||||
this.sshResponds = sshResponds;
|
this.sshResponds = sshResponds;
|
||||||
this.sshClientForIMachine = sshClientForIMachine;
|
this.sshClientForIMachine = sshClientForIMachine;
|
||||||
|
@ -121,13 +122,13 @@ public class CreateAndInstallVm implements Function<MasterSpec, IMachine> {
|
||||||
|
|
||||||
logger.debug(">> awaiting post-installation actions on vm: %s", vmName);
|
logger.debug(">> awaiting post-installation actions on vm: %s", vmName);
|
||||||
|
|
||||||
// NodeMetadata vmMetadata = imachineToNodeMetadata.apply(vm);
|
NodeMetadata vmMetadata = imachineToNodeMetadata.apply(vm);
|
||||||
|
|
||||||
// ListenableFuture<ExecResponse> execFuture =
|
ListenableFuture<ExecResponse> execFuture =
|
||||||
// machineUtils.runScriptOnNode(vmMetadata, call("cleanupUdevIfNeeded"), RunScriptOptions.NONE);
|
machineUtils.runScriptOnNode(vmMetadata, call("cleanupUdevIfNeeded"), RunScriptOptions.NONE);
|
||||||
|
|
||||||
// ExecResponse execResponse = Futures.getUnchecked(execFuture);
|
ExecResponse execResponse = Futures.getUnchecked(execFuture);
|
||||||
// checkState(execResponse.getExitStatus() == 0);
|
checkState(execResponse.getExitStatus() == 0);
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"<< installation of image complete. Powering down node(%s)",
|
"<< installation of image complete. Powering down node(%s)",
|
||||||
|
|
|
@ -64,11 +64,14 @@ import com.google.common.base.Function;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.cache.AbstractLoadingCache;
|
import com.google.common.cache.AbstractLoadingCache;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does most of the work wrt to creating the master image.
|
* A {@link LoadingCache} for masters. If the requested master has been previously created this
|
||||||
|
* returns it, if not it coordinates its creation including downloading isos and creating
|
||||||
|
* cache/config directories.
|
||||||
*
|
*
|
||||||
* @author dralves
|
* @author dralves
|
||||||
*
|
*
|
||||||
|
|
|
@ -54,6 +54,13 @@ import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates nodes, by cloning a master vm and based on the provided {@link NodeSpec}. Must be
|
||||||
|
* synchronized mainly because of snapshot creation (must be synchronized on a per-master-basis).
|
||||||
|
*
|
||||||
|
* @author dralves
|
||||||
|
*
|
||||||
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials<IMachine>> {
|
public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials<IMachine>> {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue