Search in sources :

Example 1 with LineageHolder

use of org.pentaho.metaverse.api.model.LineageHolder in project pentaho-metaverse by pentaho.

the class JobLineageHolderMap method getLineageHolder.

public LineageHolder getLineageHolder(Job job) {
    LineageHolder holder = lineageHolderMap.get(job);
    if (holder == null) {
        holder = new LineageHolder();
        lineageHolderMap.put(job, holder);
    }
    return holder;
}
Also used : LineageHolder(org.pentaho.metaverse.api.model.LineageHolder)

Example 2 with LineageHolder

use of org.pentaho.metaverse.api.model.LineageHolder in project pentaho-metaverse by pentaho.

the class TransformationRuntimeExtensionPoint method createLineGraph.

protected void createLineGraph(final Trans trans) {
    try {
        // Get the current execution profile for this transformation
        LineageHolder holder = TransLineageHolderMap.getInstance().getLineageHolder(trans);
        Future lineageTask = holder.getLineageTask();
        if (lineageTask != null) {
            try {
                lineageTask.get();
            } catch (InterruptedException e) {
            // Do nothing
            } catch (ExecutionException e) {
                log.warn(Messages.getString("ERROR.CouldNotWriteLineageGraph", trans.getName(), Const.NVL(e.getLocalizedMessage(), "Unspecified")));
                log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), e);
            }
        }
        IExecutionProfile executionProfile = holder.getExecutionProfile();
        if (executionProfile == null) {
            // Something's wrong here, the transStarted method didn't properly store the execution profile. We should know
            // the same info, so populate a new ExecutionProfile using the current Trans
            // TODO: Beware duplicate profiles!
            executionProfile = new ExecutionProfile();
            populateExecutionProfile(executionProfile, trans);
        }
        ExecutionData executionData = (ExecutionData) executionProfile.getExecutionData();
        Result result = trans.getResult();
        if (result != null) {
            executionData.setFailureCount(result.getNrErrors());
        }
        // Export the lineage info (execution profile, lineage graph, etc.)
        try {
            if (lineageWriter != null && !"none".equals(lineageWriter.getOutputStrategy())) {
                // clearOutput right before the first call to outputXYZ().
                if ("latest".equals(lineageWriter.getOutputStrategy())) {
                    lineageWriter.cleanOutput(holder);
                }
                lineageWriter.outputExecutionProfile(holder);
            }
        } catch (IOException e) {
            log.warn(Messages.getString("ERROR.CouldNotWriteExecutionProfile", trans.getName(), Const.NVL(e.getLocalizedMessage(), "Unspecified")));
            log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), e);
        }
        // lineage information into its own graph
        try {
            Job parentJob = trans.getParentJob();
            Trans parentTrans = trans.getParentTrans();
            if (parentJob == null && parentTrans == null) {
                // Add the execution profile information to the lineage graph
                addRuntimeLineageInfo(holder);
                if (lineageWriter != null && !"none".equals(lineageWriter.getOutputStrategy())) {
                    lineageWriter.outputLineageGraph(holder);
                }
            }
        } catch (IOException e) {
            log.warn(Messages.getString("ERROR.CouldNotWriteExecutionProfile", trans.getName(), Const.NVL(e.getLocalizedMessage(), "Unspecified")));
            log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), e);
        }
    } catch (Throwable t) {
        log.warn(Messages.getString("ERROR.ErrorDuringAnalysis", trans.getName(), Const.NVL(t.getLocalizedMessage(), "Unspecified")));
        log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), t);
    }
}
Also used : IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) Future(java.util.concurrent.Future) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Job(org.pentaho.di.job.Job) ExecutionProfile(org.pentaho.metaverse.impl.model.ExecutionProfile) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) Trans(org.pentaho.di.trans.Trans) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder) IExecutionData(org.pentaho.metaverse.api.model.IExecutionData) ExecutionData(org.pentaho.metaverse.impl.model.ExecutionData) Result(org.pentaho.di.core.Result)

Example 3 with LineageHolder

use of org.pentaho.metaverse.api.model.LineageHolder 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 4 with LineageHolder

use of org.pentaho.metaverse.api.model.LineageHolder 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 LineageHolder

use of org.pentaho.metaverse.api.model.LineageHolder 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

LineageHolder (org.pentaho.metaverse.api.model.LineageHolder)16 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)10 ExecutionProfile (org.pentaho.metaverse.impl.model.ExecutionProfile)8 Test (org.junit.Test)7 IExecutionData (org.pentaho.metaverse.api.model.IExecutionData)7 Trans (org.pentaho.di.trans.Trans)6 Job (org.pentaho.di.job.Job)5 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)5 ExecutionData (org.pentaho.metaverse.impl.model.ExecutionData)5 Before (org.junit.Before)3 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 Result (org.pentaho.di.core.Result)2 StepInterface (org.pentaho.di.trans.step.StepInterface)2 AnalysisContext (org.pentaho.metaverse.api.AnalysisContext)2 IDocument (org.pentaho.metaverse.api.IDocument)2 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)2 INamespace (org.pentaho.metaverse.api.INamespace)2 MetaverseException (org.pentaho.metaverse.api.MetaverseException)2