Search in sources :

Example 1 with IJobEntryExternalResourceConsumer

use of org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryExternalResourceConsumer in project pentaho-metaverse by pentaho.

the class JobEntryExternalResourceListenerTest method testBeforeAfterExecution.

@Test
public void testBeforeAfterExecution() throws Exception {
    IJobEntryExternalResourceConsumer consumer = mock(IJobEntryExternalResourceConsumer.class);
    JobMeta mockJobMeta = mock(JobMeta.class);
    Job job = mock(Job.class);
    when(job.getJobMeta()).thenReturn(mockJobMeta);
    JobEntryInterface jobEntryInterface = mock(JobEntryInterface.class);
    when(jobEntryInterface.getParentJob()).thenReturn(job);
    when(jobEntryInterface.getResourceDependencies(mockJobMeta)).thenReturn(Collections.singletonList(new ResourceReference(null, Collections.singletonList(new ResourceEntry("myFile", ResourceEntry.ResourceType.FILE)))));
    JobEntryCopy jobEntryCopy = mock(JobEntryCopy.class);
    IExecutionProfile executionProfile = mock(IExecutionProfile.class);
    IExecutionData executionData = mock(IExecutionData.class);
    when(executionProfile.getExecutionData()).thenReturn(executionData);
    JobLineageHolderMap.getInstance().getLineageHolder(job).setExecutionProfile(executionProfile);
    JobEntryExternalResourceListener listener = new JobEntryExternalResourceListener(consumer);
    FileObject mockFile = mock(FileObject.class);
    FileName mockFilename = mock(FileName.class);
    when(mockFilename.getPath()).thenReturn("/path/to/file");
    when(mockFile.getName()).thenReturn(mockFilename);
    ResultFile resultFile = mock(ResultFile.class);
    when(resultFile.getFile()).thenReturn(mockFile);
    List<ResultFile> resultFiles = Collections.singletonList(resultFile);
    Result result = mock(Result.class);
    when(result.getResultFilesList()).thenReturn(resultFiles);
    // Call beforeExecution for coverage
    listener.beforeExecution(null, null, null);
    listener.afterExecution(job, jobEntryCopy, jobEntryInterface, result);
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) FileName(org.apache.commons.vfs2.FileName) ResultFile(org.pentaho.di.core.ResultFile) Result(org.pentaho.di.core.Result) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) IExecutionData(org.pentaho.metaverse.api.model.IExecutionData) ResourceEntry(org.pentaho.di.resource.ResourceEntry) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) ResourceReference(org.pentaho.di.resource.ResourceReference) FileObject(org.apache.commons.vfs2.FileObject) IJobEntryExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryExternalResourceConsumer) Job(org.pentaho.di.job.Job) Test(org.junit.Test)

Example 2 with IJobEntryExternalResourceConsumer

use of org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryExternalResourceConsumer 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 IJobEntryExternalResourceConsumer

use of org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryExternalResourceConsumer 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)

Aggregations

JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)3 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)3 IJobEntryExternalResourceConsumer (org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryExternalResourceConsumer)3 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 Job (org.pentaho.di.job.Job)2 JobExecutionExtension (org.pentaho.di.job.JobExecutionExtension)2 Set (java.util.Set)1 FileName (org.apache.commons.vfs2.FileName)1 FileObject (org.apache.commons.vfs2.FileObject)1 Result (org.pentaho.di.core.Result)1 ResultFile (org.pentaho.di.core.ResultFile)1 JobMeta (org.pentaho.di.job.JobMeta)1 JobEntryBase (org.pentaho.di.job.entry.JobEntryBase)1 ResourceEntry (org.pentaho.di.resource.ResourceEntry)1 ResourceReference (org.pentaho.di.resource.ResourceReference)1 JobEntryExternalResourceConsumerProvider (org.pentaho.metaverse.analyzer.kettle.jobentry.JobEntryExternalResourceConsumerProvider)1 IExecutionData (org.pentaho.metaverse.api.model.IExecutionData)1 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)1 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)1