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);
}
}
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);
}
}
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() + ")");
}
}
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);
}
}
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);
}
}
Aggregations