Repository: incubator-reef Updated Branches: refs/heads/master 9b1925d16 -> fa9d49af4
[REEF-645] Remove APIs deprecated since 0.12 from reef-common: Launcher This removed deprecated classes Launcher and LaunchClass JIRA: [REEF-645](https://issues.apache.org/jira/browse/REEF-645) Pull Request: Closes #421 Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/fa9d49af Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/fa9d49af Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/fa9d49af Branch: refs/heads/master Commit: fa9d49af432aebfe0d5cfce6d9e3391e2165d801 Parents: 9b1925d Author: Mariia Mykhailova <michayl...@gmail.com> Authored: Wed Aug 26 17:23:58 2015 -0700 Committer: Markus Weimer <wei...@apache.org> Committed: Fri Aug 28 13:30:52 2015 -0700 ---------------------------------------------------------------------- .../reef/javabridge/generic/JobClient.java | 2 +- .../apache/reef/runtime/common/Launcher.java | 163 ---------------- .../reef/runtime/common/launch/LaunchClass.java | 189 ------------------- 3 files changed, 1 insertion(+), 353 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/fa9d49af/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobClient.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobClient.java b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobClient.java index 4f1a702..b1cbf25 100644 --- a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobClient.java +++ b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobClient.java @@ -263,7 +263,7 @@ public class JobClient { } /** - * Wait for the job driver to complete. This method is called from Launcher.main() + * Wait for the job driver to complete. */ public void waitForCompletion(final int waitTime) { LOG.info("Waiting for the Job Driver to complete: " + waitTime); http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/fa9d49af/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/Launcher.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/Launcher.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/Launcher.java deleted file mode 100644 index 16477fb..0000000 --- a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/Launcher.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.reef.runtime.common; - -import org.apache.reef.runtime.common.launch.LaunchClass; -import org.apache.reef.runtime.common.launch.REEFErrorHandler; -import org.apache.reef.runtime.common.launch.REEFMessageCodec; -import org.apache.reef.runtime.common.launch.parameters.ClockConfigurationPath; -import org.apache.reef.runtime.common.launch.parameters.ErrorHandlerRID; -import org.apache.reef.runtime.common.launch.parameters.LaunchID; -import org.apache.reef.tang.Configuration; -import org.apache.reef.tang.Injector; -import org.apache.reef.tang.JavaConfigurationBuilder; -import org.apache.reef.tang.Tang; -import org.apache.reef.tang.exceptions.BindException; -import org.apache.reef.tang.exceptions.InjectionException; -import org.apache.reef.tang.formats.CommandLine; -import org.apache.reef.util.EnvironmentUtils; -import org.apache.reef.util.ThreadLogger; -import org.apache.reef.util.logging.LoggingSetup; -import org.apache.reef.wake.remote.RemoteConfiguration; - -import java.io.IOException; -import java.util.Collection; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * The main entrance point into any REEF process. It is mostly instantiating LaunchClass and calling .run() on it. - * @deprecated in 0.12.0. Please use REEFLauncher, which reads ErrorHandlerRID and LaunchID from the \ - * configuration file rather than from the command line arguments. - */ -@Deprecated -public final class Launcher { - - private static final Logger LOG = Logger.getLogger(Launcher.class.getName()); - - static { - LoggingSetup.setupCommonsLogging(); - } - - private Launcher() { - } - - /** - * Parse command line options of the launcher. - * - * @param args Command line as passed into main(). - * @return TANG configuration object. - */ - private static Configuration processCommandLine( - final String[] args) throws BindException, IOException, InjectionException { - - final JavaConfigurationBuilder commandLineBuilder = - Tang.Factory.getTang().newConfigurationBuilder(); - - new CommandLine(commandLineBuilder) - .registerShortNameOfClass(ClockConfigurationPath.class) - .registerShortNameOfClass(ErrorHandlerRID.class) - .registerShortNameOfClass(LaunchID.class) - .processCommandLine(args); - - return commandLineBuilder - // Bind the wake error handler - .bindNamedParameter(RemoteConfiguration.ErrorHandler.class, REEFErrorHandler.class) - .bindNamedParameter(RemoteConfiguration.ManagerName.class, "REEF_LAUNCHER") - // Bind the wake codec - .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class) - .build(); - } - - private static void fail(final String msg, final Throwable t) { - LOG.log(Level.SEVERE, msg, t); - throw new RuntimeException(msg, t); - } - - - /** - * Launches a REEF client process (Driver or Evaluator). - * - * @param args - * @throws Exception - */ - public static void main(final String[] args) { - LOG.log(Level.WARNING, "Launcher is deprecated in REEF 0.12.0. Please use REEFLauncher, " + - "which reads ErrorHandlerRID and LaunchID from the " + - "configuration file rather than from the command line arguments"); - - LOG.log(Level.FINE, "Launcher started with user name [{0}]", System.getProperty("user.name")); - - LOG.log(Level.FINE, "Launcher started. Assertions are {0} in this process.", - EnvironmentUtils.areAssertionsEnabled() ? "ENABLED" : "DISABLED"); - Injector injector = null; - try { - injector = Tang.Factory.getTang().newInjector(processCommandLine(args)); - } catch (final BindException | IOException | InjectionException e) { - fail("Error in parsing the command line", e); - } - - try (final LaunchClass lc = injector.getInstance(LaunchClass.class)) { - LOG.log(Level.FINE, "Launcher starting"); - lc.run(); - LOG.log(Level.FINE, "Launcher exiting"); - } catch (final Throwable throwable) { - fail("Unable to run LaunchClass", throwable); - } - - LOG.log(Level.INFO, "Exiting Launcher.main()"); - if (LOG.isLoggable(Level.FINEST)) { - LOG.log(Level.FINEST, ThreadLogger.getFormattedThreadList("Threads running after Launcher.close():")); - } - System.exit(0); - if (LOG.isLoggable(Level.FINEST)) { - LOG.log(Level.FINEST, ThreadLogger.getFormattedThreadList("Threads running after System.exit():")); - } - } - - /** - * Pass values of the properties specified in the propNames array as <code>-D...</code> - * command line parameters. Currently used only to pass logging configuration to child JVMs processes. - * - * @param vargs List of command line parameters to append to. - * @param copyNull create an empty parameter if the property is missing in current process. - * @param propNames property names. - */ - public static void propagateProperties( - final Collection<String> vargs, final boolean copyNull, final String... propNames) { - for (final String propName : propNames) { - final String propValue = System.getProperty(propName); - if (propValue == null || propValue.isEmpty()) { - if (copyNull) { - vargs.add("-D" + propName); - } - } else { - vargs.add(String.format("-D%s=%s", propName, propValue)); - } - } - } - - /** - * Same as above, but with copyNull == false by default. - */ - public static void propagateProperties( - final Collection<String> vargs, final String... propNames) { - propagateProperties(vargs, false, propNames); - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/fa9d49af/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchClass.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchClass.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchClass.java deleted file mode 100644 index 240a531..0000000 --- a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchClass.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.reef.runtime.common.launch; - -import org.apache.reef.runtime.common.evaluator.PIDStoreStartHandler; -import org.apache.reef.runtime.common.launch.parameters.ClockConfigurationPath; -import org.apache.reef.runtime.common.launch.parameters.ErrorHandlerRID; -import org.apache.reef.runtime.common.launch.parameters.LaunchID; -import org.apache.reef.tang.*; -import org.apache.reef.tang.annotations.Name; -import org.apache.reef.tang.annotations.NamedParameter; -import org.apache.reef.tang.annotations.Parameter; -import org.apache.reef.tang.formats.ConfigurationSerializer; -import org.apache.reef.util.REEFVersion; -import org.apache.reef.wake.profiler.WakeProfiler; -import org.apache.reef.wake.remote.RemoteConfiguration; -import org.apache.reef.wake.time.Clock; - -import javax.inject.Inject; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * This encapsulates processes started by REEF. - * @deprecated in 0.12.0. This class is exclusively used by the deprecated Launcher. - */ -@Deprecated -public final class LaunchClass implements AutoCloseable, Runnable { - - private static final Logger LOG = Logger.getLogger(LaunchClass.class.getName()); - private final String launchID; - private final String errorHandlerID; - private final String evaluatorConfigurationPath; - private final boolean isProfilingEnabled; - private final REEFErrorHandler errorHandler; - private final ConfigurationSerializer configurationSerializer; - private WakeProfiler profiler; - - @Inject - LaunchClass(final REEFUncaughtExceptionHandler uncaughtExceptionHandler, - final REEFErrorHandler errorHandler, - @Parameter(LaunchID.class) final String launchID, - @Parameter(ErrorHandlerRID.class) final String errorHandlerID, - @Parameter(ClockConfigurationPath.class) final String evaluatorConfigurationPath, - @Parameter(ProfilingEnabled.class) final boolean enableProfiling, - final ConfigurationSerializer configurationSerializer, - final REEFVersion reefVersion) { - reefVersion.logVersion(); - 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. - } - LOG.log(Level.FINE, "Instantiated LaunchClass"); - } - - /** - * Loads the client and resource manager configuration files from disk. - */ - private Configuration getClockConfiguration() { - return Configurations.merge(readConfigurationFromDisk(), getStaticClockConfiguration()); - } - - - 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); - } - } - } - - /** - * @return the part of the clock configuration *not* read from disk. - */ - private Configuration getStaticClockConfiguration() { - final JavaConfigurationBuilder builder = Tang.Factory.getTang().newConfigurationBuilder() - .bindNamedParameter(LaunchID.class, this.launchID) - .bindNamedParameter(ErrorHandlerRID.class, this.errorHandlerID) - .bindSetEntry(Clock.StartHandler.class, PIDStoreStartHandler.class) - .bindNamedParameter(RemoteConfiguration.ErrorHandler.class, REEFErrorHandler.class) - .bindNamedParameter(RemoteConfiguration.ManagerName.class, "REEF_LAUNCHER") - .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class); - if (this.isProfilingEnabled) { - builder.bindSetEntry(Clock.StopHandler.class, ProfilingStopHandler.class); - } - return builder.build(); - } - - /** - * 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); - } - 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); - } - } - - /** - * 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"); - } - - /** - * 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 void fail(final String message, final Throwable throwable) { - this.errorHandler.onNext(new Exception(message, throwable)); - } - - @NamedParameter(doc = "If true, profiling will be enabled", short_name = "profiling", default_value = "false") - public static final class ProfilingEnabled implements Name<Boolean> { - } -}