org.pentaho.di.job
Class Job

java.lang.Object
  extended by java.lang.Thread
      extended by org.pentaho.di.job.Job
All Implemented Interfaces:
Runnable, HasLogChannelInterface, LoggingObjectInterface, NamedParams, VariableSpace

public class Job
extends Thread
implements VariableSpace, NamedParams, HasLogChannelInterface, LoggingObjectInterface

This class executes a JobInfo object.

Since:
07-apr-2003
Author:
Matt Casters

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static String CONFIGURATION_IN_EXPORT_FILENAME
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Job()
          Empty constructor, for Class.newInstance()
Job(Repository repository, JobMeta jobMeta)
           
Job(Repository repository, JobMeta jobMeta, LoggingObjectInterface parentLogging)
           
Job(String name, String file, String[] args)
           
 
Method Summary
 void activateParameters()
          Activate the currently set parameters
 void addErrors(int nrToAdd)
          Add a number of errors to the total number of erros that occured during execution.
 void addJobEntryListener(JobEntryListener jobEntryListener)
           
 void addJobListener(JobListener jobListener)
          Add a job listener to the job
 void addParameterDefinition(String key, String defValue, String description)
          Add a parameter definition to this set.
 boolean beginProcessing()
          Handle logging at start
 void clearParameters()
          Clear all parameters
 void copyParametersFrom(NamedParams params)
          Copy params to these named parameters (clearing out first).
 void copyVariablesFrom(VariableSpace space)
          Copy the variables from another space, without initializing with the defaults.
static Job createJobWithNewClassLoader()
           
 String environmentSubstitute(String aString)
          Substitute the string using the current variable space.
 String[] environmentSubstitute(String[] aString)
          Replaces environment variables in an array of strings.
 void eraseParameters()
          Clear the values.
 Result execute(int nr, Result result)
          Execute a job with previous results passed in.

Execute called by JobEntryJob: don't clear the jobEntryResults.
 void fireJobListeners()
          Sets the finished flag. Then launch all the job listeners and call the jobFinished method for each.
 Map<JobEntryCopy,JobEntryJob> getActiveJobEntryJobs()
           
 Map<JobEntryCopy,JobEntryTrans> getActiveJobEntryTransformations()
           
 long getBatchId()
           
 boolean getBooleanValueOfVariable(String variableName, boolean defaultValue)
          This method returns a boolean for the new variable check boxes.
 String getContainerObjectId()
           
 Date getCurrentDate()
           
 Date getDepDate()
           
 Date getEndDate()
           
 int getErrors()
          Get the number of errors that happened in the job.
 String getFilename()
           
 List<JobEntryListener> getJobEntryListeners()
           
 List<JobEntryResult> getJobEntryResults()
           
 List<JobListener> getJobListeners()
           
 JobMeta getJobMeta()
           
 String getJobname()
           
 JobTracker getJobTracker()
           
 LogChannelInterface getLogChannel()
           
 String getLogChannelId()
           
 Date getLogDate()
           
 List<LoggingHierarchy> getLoggingHierarchy()
           
 LogLevel getLogLevel()
           
 String getObjectCopy()
           
 ObjectId getObjectId()
           
 String getObjectName()
           
 ObjectRevision getObjectRevision()
           
 LoggingObjectType getObjectType()
           
 String getParameterDefault(String key)
          Get the default value of a parameter.
 String getParameterDescription(String key)
          Get the description of a parameter.
 String getParameterValue(String key)
          Get the value of a parameter.
 LoggingObjectInterface getParent()
           
 Job getParentJob()
           
 LoggingObjectInterface getParentLoggingObject()
           
 VariableSpace getParentVariableSpace()
          Get the parent of the variable space.
 long getPassedBatchId()
           
 Date getRegistrationDate()
          Stub
 Repository getRep()
           
 RepositoryDirectoryInterface getRepositoryDirectory()
           
 Result getResult()
           
 SocketRepository getSocketRepository()
           
 List<RowMetaAndData> getSourceRows()
           
 Date getStartDate()
           
 JobEntryCopy getStartJobEntryCopy()
           
 String getStatus()
           
 Thread getThread()
           
 String getVariable(String variableName)
          Get the value of a variable.
 String getVariable(String variableName, String defaultValue)
          Get the value of a variable with a default in case the variable is not found.
 void init()
           
 void initializeVariablesFrom(VariableSpace parent)
          Initialize variable space using the defaults, copy over the variables from the parent (using copyVariablesFrom()), after this the "injected" variables should be inserted (injectVariables()).
 void injectVariables(Map<String,String> prop)
          Inject variables.
 boolean isActive()
           
 boolean isFinished()
           
 boolean isInitialized()
           
 boolean isInteractive()
           
 boolean isStopped()
           
 String[] listParameters()
          List the parameters.
 String[] listVariables()
          List the variables (not the values) that are currently in the variable space.
 void removeJobEntryListener(JobEntryListener jobEntryListener)
          Remove a job entry listener from the job
 void removeJobListener(JobListener jobListener)
          Remove a job listener from the job
 void resetErrors()
          Set the number of occured errors to 0.
 void run()
           
static String sendToSlaveServer(JobMeta jobMeta, JobExecutionConfiguration executionConfiguration, Repository repository)
           
 void setBatchId(long batchId)
           
 void setContainerObjectId(String containerObjectId)
           
 void setFinished(boolean finished)
           
 void setInteractive(boolean interactive)
           
 void setInternalKettleVariables(VariableSpace var)
           
 void setJobTracker(JobTracker jobTracker)
           
 void setLogLevel(LogLevel logLevel)
           
 void setParameterValue(String key, String value)
          Set the value of a parameter.
 void setParentJob(Job parentJob)
           
 void setParentVariableSpace(VariableSpace parent)
          Set the parent variable space
 void setPassedBatchId(long jobBatchId)
           
 void setRepository(Repository rep)
           
 void setResult(Result result)
           
 void setSocketRepository(SocketRepository socketRepository)
           
 void setSourceRows(List<RowMetaAndData> sourceRows)
           
 void setStartJobEntryCopy(JobEntryCopy startJobEntryCopy)
           
 void setStopped(boolean stopped)
           
 void setVariable(String variableName, String variableValue)
          Sets a variable in the Kettle Variables list.
 void shareVariablesWith(VariableSpace space)
          Share a variable space from another variable space.
 void stopAll()
           
 String toString()
           
 void waitUntilFinished()
          Wait until this job has finished.
 void waitUntilFinished(long maxMiliseconds)
          Wait until this job has finished.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONFIGURATION_IN_EXPORT_FILENAME

public static final String CONFIGURATION_IN_EXPORT_FILENAME
See Also:
Constant Field Values
Constructor Detail

Job

public Job(String name,
           String file,
           String[] args)

Job

public Job(Repository repository,
           JobMeta jobMeta)

Job

public Job(Repository repository,
           JobMeta jobMeta,
           LoggingObjectInterface parentLogging)

Job

public Job()
Empty constructor, for Class.newInstance()

Method Detail

init

public void init()

toString

public String toString()
Overrides:
toString in class Thread

createJobWithNewClassLoader

public static final Job createJobWithNewClassLoader()
                                             throws KettleException
Throws:
KettleException

getJobname

public String getJobname()

setRepository

public void setRepository(Repository rep)

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread

execute

public Result execute(int nr,
                      Result result)
               throws KettleException
Execute a job with previous results passed in.

Execute called by JobEntryJob: don't clear the jobEntryResults.

Parameters:
nr - The job entry number
result - the result of the previous execution
Returns:
Result of the job execution
Throws:
KettleJobException
KettleException

fireJobListeners

public void fireJobListeners()
                      throws KettleException
Sets the finished flag. Then launch all the job listeners and call the jobFinished method for each.

Throws:
KettleException
See Also:
JobListener.jobFinished(Job)

waitUntilFinished

public void waitUntilFinished()
Wait until this job has finished.


waitUntilFinished

public void waitUntilFinished(long maxMiliseconds)
Wait until this job has finished.

Parameters:
maxMiliseconds - the maximum number of ms to wait

getErrors

public int getErrors()
Get the number of errors that happened in the job.

Returns:
nr of error that have occurred during execution. During execution of a job the number can change.

resetErrors

public void resetErrors()
Set the number of occured errors to 0.


addErrors

public void addErrors(int nrToAdd)
Add a number of errors to the total number of erros that occured during execution.

Parameters:
nrToAdd - nr of errors to add.

beginProcessing

public boolean beginProcessing()
                        throws KettleException
Handle logging at start

Returns:
true if it went OK.
Throws:
KettleException

isActive

public boolean isActive()

stopAll

public void stopAll()

setStopped

public void setStopped(boolean stopped)

isStopped

public boolean isStopped()
Returns:
Returns the stopped status of this Job...

getStartDate

public Date getStartDate()
Returns:
Returns the startDate.

getEndDate

public Date getEndDate()
Returns:
Returns the endDate.

getCurrentDate

public Date getCurrentDate()
Returns:
Returns the currentDate.

getDepDate

public Date getDepDate()
Returns:
Returns the depDate.

getLogDate

public Date getLogDate()
Returns:
Returns the logDate.

getJobMeta

public JobMeta getJobMeta()
Returns:
Returns the jobinfo.

getRep

public Repository getRep()
Returns:
Returns the rep.

getThread

public Thread getThread()

getJobTracker

public JobTracker getJobTracker()
Returns:
Returns the jobTracker.

setJobTracker

public void setJobTracker(JobTracker jobTracker)
Parameters:
jobTracker - The jobTracker to set.

setSourceRows

public void setSourceRows(List<RowMetaAndData> sourceRows)

getSourceRows

public List<RowMetaAndData> getSourceRows()

getParentJob

public Job getParentJob()
Returns:
Returns the parentJob.

setParentJob

public void setParentJob(Job parentJob)
Parameters:
parentJob - The parentJob to set.

getResult

public Result getResult()

setResult

public void setResult(Result result)

isInitialized

public boolean isInitialized()
Returns:
Returns the initialized.

getBatchId

public long getBatchId()
Returns:
Returns the batchId.

setBatchId

public void setBatchId(long batchId)
Parameters:
batchId - The batchId to set.

getPassedBatchId

public long getPassedBatchId()
Returns:
the jobBatchId

setPassedBatchId

public void setPassedBatchId(long jobBatchId)
Parameters:
jobBatchId - the jobBatchId to set

setInternalKettleVariables

public void setInternalKettleVariables(VariableSpace var)

copyVariablesFrom

public void copyVariablesFrom(VariableSpace space)
Description copied from interface: VariableSpace
Copy the variables from another space, without initializing with the defaults. This does not affect any parent relationship.

Specified by:
copyVariablesFrom in interface VariableSpace
Parameters:
space - the space to copy the variables from.

environmentSubstitute

public String environmentSubstitute(String aString)
Description copied from interface: VariableSpace
Substitute the string using the current variable space.

Specified by:
environmentSubstitute in interface VariableSpace
Parameters:
aString - The string to substitute.
Returns:
The substituted string.

environmentSubstitute

public String[] environmentSubstitute(String[] aString)
Description copied from interface: VariableSpace
Replaces environment variables in an array of strings. See also: environmentSubstitute(String string)

Specified by:
environmentSubstitute in interface VariableSpace
Parameters:
aString - The array of strings that wants its variables to be replaced.
Returns:
the array with the environment variables replaced.

getParentVariableSpace

public VariableSpace getParentVariableSpace()
Description copied from interface: VariableSpace
Get the parent of the variable space.

Specified by:
getParentVariableSpace in interface VariableSpace
Returns:
the parent.

setParentVariableSpace

public void setParentVariableSpace(VariableSpace parent)
Description copied from interface: VariableSpace
Set the parent variable space

Specified by:
setParentVariableSpace in interface VariableSpace
Parameters:
parent - The parent variable space to set

getVariable

public String getVariable(String variableName,
                          String defaultValue)
Description copied from interface: VariableSpace
Get the value of a variable with a default in case the variable is not found.

Specified by:
getVariable in interface VariableSpace
Parameters:
variableName - The name of the variable
defaultValue - The default value in case the variable could not be found
Returns:
the String value of a variable

getVariable

public String getVariable(String variableName)
Description copied from interface: VariableSpace
Get the value of a variable.

Specified by:
getVariable in interface VariableSpace
Parameters:
variableName - The name of the variable
Returns:
the String value of a variable or null in case the variable could not be found.

getBooleanValueOfVariable

public boolean getBooleanValueOfVariable(String variableName,
                                         boolean defaultValue)
Description copied from interface: VariableSpace
This method returns a boolean for the new variable check boxes. If the variable name is not set or the variable name is not specified, this method simply returns the default value. If not, it convert the variable value to a boolean. "Y", "YES" and "TRUE" all convert to true. (case insensitive)

Specified by:
getBooleanValueOfVariable in interface VariableSpace
Parameters:
variableName - The variable to look up.
defaultValue - The default value to return.
Returns:
See Also:
static method ValueMeta.convertStringToBoolean()

initializeVariablesFrom

public void initializeVariablesFrom(VariableSpace parent)
Description copied from interface: VariableSpace
Initialize variable space using the defaults, copy over the variables from the parent (using copyVariablesFrom()), after this the "injected" variables should be inserted (injectVariables()). The parent is set as parent variable space.

Specified by:
initializeVariablesFrom in interface VariableSpace
Parameters:
parent - the parent to start from, or null if root.

listVariables

public String[] listVariables()
Description copied from interface: VariableSpace
List the variables (not the values) that are currently in the variable space.

Specified by:
listVariables in interface VariableSpace
Returns:
Array of String variable names.

setVariable

public void setVariable(String variableName,
                        String variableValue)
Description copied from interface: VariableSpace
Sets a variable in the Kettle Variables list.

Specified by:
setVariable in interface VariableSpace
Parameters:
variableName - The name of the variable to set
variableValue - The value of the variable to set. If the variableValue is null, the variable is cleared from the list.

shareVariablesWith

public void shareVariablesWith(VariableSpace space)
Description copied from interface: VariableSpace
Share a variable space from another variable space. This means that the object should take over the space used as argument.

Specified by:
shareVariablesWith in interface VariableSpace
Parameters:
space - Variable space to be shared.

injectVariables

public void injectVariables(Map<String,String> prop)
Description copied from interface: VariableSpace
Inject variables. The behaviour should be that the properties object will be stored and at the time the VariableSpace is initialized (or upon calling this method if the space is already initialized). After injecting the link of the properties object should be removed.

Specified by:
injectVariables in interface VariableSpace
Parameters:
prop - Properties object containing key-value pairs.

getStatus

public String getStatus()

sendToSlaveServer

public static String sendToSlaveServer(JobMeta jobMeta,
                                       JobExecutionConfiguration executionConfiguration,
                                       Repository repository)
                                throws KettleException
Throws:
KettleException

addJobListener

public void addJobListener(JobListener jobListener)
Add a job listener to the job

Parameters:
jobListener - the job listener to add

addJobEntryListener

public void addJobEntryListener(JobEntryListener jobEntryListener)

removeJobListener

public void removeJobListener(JobListener jobListener)
Remove a job listener from the job

Parameters:
jobListener - the job listener to remove

removeJobEntryListener

public void removeJobEntryListener(JobEntryListener jobEntryListener)
Remove a job entry listener from the job

Parameters:
jobListener - the job entry listener to remove

getJobEntryListeners

public List<JobEntryListener> getJobEntryListeners()

getJobListeners

public List<JobListener> getJobListeners()

isFinished

public boolean isFinished()
Returns:
the finished

setFinished

public void setFinished(boolean finished)
Parameters:
finished - the finished to set

addParameterDefinition

public void addParameterDefinition(String key,
                                   String defValue,
                                   String description)
                            throws DuplicateParamException
Description copied from interface: NamedParams
Add a parameter definition to this set. TODO: default, throw exception

Specified by:
addParameterDefinition in interface NamedParams
Parameters:
key - Name of the parameter.
defValue - default value.
description - Description of the parameter.
Throws:
DuplicateParamException - Upon duplicate parameter definitions

getParameterDescription

public String getParameterDescription(String key)
                               throws UnknownParamException
Description copied from interface: NamedParams
Get the description of a parameter.

Specified by:
getParameterDescription in interface NamedParams
Parameters:
key - Key to get value for.
Returns:
description of parameter key.
Throws:
UnknownParamException - Parameter 'key' is unknown.

getParameterDefault

public String getParameterDefault(String key)
                           throws UnknownParamException
Description copied from interface: NamedParams
Get the default value of a parameter.

Specified by:
getParameterDefault in interface NamedParams
Parameters:
key - Key to get value for.
Returns:
default value for parameter key.
Throws:
UnknownParamException - Parameter 'key' is unknown.

getParameterValue

public String getParameterValue(String key)
                         throws UnknownParamException
Description copied from interface: NamedParams
Get the value of a parameter.

Specified by:
getParameterValue in interface NamedParams
Parameters:
key - Key to get value for.
Returns:
value of parameter key.
Throws:
UnknownParamException - Parameter 'key' is unknown.

listParameters

public String[] listParameters()
Description copied from interface: NamedParams
List the parameters.

Specified by:
listParameters in interface NamedParams
Returns:
Array of parameters.

setParameterValue

public void setParameterValue(String key,
                              String value)
                       throws UnknownParamException
Description copied from interface: NamedParams
Set the value of a parameter.

Specified by:
setParameterValue in interface NamedParams
Parameters:
key - key to set value of
value - value to set it to.
Throws:
UnknownParamException - Parameter 'key' is unknown.

eraseParameters

public void eraseParameters()
Description copied from interface: NamedParams
Clear the values.

Specified by:
eraseParameters in interface NamedParams

clearParameters

public void clearParameters()
Description copied from interface: NamedParams
Clear all parameters

Specified by:
clearParameters in interface NamedParams

activateParameters

public void activateParameters()
Description copied from interface: NamedParams
Activate the currently set parameters

Specified by:
activateParameters in interface NamedParams

copyParametersFrom

public void copyParametersFrom(NamedParams params)
Description copied from interface: NamedParams
Copy params to these named parameters (clearing out first).

Specified by:
copyParametersFrom in interface NamedParams
Parameters:
params - the parameters to copy from.

setSocketRepository

public void setSocketRepository(SocketRepository socketRepository)

getSocketRepository

public SocketRepository getSocketRepository()

getLogChannel

public LogChannelInterface getLogChannel()
Specified by:
getLogChannel in interface HasLogChannelInterface

getObjectName

public String getObjectName()
Specified by:
getObjectName in interface LoggingObjectInterface
Returns:
the name

getObjectCopy

public String getObjectCopy()
Specified by:
getObjectCopy in interface LoggingObjectInterface
Returns:
A string identifying a copy in a series of steps...

getFilename

public String getFilename()
Specified by:
getFilename in interface LoggingObjectInterface
Returns:
the filename

getLogChannelId

public String getLogChannelId()
Specified by:
getLogChannelId in interface LoggingObjectInterface
Returns:
the log channel id

getObjectId

public ObjectId getObjectId()
Specified by:
getObjectId in interface LoggingObjectInterface
Returns:
the objectId in a repository

getObjectRevision

public ObjectRevision getObjectRevision()
Specified by:
getObjectRevision in interface LoggingObjectInterface
Returns:
the object revision in a repository

getObjectType

public LoggingObjectType getObjectType()
Specified by:
getObjectType in interface LoggingObjectInterface
Returns:
the objectType

getParent

public LoggingObjectInterface getParent()
Specified by:
getParent in interface LoggingObjectInterface
Returns:
the parent

getRepositoryDirectory

public RepositoryDirectoryInterface getRepositoryDirectory()
Specified by:
getRepositoryDirectory in interface LoggingObjectInterface
Returns:
the repositoryDirectory

getLogLevel

public LogLevel getLogLevel()
Specified by:
getLogLevel in interface LoggingObjectInterface
Returns:
The logging level of the log channel of this logging object.

setLogLevel

public void setLogLevel(LogLevel logLevel)

getLoggingHierarchy

public List<LoggingHierarchy> getLoggingHierarchy()

isInteractive

public boolean isInteractive()
Returns:
the interactive

setInteractive

public void setInteractive(boolean interactive)
Parameters:
interactive - the interactive to set

getActiveJobEntryTransformations

public Map<JobEntryCopy,JobEntryTrans> getActiveJobEntryTransformations()
Returns:
the activeJobEntryTransformations

getActiveJobEntryJobs

public Map<JobEntryCopy,JobEntryJob> getActiveJobEntryJobs()
Returns:
the activeJobEntryJobs

getJobEntryResults

public List<JobEntryResult> getJobEntryResults()
Returns:
A flat list of results in THIS job, in the order of execution of job entries

getContainerObjectId

public String getContainerObjectId()
Specified by:
getContainerObjectId in interface LoggingObjectInterface
Returns:
the carteObjectId

setContainerObjectId

public void setContainerObjectId(String containerObjectId)
Parameters:
containerObjectId - the execution container object id to set

getParentLoggingObject

public LoggingObjectInterface getParentLoggingObject()

getRegistrationDate

public Date getRegistrationDate()
Stub

Specified by:
getRegistrationDate in interface LoggingObjectInterface
Returns:
The registration date of this logging object. Null if it's not registered.

getStartJobEntryCopy

public JobEntryCopy getStartJobEntryCopy()
Returns:
the startJobEntryCopy

setStartJobEntryCopy

public void setStartJobEntryCopy(JobEntryCopy startJobEntryCopy)
Parameters:
startJobEntryCopy - the startJobEntryCopy to set