Search in sources :

Example 1 with DBRProcessDescriptor

use of org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor in project dbeaver by serge-rider.

the class DataSourceDescriptor method processEvents.

private void processEvents(DBRProgressMonitor monitor, DBPConnectionEventType eventType) {
    DBPConnectionConfiguration info = getActualConnectionConfiguration();
    DBRShellCommand command = info.getEvent(eventType);
    if (command != null && command.isEnabled()) {
        final DBRProcessDescriptor processDescriptor = new DBRProcessDescriptor(command, getVariablesResolver(true));
        monitor.subTask("Execute process " + processDescriptor.getName());
        DBWorkbench.getPlatformUI().executeProcess(processDescriptor);
        {
            // Run output grab job
            new AbstractJob(processDescriptor.getName() + ": output reader") {

                @Override
                protected IStatus run(DBRProgressMonitor monitor) {
                    try {
                        String output = processDescriptor.dumpErrors();
                        log.debug("Process error output:\n" + output);
                    } catch (Exception e) {
                        log.debug(e);
                    }
                    return Status.OK_STATUS;
                }
            }.schedule();
        }
        if (command.isWaitProcessFinish()) {
            int resultCode;
            if (command.getWaitProcessTimeoutMs() >= 0) {
                resultCode = processDescriptor.waitFor(command.getWaitProcessTimeoutMs());
            } else {
                resultCode = processDescriptor.waitFor();
            }
            log.debug(processDescriptor.getName() + " result code: " + resultCode);
        }
        addChildProcess(processDescriptor);
    }
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBRProcessDescriptor(org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBException(org.jkiss.dbeaver.DBException) IOException(java.io.IOException)

Example 2 with DBRProcessDescriptor

use of org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor in project dbeaver by serge-rider.

the class StreamTransferConsumer method executeFinishCommand.

private void executeFinishCommand() {
    String commandLine = translatePattern(settings.getFinishProcessCommand(), outputFile);
    DBRShellCommand command = new DBRShellCommand(commandLine);
    DBRProcessDescriptor processDescriptor = new DBRProcessDescriptor(command);
    try {
        processDescriptor.execute();
    } catch (DBException e) {
        DBWorkbench.getPlatformUI().showError(DTMessages.stream_transfer_consumer_title_run_process, NLS.bind(DTMessages.stream_transfer_consumer_message_error_running_process, commandLine), e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRProcessDescriptor(org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand)

Example 3 with DBRProcessDescriptor

use of org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor in project dbeaver by serge-rider.

the class DataSourceDescriptor method disconnect.

private boolean disconnect(final DBRProgressMonitor monitor, boolean reflect) {
    if (dataSource == null) {
        log.error("Datasource is not connected");
        return true;
    }
    if (connecting) {
        log.error("Connect/disconnect is in progress");
        return false;
    }
    connecting = true;
    try {
        releaseDataSourceUsers(monitor);
        monitor.beginTask("Disconnect from '" + getName() + "'", 5 + dataSource.getAvailableInstances().size());
        processEvents(monitor, DBPConnectionEventType.BEFORE_DISCONNECT);
        monitor.worked(1);
        // Close datasource
        monitor.subTask("Close connection");
        if (dataSource != null) {
            dataSource.shutdown(monitor);
        }
        monitor.worked(1);
        // Close tunnelHandler
        if (tunnelHandler != null) {
            monitor.subTask("Close tunnel");
            try {
                tunnelHandler.closeTunnel(monitor);
            } catch (Throwable e) {
                log.error("Error closing tunnel", e);
            }
        }
        monitor.worked(1);
        proxyHandler = null;
        processEvents(monitor, DBPConnectionEventType.AFTER_DISCONNECT);
        monitor.worked(1);
        monitor.done();
        // Terminate child processes
        synchronized (childProcesses) {
            for (Iterator<DBRProcessDescriptor> iter = childProcesses.iterator(); iter.hasNext(); ) {
                DBRProcessDescriptor process = iter.next();
                if (process.isRunning() && process.getCommand().isTerminateAtDisconnect()) {
                    process.terminate();
                }
                iter.remove();
            }
        }
        this.dataSource = null;
        this.resolvedConnectionInfo = null;
        this.connectTime = null;
        if (reflect) {
            // Reflect UI
            getRegistry().notifyDataSourceListeners(new DBPEvent(DBPEvent.Action.OBJECT_UPDATE, this, false));
        }
        return true;
    } finally {
        connecting = false;
        log.debug("Disconnected (" + getId() + ")");
    }
}
Also used : DBRProcessDescriptor(org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor)

Example 4 with DBRProcessDescriptor

use of org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor in project dbeaver by dbeaver.

the class StreamTransferConsumer method executeFinishCommand.

private void executeFinishCommand() {
    String commandLine = translatePattern(settings.getFinishProcessCommand(), outputFile);
    DBRShellCommand command = new DBRShellCommand(commandLine);
    DBRProcessDescriptor processDescriptor = new DBRProcessDescriptor(command);
    try {
        processDescriptor.execute();
    } catch (DBException e) {
        DBWorkbench.getPlatformUI().showError(DTMessages.stream_transfer_consumer_title_run_process, NLS.bind(DTMessages.stream_transfer_consumer_message_error_running_process, commandLine), e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBRProcessDescriptor(org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand)

Example 5 with DBRProcessDescriptor

use of org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor in project dbeaver by dbeaver.

the class DataSourceDescriptor method processEvents.

private void processEvents(DBRProgressMonitor monitor, DBPConnectionEventType eventType) {
    DBPConnectionConfiguration info = getActualConnectionConfiguration();
    DBRShellCommand command = info.getEvent(eventType);
    if (command != null && command.isEnabled()) {
        final DBRProcessDescriptor processDescriptor = new DBRProcessDescriptor(command, getVariablesResolver(true));
        monitor.subTask("Execute process " + processDescriptor.getName());
        DBWorkbench.getPlatformUI().executeProcess(processDescriptor);
        {
            // Run output grab job
            new AbstractJob(processDescriptor.getName() + ": output reader") {

                @Override
                protected IStatus run(DBRProgressMonitor monitor) {
                    try {
                        String output = processDescriptor.dumpErrors();
                        log.debug("Process error output:\n" + output);
                    } catch (Exception e) {
                        log.debug(e);
                    }
                    return Status.OK_STATUS;
                }
            }.schedule();
        }
        if (command.isWaitProcessFinish()) {
            int resultCode;
            if (command.getWaitProcessTimeoutMs() >= 0) {
                resultCode = processDescriptor.waitFor(command.getWaitProcessTimeoutMs());
            } else {
                resultCode = processDescriptor.waitFor();
            }
            log.debug(processDescriptor.getName() + " result code: " + resultCode);
        }
        addChildProcess(processDescriptor);
    }
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBRProcessDescriptor(org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBException(org.jkiss.dbeaver.DBException) IOException(java.io.IOException)

Aggregations

DBRProcessDescriptor (org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor)6 DBException (org.jkiss.dbeaver.DBException)4 DBRShellCommand (org.jkiss.dbeaver.model.runtime.DBRShellCommand)4 IOException (java.io.IOException)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2