@VisibleForTesting public static Injector createInjector(CConfiguration cConf, Configuration hConf, ProgramId programId, ProgramOptions programOptions) { String runId = programOptions.getArguments().getOption(ProgramOptionConstants.RUN_ID); List<Module> modules = new ArrayList<>(); modules.add(new DistributedProgramContainerModule(cConf, hConf, programId.run(runId), programOptions.getArguments())); ClusterMode clusterMode = ProgramRunners.getClusterMode(programOptions); modules.add(clusterMode == ClusterMode.ON_PREMISE ? new DistributedArtifactManagerModule() : new AbstractModule() { @Override protected void configure() { bind(PluginFinder.class).to(UnsupportedPluginFinder.class); } }); return Guice.createInjector(modules); }
private void addOnPremiseModules(List<Module> modules) { String instanceId = systemArgs.getOption(ProgramOptionConstants.INSTANCE_ID); modules.add(new LocationRuntimeModule().getDistributedModules()); modules.add(new KafkaClientModule()); modules.add(new LoggingModules().getDistributedModules()); modules.add(new DataFabricModules(generateClientId(programRunId, instanceId)).getDistributedModules()); modules.add(new DataSetsModules().getDistributedModules()); modules.add(new NamespaceClientRuntimeModule().getDistributedModules()); modules.add(new DistributedProgramStreamModule()); }
/** * Optionally adds {@link RuntimeMonitorServer} binding. */ private void bindRuntimeMonitorServer(Binder binder) { try { Path keyStorePath = Paths.get(Constants.RuntimeMonitor.SERVER_KEYSTORE); Path trustStorePath = Paths.get(Constants.RuntimeMonitor.CLIENT_KEYSTORE); // If there is no key store or trust store, don't add the binding. // The reason is that this module is used in all containers, but only the driver container would have the // key store files. if (!Files.isReadable(keyStorePath) || !Files.isReadable(trustStorePath)) { return; } KeyStore keyStore = loadKeyStore(keyStorePath); KeyStore trustStore = loadKeyStore(trustStorePath); binder.install(new PrivateModule() { @Override protected void configure() { bind(KeyStore.class).annotatedWith(Constants.AppFabric.KeyStore.class).toInstance(keyStore); bind(KeyStore.class).annotatedWith(Constants.AppFabric.TrustStore.class).toInstance(trustStore); bind(RuntimeMonitorServer.class); expose(RuntimeMonitorServer.class); } }); } catch (Exception e) { // Just log if failed to load the KeyStores. It will fail when RuntimeMonitorServer is needed. LOG.error("Failed to load key store and/or trust store", e); } }
@Override protected void configure() { List<Module> modules = getCoreModules(programRunId.getParent()); String principal = systemArgs.getOption(ProgramOptionConstants.PRINCIPAL); AuthenticationContextModules authModules = new AuthenticationContextModules(); modules.add(principal == null ? authModules.getProgramContainerModule() : authModules.getProgramContainerModule(principal)); install(Modules.override(modules).with(new AbstractModule() { @Override protected void configure() { // Overrides the LineageWriter, UsageWriter to write to TMS instead bind(LineageWriter.class).to(MessagingLineageWriter.class); bind(FieldLineageWriter.class).to(MessagingLineageWriter.class); bind(UsageWriter.class).to(MessagingUsageWriter.class); } })); }
addOnPremiseModules(modules); break; case ISOLATED: addIsolatedModules(modules); break; default:
@Override protected void configure() { List<Module> modules = getCoreModules(programRunId.getParent()); String principal = systemArgs.getOption(ProgramOptionConstants.PRINCIPAL); AuthenticationContextModules authModules = new AuthenticationContextModules(); modules.add(principal == null ? authModules.getProgramContainerModule() : authModules.getProgramContainerModule(principal)); install(Modules.override(modules).with(new AbstractModule() { @Override protected void configure() { // Overrides the LineageWriter, UsageWriter to write to TMS instead bind(LineageWriter.class).to(MessagingLineageWriter.class); bind(FieldLineageWriter.class).to(MessagingLineageWriter.class); bind(UsageWriter.class).to(MessagingUsageWriter.class); } })); }
addOnPremiseModules(modules); break; case ISOLATED: addIsolatedModules(modules); break; default:
@VisibleForTesting public static Injector createInjector(CConfiguration cConf, Configuration hConf, ProgramId programId, ProgramOptions programOptions) { String runId = programOptions.getArguments().getOption(ProgramOptionConstants.RUN_ID); List<Module> modules = new ArrayList<>(); modules.add(new DistributedProgramContainerModule(cConf, hConf, programId.run(runId), programOptions.getArguments())); ClusterMode clusterMode = ProgramRunners.getClusterMode(programOptions); modules.add(clusterMode == ClusterMode.ON_PREMISE ? new DistributedArtifactManagerModule() : new AbstractModule() { @Override protected void configure() { bind(PluginFinder.class).to(UnsupportedPluginFinder.class); } }); return Guice.createInjector(modules); }
private void addOnPremiseModules(List<Module> modules) { String instanceId = systemArgs.getOption(ProgramOptionConstants.INSTANCE_ID); modules.add(new DFSLocationModule()); modules.add(new KafkaClientModule()); modules.add(new KafkaLogAppenderModule()); modules.add(new DataFabricModules(generateClientId(programRunId, instanceId)).getDistributedModules()); modules.add(new DataSetsModules().getDistributedModules()); modules.add(new NamespaceQueryAdminModule()); modules.add(new AbstractModule() { @Override protected void configure() { // bind explore client to ProgramDiscoveryExploreClient which is aware of the programId bind(ExploreClient.class).to(ProgramDiscoveryExploreClient.class).in(Scopes.SINGLETON); } }); }
/** * Optionally adds {@link RuntimeMonitorServer} binding. */ private void bindRuntimeMonitorServer(Binder binder) { try { Path keyStorePath = Paths.get(Constants.RuntimeMonitor.SERVER_KEYSTORE); Path trustStorePath = Paths.get(Constants.RuntimeMonitor.CLIENT_KEYSTORE); // If there is no key store or trust store, don't add the binding. // The reason is that this module is used in all containers, but only the driver container would have the // key store files. if (!Files.isReadable(keyStorePath) || !Files.isReadable(trustStorePath)) { return; } KeyStore keyStore = loadKeyStore(keyStorePath); KeyStore trustStore = loadKeyStore(trustStorePath); binder.install(new PrivateModule() { @Override protected void configure() { bind(KeyStore.class).annotatedWith(Constants.AppFabric.KeyStore.class).toInstance(keyStore); bind(KeyStore.class).annotatedWith(Constants.AppFabric.TrustStore.class).toInstance(trustStore); bind(RuntimeMonitorServer.class); expose(RuntimeMonitorServer.class); } }); } catch (Exception e) { // Just log if failed to load the KeyStores. It will fail when RuntimeMonitorServer is needed. LOG.error("Failed to load key store and/or trust store", e); } }
@VisibleForTesting public static Injector createInjector(CConfiguration cConf, Configuration hConf, ProgramId programId, ProgramOptions programOptions) { String runId = programOptions.getArguments().getOption(ProgramOptionConstants.RUN_ID); List<Module> modules = new ArrayList<>(); modules.add(new DistributedProgramContainerModule(cConf, hConf, programId.run(runId), programOptions.getArguments())); ClusterMode clusterMode = ProgramRunners.getClusterMode(programOptions); modules.add(clusterMode == ClusterMode.ON_PREMISE ? new DistributedArtifactManagerModule() : new AbstractModule() { @Override protected void configure() { bind(PluginFinder.class).to(UnsupportedPluginFinder.class); } }); return Guice.createInjector(modules); }
private static Injector createInjector(CConfiguration cConf, Configuration hConf) { MapReduceContextConfig mapReduceContextConfig = new MapReduceContextConfig(hConf); // principal will be null if running on a kerberos distributed cluster ProgramOptions programOptions = mapReduceContextConfig.getProgramOptions(); Arguments systemArgs = programOptions.getArguments(); String runId = systemArgs.getOption(ProgramOptionConstants.RUN_ID); return Guice.createInjector( new DistributedProgramContainerModule(cConf, hConf, mapReduceContextConfig.getProgramId().run(runId), systemArgs) ); } }
private static Injector createInjector(CConfiguration cConf, Configuration hConf) { MapReduceContextConfig mapReduceContextConfig = new MapReduceContextConfig(hConf); // principal will be null if running on a kerberos distributed cluster ProgramOptions programOptions = mapReduceContextConfig.getProgramOptions(); Arguments systemArgs = programOptions.getArguments(); String runId = systemArgs.getOption(ProgramOptionConstants.RUN_ID); return Guice.createInjector( new DistributedProgramContainerModule(cConf, hConf, mapReduceContextConfig.getProgramId().run(runId), systemArgs) ); } }
/** * Creates a Guice {@link Module} that will be used to create the Guice {@link Injector} used for the * program execution. * * @param cConf the CDAP configuration * @param hConf the Hadoop configuration * @param programOptions the {@link ProgramOptions} for the program execution * @param programRunId the {@link ProgramRunId} for this program run. * @return a guice {@link Module}. */ protected Module createModule(CConfiguration cConf, Configuration hConf, ProgramOptions programOptions, ProgramRunId programRunId) { Module module = new DistributedProgramContainerModule(cConf, hConf, programRunId, programOptions.getArguments(), getServiceAnnouncer()); if (ProgramRunners.getClusterMode(programOptions) == ClusterMode.ISOLATED) { // In isolated mode, TMS runs in the "launcher" container. // We don't do this in the DistributedProgramContainerModule // because that module is used in both launcher and task containers module = Modules.override(module).with( new MessagingServerRuntimeModule().getStandaloneModules(), new AbstractModule() { @Override protected void configure() { // Bind a Cancellable for the RuntimeMonitor to stop this program run. bind(Cancellable.class).toInstance(() -> stop()); } }); } return module; }
/** * Creates a Guice {@link Module} that will be used to create the Guice {@link Injector} used for the * program execution. * * @param cConf the CDAP configuration * @param hConf the Hadoop configuration * @param programOptions the {@link ProgramOptions} for the program execution * @param programRunId the {@link ProgramRunId} for this program run. * @return a guice {@link Module}. */ protected Module createModule(CConfiguration cConf, Configuration hConf, ProgramOptions programOptions, ProgramRunId programRunId) { Module module = new DistributedProgramContainerModule(cConf, hConf, programRunId, programOptions.getArguments(), getServiceAnnouncer()); if (ProgramRunners.getClusterMode(programOptions) == ClusterMode.ISOLATED) { // In isolated mode, TMS runs in the "launcher" container. // We don't do this in the DistributedProgramContainerModule // because that module is used in both launcher and task containers module = Modules.override(module).with( new MessagingServerRuntimeModule().getStandaloneModules(), new AbstractModule() { @Override protected void configure() { // Bind a Cancellable for the RuntimeMonitor to stop this program run. bind(Cancellable.class).toInstance(() -> stop()); } }); } return module; }