Repository: incubator-reef Updated Branches: refs/heads/master b2e85d12a -> b9f38b25d
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/b9f38b25/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/Launch.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/Launch.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/Launch.java deleted file mode 100644 index 4fbe397..0000000 --- a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/Launch.java +++ /dev/null @@ -1,185 +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.examples.retained_eval; - -import org.apache.reef.client.ClientConfiguration; -import org.apache.reef.examples.library.Command; -import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration; -import org.apache.reef.runtime.yarn.client.YarnClientConfiguration; -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.annotations.Name; -import org.apache.reef.tang.annotations.NamedParameter; -import org.apache.reef.tang.exceptions.BindException; -import org.apache.reef.tang.exceptions.InjectionException; -import org.apache.reef.tang.formats.AvroConfigurationSerializer; -import org.apache.reef.tang.formats.CommandLine; - -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Retained Evaluators example - main class. - */ -public final class Launch { - - /** - * The upper limit on the number of Evaluators that the local resourcemanager will hand out concurrently - */ - private static final int MAX_NUMBER_OF_EVALUATORS = 4; - /** - * Standard Java logger - */ - private static final Logger LOG = Logger.getLogger(Launch.class.getName()); - - /** - * This class should not be instantiated. - */ - private Launch() { - throw new RuntimeException("Do not instantiate this class!"); - } - - /** - * Parse the command line arguments. - * - * @param args command line arguments, as passed to main() - * @return Configuration object. - * @throws BindException configuration error. - * @throws IOException error reading the configuration. - */ - private static Configuration parseCommandLine(final String[] args) - throws BindException, IOException { - final JavaConfigurationBuilder confBuilder = Tang.Factory.getTang().newConfigurationBuilder(); - final CommandLine cl = new CommandLine(confBuilder); - cl.registerShortNameOfClass(Local.class); - cl.registerShortNameOfClass(Command.class); - cl.registerShortNameOfClass(NumRuns.class); - cl.registerShortNameOfClass(NumEval.class); - cl.processCommandLine(args); - return confBuilder.build(); - } - - private static Configuration cloneCommandLineConfiguration(final Configuration commandLineConf) - throws InjectionException, BindException { - final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf); - final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder(); - cb.bindNamedParameter(Command.class, injector.getNamedInstance(Command.class)); - cb.bindNamedParameter(NumRuns.class, String.valueOf(injector.getNamedInstance(NumRuns.class))); - cb.bindNamedParameter(NumEval.class, String.valueOf(injector.getNamedInstance(NumEval.class))); - return cb.build(); - } - - /** - * Parse command line arguments and create TANG configuration ready to be submitted to REEF. - * - * @param args Command line arguments, as passed into main(). - * @return (immutable) TANG Configuration object. - * @throws BindException if configuration commandLineInjector fails. - * @throws InjectionException if configuration commandLineInjector fails. - * @throws IOException error reading the configuration. - */ - private static Configuration getClientConfiguration(final String[] args) - throws BindException, InjectionException, IOException { - - final Configuration commandLineConf = parseCommandLine(args); - - final Configuration clientConfiguration = ClientConfiguration.CONF - .set(ClientConfiguration.ON_JOB_RUNNING, JobClient.RunningJobHandler.class) - .set(ClientConfiguration.ON_JOB_MESSAGE, JobClient.JobMessageHandler.class) - .set(ClientConfiguration.ON_JOB_COMPLETED, JobClient.CompletedJobHandler.class) - .set(ClientConfiguration.ON_JOB_FAILED, JobClient.FailedJobHandler.class) - .set(ClientConfiguration.ON_RUNTIME_ERROR, JobClient.RuntimeErrorHandler.class) - .build(); - - // TODO: Remove the injector, have stuff injected. - final Injector commandLineInjector = Tang.Factory.getTang().newInjector(commandLineConf); - final boolean isLocal = commandLineInjector.getNamedInstance(Local.class); - final Configuration runtimeConfiguration; - if (isLocal) { - LOG.log(Level.INFO, "Running on the local runtime"); - runtimeConfiguration = LocalRuntimeConfiguration.CONF - .set(LocalRuntimeConfiguration.MAX_NUMBER_OF_EVALUATORS, MAX_NUMBER_OF_EVALUATORS) - .build(); - } else { - LOG.log(Level.INFO, "Running on YARN"); - runtimeConfiguration = YarnClientConfiguration.CONF.build(); - } - - return Tang.Factory.getTang() - .newConfigurationBuilder(runtimeConfiguration, clientConfiguration, - cloneCommandLineConfiguration(commandLineConf)) - .build(); - } - - /** - * Main method that starts the Retained Evaluators job. - * - * @return a string that contains last results from all evaluators. - */ - public static String run(final Configuration config) throws InjectionException { - final Injector injector = Tang.Factory.getTang().newInjector(config); - final JobClient client = injector.getInstance(JobClient.class); - client.submit(); - return client.waitForCompletion(); - } - - /** - * Main method that starts the Retained Evaluators job. - * - * @param args command line parameters. - */ - public static void main(final String[] args) { - try { - final Configuration config = getClientConfiguration(args); - LOG.log(Level.FINEST, "Configuration:\n--\n{0}--", - new AvroConfigurationSerializer().toString(config)); - run(config); - LOG.info("Done!"); - } catch (final BindException | InjectionException | IOException ex) { - LOG.log(Level.SEVERE, "Job configuration error", ex); - } - } - - /** - * Command line parameter: number of experiments to run. - */ - @NamedParameter(doc = "Number of times to run the command", - short_name = "num_runs", default_value = "1") - public static final class NumRuns implements Name<Integer> { - } - - /** - * Command line parameter: number of evaluators to allocate. - */ - @NamedParameter(doc = "Number of evaluators to request", - short_name = "num_eval", default_value = "1") - public static final class NumEval implements Name<Integer> { - } - - /** - * Command line parameter = true to run locally, or false to run on YARN. - */ - @NamedParameter(doc = "Whether or not to run on the local runtime", - short_name = "local", default_value = "true") - public static final class Local implements Name<Boolean> { - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/b9f38b25/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/package-info.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/package-info.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/package-info.java deleted file mode 100644 index 842b659..0000000 --- a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/package-info.java +++ /dev/null @@ -1,22 +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. - */ -/** - * The Retained Evaluators example. - */ -package org.apache.reef.examples.retained_eval; http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/b9f38b25/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerDriver.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerDriver.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerDriver.java index 890d872..4324f15 100644 --- a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerDriver.java +++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerDriver.java @@ -146,9 +146,9 @@ public final class SchedulerDriver { } /** - * Non-retainable version of CompletedTaskHandler. - * When Task completes, it closes the active context to deallocate the evaluator - * and if there is outstanding commands, allocate another evaluator. + * When a Task completes, the task is marked as finished. + * The evaluator is reused for the next Task if retainable is set to {@code true}. + * Otherwise the evaluator is released. */ final class CompletedTaskHandler implements EventHandler<CompletedTask> { @Override http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/b9f38b25/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java index 4c48159..329b29c 100644 --- a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java +++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java @@ -26,8 +26,7 @@ import org.junit.runners.Suite; */ @RunWith(Suite.class) @Suite.SuiteClasses({ - TestHelloREEF.class, - TestRetainedEvaluators.class + TestHelloREEF.class }) public final class ExamplesTestSuite { } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/b9f38b25/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestRetainedEvaluators.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestRetainedEvaluators.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestRetainedEvaluators.java deleted file mode 100644 index a563eab..0000000 --- a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestRetainedEvaluators.java +++ /dev/null @@ -1,81 +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.tests.examples; - -import org.apache.reef.examples.library.Command; -import org.apache.reef.examples.retained_eval.JobClient; -import org.apache.reef.examples.retained_eval.Launch; -import org.apache.reef.tang.Configuration; -import org.apache.reef.tang.Configurations; -import org.apache.reef.tang.Tang; -import org.apache.reef.tang.exceptions.InjectionException; -import org.apache.reef.tests.LocalTestEnvironment; -import org.apache.reef.tests.TestEnvironment; -import org.apache.reef.tests.TestEnvironmentFactory; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * An integration test for retained evaluators: Run a simple `echo` on a couple of Evaluators a few times and make sure - * it comes back. - */ -public final class TestRetainedEvaluators { - /** - * Message to print in (remote) shells. - */ - private static final String MESSAGE = "Hello REEF"; - - private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment(); - - /** - * @return the Configuration for Launch for this test. - */ - private static Configuration getLaunchConfiguration() { - return Tang.Factory.getTang().newConfigurationBuilder() - .bindNamedParameter(Launch.NumEval.class, "" + (LocalTestEnvironment.MAX_NUMBER_OF_EVALUATORS - 1)) - .bindNamedParameter(Launch.NumRuns.class, "2") - .bindNamedParameter(Command.class, "echo " + MESSAGE) - .build(); - } - - @Before - public void setUp() throws Exception { - this.testEnvironment.setUp(); - } - - @After - public void tearDown() throws Exception { - this.testEnvironment.tearDown(); - } - - @Test - public void testRetainedEvaluators() throws InjectionException { - final Configuration clientConfiguration = Configurations.merge( - JobClient.getClientConfiguration(), // The special job client. - getLaunchConfiguration(), // Specific configuration for this job - testEnvironment.getRuntimeConfiguration() // The runtime we shall use - ); - - final String result = Launch.run(clientConfiguration); - Assert.assertNotNull(result); - Assert.assertTrue(result.contains(MESSAGE)); - } -}
