Search in sources :

Example 71 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class JobExecutorTest method setUp.

@Before
public void setUp() throws Exception {
    executor = StepMockUtil.getStep(JobExecutor.class, JobExecutorMeta.class, "TransExecutorUnitTest");
    executor = spy(executor);
    executor.setInputRowMeta(mock(RowMetaInterface.class));
    doNothing().when(executor).discardLogLines(any(JobExecutorData.class));
    meta = new JobExecutorMeta();
    data = new JobExecutorData();
    Job job = mock(Job.class);
    doReturn(job).when(executor).createJob(any(Repository.class), any(JobMeta.class), any(LoggingObjectInterface.class));
    doReturn(ArrayUtils.EMPTY_STRING_ARRAY).when(job).listParameters();
    data.groupBuffer = new ArrayList<>();
    data.groupSize = -1;
    data.groupTime = -1;
    data.groupField = null;
}
Also used : Repository(org.pentaho.di.repository.Repository) JobMeta(org.pentaho.di.job.JobMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Job(org.pentaho.di.job.Job) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) Before(org.junit.Before)

Example 72 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class RunConfigurationInjectExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(LogChannelInterface log, Object object) throws KettleException {
    if (!(object instanceof JobExecutionExtension)) {
        return;
    }
    JobExecutionExtension extension = (JobExecutionExtension) object;
    Job job = extension.job;
    JobMeta jobMeta = job.getJobMeta();
    final EmbeddedMetaStore embeddedMetaStore = jobMeta.getEmbeddedMetaStore();
    RunConfigurationManager embeddedRunConfigurationManager = EmbeddedRunConfigurationManager.build(embeddedMetaStore);
    // will load and save to meta all run configurations
    for (JobEntryTrans trans : job.getActiveJobEntryTransformations().values()) {
        RunConfiguration loadedRunConfiguration = runConfigurationManager.load(jobMeta.environmentSubstitute(trans.getRunConfiguration()));
        embeddedRunConfigurationManager.save(loadedRunConfiguration);
    }
    for (JobEntryJob subJob : job.getActiveJobEntryJobs().values()) {
        RunConfiguration loadedRunConfiguration = runConfigurationManager.load(jobMeta.environmentSubstitute(subJob.getRunConfiguration()));
        embeddedRunConfigurationManager.save(loadedRunConfiguration);
    }
}
Also used : JobExecutionExtension(org.pentaho.di.job.JobExecutionExtension) JobMeta(org.pentaho.di.job.JobMeta) RunConfiguration(org.pentaho.di.engine.configuration.api.RunConfiguration) RunConfigurationManager(org.pentaho.di.engine.configuration.impl.RunConfigurationManager) EmbeddedRunConfigurationManager(org.pentaho.di.engine.configuration.impl.EmbeddedRunConfigurationManager) JobEntryTrans(org.pentaho.di.job.entries.trans.JobEntryTrans) JobEntryJob(org.pentaho.di.job.entries.job.JobEntryJob) Job(org.pentaho.di.job.Job) EmbeddedMetaStore(org.pentaho.di.core.attributes.metastore.EmbeddedMetaStore) JobEntryJob(org.pentaho.di.job.entries.job.JobEntryJob)

Example 73 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class JobGraph method startJob.

public synchronized void startJob(JobExecutionConfiguration executionConfiguration) throws KettleException {
    // 
    if (job == null || job.isFinished() && !job.isActive()) {
        // Auto save feature...
        // 
        handleJobMetaChanges(jobMeta);
        // 
        if (((jobMeta.getName() != null && jobMeta.getObjectId() != null && spoon.rep != null) || (jobMeta.getFilename() != null && spoon.rep == null)) && // Didn't change
        !jobMeta.hasChanged()) {
            if (job == null || (job != null && !job.isActive())) {
                try {
                    // 
                    if (executionConfiguration.isClearingLog()) {
                        jobLogDelegate.clearLog();
                    }
                    // 
                    if (job != null) {
                        KettleLogStore.discardLines(job.getLogChannelId(), true);
                    }
                    JobMeta runJobMeta;
                    if (spoon.rep != null) {
                        runJobMeta = spoon.rep.loadJob(jobMeta.getName(), jobMeta.getRepositoryDirectory(), null, null);
                    } else {
                        runJobMeta = new JobMeta(null, jobMeta.getFilename(), null, jobMeta.getMetaStore(), null);
                    }
                    String spoonObjectId = UUID.randomUUID().toString();
                    SimpleLoggingObject spoonLoggingObject = new SimpleLoggingObject("SPOON", LoggingObjectType.SPOON, null);
                    spoonLoggingObject.setContainerObjectId(spoonObjectId);
                    spoonLoggingObject.setLogLevel(executionConfiguration.getLogLevel());
                    job = new Job(spoon.rep, runJobMeta, spoonLoggingObject);
                    job.setLogLevel(executionConfiguration.getLogLevel());
                    job.shareVariablesWith(jobMeta);
                    job.setInteractive(true);
                    job.setGatheringMetrics(executionConfiguration.isGatheringMetrics());
                    job.setArguments(executionConfiguration.getArgumentStrings());
                    // Pass specific extension points...
                    // 
                    job.getExtensionDataMap().putAll(executionConfiguration.getExtensionOptions());
                    // Add job entry listeners
                    // 
                    job.addJobEntryListener(createRefreshJobEntryListener());
                    // 
                    if (!Utils.isEmpty(executionConfiguration.getStartCopyName())) {
                        JobEntryCopy startJobEntryCopy = runJobMeta.findJobEntry(executionConfiguration.getStartCopyName(), executionConfiguration.getStartCopyNr(), false);
                        job.setStartJobEntryCopy(startJobEntryCopy);
                    }
                    // Set the named parameters
                    Map<String, String> paramMap = executionConfiguration.getParams();
                    Set<String> keys = paramMap.keySet();
                    for (String key : keys) {
                        job.getJobMeta().setParameterValue(key, Const.NVL(paramMap.get(key), ""));
                    }
                    job.getJobMeta().activateParameters();
                    log.logMinimal(BaseMessages.getString(PKG, "JobLog.Log.StartingJob"));
                    job.start();
                    jobGridDelegate.previousNrItems = -1;
                    // Link to the new jobTracker!
                    jobGridDelegate.jobTracker = job.getJobTracker();
                    // Attach a listener to notify us that the transformation has
                    // finished.
                    job.addJobListener(new JobAdapter() {

                        public void jobFinished(Job job) {
                            JobGraph.this.jobFinished();
                        }
                    });
                    // Show the execution results views
                    // 
                    addAllTabs();
                } catch (KettleException e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "JobLog.Dialog.CanNotOpenJob.Title"), BaseMessages.getString(PKG, "JobLog.Dialog.CanNotOpenJob.Message"), e);
                    job = null;
                }
            } else {
                MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
                m.setText(BaseMessages.getString(PKG, "JobLog.Dialog.JobIsAlreadyRunning.Title"));
                m.setMessage(BaseMessages.getString(PKG, "JobLog.Dialog.JobIsAlreadyRunning.Message"));
                m.open();
            }
        } else {
            if (jobMeta.hasChanged()) {
                showSaveFileMessage();
            } else if (spoon.rep != null && jobMeta.getName() == null) {
                MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
                m.setText(BaseMessages.getString(PKG, "JobLog.Dialog.PleaseGiveThisJobAName.Title"));
                m.setMessage(BaseMessages.getString(PKG, "JobLog.Dialog.PleaseGiveThisJobAName.Message"));
                m.open();
            } else {
                MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
                m.setText(BaseMessages.getString(PKG, "JobLog.Dialog.NoFilenameSaveYourJobFirst.Title"));
                m.setMessage(BaseMessages.getString(PKG, "JobLog.Dialog.NoFilenameSaveYourJobFirst.Message"));
                m.open();
            }
        }
        setControlStates();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) Job(org.pentaho.di.job.Job) JobEntryJob(org.pentaho.di.job.entries.job.JobEntryJob) JobAdapter(org.pentaho.di.job.JobAdapter) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 74 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class TransGraph method attachActiveJob.

/**
 * Finds the last active job in the running transformation to the opened jobMeta
 *
 * @param jobGraph
 * @param stepMeta
 */
private void attachActiveJob(JobGraph jobGraph, StepMeta stepMeta) {
    if (trans != null && jobGraph != null) {
        Job subJob = trans.getActiveSubjobs().get(stepMeta.getName());
        jobGraph.setJob(subJob);
        if (!jobGraph.isExecutionResultsPaneVisible()) {
            jobGraph.showExecutionResults();
        }
        jobGraph.setControlStates();
    }
}
Also used : Job(org.pentaho.di.job.Job)

Example 75 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class MLLPSocketCache method getServerSocketStreamSource.

public MLLPSocketCacheEntry getServerSocketStreamSource(String server, int port) throws Exception {
    final String key = createKey(server, port);
    MLLPSocketCacheEntry s = map.get(key);
    if (s != null) {
        return s;
    }
    // Open the socket for this server/port combination.
    // 
    ServerSocket serverSocket = new ServerSocket(port);
    StreamSource streamSource = new ServerSocketStreamSource(serverSocket, server);
    MLLPTransport transport = new MLLPTransport(streamSource);
    transport.connect();
    final MLLPSocketCacheEntry entry = new MLLPSocketCacheEntry(serverSocket, streamSource, transport);
    entry.setJobListener(new JobAdapter() {

        @Override
        public void jobFinished(Job job) throws KettleException {
            KettleException exception = null;
            try {
                entry.getTransport().disconnect();
            } catch (Exception e) {
                exception = new KettleException(e);
            }
            try {
                entry.getStreamSource().disconnect();
            } catch (Exception e) {
                exception = new KettleException(e);
            }
            try {
                entry.getServerSocket().close();
            } catch (Exception e) {
                exception = new KettleException(e);
            }
            map.remove(key);
            if (exception != null) {
                throw exception;
            }
        }
    });
    // Store a copy in our map to make sure that only the first return value contains the job listener.
    // 
    map.put(key, new MLLPSocketCacheEntry(serverSocket, streamSource, transport));
    return entry;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) MLLPTransport(ca.uhn.hl7v2.protocol.impl.MLLPTransport) ServerSocketStreamSource(ca.uhn.hl7v2.protocol.impl.ServerSocketStreamSource) ServerSocketStreamSource(ca.uhn.hl7v2.protocol.impl.ServerSocketStreamSource) StreamSource(ca.uhn.hl7v2.protocol.StreamSource) ServerSocket(java.net.ServerSocket) Job(org.pentaho.di.job.Job) JobAdapter(org.pentaho.di.job.JobAdapter) KettleException(org.pentaho.di.core.exception.KettleException)

Aggregations

Job (org.pentaho.di.job.Job)95 JobMeta (org.pentaho.di.job.JobMeta)44 Test (org.junit.Test)35 Result (org.pentaho.di.core.Result)22 KettleException (org.pentaho.di.core.exception.KettleException)20 PrintWriter (java.io.PrintWriter)17 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)17 Trans (org.pentaho.di.trans.Trans)14 IOException (java.io.IOException)11 Before (org.junit.Before)11 Point (org.pentaho.di.core.gui.Point)11 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)11 JobExecutionConfiguration (org.pentaho.di.job.JobExecutionConfiguration)10 Repository (org.pentaho.di.repository.Repository)10 ArrayList (java.util.ArrayList)9 ServletException (javax.servlet.ServletException)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)9 JobConfiguration (org.pentaho.di.job.JobConfiguration)9