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);
}
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);
}
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);
}
}
}
}
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));
}
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);
}
Aggregations