Search in sources :

Example 31 with ResourceEntry

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);
}
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 32 with ResourceEntry

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();
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) ResourceEntry(org.pentaho.di.resource.ResourceEntry) ArrayList(java.util.ArrayList) ResourceReference(org.pentaho.di.resource.ResourceReference) Job(org.pentaho.di.job.Job) Test(org.junit.Test)

Example 33 with ResourceEntry

use of org.pentaho.di.resource.ResourceEntry in project pentaho-metaverse by pentaho.

the class AbstractJobEntryJsonSerializer method writeExternalResources.

protected void writeExternalResources(T meta, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
    json.writeArrayFieldStart(JSON_PROPERTY_EXTERNAL_RESOURCES);
    JobMeta jobMeta = new JobMeta();
    if (meta.getParentJob() != null && meta.getParentJob().getJobMeta() != null) {
        jobMeta = meta.getParentJob().getJobMeta();
    }
    List<ResourceReference> dependencies = meta.getResourceDependencies(jobMeta);
    for (ResourceReference dependency : dependencies) {
        for (ResourceEntry resourceEntry : dependency.getEntries()) {
            IExternalResourceInfo resourceInfo = ExternalResourceInfoFactory.createResource(resourceEntry);
            json.writeObject(resourceInfo);
        }
    }
    json.writeEndArray();
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) ResourceEntry(org.pentaho.di.resource.ResourceEntry) ResourceReference(org.pentaho.di.resource.ResourceReference)

Example 34 with ResourceEntry

use of org.pentaho.di.resource.ResourceEntry in project pentaho-metaverse by pentaho.

the class ExternalResourceInfoFactoryTest method testCreateResource.

@Test
public void testCreateResource() throws Exception {
    ResourceEntry resourceEntry = mock(ResourceEntry.class);
    when(resourceEntry.getResource()).thenReturn("myResource");
    when(resourceEntry.getResourcetype()).thenReturn(ResourceEntry.ResourceType.ACTIONFILE);
    IExternalResourceInfo resourceInfo = ExternalResourceInfoFactory.createResource(resourceEntry);
    assertEquals(DictionaryConst.NODE_TYPE_FILE, resourceInfo.getType());
    when(resourceEntry.getResourcetype()).thenReturn(ResourceEntry.ResourceType.FILE);
    resourceInfo = ExternalResourceInfoFactory.createResource(resourceEntry, true);
    assertEquals(DictionaryConst.NODE_TYPE_FILE, resourceInfo.getType());
    when(resourceEntry.getResourcetype()).thenReturn(ResourceEntry.ResourceType.URL);
    resourceInfo = ExternalResourceInfoFactory.createResource(resourceEntry);
    assertEquals(DictionaryConst.NODE_TYPE_WEBSERVICE, resourceInfo.getType());
    when(resourceEntry.getResourcetype()).thenReturn(ResourceEntry.ResourceType.CONNECTION);
    resourceInfo = ExternalResourceInfoFactory.createResource(resourceEntry, false);
    assertEquals(DictionaryConst.NODE_TYPE_DATASOURCE, resourceInfo.getType());
    when(resourceEntry.getResourcetype()).thenReturn(ResourceEntry.ResourceType.DATABASENAME);
    resourceInfo = ExternalResourceInfoFactory.createResource(resourceEntry);
    assertEquals(DictionaryConst.NODE_TYPE_DATASOURCE, resourceInfo.getType());
    when(resourceEntry.getResourcetype()).thenReturn(ResourceEntry.ResourceType.SERVER);
    resourceInfo = ExternalResourceInfoFactory.createResource(resourceEntry);
    assertEquals("SERVER", resourceInfo.getType());
    when(resourceEntry.getResourcetype()).thenReturn(ResourceEntry.ResourceType.OTHER);
    resourceInfo = ExternalResourceInfoFactory.createResource(resourceEntry);
    assertEquals("OTHER", resourceInfo.getType());
}
Also used : ResourceEntry(org.pentaho.di.resource.ResourceEntry) Test(org.junit.Test)

Example 35 with ResourceEntry

use of org.pentaho.di.resource.ResourceEntry in project pentaho-kettle by pentaho.

the class BaseFileInputFiles method getResourceDependencies.

public List<ResourceReference> getResourceDependencies(TransMeta transMeta, StepMeta stepInfo) {
    List<ResourceReference> references = new ArrayList<ResourceReference>(5);
    ResourceReference reference = new ResourceReference(stepInfo);
    references.add(reference);
    String[] textFiles = FileInputList.createFilePathList(transMeta, fileName, fileMask, excludeFileMask, fileRequired, includeSubFolderBoolean());
    if (textFiles != null) {
        for (int i = 0; i < textFiles.length; i++) {
            reference.getEntries().add(new ResourceEntry(textFiles[i], ResourceType.FILE));
        }
    }
    return references;
}
Also used : ResourceEntry(org.pentaho.di.resource.ResourceEntry) ArrayList(java.util.ArrayList) ResourceReference(org.pentaho.di.resource.ResourceReference)

Aggregations

ResourceEntry (org.pentaho.di.resource.ResourceEntry)63 ResourceReference (org.pentaho.di.resource.ResourceReference)61 ArrayList (java.util.ArrayList)17 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 JobMeta (org.pentaho.di.job.JobMeta)4 Test (org.junit.Test)3 ResultFile (org.pentaho.di.core.ResultFile)2 Job (org.pentaho.di.job.Job)2 IExecutionData (org.pentaho.metaverse.api.model.IExecutionData)2 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)2 Throwables (com.google.common.base.Throwables)1 File (java.io.File)1 Serializable (java.io.Serializable)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1