Class Job

  • All Implemented Interfaces:
    Runnable, ExecutorInterface, org.pentaho.di.core.ExtensionDataInterface, HasLogChannelInterface, org.pentaho.di.core.logging.LoggingObjectInterface, org.pentaho.di.core.logging.LoggingObjectLifecycleInterface, org.pentaho.di.core.parameters.NamedParams, org.pentaho.di.core.variables.VariableSpace

    public class Job
    extends Thread
    implements org.pentaho.di.core.variables.VariableSpace, org.pentaho.di.core.parameters.NamedParams, HasLogChannelInterface, org.pentaho.di.core.logging.LoggingObjectInterface, ExecutorInterface, org.pentaho.di.core.ExtensionDataInterface
    This class executes a job as defined by a JobMeta object.

    The definition of a PDI job is represented by a JobMeta object. It is typically loaded from a .kjb file, a PDI repository, or it is generated dynamically. The declared parameters of the job definition are then queried using listParameters() and assigned values using calls to setParameterValue(..).

    Since:
    07-apr-2003
    Author:
    Matt Casters
    • Field Detail

      • parentJob

        protected Job parentJob
        The job that's launching this (sub-) job. This gives us access to the whole chain, including the parent variables, etc.
      • parentTrans

        protected Trans parentTrans
        The parent transformation
      • arguments

        protected String[] arguments
        The command line arguments for the job.
    • Constructor Detail

      • Job

        public Job​(Repository repository,
                   JobMeta jobMeta,
                   org.pentaho.di.core.logging.LoggingObjectInterface parentLogging)
      • Job

        public Job()
    • Method Detail

      • init

        public void init()
      • toString

        public String toString()
        Gets the name property of the JobMeta property.
        Overrides:
        toString in class Thread
        Returns:
        String name for the JobMeta
      • createJobWithNewClassLoader

        public static final Job createJobWithNewClassLoader()
                                                     throws org.pentaho.di.core.exception.KettleException
        Throws:
        org.pentaho.di.core.exception.KettleException
      • getJobname

        public String getJobname()
      • setRepository

        public void setRepository​(Repository rep)
      • run

        public void run()
        Threads main loop: called by Thread.start();
        Specified by:
        run in interface Runnable
        Overrides:
        run in class Thread
      • execute

        public org.pentaho.di.core.Result execute​(int nr,
                                                  org.pentaho.di.core.Result result)
                                           throws org.pentaho.di.core.exception.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:
        org.pentaho.di.core.exception.KettleJobException
        org.pentaho.di.core.exception.KettleException
      • fireJobFinishListeners

        public void fireJobFinishListeners()
                                    throws org.pentaho.di.core.exception.KettleException
        Sets the finished flag. Then launch all the job listeners and call the jobFinished method for each.
        Throws:
        org.pentaho.di.core.exception.KettleException
        See Also:
        JobListener.jobFinished(Job)
      • fireJobStartListeners

        public void fireJobStartListeners()
                                   throws org.pentaho.di.core.exception.KettleException
        Call all the jobStarted method for each listener.
        Throws:
        org.pentaho.di.core.exception.KettleException
        See Also:
        JobListener.jobStarted(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 org.pentaho.di.core.exception.KettleException
        Handle logging at start
        Returns:
        true if it went OK.
        Throws:
        org.pentaho.di.core.exception.KettleException
      • writeLogTableInformation

        protected void writeLogTableInformation​(JobLogTable jobLogTable,
                                                org.pentaho.di.core.logging.LogStatus status)
                                         throws org.pentaho.di.core.exception.KettleJobException,
                                                org.pentaho.di.core.exception.KettleDatabaseException
        Writes information to Job Log table. Cleans old records, in case job is finished.
        Throws:
        org.pentaho.di.core.exception.KettleJobException
        org.pentaho.di.core.exception.KettleDatabaseException
      • writeLogChannelInformation

        protected void writeLogChannelInformation()
                                           throws org.pentaho.di.core.exception.KettleException
        Write log channel information.
        Throws:
        org.pentaho.di.core.exception.KettleException - the kettle exception
      • writeJobEntryLogInformation

        protected void writeJobEntryLogInformation()
                                            throws org.pentaho.di.core.exception.KettleException
        Write job entry log information.
        Throws:
        org.pentaho.di.core.exception.KettleException - the kettle exception
      • createDataBase

        protected org.pentaho.di.core.database.Database createDataBase​(org.pentaho.di.core.database.DatabaseMeta databaseMeta)
      • isInitialized

        public boolean isInitialized()
      • setInitialized

        protected void setInitialized​(boolean initialized)
      • isActive

        public boolean isActive()
      • setActive

        protected void setActive​(boolean active)
      • isStopped

        public boolean isStopped()
      • stopAll

        public void stopAll()
        Stop all activity by setting the stopped property to true.
      • setStopped

        public void setStopped​(boolean stopped)
        Sets the stopped.
      • isFinished

        public boolean isFinished()
      • setFinished

        public void setFinished​(boolean finished)
      • getStartDate

        public Date getStartDate()
      • getEndDate

        public Date getEndDate()
      • getCurrentDate

        public Date getCurrentDate()
      • getDepDate

        public Date getDepDate()
        Gets the dep date.
        Returns:
        Returns the depDate
      • getLogDate

        public Date getLogDate()
      • getJobMeta

        public JobMeta getJobMeta()
      • getThread

        public Thread getThread()
      • getJobTracker

        public JobTracker getJobTracker()
      • setJobTracker

        public void setJobTracker​(JobTracker jobTracker)
      • setSourceRows

        public void setSourceRows​(List<org.pentaho.di.core.RowMetaAndData> sourceRows)
      • getSourceRows

        public List<org.pentaho.di.core.RowMetaAndData> getSourceRows()
        Gets the source rows.
        Returns:
        the source rows
      • getParentJob

        public Job getParentJob()
        Gets the parent job.
        Returns:
        Returns the parentJob
      • setParentJob

        public void setParentJob​(Job parentJob)
        Sets the parent job.
        Parameters:
        parentJob - The parentJob to set.
      • getResult

        public org.pentaho.di.core.Result getResult()
      • setResult

        public void setResult​(org.pentaho.di.core.Result result)
      • getBatchId

        public long getBatchId()
      • setBatchId

        public void setBatchId​(long batchId)
      • getPassedBatchId

        public long getPassedBatchId()
      • setPassedBatchId

        public void setPassedBatchId​(long jobBatchId)
      • setInternalKettleVariables

        public void setInternalKettleVariables​(org.pentaho.di.core.variables.VariableSpace var)
        Sets the internal kettle variables.
        Parameters:
        var - the new internal kettle variables.
      • setInternalEntryCurrentDirectory

        protected void setInternalEntryCurrentDirectory​(boolean hasFilename,
                                                        boolean hasRepoDir)
      • copyVariablesFrom

        public void copyVariablesFrom​(org.pentaho.di.core.variables.VariableSpace space)
        Specified by:
        copyVariablesFrom in interface org.pentaho.di.core.variables.VariableSpace
      • environmentSubstitute

        public String environmentSubstitute​(String aString)
        Specified by:
        environmentSubstitute in interface org.pentaho.di.core.variables.VariableSpace
      • environmentSubstitute

        public String[] environmentSubstitute​(String[] aString)
        Specified by:
        environmentSubstitute in interface org.pentaho.di.core.variables.VariableSpace
      • fieldSubstitute

        public String fieldSubstitute​(String aString,
                                      org.pentaho.di.core.row.RowMetaInterface rowMeta,
                                      Object[] rowData)
                               throws org.pentaho.di.core.exception.KettleValueException
        Specified by:
        fieldSubstitute in interface org.pentaho.di.core.variables.VariableSpace
        Throws:
        org.pentaho.di.core.exception.KettleValueException
      • getParentVariableSpace

        public org.pentaho.di.core.variables.VariableSpace getParentVariableSpace()
        Specified by:
        getParentVariableSpace in interface org.pentaho.di.core.variables.VariableSpace
      • setParentVariableSpace

        public void setParentVariableSpace​(org.pentaho.di.core.variables.VariableSpace parent)
        Specified by:
        setParentVariableSpace in interface org.pentaho.di.core.variables.VariableSpace
      • getVariable

        public String getVariable​(String variableName,
                                  String defaultValue)
        Specified by:
        getVariable in interface org.pentaho.di.core.variables.VariableSpace
      • getVariable

        public String getVariable​(String variableName)
        Specified by:
        getVariable in interface org.pentaho.di.core.variables.VariableSpace
      • getBooleanValueOfVariable

        public boolean getBooleanValueOfVariable​(String variableName,
                                                 boolean defaultValue)
        Specified by:
        getBooleanValueOfVariable in interface org.pentaho.di.core.variables.VariableSpace
      • initializeVariablesFrom

        public void initializeVariablesFrom​(org.pentaho.di.core.variables.VariableSpace parent)
        Specified by:
        initializeVariablesFrom in interface org.pentaho.di.core.variables.VariableSpace
      • listVariables

        public String[] listVariables()
        Specified by:
        listVariables in interface org.pentaho.di.core.variables.VariableSpace
      • setVariable

        public void setVariable​(String variableName,
                                String variableValue)
        Specified by:
        setVariable in interface org.pentaho.di.core.variables.VariableSpace
      • shareVariablesWith

        public void shareVariablesWith​(org.pentaho.di.core.variables.VariableSpace space)
        Specified by:
        shareVariablesWith in interface org.pentaho.di.core.variables.VariableSpace
      • injectVariables

        public void injectVariables​(Map<String,​String> prop)
        Specified by:
        injectVariables in interface org.pentaho.di.core.variables.VariableSpace
      • getStatus

        public String getStatus()
      • sendToSlaveServer

        public static String sendToSlaveServer​(JobMeta jobMeta,
                                               JobExecutionConfiguration executionConfiguration,
                                               Repository repository,
                                               org.pentaho.metastore.api.IMetaStore metaStore)
                                        throws org.pentaho.di.core.exception.KettleException
        Send to slave server.
        Parameters:
        jobMeta - the job meta
        executionConfiguration - the execution configuration
        repository - the repository
        metaStore - the metaStore
        Returns:
        the string
        Throws:
        org.pentaho.di.core.exception.KettleException - the kettle exception
      • addJobListener

        public void addJobListener​(JobListener jobListener)
      • addJobEntryListener

        public void addJobEntryListener​(JobEntryListener jobEntryListener)
      • removeJobListener

        public void removeJobListener​(JobListener jobListener)
      • removeJobEntryListener

        public void removeJobEntryListener​(JobEntryListener jobEntryListener)
      • addParameterDefinition

        public void addParameterDefinition​(String key,
                                           String defValue,
                                           String description)
                                    throws org.pentaho.di.core.parameters.DuplicateParamException
        Specified by:
        addParameterDefinition in interface org.pentaho.di.core.parameters.NamedParams
        Throws:
        org.pentaho.di.core.parameters.DuplicateParamException
      • getParameterDescription

        public String getParameterDescription​(String key)
                                       throws org.pentaho.di.core.parameters.UnknownParamException
        Specified by:
        getParameterDescription in interface org.pentaho.di.core.parameters.NamedParams
        Throws:
        org.pentaho.di.core.parameters.UnknownParamException
      • getParameterDefault

        public String getParameterDefault​(String key)
                                   throws org.pentaho.di.core.parameters.UnknownParamException
        Specified by:
        getParameterDefault in interface org.pentaho.di.core.parameters.NamedParams
        Throws:
        org.pentaho.di.core.parameters.UnknownParamException
      • getParameterValue

        public String getParameterValue​(String key)
                                 throws org.pentaho.di.core.parameters.UnknownParamException
        Specified by:
        getParameterValue in interface org.pentaho.di.core.parameters.NamedParams
        Throws:
        org.pentaho.di.core.parameters.UnknownParamException
      • listParameters

        public String[] listParameters()
        Specified by:
        listParameters in interface org.pentaho.di.core.parameters.NamedParams
      • setParameterValue

        public void setParameterValue​(String key,
                                      String value)
                               throws org.pentaho.di.core.parameters.UnknownParamException
        Specified by:
        setParameterValue in interface org.pentaho.di.core.parameters.NamedParams
        Throws:
        org.pentaho.di.core.parameters.UnknownParamException
      • eraseParameters

        public void eraseParameters()
        Specified by:
        eraseParameters in interface org.pentaho.di.core.parameters.NamedParams
      • clearParameters

        public void clearParameters()
        Specified by:
        clearParameters in interface org.pentaho.di.core.parameters.NamedParams
      • activateParameters

        public void activateParameters()
        Specified by:
        activateParameters in interface org.pentaho.di.core.parameters.NamedParams
      • copyParametersFrom

        public void copyParametersFrom​(org.pentaho.di.core.parameters.NamedParams params)
        Specified by:
        copyParametersFrom in interface org.pentaho.di.core.parameters.NamedParams
      • mergeParametersWith

        public void mergeParametersWith​(org.pentaho.di.core.parameters.NamedParams params,
                                        boolean replace)
        Specified by:
        mergeParametersWith in interface org.pentaho.di.core.parameters.NamedParams
      • setSocketRepository

        public void setSocketRepository​(SocketRepository socketRepository)
        Sets the socket repository.
        Parameters:
        socketRepository - the new socket repository
      • getSocketRepository

        public SocketRepository getSocketRepository()
        Gets the socket repository.
        Returns:
        the socket repository
      • getLogChannel

        public org.pentaho.di.core.logging.LogChannelInterface getLogChannel()
        Gets the log channel interface.
        Specified by:
        getLogChannel in interface HasLogChannelInterface
        Returns:
        LogChannelInterface
      • getObjectName

        public String getObjectName()
        Gets the job name.
        Specified by:
        getObjectName in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        jobName
      • getObjectCopy

        public String getObjectCopy()
        Always returns null for Job.
        Specified by:
        getObjectCopy in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        null
      • getFilename

        public String getFilename()
        Gets the file name.
        Specified by:
        getFilename in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        the filename
      • getLogChannelId

        public String getLogChannelId()
        Gets the log channel id.
        Specified by:
        getLogChannelId in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        the logChannelId
      • getObjectId

        public org.pentaho.di.repository.ObjectId getObjectId()
        Gets the jobMeta's object id.
        Specified by:
        getObjectId in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        ObjectId
      • getObjectRevision

        public org.pentaho.di.repository.ObjectRevision getObjectRevision()
        Gets the job meta's object revision.
        Specified by:
        getObjectRevision in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        ObjectRevision
      • getObjectType

        public org.pentaho.di.core.logging.LoggingObjectType getObjectType()
        Gets LoggingObjectType.JOB, which is always the value for Job.
        Specified by:
        getObjectType in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        LoggingObjectType LoggingObjectType.JOB
      • getParent

        public org.pentaho.di.core.logging.LoggingObjectInterface getParent()
        Gets parent logging object.
        Specified by:
        getParent in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        parentLoggingObject
      • getRepositoryDirectory

        public org.pentaho.di.repository.RepositoryDirectoryInterface getRepositoryDirectory()
        Gets the job meta's repository directory interface.
        Specified by:
        getRepositoryDirectory in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        RepositoryDirectoryInterface
      • getLogLevel

        public org.pentaho.di.core.logging.LogLevel getLogLevel()
        Gets the logLevel.
        Specified by:
        getLogLevel in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        logLevel
      • setLogLevel

        public void setLogLevel​(org.pentaho.di.core.logging.LogLevel logLevel)
        Sets the log level.
        Parameters:
        logLevel - the new log level
      • getLoggingHierarchy

        public List<org.pentaho.di.core.logging.LoggingHierarchy> getLoggingHierarchy()
        Gets the logging hierarchy.
        Returns:
        the logging hierarchy
      • isInteractive

        public boolean isInteractive()
        Gets the boolean value of interactive.
        Returns:
        the interactive
      • setInteractive

        public void setInteractive​(boolean interactive)
        Sets the value of interactive.
        Parameters:
        interactive - the interactive to set
      • getActiveJobEntryTransformations

        public Map<JobEntryCopy,​JobEntryTrans> getActiveJobEntryTransformations()
        Gets the activeJobEntryTransformations.
        Returns:
        the activeJobEntryTransformations
      • getActiveJobEntryJobs

        public Map<JobEntryCopy,​JobEntryJob> getActiveJobEntryJobs()
        Gets the activeJobEntryJobs.
        Returns:
        the activeJobEntryJobs
      • getJobEntryResults

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

        public String getContainerObjectId()
        Gets the carteObjectId.
        Specified by:
        getContainerObjectId in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        the carteObjectId
      • setContainerObjectId

        public void setContainerObjectId​(String containerObjectId)
        Sets the execution container object id (containerObjectId).
        Parameters:
        containerObjectId - the execution container object id to set
      • getParentLoggingObject

        public org.pentaho.di.core.logging.LoggingObjectInterface getParentLoggingObject()
        Gets the parent logging object.
        Returns:
        the parent logging object
      • getRegistrationDate

        public Date getRegistrationDate()
        Gets the registration date. For job, this always returns null
        Specified by:
        getRegistrationDate in interface org.pentaho.di.core.logging.LoggingObjectInterface
        Returns:
        null
      • getStartJobEntryCopy

        public JobEntryCopy getStartJobEntryCopy()
        Gets the start job entry copy.
        Returns:
        the startJobEntryCopy
      • setStartJobEntryCopy

        public void setStartJobEntryCopy​(JobEntryCopy startJobEntryCopy)
        Sets the start job entry copy.
        Parameters:
        startJobEntryCopy - the startJobEntryCopy to set
      • setExecutingServer

        public void setExecutingServer​(String executingServer)
        Sets the executing server.
        Specified by:
        setExecutingServer in interface ExecutorInterface
        Parameters:
        executingServer - the executingServer to set
      • setExecutingUser

        public void setExecutingUser​(String executingUser)
        Sets the executing user.
        Specified by:
        setExecutingUser in interface ExecutorInterface
        Parameters:
        executingUser - the executingUser to set
      • isGatheringMetrics

        public boolean isGatheringMetrics()
        Specified by:
        isGatheringMetrics in interface org.pentaho.di.core.logging.LoggingObjectInterface
      • setGatheringMetrics

        public void setGatheringMetrics​(boolean gatheringMetrics)
        Specified by:
        setGatheringMetrics in interface org.pentaho.di.core.logging.LoggingObjectInterface
      • isForcingSeparateLogging

        public boolean isForcingSeparateLogging()
        Specified by:
        isForcingSeparateLogging in interface org.pentaho.di.core.logging.LoggingObjectInterface
      • setForcingSeparateLogging

        public void setForcingSeparateLogging​(boolean forcingSeparateLogging)
        Specified by:
        setForcingSeparateLogging in interface org.pentaho.di.core.logging.LoggingObjectInterface
      • getTransactionId

        public String getTransactionId()
        Gets the transaction id.
        Returns:
        the transactionId
      • setTransactionId

        public void setTransactionId​(String transactionId)
        Sets the transaction id.
        Parameters:
        transactionId - the transactionId to set
      • setDelegationListeners

        public void setDelegationListeners​(List<DelegationListener> delegationListeners)
      • addDelegationListener

        public void addDelegationListener​(DelegationListener delegationListener)
      • getArguments

        public String[] getArguments()
      • setArguments

        public void setArguments​(String[] arguments)
      • getParentTrans

        public Trans getParentTrans()
      • setParentTrans

        public void setParentTrans​(Trans parentTrans)
      • getExtensionDataMap

        public Map<String,​Object> getExtensionDataMap()
        Specified by:
        getExtensionDataMap in interface org.pentaho.di.core.ExtensionDataInterface
      • getStartJobEntryResult

        public org.pentaho.di.core.Result getStartJobEntryResult()
      • setStartJobEntryResult

        public void setStartJobEntryResult​(org.pentaho.di.core.Result startJobEntryResult)
      • startHeartbeat

        protected ExecutorService startHeartbeat​(long intervalInSeconds)
      • shutdownHeartbeat

        protected void shutdownHeartbeat​(ExecutorService heartbeat)
      • callBeforeLog

        public void callBeforeLog()
        Specified by:
        callBeforeLog in interface org.pentaho.di.core.logging.LoggingObjectLifecycleInterface
      • callAfterLog

        public void callAfterLog()
        Specified by:
        callAfterLog in interface org.pentaho.di.core.logging.LoggingObjectLifecycleInterface