org.apache.oozie.command
Class Command<T,S extends Store>

java.lang.Object
  extended by org.apache.oozie.command.Command<T,S>
All Implemented Interfaces:
Callable<T>, XCallable<T>
Direct Known Subclasses:
CoordinatorCommand

public abstract class Command<T,S extends Store>
extends Object
implements XCallable<T>

Base class for all synchronous and asynchronous DagEngine commands.


Field Summary
protected  boolean dryrun
           
protected  Instrumentation instrumentation
           
protected static long LOCK_FAILURE_REQUEUE_INTERVAL
           
 
Constructor Summary
Command(String name, String type, int priority, int logMask)
          Create a command that uses a WorkflowStore instance.
Command(String name, String type, int priority, int logMask, boolean withStore)
          Create a command.
Command(String name, String type, int priority, int logMask, boolean withStore, boolean dryrun)
          Create a command.
 
Method Summary
 T call()
          Execute the command #call(WorkflowStore) setting all the necessary context.
protected abstract  T call(S store)
          DagCallable subclasses must implement this method to perform their task.
protected  T execute(S store)
           
 long getCreatedTime()
          Returns the createdTime of the callable in milliseconds
 String getEntityKey()
          Get command lock key returning the key as an entity key, [not used] Just to be able to implement XCallable [to be deprecated]
protected  Instrumentation getInstrumentation()
          Return the Instrumentation instance in use.
 String getKey()
          Get command key
 String getName()
          Return the name of the command.
 int getPriority()
          Return the priority of the command.
protected abstract  Class<? extends Store> getStoreClass()
          Command subclasses must implement this method correct Store can be passed to call(store);
 String getType()
          Return the callable type.
protected  void incrCommandCounter(int count)
          Used to increment command counters.
protected  void incrJobCounter(int count)
          Used to increment job counters.
protected  void incrJobCounter(String name, int count)
          Used to increment job counters.
 boolean inInterruptMode()
          [to be deprecated]
protected  boolean lock(String id)
           
protected  void logQueueCallableFalse(List<? extends XCallable<Void>> callables)
          Logging the info if failed to queue the callables.
protected  void queueCallable(List<? extends XCallable<Void>> callables)
          Queue a list of callables for execution after the current callable call invocation completes and the WorkflowStore transaction commits.
protected  void queueCallable(XCallable<Void> callable)
          Queue a callable for execution after the current callable call invocation completes and the WorkflowStore transaction commits.
protected  void queueCallable(XCallable<Void> callable, long delay)
          Queue a callable for delayed execution after the current callable call invocation completes and the WorkflowStore transaction commits.
protected  void queueCallableForException(XCallable<Void> callable)
          Queue a callable for execution only in the event of an exception being thrown during the call invocation.
protected  void resetLogInfoAction()
          Reset the action bean information from the log info.
protected  void resetLogInfoWorkflow()
          Reset the workflow bean information from the log info.
 void setInterruptMode(boolean mode)
          set the mode of execution for the callable.
protected  void setLogInfo(CoordinatorActionBean action)
          Set the log info with the context of the given coordinator action bean.
protected  void setLogInfo(CoordinatorJobBean cBean)
          Set the log info with the context of the given coordinator bean.
protected  void setLogInfo(WorkflowActionBean action)
          Set the log info with the context of the given action bean.
protected  void setLogInfo(WorkflowJobBean workflow)
          Set the log info with the context of the given workflow bean.
 String toString()
          Return the identity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOCK_FAILURE_REQUEUE_INTERVAL

protected static final long LOCK_FAILURE_REQUEUE_INTERVAL
See Also:
Constant Field Values

instrumentation

protected Instrumentation instrumentation

dryrun

protected boolean dryrun
Constructor Detail

Command

public Command(String name,
               String type,
               int priority,
               int logMask)
Create a command that uses a WorkflowStore instance.

The current XLog.Info values are captured for execution.

Parameters:
name - command name.
type - command type.
priority - priority of the command, used when queuing for asynchronous execution.
logMask - log mask for the command logging calls.

Command

public Command(String name,
               String type,
               int priority,
               int logMask,
               boolean withStore)
Create a command.

The current XLog.Info values are captured for execution.

Parameters:
name - command name.
type - command type.
priority - priority of the command, used when queuing for asynchronous execution.
logMask - log mask for the command logging calls.
withStore - indicates if the command needs a WorkflowStore instance or not.

Command

public Command(String name,
               String type,
               int priority,
               int logMask,
               boolean withStore,
               boolean dryrun)
Create a command.

The current XLog.Info values are captured for execution.

Parameters:
name - command name.
type - command type.
priority - priority of the command, used when queuing for asynchronous execution.
logMask - log mask for the command logging calls.
withStore - indicates if the command needs a WorkflowStore instance or not.
dryrun - indicates if dryrun option is enabled. if enabled coordinator will show a diagnostic output without really submitting the job
Method Detail

getName

public String getName()
Return the name of the command.

Specified by:
getName in interface XCallable<T>
Returns:
the name of the command.

getType

public String getType()
Return the callable type.

The callable type is used for concurrency throttling in the CallableQueueService.

Specified by:
getType in interface XCallable<T>
Returns:
the callable type.

getPriority

public int getPriority()
Return the priority of the command.

Specified by:
getPriority in interface XCallable<T>
Returns:
the priority of the command.

getCreatedTime

public long getCreatedTime()
Returns the createdTime of the callable in milliseconds

Specified by:
getCreatedTime in interface XCallable<T>
Returns:
the callable createdTime

call

public final T call()
             throws CommandException
Execute the command #call(WorkflowStore) setting all the necessary context.

The XLog.Info is set to the values at instance creation time.

The command execution is logged and instrumented.

If a WorkflowStore is used, a fresh instance will be passed and it will be commited after the #call(WorkflowStore) execution. It will be closed without committing if an exception is thrown.

Commands queued via the DagCommand queue methods are queued for execution after the workflow store has been committed.

If an exception happends the queued commands will not be effectively queued for execution. Instead, the the commands queued for exception will be effectively queued fro execution..

Specified by:
call in interface Callable<T>
Throws:
CommandException - thrown if the command could not be executed successfully, the workflow store is closed without committing, thus doing a rollback.

queueCallable

protected void queueCallable(XCallable<Void> callable)
Queue a callable for execution after the current callable call invocation completes and the WorkflowStore transaction commits.

All queued callables, regardless of the number of queue invocations, are queued for a single serial execution.

If the call invocation throws an exception all queued callables are discarded, they are not queued for execution.

Parameters:
callable - callable to queue for execution.

queueCallable

protected void queueCallable(List<? extends XCallable<Void>> callables)
Queue a list of callables for execution after the current callable call invocation completes and the WorkflowStore transaction commits.

All queued callables, regardless of the number of queue invocations, are queued for a single serial execution.

If the call invocation throws an exception all queued callables are discarded, they are not queued for execution.

Parameters:
callables - list of callables to queue for execution.

queueCallable

protected void queueCallable(XCallable<Void> callable,
                             long delay)
Queue a callable for delayed execution after the current callable call invocation completes and the WorkflowStore transaction commits.

All queued delayed callables, regardless of the number of delay queue invocations, are queued for a single serial delayed execution with the highest delay of all queued callables.

If the call invocation throws an exception all queued callables are discarded, they are not queued for execution.

Parameters:
callable - callable to queue for delayed execution.
delay - the queue delay in milliseconds

queueCallableForException

protected void queueCallableForException(XCallable<Void> callable)
Queue a callable for execution only in the event of an exception being thrown during the call invocation.

If an exception does not happen, all the callables queued by this method are discarded, they are not queued for execution.

All queued callables, regardless of the number of queue invocations, are queued for a single serial execution.

Parameters:
callable - callable to queue for execution in the case of an exception.

logQueueCallableFalse

protected void logQueueCallableFalse(List<? extends XCallable<Void>> callables)
Logging the info if failed to queue the callables.

Parameters:
callables -

call

protected abstract T call(S store)
                   throws StoreException,
                          CommandException
DagCallable subclasses must implement this method to perform their task.

The workflow store works in transactional mode. The transaction is committed only if this method ends successfully. Otherwise the transaction is rolledback.

Parameters:
store - the workflow store instance for the callable, null if the callable does not use a store.
Returns:
the return value of the callable.
Throws:
StoreException - thrown if the workflow store could not perform an operation.
CommandException - thrown if the command could not perform its operation.

getStoreClass

protected abstract Class<? extends Store> getStoreClass()
Command subclasses must implement this method correct Store can be passed to call(store);

Returns:
the Store class for use by Callable
Throws:
CommandException - thrown if the command could not perform its operation.

setLogInfo

protected void setLogInfo(CoordinatorJobBean cBean)
Set the log info with the context of the given coordinator bean.

Parameters:
cBean - coordinator bean.

setLogInfo

protected void setLogInfo(CoordinatorActionBean action)
Set the log info with the context of the given coordinator action bean.

Parameters:
action - action bean.

setLogInfo

protected void setLogInfo(WorkflowJobBean workflow)
Set the log info with the context of the given workflow bean.

Parameters:
workflow - workflow bean.

setLogInfo

protected void setLogInfo(WorkflowActionBean action)
Set the log info with the context of the given action bean.

Parameters:
action - action bean.

resetLogInfoAction

protected void resetLogInfoAction()
Reset the action bean information from the log info.


resetLogInfoWorkflow

protected void resetLogInfoWorkflow()
Reset the workflow bean information from the log info.


incrCommandCounter

protected void incrCommandCounter(int count)
Used to increment command counters.

Parameters:
count - the increment count.

incrJobCounter

protected void incrJobCounter(int count)
Used to increment job counters. The counter name s the same as the command name.

Parameters:
count - the increment count.

incrJobCounter

protected void incrJobCounter(String name,
                              int count)
Used to increment job counters.

Parameters:
name - the job name.
count - the increment count.

getInstrumentation

protected Instrumentation getInstrumentation()
Return the Instrumentation instance in use.

Returns:
the Instrumentation instance in use.

toString

public String toString()
Return the identity.

Overrides:
toString in class Object
Returns:
the identity.

lock

protected boolean lock(String id)
                throws InterruptedException
Throws:
InterruptedException

execute

protected T execute(S store)
             throws CommandException,
                    StoreException
Throws:
CommandException
StoreException

getKey

public String getKey()
Get command key

Specified by:
getKey in interface XCallable<T>
Returns:
command key

getEntityKey

public String getEntityKey()
Get command lock key returning the key as an entity key, [not used] Just to be able to implement XCallable [to be deprecated]

Specified by:
getEntityKey in interface XCallable<T>
Returns:
key

setInterruptMode

public void setInterruptMode(boolean mode)
set the mode of execution for the callable. True if in interrupt, false if not [to be deprecated]

Specified by:
setInterruptMode in interface XCallable<T>

inInterruptMode

public boolean inInterruptMode()
[to be deprecated]

Specified by:
inInterruptMode in interface XCallable<T>
Returns:
the mode of execution. true if it is executed as an Interrupt, false otherwise


Copyright © 2012 Apache Software Foundation. All Rights Reserved.