Search in sources :

Example 1 with LogStatus

use of org.pentaho.di.core.logging.LogStatus in project pentaho-kettle by pentaho.

the class Trans method endProcessing.

/**
 * End processing. Also handle any logging operations associated with the end of a transformation
 *
 * @return true if all end processing is successful, false otherwise
 * @throws KettleException if any errors occur during processing
 */
private synchronized boolean endProcessing() throws KettleException {
    LogStatus status;
    if (isStopped()) {
        status = LogStatus.STOP;
    } else if (isFinished()) {
        status = LogStatus.END;
    } else if (isPaused()) {
        status = LogStatus.PAUSED;
    } else {
        status = LogStatus.RUNNING;
    }
    TransLogTable transLogTable = transMeta.getTransLogTable();
    int intervalInSeconds = Const.toInt(environmentSubstitute(transLogTable.getLogInterval()), -1);
    logDate = new Date();
    // OK, we have some logging to do...
    // 
    DatabaseMeta logcon = transMeta.getTransLogTable().getDatabaseMeta();
    String logTable = transMeta.getTransLogTable().getActualTableName();
    if (logcon != null) {
        Database ldb = null;
        try {
            // 
            if (transLogTableDatabaseConnection == null) {
                ldb = new Database(this, logcon);
                ldb.shareVariablesWith(this);
                ldb.connect();
                ldb.setCommit(logCommitSize);
                transLogTableDatabaseConnection = ldb;
            } else {
                ldb = transLogTableDatabaseConnection;
            }
            // 
            if (!Utils.isEmpty(logTable)) {
                ldb.writeLogRecord(transLogTable, status, this, null);
            }
            // 
            if (status.equals(LogStatus.END) || status.equals(LogStatus.STOP)) {
                ldb.cleanupLogRecords(transLogTable, getName());
            }
            // 
            if (!ldb.isAutoCommit()) {
                ldb.commitLog(true, transMeta.getTransLogTable());
            }
        } catch (KettleDatabaseException e) {
            // PDI-9790 error write to log db is transaction error
            log.logError(BaseMessages.getString(PKG, "Database.Error.WriteLogTable", logTable), e);
            errors.incrementAndGet();
        // end PDI-9790
        } catch (Exception e) {
            throw new KettleException(BaseMessages.getString(PKG, "Trans.Exception.ErrorWritingLogRecordToTable", transMeta.getTransLogTable().getActualTableName()), e);
        } finally {
            if (intervalInSeconds <= 0 || (status.equals(LogStatus.END) || status.equals(LogStatus.STOP))) {
                ldb.disconnect();
                // disconnected
                transLogTableDatabaseConnection = null;
            }
        }
    }
    return true;
}
Also used : LogStatus(org.pentaho.di.core.logging.LogStatus) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Database(org.pentaho.di.core.database.Database) TransLogTable(org.pentaho.di.core.logging.TransLogTable) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) Date(java.util.Date) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Example 2 with LogStatus

use of org.pentaho.di.core.logging.LogStatus in project pentaho-kettle by pentaho.

the class JobHistoryDelegate method displayHistoryData.

private void displayHistoryData(final int index) {
    JobHistoryLogTab model = models[index];
    if (model.logDisplayTableView == null || model.logDisplayTableView.isDisposed()) {
        return;
    }
    // display the data in the table view
    ColumnInfo[] colinf = model.logDisplayTableView.getColumns();
    int selectionIndex = model.logDisplayTableView.getSelectionIndex();
    model.logDisplayTableView.table.clearAll();
    List<Object[]> rows = model.rows;
    LogTableField errorsField = model.logTable.getErrorsField();
    LogTableField statusField = model.logTable.getStatusField();
    if (rows != null && rows.size() > 0) {
        // we need to map ui columns to db columns before rendering data
        Map<String, Integer> map = getColumnMappings(model);
        // add row data to the table view
        for (Object[] rowData : rows) {
            TableItem item = new TableItem(model.logDisplayTableView.table, SWT.NONE);
            for (int c = 0; c < colinf.length; c++) {
                ColumnInfo column = colinf[c];
                ValueMetaInterface valueMeta = column.getValueMeta();
                String string = null;
                try {
                    string = valueMeta.getString(rowData[map.get(column.getValueMeta().getName())]);
                } catch (KettleValueException e) {
                    log.logError("history data conversion issue", e);
                }
                item.setText(c + 1, Const.NVL(string, ""));
            }
            // Add some color
            // 
            Long errors = null;
            LogStatus status = null;
            if (errorsField != null) {
                ValueMetaInterface valueMeta = getValueMetaForColumn(colinf, errorsField);
                try {
                    errors = valueMeta.getInteger(rowData[map.get(valueMeta.getName())]);
                } catch (KettleValueException e) {
                    log.logError("history data conversion issue", e);
                }
            }
            if (statusField != null) {
                ValueMetaInterface valueMeta = getValueMetaForColumn(colinf, statusField);
                String statusString = null;
                try {
                    statusString = valueMeta.getString(rowData[map.get(valueMeta.getName())]);
                } catch (KettleValueException e) {
                    log.logError("history data conversion issue", e);
                }
                if (statusString != null) {
                    status = LogStatus.findStatus(statusString);
                }
            }
            if (errors != null && errors > 0L) {
                item.setBackground(GUIResource.getInstance().getColorRed());
            } else if (status != null && LogStatus.STOP.equals(status)) {
                item.setBackground(GUIResource.getInstance().getColorYellow());
            }
        }
        model.logDisplayTableView.removeEmptyRows();
        model.logDisplayTableView.setRowNums();
        model.logDisplayTableView.optWidth(true);
    } else {
        model.logDisplayTableView.clearAll(false);
    }
    if (selectionIndex >= 0 && selectionIndex < model.logDisplayTableView.getItemCount()) {
        model.logDisplayTableView.table.select(selectionIndex);
        showLogEntry();
    }
}
Also used : LogTableField(org.pentaho.di.core.logging.LogTableField) TableItem(org.eclipse.swt.widgets.TableItem) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) LogStatus(org.pentaho.di.core.logging.LogStatus) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 3 with LogStatus

use of org.pentaho.di.core.logging.LogStatus in project pentaho-kettle by pentaho.

the class TransHistoryDelegate method displayHistoryData.

private void displayHistoryData(final int index) {
    TransHistoryLogTab model = models[index];
    if (model.logDisplayTableView == null || model.logDisplayTableView.isDisposed()) {
        return;
    }
    // display the data in the table view
    ColumnInfo[] colinf = model.logDisplayTableView.getColumns();
    int selectionIndex = model.logDisplayTableView.getSelectionIndex();
    model.logDisplayTableView.table.clearAll();
    List<Object[]> rows = model.rows;
    LogTableField errorsField = model.logTable.getErrorsField();
    LogTableField statusField = model.logTable.getStatusField();
    if (rows != null && rows.size() > 0) {
        // we need to map ui columns to db columns before rendering data
        Map<String, Integer> map = getColumnMappings(model);
        // add row data to the table view
        for (Object[] rowData : rows) {
            TableItem item = new TableItem(model.logDisplayTableView.table, SWT.NONE);
            for (int c = 0; c < colinf.length; c++) {
                ColumnInfo column = colinf[c];
                ValueMetaInterface valueMeta = column.getValueMeta();
                String string = null;
                try {
                    string = valueMeta.getString(rowData[map.get(column.getValueMeta().getName())]);
                } catch (KettleValueException e) {
                    log.logError("history data conversion issue", e);
                }
                item.setText(c + 1, Const.NVL(string, ""));
            }
            // Add some color
            // 
            Long errors = null;
            LogStatus status = null;
            if (errorsField != null) {
                ValueMetaInterface valueMeta = getValueMetaForColumn(colinf, errorsField);
                try {
                    errors = valueMeta.getInteger(rowData[map.get(valueMeta.getName())]);
                } catch (KettleValueException e) {
                    log.logError("history data conversion issue", e);
                }
            }
            if (statusField != null) {
                ValueMetaInterface valueMeta = getValueMetaForColumn(colinf, statusField);
                String statusString = null;
                try {
                    statusString = valueMeta.getString(rowData[map.get(valueMeta.getName())]);
                } catch (KettleValueException e) {
                    log.logError("history data conversion issue", e);
                }
                if (statusString != null) {
                    status = LogStatus.findStatus(statusString);
                }
            }
            if (errors != null && errors > 0L) {
                item.setBackground(GUIResource.getInstance().getColorRed());
            } else if (status != null && LogStatus.STOP.equals(status)) {
                item.setBackground(GUIResource.getInstance().getColorYellow());
            }
        }
        model.logDisplayTableView.removeEmptyRows();
        model.logDisplayTableView.setRowNums();
        model.logDisplayTableView.optWidth(true);
    } else {
        model.logDisplayTableView.clearAll(false);
    }
    if (selectionIndex >= 0 && selectionIndex < model.logDisplayTableView.getItemCount()) {
        model.logDisplayTableView.table.select(selectionIndex);
        showLogEntry();
    }
}
Also used : LogTableField(org.pentaho.di.core.logging.LogTableField) TableItem(org.eclipse.swt.widgets.TableItem) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) LogStatus(org.pentaho.di.core.logging.LogStatus) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 4 with LogStatus

use of org.pentaho.di.core.logging.LogStatus in project pentaho-kettle by pentaho.

the class Job method endProcessing.

// 
// Handle logging at end
/**
 * End processing.
 *
 * @return true, if successful
 * @throws KettleJobException
 *           the kettle job exception
 */
private boolean endProcessing() throws KettleJobException {
    LogStatus status;
    if (!isActive()) {
        if (isStopped()) {
            status = LogStatus.STOP;
        } else {
            status = LogStatus.END;
        }
    } else {
        status = LogStatus.RUNNING;
    }
    try {
        if (errors.get() == 0 && result != null && !result.getResult()) {
            errors.incrementAndGet();
        }
        logDate = new Date();
        /*
       * Sums errors, read, written, etc.
       */
        JobLogTable jobLogTable = jobMeta.getJobLogTable();
        if (jobLogTable.isDefined()) {
            writeLogTableInformation(jobLogTable, status);
        }
        return true;
    } catch (Exception e) {
        // In case something else goes wrong.
        throw new KettleJobException(e);
    }
}
Also used : LogStatus(org.pentaho.di.core.logging.LogStatus) JobLogTable(org.pentaho.di.core.logging.JobLogTable) Date(java.util.Date) 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) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Aggregations

KettleValueException (org.pentaho.di.core.exception.KettleValueException)4 LogStatus (org.pentaho.di.core.logging.LogStatus)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 Date (java.util.Date)2 TableItem (org.eclipse.swt.widgets.TableItem)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 KettleException (org.pentaho.di.core.exception.KettleException)2 LogTableField (org.pentaho.di.core.logging.LogTableField)2 DuplicateParamException (org.pentaho.di.core.parameters.DuplicateParamException)2 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Database (org.pentaho.di.core.database.Database)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 KettleFileException (org.pentaho.di.core.exception.KettleFileException)1 KettleJobException (org.pentaho.di.core.exception.KettleJobException)1 KettleTransException (org.pentaho.di.core.exception.KettleTransException)1 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)1 JobLogTable (org.pentaho.di.core.logging.JobLogTable)1