moved host module creation to contextbuilder

This commit is contained in:
David Ribeiro Alves 2012-03-10 17:16:20 +00:00
parent 00c16d5315
commit ad6b655ea1
4 changed files with 30 additions and 21 deletions

View File

@ -48,7 +48,7 @@ public abstract class ComputeServiceContextBuilder<S, A> extends RestContextBuil
@Override
public Injector buildInjector() {
addImageResolutionModuleIfNotPresent();
addHostModuleIfNotPresent();
return super.buildInjector();
}
@ -67,7 +67,7 @@ public abstract class ComputeServiceContextBuilder<S, A> extends RestContextBuil
asyncClientType)));
}
protected void addImageResolutionModuleIfNotPresent() {
protected void addHostModuleIfNotPresent() {
if (!Iterables.any(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().isAnnotationPresent(ResolvesImages.class);

View File

@ -19,13 +19,20 @@
package org.jclouds.virtualbox;
import java.net.URI;
import java.util.List;
import java.util.Properties;
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.virtualbox.config.VirtualBoxComputeServiceContextModule;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.inject.Module;
/**
@ -43,6 +50,25 @@ public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBui
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new VirtualBoxComputeServiceContextModule());
addHostModuleIfNotPresent(modules);
}
protected void addHostModuleIfNotPresent(List<Module> modules) {
if (!Iterables.any(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().equals(CacheNodeStoreModule.class);
}
})) {
CacheNodeStoreModule hostModule = new CacheNodeStoreModule(ImmutableMap.of(
"host",
Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
.osVersion(System.getProperty("os.version")).group("ssh")
.username(System.getProperty("user.name"))
.credentialUrl(URI.create("file://" + System.getProperty("user.home") + "/.ssh/id_rsa"))
.build()));
modules.add(hostModule);
}
}
}

View File

@ -176,16 +176,8 @@ public class VirtualBoxComputeServiceContextModule extends
String provider = "byon";
String identity = "";
String credential = "";
CacheNodeStoreModule hostModule = new CacheNodeStoreModule(ImmutableMap.of(
"host",
Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
.osVersion(System.getProperty("os.version")).group("ssh")
.username(System.getProperty("user.name"))
.credentialUrl(URI.create("file://" + System.getProperty("user.home") + "/.ssh/id_rsa"))
.build()));
return new ComputeServiceContextFactory().createContext(provider, identity, credential,
ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule(), hostModule));
ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule()));
}
@Provides

View File

@ -135,17 +135,8 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
setupCredentials();
Properties overrides = new VirtualBoxPropertiesBuilder(setupProperties()).build();
CacheNodeStoreModule hostModule = new CacheNodeStoreModule(ImmutableMap.of(
"host",
Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
.osVersion(System.getProperty("os.version")).group("ssh")
.username(System.getProperty("user.name"))
.credentialUrl(URI.create("file://" + System.getProperty("user.home") + "/.ssh/id_rsa"))
.build()));
context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet
.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule(), hostModule, new ExecutorServiceModule(
.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule(), new ExecutorServiceModule(
singleThreadExec, singleThreadExec)), overrides);
context.utils().injector().injectMembers(this);