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);
}
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());
}
}
}
}
}
}
}
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);
}
Aggregations