Search in sources :

Example 6 with SlaveServerTransStatus

use of org.pentaho.di.www.SlaveServerTransStatus in project pentaho-kettle by pentaho.

the class Trans method monitorRemoteTransformation.

/**
 * Monitors a remote transformation at the specified interval.
 *
 * @param log
 *          the log channel interface
 * @param carteObjectId
 *          the Carte object ID
 * @param transName
 *          the transformation name
 * @param remoteSlaveServer
 *          the remote slave server
 * @param sleepTimeSeconds
 *          the sleep time (in seconds)
 */
public static void monitorRemoteTransformation(LogChannelInterface log, String carteObjectId, String transName, SlaveServer remoteSlaveServer, int sleepTimeSeconds) {
    long errors = 0;
    boolean allFinished = false;
    while (!allFinished && errors == 0) {
        allFinished = true;
        errors = 0L;
        // Check the remote server
        if (allFinished && errors == 0) {
            try {
                SlaveServerTransStatus transStatus = remoteSlaveServer.getTransStatus(transName, carteObjectId, 0);
                if (transStatus.isRunning()) {
                    if (log.isDetailed()) {
                        log.logDetailed(transName, "Remote transformation is still running.");
                    }
                    allFinished = false;
                } else {
                    if (log.isDetailed()) {
                        log.logDetailed(transName, "Remote transformation has finished.");
                    }
                }
                Result result = transStatus.getResult();
                errors += result.getNrErrors();
            } catch (Exception e) {
                errors += 1;
                log.logError(transName, "Unable to contact remote slave server '" + remoteSlaveServer.getName() + "' to check transformation status : " + e.toString());
            }
        }
        // 
        if (!allFinished) {
            // Not finished or error: wait a bit longer
            if (log.isDetailed()) {
                log.logDetailed(transName, "The remote transformation is still running, waiting a few seconds...");
            }
            try {
                Thread.sleep(sleepTimeSeconds * 1000);
            } catch (Exception e) {
            // Ignore errors
            }
        // Check all slaves every x seconds.
        }
    }
    log.logMinimal(transName, "The remote transformation has finished.");
    // 
    try {
        WebResult webResult = remoteSlaveServer.cleanupTransformation(transName, carteObjectId);
        if (!WebResult.STRING_OK.equals(webResult.getResult())) {
            log.logError(transName, "Unable to run clean-up on remote transformation '" + transName + "' : " + webResult.getMessage());
            errors += 1;
        }
    } catch (Exception e) {
        errors += 1;
        log.logError(transName, "Unable to contact slave server '" + remoteSlaveServer.getName() + "' to clean up transformation : " + e.toString());
    }
}
Also used : SlaveServerTransStatus(org.pentaho.di.www.SlaveServerTransStatus) WebResult(org.pentaho.di.www.WebResult) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) WebResult(org.pentaho.di.www.WebResult) Result(org.pentaho.di.core.Result)

Example 7 with SlaveServerTransStatus

use of org.pentaho.di.www.SlaveServerTransStatus in project pentaho-kettle by pentaho.

the class Trans method getClusteredTransformationResult.

/**
 * Gets the clustered transformation result.
 *
 * @param log
 *          the log channel interface
 * @param transSplitter
 *          the TransSplitter object
 * @param parentJob
 *          the parent job
 * @param loggingRemoteWork
 *          log remote execution logs locally
 * @return the clustered transformation result
 */
public static final Result getClusteredTransformationResult(LogChannelInterface log, TransSplitter transSplitter, Job parentJob, boolean loggingRemoteWork) {
    Result result = new Result();
    // 
    // See if the remote transformations have finished.
    // We could just look at the master, but I doubt that that is enough in all situations.
    // 
    // <-- ask these guys
    SlaveServer[] slaveServers = transSplitter.getSlaveTargets();
    TransMeta[] slaves = transSplitter.getSlaves();
    SlaveServer masterServer;
    try {
        masterServer = transSplitter.getMasterServer();
    } catch (KettleException e) {
        log.logError("Error getting the master server", e);
        masterServer = null;
        result.setNrErrors(result.getNrErrors() + 1);
    }
    TransMeta master = transSplitter.getMaster();
    // 
    for (int s = 0; s < slaveServers.length; s++) {
        try {
            // Get the detailed status of the slave transformation...
            // 
            SlaveServerTransStatus transStatus = slaveServers[s].getTransStatus(slaves[s].getName(), "", 0);
            Result transResult = transStatus.getResult(slaves[s]);
            result.add(transResult);
            if (loggingRemoteWork) {
                log.logBasic("-- Slave : " + slaveServers[s].getName());
                log.logBasic(transStatus.getLoggingString());
            }
        } catch (Exception e) {
            result.setNrErrors(result.getNrErrors() + 1);
            log.logError("Unable to contact slave server '" + slaveServers[s].getName() + "' to get result of slave transformation : " + e.toString());
        }
    }
    // 
    if (master != null && master.nrSteps() > 0) {
        try {
            // Get the detailed status of the slave transformation...
            // 
            SlaveServerTransStatus transStatus = masterServer.getTransStatus(master.getName(), "", 0);
            Result transResult = transStatus.getResult(master);
            result.add(transResult);
            if (loggingRemoteWork) {
                log.logBasic("-- Master : " + masterServer.getName());
                log.logBasic(transStatus.getLoggingString());
            }
        } catch (Exception e) {
            result.setNrErrors(result.getNrErrors() + 1);
            log.logError("Unable to contact master server '" + masterServer.getName() + "' to get result of master transformation : " + e.toString());
        }
    }
    return result;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SlaveServerTransStatus(org.pentaho.di.www.SlaveServerTransStatus) SlaveServer(org.pentaho.di.cluster.SlaveServer) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) WebResult(org.pentaho.di.www.WebResult) Result(org.pentaho.di.core.Result)

Example 8 with SlaveServerTransStatus

use of org.pentaho.di.www.SlaveServerTransStatus in project pentaho-kettle by pentaho.

the class SpoonSlave method remove.

protected void remove() {
    TreeEntry treeEntry = getTreeEntry();
    if (treeEntry == null) {
        return;
    }
    if (treeEntry.isTransformation()) {
        // Transformation
        SlaveServerTransStatus transStatus = slaveServerStatus.findTransStatus(treeEntry.name, treeEntry.id);
        if (transStatus != null) {
            if (!transStatus.isRunning() && !transStatus.isPaused() && !transStatus.isStopped()) {
                try {
                    WebResult webResult = slaveServer.removeTransformation(treeEntry.name, transStatus.getId());
                    if (WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                        // Force refresh in order to give faster visual feedback and reengage the timer
                        wTree.deselectAll();
                        engageViewAndLogUpdateTimer();
                    } else {
                        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingTrans.Message"), webResult.getMessage());
                        dialog.setReadOnly();
                        dialog.open();
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingTrans.Message"), e);
                }
            }
        }
    } else if (treeEntry.isJob()) {
        // Job
        SlaveServerJobStatus jobStatus = slaveServerStatus.findJobStatus(treeEntry.name, treeEntry.id);
        if (jobStatus != null) {
            if (!jobStatus.isRunning()) {
                try {
                    WebResult webResult = slaveServer.removeJob(treeEntry.name, jobStatus.getId());
                    if (WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                        // Force refresh in order to give faster visual feedback and reengage the timer
                        wTree.deselectAll();
                        engageViewAndLogUpdateTimer();
                    } else {
                        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingJob.Message"), webResult.getMessage());
                        dialog.setReadOnly();
                        dialog.open();
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingJob.Message"), e);
                }
            }
        }
    }
}
Also used : SlaveServerJobStatus(org.pentaho.di.www.SlaveServerJobStatus) SlaveServerTransStatus(org.pentaho.di.www.SlaveServerTransStatus) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) WebResult(org.pentaho.di.www.WebResult)

Example 9 with SlaveServerTransStatus

use of org.pentaho.di.www.SlaveServerTransStatus in project pentaho-kettle by pentaho.

the class SpoonSlave method stop.

protected void stop() {
    TreeEntry treeEntry = getTreeEntry();
    if (treeEntry == null) {
        return;
    }
    if (treeEntry.isTransformation()) {
        // Transformation
        SlaveServerTransStatus transStatus = slaveServerStatus.findTransStatus(treeEntry.name, treeEntry.id);
        if (transStatus != null) {
            if (transStatus.isRunning() || transStatus.isPaused()) {
                try {
                    WebResult webResult = slaveServer.stopTransformation(treeEntry.name, transStatus.getId());
                    if (!WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingTrans.Message"), webResult.getMessage());
                        dialog.setReadOnly();
                        dialog.open();
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingTrans.Message"), e);
                }
            }
        }
    } else if (treeEntry.isJob()) {
        // Job
        SlaveServerJobStatus jobStatus = slaveServerStatus.findJobStatus(treeEntry.name, treeEntry.id);
        if (jobStatus != null) {
            if (jobStatus.isRunning()) {
                try {
                    WebResult webResult = slaveServer.stopJob(treeEntry.name, jobStatus.getId());
                    if (!WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingJob.Message"), webResult.getMessage());
                        dialog.setReadOnly();
                        dialog.open();
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingJob.Message"), e);
                }
            }
        }
    }
}
Also used : SlaveServerJobStatus(org.pentaho.di.www.SlaveServerJobStatus) SlaveServerTransStatus(org.pentaho.di.www.SlaveServerTransStatus) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) WebResult(org.pentaho.di.www.WebResult)

Example 10 with SlaveServerTransStatus

use of org.pentaho.di.www.SlaveServerTransStatus in project pentaho-kettle by pentaho.

the class SpoonSlave method treeItemSelected.

public void treeItemSelected(TreeItem item) {
    if (item == null) {
        // there is nothing to do
        return;
    }
    // load node upon expansion
    if (item.getData("transStatus") != null) {
        SlaveServerTransStatus transStatus = (SlaveServerTransStatus) item.getData("transStatus");
        try {
            if (log.isDetailed()) {
                log.logDetailed("Getting transformation status for [{0}] on server [{1}]", transStatus.getTransName(), SpoonSlave.this.slaveServer);
            }
            SlaveServerTransStatus ts = SpoonSlave.this.slaveServer.getTransStatus(transStatus.getTransName(), transStatus.getId(), 0);
            if (log.isDetailed()) {
                log.logDetailed("Finished receiving transformation status for [{0}] from server [{1}]", transStatus.getTransName(), SpoonSlave.this.slaveServer);
            }
            List<StepStatus> stepStatusList = ts.getStepStatusList();
            transStatus.setStepStatusList(stepStatusList);
            String logging = ts.getLoggingString();
            String[] lines = logging.split("\r\n|\r|\n");
            if (lines.length > PropsUI.getInstance().getMaxNrLinesInLog()) {
                // Trim to view the last x lines
                int offset = lines.length - PropsUI.getInstance().getMaxNrLinesInLog();
                StringBuilder trimmedLog = new StringBuilder();
                // Keep only the text from offset to the end of the log
                while (offset != lines.length) {
                    trimmedLog.append(lines[offset++]).append('\n');
                }
                logging = trimmedLog.toString();
            }
            currentLogText = logging;
            item.removeAll();
            for (StepStatus stepStatus : stepStatusList) {
                TreeItem stepItem = new TreeItem(item, SWT.NONE);
                stepItem.setText(stepStatus.getSpoonSlaveLogFields());
            }
        } catch (Exception e) {
            transStatus.setErrorDescription("Unable to access transformation details : " + Const.CR + Const.getStackTracker(e));
        }
    } else if (item.getData("jobStatus") != null) {
        SlaveServerJobStatus jobStatus = (SlaveServerJobStatus) item.getData("jobStatus");
        try {
            if (log.isDetailed()) {
                log.logDetailed("Getting job status for [{0}] on server [{1}]", jobStatus.getJobName(), slaveServer);
            }
            SlaveServerJobStatus ts = slaveServer.getJobStatus(jobStatus.getJobName(), jobStatus.getId(), 0);
            if (log.isDetailed()) {
                log.logDetailed("Finished receiving job status for [{0}] from server [{1}]", jobStatus.getJobName(), slaveServer);
            }
            String logging = ts.getLoggingString();
            String[] lines = logging.split("\r\n|\r|\n");
            if (lines.length > PropsUI.getInstance().getMaxNrLinesInLog()) {
                // Trim to view the last x lines
                int offset = lines.length - PropsUI.getInstance().getMaxNrLinesInLog();
                StringBuilder trimmedLog = new StringBuilder();
                // Keep only the text from offset to the end of the log
                while (offset != lines.length) {
                    trimmedLog.append(lines[offset++]).append('\n');
                }
                logging = trimmedLog.toString();
            }
            currentLogText = logging;
            Result result = ts.getResult();
            if (result != null) {
                item.setText(2, "" + result.getNrLinesRead());
                item.setText(3, "" + result.getNrLinesWritten());
                item.setText(4, "" + result.getNrLinesInput());
                item.setText(5, "" + result.getNrLinesOutput());
                item.setText(6, "" + result.getNrLinesUpdated());
                item.setText(7, "" + result.getNrLinesRejected());
                item.setText(8, "" + result.getNrErrors());
            }
        } catch (Exception e) {
            jobStatus.setErrorDescription("Unable to access transformation details : " + Const.CR + Const.getStackTracker(e));
        }
    }
}
Also used : SlaveServerJobStatus(org.pentaho.di.www.SlaveServerJobStatus) TreeItem(org.eclipse.swt.widgets.TreeItem) SlaveServerTransStatus(org.pentaho.di.www.SlaveServerTransStatus) StepStatus(org.pentaho.di.trans.step.StepStatus) WebResult(org.pentaho.di.www.WebResult) Result(org.pentaho.di.core.Result)

Aggregations

SlaveServerTransStatus (org.pentaho.di.www.SlaveServerTransStatus)10 WebResult (org.pentaho.di.www.WebResult)7 SlaveServerJobStatus (org.pentaho.di.www.SlaveServerJobStatus)6 Result (org.pentaho.di.core.Result)5 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 KettleException (org.pentaho.di.core.exception.KettleException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SlaveServer (org.pentaho.di.cluster.SlaveServer)3 KettleFileException (org.pentaho.di.core.exception.KettleFileException)3 KettleTransException (org.pentaho.di.core.exception.KettleTransException)3 KettleValueException (org.pentaho.di.core.exception.KettleValueException)3 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)3 DuplicateParamException (org.pentaho.di.core.parameters.DuplicateParamException)3 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)3 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)3 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)3 TreeItem (org.eclipse.swt.widgets.TreeItem)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ResultFile (org.pentaho.di.core.ResultFile)1