Search in sources :

Example 6 with KettleJobException

use of org.pentaho.di.core.exception.KettleJobException in project pentaho-kettle by pentaho.

the class Job method beginProcessing.

/**
 * Handle logging at start
 *
 * @return true if it went OK.
 *
 * @throws KettleException
 */
public boolean beginProcessing() throws KettleException {
    currentDate = new Date();
    logDate = new Date();
    startDate = Const.MIN_DATE;
    endDate = currentDate;
    resetErrors();
    final JobLogTable jobLogTable = jobMeta.getJobLogTable();
    int intervalInSeconds = Const.toInt(environmentSubstitute(jobLogTable.getLogInterval()), -1);
    if (jobLogTable.isDefined()) {
        DatabaseMeta logcon = jobMeta.getJobLogTable().getDatabaseMeta();
        String schemaName = environmentSubstitute(jobMeta.getJobLogTable().getActualSchemaName());
        String tableName = environmentSubstitute(jobMeta.getJobLogTable().getActualTableName());
        String schemaAndTable = jobMeta.getJobLogTable().getDatabaseMeta().getQuotedSchemaTableCombination(schemaName, tableName);
        Database ldb = new Database(this, logcon);
        ldb.shareVariablesWith(this);
        ldb.connect();
        ldb.setCommit(logCommitSize);
        try {
            // See if we have to add a batch id...
            Long id_batch = new Long(1);
            if (jobMeta.getJobLogTable().isBatchIdUsed()) {
                id_batch = logcon.getNextBatchId(ldb, schemaName, tableName, jobLogTable.getKeyField().getFieldName());
                setBatchId(id_batch.longValue());
                if (getPassedBatchId() <= 0) {
                    setPassedBatchId(id_batch.longValue());
                }
            }
            Object[] lastr = ldb.getLastLogDate(schemaAndTable, jobMeta.getName(), true, LogStatus.END);
            if (!Utils.isEmpty(lastr)) {
                Date last;
                try {
                    last = ldb.getReturnRowMeta().getDate(lastr, 0);
                } catch (KettleValueException e) {
                    throw new KettleJobException(BaseMessages.getString(PKG, "Job.Log.ConversionError", "" + tableName), e);
                }
                if (last != null) {
                    startDate = last;
                }
            }
            depDate = currentDate;
            ldb.writeLogRecord(jobMeta.getJobLogTable(), LogStatus.START, this, null);
            if (!ldb.isAutoCommit()) {
                ldb.commitLog(true, jobMeta.getJobLogTable());
            }
            ldb.disconnect();
            // 
            if (intervalInSeconds > 0) {
                final Timer timer = new Timer(getName() + " - interval logging timer");
                TimerTask timerTask = new TimerTask() {

                    public void run() {
                        try {
                            endProcessing();
                        } catch (Exception e) {
                            log.logError(BaseMessages.getString(PKG, "Job.Exception.UnableToPerformIntervalLogging"), e);
                            // Also stop the show...
                            // 
                            errors.incrementAndGet();
                            stopAll();
                        }
                    }
                };
                timer.schedule(timerTask, intervalInSeconds * 1000, intervalInSeconds * 1000);
                addJobListener(new JobAdapter() {

                    public void jobFinished(Job job) {
                        timer.cancel();
                    }
                });
            }
            // Add a listener at the end of the job to take of writing the final job
            // log record...
            // 
            addJobListener(new JobAdapter() {

                public void jobFinished(Job job) throws KettleException {
                    try {
                        endProcessing();
                    } catch (KettleJobException e) {
                        log.logError(BaseMessages.getString(PKG, "Job.Exception.UnableToWriteToLoggingTable", jobLogTable.toString()), e);
                        // job is failed in case log database record is failed!
                        throw new KettleException(e);
                    }
                }
            });
        } catch (KettleDatabaseException dbe) {
            // This is even before actual execution
            addErrors(1);
            throw new KettleJobException(BaseMessages.getString(PKG, "Job.Log.UnableToProcessLoggingStart", "" + tableName), dbe);
        } finally {
            ldb.disconnect();
        }
    }
    // If we need to write out the job entry logging information, do so at the end of the job:
    // 
    JobEntryLogTable jobEntryLogTable = jobMeta.getJobEntryLogTable();
    if (jobEntryLogTable.isDefined()) {
        addJobListener(new JobAdapter() {

            public void jobFinished(Job job) throws KettleException {
                try {
                    writeJobEntryLogInformation();
                } catch (KettleException e) {
                    throw new KettleException(BaseMessages.getString(PKG, "Job.Exception.UnableToPerformJobEntryLoggingAtJobEnd"), e);
                }
            }
        });
    }
    // If we need to write the log channel hierarchy and lineage information,
    // add a listener for that too...
    // 
    ChannelLogTable channelLogTable = jobMeta.getChannelLogTable();
    if (channelLogTable.isDefined()) {
        addJobListener(new JobAdapter() {

            public void jobFinished(Job job) throws KettleException {
                try {
                    writeLogChannelInformation();
                } catch (KettleException e) {
                    throw new KettleException(BaseMessages.getString(PKG, "Job.Exception.UnableToPerformLoggingAtTransEnd"), e);
                }
            }
        });
    }
    JobExecutionExtension extension = new JobExecutionExtension(this, result, null, false);
    ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.JobBeginProcessing.id, extension);
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobLogTable(org.pentaho.di.core.logging.JobLogTable) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Date(java.util.Date) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) KettleJobException(org.pentaho.di.core.exception.KettleJobException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleJobException(org.pentaho.di.core.exception.KettleJobException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) Database(org.pentaho.di.core.database.Database) FileObject(org.apache.commons.vfs2.FileObject) JobEntryLogTable(org.pentaho.di.core.logging.JobEntryLogTable) KettleValueException(org.pentaho.di.core.exception.KettleValueException) JobEntryJob(org.pentaho.di.job.entries.job.JobEntryJob)

Example 7 with KettleJobException

use of org.pentaho.di.core.exception.KettleJobException in project pentaho-kettle by pentaho.

the class RepositoryBrowserController method rename.

public ObjectId rename(String id, String path, String newName, String type, String oldName) throws KettleException {
    RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
    ObjectId objectId = null;
    switch(type) {
        case JOB:
            if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.JOB)) {
                throw new KettleObjectExistsException();
            }
            if (isJobOpened(id, path, oldName)) {
                throw new KettleJobException();
            }
            renameRecent(id, type, newName);
            objectId = getRepository().renameJob(() -> id, repositoryDirectoryInterface, newName);
            break;
        case TRANSFORMATION:
            if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.TRANSFORMATION)) {
                throw new KettleObjectExistsException();
            }
            if (isTransOpened(id, path, oldName)) {
                throw new KettleTransException();
            }
            renameRecent(id, type, newName);
            objectId = getRepository().renameTransformation(() -> id, repositoryDirectoryInterface, newName);
            break;
        case FOLDER:
            isFileOpenedInFolder(path);
            RepositoryDirectoryInterface parent = findDirectory(path).getParent();
            if (parent == null) {
                parent = findDirectory(path);
            }
            RepositoryDirectoryInterface child = parent.findChild(newName);
            if (child != null) {
                throw new KettleObjectExistsException();
            }
            if (getRepository() instanceof RepositoryExtended) {
                objectId = ((RepositoryExtended) getRepository()).renameRepositoryDirectory(() -> id, null, newName, true);
            } else {
                objectId = getRepository().renameRepositoryDirectory(() -> id, null, newName);
            }
            break;
    }
    return objectId;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Example 8 with KettleJobException

use of org.pentaho.di.core.exception.KettleJobException in project pentaho-kettle by pentaho.

the class RepositoryBrowserController method remove.

public boolean remove(String id, String name, String path, String type) throws KettleException {
    try {
        switch(type) {
            case JOB:
                if (isJobOpened(id, path, name)) {
                    throw new KettleJobException();
                }
                getRepository().deleteJob(() -> id);
                break;
            case TRANSFORMATION:
                if (isTransOpened(id, path, name)) {
                    throw new KettleTransException();
                }
                getRepository().deleteTransformation(() -> id);
                break;
            case FOLDER:
                isFileOpenedInFolder(path);
                removeRecentsUsingPath(path);
                RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
                if (getRepository() instanceof RepositoryExtended) {
                    ((RepositoryExtended) getRepository()).deleteRepositoryDirectory(repositoryDirectoryInterface, true);
                } else {
                    getRepository().deleteRepositoryDirectory(repositoryDirectoryInterface);
                }
                break;
        }
        return true;
    } catch (KettleTransException | KettleJobException ke) {
        throw ke;
    } catch (Exception e) {
        return false;
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleTransException(org.pentaho.di.core.exception.KettleTransException) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) KettleJobException(org.pentaho.di.core.exception.KettleJobException) KettleException(org.pentaho.di.core.exception.KettleException) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Example 9 with KettleJobException

use of org.pentaho.di.core.exception.KettleJobException in project pentaho-kettle by pentaho.

the class SFTPClient method setProxy.

public void setProxy(String host, String port, String user, String pass, String proxyType) throws KettleJobException {
    if (Utils.isEmpty(host) || Const.toInt(port, 0) == 0) {
        throw new KettleJobException("Proxy server name must be set and server port must be greater than zero.");
    }
    Proxy proxy = null;
    String proxyhost = host + ":" + port;
    if (proxyType.equals(PROXY_TYPE_HTTP)) {
        proxy = new ProxyHTTP(proxyhost);
        if (!Utils.isEmpty(user)) {
            ((ProxyHTTP) proxy).setUserPasswd(user, pass);
        }
    } else if (proxyType.equals(PROXY_TYPE_SOCKS5)) {
        proxy = new ProxySOCKS5(proxyhost);
        if (!Utils.isEmpty(user)) {
            ((ProxySOCKS5) proxy).setUserPasswd(user, pass);
        }
    }
    s.setProxy(proxy);
}
Also used : Proxy(com.jcraft.jsch.Proxy) ProxySOCKS5(com.jcraft.jsch.ProxySOCKS5) ProxyHTTP(com.jcraft.jsch.ProxyHTTP) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Example 10 with KettleJobException

use of org.pentaho.di.core.exception.KettleJobException in project pentaho-kettle by pentaho.

the class SFTPClient method put.

public void put(FileObject fileObject, String remoteFile) throws KettleJobException {
    int mode = ChannelSftp.OVERWRITE;
    InputStream inputStream = null;
    try {
        inputStream = KettleVFS.getInputStream(fileObject);
        c.put(inputStream, remoteFile, null, mode);
    } catch (Exception e) {
        throw new KettleJobException(e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                throw new KettleJobException(e);
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) KettleJobException(org.pentaho.di.core.exception.KettleJobException) SftpException(com.jcraft.jsch.SftpException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) JSchException(com.jcraft.jsch.JSchException) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Aggregations

KettleJobException (org.pentaho.di.core.exception.KettleJobException)16 SftpException (com.jcraft.jsch.SftpException)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 KettleException (org.pentaho.di.core.exception.KettleException)4 JSchException (com.jcraft.jsch.JSchException)3 IOException (java.io.IOException)3 FileObject (org.apache.commons.vfs2.FileObject)3 Result (org.pentaho.di.core.Result)3 KettleTransException (org.pentaho.di.core.exception.KettleTransException)3 InputStream (java.io.InputStream)2 Date (java.util.Date)2 Database (org.pentaho.di.core.database.Database)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 KettleObjectExistsException (org.pentaho.di.core.exception.KettleObjectExistsException)2 KettleValueException (org.pentaho.di.core.exception.KettleValueException)2 JobLogTable (org.pentaho.di.core.logging.JobLogTable)2 DuplicateParamException (org.pentaho.di.core.parameters.DuplicateParamException)2 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2