Search in sources :

Example 11 with IMetaverseNode

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

the class TransExecutorStepAnalyzer method customAnalyze.

@Override
protected void customAnalyze(TransExecutorMeta meta, IMetaverseNode node) throws MetaverseAnalyzerException {
    String transPath = meta.getFileName();
    TransMeta subTransMeta = null;
    Repository repo = parentTransMeta.getRepository();
    switch(meta.getSpecificationMethod()) {
        case FILENAME:
            transPath = parentTransMeta.environmentSubstitute(meta.getFileName());
            try {
                String normalized = KettleAnalyzerUtil.normalizeFilePath(transPath);
                subTransMeta = getSubTransMeta(normalized);
                transPath = normalized;
            } catch (Exception e) {
                throw new MetaverseAnalyzerException("Sub transformation can not be found - " + transPath, e);
            }
            break;
        case REPOSITORY_BY_NAME:
            if (repo != null) {
                String dir = parentTransMeta.environmentSubstitute(meta.getDirectoryPath());
                String file = parentTransMeta.environmentSubstitute(meta.getTransName());
                try {
                    RepositoryDirectoryInterface rdi = repo.findDirectory(dir);
                    subTransMeta = repo.loadTransformation(file, rdi, null, true, null);
                    transPath = subTransMeta.getPathAndName() + "." + subTransMeta.getDefaultExtension();
                } catch (KettleException e) {
                    throw new MetaverseAnalyzerException("Sub transformation can not be found in repository - " + file, e);
                }
            } else {
                throw new MetaverseAnalyzerException("Not connected to a repository, can't get the transformation");
            }
            break;
        case REPOSITORY_BY_REFERENCE:
            if (repo != null) {
                try {
                    subTransMeta = repo.loadTransformation(meta.getTransObjectId(), null);
                    transPath = subTransMeta.getPathAndName() + "." + subTransMeta.getDefaultExtension();
                } catch (KettleException e) {
                    throw new MetaverseAnalyzerException("Sub transformation can not be found by reference - " + meta.getTransObjectId(), e);
                }
            } else {
                throw new MetaverseAnalyzerException("Not connected to a repository, can't get the transformation");
            }
            break;
    }
    // analyze the sub trans?
    IComponentDescriptor ds = new MetaverseComponentDescriptor(subTransMeta.getName(), DictionaryConst.NODE_TYPE_TRANS, descriptor.getNamespace().getParentNamespace());
    IMetaverseNode transformationNode = createNodeFromDescriptor(ds);
    transformationNode.setProperty(DictionaryConst.PROPERTY_NAMESPACE, ds.getNamespaceId());
    transformationNode.setProperty(DictionaryConst.PROPERTY_PATH, transPath);
    transformationNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DOCUMENT);
    metaverseBuilder.addLink(node, DictionaryConst.LINK_EXECUTES, transformationNode);
    connectToSubTransInputFields(meta, subTransMeta, transformationNode, descriptor);
    connectToSubTransOutputFields(meta, subTransMeta, transformationNode, descriptor);
    node.setProperty(TRANSFORMATION_TO_EXECUTE, transPath);
    if (StringUtils.isNotEmpty(meta.getExecutionResultTargetStep())) {
        node.setProperty(EXECUTION_RESULTS_TARGET, meta.getExecutionResultTargetStep());
    }
    if (StringUtils.isNotEmpty(meta.getOutputRowsSourceStep())) {
        node.setProperty(OUTPUT_ROWS_TARGET, meta.getOutputRowsSourceStep());
    }
    if (StringUtils.isNotEmpty(meta.getResultFilesTargetStep())) {
        node.setProperty(RESULT_FILES_TARGET, meta.getResultFilesTargetStep());
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) TransMeta(org.pentaho.di.trans.TransMeta) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) FileNotFoundException(java.io.FileNotFoundException) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 12 with IMetaverseNode

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

the class BlueprintsGraphMetaverseReader method findLink.

@Override
public IMetaverseLink findLink(String leftNodeID, String linkType, String rightNodeID, Direction direction) {
    Vertex vertex = getGraph().getVertex(leftNodeID);
    if (vertex == null) {
        return null;
    }
    Iterable<Edge> edges = linkType == null ? vertex.getEdges(direction) : vertex.getEdges(direction, linkType);
    IMetaverseLink link = new MetaverseLink();
    IMetaverseNode node1 = new MetaverseNode(vertex);
    Direction opDirection = direction == Direction.IN ? Direction.OUT : Direction.IN;
    Vertex vertex2 = null;
    if (rightNodeID != null) {
        Iterator<Edge> it = edges.iterator();
        while (it.hasNext()) {
            Edge edge = it.next();
            if (rightNodeID.equals((String) edge.getVertex(opDirection).getId())) {
                vertex2 = edge.getVertex(opDirection);
                IMetaverseNode node2 = new MetaverseNode(vertex2);
                String label = edge.getLabel();
                link.setLabel(label);
                String localized = Messages.getString(MetaverseUtil.MESSAGE_PREFIX_LINKTYPE + label);
                if (!localized.startsWith("!")) {
                    link.setProperty(DictionaryConst.PROPERTY_TYPE_LOCALIZED, localized);
                }
                if (direction == Direction.OUT) {
                    link.setFromNode(node1);
                    link.setToNode(node2);
                } else {
                    link.setFromNode(node2);
                    link.setToNode(node1);
                }
                return link;
            }
        }
    }
    return null;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseLink(org.pentaho.dictionary.MetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) MetaverseNode(org.pentaho.metaverse.impl.MetaverseNode) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Edge(com.tinkerpop.blueprints.Edge) Direction(com.tinkerpop.blueprints.Direction)

Example 13 with IMetaverseNode

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

the class BaseLocator method startScan.

/**
 * Starts a full scan by this locator.
 *
 * @param locatorRunner The locator runner to use
 * @throws MetaverseLocatorException
 */
protected void startScan(LocatorRunner<T> locatorRunner) throws MetaverseLocatorException {
    if (futureTask != null && !futureTask.isDone()) {
        throw new MetaverseLocatorException(Messages.getString("ERROR.BaseLocator.ScanAlreadyExecuting"));
    }
    IMetaverseNode node = getLocatorNode();
    Date lastRun = new Date();
    node.setProperty("lastScan", Long.toString(lastRun.getTime()));
    metaverseBuilder.addNode(node);
    runner = locatorRunner;
    runner.setLocator(this);
    LOG.debug(Messages.getString("DEBUG.Locator.StartScan", getLocatorType()));
    futureTask = completionService.submit(runner, node.getStringID());
}
Also used : MetaverseLocatorException(org.pentaho.metaverse.api.MetaverseLocatorException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Date(java.util.Date)

Example 14 with IMetaverseNode

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

the class BaseLocator method getNamespace.

protected INamespace getNamespace() {
    IMetaverseNode locatorNode = metaverseBuilder.getMetaverseObjectFactory().createNodeObject(UUID.randomUUID().toString(), getRepositoryId(), DictionaryConst.NODE_TYPE_LOCATOR);
    locatorNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_LOCATOR);
    return new Namespace(locatorNode.getLogicalId());
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace)

Example 15 with IMetaverseNode

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

the class MetaverseReaderIT method testSearch.

@Test
public void testSearch() throws Exception {
    List<String> whatWeAreLookingFor = new ArrayList<String>(Arrays.asList(DictionaryConst.NODE_TYPE_TRANS));
    List<IMetaverseNode> nodes = reader.findNodes(DictionaryConst.PROPERTY_TYPE, DictionaryConst.NODE_TYPE_DATA_COLUMN);
    List<String> startingPoint = new ArrayList<String>(Arrays.asList(nodes.get(0).getStringID()));
    System.out.println("Looking for Transformations that write/read Database Column " + nodes.get(0).getName());
    Graph g = reader.search(whatWeAreLookingFor, startingPoint, false);
    // make sure the Transformation node is in the resulting graph
    assertNotNull(g.getVertices(DictionaryConst.PROPERTY_TYPE, DictionaryConst.NODE_TYPE_TRANS));
    // make sure the starting point node is in the resulting graph
    assertNotNull(g.getVertex(nodes.get(0).getStringID()));
    GraphMLWriter writer = new GraphMLWriter();
    writer.outputGraph(g, new FileOutputStream(IntegrationTestUtil.getOutputPath("searchOut.graphml")));
}
Also used : Graph(com.tinkerpop.blueprints.Graph) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)131 Test (org.junit.Test)77 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)30 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)23 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)16 ValueMeta (org.pentaho.di.core.row.ValueMeta)13 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)12 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)11 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)11 Vertex (com.tinkerpop.blueprints.Vertex)10 ArrayList (java.util.ArrayList)10 INamespace (org.pentaho.metaverse.api.INamespace)10 TransMeta (org.pentaho.di.trans.TransMeta)9 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)9 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)9 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)8 Namespace (org.pentaho.metaverse.api.Namespace)8 StepField (org.pentaho.metaverse.api.StepField)8 HashMap (java.util.HashMap)7 Matchers.anyString (org.mockito.Matchers.anyString)7