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.hellomultiruntime;
020
021import org.apache.reef.client.DriverConfiguration;
022import org.apache.reef.client.DriverLauncher;
023import org.apache.reef.client.LauncherStatus;
024import org.apache.reef.runtime.multi.client.MultiRuntimeConfigurationBuilder;
025import org.apache.reef.tang.Configuration;
026import org.apache.reef.tang.exceptions.BindException;
027import org.apache.reef.tang.exceptions.InjectionException;
028
029import java.util.logging.Level;
030import java.util.logging.Logger;
031
032/**
033 * The Client for running HelloREEFMulti on YARN.
034 */
035public final class HelloREEFMultiYarn {
036
037  private static final Logger LOG = Logger.getLogger(HelloREEFMultiYarn.class.getName());
038
039  /**
040   * Number of milliseconds to wait for the job to complete.
041   * Setting to 100 sec because running on RM HA clusters take around
042   * 50 seconds to set the job to running.
043   */
044  private static final int JOB_TIMEOUT = 100000; // 100 sec.
045
046  /**
047   * @return the configuration of the HelloREEF driver.
048   */
049  private static Configuration getDriverConfiguration() {
050    return DriverConfiguration.CONF
051        .set(DriverConfiguration.GLOBAL_LIBRARIES,
052            HelloREEFMultiYarn.class.getProtectionDomain().getCodeSource().getLocation().getFile())
053        .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEFMultiYarn")
054        .set(DriverConfiguration.ON_DRIVER_STARTED, HelloMultiRuntimeDriver.StartHandler.class)
055        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloMultiRuntimeDriver.EvaluatorAllocatedHandler.class)
056        .build();
057  }
058
059  private static Configuration getHybridYarnSubmissionRuntimeConfiguration() {
060    return new MultiRuntimeConfigurationBuilder()
061            .setDefaultRuntime(org.apache.reef.runtime.yarn.driver.RuntimeIdentifier.RUNTIME_NAME)
062            .setSubmissionRuntime(org.apache.reef.runtime.yarn.driver.RuntimeIdentifier.RUNTIME_NAME)
063            .addRuntime(org.apache.reef.runtime.local.driver.RuntimeIdentifier.RUNTIME_NAME)
064            .addRuntime(org.apache.reef.runtime.yarn.driver.RuntimeIdentifier.RUNTIME_NAME)
065            .setMaxEvaluatorsNumberForLocalRuntime(1)
066            .build();
067  }
068
069  /**
070   * Start Hello REEF job.
071   *
072   * @param args command line parameters.
073   * @throws BindException      configuration error.
074   * @throws InjectionException configuration error.
075   */
076  public static void main(final String[] args) throws BindException, InjectionException {
077    final Configuration runtimeConf = getHybridYarnSubmissionRuntimeConfiguration();
078    final Configuration driverConf = getDriverConfiguration();
079
080    final LauncherStatus status = DriverLauncher
081        .getLauncher(runtimeConf)
082        .run(driverConf, JOB_TIMEOUT);
083    LOG.log(Level.INFO, "REEF job completed: {0}", status);
084  }
085
086  /**
087   * Empty private constructor to prohibit instantiation of utility class.
088   */
089  private HelloREEFMultiYarn() {
090  }
091}