Search in sources :

Example 1 with JobExecutionExtension

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

the class RunConfigurationInjectExtensionPointTest method setup.

@Before
public void setup() {
    runConfigurationInjectExtensionPoint = new RunConfigurationInjectExtensionPoint(runConfigurationManager);
    executionExt = new JobExecutionExtension(job, result, jobEntryCopy, false);
    when(abstractMeta.getEmbeddedMetaStore()).thenReturn(embeddedMetaStore);
    when(transExecutionConfiguration.getRunConfiguration()).thenReturn(runConfName);
    when(runConfigurationManager.load(runConfName)).thenReturn(runConfiguration);
    when(job.getJobMeta()).thenReturn(jobMeta);
    when(jobMeta.getEmbeddedMetaStore()).thenReturn(embeddedMetaStore);
    when(jobMeta.environmentSubstitute(anyString())).thenReturn(runConfName);
    when(jobEntryJobs.getRunConfiguration()).thenReturn(runConfName);
    when(jobEntryTrans.getRunConfiguration()).thenReturn(runConfName);
    trans.put(jobEntryCopy, jobEntryTrans);
    jobs.put(jobEntryCopy, jobEntryJobs);
    when(job.getActiveJobEntryTransformations()).thenReturn(trans);
    when(job.getActiveJobEntryJobs()).thenReturn(jobs);
}
Also used : JobExecutionExtension(org.pentaho.di.job.JobExecutionExtension) Before(org.junit.Before)

Example 2 with JobExecutionExtension

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

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

use of org.pentaho.di.job.JobExecutionExtension 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)

Aggregations

JobExecutionExtension (org.pentaho.di.job.JobExecutionExtension)4 HashSet (java.util.HashSet)2 Job (org.pentaho.di.job.Job)2 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)2 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)2 IJobEntryExternalResourceConsumer (org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryExternalResourceConsumer)2 Set (java.util.Set)1 Before (org.junit.Before)1 Test (org.junit.Test)1 EmbeddedMetaStore (org.pentaho.di.core.attributes.metastore.EmbeddedMetaStore)1 RunConfiguration (org.pentaho.di.engine.configuration.api.RunConfiguration)1 EmbeddedRunConfigurationManager (org.pentaho.di.engine.configuration.impl.EmbeddedRunConfigurationManager)1 RunConfigurationManager (org.pentaho.di.engine.configuration.impl.RunConfigurationManager)1 JobMeta (org.pentaho.di.job.JobMeta)1 JobEntryJob (org.pentaho.di.job.entries.job.JobEntryJob)1 JobEntryTrans (org.pentaho.di.job.entries.trans.JobEntryTrans)1 JobEntryBase (org.pentaho.di.job.entry.JobEntryBase)1 JobEntryExternalResourceConsumerProvider (org.pentaho.metaverse.analyzer.kettle.jobentry.JobEntryExternalResourceConsumerProvider)1 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)1