Search in sources :

Example 21 with Injector

use of com.google.inject.Injector in project hudson-2.x by hudson.

the class InjectomaticImpl method inject.

public void inject(final Object component) {
    checkNotNull(component);
    Class type = component.getClass();
    if (!isInjectable(type)) {
        log.trace("Type not injectable; skipping: {}", type);
        return;
    }
    // Find the injector for the component
    ClassLoader tmp = type.getClassLoader();
    Injector injector;
    // If the component belongs to a plugin, then use the plugin's injector
    if (tmp instanceof PluginClassLoader) {
        PluginClassLoader cl = (PluginClassLoader) tmp;
        injector = container.injector(cl.getPlugin());
    } else {
        // Use the root injector if we did not load from a plugin
        injector = ((SmoothieContainerImpl) container).rootInjector();
    }
    if (log.isTraceEnabled()) {
        log.trace("Injecting: {}", OID.get(component));
    }
    injector.injectMembers(component);
}
Also used : Injector(com.google.inject.Injector) PluginClassLoader(org.hudsonci.inject.internal.plugin.PluginClassLoader) PluginClassLoader(org.hudsonci.inject.internal.plugin.PluginClassLoader)

Example 22 with Injector

use of com.google.inject.Injector in project hudson-2.x by hudson.

the class SmoothieContainerImpl method register.

public void register(final PluginWrapper plugin) {
    assert plugin != null;
    if (log.isTraceEnabled()) {
        log.trace("Registering plugin: {}", plugin.getShortName());
    }
    // Don't allow re-registration of plugins
    if (injectors.containsKey(plugin)) {
        throw new IllegalStateException("Plugin already registered");
    }
    Injector injector = createInjector(new PluginModule(plugin));
    injectors.put(plugin, injector);
}
Also used : Injector(com.google.inject.Injector)

Example 23 with Injector

use of com.google.inject.Injector in project jmxtrans by jmxtrans.

the class JsonUtilsTest method setupJsonUtils.

@Before
public void setupJsonUtils() {
    Injector injector = JmxTransModule.createInjector(new JmxTransConfiguration());
    jsonUtils = injector.getInstance(JsonUtils.class);
    closer.register(ResetableSystemProperty.setSystemProperty("server.port", "1099"));
    closer.register(ResetableSystemProperty.setSystemProperty("server.attribute", "HeapMemoryUsage"));
    closer.register(ResetableSystemProperty.setSystemProperty("server.thread", "2"));
}
Also used : JmxTransConfiguration(com.googlecode.jmxtrans.cli.JmxTransConfiguration) Injector(com.google.inject.Injector) Before(org.junit.Before)

Example 24 with Injector

use of com.google.inject.Injector in project hadoop by apache.

the class TestContainerLogsPage method testContainerLogPageAccess.

@Test(timeout = 10000)
public void testContainerLogPageAccess() throws IOException {
    // SecureIOUtils require Native IO to be enabled. This test will run
    // only if it is enabled.
    assumeTrue(NativeIO.isAvailable());
    String user = "randomUser" + System.currentTimeMillis();
    File absLogDir = null, appDir = null, containerDir = null, syslog = null;
    try {
        // target log directory
        absLogDir = new File("target", TestContainerLogsPage.class.getSimpleName() + "LogDir").getAbsoluteFile();
        absLogDir.mkdir();
        Configuration conf = new Configuration();
        conf.set(YarnConfiguration.NM_LOG_DIRS, absLogDir.toURI().toString());
        conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
        UserGroupInformation.setConfiguration(conf);
        NodeHealthCheckerService healthChecker = createNodeHealthCheckerService(conf);
        healthChecker.init(conf);
        LocalDirsHandlerService dirsHandler = healthChecker.getDiskHandler();
        // Add an application and the corresponding containers
        RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(conf);
        long clusterTimeStamp = 1234;
        ApplicationId appId = BuilderUtils.newApplicationId(recordFactory, clusterTimeStamp, 1);
        Application app = mock(Application.class);
        when(app.getAppId()).thenReturn(appId);
        // Making sure that application returns a random user. This is required
        // for SecureIOUtils' file owner check.
        when(app.getUser()).thenReturn(user);
        ApplicationAttemptId appAttemptId = BuilderUtils.newApplicationAttemptId(appId, 1);
        ContainerId container1 = BuilderUtils.newContainerId(recordFactory, appId, appAttemptId, 0);
        // Testing secure read access for log files
        // Creating application and container directory and syslog file.
        appDir = new File(absLogDir, appId.toString());
        appDir.mkdir();
        containerDir = new File(appDir, container1.toString());
        containerDir.mkdir();
        syslog = new File(containerDir, "syslog");
        syslog.createNewFile();
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(syslog));
        out.write("Log file Content".getBytes());
        out.close();
        Context context = mock(Context.class);
        ConcurrentMap<ApplicationId, Application> appMap = new ConcurrentHashMap<ApplicationId, Application>();
        appMap.put(appId, app);
        when(context.getApplications()).thenReturn(appMap);
        ConcurrentHashMap<ContainerId, Container> containers = new ConcurrentHashMap<ContainerId, Container>();
        when(context.getContainers()).thenReturn(containers);
        when(context.getLocalDirsHandler()).thenReturn(dirsHandler);
        MockContainer container = new MockContainer(appAttemptId, new AsyncDispatcher(), conf, user, appId, 1);
        container.setState(ContainerState.RUNNING);
        context.getContainers().put(container1, container);
        ContainersLogsBlock cLogsBlock = new ContainersLogsBlock(context);
        Map<String, String> params = new HashMap<String, String>();
        params.put(YarnWebParams.CONTAINER_ID, container1.toString());
        params.put(YarnWebParams.CONTAINER_LOG_TYPE, "syslog");
        Injector injector = WebAppTests.testPage(ContainerLogsPage.class, ContainersLogsBlock.class, cLogsBlock, params, (Module[]) null);
        PrintWriter spyPw = WebAppTests.getPrintWriter(injector);
        verify(spyPw).write("Exception reading log file. Application submitted by '" + user + "' doesn't own requested log file : syslog");
    } finally {
        if (syslog != null) {
            syslog.delete();
        }
        if (containerDir != null) {
            containerDir.delete();
        }
        if (appDir != null) {
            appDir.delete();
        }
        if (absLogDir != null) {
            absLogDir.delete();
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) NodeHealthCheckerService(org.apache.hadoop.yarn.server.nodemanager.NodeHealthCheckerService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Injector(com.google.inject.Injector) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BufferedOutputStream(java.io.BufferedOutputStream) PrintWriter(java.io.PrintWriter) NMContext(org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext) Context(org.apache.hadoop.yarn.server.nodemanager.Context) ContainersLogsBlock(org.apache.hadoop.yarn.server.nodemanager.webapp.ContainerLogsPage.ContainersLogsBlock) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) LocalDirsHandlerService(org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService) RecordFactory(org.apache.hadoop.yarn.factories.RecordFactory) AsyncDispatcher(org.apache.hadoop.yarn.event.AsyncDispatcher) FileOutputStream(java.io.FileOutputStream) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Module(com.google.inject.Module) File(java.io.File) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) Test(org.junit.Test)

Example 25 with Injector

use of com.google.inject.Injector in project hadoop by apache.

the class TestRMWebApp method testControllerIndex.

@Test
public void testControllerIndex() {
    Injector injector = WebAppTests.createMockInjector(TestRMWebApp.class, this, new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(ApplicationACLsManager.class).toInstance(new ApplicationACLsManager(new Configuration()));
        }
    });
    RmController c = injector.getInstance(RmController.class);
    c.index();
    assertEquals("Applications", c.get(TITLE, "unknown"));
}
Also used : Binder(com.google.inject.Binder) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Injector(com.google.inject.Injector) Module(com.google.inject.Module) Test(org.junit.Test)

Aggregations

Injector (com.google.inject.Injector)2117 AbstractModule (com.google.inject.AbstractModule)624 Test (org.junit.Test)513 Module (com.google.inject.Module)386 Binder (com.google.inject.Binder)140 Before (org.junit.Before)116 Properties (java.util.Properties)110 Test (org.testng.annotations.Test)105 Key (com.google.inject.Key)91 HttpServletRequest (javax.servlet.http.HttpServletRequest)78 Map (java.util.Map)75 Provider (com.google.inject.Provider)74 TypeLiteral (com.google.inject.TypeLiteral)70 IOException (java.io.IOException)69 Set (java.util.Set)63 BeforeClass (org.junit.BeforeClass)61 File (java.io.File)59 ImmutableList (com.google.common.collect.ImmutableList)58 CConfiguration (co.cask.cdap.common.conf.CConfiguration)55 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)55