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