This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.examples.hello;
020
021import org.apache.reef.client.DriverConfiguration;
022import org.apache.reef.client.DriverLauncher;
023import org.apache.reef.client.LauncherStatus;
024import org.apache.reef.runtime.standalone.client.StandaloneRuntimeConfiguration;
025import org.apache.reef.runtime.standalone.client.parameters.NodeListFilePath;
026import org.apache.reef.runtime.standalone.client.parameters.SshPortNum;
027import org.apache.reef.tang.Configuration;
028import org.apache.reef.tang.Injector;
029import org.apache.reef.tang.JavaConfigurationBuilder;
030import org.apache.reef.tang.Tang;
031import org.apache.reef.tang.exceptions.BindException;
032import org.apache.reef.tang.exceptions.InjectionException;
033import org.apache.reef.tang.formats.CommandLine;
034import org.apache.reef.util.EnvironmentUtils;
035
036import java.io.IOException;
037import java.util.logging.Level;
038import java.util.logging.Logger;
039
040/**
041 * The Client for Hello REEF example on standalone environment.
042 * This can be run with the command: `java -cp lang/java/reef-examples/target/reef-examples-*-SNAPSHOT-shaded.jar
043 *     org.apache.reef.examples.hello.HelloREEFStandalone -nodelist ../NodeList.txt -port 22`
044 * Here, we assume that the list of nodes is saved in the ../Nodelist.txt file, with each line containing ssh addresses
045 * (i.e. `username@147.12.0.16`), and `~/.ssh/id_dsa` is set up on your local, with `~/.ssh/authorized_keys` containing
046 * the contents of your `~/.ssh/id_dsa.pub`.
047 * The port parameter is optional.
048 */
049public final class HelloREEFStandalone {
050  private static final Logger LOG = Logger.getLogger(HelloREEFStandalone.class.getName());
051
052  /**
053   * Number of milliseconds to wait for the job to complete.
054   */
055  private static final int JOB_TIMEOUT = 10000; // 10 sec.
056
057
058  /**
059   * @return the configuration of the runtime
060   */
061  private static Configuration getRuntimeConfiguration(final String nodeListFileName, final int sshPortNum) {
062    return StandaloneRuntimeConfiguration.CONF
063        .set(StandaloneRuntimeConfiguration.NODE_LIST_FILE_PATH, nodeListFileName)
064        .set(StandaloneRuntimeConfiguration.SSH_PORT_NUM, sshPortNum)
065        .build();
066  }
067
068  /**
069   * @return the configuration of the HelloREEF driver.
070   */
071  private static Configuration getDriverConfiguration() {
072    return DriverConfiguration.CONF
073        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class))
074        .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEFStandalone")
075        .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
076        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class)
077        .build();
078  }
079
080  /**
081   * Start Hello REEF job.
082   *
083   * @param args command line parameters.
084   * @throws BindException      configuration error.
085   * @throws InjectionException configuration error.
086   */
087  public static void main(final String[] args) throws BindException, InjectionException {
088
089    final Tang tang = Tang.Factory.getTang();
090
091    final JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
092
093    try{
094      new CommandLine(cb)
095          .registerShortNameOfClass(NodeListFilePath.class)
096          .registerShortNameOfClass(SshPortNum.class)
097          .processCommandLine(args);
098    } catch(final IOException ex) {
099      LOG.log(Level.SEVERE, "Missing parameter 'nodelist' or wrong parameter input.");
100      throw new RuntimeException("Missing parameter 'nodelist' or wrong parameter input: ", ex);
101    }
102
103    final Injector injector = tang.newInjector(cb.build());
104
105    final String nodeListFilePath = injector.getNamedInstance(NodeListFilePath.class);
106    final int sshPortNum = injector.getNamedInstance(SshPortNum.class);
107
108    final Configuration runtimeConf = getRuntimeConfiguration(nodeListFilePath, sshPortNum);
109    final Configuration driverConf = getDriverConfiguration();
110
111    final LauncherStatus status = DriverLauncher
112        .getLauncher(runtimeConf)
113        .run(driverConf, JOB_TIMEOUT);
114    LOG.log(Level.INFO, "REEF job completed: {0}", status);
115  }
116
117  /**
118   * Empty private constructor to prohibit instantiation of utility class.
119   */
120  private HelloREEFStandalone() {
121  }
122}