@Override protected void configure() { LOGGER.debug("Configuring guice"); bind(MyriadConfiguration.class).toInstance(cfg); bind(Configuration.class).toInstance(hadoopConf); bind(RMContext.class).toInstance(rmContext); bind(AbstractYarnScheduler.class).toInstance(yarnScheduler); bind(InterceptorRegistry.class).toInstance(interceptorRegistry); bind(MyriadDriverManager.class).in(Scopes.SINGLETON); bind(org.apache.myriad.scheduler.MyriadScheduler.class).in(Scopes.SINGLETON); bind(ServiceProfileManager.class).in(Scopes.SINGLETON); bind(DisruptorManager.class).in(Scopes.SINGLETON); bind(ReconcileService.class).in(Scopes.SINGLETON); bind(HttpConnectorProvider.class).in(Scopes.SINGLETON); bind(MyriadWebServer.class).in(Scopes.SINGLETON); // add special binding between TaskFactory and NMTaskFactory to ease up // usage of TaskFactory bind(TaskFactory.class).annotatedWith(NMTaskFactoryAnnotation.class).to(NMTaskFactory.class); bind(YarnNodeCapacityManager.class).in(Scopes.SINGLETON); bind(NodeStore.class).in(Scopes.SINGLETON); bind(OfferLifecycleManager.class).in(Scopes.SINGLETON); bind(NMHeartBeatHandler.class).asEagerSingleton(); MapBinder<String, TaskFactory> mapBinder = MapBinder.newMapBinder(binder(), String.class, TaskFactory.class); mapBinder .addBinding(NodeManagerConfiguration.DEFAULT_NM_TASK_PREFIX) .to(NMTaskFactory.class) .in(Scopes.SINGLETON); Map<String, ServiceConfiguration> auxServicesConfigs = cfg.getServiceConfigurations(); for (Map.Entry<String, ServiceConfiguration> entry : auxServicesConfigs.entrySet()) { if (entry.getValue().getTaskFactoryImplName().isPresent()) { String taskFactoryClass = entry.getValue().getTaskFactoryImplName().get(); try { Class<? extends TaskFactory> implClass = getTaskFactoryClass(taskFactoryClass); mapBinder.addBinding(entry.getKey()).to(implClass).in(Scopes.SINGLETON); } catch (ClassNotFoundException e) { LOGGER.error("ClassNotFoundException", e); } } else { // TODO (hokiegeek2) Confirm if this else statement and logic should still be here mapBinder.addBinding(entry.getKey()).to(ServiceTaskFactory.class).in(Scopes.SINGLETON); } } // TODO(Santosh): Should be configurable as well bind(NodeScaleDownPolicy.class).to(LeastAMNodesFirstPolicy.class).in(Scopes.SINGLETON); }
@Provides @Singleton State providesStateStore(MyriadConfiguration cfg) { return new ZooKeeperState( cfg.getZkServers(), cfg.getZkTimeout(), TimeUnit.MILLISECONDS, "/myriad/" + cfg.getFrameworkName()); }
@Provides @Singleton SchedulerDriver providesSchedulerDriver( MyriadScheduler scheduler, MyriadConfiguration cfg, SchedulerState schedulerState) { Builder frameworkInfoBuilder = FrameworkInfo.newBuilder() .setUser("") .setName(cfg.getFrameworkName()) .setCheckpoint(cfg.isCheckpoint()) .setFailoverTimeout(cfg.getFrameworkFailoverTimeout()); if (StringUtils.isNotEmpty(cfg.getFrameworkRole())) { frameworkInfoBuilder.setRole(cfg.getFrameworkRole()); } FrameworkID frameworkId = schedulerState.getFrameworkID(); if (frameworkId != null) { LOGGER.info("Attempting to re-register with frameworkId: {}", frameworkId.getValue()); frameworkInfoBuilder.setId(frameworkId); } String mesosAuthenticationPrincipal = cfg.getMesosAuthenticationPrincipal(); String mesosAuthenticationSecretFilename = cfg.getMesosAuthenticationSecretFilename(); if (StringUtils.isNotEmpty(mesosAuthenticationPrincipal)) { frameworkInfoBuilder.setPrincipal(mesosAuthenticationPrincipal); Credential.Builder credentialBuilder = Credential.newBuilder(); credentialBuilder.setPrincipal(mesosAuthenticationPrincipal); if (StringUtils.isNotEmpty(mesosAuthenticationSecretFilename)) { try { credentialBuilder.setSecretBytes( ByteString.readFrom(new FileInputStream(mesosAuthenticationSecretFilename))); } catch (FileNotFoundException ex) { LOGGER.error("Mesos authentication secret file was not found", ex); throw new RuntimeException(ex); } catch (IOException ex) { LOGGER.error("Error reading Mesos authentication secret file", ex); throw new RuntimeException(ex); } } return new MesosSchedulerDriver( scheduler, frameworkInfoBuilder.build(), cfg.getMesosMaster(), credentialBuilder.build()); } else { return new MesosSchedulerDriver( scheduler, frameworkInfoBuilder.build(), cfg.getMesosMaster()); } }
@Provides @Singleton SchedulerState providesSchedulerState(MyriadConfiguration cfg) { LOGGER.debug("Configuring SchedulerState provider"); MyriadStateStore myriadStateStore = null; if (cfg.isHAEnabled()) { myriadStateStore = providesMyriadStateStore(); if (myriadStateStore == null) { throw new RuntimeException( "Could not find a state store" + " implementation for Myriad. The 'yarn.resourcemanager.store.class'" + " property should be set to a class implementing the" + " MyriadStateStore interface. For e.g." + " org.apache.hadoop.yarn.server.resourcemanager.recovery.MyriadFileSystemRMStateStore"); } } return new SchedulerState(myriadStateStore); }