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);
}
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);
}
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"));
}
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();
}
}
}
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"));
}
Aggregations