Search in sources :

Example 21 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class JobEntryAnalyzer method addConnectionNodes.

/**
 * Adds any used database connections to the metaverse using the appropriate analyzer
 *
 * @throws MetaverseAnalyzerException
 */
protected void addConnectionNodes(IComponentDescriptor descriptor) throws MetaverseAnalyzerException {
    if (jobEntryInterface == null) {
        throw new MetaverseAnalyzerException(Messages.getString("ERROR.JobEntryInterface.IsNull"));
    }
    if (connectionAnalyzer != null) {
        List<? extends Object> connections = connectionAnalyzer.getUsedConnections(jobEntryInterface);
        for (Object connection : connections) {
            String connName = null;
            // see if the connection object has a getName method
            try {
                Method getNameMethod = connection.getClass().getMethod("getName", null);
                connName = (String) getNameMethod.invoke(connection, null);
            } catch (Exception e) {
            // doesn't have a getName method, will try to get it from the descriptor later
            }
            try {
                IComponentDescriptor connDescriptor = connectionAnalyzer.buildComponentDescriptor(descriptor, connection);
                connName = connName == null ? descriptor.getName() : connName;
                IMetaverseNode connNode = connectionAnalyzer.analyze(connDescriptor, connection);
                metaverseBuilder.addLink(connNode, DictionaryConst.LINK_DEPENDENCYOF, rootNode);
            } catch (Throwable t) {
                // Don't throw the exception if a DB connection couldn't be analyzed, just log it and move on
                LOGGER.warn(Messages.getString("WARNING.AnalyzingDatabaseConnection", connName), t);
            }
        }
    }
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Method(java.lang.reflect.Method) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException)

Example 22 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class BaseKettleMetaverseComponentTest method testCreateFileNode.

@Test
public void testCreateFileNode() throws Exception {
    component.createFileNode(null, null);
    assertNull(component.createFileNode("/path/to/my/file", null));
    IMetaverseBuilder metaverseBuilder = mock(IMetaverseBuilder.class);
    when(metaverseBuilder.getMetaverseObjectFactory()).thenReturn(new MetaverseObjectFactory());
    component.setMetaverseBuilder(metaverseBuilder);
    IComponentDescriptor descriptor = mock(IComponentDescriptor.class);
    INamespace ns = mock(INamespace.class);
    when(descriptor.getNamespace()).thenReturn(ns);
    assertNotNull(component.createFileNode("/path/to/my/file", descriptor));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) INamespace(org.pentaho.metaverse.api.INamespace) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) Test(org.junit.Test)

Example 23 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testCreateFieldNode_virtual.

@Test
public void testCreateFieldNode_virtual() throws Exception {
    IComponentDescriptor fieldDescriptor = mock(IComponentDescriptor.class);
    ValueMetaInterface fieldMeta = new ValueMeta("address");
    MetaverseTransientNode node = new MetaverseTransientNode("hello");
    doReturn(node).when(analyzer).createNodeFromDescriptor(fieldDescriptor);
    IMetaverseNode fieldNode = analyzer.createFieldNode(fieldDescriptor, fieldMeta, "nextStep", false);
    assertNotNull(fieldNode);
    assertNotNull(fieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
    assertEquals("nextStep", fieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
    // make sure it did not added to the graph
    verify(builder, never()).addNode(node);
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 24 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class StepAnalyzerTest method testCreateFieldNode_NoTargetStep.

@Test
public void testCreateFieldNode_NoTargetStep() throws Exception {
    IComponentDescriptor fieldDescriptor = mock(IComponentDescriptor.class);
    ValueMetaInterface fieldMeta = new ValueMeta("address");
    MetaverseTransientNode node = new MetaverseTransientNode("hello");
    doReturn(node).when(analyzer).createNodeFromDescriptor(fieldDescriptor);
    IMetaverseNode fieldNode = analyzer.createFieldNode(fieldDescriptor, fieldMeta, null, true);
    assertNotNull(fieldNode);
    assertNotNull(fieldNode.getProperty(DictionaryConst.PROPERTY_KETTLE_TYPE));
    assertNull(fieldNode.getProperty(DictionaryConst.PROPERTY_TARGET_STEP));
    // make sure it did not added to the graph
    verify(builder, never()).addNode(node);
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) ValueMeta(org.pentaho.di.core.row.ValueMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 25 with IComponentDescriptor

use of org.pentaho.metaverse.api.IComponentDescriptor in project pentaho-metaverse by pentaho.

the class JobAnalyzer method analyze.

@Override
public synchronized IMetaverseNode analyze(IComponentDescriptor descriptor, IDocument document) throws MetaverseAnalyzerException {
    validateState(document);
    Object repoObject = document.getContent();
    JobMeta jobMeta = null;
    if (repoObject instanceof String) {
        // hydrate the job
        try {
            String content = (String) repoObject;
            ByteArrayInputStream xmlStream = new ByteArrayInputStream(content.getBytes());
            jobMeta = new JobMeta(xmlStream, null, null);
        } catch (KettleXMLException e) {
            throw new MetaverseAnalyzerException(e);
        }
    } else if (repoObject instanceof JobMeta) {
        jobMeta = (JobMeta) repoObject;
    }
    // construct a dummy job based on our JobMeta so we get out VariableSpace set properly
    jobMeta.setFilename(document.getStringID());
    IComponentDescriptor documentDescriptor = new MetaverseComponentDescriptor(document.getStringID(), DictionaryConst.NODE_TYPE_JOB, new Namespace(descriptor.getLogicalId()), descriptor.getContext());
    // Create a metaverse node and start filling in details
    IMetaverseNode jobNode = metaverseObjectFactory.createNodeObject(document.getNamespace(), jobMeta.getName(), DictionaryConst.NODE_TYPE_JOB);
    jobNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DOCUMENT);
    return analyze(documentDescriptor, jobMeta, jobNode, (String) document.getProperty(DictionaryConst.PROPERTY_PATH));
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) ByteArrayInputStream(java.io.ByteArrayInputStream) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Aggregations

IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)27 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)22 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)16 Test (org.junit.Test)10 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)9 INamespace (org.pentaho.metaverse.api.INamespace)8 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)6 KettleStepException (org.pentaho.di.core.exception.KettleStepException)5 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)5 JobMeta (org.pentaho.di.job.JobMeta)5 StepMeta (org.pentaho.di.trans.step.StepMeta)5 Namespace (org.pentaho.metaverse.api.Namespace)5 KettleException (org.pentaho.di.core.exception.KettleException)4 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 TransMeta (org.pentaho.di.trans.TransMeta)4 IDocument (org.pentaho.metaverse.api.IDocument)4 FileNotFoundException (java.io.FileNotFoundException)3 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)3 ValueMeta (org.pentaho.di.core.row.ValueMeta)3