Search in sources :

Example 6 with IMetaverseLink

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

the class MetaverseBuilderTest method testDeleteLink_emptyLink.

@Test
public void testDeleteLink_emptyLink() {
    IMetaverseLink link = builder.createLinkObject();
    // now lets try to delete the link, no errors should happen
    builder.deleteLink(link);
}
Also used : IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) Test(org.junit.Test)

Example 7 with IMetaverseLink

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

the class TransformationAnalyzer method analyze.

@Override
public synchronized IMetaverseNode analyze(IComponentDescriptor descriptor, IDocument document) throws MetaverseAnalyzerException {
    validateState(document);
    Object repoObject = document.getContent();
    TransMeta transMeta = null;
    if (repoObject instanceof String) {
        // hydrate the transformation
        try {
            String content = (String) repoObject;
            ByteArrayInputStream xmlStream = new ByteArrayInputStream(content.getBytes());
            transMeta = new TransMeta(xmlStream, null, false, null, null);
            transMeta.setFilename(document.getStringID());
            if (transMeta.hasMissingPlugins()) {
                throw new MetaverseAnalyzerException(Messages.getErrorString("ERROR.MissingPlugin"));
            }
        } catch (KettleException e) {
            throw new MetaverseAnalyzerException(e);
        }
    } else if (repoObject instanceof TransMeta) {
        transMeta = (TransMeta) repoObject;
    }
    Trans t = new Trans(transMeta);
    t.setInternalKettleVariables(transMeta);
    IComponentDescriptor documentDescriptor = new MetaverseComponentDescriptor(document.getStringID(), DictionaryConst.NODE_TYPE_TRANS, new Namespace(descriptor.getLogicalId()), descriptor.getContext());
    // Create a metaverse node and start filling in details
    IMetaverseNode node = metaverseObjectFactory.createNodeObject(document.getNamespace(), transMeta.getName(), DictionaryConst.NODE_TYPE_TRANS);
    node.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DOCUMENT);
    // pull out the standard fields
    String description = transMeta.getDescription();
    if (description != null) {
        node.setProperty(DictionaryConst.PROPERTY_DESCRIPTION, description);
    }
    String extendedDescription = transMeta.getExtendedDescription();
    if (extendedDescription != null) {
        node.setProperty("extendedDescription", extendedDescription);
    }
    Date createdDate = transMeta.getCreatedDate();
    if (createdDate != null) {
        node.setProperty(DictionaryConst.PROPERTY_CREATED, Long.toString(createdDate.getTime()));
    }
    String createdUser = transMeta.getCreatedUser();
    if (createdUser != null) {
        node.setProperty(DictionaryConst.PROPERTY_CREATED_BY, createdUser);
    }
    Date lastModifiedDate = transMeta.getModifiedDate();
    if (lastModifiedDate != null) {
        node.setProperty(DictionaryConst.PROPERTY_LAST_MODIFIED, Long.toString(lastModifiedDate.getTime()));
    }
    String lastModifiedUser = transMeta.getModifiedUser();
    if (lastModifiedUser != null) {
        node.setProperty(DictionaryConst.PROPERTY_LAST_MODIFIED_BY, lastModifiedUser);
    }
    String version = transMeta.getTransversion();
    if (version != null) {
        node.setProperty(DictionaryConst.PROPERTY_ARTIFACT_VERSION, version);
    }
    String status = Messages.getString("INFO.JobOrTrans.Status_" + Integer.toString(transMeta.getTransstatus()));
    if (status != null && !status.startsWith("!")) {
        node.setProperty(DictionaryConst.PROPERTY_STATUS, status);
    }
    node.setProperty(DictionaryConst.PROPERTY_PATH, document.getProperty(DictionaryConst.PROPERTY_PATH));
    String[] parameters = transMeta.listParameters();
    if (parameters != null) {
        for (String parameter : parameters) {
            try {
                // Determine parameter properties and add them to a map, then the map to the list
                String defaultParameterValue = transMeta.getParameterDefault(parameter);
                String parameterValue = transMeta.getParameterValue(parameter);
                String parameterDescription = transMeta.getParameterDescription(parameter);
                PropertiesHolder paramProperties = new PropertiesHolder();
                paramProperties.setProperty("defaultValue", defaultParameterValue);
                paramProperties.setProperty("value", parameterValue);
                paramProperties.setProperty("description", parameterDescription);
                node.setProperty("parameter_" + parameter, paramProperties.toString());
            } catch (UnknownParamException upe) {
                // This shouldn't happen as we're using the list provided by the meta
                throw new MetaverseAnalyzerException(upe);
            }
        }
    }
    // handle the step
    for (int stepNr = 0; stepNr < transMeta.nrSteps(); stepNr++) {
        StepMeta stepMeta = transMeta.getStep(stepNr);
        try {
            if (stepMeta != null) {
                if (stepMeta.getParentTransMeta() == null) {
                    stepMeta.setParentTransMeta(transMeta);
                }
                IMetaverseNode stepNode = null;
                IComponentDescriptor stepDescriptor = new MetaverseComponentDescriptor(stepMeta.getName(), DictionaryConst.NODE_TYPE_TRANS_STEP, node, documentDescriptor.getContext());
                Set<IStepAnalyzer> stepAnalyzers = getStepAnalyzers(stepMeta);
                if (stepAnalyzers != null && !stepAnalyzers.isEmpty()) {
                    for (IStepAnalyzer stepAnalyzer : stepAnalyzers) {
                        stepAnalyzer.setMetaverseBuilder(metaverseBuilder);
                        stepNode = (IMetaverseNode) stepAnalyzer.analyze(stepDescriptor, getBaseStepMetaFromStepMeta(stepMeta));
                    }
                } else {
                    GenericStepMetaAnalyzer defaultStepAnalyzer = new GenericStepMetaAnalyzer();
                    defaultStepAnalyzer.setMetaverseBuilder(metaverseBuilder);
                    stepNode = defaultStepAnalyzer.analyze(stepDescriptor, getBaseStepMetaFromStepMeta(stepMeta));
                }
                if (stepNode != null) {
                    metaverseBuilder.addLink(node, DictionaryConst.LINK_CONTAINS, stepNode);
                }
            }
        } catch (Throwable mae) {
            // Don't throw an exception, just log and carry on
            log.warn(Messages.getString("ERROR.ErrorDuringAnalysis", stepMeta.getName(), Const.NVL(mae.getLocalizedMessage(), "Unspecified")));
            log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), mae);
        }
    }
    // Model the hops between steps
    int numHops = transMeta.nrTransHops();
    for (int i = 0; i < numHops; i++) {
        TransHopMeta hop = transMeta.getTransHop(i);
        StepMeta fromStep = hop.getFromStep();
        StepMeta toStep = hop.getToStep();
        INamespace childNs = new Namespace(node.getLogicalId());
        // process legitimate hops
        if (fromStep != null && toStep != null) {
            IMetaverseNode fromStepNode = metaverseObjectFactory.createNodeObject(childNs, fromStep.getName(), DictionaryConst.NODE_TYPE_TRANS_STEP);
            IMetaverseNode toStepNode = metaverseObjectFactory.createNodeObject(childNs, toStep.getName(), DictionaryConst.NODE_TYPE_TRANS_STEP);
            // Create and decorate the link between the steps
            IMetaverseLink link = metaverseObjectFactory.createLinkObject();
            link.setFromNode(fromStepNode);
            link.setLabel(DictionaryConst.LINK_HOPSTO);
            link.setToNode(toStepNode);
            // Is this hop enabled?
            link.setProperty(DictionaryConst.PROPERTY_ENABLED, hop.isEnabled());
            // Add metadata about the type of stream (target, error, info) it is. Default to "target".
            String linkType = "target";
            if (fromStep.isSendingErrorRowsToStep(toStep)) {
                linkType = "error";
            } else {
                String[] infoStepnames = toStep.getStepMetaInterface().getStepIOMeta().getInfoStepnames();
                // If the "from" step is the source of an info stream to the "to" step, it's an "info" hop
                if (Const.indexOfString(fromStep.getName(), infoStepnames) >= 0) {
                    linkType = "info";
                }
            }
            link.setProperty(DictionaryConst.PROPERTY_TYPE, linkType);
            metaverseBuilder.addLink(link);
        }
    }
    metaverseBuilder.addNode(node);
    addParentLink(documentDescriptor, node);
    return node;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PropertiesHolder(org.pentaho.metaverse.api.PropertiesHolder) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) TransMeta(org.pentaho.di.trans.TransMeta) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) Date(java.util.Date) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor) IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) INamespace(org.pentaho.metaverse.api.INamespace) ByteArrayInputStream(java.io.ByteArrayInputStream) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans) GenericStepMetaAnalyzer(org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer)

Example 8 with IMetaverseLink

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

the class BlueprintsGraphMetaverseReaderTest method testFindLink.

@Test
public void testFindLink() throws Exception {
    BlueprintsGraphMetaverseReader metaverseReader = new BlueprintsGraphMetaverseReader(graph);
    IMetaverseLink link = metaverseReader.findLink("datasource1.table1.field1", "populates", "trans2.ktr;field1", Direction.OUT);
    assertNotNull("Link is null", link);
    assertEquals("Label is wrong", "populates", link.getLabel());
    assertEquals("Id is wrong", "datasource1.table1.field1", link.getFromNode().getStringID());
    assertEquals("Id is wrong", "trans2.ktr;field1", link.getToNode().getStringID());
    link = metaverseReader.findLink("bogus", "populates", "trans2.ktr;field1", Direction.OUT);
    assertNull("Link is not null", link);
    link = metaverseReader.findLink("datasource1.table1.field1", "bogus", "trans2.ktr;field1", Direction.OUT);
    assertNull("Link is not null", link);
    link = metaverseReader.findLink("datasource1.table1.field1", "populates", "bogus", Direction.OUT);
    assertNull("Link is not null", link);
    link = metaverseReader.findLink("datasource1.table1.field1", "populates", "trans2.ktr;field1", Direction.IN);
    assertNull("Link is not null", link);
    link = metaverseReader.findLink("job2.kjb", "populates", "trans2.ktr;field1", Direction.OUT);
    assertNull("Link is not null", link);
    link = metaverseReader.findLink("trans2.ktr;field1", "populates", "datasource1.table1.field1", Direction.IN);
    assertNotNull("Link is null", link);
    assertEquals("Label is wrong", "populates", link.getLabel());
    assertEquals("Id is wrong", "datasource1.table1.field1", link.getFromNode().getStringID());
    assertEquals("Type is wrong", "trans2.ktr;field1", link.getToNode().getStringID());
    assertEquals("Localized type", "Populates", link.getProperty(DictionaryConst.PROPERTY_TYPE_LOCALIZED));
}
Also used : IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) Test(org.junit.Test)

Example 9 with IMetaverseLink

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

the class MetaverseBuilderTest method createAndTestLink.

private IMetaverseLink createAndTestLink() {
    builder.addNode(node);
    IMetaverseNode node2 = builder.createNodeObject("nodeToId");
    node2.setName("to name");
    IMetaverseLink link = builder.createLinkObject();
    link.setFromNode(node);
    link.setLabel("uses");
    link.setToNode(node2);
    builder.addLink(link);
    Vertex fromResult = graph.getVertex(node.getStringID());
    Vertex toResult = graph.getVertex(node2.getStringID());
    // we added this node explicitly through addNode, it should NOT be flagged as virtual
    assertFalse((Boolean) fromResult.getProperty(DictionaryConst.NODE_VIRTUAL));
    // we added this node implicitly through the addLink, it should be flagged as virtual
    assertTrue((Boolean) toResult.getProperty(DictionaryConst.NODE_VIRTUAL));
    // verify the link is there
    assertNotNull(fromResult.getEdges(Direction.OUT, "uses"));
    assertNotNull(toResult.getEdges(Direction.IN, "uses"));
    return link;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink)

Example 10 with IMetaverseLink

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

the class MetaverseBuilderTest method testDeleteLink_fromNodeHasMutipleLinks.

@Test
public void testDeleteLink_fromNodeHasMutipleLinks() {
    IMetaverseLink link = createAndTestLink();
    // add another link using the same test node
    IMetaverseNode node3 = builder.createNodeObject("another");
    node3.setName("to another");
    // add another link
    builder.addLink(node, "uses", node3);
    Vertex beforeDeleteFrom = graph.getVertex(link.getFromNode().getStringID());
    int count = 0;
    for (Edge edge : beforeDeleteFrom.getEdges(Direction.OUT, "uses")) {
        count++;
        System.out.println(edge.toString());
    }
    // we should have 2 edges for this node before we delete one
    assertEquals(2, count);
    // now lets try to delete the link
    builder.deleteLink(link);
    Vertex fromResult = graph.getVertex(link.getFromNode().getStringID());
    Vertex toResult = graph.getVertex(link.getToNode().getStringID());
    Vertex anotherResult = graph.getVertex(node3.getStringID());
    // the from node was explicitly added, it should still be there
    assertNotNull(fromResult);
    // the uses link should be gone
    // the "another" link should still be there
    count = 0;
    for (Edge edge : fromResult.getEdges(Direction.OUT, "uses")) {
        count++;
        assertEquals("another", edge.getVertex(Direction.IN).getId());
        System.out.println(edge.toString());
    }
    assertEquals(1, count);
    // any virtual nodes that were associated with the link should also be removed
    assertNull(toResult);
    assertNotNull(anotherResult);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Aggregations

IMetaverseLink (org.pentaho.metaverse.api.IMetaverseLink)12 Vertex (com.tinkerpop.blueprints.Vertex)8 Test (org.junit.Test)8 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)5 Edge (com.tinkerpop.blueprints.Edge)3 MetaverseLink (org.pentaho.dictionary.MetaverseLink)2 Direction (com.tinkerpop.blueprints.Direction)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Date (java.util.Date)1 KettleException (org.pentaho.di.core.exception.KettleException)1 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)1 Trans (org.pentaho.di.trans.Trans)1 TransHopMeta (org.pentaho.di.trans.TransHopMeta)1 TransMeta (org.pentaho.di.trans.TransMeta)1 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 GenericStepMetaAnalyzer (org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer)1 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)1 INamespace (org.pentaho.metaverse.api.INamespace)1 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)1