Search in sources :

Example 6 with JobAdapter

use of org.pentaho.di.job.JobAdapter 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 7 with JobAdapter

use of org.pentaho.di.job.JobAdapter 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)7 JobAdapter (org.pentaho.di.job.JobAdapter)7 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)6 JobMeta (org.pentaho.di.job.JobMeta)6 KettleException (org.pentaho.di.core.exception.KettleException)5 JobExecutionConfiguration (org.pentaho.di.job.JobExecutionConfiguration)5 Repository (org.pentaho.di.repository.Repository)5 JobConfiguration (org.pentaho.di.job.JobConfiguration)4 IOException (java.io.IOException)3 PrintWriter (java.io.PrintWriter)3 ServletException (javax.servlet.ServletException)3 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)3 LogLevel (org.pentaho.di.core.logging.LogLevel)2 StreamSource (ca.uhn.hl7v2.protocol.StreamSource)1 MLLPTransport (ca.uhn.hl7v2.protocol.impl.MLLPTransport)1 ServerSocketStreamSource (ca.uhn.hl7v2.protocol.impl.ServerSocketStreamSource)1 BufferedReader (java.io.BufferedReader)1 ServerSocket (java.net.ServerSocket)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1