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.yarn.client.YarnClientConfiguration; 025import org.apache.reef.tang.Configuration; 026import org.apache.reef.tang.exceptions.InjectionException; 027 028import java.util.logging.Level; 029import java.util.logging.Logger; 030 031/** 032 * The Client for Hello REEF example. 033 */ 034public final class HelloReefYarn { 035 036 private static final Logger LOG = Logger.getLogger(HelloReefYarn.class.getName()); 037 038 /** 039 * Number of milliseconds to wait for the job to complete. 040 */ 041 private static final int JOB_TIMEOUT = 30000; // 30 sec. 042 043 044 /** 045 * @return the configuration of the HelloREEF driver. 046 */ 047 private static Configuration getDriverConfiguration() { 048 return DriverConfiguration.CONF 049 .set(DriverConfiguration.GLOBAL_LIBRARIES, HelloReefYarn.class.getProtectionDomain().getCodeSource().getLocation().getFile()) 050 .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEF") 051 .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class) 052 .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class) 053 .build(); 054 } 055 056 /** 057 * Start Hello REEF job. Runs method runHelloReef(). 058 * 059 * @param args command line parameters. 060 * @throws org.apache.reef.tang.exceptions.BindException configuration error. 061 * @throws org.apache.reef.tang.exceptions.InjectionException configuration error. 062 */ 063 public static void main(final String[] args) throws InjectionException { 064 065 final LauncherStatus status = DriverLauncher 066 .getLauncher(YarnClientConfiguration.CONF.build()) 067 .run(getDriverConfiguration(), JOB_TIMEOUT); 068 LOG.log(Level.INFO, "REEF job completed: {0}", status); 069 } 070}