Search in sources :

Example 1 with IProgressMonitor

use of org.apache.hop.core.IProgressMonitor in project hop by apache.

the class HopImport method run.

@Override
public void run() {
    try {
        log = new LogChannel("HopImport");
        if (listPluginTypes != null && listPluginTypes) {
            printPluginTypes();
            return;
        }
        if (!validateOptions()) {
            cmd.usage(System.err);
            return;
        }
        hopImport = loadImportPlugin();
        if (hopImport == null) {
            return;
        }
        log.logDetailed("Start of Hop Import");
        // Set the options...
        // 
        hopImport.setValidateInputFolder(inputFolderName);
        hopImport.setValidateOutputFolder(outputFolderName);
        hopImport.setKettlePropertiesFilename(kettlePropertiesFilename);
        hopImport.setJdbcPropertiesFilename(jdbcPropertiesFilename);
        hopImport.setSharedXmlFilename(sharedXmlFilename);
        if (skippingExistingTargetFiles != null) {
            log.logBasic("Import is " + (skippingExistingTargetFiles ? "" : "not ") + "skipping existing target files");
            hopImport.setSkippingExistingTargetFiles(skippingExistingTargetFiles);
        }
        if (skippingHiddenFilesAndFolders != null) {
            log.logBasic("Import is " + (skippingHiddenFilesAndFolders ? "" : "not ") + "skipping hidden files and folders");
            hopImport.setSkippingHiddenFilesAndFolders(skippingHiddenFilesAndFolders);
        }
        if (skippingFolders != null) {
            log.logBasic("Import is " + (skippingFolders ? "" : "not ") + "skipping sub-folders");
            hopImport.setSkippingFolders(skippingFolders);
        }
        hopImport.setTargetConfigFilename(targetConfigFilename);
        // Allow plugins to modify the elements loaded so far, before a pipeline or workflow is even
        // loaded
        // 
        ExtensionPointHandler.callExtensionPoint(log, variables, HopExtensionPoint.HopImportStart.id, this);
        // Handle the options of the configuration plugins
        // 
        Map<String, Object> mixins = cmd.getMixins();
        for (String key : mixins.keySet()) {
            Object mixin = mixins.get(key);
            if (mixin instanceof IConfigOptions) {
                IConfigOptions configOptions = (IConfigOptions) mixin;
                configOptions.handleOption(log, this, variables);
            }
        }
        // Text version of a progress monitor...
        // 
        IProgressMonitor monitor = new LogProgressMonitor(log);
        // Run the import...
        // 
        hopImport.runImport(monitor);
        // Print the report...
        // 
        log.logBasic(Const.CR);
        log.logBasic(hopImport.getImportReport());
        ExtensionPointHandler.callExtensionPoint(log, variables, HopExtensionPoint.HopImportEnd.id, this);
    } catch (Exception e) {
        throw new ExecutionException(cmd, "There was an error during import", e);
    }
}
Also used : IConfigOptions(org.apache.hop.core.config.plugin.IConfigOptions) IProgressMonitor(org.apache.hop.core.IProgressMonitor) ILogChannel(org.apache.hop.core.logging.ILogChannel) LogChannel(org.apache.hop.core.logging.LogChannel) ExecutionException(picocli.CommandLine.ExecutionException) LogProgressMonitor(org.apache.hop.core.LogProgressMonitor) HopException(org.apache.hop.core.exception.HopException) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) IOException(java.io.IOException)

Example 2 with IProgressMonitor

use of org.apache.hop.core.IProgressMonitor in project hop by apache.

the class GetPreviewTableProgressDialog method open.

public List<Object[]> open() {
    IRunnableWithProgress op = monitor -> {
        db = new Database(HopGui.getInstance().getLoggingObject(), variables, dbMeta);
        try {
            db.connect();
            if (limit > 0) {
                db.setQueryLimit(limit);
            }
            rows = db.getFirstRows(tableName, limit, new ProgressMonitorAdapter(monitor));
            rowMeta = db.getReturnRowMeta();
        } catch (HopException e) {
            throw new InvocationTargetException(e, "Couldn't find any rows because of an error :" + e.toString());
        } finally {
            db.disconnect();
        }
    };
    try {
        final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
        // Run something in the background to cancel active database queries, forecably if needed!
        Runnable run = () -> {
            IProgressMonitor monitor = pmd.getProgressMonitor();
            while (pmd.getShell() == null || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                // Ignore
                }
            }
            if (monitor.isCanceled()) {
                try {
                    db.cancelQuery();
                } catch (Exception e) {
                // Ignore
                }
            }
        };
        // Start the cancel tracker in the background!
        new Thread(run).start();
        pmd.run(true, op);
    } catch (InvocationTargetException e) {
        showErrorDialog(e);
        return null;
    } catch (InterruptedException e) {
        showErrorDialog(e);
        return null;
    }
    return rows;
}
Also used : Database(org.apache.hop.core.database.Database) IRowMeta(org.apache.hop.core.row.IRowMeta) Shell(org.eclipse.swt.widgets.Shell) BaseMessages(org.apache.hop.i18n.BaseMessages) IVariables(org.apache.hop.core.variables.IVariables) HopException(org.apache.hop.core.exception.HopException) ProgressMonitorDialog(org.apache.hop.ui.core.dialog.ProgressMonitorDialog) HopGui(org.apache.hop.ui.hopgui.HopGui) InvocationTargetException(java.lang.reflect.InvocationTargetException) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) List(java.util.List) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) IProgressMonitor(org.apache.hop.core.IProgressMonitor) IRunnableWithProgress(org.apache.hop.core.IRunnableWithProgress) ProgressMonitorAdapter(org.apache.hop.core.ProgressMonitorAdapter) IProgressMonitor(org.apache.hop.core.IProgressMonitor) HopException(org.apache.hop.core.exception.HopException) ProgressMonitorDialog(org.apache.hop.ui.core.dialog.ProgressMonitorDialog) Database(org.apache.hop.core.database.Database) ProgressMonitorAdapter(org.apache.hop.core.ProgressMonitorAdapter) InvocationTargetException(java.lang.reflect.InvocationTargetException) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.apache.hop.core.IRunnableWithProgress)

Example 3 with IProgressMonitor

use of org.apache.hop.core.IProgressMonitor in project hop by apache.

the class GetQueryFieldsProgressDialog method open.

public IRowMeta open() {
    IRunnableWithProgress op = monitor -> {
        db = new Database(HopGui.getInstance().getLoggingObject(), variables, databaseMeta);
        try {
            db.connect();
            result = db.getQueryFields(sql, false);
            if (monitor.isCanceled()) {
                throw new InvocationTargetException(new Exception("This operation was cancelled!"));
            }
        } catch (Exception e) {
            throw new InvocationTargetException(e, "Problem encountered determining query fields: " + e.toString());
        } finally {
            db.disconnect();
        }
    };
    try {
        final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
        // Run something in the background to cancel active database queries, forecably if needed!
        Runnable run = () -> {
            IProgressMonitor monitor = pmd.getProgressMonitor();
            while (pmd.getShell() == null || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
                try {
                    Thread.sleep(250);
                } catch (InterruptedException e) {
                // Ignore
                }
            }
            if (monitor.isCanceled()) {
                try {
                    db.cancelQuery();
                } catch (Exception e) {
                // Ignore
                }
            }
        };
        // Dump the cancel looker in the background!
        new Thread(run).start();
        pmd.run(true, op);
    } catch (InvocationTargetException e) {
        showErrorDialog(e);
        return null;
    } catch (InterruptedException e) {
        showErrorDialog(e);
        return null;
    }
    return result;
}
Also used : ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) Database(org.apache.hop.core.database.Database) IRowMeta(org.apache.hop.core.row.IRowMeta) Shell(org.eclipse.swt.widgets.Shell) BaseMessages(org.apache.hop.i18n.BaseMessages) IVariables(org.apache.hop.core.variables.IVariables) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) ProgressMonitorDialog(org.apache.hop.ui.core.dialog.ProgressMonitorDialog) HopGui(org.apache.hop.ui.hopgui.HopGui) IProgressMonitor(org.apache.hop.core.IProgressMonitor) IRunnableWithProgress(org.apache.hop.core.IRunnableWithProgress) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.apache.hop.core.IProgressMonitor) ProgressMonitorDialog(org.apache.hop.ui.core.dialog.ProgressMonitorDialog) Database(org.apache.hop.core.database.Database) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.apache.hop.core.IRunnableWithProgress)

Example 4 with IProgressMonitor

use of org.apache.hop.core.IProgressMonitor in project hop by apache.

the class GetTableSizeProgressDialog method open.

public Long open() {
    IRunnableWithProgress op = monitor -> {
        db = new Database(HopGui.getInstance().getLoggingObject(), variables, databaseMeta);
        try {
            db.connect();
            String sql = databaseMeta.getIDatabase().getSelectCountStatement(tableName);
            RowMetaAndData row = db.getOneRow(sql);
            size = row.getRowMeta().getInteger(row.getData(), 0);
            if (monitor.isCanceled()) {
                throw new InvocationTargetException(new Exception("This operation was cancelled!"));
            }
        } catch (HopException e) {
            throw new InvocationTargetException(e, "Couldn't get a result because of an error :" + e.toString());
        } finally {
            db.disconnect();
            monitor.done();
        }
    };
    try {
        final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
        // Run something in the background to cancel active database queries, forcibly if needed!
        Runnable run = () -> {
            IProgressMonitor monitor = pmd.getProgressMonitor();
            while (pmd.getShell() == null || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                // Ignore
                }
            }
            if (monitor.isCanceled()) {
                try {
                    db.cancelQuery();
                } catch (Exception e) {
                // Ignore
                }
            }
        };
        // Start the cancel tracker in the background!
        new Thread(run).start();
        pmd.run(true, op);
    } catch (InvocationTargetException e) {
        showErrorDialog(e);
        return null;
    } catch (InterruptedException e) {
        showErrorDialog(e);
        return null;
    }
    return size;
}
Also used : Database(org.apache.hop.core.database.Database) Shell(org.eclipse.swt.widgets.Shell) BaseMessages(org.apache.hop.i18n.BaseMessages) IVariables(org.apache.hop.core.variables.IVariables) HopException(org.apache.hop.core.exception.HopException) ProgressMonitorDialog(org.apache.hop.ui.core.dialog.ProgressMonitorDialog) HopGui(org.apache.hop.ui.hopgui.HopGui) RowMetaAndData(org.apache.hop.core.RowMetaAndData) InvocationTargetException(java.lang.reflect.InvocationTargetException) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) IProgressMonitor(org.apache.hop.core.IProgressMonitor) IRunnableWithProgress(org.apache.hop.core.IRunnableWithProgress) HopException(org.apache.hop.core.exception.HopException) ProgressMonitorDialog(org.apache.hop.ui.core.dialog.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.apache.hop.core.IRunnableWithProgress) IProgressMonitor(org.apache.hop.core.IProgressMonitor) RowMetaAndData(org.apache.hop.core.RowMetaAndData) Database(org.apache.hop.core.database.Database)

Example 5 with IProgressMonitor

use of org.apache.hop.core.IProgressMonitor in project hop by apache.

the class PipelinePreviewProgressDialog method open.

/**
 * Opens the progress dialog
 *
 * @param showErrorDialogs dictates whether error dialogs should be shown when errors occur - can
 *     be set to "false" to let the caller control error dialogs instead.
 * @return a {@link PipelineMeta}
 */
public PipelineMeta open(final boolean showErrorDialogs) {
    final HopGui hopGui = HopGui.getInstance();
    IRunnableWithProgress op = monitor -> doPreview(hopGui, monitor, showErrorDialogs);
    try {
        final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
        // Run something in the background to cancel active database queries, force this if needed!
        Runnable run = () -> {
            IProgressMonitor monitor = pmd.getProgressMonitor();
            while (pmd.getShell() == null || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                // Ignore
                }
            }
            if (monitor.isCanceled()) {
                try {
                    pipeline.stopAll();
                } catch (Exception e) {
                /* Ignore */
                }
            }
        };
        // Start the cancel tracker in the background!
        new Thread(run).start();
        pmd.run(true, op);
    } catch (InvocationTargetException | InterruptedException e) {
        if (showErrorDialogs) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "PipelinePreviewProgressDialog.ErrorLoadingPipeline.DialogTitle"), BaseMessages.getString(PKG, "PipelinePreviewProgressDialog.ErrorLoadingPipeline.DialogMessage"), e);
        }
        pipelineMeta = null;
    }
    return pipelineMeta;
}
Also used : IRowMeta(org.apache.hop.core.row.IRowMeta) Shell(org.eclipse.swt.widgets.Shell) BaseMessages(org.apache.hop.i18n.BaseMessages) HopLogStore(org.apache.hop.core.logging.HopLogStore) IVariables(org.apache.hop.core.variables.IVariables) PipelineDebugMeta(org.apache.hop.pipeline.debug.PipelineDebugMeta) TransformDebugMeta(org.apache.hop.pipeline.debug.TransformDebugMeta) HopException(org.apache.hop.core.exception.HopException) ProgressMonitorDialog(org.apache.hop.ui.core.dialog.ProgressMonitorDialog) HopGui(org.apache.hop.ui.hopgui.HopGui) LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) List(java.util.List) Pipeline(org.apache.hop.pipeline.Pipeline) IProgressMonitor(org.apache.hop.core.IProgressMonitor) IRunnableWithProgress(org.apache.hop.core.IRunnableWithProgress) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) IProgressMonitor(org.apache.hop.core.IProgressMonitor) ProgressMonitorDialog(org.apache.hop.ui.core.dialog.ProgressMonitorDialog) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HopGui(org.apache.hop.ui.hopgui.HopGui) IRunnableWithProgress(org.apache.hop.core.IRunnableWithProgress)

Aggregations

IProgressMonitor (org.apache.hop.core.IProgressMonitor)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IRunnableWithProgress (org.apache.hop.core.IRunnableWithProgress)5 IVariables (org.apache.hop.core.variables.IVariables)5 BaseMessages (org.apache.hop.i18n.BaseMessages)5 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)5 ProgressMonitorDialog (org.apache.hop.ui.core.dialog.ProgressMonitorDialog)5 HopGui (org.apache.hop.ui.hopgui.HopGui)5 Shell (org.eclipse.swt.widgets.Shell)5 HopException (org.apache.hop.core.exception.HopException)4 List (java.util.List)3 Database (org.apache.hop.core.database.Database)3 DatabaseMeta (org.apache.hop.core.database.DatabaseMeta)3 IRowMeta (org.apache.hop.core.row.IRowMeta)3 ProgressMonitorAdapter (org.apache.hop.core.ProgressMonitorAdapter)2 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ICheckResult (org.apache.hop.core.ICheckResult)1 LogProgressMonitor (org.apache.hop.core.LogProgressMonitor)1