Search in sources :

Example 1 with IMetaverseBuilder

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

the class TransExtensionPointUtil method addLineageGraph.

public static void addLineageGraph(final TransMeta transMeta) throws MetaverseException {
    if (transMeta == null) {
        throw new MetaverseException(Messages.getString("ERROR.Document.IsNull"));
    }
    // Get the "natural" filename (repo-based if in repository, filesystem-based otherwise)
    String filename = getFilename(transMeta);
    final Graph graph = new TinkerGraph();
    final IMetaverseBuilder metaverseBuilder = new MetaverseBuilder(graph);
    final IMetaverseObjectFactory objFactory = MetaverseUtil.getDocumentController().getMetaverseObjectFactory();
    // Add the client design node
    final String clientName = KettleClientEnvironment.getInstance().getClient().toString();
    final INamespace namespace = new Namespace(clientName);
    final IMetaverseNode designNode = objFactory.createNodeObject(clientName, clientName, DictionaryConst.NODE_TYPE_LOCATOR);
    metaverseBuilder.addNode(designNode);
    // Create a document object containing the transMeta
    final IDocument document = MetaverseUtil.createDocument(namespace, transMeta, filename, transMeta.getName(), "ktr", URLConnection.getFileNameMap().getContentTypeFor("trans.ktr"));
    MetaverseUtil.addLineageGraph(document, graph);
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) INamespace(org.pentaho.metaverse.api.INamespace) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IMetaverseObjectFactory(org.pentaho.metaverse.api.IMetaverseObjectFactory) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseBuilder(org.pentaho.metaverse.impl.MetaverseBuilder) MetaverseException(org.pentaho.metaverse.api.MetaverseException) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) IDocument(org.pentaho.metaverse.api.IDocument)

Example 2 with IMetaverseBuilder

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

the class TransformationRuntimeExtensionPoint method startAnalyzer.

protected void startAnalyzer(Trans trans) throws KettleException {
    if (trans == null) {
        return;
    }
    // Create and populate an execution profile with what we know so far
    ExecutionProfile executionProfile = new ExecutionProfile();
    populateExecutionProfile(executionProfile, trans);
    IMetaverseBuilder builder = TransLineageHolderMap.getInstance().getMetaverseBuilder(trans);
    // Analyze the current transformation
    if (documentAnalyzer != null) {
        documentAnalyzer.setMetaverseBuilder(builder);
        // Create a document for the Trans
        final String clientName = executionProfile.getExecutionEngine().getName();
        final INamespace namespace = new Namespace(clientName);
        final IMetaverseNode designNode = builder.getMetaverseObjectFactory().createNodeObject(clientName, clientName, DictionaryConst.NODE_TYPE_LOCATOR);
        builder.addNode(designNode);
        final TransMeta transMeta = trans.getTransMeta();
        String id = TransExtensionPointUtil.getFilename(transMeta);
        IDocument metaverseDocument = builder.getMetaverseObjectFactory().createDocumentObject();
        metaverseDocument.setNamespace(namespace);
        metaverseDocument.setContent(transMeta);
        metaverseDocument.setStringID(id);
        metaverseDocument.setName(transMeta.getName());
        metaverseDocument.setExtension("ktr");
        metaverseDocument.setMimeType(URLConnection.getFileNameMap().getContentTypeFor("trans.ktr"));
        metaverseDocument.setContext(new AnalysisContext(DictionaryConst.CONTEXT_RUNTIME));
        String normalizedPath;
        try {
            normalizedPath = KettleAnalyzerUtil.normalizeFilePath(id);
        } catch (MetaverseException e) {
            normalizedPath = id;
        }
        metaverseDocument.setProperty(DictionaryConst.PROPERTY_NAME, trans.getName());
        metaverseDocument.setProperty(DictionaryConst.PROPERTY_PATH, normalizedPath);
        metaverseDocument.setProperty(DictionaryConst.PROPERTY_NAMESPACE, namespace.getNamespaceId());
        Runnable analyzerRunner = MetaverseUtil.getAnalyzerRunner(documentAnalyzer, metaverseDocument);
        MetaverseCompletionService.getInstance().submit(analyzerRunner, id);
    }
    // Save the lineage objects for later
    LineageHolder holder = TransLineageHolderMap.getInstance().getLineageHolder(trans);
    holder.setExecutionProfile(executionProfile);
    holder.setMetaverseBuilder(builder);
}
Also used : INamespace(org.pentaho.metaverse.api.INamespace) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) TransMeta(org.pentaho.di.trans.TransMeta) AnalysisContext(org.pentaho.metaverse.api.AnalysisContext) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) ExecutionProfile(org.pentaho.metaverse.impl.model.ExecutionProfile) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) IDocument(org.pentaho.metaverse.api.IDocument) MetaverseException(org.pentaho.metaverse.api.MetaverseException) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder)

Example 3 with IMetaverseBuilder

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

the class MetaverseUtil method addLineageGraph.

public static void addLineageGraph(final IDocument document, Graph graph) throws MetaverseException {
    if (document == null) {
        throw new MetaverseException(Messages.getString("ERROR.Document.IsNull"));
    }
    // Find the transformation analyzer(s) and create Futures to analyze the transformation.
    // Right now we expect a single transformation analyzer in the system. If we need to support more,
    // the lineageGraphMap needs to map the TransMeta to a collection of Futures, etc.
    IDocumentController docController = MetaverseUtil.getDocumentController();
    if (docController != null) {
        // Create a new builder, setting it on the DocumentController if possible
        IMetaverseBuilder metaverseBuilder = new MetaverseBuilder(graph);
        docController.setMetaverseBuilder(metaverseBuilder);
        List<IDocumentAnalyzer> matchingAnalyzers = docController.getDocumentAnalyzers("ktr");
        if (matchingAnalyzers != null) {
            for (final IDocumentAnalyzer analyzer : matchingAnalyzers) {
                Runnable analyzerRunner = getAnalyzerRunner(analyzer, document);
                Graph g = (graph != null) ? graph : new TinkerGraph();
                Future<Graph> transAnalysis = LineageGraphCompletionService.getInstance().submit(analyzerRunner, g);
                // Save this Future, the client will call it when the analysis is needed
                LineageGraphMap.getInstance().put(document.getContent(), transAnalysis);
            }
        }
    }
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) IDocumentController(org.pentaho.metaverse.api.IDocumentController) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IDocumentAnalyzer(org.pentaho.metaverse.api.IDocumentAnalyzer) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseBuilder(org.pentaho.metaverse.impl.MetaverseBuilder) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) MetaverseException(org.pentaho.metaverse.api.MetaverseException)

Example 4 with IMetaverseBuilder

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

the class BaseRuntimeExtensionPointTest method testWriteLineageHolder.

@Test
public void testWriteLineageHolder() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    assertEquals(0, baos.size());
    PrintStream stringStream = new PrintStream(baos);
    IGraphWriter graphWriter = mock(IGraphWriter.class);
    IExecutionProfile executionProfile = new ExecutionProfile();
    executionProfile.setName("testName");
    IMetaverseBuilder builder = mock(IMetaverseBuilder.class);
    LineageHolder holder = new LineageHolder(executionProfile, builder);
    LineageWriter lineageWriter = new LineageWriter();
    lineageWriter.setProfileOutputStream(stringStream);
    lineageWriter.setGraphOutputStream(System.out);
    lineageWriter.setOutputStrategy("all");
    lineageWriter.setGraphWriter(graphWriter);
    extensionPoint.setLineageWriter(lineageWriter);
    extensionPoint.writeLineageInfo(holder);
    assertNotEquals(0, baos.size());
    assertTrue(baos.toString().contains("testName"));
    verify(graphWriter, times(1)).outputGraph(any(Graph.class), any(OutputStream.class));
}
Also used : PrintStream(java.io.PrintStream) Graph(com.tinkerpop.blueprints.Graph) LineageWriter(org.pentaho.metaverse.impl.LineageWriter) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) IGraphWriter(org.pentaho.metaverse.api.IGraphWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) ExecutionProfile(org.pentaho.metaverse.impl.model.ExecutionProfile) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder) Test(org.junit.Test)

Example 5 with IMetaverseBuilder

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

the class JobLineageHolderMapTest method testGetMetaverseBuilder.

@Test
public void testGetMetaverseBuilder() throws Exception {
    assertNull(jobLineageHolderMap.getMetaverseBuilder(null));
    Job job = mock(Job.class);
    when(job.getParentJob()).thenReturn(null);
    when(job.getParentTrans()).thenReturn(null);
    mockHolder.setMetaverseBuilder(mockBuilder);
    jobLineageHolderMap.putLineageHolder(job, mockHolder);
    IMetaverseBuilder builder = jobLineageHolderMap.getMetaverseBuilder(job);
    assertNotNull(builder);
    Job parentJob = mock(Job.class);
    when(parentJob.getParentJob()).thenReturn(null);
    when(parentJob.getParentTrans()).thenReturn(null);
    when(job.getParentJob()).thenReturn(parentJob);
    LineageHolder mockParentHolder = spy(new LineageHolder());
    IMetaverseBuilder mockParentBuilder = mock(IMetaverseBuilder.class);
    jobLineageHolderMap.putLineageHolder(parentJob, mockParentHolder);
    mockParentHolder.setMetaverseBuilder(null);
    assertEquals(defaultBuilder, jobLineageHolderMap.getMetaverseBuilder(job));
    mockParentHolder.setMetaverseBuilder(mockParentBuilder);
    builder = jobLineageHolderMap.getMetaverseBuilder(job);
    assertNotNull(builder);
}
Also used : Job(org.pentaho.di.job.Job) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder) Test(org.junit.Test)

Aggregations

IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)20 Test (org.junit.Test)12 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)10 Graph (com.tinkerpop.blueprints.Graph)7 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)6 LineageHolder (org.pentaho.metaverse.api.model.LineageHolder)5 IDocumentEvent (org.pentaho.metaverse.api.IDocumentEvent)4 INamespace (org.pentaho.metaverse.api.INamespace)4 MetaverseDocument (org.pentaho.metaverse.api.MetaverseDocument)4 MetaverseException (org.pentaho.metaverse.api.MetaverseException)4 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)4 JobMeta (org.pentaho.di.job.JobMeta)3 TransMeta (org.pentaho.di.trans.TransMeta)3 IDocument (org.pentaho.metaverse.api.IDocument)3 IDocumentController (org.pentaho.metaverse.api.IDocumentController)3 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)3 Namespace (org.pentaho.metaverse.api.Namespace)3 ExecutionProfile (org.pentaho.metaverse.impl.model.ExecutionProfile)3 Job (org.pentaho.di.job.Job)2 AnalysisContext (org.pentaho.metaverse.api.AnalysisContext)2