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.annotations.Provided; 022import org.apache.reef.annotations.audience.ClientSide; 023import org.apache.reef.annotations.audience.Public; 024import org.apache.reef.driver.context.ActiveContext; 025import org.apache.reef.driver.context.ClosedContext; 026import org.apache.reef.driver.context.ContextMessage; 027import org.apache.reef.driver.context.FailedContext; 028import org.apache.reef.driver.evaluator.AllocatedEvaluator; 029import org.apache.reef.driver.evaluator.CompletedEvaluator; 030import org.apache.reef.driver.evaluator.FailedEvaluator; 031import org.apache.reef.driver.parameters.*; 032import org.apache.reef.driver.task.*; 033import org.apache.reef.tang.formats.*; 034import org.apache.reef.wake.EventHandler; 035import org.apache.reef.wake.time.Clock; 036import org.apache.reef.wake.time.event.StartTime; 037import org.apache.reef.wake.time.event.StopTime; 038 039/** 040 * Use this ConfigurationModule to configure Services to be run in the Driver. 041 * <p/> 042 * A service is a set of event handlers that are informed of events in addition to * the event handlers defined in 043 * DriverConfiguration. However, most services will treat the events as read-only. Doing differently should be 044 * documented clearly in the Service documentation. 045 */ 046@ClientSide 047@Public 048@Provided 049public final class DriverServiceConfiguration extends ConfigurationModuleBuilder { 050 051 052 /** 053 * Files to be made available on the Driver and all Evaluators. 054 */ 055 public static final OptionalParameter<String> GLOBAL_FILES = new OptionalParameter<>(); 056 057 /** 058 * Libraries to be made available on the Driver and all Evaluators. 059 */ 060 public static final OptionalParameter<String> GLOBAL_LIBRARIES = new OptionalParameter<>(); 061 062 /** 063 * Files to be made available on the Driver only. 064 */ 065 public static final OptionalParameter<String> LOCAL_FILES = new OptionalParameter<>(); 066 067 /** 068 * Libraries to be made available on the Driver only. 069 */ 070 public static final OptionalParameter<String> LOCAL_LIBRARIES = new OptionalParameter<>(); 071 072 /** 073 * The event handler invoked right after the driver boots up. 074 */ 075 public static final RequiredImpl<EventHandler<StartTime>> ON_DRIVER_STARTED = new RequiredImpl<>(); 076 077 /** 078 * The event handler invoked right before the driver shuts down. Defaults to ignore. 079 */ 080 public static final OptionalImpl<EventHandler<StopTime>> ON_DRIVER_STOP = new OptionalImpl<>(); 081 082 // ***** EVALUATOR HANDLER BINDINGS: 083 084 /** 085 * Event handler for allocated evaluators. Defaults to returning the evaluator if not bound. 086 */ 087 public static final OptionalImpl<EventHandler<AllocatedEvaluator>> ON_EVALUATOR_ALLOCATED = new OptionalImpl<>(); 088 089 /** 090 * Event handler for completed evaluators. Defaults to logging if not bound. 091 */ 092 public static final OptionalImpl<EventHandler<CompletedEvaluator>> ON_EVALUATOR_COMPLETED = new OptionalImpl<>(); 093 094 /** 095 * Event handler for failed evaluators. Defaults to job failure if not bound. 096 */ 097 public static final OptionalImpl<EventHandler<FailedEvaluator>> ON_EVALUATOR_FAILED = new OptionalImpl<>(); 098 099 // ***** TASK HANDLER BINDINGS: 100 101 /** 102 * Event handler for task messages. Defaults to logging if not bound. 103 */ 104 public static final OptionalImpl<EventHandler<TaskMessage>> ON_TASK_MESSAGE = new OptionalImpl<>(); 105 106 /** 107 * Event handler for completed tasks. Defaults to closing the context the task ran on if not bound. 108 */ 109 public static final OptionalImpl<EventHandler<CompletedTask>> ON_TASK_COMPLETED = new OptionalImpl<>(); 110 111 /** 112 * Event handler for failed tasks. Defaults to job failure if not bound. 113 */ 114 public static final OptionalImpl<EventHandler<FailedTask>> ON_TASK_FAILED = new OptionalImpl<>(); 115 116 /** 117 * Event handler for running tasks. Defaults to logging if not bound. 118 */ 119 public static final OptionalImpl<EventHandler<RunningTask>> ON_TASK_RUNNING = new OptionalImpl<>(); 120 121 /** 122 * Event handler for running tasks in previous evaluator, when driver restarted. Defaults to logging if not bound. 123 */ 124 public static final OptionalImpl<EventHandler<RunningTask>> ON_DRIVER_RESTART_TASK_RUNNING = new OptionalImpl<>(); 125 126 /** 127 * Event handler for suspended tasks. Defaults to job failure if not bound. Rationale: many jobs don't support 128 * task suspension. Hence, this parameter should be optional. The only sane default is to crash the job, then. 129 */ 130 public static final OptionalImpl<EventHandler<SuspendedTask>> ON_TASK_SUSPENDED = new OptionalImpl<>(); 131 132 133 // ***** CONTEXT HANDLER BINDINGS: 134 135 /** 136 * Event handler for active context. Defaults to closing the context if not bound. 137 */ 138 public static final OptionalImpl<EventHandler<ActiveContext>> ON_CONTEXT_ACTIVE = new OptionalImpl<>(); 139 140 /** 141 * Event handler for active context when driver restart. Defaults to closing the context if not bound. 142 */ 143 public static final OptionalImpl<EventHandler<ActiveContext>> ON_DRIVER_RESTART_CONTEXT_ACTIVE = new OptionalImpl<>(); 144 145 /** 146 * Event handler for closed context. Defaults to logging if not bound. 147 */ 148 public static final OptionalImpl<EventHandler<ClosedContext>> ON_CONTEXT_CLOSED = new OptionalImpl<>(); 149 150 /** 151 * Event handler for closed context. Defaults to job failure if not bound. 152 */ 153 public static final OptionalImpl<EventHandler<FailedContext>> ON_CONTEXT_FAILED = new OptionalImpl<>(); 154 155 /** 156 * Event handler for context messages. Defaults to logging if not bound. 157 */ 158 public static final OptionalImpl<EventHandler<ContextMessage>> ON_CONTEXT_MESSAGE = new OptionalImpl<>(); 159 160 161 /** 162 * ConfigurationModule to fill out to get a legal Driver Configuration. 163 */ 164 public static final ConfigurationModule CONF = new DriverServiceConfiguration() 165 // Files use the very same named parameters as the DriverConfiguration 166 .bindSetEntry(JobGlobalFiles.class, GLOBAL_FILES) 167 .bindSetEntry(JobGlobalLibraries.class, GLOBAL_LIBRARIES) 168 .bindSetEntry(DriverLocalFiles.class, LOCAL_FILES) 169 .bindSetEntry(DriverLocalLibraries.class, LOCAL_LIBRARIES) 170 171 // Start and stop events are the same handlers for applications and services. 172 .bindSetEntry(Clock.StartHandler.class, ON_DRIVER_STARTED) 173 .bindSetEntry(Clock.StopHandler.class, ON_DRIVER_STOP) 174 175 // Evaluator handlers 176 .bindSetEntry(ServiceEvaluatorAllocatedHandlers.class, ON_EVALUATOR_ALLOCATED) 177 .bindSetEntry(ServiceEvaluatorCompletedHandlers.class, ON_EVALUATOR_COMPLETED) 178 .bindSetEntry(ServiceEvaluatorFailedHandlers.class, ON_EVALUATOR_FAILED) 179 180 // Task handlers 181 .bindSetEntry(ServiceTaskRunningHandlers.class, ON_TASK_RUNNING) 182 .bindSetEntry(DriverRestartTaskRunningHandlers.class, ON_DRIVER_RESTART_TASK_RUNNING) 183 .bindSetEntry(ServiceTaskFailedHandlers.class, ON_TASK_FAILED) 184 .bindSetEntry(ServiceTaskMessageHandlers.class, ON_TASK_MESSAGE) 185 .bindSetEntry(ServiceTaskCompletedHandlers.class, ON_TASK_COMPLETED) 186 .bindSetEntry(ServiceTaskSuspendedHandlers.class, ON_TASK_SUSPENDED) 187 188 // Context handlers 189 .bindSetEntry(ServiceContextActiveHandlers.class, ON_CONTEXT_ACTIVE) 190 .bindSetEntry(DriverRestartContextActiveHandlers.class, ON_DRIVER_RESTART_CONTEXT_ACTIVE) 191 .bindSetEntry(ServiceContextClosedHandlers.class, ON_CONTEXT_CLOSED) 192 .bindSetEntry(ServiceContextMessageHandlers.class, ON_CONTEXT_MESSAGE) 193 .bindSetEntry(ServiceContextFailedHandlers.class, ON_CONTEXT_FAILED) 194 195 .build(); 196}