Search in sources :

Example 81 with JobEntryCopy

use of org.pentaho.di.job.entry.JobEntryCopy in project pentaho-metaverse by pentaho.

the class JobEntryExternalResourceConsumerListener method callExtensionPoint.

/**
 * This method is called by the Kettle code when a job entry is about to start
 *
 * @param log    the logging channel to log debugging information to
 * @param object The subject object that is passed to the plugin code
 * @throws org.pentaho.di.core.exception.KettleException In case the plugin decides that an error has occurred
 *                                                       and the parent process should stop.
 */
@Override
public void callExtensionPoint(LogChannelInterface log, Object object) throws KettleException {
    if (jobEntryConsumerProvider == null) {
        jobEntryConsumerProvider = (IJobEntryExternalResourceConsumerProvider) MetaverseBeanUtil.getInstance().get("IJobEntryExternalResourceConsumerProvider");
    }
    JobExecutionExtension jobExec = (JobExecutionExtension) object;
    JobEntryCopy jobEntryCopy = jobExec.jobEntryCopy;
    if (jobEntryCopy != null) {
        JobEntryInterface meta = jobEntryCopy.getEntry();
        if (meta != null) {
            Class<?> metaClass = meta.getClass();
            if (JobEntryBase.class.isAssignableFrom(metaClass)) {
                if (jobEntryConsumerProvider != null) {
                    // Put the class into a collection and get the consumers that can process this class
                    Set<Class<?>> metaClassSet = new HashSet<Class<?>>(1);
                    metaClassSet.add(metaClass);
                    List<IJobEntryExternalResourceConsumer> jobEntryConsumers = jobEntryConsumerProvider.getExternalResourceConsumers(metaClassSet);
                    if (jobEntryConsumers != null) {
                        for (IJobEntryExternalResourceConsumer jobEntryConsumer : jobEntryConsumers) {
                            // We might know enough at this point, so call the consumer
                            Collection<IExternalResourceInfo> resources = jobEntryConsumer.getResourcesFromMeta(meta);
                            addExternalResources(resources, meta);
                            // Add a JobEntryListener to collect external resource info after a job entry has finished
                            if (jobExec.job != null && jobEntryConsumer.isDataDriven(meta)) {
                                // Add the consumer as a resource listener, this is done to override the default impl
                                if (jobEntryConsumer instanceof JobEntryExternalResourceListener) {
                                    jobExec.job.addJobEntryListener((JobEntryExternalResourceListener) jobEntryConsumer);
                                } else {
                                    jobExec.job.addJobEntryListener(new JobEntryExternalResourceListener());
                                }
                            }
                        }
                    } else {
                        // Add a JobEntryListener to collect external resource info after a job entry has finished
                        if (jobExec.job != null) {
                            jobExec.job.addJobEntryListener(new JobEntryExternalResourceListener());
                        }
                    }
                }
            }
        }
    }
}
Also used : JobExecutionExtension(org.pentaho.di.job.JobExecutionExtension) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) IJobEntryExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryExternalResourceConsumer) HashSet(java.util.HashSet)

Example 82 with JobEntryCopy

use of org.pentaho.di.job.entry.JobEntryCopy in project pentaho-metaverse by pentaho.

the class JobEntryExternalResourceConsumerListenerTest method testCallJobEntryExtensionPoint.

@Test
public void testCallJobEntryExtensionPoint() throws Exception {
    JobEntryExternalResourceConsumerListener jobEntryExtensionPoint = new JobEntryExternalResourceConsumerListener();
    jobEntryExtensionPoint.setJobEntryExternalResourceConsumerProvider(MetaverseTestUtils.getJobEntryExternalResourceConsumerProvider());
    JobExecutionExtension jobExec = mock(JobExecutionExtension.class);
    JobEntryBase jobEntryBase = mock(JobEntryBase.class, withSettings().extraInterfaces(JobEntryInterface.class));
    JobEntryInterface jobEntryInterface = (JobEntryInterface) jobEntryBase;
    JobEntryCopy jobEntryCopy = mock(JobEntryCopy.class);
    when(jobEntryCopy.getEntry()).thenReturn(jobEntryInterface);
    jobExec.jobEntryCopy = jobEntryCopy;
    jobEntryExtensionPoint.callExtensionPoint(null, jobExec);
    // Adda consumer
    Map<Class<? extends JobEntryBase>, Set<IJobEntryExternalResourceConsumer>> jobEntryConsumerMap = new JobEntryExternalResourceConsumerProvider().getJobEntryConsumerMap();
    Set<IJobEntryExternalResourceConsumer> consumers = new HashSet<IJobEntryExternalResourceConsumer>();
    jobEntryConsumerMap.put(jobEntryBase.getClass(), consumers);
    jobEntryExtensionPoint.callExtensionPoint(null, jobExec);
    IJobEntryExternalResourceConsumer consumer = mock(IJobEntryExternalResourceConsumer.class);
    when(consumer.getResourcesFromMeta(Mockito.any())).thenReturn(Collections.emptyList());
    consumers.add(consumer);
    Job mockJob = mock(Job.class);
    when(jobEntryInterface.getParentJob()).thenReturn(mockJob);
    jobExec.job = mockJob;
    jobEntryExtensionPoint.callExtensionPoint(null, jobExec);
    when(consumer.isDataDriven(Mockito.any())).thenReturn(Boolean.TRUE);
    jobEntryExtensionPoint.callExtensionPoint(null, jobExec);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobExecutionExtension(org.pentaho.di.job.JobExecutionExtension) JobEntryBase(org.pentaho.di.job.entry.JobEntryBase) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryExternalResourceConsumerProvider(org.pentaho.metaverse.analyzer.kettle.jobentry.JobEntryExternalResourceConsumerProvider) IJobEntryExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryExternalResourceConsumer) Job(org.pentaho.di.job.Job) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 83 with JobEntryCopy

use of org.pentaho.di.job.entry.JobEntryCopy in project pentaho-metaverse by pentaho.

the class JobMetaJsonSerializerTest method testSerializeSteps.

@Test
public void testSerializeSteps() throws Exception {
    when(meta.nrJobEntries()).thenReturn(2);
    JobEntryCopy jobEntryCopy = mock(JobEntryCopy.class);
    JobEntryInterface jobEntryInterface = new JobEntrySuccess("name", "description");
    when(meta.getJobEntry(anyInt())).thenReturn(jobEntryCopy);
    when(meta.getName()).thenReturn("JobMeta");
    when(jobEntryCopy.getName()).thenReturn("JobEntry");
    when(jobEntryCopy.getEntry()).thenReturn(jobEntryInterface);
    serializer.serializeSteps(meta, json);
    verify(json, times(2)).writeObject(jobEntryInterface);
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobEntrySuccess(org.pentaho.di.job.entries.success.JobEntrySuccess) Test(org.junit.Test)

Example 84 with JobEntryCopy

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

the class BaseJobServlet method createJob.

protected Job createJob(JobConfiguration jobConfiguration) throws UnknownParamException {
    JobExecutionConfiguration jobExecutionConfiguration = jobConfiguration.getJobExecutionConfiguration();
    JobMeta jobMeta = jobConfiguration.getJobMeta();
    jobMeta.setLogLevel(jobExecutionConfiguration.getLogLevel());
    jobMeta.injectVariables(jobExecutionConfiguration.getVariables());
    // If there was a repository, we know about it at this point in time.
    final Repository repository = jobConfiguration.getJobExecutionConfiguration().getRepository();
    String carteObjectId = UUID.randomUUID().toString();
    SimpleLoggingObject servletLoggingObject = getServletLogging(carteObjectId, jobExecutionConfiguration.getLogLevel());
    // Create the transformation and store in the list...
    final Job job = new Job(repository, jobMeta, servletLoggingObject);
    // Setting variables
    job.initializeVariablesFrom(null);
    job.getJobMeta().setMetaStore(jobMap.getSlaveServerConfig().getMetaStore());
    job.getJobMeta().setInternalKettleVariables(job);
    job.injectVariables(jobConfiguration.getJobExecutionConfiguration().getVariables());
    job.setArguments(jobExecutionConfiguration.getArgumentStrings());
    job.setSocketRepository(getSocketRepository());
    copyJobParameters(job, jobExecutionConfiguration.getParams());
    // Check if there is a starting point specified.
    String startCopyName = jobExecutionConfiguration.getStartCopyName();
    if (startCopyName != null && !startCopyName.isEmpty()) {
        int startCopyNr = jobExecutionConfiguration.getStartCopyNr();
        JobEntryCopy startJobEntryCopy = jobMeta.findJobEntry(startCopyName, startCopyNr, false);
        job.setStartJobEntryCopy(startJobEntryCopy);
    }
    // Note: the plugin (Job and Trans) job entries need to call the delegation listeners in the parent job.
    if (jobExecutionConfiguration.isExpandingRemoteJob()) {
        job.addDelegationListener(new CarteDelegationHandler(getTransformationMap(), getJobMap()));
    }
    // Make sure to disconnect from the repository when the job finishes.
    if (repository != null) {
        job.addJobListener(new JobAdapter() {

            public void jobFinished(Job job) {
                repository.disconnect();
            }
        });
    }
    getJobMap().addJob(job.getJobname(), carteObjectId, job, jobConfiguration);
    final Long passedBatchId = jobExecutionConfiguration.getPassedBatchId();
    if (passedBatchId != null) {
        job.setPassedBatchId(passedBatchId);
    }
    return job;
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) Repository(org.pentaho.di.repository.Repository) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) Job(org.pentaho.di.job.Job) JobExecutionConfiguration(org.pentaho.di.job.JobExecutionConfiguration) JobAdapter(org.pentaho.di.job.JobAdapter)

Example 85 with JobEntryCopy

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

the class GetJobImageServlet method generateJobImage.

private BufferedImage generateJobImage(JobMeta jobMeta) throws Exception {
    float magnification = 1.0f;
    Point maximum = jobMeta.getMaximum();
    maximum.multiply(magnification);
    SwingGC gc = new SwingGC(null, maximum, 32, 0, 0);
    JobPainter jobPainter = new JobPainter(gc, jobMeta, maximum, null, null, null, null, null, new ArrayList<AreaOwner>(), new ArrayList<JobEntryCopy>(), 32, 1, 0, 0, true, "Arial", 10);
    jobPainter.setMagnification(magnification);
    jobPainter.drawJob();
    BufferedImage image = (BufferedImage) gc.getImage();
    return image;
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobPainter(org.pentaho.di.job.JobPainter) AreaOwner(org.pentaho.di.core.gui.AreaOwner) Point(org.pentaho.di.core.gui.Point) SwingGC(org.pentaho.di.core.gui.SwingGC) BufferedImage(java.awt.image.BufferedImage)

Aggregations

JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)149 Point (org.pentaho.di.core.gui.Point)54 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)51 JobMeta (org.pentaho.di.job.JobMeta)47 KettleException (org.pentaho.di.core.exception.KettleException)30 Test (org.junit.Test)28 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)28 NotePadMeta (org.pentaho.di.core.NotePadMeta)24 JobHopMeta (org.pentaho.di.job.JobHopMeta)24 ArrayList (java.util.ArrayList)18 Job (org.pentaho.di.job.Job)18 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)16 JobEntryTrans (org.pentaho.di.job.entries.trans.JobEntryTrans)15 MessageBox (org.eclipse.swt.widgets.MessageBox)13 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)10 Result (org.pentaho.di.core.Result)8 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)8 AreaOwner (org.pentaho.di.core.gui.AreaOwner)8 JobEntrySpecial (org.pentaho.di.job.entries.special.JobEntrySpecial)8 Before (org.junit.Before)7