Search in sources :

Example 1 with StepDebugMeta

use of org.pentaho.di.trans.debug.StepDebugMeta in project pentaho-kettle by pentaho.

the class TransGraph method showLastPreviewResults.

public synchronized void showLastPreviewResults() {
    if (lastTransDebugMeta == null || lastTransDebugMeta.getStepDebugMetaMap().isEmpty()) {
        return;
    }
    final List<String> stepnames = new ArrayList<>();
    final List<RowMetaInterface> rowMetas = new ArrayList<>();
    final List<List<Object[]>> rowBuffers = new ArrayList<>();
    // 
    for (StepMeta stepMeta : lastTransDebugMeta.getStepDebugMetaMap().keySet()) {
        StepDebugMeta stepDebugMeta = lastTransDebugMeta.getStepDebugMetaMap().get(stepMeta);
        stepnames.add(stepMeta.getName());
        rowMetas.add(stepDebugMeta.getRowBufferMeta());
        rowBuffers.add(stepDebugMeta.getRowBuffer());
    }
    getDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {
            EnterPreviewRowsDialog dialog = new EnterPreviewRowsDialog(shell, SWT.NONE, stepnames, rowMetas, rowBuffers);
            dialog.open();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) ArrayList(java.util.ArrayList) List(java.util.List) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) EnterPreviewRowsDialog(org.pentaho.di.ui.spoon.dialog.EnterPreviewRowsDialog) StepDebugMeta(org.pentaho.di.trans.debug.StepDebugMeta)

Example 2 with StepDebugMeta

use of org.pentaho.di.trans.debug.StepDebugMeta in project pentaho-kettle by pentaho.

the class TransDebugDialog method showStepDebugInformation.

private void showStepDebugInformation() {
    // 
    for (Control control : wComposite.getChildren()) {
        control.dispose();
    }
    wComposite.layout(true, true);
    int[] selectionIndices = wSteps.table.getSelectionIndices();
    if (selectionIndices == null || selectionIndices.length != 1) {
        return;
    }
    previousIndex = selectionIndices[0];
    // What step did we click on?
    // 
    final StepMeta stepMeta = transDebugMeta.getTransMeta().getStep(selectionIndices[0]);
    // What is the step debugging metadata?
    // --> This can be null (most likely scenario)
    // 
    final StepDebugMeta stepDebugMeta = stepDebugMetaMap.get(stepMeta);
    // At the top we'll put a few common items like first[x], etc.
    // 
    // The row count (e.g. number of rows to keep)
    // 
    wRowCount = new LabelText(wComposite, BaseMessages.getString(PKG, "TransDebugDialog.RowCount.Label"), BaseMessages.getString(PKG, "TransDebugDialog.RowCount.ToolTip"));
    FormData fdRowCount = new FormData();
    fdRowCount.left = new FormAttachment(0, 0);
    fdRowCount.right = new FormAttachment(100, 0);
    fdRowCount.top = new FormAttachment(0, 0);
    wRowCount.setLayoutData(fdRowCount);
    wRowCount.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            ok(false);
        }
    });
    // Do we retrieve the first rows passing?
    // 
    wFirstRows = new Button(wComposite, SWT.CHECK);
    props.setLook(wFirstRows);
    wFirstRows.setText(BaseMessages.getString(PKG, "TransDebugDialog.FirstRows.Label"));
    wFirstRows.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.FirstRows.ToolTip"));
    FormData fdFirstRows = new FormData();
    fdFirstRows.left = new FormAttachment(middle, 0);
    fdFirstRows.right = new FormAttachment(100, 0);
    fdFirstRows.top = new FormAttachment(wRowCount, margin);
    wFirstRows.setLayoutData(fdFirstRows);
    // Do we pause on break point, when the condition is met?
    // 
    wPauseBreakPoint = new Button(wComposite, SWT.CHECK);
    props.setLook(wPauseBreakPoint);
    wPauseBreakPoint.setText(BaseMessages.getString(PKG, "TransDebugDialog.PauseBreakPoint.Label"));
    wPauseBreakPoint.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.PauseBreakPoint.ToolTip"));
    FormData fdPauseBreakPoint = new FormData();
    fdPauseBreakPoint.left = new FormAttachment(middle, 0);
    fdPauseBreakPoint.right = new FormAttachment(100, 0);
    fdPauseBreakPoint.top = new FormAttachment(wFirstRows, margin);
    wPauseBreakPoint.setLayoutData(fdPauseBreakPoint);
    // The condition to pause for...
    // 
    condition = null;
    if (stepDebugMeta != null) {
        condition = stepDebugMeta.getCondition();
    }
    if (condition == null) {
        condition = new Condition();
    }
    // The input fields...
    try {
        stepInputFields = transDebugMeta.getTransMeta().getStepFields(stepMeta);
    } catch (KettleStepException e) {
        stepInputFields = new RowMeta();
    }
    wlCondition = new Label(wComposite, SWT.RIGHT);
    props.setLook(wlCondition);
    wlCondition.setText(BaseMessages.getString(PKG, "TransDebugDialog.Condition.Label"));
    wlCondition.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.Condition.ToolTip"));
    FormData fdlCondition = new FormData();
    fdlCondition.left = new FormAttachment(0, 0);
    fdlCondition.right = new FormAttachment(middle, -margin);
    fdlCondition.top = new FormAttachment(wPauseBreakPoint, margin);
    wlCondition.setLayoutData(fdlCondition);
    wCondition = new ConditionEditor(wComposite, SWT.BORDER, condition, stepInputFields);
    FormData fdCondition = new FormData();
    fdCondition.left = new FormAttachment(middle, 0);
    fdCondition.right = new FormAttachment(100, 0);
    fdCondition.top = new FormAttachment(wPauseBreakPoint, margin);
    fdCondition.bottom = new FormAttachment(100, 0);
    wCondition.setLayoutData(fdCondition);
    getStepDebugData(stepDebugMeta);
    // Add a "clear" button at the bottom on the left...
    // 
    Button wClear = new Button(wComposite, SWT.PUSH);
    props.setLook(wClear);
    wClear.setText(BaseMessages.getString(PKG, "TransDebugDialog.Clear.Label"));
    wClear.setToolTipText(BaseMessages.getString(PKG, "TransDebugDialog.Clear.ToolTip"));
    FormData fdClear = new FormData();
    fdClear.left = new FormAttachment(0, 0);
    fdClear.bottom = new FormAttachment(100, 0);
    wClear.setLayoutData(fdClear);
    wClear.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            // Clear the preview step information for this step...
            // 
            stepDebugMetaMap.remove(stepMeta);
            wSteps.table.setSelection(new int[] {});
            previousIndex = -1;
            // refresh the steps list...
            // 
            refreshStepList();
            showStepDebugInformation();
        }
    });
    wComposite.layout(true, true);
}
Also used : FormData(org.eclipse.swt.layout.FormData) Condition(org.pentaho.di.core.Condition) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ConditionEditor(org.pentaho.di.ui.core.widget.ConditionEditor) Label(org.eclipse.swt.widgets.Label) StepMeta(org.pentaho.di.trans.step.StepMeta) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LabelText(org.pentaho.di.ui.core.widget.LabelText) FormAttachment(org.eclipse.swt.layout.FormAttachment) StepDebugMeta(org.pentaho.di.trans.debug.StepDebugMeta)

Example 3 with StepDebugMeta

use of org.pentaho.di.trans.debug.StepDebugMeta in project pentaho-kettle by pentaho.

the class TransPreviewProgressDialog method doPreview.

private void doPreview(final IProgressMonitor progressMonitor, final boolean showErrorDialogs) {
    // capture the date/time before trying to preview...used only if there is an error.
    Date now = new Date();
    progressMonitor.beginTask(BaseMessages.getString(PKG, "TransPreviewProgressDialog.Monitor.BeginTask.Title"), 100);
    // This transformation is ready to run in preview!
    trans = new Trans(transMeta);
    trans.setPreview(true);
    // 
    try {
        trans.prepareExecution(null);
    } catch (final KettleException e) {
        if (showErrorDialogs) {
            shell.getDisplay().asyncExec(new Runnable() {

                public void run() {
                    // We do not want to display all of the error messages for this ktr's log channel ID
                    // So we must parse out the error messages to display only the messages that are specific
                    // to this preview Exception
                    // 
                    String errorMessage = parseErrorMessage(e.getMessage(), now);
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "TransPreviewProgressDialog.Exception.ErrorPreparingTransformation"), new Exception(errorMessage, e.getCause()));
                }
            });
        }
        // 
        return;
    }
    // Add the preview / debugging information...
    // 
    transDebugMeta = new TransDebugMeta(transMeta);
    for (int i = 0; i < previewStepNames.length; i++) {
        StepMeta stepMeta = transMeta.findStep(previewStepNames[i]);
        StepDebugMeta stepDebugMeta = new StepDebugMeta(stepMeta);
        stepDebugMeta.setReadingFirstRows(true);
        stepDebugMeta.setRowCount(previewSize[i]);
        transDebugMeta.getStepDebugMetaMap().put(stepMeta, stepDebugMeta);
    }
    int previousPct = 0;
    final List<String> previewComplete = new ArrayList<String>();
    // We add a break-point that is called every time we have a step with a full preview row buffer
    // That makes it easy and fast to see if we have all the rows we need
    // 
    transDebugMeta.addBreakPointListers(new BreakPointListener() {

        public void breakPointHit(TransDebugMeta transDebugMeta, StepDebugMeta stepDebugMeta, RowMetaInterface rowBufferMeta, List<Object[]> rowBuffer) {
            String stepName = stepDebugMeta.getStepMeta().getName();
            previewComplete.add(stepName);
            progressMonitor.subTask(BaseMessages.getString(PKG, "TransPreviewProgressDialog.SubTask.StepPreviewFinished", stepName));
        }
    });
    // set the appropriate listeners on the transformation...
    // 
    transDebugMeta.addRowListenersToTransformation(trans);
    // 
    try {
        trans.startThreads();
    } catch (final KettleException e) {
        shell.getDisplay().asyncExec(new Runnable() {

            public void run() {
                new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "TransPreviewProgressDialog.Exception.ErrorPreparingTransformation"), e);
            }
        });
        // 
        return;
    }
    while (previewComplete.size() < previewStepNames.length && !trans.isFinished() && !progressMonitor.isCanceled()) {
        // How many rows are done?
        int nrDone = 0;
        int nrTotal = 0;
        for (StepDebugMeta stepDebugMeta : transDebugMeta.getStepDebugMetaMap().values()) {
            nrDone += stepDebugMeta.getRowBuffer().size();
            nrTotal += stepDebugMeta.getRowCount();
        }
        int pct = 100 * nrDone / nrTotal;
        int worked = pct - previousPct;
        if (worked > 0) {
            progressMonitor.worked(worked);
        }
        previousPct = pct;
        // Change the percentage...
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        // Ignore errors
        }
        if (progressMonitor.isCanceled()) {
            cancelled = true;
            trans.stopAll();
        }
    }
    trans.stopAll();
    // Capture preview activity to a String:
    loggingText = KettleLogStore.getAppender().getBuffer(trans.getLogChannel().getLogChannelId(), true).toString();
    progressMonitor.done();
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) Date(java.util.Date) KettleException(org.pentaho.di.core.exception.KettleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BreakPointListener(org.pentaho.di.trans.debug.BreakPointListener) Trans(org.pentaho.di.trans.Trans) TransDebugMeta(org.pentaho.di.trans.debug.TransDebugMeta) StepDebugMeta(org.pentaho.di.trans.debug.StepDebugMeta)

Example 4 with StepDebugMeta

use of org.pentaho.di.trans.debug.StepDebugMeta in project pentaho-kettle by pentaho.

the class TransDebugDialog method getStepDebugMeta.

/**
 * Grab the step debugging information from the dialog. Store it in our private map
 */
private void getStepDebugMeta() {
    int index = wSteps.getSelectionIndex();
    if (previousIndex >= 0) {
        // 
        if (wComposite.getChildren().length == 0) {
            return;
        }
        StepMeta stepMeta = transDebugMeta.getTransMeta().getStep(previousIndex);
        StepDebugMeta stepDebugMeta = new StepDebugMeta(stepMeta);
        stepDebugMeta.setCondition(condition);
        stepDebugMeta.setPausingOnBreakPoint(wPauseBreakPoint.getSelection());
        stepDebugMeta.setReadingFirstRows(wFirstRows.getSelection());
        stepDebugMeta.setRowCount(Const.toInt(wRowCount.getText(), -1));
        stepDebugMetaMap.put(stepMeta, stepDebugMeta);
    }
    previousIndex = index;
}
Also used : StepMeta(org.pentaho.di.trans.step.StepMeta) StepDebugMeta(org.pentaho.di.trans.debug.StepDebugMeta)

Example 5 with StepDebugMeta

use of org.pentaho.di.trans.debug.StepDebugMeta in project pentaho-kettle by pentaho.

the class TransDebugDialog method refreshStepList.

private void refreshStepList() {
    GUIResource resource = GUIResource.getInstance();
    // Add the list of steps...
    // 
    int maxIconSize = 0;
    int indexSelected = -1;
    wSteps.table.removeAll();
    for (int i = 0; i < transDebugMeta.getTransMeta().getSteps().size(); i++) {
        StepMeta stepMeta = transDebugMeta.getTransMeta().getStep(i);
        TableItem item = new TableItem(wSteps.table, SWT.NONE);
        Image image = resource.getImagesSteps().get(stepMeta.getStepID()).getAsBitmapForSize(display, ConstUI.ICON_SIZE, ConstUI.ICON_SIZE);
        item.setImage(0, image);
        item.setText(0, "");
        item.setText(1, stepMeta.getName());
        if (image.getBounds().width > maxIconSize) {
            maxIconSize = image.getBounds().width;
        }
        StepDebugMeta stepDebugMeta = stepDebugMetaMap.get(stepMeta);
        if (stepDebugMeta != null) {
            // We have debugging information so we mark the row
            // 
            item.setBackground(resource.getColorLightPentaho());
            if (indexSelected < 0) {
                indexSelected = i;
            }
        }
    }
    wSteps.removeEmptyRows();
    wSteps.optWidth(false);
    wSteps.table.getColumn(0).setWidth(maxIconSize + 10);
    wSteps.table.getColumn(0).setAlignment(SWT.CENTER);
    // 
    if (indexSelected >= 0) {
        wSteps.table.setSelection(indexSelected);
        showStepDebugInformation();
    }
}
Also used : GUIResource(org.pentaho.di.ui.core.gui.GUIResource) TableItem(org.eclipse.swt.widgets.TableItem) Image(org.eclipse.swt.graphics.Image) StepMeta(org.pentaho.di.trans.step.StepMeta) StepDebugMeta(org.pentaho.di.trans.debug.StepDebugMeta)

Aggregations

StepDebugMeta (org.pentaho.di.trans.debug.StepDebugMeta)8 StepMeta (org.pentaho.di.trans.step.StepMeta)7 KettleException (org.pentaho.di.core.exception.KettleException)4 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)4 TransDebugMeta (org.pentaho.di.trans.debug.TransDebugMeta)4 ArrayList (java.util.ArrayList)3 Trans (org.pentaho.di.trans.Trans)3 BreakPointListener (org.pentaho.di.trans.debug.BreakPointListener)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Image (org.eclipse.swt.graphics.Image)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 Button (org.eclipse.swt.widgets.Button)1