private void fail(final String message, final Throwable throwable) { this.errorHandler.onNext(new Exception(message, throwable)); }
/** * Loads the client and resource manager configuration files from disk. */ private Configuration getClockConfiguration() { return Configurations.merge(readConfigurationFromDisk(), getStaticClockConfiguration()); }
@Override public final synchronized void uncaughtException(final Thread thread, final Throwable throwable) { final String msg = "Thread " + thread.getName() + " threw an uncaught exception."; LOG.log(Level.SEVERE, msg, throwable); this.errorHandler.onNext(new Exception(msg, throwable)); try { this.wait(100); // TODO: Remove } catch (final InterruptedException e) { } this.errorHandler.close(); LOG.log(Level.SEVERE, "System.exit(1)"); System.exit(1); }
/** * Assembles the command to execute the Driver in list form. */ private List<String> getCommandList( final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto) { return new JavaLaunchCommandBuilder() .setJavaPath("%JAVA_HOME%/bin/java") .setErrorHandlerRID(jobSubmissionProto.getRemoteId()) .setLaunchID(jobSubmissionProto.getIdentifier()) .setConfigurationFileName(this.filenames.getDriverConfigurationPath()) .setClassPath(this.classpath.getDriverClasspath()) .setMemory(jobSubmissionProto.getDriverMemory()) .setStandardErr(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getDriverStderrFileName()) .setStandardOut(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getDriverStdoutFileName()) .build(); }
switch (resourceLaunchProto.getType()) { case JVM: commandBuilder = new JavaLaunchCommandBuilder() .setClassPath(this.classpath.getEvaluatorClasspath()); break; case CLR: commandBuilder = new CLRLaunchCommandBuilder(); break; default: .setErrorHandlerRID(resourceLaunchProto.getRemoteId()) .setLaunchID(resourceLaunchProto.getIdentifier()) .setConfigurationFileName(this.filenames.getEvaluatorConfigurationPath()) .setMemory((int) (this.jvmHeapFactor * container.getResource().getMemory())) .setStandardErr(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getEvaluatorStderrFileName()) .setStandardOut(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getEvaluatorStdoutFileName()) .build();
this.configurationSerializer.toFile(driverConfiguration, runtimeConfigurationFile); final List<String> command = new JavaLaunchCommandBuilder() .setErrorHandlerRID(t.getRemoteId()) .setLaunchID(t.getIdentifier()) .setConfigurationFileName(this.filenames.getDriverConfigurationPath()) .setClassPath(this.classpath.getDriverClasspath()) .setMemory(DRIVER_MEMORY) .build();
/** * Starts the Clock. * This blocks until the clock returns. */ @Override public void run() { LOG.entering(this.getClass().getName(), "run", "Starting the clock"); try { this.getClock().run(); } catch (final Throwable t) { fail("Fatal exception while executing the clock", t); } LOG.exiting(this.getClass().getName(), "run", "Clock terminated"); }
/** * Instantiates the clock. * * @return a clock object. */ private Clock getClock() { try { final Injector clockInjector = Tang.Factory.getTang().newInjector(this.getClockConfiguration()); if (isProfilingEnabled) { clockInjector.bindAspect(profiler); } clockInjector.bindVolatileInstance(RemoteManager.class, this.remoteManager); return clockInjector.getInstance(Clock.class); } catch (final Throwable ex) { fail("Unable to instantiate the clock", ex); throw new RuntimeException("Unable to instantiate the clock", ex); } }
add(DEFAULT_JAVA_PATH); } else { add(javaPath); add("-XX:PermSize=128m"); add("-XX:MaxPermSize=128m"); add("-Xmx" + megaBytes + "m"); add("-ea"); add("-classpath"); add(classPath); add(Launcher.class.getName()); add("-" + ErrorHandlerRID.SHORT_NAME); add(errorHandlerRID); add("-" + LaunchID.SHORT_NAME); add(launchID); add("-" + ClockConfigurationPath.SHORT_NAME); add(evaluatorConfigurationPath); add("1>"); add(stdoutPath); add("2>"); add(stderrPath);
/** * Closes the remote manager managed by this class. * * @throws Exception */ @Override public void close() throws Exception { LOG.entering(this.getClass().getName(), "close"); this.errorHandler.close(); // Also closes the remoteManager LOG.exiting(this.getClass().getName(), "close"); }
private Configuration readConfigurationFromDisk() { LOG.log(Level.FINEST, "Loading configuration file: {0}", this.evaluatorConfigurationPath); final File evaluatorConfigFile = new File(this.evaluatorConfigurationPath); if (!evaluatorConfigFile.exists()) { final String message = "The configuration file " + this.evaluatorConfigurationPath + "doesn't exist. This points to an issue in the job submission."; fail(message, new FileNotFoundException()); throw new RuntimeException(message); } else if (!evaluatorConfigFile.canRead()) { final String message = "The configuration file " + this.evaluatorConfigurationPath + " exists, but can't be read"; fail(message, new IOException()); throw new RuntimeException(message); } else { try { return this.configurationSerializer.fromFile(evaluatorConfigFile); } catch (final IOException e) { final String message = "Unable to parse the configuration file " + this.evaluatorConfigurationPath; fail(message, e); throw new RuntimeException(message, e); } } }
@Inject LaunchClass(final RemoteManager remoteManager, final REEFUncaughtExceptionHandler uncaughtExceptionHandler, final REEFErrorHandler errorHandler, final @Parameter(LaunchID.class) String launchID, final @Parameter(ErrorHandlerRID.class) String errorHandlerID, final @Parameter(ClockConfigurationPath.class) String evaluatorConfigurationPath, final @Parameter(ProfilingEnabled.class) boolean enableProfiling, final ConfigurationSerializer configurationSerializer) { this.remoteManager = remoteManager; this.launchID = launchID; this.errorHandlerID = errorHandlerID; this.evaluatorConfigurationPath = evaluatorConfigurationPath; this.isProfilingEnabled = enableProfiling; this.errorHandler = errorHandler; this.configurationSerializer = configurationSerializer; // Registering a default exception handler. It sends every exception to the upstream RemoteManager Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler); if (isProfilingEnabled) { this.profiler = new WakeProfiler(); ProfilingStopHandler.setProfiler(profiler); // TODO: This probably should be bound via Tang. } }
lc.run(); LOG.log(Level.FINE, "Launcher exiting"); } catch (final Throwable throwable) {
final List<String> launchCommand = new JavaLaunchCommandBuilder() .setErrorHandlerRID(jobSubmissionProto.getRemoteId()) .setLaunchID(jobSubmissionProto.getIdentifier()) .setConfigurationFileName(this.filenames.getDriverConfigurationPath()) .setClassPath(this.classpath.getDriverClasspath()) .setMemory(amMemory) .setStandardOut(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getDriverStdoutFileName()) .setStandardErr(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getDriverStderrFileName()) .build();
switch (launchRequest.getType()) { case JVM: commandBuilder = new JavaLaunchCommandBuilder() .setClassPath(this.classpathProvider.getEvaluatorClasspath()); break; case CLR: commandBuilder = new CLRLaunchCommandBuilder(); break; default: .setErrorHandlerRID(this.remoteManager.getMyIdentifier()) .setLaunchID(c.getNodeID()) .setConfigurationFileName(this.fileNames.getEvaluatorConfigurationPath()) .setMemory((int) (this.jvmHeapFactor * c.getMemory())) .build();