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.REEF; 023import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration; 024import org.apache.reef.tang.Configuration; 025import org.apache.reef.tang.Tang; 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 * A main() for running hello REEF without a persistent client connection. 035 */ 036public final class HelloREEFNoClient { 037 038 private static final Logger LOG = Logger.getLogger(HelloREEFNoClient.class.getName()); 039 040 /** 041 * The upper limit on the number of Evaluators that the local resourcemanager will hand out concurrently. 042 */ 043 private static final int MAX_NUMBER_OF_EVALUATORS = 2; 044 045 /** 046 * @return the configuration of the runtime 047 */ 048 private static Configuration getRuntimeConfiguration() { 049 return LocalRuntimeConfiguration.CONF 050 .set(LocalRuntimeConfiguration.MAX_NUMBER_OF_EVALUATORS, MAX_NUMBER_OF_EVALUATORS) 051 .build(); 052 } 053 054 /** 055 * @return the configuration of the HelloREEF driver. 056 */ 057 private static Configuration getDriverConfiguration() { 058 return DriverConfiguration.CONF 059 .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class)) 060 .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEF") 061 .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class) 062 .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class) 063 .build(); 064 } 065 066 /** 067 * Used in the HDInsight example. 068 * @param runtimeConf the configuration of the runtime 069 * @throws InjectionException 070 */ 071 public static void runHelloReefWithoutClient(final Configuration runtimeConf) throws InjectionException { 072 final REEF reef = Tang.Factory.getTang().newInjector(runtimeConf).getInstance(REEF.class); 073 final Configuration driverConf = getDriverConfiguration(); 074 reef.submit(driverConf); 075 } 076 077 public static void main(final String[] args) throws BindException, InjectionException { 078 final Configuration runtimeConf = getRuntimeConfiguration(); 079 final Configuration driverConf = getDriverConfiguration(); 080 081 final REEF reef = Tang.Factory.getTang().newInjector(runtimeConf).getInstance(REEF.class); 082 reef.submit(driverConf); 083 LOG.log(Level.INFO, "Job Submitted"); 084 } 085 086 /** 087 * Empty private constructor to prohibit instantiation of utility class. 088 */ 089 private HelloREEFNoClient() { 090 } 091}