Search in sources :

Example 1 with SlaveServerJobStatus

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

the class JobEntryJobIT method testLogfileWritesFromRemote.

@Test
public void testLogfileWritesFromRemote() throws Exception {
    JobEntryJob job = spy(new JobEntryJob(JOB_ENTRY_JOB_NAME));
    doCallRealMethod().when(job).execute(any(Result.class), anyInt());
    Job parentJob = mock(Job.class);
    JobMeta parentJobMeta = mock(JobMeta.class);
    JobMeta jobMeta = mock(JobMeta.class);
    SlaveServer slaveServer = mock(SlaveServer.class);
    LogChannelInterface log = mock(LogChannelInterface.class);
    SlaveServerJobStatus status = mock(SlaveServerJobStatus.class);
    when(parentJob.getLogLevel()).thenReturn(LogLevel.BASIC);
    when(parentJobMeta.getRepositoryDirectory()).thenReturn(null);
    when(jobMeta.getRepositoryDirectory()).thenReturn(mock(RepositoryDirectoryInterface.class));
    when(jobMeta.getName()).thenReturn(JOB_META_NAME);
    when(parentJob.getJobMeta()).thenReturn(parentJobMeta);
    when(parentJobMeta.findSlaveServer(REMOTE_SLAVE_SERVER_NAME)).thenReturn(slaveServer);
    when(slaveServer.getLogChannel()).thenReturn(log);
    when(log.getLogLevel()).thenReturn(LogLevel.BASIC);
    when(slaveServer.sendXML(anyString(), anyString())).thenReturn(REPLY);
    when(slaveServer.execService(anyString())).thenReturn(REPLY);
    when(slaveServer.getJobStatus(anyString(), anyString(), anyInt())).thenReturn(status);
    when(status.getResult()).thenReturn(mock(Result.class));
    when(status.getLoggingString()).thenReturn(LOG);
    FILE = Files.createTempFile("file", "");
    doReturn(LOG_FILE_NAME).when(job).getLogFilename();
    doReturn(FILE.toString()).when(job).environmentSubstitute(LOG_FILE_NAME);
    doReturn(REMOTE_SLAVE_SERVER_NAME).when(job).environmentSubstitute(REMOTE_SLAVE_SERVER_NAME);
    doReturn(jobMeta).when(job).getJobMeta(any(Repository.class), any(VariableSpace.class));
    doNothing().when(job).copyVariablesFrom(anyObject());
    doNothing().when(job).setParentVariableSpace(anyObject());
    job.setLogfile = true;
    job.createParentFolder = false;
    job.logFileLevel = LogLevel.BASIC;
    job.execPerRow = false;
    job.paramsFromPrevious = false;
    job.argFromPrevious = false;
    job.waitingToFinish = true;
    job.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
    job.setRemoteSlaveServerName(REMOTE_SLAVE_SERVER_NAME);
    job.setParentJob(parentJob);
    job.setParentJobMeta(parentJobMeta);
    job.execute(new Result(), 0);
    String result = Files.lines(FILE).collect(Collectors.joining(""));
    assertTrue(result.contains(LOG));
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) JobMeta(org.pentaho.di.job.JobMeta) SlaveServerJobStatus(org.pentaho.di.www.SlaveServerJobStatus) Repository(org.pentaho.di.repository.Repository) VariableSpace(org.pentaho.di.core.variables.VariableSpace) Matchers.anyString(org.mockito.Matchers.anyString) Job(org.pentaho.di.job.Job) SlaveServer(org.pentaho.di.cluster.SlaveServer) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 2 with SlaveServerJobStatus

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

the class SpoonSlave method refreshView.

private synchronized void refreshView() {
    if (wTree.isDisposed()) {
        return;
    }
    if (refreshBusy) {
        return;
    }
    refreshBusy = true;
    if (log.isDetailed()) {
        log.logDetailed("Refresh");
    }
    transParentItem.removeAll();
    jobParentItem.removeAll();
    wText.setText("");
    // Determine the transformations on the slave servers
    try {
        slaveServerStatus = slaveServer.getStatus();
    } catch (Exception e) {
        slaveServerStatus = new SlaveServerStatus("Error contacting server");
        slaveServerStatus.setErrorDescription(Const.getStackTracker(e));
        if (log.isDebug()) {
            log.logDebug(slaveServerStatus.getErrorDescription());
        }
        wText.setText(setExceptionMessage(e));
    }
    List<SlaveServerTransStatus> transStatusList = slaveServerStatus.getTransStatusList();
    for (SlaveServerTransStatus transStatus : transStatusList) {
        TreeItem transItem = new TreeItem(transParentItem, SWT.NONE);
        transItem.setText(0, transStatus.getTransName());
        transItem.setText(9, transStatus.getStatusDescription());
        transItem.setText(13, Const.NVL(transStatus.getId(), ""));
        transItem.setText(14, Const.NVL(XMLHandler.date2string(transStatus.getLogDate()), ""));
        transItem.setImage(GUIResource.getInstance().getImageTransGraph());
        transItem.setData("transStatus", transStatus);
    }
    for (int i = 0; i < slaveServerStatus.getJobStatusList().size(); i++) {
        SlaveServerJobStatus jobStatus = slaveServerStatus.getJobStatusList().get(i);
        TreeItem jobItem = new TreeItem(jobParentItem, SWT.NONE);
        jobItem.setText(0, jobStatus.getJobName());
        jobItem.setText(9, jobStatus.getStatusDescription());
        jobItem.setText(13, Const.NVL(jobStatus.getId(), ""));
        jobItem.setText(14, Const.NVL(XMLHandler.date2string(jobStatus.getLogDate()), ""));
        jobItem.setImage(GUIResource.getInstance().getImageJobGraph());
        jobItem.setData("jobStatus", jobStatus);
    }
    TreeMemory.setExpandedFromMemory(wTree, STRING_SLAVE_LOG_TREE_NAME + slaveServer.toString());
    TreeUtil.setOptimalWidthOnColumns(wTree);
    refreshBusy = false;
}
Also used : SlaveServerStatus(org.pentaho.di.www.SlaveServerStatus) SlaveServerJobStatus(org.pentaho.di.www.SlaveServerJobStatus) TreeItem(org.eclipse.swt.widgets.TreeItem) SlaveServerTransStatus(org.pentaho.di.www.SlaveServerTransStatus)

Example 3 with SlaveServerJobStatus

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

the class SpoonSlave method start.

protected void start() {
    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()) {
                try {
                    WebResult webResult = slaveServer.startTransformation(treeEntry.name, transStatus.getId());
                    if (!WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingTrans.Message"), webResult.getMessage());
                        dialog.setReadOnly();
                        dialog.open();
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingTrans.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.startJob(treeEntry.name, jobStatus.getId());
                    if (!WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingJob.Message"), webResult.getMessage());
                        dialog.setReadOnly();
                        dialog.open();
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingJob.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 4 with SlaveServerJobStatus

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

the class SpoonSlave method showLog.

/**
 * Someone clicks on a line: show the log or error message associated with that in the text-box
 */
public void showLog() {
    TreeEntry treeEntry = getTreeEntry();
    if (treeEntry == null) {
        return;
    }
    if (treeEntry.length <= 1) {
        return;
    }
    if (treeEntry.isTransformation()) {
        // Transformation
        SlaveServerTransStatus transStatus = slaveServerStatus.findTransStatus(treeEntry.name, treeEntry.id);
        StringBuilder message = new StringBuilder();
        String errorDescription = transStatus.getErrorDescription();
        if (!Utils.isEmpty(errorDescription)) {
            message.append(errorDescription).append(Const.CR).append(Const.CR);
        }
        if (!Utils.isEmpty(currentLogText)) {
            message.append(currentLogText).append(Const.CR);
        }
        wText.setText(message.toString());
        wText.setSelection(wText.getText().length());
        wText.showSelection();
    } else if (treeEntry.isJob()) {
        // Job
        SlaveServerJobStatus jobStatus = slaveServerStatus.findJobStatus(treeEntry.name, treeEntry.id);
        StringBuilder message = new StringBuilder();
        String errorDescription = jobStatus.getErrorDescription();
        if (!Utils.isEmpty(errorDescription)) {
            message.append(errorDescription).append(Const.CR).append(Const.CR);
        }
        if (!Utils.isEmpty(currentLogText)) {
            message.append(currentLogText).append(Const.CR);
        }
        wText.setText(message.toString());
        wText.setSelection(wText.getText().length());
        wText.showSelection();
    } else {
        currentLogText = null;
    }
}
Also used : SlaveServerJobStatus(org.pentaho.di.www.SlaveServerJobStatus) SlaveServerTransStatus(org.pentaho.di.www.SlaveServerTransStatus)

Example 5 with SlaveServerJobStatus

use of org.pentaho.di.www.SlaveServerJobStatus 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)

Aggregations

SlaveServerJobStatus (org.pentaho.di.www.SlaveServerJobStatus)8 SlaveServerTransStatus (org.pentaho.di.www.SlaveServerTransStatus)6 WebResult (org.pentaho.di.www.WebResult)4 Result (org.pentaho.di.core.Result)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 SlaveServer (org.pentaho.di.cluster.SlaveServer)2 Job (org.pentaho.di.job.Job)2 JobMeta (org.pentaho.di.job.JobMeta)2 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 FileObject (org.apache.commons.vfs2.FileObject)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ResultFile (org.pentaho.di.core.ResultFile)1 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1