Search in sources :

Example 1 with Binder

use of com.google.inject.Binder 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)

Example 2 with Binder

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

the class TestRMWebAppFairScheduler method testFairSchedulerWebAppPage.

@Test
public void testFairSchedulerWebAppPage() {
    List<RMAppState> appStates = Arrays.asList(RMAppState.NEW, RMAppState.NEW_SAVING, RMAppState.SUBMITTED);
    final RMContext rmContext = mockRMContext(appStates);
    Injector injector = WebAppTests.createMockInjector(RMContext.class, rmContext, new Module() {

        @Override
        public void configure(Binder binder) {
            try {
                ResourceManager mockRmWithFairScheduler = mockRm(rmContext);
                binder.bind(ResourceManager.class).toInstance(mockRmWithFairScheduler);
                binder.bind(ApplicationBaseProtocol.class).toInstance(mockRmWithFairScheduler.getClientRMService());
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    });
    FairSchedulerPage fsViewInstance = injector.getInstance(FairSchedulerPage.class);
    fsViewInstance.render();
    WebAppTests.flushOutput(injector);
}
Also used : RMContext(org.apache.hadoop.yarn.server.resourcemanager.RMContext) Binder(com.google.inject.Binder) RMAppState(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState) Injector(com.google.inject.Injector) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) IOException(java.io.IOException) Module(com.google.inject.Module) Test(org.junit.Test)

Example 3 with Binder

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

the class TestRMWebAppFairScheduler method testFairSchedulerWebAppPageInInconsistentState.

/**
   *  Testing inconsistent state between AbstractYarnScheduler#applications and
   *  RMContext#applications
   */
@Test
public void testFairSchedulerWebAppPageInInconsistentState() {
    List<RMAppState> appStates = Arrays.asList(RMAppState.NEW, RMAppState.NEW_SAVING, RMAppState.SUBMITTED, RMAppState.RUNNING, RMAppState.FINAL_SAVING, RMAppState.ACCEPTED, RMAppState.FINISHED);
    final RMContext rmContext = mockRMContext(appStates);
    Injector injector = WebAppTests.createMockInjector(RMContext.class, rmContext, new Module() {

        @Override
        public void configure(Binder binder) {
            try {
                ResourceManager mockRmWithFairScheduler = mockRmWithApps(rmContext);
                binder.bind(ResourceManager.class).toInstance(mockRmWithFairScheduler);
                binder.bind(ApplicationBaseProtocol.class).toInstance(mockRmWithFairScheduler.getClientRMService());
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    });
    FairSchedulerPage fsViewInstance = injector.getInstance(FairSchedulerPage.class);
    try {
        fsViewInstance.render();
    } catch (Exception e) {
        Assert.fail("Failed to render FairSchedulerPage: " + StringUtils.stringifyException(e));
    }
    WebAppTests.flushOutput(injector);
}
Also used : RMContext(org.apache.hadoop.yarn.server.resourcemanager.RMContext) Binder(com.google.inject.Binder) RMAppState(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState) Injector(com.google.inject.Injector) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) IOException(java.io.IOException) Module(com.google.inject.Module) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with Binder

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

the class TestAppPage method testAppBlockRenderWithNullCurrentAppAttempt.

@Test
public void testAppBlockRenderWithNullCurrentAppAttempt() throws Exception {
    final ApplicationId APP_ID = ApplicationId.newInstance(1234L, 0);
    Injector injector;
    // init app
    RMApp app = mock(RMApp.class);
    when(app.getTrackingUrl()).thenReturn("http://host:123");
    when(app.getState()).thenReturn(RMAppState.FAILED);
    when(app.getApplicationId()).thenReturn(APP_ID);
    when(app.getApplicationType()).thenReturn("Type");
    when(app.getUser()).thenReturn("user");
    when(app.getName()).thenReturn("Name");
    when(app.getQueue()).thenReturn("queue");
    when(app.getDiagnostics()).thenReturn(new StringBuilder());
    when(app.getFinalApplicationStatus()).thenReturn(FinalApplicationStatus.FAILED);
    when(app.getFinalApplicationStatus()).thenReturn(FinalApplicationStatus.FAILED);
    when(app.getStartTime()).thenReturn(0L);
    when(app.getFinishTime()).thenReturn(0L);
    when(app.createApplicationState()).thenReturn(YarnApplicationState.FAILED);
    RMAppMetrics appMetrics = new RMAppMetrics(Resource.newInstance(0, 0), 0, 0, 0, 0, 0, 0);
    when(app.getRMAppMetrics()).thenReturn(appMetrics);
    // initialize RM Context, and create RMApp, without creating RMAppAttempt
    final RMContext rmContext = TestRMWebApp.mockRMContext(15, 1, 2, 8);
    rmContext.getRMApps().put(APP_ID, app);
    injector = WebAppTests.createMockInjector(RMContext.class, rmContext, new Module() {

        @Override
        public void configure(Binder binder) {
            try {
                ResourceManager rm = TestRMWebApp.mockRm(rmContext);
                binder.bind(ResourceManager.class).toInstance(rm);
                binder.bind(ApplicationBaseProtocol.class).toInstance(rm.getClientRMService());
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    });
    AppBlock instance = injector.getInstance(AppBlock.class);
    instance.set(YarnWebParams.APPLICATION_ID, APP_ID.toString());
    instance.render();
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) RMContext(org.apache.hadoop.yarn.server.resourcemanager.RMContext) ApplicationBaseProtocol(org.apache.hadoop.yarn.api.ApplicationBaseProtocol) RMAppMetrics(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppMetrics) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) IOException(java.io.IOException) Binder(com.google.inject.Binder) AppBlock(org.apache.hadoop.yarn.server.webapp.AppBlock) Injector(com.google.inject.Injector) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Module(com.google.inject.Module) Test(org.junit.Test)

Example 5 with Binder

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

the class TestNodesPage method setUp.

@Before
public void setUp() throws Exception {
    final RMContext mockRMContext = TestRMWebApp.mockRMContext(3, numberOfRacks, numberOfNodesPerRack, 8 * TestRMWebApp.GiB);
    injector = WebAppTests.createMockInjector(RMContext.class, mockRMContext, new Module() {

        @Override
        public void configure(Binder binder) {
            try {
                binder.bind(ResourceManager.class).toInstance(TestRMWebApp.mockRm(mockRMContext));
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    });
}
Also used : RMContext(org.apache.hadoop.yarn.server.resourcemanager.RMContext) Binder(com.google.inject.Binder) ResourceManager(org.apache.hadoop.yarn.server.resourcemanager.ResourceManager) IOException(java.io.IOException) Module(com.google.inject.Module) Before(org.junit.Before)

Aggregations

Binder (com.google.inject.Binder)67 Module (com.google.inject.Module)64 Injector (com.google.inject.Injector)49 Test (org.junit.Test)40 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 Self (io.druid.guice.annotations.Self)12 DruidNode (io.druid.server.DruidNode)12 IOException (java.io.IOException)10 TypeLiteral (com.google.inject.TypeLiteral)9 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)9 Properties (java.util.Properties)8 RMContext (org.apache.hadoop.yarn.server.resourcemanager.RMContext)7 ResourceManager (org.apache.hadoop.yarn.server.resourcemanager.ResourceManager)7 ImmutableList (com.google.common.collect.ImmutableList)5 Lifecycle (io.druid.java.util.common.lifecycle.Lifecycle)5 List (java.util.List)5 Provides (com.google.inject.Provides)4 LifecycleModule (io.druid.guice.LifecycleModule)4 HashSet (java.util.HashSet)4 AnnotationIntrospectorPair (com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair)3