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.proto.ReefServiceProtos;
024import org.apache.reef.runtime.common.REEFEnvironment;
025import org.apache.reef.runtime.yarn.client.unmanaged.UnmanagedAmYarnClientConfiguration;
026import org.apache.reef.runtime.yarn.client.unmanaged.UnmanagedAmYarnDriverConfiguration;
027import org.apache.reef.tang.Configuration;
028import org.apache.reef.tang.exceptions.InjectionException;
029import org.apache.reef.util.EnvironmentUtils;
030import org.apache.reef.util.ThreadLogger;
031
032import java.util.logging.Level;
033import java.util.logging.Logger;
034
035/**
036 * The Client for running HelloREEF on YARN in unmanaged AM mode.
037 */
038public final class HelloREEFYarnUnmanagedAM {
039
040  private static final Logger LOG = Logger.getLogger(HelloREEFYarnUnmanagedAM.class.getName());
041
042  private static final String DRIVER_ROOT_PATH = ".";
043  private static final String JAR_PATH = EnvironmentUtils.getClassLocation(HelloREEFYarnUnmanagedAM.class);
044
045  private static final Configuration RUNTIME_CONFIG = UnmanagedAmYarnClientConfiguration.CONF
046      .set(UnmanagedAmYarnClientConfiguration.ROOT_FOLDER, DRIVER_ROOT_PATH)
047      .build();
048
049  private static final Configuration DRIVER_CONFIG = DriverConfiguration.CONF
050      .set(DriverConfiguration.GLOBAL_LIBRARIES, JAR_PATH)
051      .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloReef_UnmanagedAm")
052      .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
053      .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class)
054      .build();
055
056  /**
057   * Start Hello REEF job with Unmanaged Driver running locally in the same process.
058   * @param args command line parameters. Not used.
059   * @throws InjectionException configuration error.
060   */
061  public static void main(final String[] args) throws InjectionException {
062
063    LOG.log(Level.FINE, "Launching Unmanaged AM: {0}", JAR_PATH);
064
065    try (final DriverLauncher client = DriverLauncher.getLauncher(RUNTIME_CONFIG)) {
066
067      final String appId = client.submit(DRIVER_CONFIG, 10000);
068      LOG.log(Level.INFO, "Job submitted: {0}", appId);
069
070      final Configuration yarnAmConfig = UnmanagedAmYarnDriverConfiguration.CONF
071          .set(UnmanagedAmYarnDriverConfiguration.JOB_IDENTIFIER, appId)
072          .set(UnmanagedAmYarnDriverConfiguration.JOB_SUBMISSION_DIRECTORY, DRIVER_ROOT_PATH)
073          .build();
074
075      try (final REEFEnvironment reef = REEFEnvironment.fromConfiguration(yarnAmConfig, DRIVER_CONFIG)) {
076        reef.run();
077        final ReefServiceProtos.JobStatusProto status = reef.getLastStatus();
078        LOG.log(Level.INFO, "REEF job {0} completed: state {1}", new Object[] {appId, status.getState()});
079      }
080    }
081
082    ThreadLogger.logThreads(LOG, Level.FINEST, "Threads running after DriverLauncher.close():");
083    System.exit(0); // TODO[REEF-1715]: Should be able to exit cleanly at the end of main()
084  }
085
086  /** Empty private constructor to prohibit instantiation of utility class. */
087  private HelloREEFYarnUnmanagedAM() { }
088}