Search in sources :

Example 1 with LogTableField

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

the class JobHistoryDelegate method showLogEntry.

private void showLogEntry() {
    JobHistoryLogTab model = models[tabFolder.getSelectionIndex()];
    Text text = model.logDisplayText;
    if (text == null || text.isDisposed()) {
        return;
    }
    List<Object[]> list = model.rows;
    if (list == null || list.size() == 0) {
        String message;
        if (model.logTable.isDefined()) {
            message = BaseMessages.getString(PKG, "JobHistory.PleaseRefresh.Message");
        } else {
            message = BaseMessages.getString(PKG, "JobHistory.HistoryConfiguration.Message");
        }
        text.setText(message);
        return;
    }
    // grab the selected line in the table:
    int nr = model.logDisplayTableView.table.getSelectionIndex();
    if (nr >= 0 && nr < list.size()) {
        // OK, grab this one from the buffer...
        Object[] row = list.get(nr);
        // What is the name of the log field?
        // 
        LogTableField logField = model.logTable.getLogField();
        if (logField != null) {
            int index = model.logTableFields.indexOf(logField);
            if (index >= 0) {
                String logText = row[index].toString();
                text.setText(Const.NVL(logText, ""));
                text.setSelection(text.getText().length());
                text.showSelection();
            } else {
                text.setText(BaseMessages.getString(PKG, "JobHistory.HistoryConfiguration.NoLoggingFieldDefined"));
            }
        }
    }
}
Also used : LogTableField(org.pentaho.di.core.logging.LogTableField) Text(org.eclipse.swt.widgets.Text) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 2 with LogTableField

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

the class JobHistoryDelegate method displayHistoryData.

private void displayHistoryData(final int index) {
    JobHistoryLogTab model = models[index];
    ColumnInfo[] colinf = model.logDisplayTableView.getColumns();
    // 
    if (model.logDisplayTableView == null || model.logDisplayTableView.isDisposed()) {
        return;
    }
    int selectionIndex = model.logDisplayTableView.getSelectionIndex();
    model.logDisplayTableView.table.clearAll();
    List<Object[]> rows = model.rows;
    if (rows != null && rows.size() > 0) {
        // 
        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[c]);
                } 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;
            LogTableField errorsField = model.logTable.getErrorsField();
            if (errorsField != null) {
                int index1 = model.logTableFields.indexOf(errorsField);
                try {
                    errors = colinf[index1].getValueMeta().getInteger(rowData[index1]);
                } catch (KettleValueException e) {
                    log.logError("history data conversion issue", e);
                }
            }
            LogTableField statusField = model.logTable.getStatusField();
            if (statusField != null) {
                int index1 = model.logTableFields.indexOf(statusField);
                String statusString = null;
                try {
                    statusString = colinf[index1].getValueMeta().getString(rowData[index1]);
                } 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);
    // new TableItem(wFields.get(tabIndex).table, SWT.NONE); // Give it an item to prevent errors on various
    // platforms.
    }
    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 LogTableField

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

the class JobHistoryDelegate method replayHistory.

/**
 * Public for XUL.
 */
public void replayHistory() {
    JobHistoryLogTab model = models[tabFolder.getSelectionIndex()];
    int idx = model.logDisplayTableView.getSelectionIndex();
    if (idx >= 0) {
        String[] fields = model.logDisplayTableView.getItem(idx);
        int batchId = Const.toInt(fields[0], -1);
        // String dateString = fields[13];
        // Date replayDate = XMLHandler.stringToDate(dateString);
        List<JobEntryCopyResult> results = null;
        boolean gotResults = false;
        // We check in the Job Entry Logging to see the results from all the various job entries that were executed.
        // 
        JobEntryLogTable jeLogTable = jobMeta.getJobEntryLogTable();
        if (jeLogTable.isDefined()) {
            try {
                DatabaseMeta databaseMeta = jobMeta.getJobEntryLogTable().getDatabaseMeta();
                Database db = new Database(Spoon.loggingObject, databaseMeta);
                try {
                    db.connect();
                    String schemaTable = databaseMeta.getQuotedSchemaTableCombination(jeLogTable.getActualSchemaName(), jeLogTable.getActualTableName());
                    String sql = "SELECT * FROM " + schemaTable + " WHERE " + databaseMeta.quoteField(jeLogTable.getKeyField().getFieldName()) + " = " + batchId;
                    List<Object[]> rows = db.getRows(sql, 0);
                    RowMetaInterface rowMeta = db.getReturnRowMeta();
                    results = new ArrayList<JobEntryCopyResult>();
                    int jobEntryNameIndex = rowMeta.indexOfValue(jeLogTable.findField(JobEntryLogTable.ID.JOBENTRYNAME.toString()).getFieldName());
                    int jobEntryResultIndex = rowMeta.indexOfValue(jeLogTable.findField(JobEntryLogTable.ID.RESULT.toString()).getFieldName());
                    int jobEntryErrorsIndex = rowMeta.indexOfValue(jeLogTable.findField(JobEntryLogTable.ID.ERRORS.toString()).getFieldName());
                    LogTableField copyNrField = jeLogTable.findField(JobEntryLogTable.ID.COPY_NR.toString());
                    int jobEntryCopyNrIndex = copyNrField == null ? -1 : (copyNrField.isEnabled() ? rowMeta.indexOfValue(copyNrField.getFieldName()) : -1);
                    for (Object[] row : rows) {
                        String jobEntryName = rowMeta.getString(row, jobEntryNameIndex);
                        boolean jobEntryResult = rowMeta.getBoolean(row, jobEntryResultIndex);
                        long errors = rowMeta.getInteger(row, jobEntryErrorsIndex);
                        long copyNr = jobEntryCopyNrIndex < 0 ? 0 : rowMeta.getInteger(row, jobEntryCopyNrIndex);
                        JobEntryCopyResult result = new JobEntryCopyResult(jobEntryName, jobEntryResult, errors, (int) copyNr);
                        results.add(result);
                    }
                } finally {
                    db.disconnect();
                }
                gotResults = true;
            } catch (Exception e) {
                new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "JobHistoryDelegate.ReplayHistory.UnexpectedErrorReadingJobEntryHistory.Text"), BaseMessages.getString(PKG, "JobHistoryDelegate.ReplayHistory.UnexpectedErrorReadingJobEntryHistory.Message"), e);
            }
        } else {
            MessageBox box = new MessageBox(spoon.getShell(), SWT.ICON_ERROR | SWT.OK);
            box.setText(BaseMessages.getString(PKG, "JobHistoryDelegate.ReplayHistory.NoJobEntryTable.Text"));
            box.setMessage(BaseMessages.getString(PKG, "JobHistoryDelegate.ReplayHistory.NoJobEntryTable.Message"));
            box.open();
        }
        // spoon.executeJob(jobGraph.getManagedObject(), true, false, replayDate, false);
        if (!gotResults) {
            // For some reason we have no execution results, simply list all the job entries so the user can choose...
            // 
            results = new ArrayList<JobEntryCopyResult>();
            for (JobEntryCopy copy : jobMeta.getJobCopies()) {
                results.add(new JobEntryCopyResult(copy.getName(), null, null, copy.getNr()));
            }
        }
        // OK, now that we have our list of job entries, let's first try to find the first job-entry that had a false
        // result or where errors>0
        // If the error was handled, we look further for a more appropriate target.
        // 
        JobEntryCopy selection = null;
        boolean more = true;
        JobEntryCopy start = jobMeta.findStart();
        while (selection == null && more) {
            int nrNext = jobMeta.findNrNextJobEntries(start);
            more = nrNext > 0;
            for (int n = 0; n < nrNext; n++) {
                JobEntryCopy copy = jobMeta.findNextJobEntry(start, n);
                // See if we can find a result for this job entry...
                // 
                JobEntryCopyResult result = JobEntryCopyResult.findResult(results, copy);
                if (result != null) {
                    System.out.println("TODO: replay");
                // Do nothing???
                }
            }
        }
        // 
        for (JobEntryCopyResult result : results) {
            System.out.println("Job entry copy result --  Name=" + result.getJobEntryName() + ", result=" + result.getResult() + ", errors=" + result.getErrors() + ", nr=" + result.getCopyNr());
        }
    }
}
Also used : LogTableField(org.pentaho.di.core.logging.LogTableField) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleValueException(org.pentaho.di.core.exception.KettleValueException) MessageBox(org.eclipse.swt.widgets.MessageBox) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) Database(org.pentaho.di.core.database.Database) JobEntryLogTable(org.pentaho.di.core.logging.JobEntryLogTable)

Example 4 with LogTableField

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

the class JobDialog method showChannelLogTableOptions.

private void showChannelLogTableOptions(ChannelLogTable channelLogTable) {
    addDBSchemaTableLogOptions(channelLogTable);
    // The log timeout in days
    // 
    Label wlLogTimeout = new Label(wLogOptionsComposite, SWT.RIGHT);
    wlLogTimeout.setText(BaseMessages.getString(PKG, "JobDialog.LogTimeout.Label"));
    wlLogTimeout.setToolTipText(BaseMessages.getString(PKG, "JobDialog.LogTimeout.Tooltip"));
    props.setLook(wlLogTimeout);
    FormData fdlLogTimeout = new FormData();
    fdlLogTimeout.left = new FormAttachment(0, 0);
    fdlLogTimeout.right = new FormAttachment(middle, -margin);
    fdlLogTimeout.top = new FormAttachment(wLogTable, margin);
    wlLogTimeout.setLayoutData(fdlLogTimeout);
    wLogTimeout = new TextVar(jobMeta, wLogOptionsComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wLogTimeout.setToolTipText(BaseMessages.getString(PKG, "JobDialog.LogTimeout.Tooltip"));
    props.setLook(wLogTimeout);
    wLogTimeout.addModifyListener(lsMod);
    FormData fdLogTimeout = new FormData();
    fdLogTimeout.left = new FormAttachment(middle, 0);
    fdLogTimeout.top = new FormAttachment(wLogTable, margin);
    fdLogTimeout.right = new FormAttachment(100, 0);
    wLogTimeout.setLayoutData(fdLogTimeout);
    wLogTimeout.setText(Const.NVL(channelLogTable.getTimeoutInDays(), ""));
    // Add the fields grid...
    // 
    Label wlFields = new Label(wLogOptionsComposite, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "JobDialog.TransLogTable.Fields.Label"));
    props.setLook(wlFields);
    FormData fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wLogTimeout, margin * 2);
    wlFields.setLayoutData(fdlFields);
    final java.util.List<LogTableField> fields = channelLogTable.getFields();
    final int nrRows = fields.size();
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "JobDialog.TransLogTable.Fields.FieldName"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "JobDialog.TransLogTable.Fields.Description"), ColumnInfo.COLUMN_TYPE_TEXT, false, true) };
    FieldDisabledListener disabledListener = new FieldDisabledListener() {

        public boolean isFieldDisabled(int rowNr) {
            if (rowNr >= 0 && rowNr < fields.size()) {
                LogTableField field = fields.get(rowNr);
                return field.isSubjectAllowed();
            } else {
                return true;
            }
        }
    };
    colinf[1].setDisabledListener(disabledListener);
    wOptionFields = new // add a
    TableView(// add a
    jobMeta, // add a
    wLogOptionsComposite, // add a
    SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.CHECK, // left...
    colinf, nrRows, true, lsMod, props);
    wOptionFields.setSortable(false);
    for (int i = 0; i < fields.size(); i++) {
        LogTableField field = fields.get(i);
        TableItem item = wOptionFields.table.getItem(i);
        item.setChecked(field.isEnabled());
        item.setText(new String[] { "", Const.NVL(field.getFieldName(), ""), Const.NVL(field.getDescription(), "") });
    }
    wOptionFields.table.getColumn(0).setText(BaseMessages.getString(PKG, "JobDialog.TransLogTable.Fields.Enabled"));
    FormData fdOptionFields = new FormData();
    fdOptionFields.left = new FormAttachment(0, 0);
    fdOptionFields.top = new FormAttachment(wlFields, margin);
    fdOptionFields.right = new FormAttachment(100, 0);
    fdOptionFields.bottom = new FormAttachment(100, 0);
    wOptionFields.setLayoutData(fdOptionFields);
    wOptionFields.optWidth(true);
    wOptionFields.layout();
}
Also used : FormData(org.eclipse.swt.layout.FormData) LogTableField(org.pentaho.di.core.logging.LogTableField) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) FieldDisabledListener(org.pentaho.di.ui.core.widget.FieldDisabledListener) TextVar(org.pentaho.di.ui.core.widget.TextVar) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 5 with LogTableField

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

the class JobDialog method showJobEntryLogTableOptions.

private void showJobEntryLogTableOptions(JobEntryLogTable jobEntryLogTable) {
    addDBSchemaTableLogOptions(jobEntryLogTable);
    // The log timeout in days
    // 
    Label wlLogTimeout = new Label(wLogOptionsComposite, SWT.RIGHT);
    wlLogTimeout.setText(BaseMessages.getString(PKG, "JobDialog.LogTimeout.Label"));
    wlLogTimeout.setToolTipText(BaseMessages.getString(PKG, "JobDialog.LogTimeout.Tooltip"));
    props.setLook(wlLogTimeout);
    FormData fdlLogTimeout = new FormData();
    fdlLogTimeout.left = new FormAttachment(0, 0);
    fdlLogTimeout.right = new FormAttachment(middle, -margin);
    fdlLogTimeout.top = new FormAttachment(wLogTable, margin);
    wlLogTimeout.setLayoutData(fdlLogTimeout);
    wLogTimeout = new TextVar(jobMeta, wLogOptionsComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    wLogTimeout.setToolTipText(BaseMessages.getString(PKG, "JobDialog.LogTimeout.Tooltip"));
    props.setLook(wLogTimeout);
    wLogTimeout.addModifyListener(lsMod);
    FormData fdLogTimeout = new FormData();
    fdLogTimeout.left = new FormAttachment(middle, 0);
    fdLogTimeout.top = new FormAttachment(wLogTable, margin);
    fdLogTimeout.right = new FormAttachment(100, 0);
    wLogTimeout.setLayoutData(fdLogTimeout);
    wLogTimeout.setText(Const.NVL(jobEntryLogTable.getTimeoutInDays(), ""));
    // Add the fields grid...
    // 
    Label wlFields = new Label(wLogOptionsComposite, SWT.NONE);
    wlFields.setText(BaseMessages.getString(PKG, "JobDialog.TransLogTable.Fields.Label"));
    props.setLook(wlFields);
    FormData fdlFields = new FormData();
    fdlFields.left = new FormAttachment(0, 0);
    fdlFields.top = new FormAttachment(wLogTimeout, margin * 2);
    wlFields.setLayoutData(fdlFields);
    final java.util.List<LogTableField> fields = jobEntryLogTable.getFields();
    final int nrRows = fields.size();
    ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "JobDialog.TransLogTable.Fields.FieldName"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "JobDialog.TransLogTable.Fields.Description"), ColumnInfo.COLUMN_TYPE_TEXT, false, true) };
    FieldDisabledListener disabledListener = new FieldDisabledListener() {

        public boolean isFieldDisabled(int rowNr) {
            if (rowNr >= 0 && rowNr < fields.size()) {
                LogTableField field = fields.get(rowNr);
                return field.isSubjectAllowed();
            } else {
                return true;
            }
        }
    };
    colinf[1].setDisabledListener(disabledListener);
    wOptionFields = new // add a
    TableView(// add a
    jobMeta, // add a
    wLogOptionsComposite, // add a
    SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.CHECK, // left...
    colinf, nrRows, true, lsMod, props);
    wOptionFields.setSortable(false);
    for (int i = 0; i < fields.size(); i++) {
        LogTableField field = fields.get(i);
        TableItem item = wOptionFields.table.getItem(i);
        item.setChecked(field.isEnabled());
        item.setText(new String[] { "", Const.NVL(field.getFieldName(), ""), Const.NVL(field.getDescription(), "") });
    }
    wOptionFields.table.getColumn(0).setText(BaseMessages.getString(PKG, "JobDialog.TransLogTable.Fields.Enabled"));
    FormData fdOptionFields = new FormData();
    fdOptionFields.left = new FormAttachment(0, 0);
    fdOptionFields.top = new FormAttachment(wlFields, margin);
    fdOptionFields.right = new FormAttachment(100, 0);
    fdOptionFields.bottom = new FormAttachment(100, 0);
    wOptionFields.setLayoutData(fdOptionFields);
    wOptionFields.optWidth(true);
    wOptionFields.layout();
}
Also used : FormData(org.eclipse.swt.layout.FormData) LogTableField(org.pentaho.di.core.logging.LogTableField) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) FieldDisabledListener(org.pentaho.di.ui.core.widget.FieldDisabledListener) TextVar(org.pentaho.di.ui.core.widget.TextVar) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

LogTableField (org.pentaho.di.core.logging.LogTableField)25 TableItem (org.eclipse.swt.widgets.TableItem)18 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)10 FormAttachment (org.eclipse.swt.layout.FormAttachment)8 FormData (org.eclipse.swt.layout.FormData)8 Label (org.eclipse.swt.widgets.Label)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)8 TextVar (org.pentaho.di.ui.core.widget.TextVar)8 FieldDisabledListener (org.pentaho.di.ui.core.widget.FieldDisabledListener)7 KettleValueException (org.pentaho.di.core.exception.KettleValueException)6 TableView (org.pentaho.di.ui.core.widget.TableView)5 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 Database (org.pentaho.di.core.database.Database)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)3 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Text (org.eclipse.swt.widgets.Text)2 KettleException (org.pentaho.di.core.exception.KettleException)2 LogStatus (org.pentaho.di.core.logging.LogStatus)2 LogTableInterface (org.pentaho.di.core.logging.LogTableInterface)2