use of io.cdap.cdap.app.guice.ClusterMode in project cdap by caskdata.
the class AbstractProgramTwillRunnable method doInitialize.
/**
* Prepares this instance to execute a program.
*
* @param programOptionFile a json file containing the serialized {@link ProgramOptions}
* @throws Exception if failed to initialize
*/
private void doInitialize(File programOptionFile) throws Exception {
controllerFuture = new CompletableFuture<>();
programCompletion = new CompletableFuture<>();
// Setup process wide settings
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
System.setSecurityManager(new ProgramContainerSecurityManager(System.getSecurityManager()));
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
// Create the ProgramOptions
programOptions = createProgramOptions(programOptionFile);
programRunId = programOptions.getProgramId().run(ProgramRunners.getRunId(programOptions));
Arguments systemArgs = programOptions.getArguments();
LoggingContextAccessor.setLoggingContext(LoggingContextHelper.getLoggingContextWithRunId(programRunId, systemArgs.asMap()));
ClusterMode clusterMode = ProgramRunners.getClusterMode(programOptions);
// Loads configurations
Configuration hConf = new Configuration();
if (clusterMode == ClusterMode.ON_PREMISE) {
hConf.clear();
hConf.addResource(new File(systemArgs.getOption(ProgramOptionConstants.HADOOP_CONF_FILE)).toURI().toURL());
}
UserGroupInformation.setConfiguration(hConf);
CConfiguration cConf = CConfiguration.create();
cConf.clear();
cConf.addResource(new File(systemArgs.getOption(ProgramOptionConstants.CDAP_CONF_FILE)).toURI().toURL());
maxStopSeconds = cConf.getLong(io.cdap.cdap.common.conf.Constants.AppFabric.PROGRAM_MAX_STOP_SECONDS);
Injector injector = Guice.createInjector(createModule(cConf, hConf, programOptions, programRunId));
// Initialize log appender
logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
logAppenderInitializer.initialize();
SystemArguments.setLogLevel(programOptions.getUserArguments(), logAppenderInitializer);
// Setup the proxy selector for in active monitoring mode
oldProxySelector = ProxySelector.getDefault();
if (clusterMode == ClusterMode.ISOLATED) {
RuntimeMonitors.setupMonitoring(injector, programOptions);
}
// Create list of core services. They'll will be started in the run method and shutdown when the run
// method completed
coreServices = createCoreServices(injector, programOptions);
// Create the ProgramRunner
programRunner = createProgramRunner(injector);
// Create the Program instance
Location programJarLocation = Locations.toLocation(new File(systemArgs.getOption(ProgramOptionConstants.PROGRAM_JAR)));
ApplicationSpecification appSpec = readJsonFile(new File(systemArgs.getOption(ProgramOptionConstants.APP_SPEC_FILE)), ApplicationSpecification.class);
// Expand the program jar for creating classloader
ClassLoaderFolder classLoaderFolder = BundleJarUtil.prepareClassLoaderFolder(programJarLocation, () -> new File("expanded." + System.currentTimeMillis() + programJarLocation.getName()));
program = Programs.create(cConf, programRunner, new ProgramDescriptor(programOptions.getProgramId(), appSpec), programJarLocation, classLoaderFolder.getDir());
}
use of io.cdap.cdap.app.guice.ClusterMode in project cdap by caskdata.
the class SparkTwillRunnableModuleTest method testSpark.
@Test
public void testSpark() {
ProgramRunId programRunId = NamespaceId.DEFAULT.app("test").spark("spark").run(RunIds.generate());
for (ClusterMode mode : ClusterMode.values()) {
Module module = new SparkTwillRunnable("spark") {
@Override
protected ServiceAnnouncer getServiceAnnouncer() {
return new MockTwillContext();
}
}.createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
Injector injector = Guice.createInjector(module);
injector.getInstance(SparkProgramRunner.class);
injector.getInstance(ExploreClient.class);
Injector contextInjector = SparkRuntimeContextProvider.createInjector(CConfiguration.create(), new Configuration(), programRunId.getParent(), createProgramOptions(programRunId, mode));
contextInjector.getInstance(PluginFinder.class);
contextInjector.getInstance(ExploreClient.class);
}
}
use of io.cdap.cdap.app.guice.ClusterMode in project cdap by caskdata.
the class ProgramTwillRunnableModuleTest method testService.
@Test
public void testService() {
ProgramRunId programRunId = NamespaceId.DEFAULT.app("test").service("service").run(RunIds.generate());
for (ClusterMode mode : ClusterMode.values()) {
Module module = new ServiceTwillRunnable("service") {
@Override
protected ServiceAnnouncer getServiceAnnouncer() {
return new MockTwillContext();
}
}.createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
Injector injector = Guice.createInjector(module);
injector.getInstance(ServiceProgramRunner.class);
injector.getInstance(ExploreClient.class);
}
}
use of io.cdap.cdap.app.guice.ClusterMode in project cdap by caskdata.
the class ProgramTwillRunnableModuleTest method testWorkflow.
@Test
public void testWorkflow() {
ProgramRunId programRunId = NamespaceId.DEFAULT.app("test").workflow("workflow").run(RunIds.generate());
for (ClusterMode mode : ClusterMode.values()) {
Module module = new WorkflowTwillRunnable("workflow").createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
Injector injector = Guice.createInjector(module);
injector.getInstance(WorkflowProgramRunner.class);
// Workflow supports spark, which supports PluginFinder
injector.getInstance(PluginFinder.class);
injector.getInstance(ExploreClient.class);
}
}
use of io.cdap.cdap.app.guice.ClusterMode in project cdap by caskdata.
the class ProgramTwillRunnableModuleTest method testMapReduce.
@Test
public void testMapReduce() {
ProgramRunId programRunId = NamespaceId.DEFAULT.app("test").mr("mapreduce").run(RunIds.generate());
for (ClusterMode mode : ClusterMode.values()) {
Module module = new MapReduceTwillRunnable("mapreduce").createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
Injector injector = Guice.createInjector(module);
injector.getInstance(MapReduceProgramRunner.class);
injector.getInstance(ExploreClient.class);
}
}
Aggregations