org.apache.oozie.action
Class ActionExecutor

java.lang.Object
  extended by org.apache.oozie.action.ActionExecutor
Direct Known Subclasses:
ControlNodeActionExecutor, DecisionActionExecutor, EmailActionExecutor, FsActionExecutor, JavaActionExecutor, SshActionExecutor, SubWorkflowActionExecutor

public abstract class ActionExecutor
extends Object

Base action executor class.

All the action executors should extend this class.


Nested Class Summary
static interface ActionExecutor.Context
          Context information passed to the ActionExecutor methods.
 
Field Summary
static String CONF_PREFIX
          Configuration prefix for action executor (sub-classes) properties.
static String ERROR_OTHER
          Error code used by convertException(java.lang.Exception) when there is not register error information for an exception.
static String MAX_RETRIES
           
 boolean requiresNNJT
           
static long RETRY_INTERVAL
          Define the default inteval in seconds between retries.
 
Constructor Summary
protected ActionExecutor(String type)
          Create an action executor with default retry parameters.
protected ActionExecutor(String type, long retryInterval)
          Create an action executor.
 
Method Summary
abstract  void check(ActionExecutor.Context context, org.apache.oozie.client.WorkflowAction action)
          Check if an action has completed.
protected  ActionExecutorException convertException(Exception ex)
          Utility method to handle exceptions in the start(org.apache.oozie.action.ActionExecutor.Context, org.apache.oozie.client.WorkflowAction), end(org.apache.oozie.action.ActionExecutor.Context, org.apache.oozie.client.WorkflowAction), kill(org.apache.oozie.action.ActionExecutor.Context, org.apache.oozie.client.WorkflowAction) and check(org.apache.oozie.action.ActionExecutor.Context, org.apache.oozie.client.WorkflowAction) methods

It uses the error registry to convert exceptions to ActionExecutorExceptions.

static void disableInit()
          Disable action type initialization.
static void enableInit()
          Enable action type initialization.
abstract  void end(ActionExecutor.Context context, org.apache.oozie.client.WorkflowAction action)
          End an action after it has executed.
 org.apache.hadoop.fs.Path getActionDir(String jobId, org.apache.oozie.client.WorkflowAction action, String key, boolean temp)
          Return the path that will be used to store action specific data.
protected  String getActionDirPath(String jobId, org.apache.oozie.client.WorkflowAction action, String key, boolean temp)
          Return the path that will be used to store action specific data
protected  String getActionSignal(org.apache.oozie.client.WorkflowAction.Status status)
          Convenience method that return the signal for an Action based on the action status.
 int getMaxRetries()
          Return the maximum number of retries for the action executor.
 org.apache.hadoop.conf.Configuration getOozieConf()
          Return Oozie configuration.
 String getOozieRuntimeDir()
          Return the runtime directory of the Oozie instance.
 String getOozieSystemId()
          Return the system ID, this ID is defined in Oozie configuration.
 long getRetryInterval()
          Return the retry interval for the action executor in seconds.
 String getType()
          Return the action executor type.
 void initActionType()
          Invoked once at system initialization time.
abstract  boolean isCompleted(String externalStatus)
          Return if the external status indicates that the action has completed.
abstract  void kill(ActionExecutor.Context context, org.apache.oozie.client.WorkflowAction action)
          Kill an action.
protected  void registerError(String exClass, ActionExecutorException.ErrorType errorType, String errorCode)
          Register error handling information for an exception.
static void resetInitInfo()
          Clear all init settings for all action types.
 void setMaxRetries(int maxRetries)
          Set the maximum number of retries for the action executor.
 void setRetryInterval(long retryInterval)
          Sets the retry interval for the action executor.
abstract  void start(ActionExecutor.Context context, org.apache.oozie.client.WorkflowAction action)
          Start an action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONF_PREFIX

public static final String CONF_PREFIX
Configuration prefix for action executor (sub-classes) properties.

See Also:
Constant Field Values

MAX_RETRIES

public static final String MAX_RETRIES
See Also:
Constant Field Values

ERROR_OTHER

public static final String ERROR_OTHER
Error code used by convertException(java.lang.Exception) when there is not register error information for an exception.

See Also:
Constant Field Values

requiresNNJT

public boolean requiresNNJT

RETRY_INTERVAL

public static final long RETRY_INTERVAL
Define the default inteval in seconds between retries.

See Also:
Constant Field Values
Constructor Detail

ActionExecutor

protected ActionExecutor(String type)
Create an action executor with default retry parameters.

Parameters:
type - action executor type.

ActionExecutor

protected ActionExecutor(String type,
                         long retryInterval)
Create an action executor.

Parameters:
type - action executor type.
retryAttempts - retry attempts.
retryInterval - retry interval, in seconds.
Method Detail

resetInitInfo

public static void resetInitInfo()
Clear all init settings for all action types.


enableInit

public static void enableInit()
Enable action type initialization.


disableInit

public static void disableInit()
Disable action type initialization.


initActionType

public void initActionType()
Invoked once at system initialization time.

It can be used to register error information for the expected exceptions. Exceptions should be register from subclasses to superclasses to ensure proper detection, same thing that it is done in a normal catch.

This method should invoke the registerError(java.lang.String, org.apache.oozie.action.ActionExecutorException.ErrorType, java.lang.String) method to register all its possible errors.

Subclasses overriding must invoke super.


getOozieSystemId

public String getOozieSystemId()
Return the system ID, this ID is defined in Oozie configuration.

Returns:
the system ID.

getOozieRuntimeDir

public String getOozieRuntimeDir()
Return the runtime directory of the Oozie instance.

The directory is created under TMP and it is always a new directory per system initialization.

Returns:
the runtime directory of the Oozie instance.

getOozieConf

public org.apache.hadoop.conf.Configuration getOozieConf()
Return Oozie configuration.

This is useful for actions that need access to configuration properties.

Returns:
Oozie configuration.

registerError

protected void registerError(String exClass,
                             ActionExecutorException.ErrorType errorType,
                             String errorCode)
Register error handling information for an exception.

Parameters:
exClass - excpetion class name (to work in case of a particular exception not being in the classpath, needed to be able to handle multiple version of Hadoop or other JARs used by executors with the same codebase).
errorType - error type for the exception.
errorCode - error code for the exception.

getType

public String getType()
Return the action executor type.

Returns:
the action executor type.

getMaxRetries

public int getMaxRetries()
Return the maximum number of retries for the action executor.

Returns:
the maximum number of retries for the action executor.

setMaxRetries

public void setMaxRetries(int maxRetries)
Set the maximum number of retries for the action executor.

Parameters:
maxRetries - the maximum number of retries.

getRetryInterval

public long getRetryInterval()
Return the retry interval for the action executor in seconds.

Returns:
the retry interval for the action executor in seconds.

setRetryInterval

public void setRetryInterval(long retryInterval)
Sets the retry interval for the action executor.

Parameters:
retryInterval - retry interval in seconds.

convertException

protected ActionExecutorException convertException(Exception ex)
Utility method to handle exceptions in the start(org.apache.oozie.action.ActionExecutor.Context, org.apache.oozie.client.WorkflowAction), end(org.apache.oozie.action.ActionExecutor.Context, org.apache.oozie.client.WorkflowAction), kill(org.apache.oozie.action.ActionExecutor.Context, org.apache.oozie.client.WorkflowAction) and check(org.apache.oozie.action.ActionExecutor.Context, org.apache.oozie.client.WorkflowAction) methods

It uses the error registry to convert exceptions to ActionExecutorExceptions.

Parameters:
ex - exception to convert.
Returns:
ActionExecutorException converted exception.

getActionSignal

protected String getActionSignal(org.apache.oozie.client.WorkflowAction.Status status)
Convenience method that return the signal for an Action based on the action status.

Parameters:
status - action status.
Returns:
the action signal.

getActionDirPath

protected String getActionDirPath(String jobId,
                                  org.apache.oozie.client.WorkflowAction action,
                                  String key,
                                  boolean temp)
Return the path that will be used to store action specific data

Parameters:
jobId - Worfklow ID
action - Action
key - An Identifier
temp - temp directory flag
Returns:
A string that has the path

getActionDir

public org.apache.hadoop.fs.Path getActionDir(String jobId,
                                              org.apache.oozie.client.WorkflowAction action,
                                              String key,
                                              boolean temp)
Return the path that will be used to store action specific data.

Parameters:
jobId - Workflow ID
action - Action
key - An identifier
temp - Temp directory flag
Returns:
Path to the directory

start

public abstract void start(ActionExecutor.Context context,
                           org.apache.oozie.client.WorkflowAction action)
                    throws ActionExecutorException
Start an action.

The ActionExecutor.Context.setStartData(java.lang.String, java.lang.String, java.lang.String) method must be called within this method.

If the action has completed, the ActionExecutor.Context.setExecutionData(java.lang.String, java.util.Properties) method must be called within this method.

Parameters:
context - executor context.
action - the action to start.
Throws:
ActionExecutorException - thrown if the action could not start.

end

public abstract void end(ActionExecutor.Context context,
                         org.apache.oozie.client.WorkflowAction action)
                  throws ActionExecutorException
End an action after it has executed.

The ActionExecutor.Context.setEndData(org.apache.oozie.client.WorkflowAction.Status, java.lang.String) method must be called within this method.

Parameters:
context - executor context.
action - the action to end.
Throws:
ActionExecutorException - thrown if the action could not end.

check

public abstract void check(ActionExecutor.Context context,
                           org.apache.oozie.client.WorkflowAction action)
                    throws ActionExecutorException
Check if an action has completed. This method must be implemented by Async Action Executors.

If the action has completed, the ActionExecutor.Context.setExecutionData(java.lang.String, java.util.Properties) method must be called within this method.

If the action has not completed, the ActionExecutor.Context.setExternalStatus(java.lang.String) method must be called within this method.

Parameters:
context - executor context.
action - the action to end.
Throws:
ActionExecutorException - thrown if the action could not be checked.

kill

public abstract void kill(ActionExecutor.Context context,
                          org.apache.oozie.client.WorkflowAction action)
                   throws ActionExecutorException
Kill an action.

The ActionExecutor.Context.setEndData(org.apache.oozie.client.WorkflowAction.Status, java.lang.String) method must be called within this method.

Parameters:
context - executor context.
action - the action to kill.
Throws:
ActionExecutorException - thrown if the action could not be killed.

isCompleted

public abstract boolean isCompleted(String externalStatus)
Return if the external status indicates that the action has completed.

Parameters:
externalStatus - external status to check.
Returns:
if the external status indicates that the action has completed.


Copyright © 2013 Apache Software Foundation. All Rights Reserved.