Search in sources :

Example 16 with Binder

use of com.google.inject.Binder in project druid by druid-io.

the class MetadataStorageTablesConfigTest method testSerdeMetadataStorageTablesConfig.

@Test
public void testSerdeMetadataStorageTablesConfig() throws Exception {
    Injector injector = Guice.createInjector(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.install(new PropertiesModule(Arrays.asList("test.runtime.properties")));
            binder.install(new ConfigModule());
            binder.install(new DruidGuiceExtensions());
            JsonConfigProvider.bind(binder, "druid.metadata.storage.tables", MetadataStorageTablesConfig.class);
        }

        @Provides
        @LazySingleton
        public ObjectMapper jsonMapper() {
            return new DefaultObjectMapper();
        }
    });
    Properties props = injector.getInstance(Properties.class);
    MetadataStorageTablesConfig config = injector.getInstance(MetadataStorageTablesConfig.class);
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.base"), config.getBase());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.segments"), config.getSegmentsTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.rules"), config.getRulesTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.config"), config.getConfigTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.tasks"), config.getEntryTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.taskLog"), config.getLogTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.taskLock"), config.getLockTable(MetadataStorageTablesConfig.TASK_ENTRY_TYPE));
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.dataSource"), config.getDataSourceTable());
    Assert.assertEquals(props.getProperty("druid.metadata.storage.tables.supervisors"), config.getSupervisorTable());
}
Also used : Provides(com.google.inject.Provides) Properties(java.util.Properties) Binder(com.google.inject.Binder) MetadataStorageTablesConfig(io.druid.metadata.MetadataStorageTablesConfig) Injector(com.google.inject.Injector) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Module(com.google.inject.Module) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 17 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 18 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 19 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 20 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)

Aggregations

Binder (com.google.inject.Binder)72 Module (com.google.inject.Module)65 Injector (com.google.inject.Injector)51 Test (org.junit.Test)41 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 Key (com.google.inject.Key)4 Provides (com.google.inject.Provides)4 LifecycleModule (io.druid.guice.LifecycleModule)4 HashSet (java.util.HashSet)4