Search in sources :

Example 1 with SpaceModule

use of org.eclipse.sisu.space.SpaceModule in project nexus-public by sonatype.

the class TaskSchedulerHelper method init.

public void init(@Nullable final Integer poolSize, @Nullable final JobFactory factory) throws Exception {
    eventManager = new SimpleEventManager();
    applicationDirectories = mock(ApplicationDirectories.class);
    baseUrlManager = mock(BaseUrlManager.class);
    nodeAccess = mock(NodeAccess.class);
    lastShutdownTimeService = mock(LastShutdownTimeService.class);
    statusDelayedExecutor = mock(DatabaseStatusDelayedExecutor.class);
    Module module = binder -> {
        Properties properties = new Properties();
        properties.put("basedir", util.getBaseDir());
        if (poolSize != null) {
            properties.put("nexus.quartz.poolSize", poolSize);
        }
        binder.bind(ParameterKeys.PROPERTIES).toInstance(properties);
        binder.bind(EventManager.class).toInstance(eventManager);
        File workDir = util.createTempDir(util.getTargetDir(), "workdir");
        when(applicationDirectories.getWorkDirectory(anyString())).thenReturn(workDir);
        binder.bind(ApplicationDirectories.class).toInstance(applicationDirectories);
        binder.bind(BaseUrlManager.class).toInstance(baseUrlManager);
        binder.bind(DatabaseInstance.class).annotatedWith(Names.named("config")).toInstance(databaseInstance);
        doAnswer(i -> {
            ((Runnable) i.getArguments()[0]).run();
            return null;
        }).when(statusDelayedExecutor).execute(any(Runnable.class));
        binder.bind(DatabaseStatusDelayedExecutor.class).toInstance(statusDelayedExecutor);
        when(nodeAccess.getId()).thenReturn("test-12345");
        when(nodeAccess.getMemberIds()).thenReturn(ImmutableSet.of("test-12345"));
        binder.bind(NodeAccess.class).toInstance(nodeAccess);
        if (factory != null) {
            binder.bind(JobFactory.class).toInstance(factory);
        }
        binder.bind(LastShutdownTimeService.class).toInstance(lastShutdownTimeService);
        when(lastShutdownTimeService.estimateLastShutdownTime()).thenReturn(Optional.empty());
        // filtering by feature flag is not supported here yet
        binder.bind(JobStore.class).to(JobStoreImpl.class);
    };
    this.injector = Guice.createInjector(new WireModule(module, new StateGuardModule(), new SpaceModule(new URLClassSpace(TaskSchedulerHelper.class.getClassLoader()), BeanScanning.INDEX)));
    injector.injectMembers(this);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Module(com.google.inject.Module) SpaceModule(org.eclipse.sisu.space.SpaceModule) NodeAccess(org.sonatype.nexus.common.node.NodeAccess) EventManager(org.sonatype.nexus.common.event.EventManager) Inject(javax.inject.Inject) MutableBeanLocator(org.eclipse.sisu.inject.MutableBeanLocator) JobStore(org.quartz.spi.JobStore) JobStoreImpl(org.sonatype.nexus.quartz.internal.orient.JobStoreImpl) BeanScanning(org.eclipse.sisu.space.BeanScanning) Mockito.doAnswer(org.mockito.Mockito.doAnswer) SchedulerSPI(org.sonatype.nexus.scheduling.spi.SchedulerSPI) Nullable(javax.annotation.Nullable) DatabaseStatusDelayedExecutor(org.sonatype.nexus.thread.DatabaseStatusDelayedExecutor) ApplicationDirectories(org.sonatype.nexus.common.app.ApplicationDirectories) ParameterKeys(org.eclipse.sisu.wire.ParameterKeys) WireModule(org.eclipse.sisu.wire.WireModule) Properties(java.util.Properties) ImmutableSet(com.google.common.collect.ImmutableSet) QuartzSchedulerProvider(org.sonatype.nexus.quartz.internal.QuartzSchedulerProvider) TaskScheduler(org.sonatype.nexus.scheduling.TaskScheduler) JobFactory(org.quartz.spi.JobFactory) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) LastShutdownTimeService(org.sonatype.nexus.common.log.LastShutdownTimeService) StateGuardModule(org.sonatype.nexus.common.stateguard.StateGuardModule) Names(com.google.inject.name.Names) Mockito.when(org.mockito.Mockito.when) DatabaseInstance(org.sonatype.nexus.orient.DatabaseInstance) File(java.io.File) URLClassSpace(org.eclipse.sisu.space.URLClassSpace) Injector(com.google.inject.Injector) TestUtil(org.sonatype.goodies.testsupport.TestUtil) SimpleEventManager(org.sonatype.nexus.testcommon.event.SimpleEventManager) Optional(java.util.Optional) Guice(com.google.inject.Guice) BaseUrlManager(org.sonatype.nexus.common.app.BaseUrlManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) NodeAccess(org.sonatype.nexus.common.node.NodeAccess) JobStoreImpl(org.sonatype.nexus.quartz.internal.orient.JobStoreImpl) WireModule(org.eclipse.sisu.wire.WireModule) DatabaseStatusDelayedExecutor(org.sonatype.nexus.thread.DatabaseStatusDelayedExecutor) ApplicationDirectories(org.sonatype.nexus.common.app.ApplicationDirectories) StateGuardModule(org.sonatype.nexus.common.stateguard.StateGuardModule) SimpleEventManager(org.sonatype.nexus.testcommon.event.SimpleEventManager) Properties(java.util.Properties) DatabaseInstance(org.sonatype.nexus.orient.DatabaseInstance) LastShutdownTimeService(org.sonatype.nexus.common.log.LastShutdownTimeService) BaseUrlManager(org.sonatype.nexus.common.app.BaseUrlManager) URLClassSpace(org.eclipse.sisu.space.URLClassSpace) Module(com.google.inject.Module) SpaceModule(org.eclipse.sisu.space.SpaceModule) WireModule(org.eclipse.sisu.wire.WireModule) StateGuardModule(org.sonatype.nexus.common.stateguard.StateGuardModule) File(java.io.File) SpaceModule(org.eclipse.sisu.space.SpaceModule)

Example 2 with SpaceModule

use of org.eclipse.sisu.space.SpaceModule in project nexus-public by sonatype.

the class AbstractSecurityTest method doSetUp.

@Before
public final void doSetUp() throws Exception {
    List<Module> modules = new ArrayList<>();
    customizeModules(modules);
    modules.add(new SpaceModule(new URLClassSpace(getClass().getClassLoader()), BeanScanning.INDEX));
    Guice.createInjector(new WireModule(modules));
    setUp();
}
Also used : WireModule(org.eclipse.sisu.wire.WireModule) ArrayList(java.util.ArrayList) URLClassSpace(org.eclipse.sisu.space.URLClassSpace) Module(com.google.inject.Module) SpaceModule(org.eclipse.sisu.space.SpaceModule) WireModule(org.eclipse.sisu.wire.WireModule) AbstractModule(com.google.inject.AbstractModule) SpaceModule(org.eclipse.sisu.space.SpaceModule) Before(org.junit.Before)

Example 3 with SpaceModule

use of org.eclipse.sisu.space.SpaceModule in project concord by walmartlabs.

the class CurrentClasspathModule method configure.

@Override
protected void configure() {
    ClassLoader cl = this.getClass().getClassLoader();
    install(new SpaceModule(new URLClassSpace(cl), BeanScanning.GLOBAL_INDEX));
}
Also used : URLClassSpace(org.eclipse.sisu.space.URLClassSpace) SpaceModule(org.eclipse.sisu.space.SpaceModule)

Example 4 with SpaceModule

use of org.eclipse.sisu.space.SpaceModule in project concord by walmartlabs.

the class ProcessDependenciesModule method configure.

@Override
protected void configure() {
    try {
        ClassLoader cl = loadDependencies(workDir, dependencies, debug);
        // required to support ScriptEngines from external dependencies
        Thread.currentThread().setContextClassLoader(cl);
        install(new SpaceModule(new URLClassSpace(cl), BeanScanning.GLOBAL_INDEX));
        bind(ClassLoader.class).annotatedWith(Names.named("runtime")).toInstance(cl);
    } catch (IOException e) {
        addError(e);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassSpace(org.eclipse.sisu.space.URLClassSpace) IOException(java.io.IOException) SpaceModule(org.eclipse.sisu.space.SpaceModule)

Example 5 with SpaceModule

use of org.eclipse.sisu.space.SpaceModule in project concord by walmartlabs.

the class MigrateDB method main.

public static void main(String[] args) throws Exception {
    EnvironmentSelector environmentSelector = new EnvironmentSelector();
    Config cfg = new ConfigurationProcessor("concord-server", environmentSelector.select()).process();
    Injector injector = Guice.createInjector(new WireModule(new SpaceModule(new URLClassSpace(MigrateDB.class.getClassLoader()), BeanScanning.CACHE), new OllieConfigurationModule("com.walmartlabs.concord.server", cfg), new DatabaseModule()));
    new MigrateDB().run(injector);
}
Also used : OllieConfigurationModule(com.walmartlabs.ollie.config.OllieConfigurationModule) WireModule(org.eclipse.sisu.wire.WireModule) EnvironmentSelector(com.walmartlabs.ollie.config.EnvironmentSelector) Config(com.typesafe.config.Config) Injector(com.google.inject.Injector) ConfigurationProcessor(com.walmartlabs.ollie.config.ConfigurationProcessor) DatabaseModule(com.walmartlabs.concord.db.DatabaseModule) URLClassSpace(org.eclipse.sisu.space.URLClassSpace) SpaceModule(org.eclipse.sisu.space.SpaceModule)

Aggregations

SpaceModule (org.eclipse.sisu.space.SpaceModule)8 URLClassSpace (org.eclipse.sisu.space.URLClassSpace)8 WireModule (org.eclipse.sisu.wire.WireModule)6 Injector (com.google.inject.Injector)4 Module (com.google.inject.Module)3 AbstractModule (com.google.inject.AbstractModule)2 URLClassLoader (java.net.URLClassLoader)2 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Guice (com.google.inject.Guice)1 Names (com.google.inject.name.Names)1 Config (com.typesafe.config.Config)1 DatabaseModule (com.walmartlabs.concord.db.DatabaseModule)1 RunnerConfiguration (com.walmartlabs.concord.runtime.common.cfg.RunnerConfiguration)1 Task (com.walmartlabs.concord.sdk.Task)1 ConfigurationProcessor (com.walmartlabs.ollie.config.ConfigurationProcessor)1 EnvironmentSelector (com.walmartlabs.ollie.config.EnvironmentSelector)1 OllieConfigurationModule (com.walmartlabs.ollie.config.OllieConfigurationModule)1