Search in sources :

Example 31 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class ConnectionExternalResourceStepAnalyzerTest method testCustomAnalyze_input.

@Test
public void testCustomAnalyze_input() throws Exception {
    // fake the super.analyze call
    doReturn(node).when((StepAnalyzer<BaseStepMeta>) analyzer).analyze(descriptor, meta);
    analyzer.setExternalResourceConsumer(erc);
    List<IExternalResourceInfo> resources = new ArrayList<>();
    IExternalResourceInfo resInfo = mock(IExternalResourceInfo.class);
    resources.add(resInfo);
    when(resInfo.isInput()).thenReturn(true);
    when(erc.getResourcesFromMeta(meta, context)).thenReturn(resources);
    IMetaverseNode connectionNode = mock(IMetaverseNode.class);
    doReturn(connectionNode).when(analyzer).getConnectionNode();
    doReturn(resourceNode).when(analyzer).createResourceNode(any(IExternalResourceInfo.class));
    when(erc.getResources(eq(meta), any(IAnalysisContext.class))).thenReturn(resources);
    analyzer.customAnalyze(meta, node);
    verify(builder).addNode(resourceNode);
    verify(builder).addLink(resourceNode, DictionaryConst.LINK_READBY, node);
    verify(builder).addNode(connectionNode);
    verify(builder).addLink(connectionNode, DictionaryConst.LINK_DEPENDENCYOF, node);
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) ArrayList(java.util.ArrayList) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) Test(org.junit.Test)

Example 32 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class ExternalResourceStepAnalyzerTest method testAnalyze_output.

@Test
public void testAnalyze_output() throws Exception {
    // fake the super.analyze call
    doReturn(node).when((StepAnalyzer<BaseStepMeta>) analyzer).analyze(descriptor, meta);
    analyzer.setExternalResourceConsumer(erc);
    List<IExternalResourceInfo> resources = new ArrayList<>();
    IExternalResourceInfo resInfo = mock(IExternalResourceInfo.class);
    resources.add(resInfo);
    when(resInfo.isInput()).thenReturn(false);
    when(resInfo.isOutput()).thenReturn(true);
    when(erc.getResources(eq(meta), any(IAnalysisContext.class))).thenReturn(resources);
    analyzer.customAnalyze(meta, node);
    verify(builder).addNode(resourceNode);
    verify(builder).addLink(node, DictionaryConst.LINK_WRITESTO, resourceNode);
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) ArrayList(java.util.ArrayList) IAnalysisContext(org.pentaho.metaverse.api.IAnalysisContext) Test(org.junit.Test)

Example 33 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class TableOutputExternalResourceConsumer method getResourcesFromMeta.

@Override
public Collection<IExternalResourceInfo> getResourcesFromMeta(TableOutputMeta meta, IAnalysisContext context) {
    Set<IExternalResourceInfo> resources = new HashSet<IExternalResourceInfo>();
    DatabaseMeta dbMeta = meta.getDatabaseMeta();
    if (dbMeta != null) {
        IExternalResourceInfo databaseResource = ExternalResourceInfoFactory.createDatabaseResource(dbMeta, false);
        String tableName = context.equals(DictionaryConst.CONTEXT_RUNTIME) ? meta.getParentStepMeta().getParentTransMeta().environmentSubstitute(meta.getTableName()) : meta.getTableName();
        String schema = context.getContextName().equals(DictionaryConst.CONTEXT_RUNTIME) ? meta.getParentStepMeta().getParentTransMeta().environmentSubstitute(meta.getSchemaName()) : meta.getSchemaName();
        databaseResource.getAttributes().put(DictionaryConst.PROPERTY_TABLE, tableName);
        databaseResource.getAttributes().put(DictionaryConst.PROPERTY_SCHEMA, schema);
        resources.add(databaseResource);
    }
    return resources;
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) HashSet(java.util.HashSet)

Example 34 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class TextFileOutputExternalResourceConsumer method getResourcesFromRow.

@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(TextFileOutput textFileOutput, RowMetaInterface rowMeta, Object[] row) {
    Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
    // For some reason the step doesn't return the StepMetaInterface directly, so go around it
    TextFileOutputMeta meta = (TextFileOutputMeta) textFileOutput.getStepMeta().getStepMetaInterface();
    try {
        TextFileOutputData data = ((TextFileOutputData) textFileOutput.getStepDataInterface());
        String filename = rowMeta.getString(row, meta.getFileNameField(), meta.getFileName());
        if (null != data) {
            // For some reason, the first call to process row doesn't have the data.fileName filled in, so
            // fall back to the filename field value, and then to the meta's filename
            filename = textFileOutput.buildFilename(Const.isEmpty(data.fileName) ? filename : data.fileName, true);
        }
        if (!Const.isEmpty(filename)) {
            FileObject fileObject = KettleVFS.getFileObject(filename);
            resources.add(ExternalResourceInfoFactory.createFileResource(fileObject, false));
        }
    } catch (KettleException kve) {
    // TODO throw exception or ignore?
    }
    return resources;
}
Also used : TextFileOutputMeta(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta) KettleException(org.pentaho.di.core.exception.KettleException) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) FileObject(org.apache.commons.vfs2.FileObject) LinkedList(java.util.LinkedList) TextFileOutputData(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputData)

Example 35 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo 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)

Aggregations

IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)64 Test (org.junit.Test)38 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)16 StepMeta (org.pentaho.di.trans.step.StepMeta)16 LinkedList (java.util.LinkedList)12 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)12 HashSet (java.util.HashSet)10 KettleException (org.pentaho.di.core.exception.KettleException)10 ArrayList (java.util.ArrayList)8 VariableSpace (org.pentaho.di.core.variables.VariableSpace)8 FileObject (org.apache.commons.vfs2.FileObject)7 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)5 List (java.util.List)4 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)4 IStepExternalResourceConsumer (org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer)3 WebServiceResourceInfo (org.pentaho.metaverse.api.model.WebServiceResourceInfo)3 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2