use of org.pentaho.di.resource.ResourceEntry in project pentaho-metaverse by pentaho.
the class JobEntryExternalResourceListener method afterExecution.
@Override
public void afterExecution(Job job, JobEntryCopy jobEntryCopy, JobEntryInterface jobEntryInterface, Result result) {
IExecutionProfile executionProfile = JobLineageHolderMap.getInstance().getLineageHolder(job).getExecutionProfile();
IExecutionData executionData = executionProfile.getExecutionData();
// Get input files (aka Resource Dependencies)
JobMeta jobMeta = job.getJobMeta();
if (jobMeta != null) {
List<ResourceReference> dependencies = jobEntryInterface.getResourceDependencies(jobMeta);
if (dependencies != null) {
for (ResourceReference ref : dependencies) {
List<ResourceEntry> resourceEntries = ref.getEntries();
if (resourceEntries != null) {
for (ResourceEntry entry : resourceEntries) {
executionData.addExternalResource(jobEntryInterface.getName(), ExternalResourceInfoFactory.createResource(entry, true));
}
}
}
}
}
// Get output files (aka result files)
if (result != null) {
List<ResultFile> resultFiles = result.getResultFilesList();
if (resultFiles != null) {
for (ResultFile resultFile : resultFiles) {
executionData.addExternalResource(jobEntryInterface.getName(), ExternalResourceInfoFactory.createFileResource(resultFile.getFile(), false));
}
}
}
}
use of org.pentaho.di.resource.ResourceEntry 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.di.resource.ResourceEntry in project pentaho-metaverse by pentaho.
the class JobEntryBaseJsonSerializerTest method testWriteExternalResources.
@Test
public void testWriteExternalResources() throws Exception {
Job parentJob = mock(Job.class);
JobMeta jobMeta = mock(JobMeta.class);
List<ResourceReference> dependencies = new ArrayList<ResourceReference>();
ResourceReference resRef = mock(ResourceReference.class);
dependencies.add(resRef);
List<ResourceEntry> resources = new ArrayList<ResourceEntry>();
ResourceEntry resEntry = mock(ResourceEntry.class);
resources.add(resEntry);
when(resRef.getEntries()).thenReturn(resources);
when(resEntry.getResource()).thenReturn("path/to/my/resource");
when(resEntry.getResourcetype()).thenReturn(ResourceEntry.ResourceType.FILE);
when(meta.getParentJob()).thenReturn(parentJob);
when(parentJob.getJobMeta()).thenReturn(jobMeta);
when(meta.getResourceDependencies(jobMeta)).thenReturn(dependencies);
serializer.writeExternalResources(meta, json, provider);
verify(json).writeArrayFieldStart(JobEntryBaseJsonSerializer.JSON_PROPERTY_EXTERNAL_RESOURCES);
verify(json).writeObject(any(IExternalResourceInfo.class));
verify(json).writeEndArray();
}
use of org.pentaho.di.resource.ResourceEntry in project pentaho-kettle by pentaho.
the class GetFileNamesMeta method getResourceDependencies.
@Override
public List<ResourceReference> getResourceDependencies(TransMeta transMeta, StepMeta stepInfo) {
List<ResourceReference> references = new ArrayList<ResourceReference>(5);
ResourceReference reference = new ResourceReference(stepInfo);
references.add(reference);
String[] files = getFilePaths(transMeta);
if (files != null) {
for (int i = 0; i < files.length; i++) {
reference.getEntries().add(new ResourceEntry(files[i], ResourceType.FILE));
}
}
return references;
}
use of org.pentaho.di.resource.ResourceEntry in project pentaho-kettle by pentaho.
the class BaseStreamStepMeta method getResourceDependencies.
@Override
public List<ResourceReference> getResourceDependencies(TransMeta transMeta, StepMeta stepInfo) {
List<ResourceReference> references = new ArrayList<>(5);
String realFilename = transMeta.environmentSubstitute(transformationPath);
ResourceReference reference = new ResourceReference(stepInfo);
references.add(reference);
if (!Utils.isEmpty(realFilename)) {
// Add the filename to the references, including a reference to this step
// meta data.
//
reference.getEntries().add(new ResourceEntry(realFilename, ResourceEntry.ResourceType.ACTIONFILE));
}
return references;
}
Aggregations