Search in sources :

Example 1 with ServletModule

use of com.google.inject.servlet.ServletModule in project hadoop by apache.

the class TestHsWebServicesJobs method testJobCountersForKilledJob.

@Test
public void testJobCountersForKilledJob() throws Exception {
    WebResource r = resource();
    appContext = new MockHistoryContext(0, 1, 1, 1, true);
    GuiceServletConfig.setInjector(Guice.createInjector(new ServletModule() {

        @Override
        protected void configureServlets() {
            webApp = mock(HsWebApp.class);
            when(webApp.name()).thenReturn("hsmockwebapp");
            bind(JAXBContextResolver.class);
            bind(HsWebServices.class);
            bind(GenericExceptionHandler.class);
            bind(WebApp.class).toInstance(webApp);
            bind(AppContext.class).toInstance(appContext);
            bind(HistoryContext.class).toInstance(appContext);
            bind(Configuration.class).toInstance(conf);
            serve("/*").with(GuiceContainer.class);
        }
    }));
    Map<JobId, Job> jobsMap = appContext.getAllJobs();
    for (JobId id : jobsMap.keySet()) {
        String jobId = MRApps.toString(id);
        ClientResponse response = r.path("ws").path("v1").path("history").path("mapreduce").path("jobs").path(jobId).path("counters/").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject json = response.getEntity(JSONObject.class);
        assertEquals("incorrect number of elements", 1, json.length());
        JSONObject info = json.getJSONObject("jobCounters");
        WebServicesTestUtils.checkStringMatch("id", MRApps.toString(id), info.getString("id"));
        assertTrue("Job shouldn't contain any counters", info.length() == 1);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Configuration(org.apache.hadoop.conf.Configuration) MockHistoryContext(org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext) AppContext(org.apache.hadoop.mapreduce.v2.app.AppContext) MockHistoryContext(org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext) HistoryContext(org.apache.hadoop.mapreduce.v2.hs.HistoryContext) WebResource(com.sun.jersey.api.client.WebResource) ServletModule(com.google.inject.servlet.ServletModule) JSONObject(org.codehaus.jettison.json.JSONObject) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) JobId(org.apache.hadoop.mapreduce.v2.api.records.JobId) WebApp(org.apache.hadoop.yarn.webapp.WebApp) Test(org.junit.Test)

Example 2 with ServletModule

use of com.google.inject.servlet.ServletModule in project hadoop by apache.

the class TestRMWithXFSFilter method createInjector.

protected void createInjector(final String headerValue, final boolean explicitlyDisabled) {
    GuiceServletConfig.setInjector(Guice.createInjector(new ServletModule() {

        @Override
        protected void configureServlets() {
            bind(JAXBContextResolver.class);
            bind(RMWebServices.class);
            bind(GenericExceptionHandler.class);
            Configuration conf = new Configuration();
            conf.setClass(YarnConfiguration.RM_SCHEDULER, FifoScheduler.class, ResourceScheduler.class);
            rm = new MockRM(conf);
            bind(ResourceManager.class).toInstance(rm);
            serve("/*").with(GuiceContainer.class);
            XFrameOptionsFilter xfsFilter = new XFrameOptionsFilter();
            Map<String, String> initParams = new HashMap<>();
            if (headerValue != null) {
                initParams.put(XFrameOptionsFilter.CUSTOM_HEADER_PARAM, headerValue);
            }
            if (explicitlyDisabled) {
                initParams.put("xframe-options-enabled", "false");
            }
            filter("/*").through(xfsFilter, initParams);
        }
    }));
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) MockRM(org.apache.hadoop.yarn.server.resourcemanager.MockRM) XFrameOptionsFilter(org.apache.hadoop.security.http.XFrameOptionsFilter) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) ServletModule(com.google.inject.servlet.ServletModule)

Example 3 with ServletModule

use of com.google.inject.servlet.ServletModule in project roboguice by roboguice.

the class GuiceObjectFactory method createInjector.

private void createInjector() {
    try {
        logger.info("Creating injector...");
        this.injector = Guice.createInjector(new AbstractModule() {

            protected void configure() {
                // Install default servlet bindings.
                install(new ServletModule());
                // Install user's module.
                if (module != null) {
                    logger.info("Installing " + module + "...");
                    install(module);
                } else {
                    logger.info("No module found. Set 'guice.module' to a Module " + "class name if you'd like to use one.");
                }
                // can validate them at startup.
                for (Class<?> boundClass : boundClasses) {
                    // TODO: Set source from Struts XML.
                    bind(boundClass);
                }
                // Validate the interceptor class.
                for (ProvidedInterceptor interceptor : interceptors) {
                    interceptor.validate(binder());
                }
            }
        });
        // Inject interceptors.
        for (ProvidedInterceptor interceptor : interceptors) {
            interceptor.inject();
        }
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(1);
    }
    logger.info("Injector created successfully.");
}
Also used : ServletModule(com.google.inject.servlet.ServletModule) AbstractModule(com.google.inject.AbstractModule)

Example 4 with ServletModule

use of com.google.inject.servlet.ServletModule in project guice by google.

the class GuiceObjectFactory method createInjector.

private void createInjector() {
    try {
        logger.info("Creating injector...");
        this.injector = Guice.createInjector(new AbstractModule() {

            @Override
            protected void configure() {
                // Install default servlet bindings.
                install(new ServletModule());
                // Install user's module.
                if (module != null) {
                    logger.info("Installing " + module + "...");
                    install(module);
                } else {
                    logger.info("No module found. Set 'guice.module' to a Module " + "class name if you'd like to use one.");
                }
                // can validate them at startup.
                for (Class<?> boundClass : boundClasses) {
                    // TODO: Set source from Struts XML.
                    bind(boundClass);
                }
                // Validate the interceptor class.
                for (ProvidedInterceptor interceptor : interceptors) {
                    interceptor.validate(binder());
                }
            }
        });
        // Inject interceptors.
        for (ProvidedInterceptor interceptor : interceptors) {
            interceptor.inject();
        }
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(1);
    }
    logger.info("Injector created successfully.");
}
Also used : ServletModule(com.google.inject.servlet.ServletModule) AbstractModule(com.google.inject.AbstractModule)

Example 5 with ServletModule

use of com.google.inject.servlet.ServletModule in project ninja by ninjaframework.

the class NinjaServletBootstrap method configure.

@Override
protected void configure() throws Exception {
    super.configure();
    // Context for servlet requests
    addModule(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Context.class).to(NinjaServletContext.class);
        }
    });
    // Load servlet module. By convention this is a ServletModule where
    // the user can register other servlets and servlet filters
    // If the file does not exist we simply load the default servlet
    String servletModuleClassName = ninjaBaseDirectoryResolver.resolveApplicationClassName(APPLICATION_GUICE_SERVLET_MODULE_CONVENTION_LOCATION);
    if (SwissKnife.doesClassExist(servletModuleClassName, this)) {
        Class<?> servletModuleClass = Class.forName(servletModuleClassName);
        ServletModule servletModule = (ServletModule) servletModuleClass.getConstructor().newInstance();
        addModule(servletModule);
    } else {
        // The servlet Module does not exist => we load the default one.
        ServletModule servletModule = new ServletModule() {

            @Override
            protected void configureServlets() {
                bind(NinjaServletDispatcher.class).asEagerSingleton();
                serve("/*").with(NinjaServletDispatcher.class);
            }
        };
        addModule(servletModule);
    }
}
Also used : ServletModule(com.google.inject.servlet.ServletModule) AbstractModule(com.google.inject.AbstractModule)

Aggregations

ServletModule (com.google.inject.servlet.ServletModule)7 AbstractModule (com.google.inject.AbstractModule)3 Injector (com.google.inject.Injector)2 HashMap (java.util.HashMap)2 Configuration (org.apache.hadoop.conf.Configuration)2 RealtimeSystemModule (com.ning.metrics.meteo.binder.RealtimeSystemModule)1 JettyServer (com.ning.metrics.meteo.server.JettyServer)1 SubscribersCompiler (com.ning.metrics.meteo.subscribers.SubscribersCompiler)1 JerseyGuiceModule (com.squarespace.jersey2.guice.JerseyGuiceModule)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 GuiceContainer (com.sun.jersey.guice.spi.container.servlet.GuiceContainer)1 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)1 AppContext (org.apache.hadoop.mapreduce.v2.app.AppContext)1 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)1 HistoryContext (org.apache.hadoop.mapreduce.v2.hs.HistoryContext)1 MockHistoryContext (org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext)1 XFrameOptionsFilter (org.apache.hadoop.security.http.XFrameOptionsFilter)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)1