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.client; 020 021import org.apache.reef.client.parameters.*; 022import org.apache.reef.runtime.common.client.parameters.ClientPresent; 023import org.apache.reef.tang.formats.ConfigurationModule; 024import org.apache.reef.tang.formats.ConfigurationModuleBuilder; 025import org.apache.reef.tang.formats.OptionalImpl; 026import org.apache.reef.wake.EventHandler; 027import org.apache.reef.wake.remote.RemoteConfiguration; 028 029/** 030 * A ConfigurationModule to fill out for the client configuration. 031 */ 032public final class ClientConfiguration extends ConfigurationModuleBuilder { 033 034 /** 035 * Event handler for messages from the running job. 036 * Default implementation just writes message to the log. 037 * A message contains a status and a client-defined message payload. 038 */ 039 public static final OptionalImpl<EventHandler<JobMessage>> ON_JOB_MESSAGE = new OptionalImpl<>(); 040 041 /** 042 * Handler for the event when a submitted REEF Job is running. 043 * Default implementation just writes to the log. 044 */ 045 public static final OptionalImpl<EventHandler<RunningJob>> ON_JOB_RUNNING = new OptionalImpl<>(); 046 047 /** 048 * Handler for the event when a submitted REEF Job is completed. 049 * Default implementation just writes to the log. 050 */ 051 public static final OptionalImpl<EventHandler<CompletedJob>> ON_JOB_COMPLETED = new OptionalImpl<>(); 052 053 /** 054 * Handler for the event when a submitted REEF Job has failed. 055 * Default implementation logs an error and rethrows the exception in the client JVM. 056 */ 057 public static final OptionalImpl<EventHandler<FailedJob>> ON_JOB_FAILED = new OptionalImpl<>(); 058 059 /** 060 * Receives fatal resourcemanager errors. The presence of this error means that the 061 * underlying REEF instance is no longer able to execute REEF jobs. The 062 * actual Jobs may or may not still be running. 063 * Default implementation logs an error and rethrows the exception in the client JVM. 064 */ 065 public static final OptionalImpl<EventHandler<FailedRuntime>> ON_RUNTIME_ERROR = new OptionalImpl<>(); 066 067 /** 068 * Error handler for events on Wake-spawned threads. 069 * Exceptions that are thrown on wake-spawned threads (e.g. in EventHandlers) will be caught by Wake and delivered to 070 * this handler. Default behavior is to log the exceptions and rethrow them as RuntimeExceptions. 071 */ 072 public static final OptionalImpl<EventHandler<Throwable>> ON_WAKE_ERROR = new OptionalImpl<>(); 073 074 public static final ConfigurationModule CONF = new ClientConfiguration() 075 .bind(JobMessageHandler.class, ON_JOB_MESSAGE) 076 .bind(JobRunningHandler.class, ON_JOB_RUNNING) 077 .bind(JobCompletedHandler.class, ON_JOB_COMPLETED) 078 .bind(JobFailedHandler.class, ON_JOB_FAILED) 079 .bind(ResourceManagerErrorHandler.class, ON_RUNTIME_ERROR) 080 .bindNamedParameter(ClientPresent.class, ClientPresent.YES) 081 .bindNamedParameter(RemoteConfiguration.ErrorHandler.class, ON_WAKE_ERROR) 082 .build(); 083}