Search in sources :

Example 6 with TransformationNode

use of org.pentaho.metaverse.frames.TransformationNode in project pentaho-metaverse by pentaho.

the class MdiValidationIT method verifyMdiInputs.

private void verifyMdiInputs(final TransformationStepNode mdiNode, final TransformationStepNode inputStepNode, final String subTransStepNodeName, final Map<String, String> fieldToPopulatedPropMap) {
    // verify that the inputStepNode itself is not null
    assertNotNull(inputStepNode);
    // get the step's output fields and verify that they are all inputs into the mdi node
    final List<StreamFieldNode> inputStepOutputFields = IteratorUtils.toList(inputStepNode.getOutputStreamFields().iterator());
    for (final StreamFieldNode field : inputStepOutputFields) {
        assertEquals(mdiNode, field.getStepThatInputsMe());
        // also verify that the step name belongs to this step
        assertTrue(IteratorUtils.toList(fieldToPopulatedPropMap.keySet().iterator()).contains(field.getName()));
    }
    // get the templateSubTransNode - we can assume that there's exactly one
    final TransformationNode templateSubTrans = (TransformationNode) IteratorUtils.toList(mdiNode.getExecutesNodes().iterator()).get(0);
    // get the virtual step node that is contained by this sub-transformation that corresponds to 'subTransStepNodeName'
    final TransformationStepNode templateSubTransStepNode = templateSubTrans.getStepNode(subTransStepNodeName);
    final List<FramedMetaverseNode> containedProperties = IteratorUtils.toList(templateSubTransStepNode.getContainedNodes().iterator());
    // defined within the 'fieldToPopulatedPropMap'
    for (final StreamFieldNode field : inputStepOutputFields) {
        // get the property name corresponding to this field name
        final String mdiPropertyName = fieldToPopulatedPropMap.get(field.getName());
        // verify that it is contained within the containedProperties (only for non-empty properties
        if (StringUtils.isNotBlank(mdiPropertyName)) {
            assertTrue(containsName(containedProperties, mdiPropertyName));
            // get the "populates" edges for this field and verify that there is one pointing to this mdi property
            final List<FramedMetaverseNode> nodesPopulatedByMe = IteratorUtils.toList(field.getNodesPopulatedByMe().iterator());
            assertTrue(containsName(nodesPopulatedByMe, mdiPropertyName));
        }
    }
}
Also used : TransformationNode(org.pentaho.metaverse.frames.TransformationNode) TransformationStepNode(org.pentaho.metaverse.frames.TransformationStepNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) FramedMetaverseNode(org.pentaho.metaverse.frames.FramedMetaverseNode)

Example 7 with TransformationNode

use of org.pentaho.metaverse.frames.TransformationNode in project pentaho-metaverse by pentaho.

the class MdiValidationIT method verifyMdiNode.

private TransformationStepNode verifyMdiNode(final Map<String, FramedMetaverseNode> stepNodeMap, final TransformationNode templateSubTransNode, final String[] expectedOutputFieldNameArray) {
    // verify that the Text Output and Text Output - Fields steps hot into the mdi step and that their output fields
    // input into the mdi step
    final TransformationStepNode mdiNode = (TransformationStepNode) stepNodeMap.get("ETL Metadata Injection");
    assertNotNull(mdiNode);
    // the MDI node should "execute" the template sub-transformation node
    assertEquals(1, getIterableSize(mdiNode.getExecutesNodes()));
    final TransformationNode executedTransNode = (TransformationNode) IteratorUtils.toList(mdiNode.getExecutesNodes().iterator()).get(0);
    assertEquals(templateSubTransNode, executedTransNode);
    final List<StreamFieldNode> mdiOutputFields = IteratorUtils.toList(mdiNode.getOutputStreamFields().iterator());
    final List<String> expectedOutputFieldNames = Arrays.asList(expectedOutputFieldNameArray == null ? new String[] {} : expectedOutputFieldNameArray);
    assertEquals(expectedOutputFieldNames.size(), mdiOutputFields.size());
    for (final StreamFieldNode field : mdiOutputFields) {
        assertTrue(expectedOutputFieldNames.contains(field.getName()));
    }
    return mdiNode;
}
Also used : TransformationNode(org.pentaho.metaverse.frames.TransformationNode) TransformationStepNode(org.pentaho.metaverse.frames.TransformationStepNode) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode)

Example 8 with TransformationNode

use of org.pentaho.metaverse.frames.TransformationNode in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testTransformationStepNodes.

@Test
public void testTransformationStepNodes() throws Exception {
    for (TransformationNode transNode : root.getTransformations()) {
        TransMeta tm = new TransMeta(new FileInputStream(transNode.getPath()), null, true, null, null);
        List<StepMeta> transMetaSteps = tm.getSteps();
        int matchCount = 0;
        for (StepMeta transMetaStep : transMetaSteps) {
            // let's see if the steps are in the graph for this transformation
            TransformationStepNode stepNode = transNode.getStepNode(transMetaStep.getName());
            assertNotNull(stepNode);
            assertEquals("Incorrect type", DictionaryConst.NODE_TYPE_TRANS_STEP, stepNode.getType());
            assertEquals("Incorrect entity type", DictionaryConst.NODE_TYPE_TRANS_STEP, stepNode.getEntity().getName());
            ++matchCount;
        }
        assertEquals("Not all transformation steps are modeled in the graph for [" + tm.getName() + "]", transMetaSteps.size(), matchCount);
        Collection<String> expectedStepNames = new TreeSet<>(transMetaSteps.stream().map(sm -> sm.getName()).collect(Collectors.toList()));
        Collection<String> actualStepNames = new TreeSet<>(StreamSupport.stream(transNode.getStepNodes().spliterator(), false).map(tsn -> tsn.asVertex().getProperty("name").toString()).collect(Collectors.toList()));
        assertEquals("Incorrect number of Steps in the graph for transformation [" + tm.getName() + "]", expectedStepNames, actualStepNames);
    }
}
Also used : TransformationNode(org.pentaho.metaverse.frames.TransformationNode) TreeSet(java.util.TreeSet) TransMeta(org.pentaho.di.trans.TransMeta) TransformationStepNode(org.pentaho.metaverse.frames.TransformationStepNode) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 9 with TransformationNode

use of org.pentaho.metaverse.frames.TransformationNode in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testTransformations.

@Test
public void testTransformations() throws Exception {
    for (TransformationNode node : root.getTransformations()) {
        assertEquals("Incorrect entity type", DictionaryConst.NODE_TYPE_TRANS, node.getEntity().getName());
        // get the TransMeta for this node
        FileInputStream fis = new FileInputStream(node.getPath());
        TransMeta tm = new TransMeta(fis, null, true, null, null);
        assertNotNull(tm);
        assertEquals(tm.getName(), node.getName());
        assertEquals(tm.getTransversion(), node.getVersion());
        assertEquals(convertNumericStatusToString(tm.getTransstatus()), node.getStatus());
        assertEquals(tm.getDescription(), node.getDescription());
        assertEquals(tm.getExtendedDescription(), node.getExtendedDescription());
        assertNotNull(node.getLastModified());
        assertEquals(tm.getModifiedUser(), node.getLastModifiedBy());
        assertNotNull(node.getLastModified());
        assertEquals(tm.getCreatedUser(), node.getCreatedBy());
        // params?
        String[] params = tm.listParameters();
        for (String param : params) {
            assertNotNull("Parameter is missing [" + param + "]", node.getParameter("parameter_" + param));
        }
    }
}
Also used : TransformationNode(org.pentaho.metaverse.frames.TransformationNode) TransMeta(org.pentaho.di.trans.TransMeta) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 10 with TransformationNode

use of org.pentaho.metaverse.frames.TransformationNode in project pentaho-metaverse by pentaho.

the class BaseMetaverseValidationIT method verifyTransformationNode.

/**
 * Verifies that the transformation node with the given name exists in the graph.
 *
 * @param transformationName the transformation node name
 * @param isSubTrans         true if looking for a node corresponding to a sub-transformation (executed by some step),
 *                           false otherwise
 * @return the verified {@link TransformationNode}
 */
protected TransformationNode verifyTransformationNode(final String transformationName, final boolean isSubTrans) {
    // verify the existence of two transformation nodes - one for the injector and one for the sub-transformation
    final List<TransformationNode> allTransformations = IteratorUtils.toList(root.getTransformations().iterator());
    final TransformationNode node = isSubTrans ? root.getSubTransformation(transformationName) : root.getTransformation(transformationName);
    assertNotNull(node);
    assertTrue(allTransformations.contains(node));
    assertEquals("{\"name\":\"" + REPO_ID + "\",\"type\":\"Locator\"}", node.getProperty(PROPERTY_NAMESPACE).toString());
    return node;
}
Also used : TransformationNode(org.pentaho.metaverse.frames.TransformationNode)

Aggregations

TransformationNode (org.pentaho.metaverse.frames.TransformationNode)18 TransformationStepNode (org.pentaho.metaverse.frames.TransformationStepNode)16 Test (org.junit.Test)15 FramedMetaverseNode (org.pentaho.metaverse.frames.FramedMetaverseNode)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 FileInputStream (java.io.FileInputStream)2 TransMeta (org.pentaho.di.trans.TransMeta)2 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 TreeSet (java.util.TreeSet)1 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 DatasourceNode (org.pentaho.metaverse.frames.DatasourceNode)1