use of org.pentaho.metaverse.api.AnalysisContext 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.AnalysisContext in project pentaho-metaverse by pentaho.
the class TableOutputExternalResourceConsumerTest method testGetResourcesFromMeta_static.
@Test
public void testGetResourcesFromMeta_static() throws Exception {
TableOutputMeta meta = mock(TableOutputMeta.class);
DatabaseMeta dbMeta = mock(DatabaseMeta.class);
DatabaseInterface dbi = mock(DatabaseInterface.class);
when(meta.getDatabaseMeta()).thenReturn(dbMeta);
when(meta.getTableName()).thenReturn("tableName");
when(meta.getSchemaName()).thenReturn("schemaName");
when(meta.getParentStepMeta()).thenReturn(parentStepMeta);
when(parentStepMeta.getParentTransMeta()).thenReturn(parentTransMeta);
when(parentTransMeta.environmentSubstitute("tableName")).thenReturn("tableName");
when(parentTransMeta.environmentSubstitute("schemaName")).thenReturn("schemaName");
when(dbMeta.getAccessTypeDesc()).thenReturn("JNDI");
when(dbMeta.getName()).thenReturn("TestConnection");
when(dbMeta.getDescription()).thenReturn("my conn description");
when(dbMeta.getDatabaseInterface()).thenReturn(dbi);
when(dbi.getPluginId()).thenReturn("POSTGRESQL");
Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(meta, new AnalysisContext(DictionaryConst.CONTEXT_STATIC));
assertEquals(1, resources.size());
IExternalResourceInfo res = resources.iterator().next();
assertEquals("TestConnection", res.getName());
assertEquals("tableName", res.getAttributes().get(DictionaryConst.PROPERTY_TABLE));
assertEquals("schemaName", res.getAttributes().get(DictionaryConst.PROPERTY_SCHEMA));
}
use of org.pentaho.metaverse.api.AnalysisContext 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);
}
}
use of org.pentaho.metaverse.api.AnalysisContext in project pentaho-metaverse by pentaho.
the class TableOutputExternalResourceConsumerTest method testGetResourcesFromMeta_runtime.
@Test
public void testGetResourcesFromMeta_runtime() throws Exception {
TableOutputMeta meta = mock(TableOutputMeta.class);
DatabaseMeta dbMeta = mock(DatabaseMeta.class);
DatabaseInterface dbi = mock(DatabaseInterface.class);
when(meta.getDatabaseMeta()).thenReturn(dbMeta);
when(meta.getTableName()).thenReturn("tableName");
when(meta.getSchemaName()).thenReturn("schemaName");
when(meta.getParentStepMeta()).thenReturn(parentStepMeta);
when(parentStepMeta.getParentTransMeta()).thenReturn(parentTransMeta);
when(parentTransMeta.environmentSubstitute("tableName")).thenReturn("tableName");
when(parentTransMeta.environmentSubstitute("schemaName")).thenReturn("schemaName");
when(dbMeta.getAccessTypeDesc()).thenReturn("JNDI");
when(dbMeta.getName()).thenReturn("TestConnection");
when(dbMeta.getDescription()).thenReturn("my conn description");
when(dbMeta.getDatabaseInterface()).thenReturn(dbi);
when(dbi.getPluginId()).thenReturn("POSTGRESQL");
Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(meta, new AnalysisContext(DictionaryConst.CONTEXT_RUNTIME));
assertEquals(1, resources.size());
IExternalResourceInfo res = resources.iterator().next();
assertEquals("TestConnection", res.getName());
assertEquals("tableName", res.getAttributes().get(DictionaryConst.PROPERTY_TABLE));
assertEquals("schemaName", res.getAttributes().get(DictionaryConst.PROPERTY_SCHEMA));
}
Aggregations