Search in sources :

Example 6 with IDocument

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

the class LineageClientIT method setUp.

@Before
public void setUp() throws Exception {
    transMeta = new TransMeta(MERGE_JOIN_KTR_FILENAME);
    IDocument doc = MetaverseUtil.createDocument(new Namespace("SPOON"), transMeta, transMeta.getFilename(), transMeta.getName(), "ktr", URLConnection.getFileNameMap().getContentTypeFor(transMeta.getFilename()));
    Graph graph = new TinkerGraph();
    MetaverseUtil.addLineageGraph(doc, graph);
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) TransMeta(org.pentaho.di.trans.TransMeta) IDocument(org.pentaho.metaverse.api.IDocument) Namespace(org.pentaho.metaverse.api.Namespace) Before(org.junit.Before)

Example 7 with IDocument

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

the class JobRuntimeExtensionPoint method callExtensionPoint.

/**
 * Callback when a job is about to be started
 *
 * @param logChannelInterface A reference to the log in this context (the Job object's log)
 * @param o                   The object being operated on (Job in this case)
 * @throws org.pentaho.di.core.exception.KettleException
 */
@Override
public void callExtensionPoint(LogChannelInterface logChannelInterface, Object o) throws KettleException {
    // Job Started listeners get called after the extension point is invoked, so just add a job listener
    if (o instanceof Job) {
        Job job = ((Job) o);
        // If runtime lineage collection is disabled, don't run any lineage processes/methods
        if (!isRuntimeEnabled()) {
            return;
        }
        // Create and populate an execution profile with what we know so far
        ExecutionProfile executionProfile = new ExecutionProfile();
        populateExecutionProfile(executionProfile, job);
        IMetaverseBuilder builder = JobLineageHolderMap.getInstance().getMetaverseBuilder(job);
        // Add the job finished listener
        job.addJobListener(this);
        // 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 JobMeta jobMeta = job.getJobMeta();
            // The variables and parameters in the Job may not have been set on the meta, so we do it here
            // to ensure the job analyzer will have access to the parameter values.
            jobMeta.copyParametersFrom(job);
            jobMeta.activateParameters();
            job.copyVariablesFrom(jobMeta);
            if (job.getRep() != null) {
                jobMeta.setRepository(job.getRep());
            }
            String id = getFilename(jobMeta);
            if (!id.endsWith(jobMeta.getDefaultExtension())) {
                id += "." + jobMeta.getDefaultExtension();
            }
            IDocument metaverseDocument = builder.getMetaverseObjectFactory().createDocumentObject();
            metaverseDocument.setNamespace(namespace);
            metaverseDocument.setContent(jobMeta);
            metaverseDocument.setStringID(id);
            metaverseDocument.setName(jobMeta.getName());
            metaverseDocument.setExtension("kjb");
            metaverseDocument.setMimeType(URLConnection.getFileNameMap().getContentTypeFor("job.kjb"));
            metaverseDocument.setContext(new AnalysisContext(DictionaryConst.CONTEXT_RUNTIME));
            String normalizedPath;
            try {
                normalizedPath = KettleAnalyzerUtil.normalizeFilePath(id);
            } catch (MetaverseException e) {
                normalizedPath = id;
            }
            metaverseDocument.setProperty(DictionaryConst.PROPERTY_NAME, job.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 = JobLineageHolderMap.getInstance().getLineageHolder(job);
        holder.setExecutionProfile(executionProfile);
        holder.setMetaverseBuilder(builder);
    }
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) AnalysisContext(org.pentaho.metaverse.api.AnalysisContext) 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) INamespace(org.pentaho.metaverse.api.INamespace) Job(org.pentaho.di.job.Job) IMetaverseBuilder(org.pentaho.metaverse.api.IMetaverseBuilder) IDocument(org.pentaho.metaverse.api.IDocument) MetaverseException(org.pentaho.metaverse.api.MetaverseException) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder)

Example 8 with IDocument

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

the class MetaverseUtil method createDocument.

public static IDocument createDocument(INamespace namespace, Object content, String id, String name, String extension, String mimeType) {
    IDocument metaverseDocument = getDocumentController().getMetaverseObjectFactory().createDocumentObject();
    metaverseDocument.setNamespace(namespace);
    metaverseDocument.setContent(content);
    metaverseDocument.setStringID(id);
    metaverseDocument.setName(name);
    metaverseDocument.setExtension(extension);
    metaverseDocument.setMimeType(mimeType);
    metaverseDocument.setProperty(DictionaryConst.PROPERTY_PATH, id);
    metaverseDocument.setProperty(DictionaryConst.PROPERTY_NAMESPACE, namespace.getNamespaceId());
    return metaverseDocument;
}
Also used : IDocument(org.pentaho.metaverse.api.IDocument)

Example 9 with IDocument

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

the class JobAnalyzerTest method testAnalyzeWithBadXML.

@Test(expected = MetaverseAnalyzerException.class)
public void testAnalyzeWithBadXML() throws MetaverseAnalyzerException {
    IDocument newMockJobDoc = mock(IDocument.class);
    when(newMockJobDoc.getType()).thenReturn(DictionaryConst.NODE_TYPE_JOB);
    when(newMockJobDoc.getContent()).thenReturn("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<job>This is not a valid JobMeta doc!");
    analyzer.analyze(descriptor, newMockJobDoc);
}
Also used : IDocument(org.pentaho.metaverse.api.IDocument) Test(org.junit.Test)

Example 10 with IDocument

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

the class TransformationAnalyzerTest method testAnalyzeWithBadXML.

@Test(expected = MetaverseAnalyzerException.class)
public void testAnalyzeWithBadXML() throws MetaverseAnalyzerException {
    IDocument newMockTransDoc = mock(IDocument.class);
    when(newMockTransDoc.getType()).thenReturn(DictionaryConst.NODE_TYPE_TRANS);
    when(newMockTransDoc.getContent()).thenReturn("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<transformation>This is not a valid TransMeta doc!");
    analyzer.analyze(descriptor, newMockTransDoc);
}
Also used : IDocument(org.pentaho.metaverse.api.IDocument) Test(org.junit.Test)

Aggregations

IDocument (org.pentaho.metaverse.api.IDocument)14 Test (org.junit.Test)8 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)4 INamespace (org.pentaho.metaverse.api.INamespace)4 Namespace (org.pentaho.metaverse.api.Namespace)4 Graph (com.tinkerpop.blueprints.Graph)3 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)3 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)3 MetaverseException (org.pentaho.metaverse.api.MetaverseException)3 TransMeta (org.pentaho.di.trans.TransMeta)2 AnalysisContext (org.pentaho.metaverse.api.AnalysisContext)2 IDocumentAnalyzer (org.pentaho.metaverse.api.IDocumentAnalyzer)2 IMetaverseObjectFactory (org.pentaho.metaverse.api.IMetaverseObjectFactory)2 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)2 LineageHolder (org.pentaho.metaverse.api.model.LineageHolder)2 ExecutionProfile (org.pentaho.metaverse.impl.model.ExecutionProfile)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1