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.proto.ReefServiceProtos; 023import org.apache.reef.runtime.common.REEFEnvironment; 024import org.apache.reef.runtime.common.driver.parameters.ClientRemoteIdentifier; 025import org.apache.reef.runtime.common.launch.REEFMessageCodec; 026import org.apache.reef.runtime.local.driver.LocalDriverConfiguration; 027import org.apache.reef.runtime.local.driver.RuntimeIdentifier; 028import org.apache.reef.tang.Configuration; 029import org.apache.reef.tang.Tang; 030import org.apache.reef.tang.exceptions.InjectionException; 031import org.apache.reef.util.EnvironmentUtils; 032import org.apache.reef.wake.remote.RemoteConfiguration; 033 034import java.util.logging.Level; 035import java.util.logging.Logger; 036 037/** 038 * The Client for Hello REEF example running driver and client in the same process. 039 */ 040public final class HelloREEFEnvironment { 041 042 private static final Logger LOG = Logger.getLogger(HelloREEFEnvironment.class.getName()); 043 044 private static final Configuration DRIVER_CONFIG = DriverConfiguration.CONF 045 .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEF_Env") 046 .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class)) 047 .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class) 048 .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class) 049 .build(); 050 051 private static final Configuration LOCAL_DRIVER_MODULE = LocalDriverConfiguration.CONF 052 .set(LocalDriverConfiguration.RUNTIME_NAMES, RuntimeIdentifier.RUNTIME_NAME) 053 .set(LocalDriverConfiguration.CLIENT_REMOTE_IDENTIFIER, ClientRemoteIdentifier.NONE) 054 .set(LocalDriverConfiguration.JOB_IDENTIFIER, "LOCAL_ENV_DRIVER_TEST") 055 .set(LocalDriverConfiguration.ROOT_FOLDER, "./REEF_LOCAL_RUNTIME") 056 .set(LocalDriverConfiguration.MAX_NUMBER_OF_EVALUATORS, 2) 057 .set(LocalDriverConfiguration.JVM_HEAP_SLACK, 0.0) 058 .build(); 059 060 private static final Configuration ENVIRONMENT_CONFIG = 061 Tang.Factory.getTang().newConfigurationBuilder() 062 .bindNamedParameter(RemoteConfiguration.ManagerName.class, "REEF_ENVIRONMENT") 063 .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class) 064 .build(); 065 066 /** 067 * Start Hello REEF job with Driver and Client sharing the same process. 068 * 069 * @param args command line parameters - not used. 070 * @throws InjectionException configuration error. 071 */ 072 public static void main(final String[] args) throws InjectionException { 073 074 try (final REEFEnvironment reef = REEFEnvironment.fromConfiguration( 075 LOCAL_DRIVER_MODULE, DRIVER_CONFIG, ENVIRONMENT_CONFIG)) { 076 reef.run(); 077 final ReefServiceProtos.JobStatusProto status = reef.getLastStatus(); 078 LOG.log(Level.INFO, "REEF job completed: {0}", status); 079 } 080 } 081 082 /** 083 * Empty private constructor to prohibit instantiation of all-static class. 084 */ 085 private HelloREEFEnvironment() { 086 } 087}