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.local.client.LocalRuntimeConfiguration; 025import org.apache.reef.tang.Configuration; 026import org.apache.reef.tang.exceptions.BindException; 027import org.apache.reef.tang.exceptions.InjectionException; 028import org.apache.reef.util.EnvironmentUtils; 029 030import java.util.logging.Level; 031import java.util.logging.Logger; 032 033/** 034 * The Client for Hello REEF example. 035 */ 036public final class HelloREEF { 037 private static final Logger LOG = Logger.getLogger(HelloREEF.class.getName()); 038 039 /** 040 * The upper limit on the number of Evaluators that the local resourcemanager will hand out concurrently. 041 */ 042 private static final int MAX_NUMBER_OF_EVALUATORS = 2; 043 044 /** 045 * Number of milliseconds to wait for the job to complete. 046 */ 047 private static final int JOB_TIMEOUT = 10000; // 10 sec. 048 049 050 /** 051 * @return the configuration of the runtime 052 */ 053 private static Configuration getRuntimeConfiguration() { 054 return LocalRuntimeConfiguration.CONF 055 .set(LocalRuntimeConfiguration.MAX_NUMBER_OF_EVALUATORS, MAX_NUMBER_OF_EVALUATORS) 056 .build(); 057 } 058 059 /** 060 * @return the configuration of the HelloREEF driver. 061 */ 062 private static Configuration getDriverConfiguration() { 063 return DriverConfiguration.CONF 064 .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class)) 065 .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEF") 066 .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class) 067 .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class) 068 .build(); 069 } 070 071 /** 072 * Start Hello REEF job. 073 * 074 * @param args command line parameters. 075 * @throws BindException configuration error. 076 * @throws InjectionException configuration error. 077 */ 078 public static void main(final String[] args) throws BindException, InjectionException { 079 final Configuration runtimeConf = getRuntimeConfiguration(); 080 final Configuration driverConf = getDriverConfiguration(); 081 082 final LauncherStatus status = DriverLauncher 083 .getLauncher(runtimeConf) 084 .run(driverConf, JOB_TIMEOUT); 085 LOG.log(Level.INFO, "REEF job completed: {0}", status); 086 } 087 088 /** 089 * Empty private constructor to prohibit instantiation of utility class. 090 */ 091 private HelloREEF() { 092 } 093}