Search in sources :

Example 1 with JobGraph

use of org.pentaho.di.ui.spoon.job.JobGraph in project pentaho-kettle by pentaho.

the class GraphTest method testDelJobNoSelections.

@Test
public void testDelJobNoSelections() {
    JobMeta jobMeta = mock(JobMeta.class);
    Spoon spoon = mock(Spoon.class);
    when(jobMeta.getSelectedEntries()).thenReturn(Collections.<JobEntryCopy>emptyList());
    JobEntryCopy je = mock(JobEntryCopy.class);
    JobGraph jobGraph = mock(JobGraph.class);
    doCallRealMethod().when(jobGraph).setJobMeta(any(JobMeta.class));
    doCallRealMethod().when(jobGraph).setSpoon(any(Spoon.class));
    doCallRealMethod().when(jobGraph).delSelected(any(JobEntryCopy.class));
    jobGraph.setJobMeta(jobMeta);
    jobGraph.setSpoon(spoon);
    jobGraph.delSelected(je);
    verify(spoon).deleteJobEntryCopies(jobMeta, je);
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) Test(org.junit.Test)

Example 2 with JobGraph

use of org.pentaho.di.ui.spoon.job.JobGraph in project pentaho-kettle by pentaho.

the class SpoonJobDelegate method executeJob.

public void executeJob(JobMeta jobMeta, boolean local, boolean remote, Date replayDate, boolean safe, String startCopyName, int startCopyNr) throws KettleException {
    if (jobMeta == null) {
        return;
    }
    JobExecutionConfiguration executionConfiguration = spoon.getJobExecutionConfiguration();
    // Remember the variables set previously
    // 
    Object[] data = spoon.variables.getData();
    String[] fields = spoon.variables.getRowMeta().getFieldNames();
    Map<String, String> variableMap = new HashMap<>();
    for (int idx = 0; idx < fields.length; idx++) {
        variableMap.put(fields[idx], data[idx].toString());
    }
    executionConfiguration.setVariables(variableMap);
    executionConfiguration.getUsedVariables(jobMeta);
    executionConfiguration.setReplayDate(replayDate);
    executionConfiguration.setRepository(spoon.rep);
    executionConfiguration.setSafeModeEnabled(safe);
    executionConfiguration.setStartCopyName(startCopyName);
    executionConfiguration.setStartCopyNr(startCopyNr);
    executionConfiguration.getUsedArguments(jobMeta, spoon.getArguments(), spoon.getMetaStore());
    executionConfiguration.setLogLevel(DefaultLogLevel.getLogLevel());
    JobExecutionConfigurationDialog dialog = newJobExecutionConfigurationDialog(executionConfiguration, jobMeta);
    if (!jobMeta.isShowDialog() || dialog.open()) {
        JobGraph jobGraph = spoon.getActiveJobGraph();
        jobGraph.jobLogDelegate.addJobLog();
        // 
        for (String varName : executionConfiguration.getVariables().keySet()) {
            String varValue = executionConfiguration.getVariables().get(varName);
            jobMeta.setVariable(varName, varValue);
        }
        // 
        for (String paramName : executionConfiguration.getParams().keySet()) {
            String paramValue = executionConfiguration.getParams().get(paramName);
            jobMeta.setParameterValue(paramName, paramValue);
        }
        jobMeta.activateParameters();
        // 
        if (executionConfiguration.getLogLevel() != null) {
            jobMeta.setLogLevel(executionConfiguration.getLogLevel());
        }
        // 
        if (executionConfiguration.getStartCopyName() != null) {
            jobMeta.setStartCopyName(executionConfiguration.getStartCopyName());
        }
        // Set the run options
        // 
        jobMeta.setClearingLog(executionConfiguration.isClearingLog());
        jobMeta.setSafeModeEnabled(executionConfiguration.isSafeModeEnabled());
        jobMeta.setExpandingRemoteJob(executionConfiguration.isExpandingRemoteJob());
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonJobMetaExecutionStart.id, jobMeta);
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonJobExecutionConfiguration.id, executionConfiguration);
        try {
            ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonTransBeforeStart.id, new Object[] { executionConfiguration, jobMeta, jobMeta, spoon.getRepository() });
        } catch (KettleException e) {
            log.logError(e.getMessage(), jobMeta.getFilename());
            return;
        }
        if (!executionConfiguration.isExecutingLocally() && !executionConfiguration.isExecutingRemotely()) {
            if (jobMeta.hasChanged()) {
                jobGraph.showSaveFileMessage();
            }
        }
        // 
        if (executionConfiguration.isExecutingLocally()) {
            jobGraph.startJob(executionConfiguration);
        } else if (executionConfiguration.isExecutingRemotely()) {
            // Executing remotely
            // Check if jobMeta has changed
            jobGraph.handleJobMetaChanges(jobMeta);
            // Activate the parameters, turn them into variables...
            // jobMeta.hasChanged()
            jobMeta.activateParameters();
            if (executionConfiguration.getRemoteServer() != null) {
                Job.sendToSlaveServer(jobMeta, executionConfiguration, spoon.rep, spoon.metaStore);
                spoon.delegates.slaves.addSpoonSlave(executionConfiguration.getRemoteServer());
            } else {
                MessageBox mb = new MessageBox(spoon.getShell(), SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NoRemoteServerSpecified.Message"));
                mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NoRemoteServerSpecified.Title"));
                mb.open();
            }
        }
    }
}
Also used : JobExecutionConfigurationDialog(org.pentaho.di.ui.job.dialog.JobExecutionConfigurationDialog) KettleException(org.pentaho.di.core.exception.KettleException) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) HashMap(java.util.HashMap) JobExecutionConfiguration(org.pentaho.di.job.JobExecutionConfiguration) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 3 with JobGraph

use of org.pentaho.di.ui.spoon.job.JobGraph in project pentaho-kettle by pentaho.

the class SpoonTabsDelegate method getActiveMeta.

public EngineMetaInterface getActiveMeta() {
    TabSet tabfolder = spoon.tabfolder;
    if (tabfolder == null) {
        return null;
    }
    TabItem tabItem = tabfolder.getSelected();
    if (tabItem == null) {
        return null;
    }
    // What transformation is in the active tab?
    // TransLog, TransGraph & TransHist contain the same transformation
    // 
    TabMapEntry mapEntry = getTab(tabfolder.getSelected());
    EngineMetaInterface meta = null;
    if (mapEntry != null) {
        if (mapEntry.getObject() instanceof TransGraph) {
            meta = (mapEntry.getObject()).getMeta();
        }
        if (mapEntry.getObject() instanceof JobGraph) {
            meta = (mapEntry.getObject()).getMeta();
        }
    }
    return meta;
}
Also used : TabItem(org.pentaho.xul.swt.tab.TabItem) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) TabSet(org.pentaho.xul.swt.tab.TabSet) EngineMetaInterface(org.pentaho.di.core.EngineMetaInterface) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) TabMapEntry(org.pentaho.di.ui.spoon.TabMapEntry)

Example 4 with JobGraph

use of org.pentaho.di.ui.spoon.job.JobGraph in project pentaho-kettle by pentaho.

the class SpoonTabsDelegate method tabClose.

public boolean tabClose(TabItem item, boolean force) throws KettleException {
    // Try to find the tab-item that's being closed.
    boolean createPerms = !RepositorySecurityUI.verifyOperations(Spoon.getInstance().getShell(), Spoon.getInstance().getRepository(), false, RepositoryOperation.MODIFY_TRANSFORMATION, RepositoryOperation.MODIFY_JOB);
    boolean close = true;
    boolean canSave = true;
    for (TabMapEntry entry : tabMap) {
        if (item.equals(entry.getTabItem())) {
            final TabItemInterface itemInterface = entry.getObject();
            final Object managedObject = itemInterface.getManagedObject();
            if (!force) {
                if (managedObject != null && AbstractMeta.class.isAssignableFrom(managedObject.getClass())) {
                    canSave = !((AbstractMeta) managedObject).hasMissingPlugins();
                }
                if (canSave) {
                    // Can we close this tab? Only allow users with create content perms to save
                    if (!itemInterface.canBeClosed() && createPerms) {
                        int reply = itemInterface.showChangedWarning();
                        if (reply == SWT.YES) {
                            close = itemInterface.applyChanges();
                        } else {
                            if (reply == SWT.CANCEL) {
                                close = false;
                            } else {
                                close = true;
                            }
                        }
                    }
                }
            }
            String beforeCloseId = null;
            String afterCloseId = null;
            if (itemInterface instanceof TransGraph) {
                beforeCloseId = KettleExtensionPoint.TransBeforeClose.id;
                afterCloseId = KettleExtensionPoint.TransAfterClose.id;
            } else if (itemInterface instanceof JobGraph) {
                beforeCloseId = KettleExtensionPoint.JobBeforeClose.id;
                afterCloseId = KettleExtensionPoint.JobAfterClose.id;
            }
            if (beforeCloseId != null) {
                try {
                    ExtensionPointHandler.callExtensionPoint(log, beforeCloseId, managedObject);
                } catch (KettleException e) {
                    // prevent tab close
                    close = false;
                }
            }
            // 
            if (close) {
                if (itemInterface instanceof TransGraph) {
                    TransMeta transMeta = (TransMeta) managedObject;
                    spoon.delegates.trans.closeTransformation(transMeta);
                    spoon.refreshTree();
                // spoon.refreshCoreObjects();
                } else if (itemInterface instanceof JobGraph) {
                    JobMeta jobMeta = (JobMeta) managedObject;
                    spoon.delegates.jobs.closeJob(jobMeta);
                    spoon.refreshTree();
                // spoon.refreshCoreObjects();
                } else if (itemInterface instanceof SpoonBrowser) {
                    this.removeTab(entry);
                    spoon.refreshTree();
                } else if (itemInterface instanceof Composite) {
                    Composite comp = (Composite) itemInterface;
                    if (comp != null && !comp.isDisposed()) {
                        comp.dispose();
                    }
                }
                if (afterCloseId != null) {
                    try {
                        ExtensionPointHandler.callExtensionPoint(log, afterCloseId, managedObject);
                    } catch (KettleException e) {
                    // fails gracefully... what else could we do?
                    }
                }
            }
            break;
        }
    }
    return close;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) Composite(org.eclipse.swt.widgets.Composite) AbstractMeta(org.pentaho.di.base.AbstractMeta) TransMeta(org.pentaho.di.trans.TransMeta) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) TabMapEntry(org.pentaho.di.ui.spoon.TabMapEntry) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) SpoonBrowser(org.pentaho.di.ui.spoon.SpoonBrowser) FileObject(org.apache.commons.vfs2.FileObject) TabItemInterface(org.pentaho.di.ui.spoon.TabItemInterface)

Example 5 with JobGraph

use of org.pentaho.di.ui.spoon.job.JobGraph in project pentaho-kettle by pentaho.

the class SpoonTabsDelegate method renameTabs.

/**
 * Rename the tabs
 */
public void renameTabs() {
    List<TabMapEntry> list = new ArrayList<TabMapEntry>(tabMap);
    for (TabMapEntry entry : list) {
        if (entry.getTabItem().isDisposed()) {
            // this should not be in the map, get rid of it.
            tabMap.remove(entry.getObjectName());
            continue;
        }
        // TabItem before = entry.getTabItem();
        // PDI-1683: need to get the String here, otherwise using only the "before" instance below, the reference gets
        // changed and result is always the same
        // String beforeText=before.getText();
        // 
        Object managedObject = entry.getObject().getManagedObject();
        if (managedObject != null) {
            if (entry.getObject() instanceof AbstractGraph) {
                AbstractMeta meta = (AbstractMeta) managedObject;
                String tabText = makeTabName(meta, entry.isShowingLocation());
                entry.getTabItem().setText(tabText);
                String toolTipText = BaseMessages.getString(PKG, "Spoon.TabTrans.Tooltip", tabText);
                if (entry.getObject() instanceof JobGraph) {
                    toolTipText = BaseMessages.getString(PKG, "Spoon.TabJob.Tooltip", tabText);
                }
                if (Const.isWindows() && !Utils.isEmpty(meta.getFilename())) {
                    toolTipText += Const.CR + Const.CR + meta.getFilename();
                }
                entry.getTabItem().setToolTipText(toolTipText);
            }
        }
    }
    spoon.setShellText();
}
Also used : AbstractGraph(org.pentaho.di.ui.spoon.AbstractGraph) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) AbstractMeta(org.pentaho.di.base.AbstractMeta) ArrayList(java.util.ArrayList) FileObject(org.apache.commons.vfs2.FileObject) TabMapEntry(org.pentaho.di.ui.spoon.TabMapEntry)

Aggregations

JobGraph (org.pentaho.di.ui.spoon.job.JobGraph)27 TransGraph (org.pentaho.di.ui.spoon.trans.TransGraph)15 JobMeta (org.pentaho.di.job.JobMeta)8 TransMeta (org.pentaho.di.trans.TransMeta)6 Test (org.junit.Test)5 TabMapEntry (org.pentaho.di.ui.spoon.TabMapEntry)5 TabItem (org.pentaho.xul.swt.tab.TabItem)5 EngineMetaInterface (org.pentaho.di.core.EngineMetaInterface)4 KettleException (org.pentaho.di.core.exception.KettleException)4 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)4 FileObject (org.apache.commons.vfs2.FileObject)3 Point (org.pentaho.di.core.gui.Point)3 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)3 AbstractMeta (org.pentaho.di.base.AbstractMeta)2 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)2 TransAction (org.pentaho.di.core.undo.TransAction)2 JobExecutionConfiguration (org.pentaho.di.job.JobExecutionConfiguration)2 PurRepository (org.pentaho.di.repository.pur.PurRepository)2 IAbsSecurityProvider (org.pentaho.di.ui.repository.pur.services.IAbsSecurityProvider)2 Spoon (org.pentaho.di.ui.spoon.Spoon)2