use of org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer in project pentaho-metaverse by pentaho.
the class AbstractStepMetaJsonSerializer method getFieldLineageMetadataProvider.
protected IFieldLineageMetadataProvider getFieldLineageMetadataProvider(T meta) {
IStepAnalyzerProvider provider = getStepAnalyzerProvider();
if (provider == null) {
// try to get it from PentahoSystem
provider = PentahoSystem.get(IStepAnalyzerProvider.class);
}
if (provider != null) {
Set<Class<?>> types = new HashSet<Class<?>>();
types.add(meta.getClass());
List<IStepAnalyzer> analyzers = provider.getAnalyzers(types);
if (analyzers != null) {
for (IStepAnalyzer analyzer : analyzers) {
// try to set up the analyzer with parent step & trans meta
if (analyzer instanceof StepAnalyzer) {
StepAnalyzer bsa = (StepAnalyzer) analyzer;
try {
bsa.validateState(null, meta);
bsa.loadInputAndOutputStreamFields(meta);
} catch (MetaverseAnalyzerException e) {
// eat it
}
}
if (analyzer instanceof IFieldLineageMetadataProvider) {
return (IFieldLineageMetadataProvider) analyzer;
}
}
}
}
return new GenericStepMetaAnalyzer();
}
use of org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer in project pentaho-metaverse by pentaho.
the class TransformationAnalyzer method getStepAnalyzers.
protected Set<IStepAnalyzer> getStepAnalyzers(final StepMeta stepMeta) {
Set<IStepAnalyzer> stepAnalyzers = new HashSet<IStepAnalyzer>();
// Attempt to discover a BaseStepMeta from the given StepMeta
BaseStepMeta baseStepMeta = getBaseStepMetaFromStepMeta(stepMeta);
stepAnalyzerProvider = getStepAnalyzerProvider();
if (stepAnalyzerProvider != null) {
if (baseStepMeta == null) {
stepAnalyzers.addAll(stepAnalyzerProvider.getAnalyzers());
} else {
Set<Class<?>> analyzerClassSet = new HashSet<Class<?>>(1);
analyzerClassSet.add(baseStepMeta.getClass());
stepAnalyzers.addAll(stepAnalyzerProvider.getAnalyzers(analyzerClassSet));
}
} else {
stepAnalyzers.add(new GenericStepMetaAnalyzer());
}
return stepAnalyzers;
}
use of org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer in project pentaho-metaverse by pentaho.
the class AbstractStepMetaJsonSerializerTest method testGetStepFieldMapper.
@Test
public void testGetStepFieldMapper() throws Exception {
IStepAnalyzerProvider provider = mock(IStepAnalyzerProvider.class);
IStepAnalyzer<DummyTransMeta> analyzer = mock(IStepAnalyzer.class, withSettings().extraInterfaces(IFieldLineageMetadataProvider.class));
List<IStepAnalyzer> analyzers = new ArrayList<IStepAnalyzer>(1);
analyzers.add(analyzer);
when(provider.getAnalyzers(any(Set.class))).thenReturn(analyzers);
serializer.setStepAnalyzerProvider(provider);
IFieldLineageMetadataProvider handler = serializer.getFieldLineageMetadataProvider(spyMeta);
assertFalse(handler instanceof GenericStepMetaAnalyzer);
}
use of org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer in project pentaho-metaverse by pentaho.
the class TransformationAnalyzer method analyze.
@Override
public synchronized IMetaverseNode analyze(IComponentDescriptor descriptor, IDocument document) throws MetaverseAnalyzerException {
validateState(document);
Object repoObject = document.getContent();
TransMeta transMeta = null;
if (repoObject instanceof String) {
// hydrate the transformation
try {
String content = (String) repoObject;
ByteArrayInputStream xmlStream = new ByteArrayInputStream(content.getBytes());
transMeta = new TransMeta(xmlStream, null, false, null, null);
transMeta.setFilename(document.getStringID());
if (transMeta.hasMissingPlugins()) {
throw new MetaverseAnalyzerException(Messages.getErrorString("ERROR.MissingPlugin"));
}
} catch (KettleException e) {
throw new MetaverseAnalyzerException(e);
}
} else if (repoObject instanceof TransMeta) {
transMeta = (TransMeta) repoObject;
}
Trans t = new Trans(transMeta);
t.setInternalKettleVariables(transMeta);
IComponentDescriptor documentDescriptor = new MetaverseComponentDescriptor(document.getStringID(), DictionaryConst.NODE_TYPE_TRANS, new Namespace(descriptor.getLogicalId()), descriptor.getContext());
// Create a metaverse node and start filling in details
IMetaverseNode node = metaverseObjectFactory.createNodeObject(document.getNamespace(), transMeta.getName(), DictionaryConst.NODE_TYPE_TRANS);
node.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DOCUMENT);
// pull out the standard fields
String description = transMeta.getDescription();
if (description != null) {
node.setProperty(DictionaryConst.PROPERTY_DESCRIPTION, description);
}
String extendedDescription = transMeta.getExtendedDescription();
if (extendedDescription != null) {
node.setProperty("extendedDescription", extendedDescription);
}
Date createdDate = transMeta.getCreatedDate();
if (createdDate != null) {
node.setProperty(DictionaryConst.PROPERTY_CREATED, Long.toString(createdDate.getTime()));
}
String createdUser = transMeta.getCreatedUser();
if (createdUser != null) {
node.setProperty(DictionaryConst.PROPERTY_CREATED_BY, createdUser);
}
Date lastModifiedDate = transMeta.getModifiedDate();
if (lastModifiedDate != null) {
node.setProperty(DictionaryConst.PROPERTY_LAST_MODIFIED, Long.toString(lastModifiedDate.getTime()));
}
String lastModifiedUser = transMeta.getModifiedUser();
if (lastModifiedUser != null) {
node.setProperty(DictionaryConst.PROPERTY_LAST_MODIFIED_BY, lastModifiedUser);
}
String version = transMeta.getTransversion();
if (version != null) {
node.setProperty(DictionaryConst.PROPERTY_ARTIFACT_VERSION, version);
}
String status = Messages.getString("INFO.JobOrTrans.Status_" + Integer.toString(transMeta.getTransstatus()));
if (status != null && !status.startsWith("!")) {
node.setProperty(DictionaryConst.PROPERTY_STATUS, status);
}
node.setProperty(DictionaryConst.PROPERTY_PATH, document.getProperty(DictionaryConst.PROPERTY_PATH));
String[] parameters = transMeta.listParameters();
if (parameters != null) {
for (String parameter : parameters) {
try {
// Determine parameter properties and add them to a map, then the map to the list
String defaultParameterValue = transMeta.getParameterDefault(parameter);
String parameterValue = transMeta.getParameterValue(parameter);
String parameterDescription = transMeta.getParameterDescription(parameter);
PropertiesHolder paramProperties = new PropertiesHolder();
paramProperties.setProperty("defaultValue", defaultParameterValue);
paramProperties.setProperty("value", parameterValue);
paramProperties.setProperty("description", parameterDescription);
node.setProperty("parameter_" + parameter, paramProperties.toString());
} catch (UnknownParamException upe) {
// This shouldn't happen as we're using the list provided by the meta
throw new MetaverseAnalyzerException(upe);
}
}
}
// handle the step
for (int stepNr = 0; stepNr < transMeta.nrSteps(); stepNr++) {
StepMeta stepMeta = transMeta.getStep(stepNr);
try {
if (stepMeta != null) {
if (stepMeta.getParentTransMeta() == null) {
stepMeta.setParentTransMeta(transMeta);
}
IMetaverseNode stepNode = null;
IComponentDescriptor stepDescriptor = new MetaverseComponentDescriptor(stepMeta.getName(), DictionaryConst.NODE_TYPE_TRANS_STEP, node, documentDescriptor.getContext());
Set<IStepAnalyzer> stepAnalyzers = getStepAnalyzers(stepMeta);
if (stepAnalyzers != null && !stepAnalyzers.isEmpty()) {
for (IStepAnalyzer stepAnalyzer : stepAnalyzers) {
stepAnalyzer.setMetaverseBuilder(metaverseBuilder);
stepNode = (IMetaverseNode) stepAnalyzer.analyze(stepDescriptor, getBaseStepMetaFromStepMeta(stepMeta));
}
} else {
GenericStepMetaAnalyzer defaultStepAnalyzer = new GenericStepMetaAnalyzer();
defaultStepAnalyzer.setMetaverseBuilder(metaverseBuilder);
stepNode = defaultStepAnalyzer.analyze(stepDescriptor, getBaseStepMetaFromStepMeta(stepMeta));
}
if (stepNode != null) {
metaverseBuilder.addLink(node, DictionaryConst.LINK_CONTAINS, stepNode);
}
}
} catch (Throwable mae) {
// Don't throw an exception, just log and carry on
log.warn(Messages.getString("ERROR.ErrorDuringAnalysis", stepMeta.getName(), Const.NVL(mae.getLocalizedMessage(), "Unspecified")));
log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), mae);
}
}
// Model the hops between steps
int numHops = transMeta.nrTransHops();
for (int i = 0; i < numHops; i++) {
TransHopMeta hop = transMeta.getTransHop(i);
StepMeta fromStep = hop.getFromStep();
StepMeta toStep = hop.getToStep();
INamespace childNs = new Namespace(node.getLogicalId());
// process legitimate hops
if (fromStep != null && toStep != null) {
IMetaverseNode fromStepNode = metaverseObjectFactory.createNodeObject(childNs, fromStep.getName(), DictionaryConst.NODE_TYPE_TRANS_STEP);
IMetaverseNode toStepNode = metaverseObjectFactory.createNodeObject(childNs, toStep.getName(), DictionaryConst.NODE_TYPE_TRANS_STEP);
// Create and decorate the link between the steps
IMetaverseLink link = metaverseObjectFactory.createLinkObject();
link.setFromNode(fromStepNode);
link.setLabel(DictionaryConst.LINK_HOPSTO);
link.setToNode(toStepNode);
// Is this hop enabled?
link.setProperty(DictionaryConst.PROPERTY_ENABLED, hop.isEnabled());
// Add metadata about the type of stream (target, error, info) it is. Default to "target".
String linkType = "target";
if (fromStep.isSendingErrorRowsToStep(toStep)) {
linkType = "error";
} else {
String[] infoStepnames = toStep.getStepMetaInterface().getStepIOMeta().getInfoStepnames();
// If the "from" step is the source of an info stream to the "to" step, it's an "info" hop
if (Const.indexOfString(fromStep.getName(), infoStepnames) >= 0) {
linkType = "info";
}
}
link.setProperty(DictionaryConst.PROPERTY_TYPE, linkType);
metaverseBuilder.addLink(link);
}
}
metaverseBuilder.addNode(node);
addParentLink(documentDescriptor, node);
return node;
}
use of org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer in project pentaho-metaverse by pentaho.
the class AbstractStepMetaJsonSerializerTest method testGetStepFieldMapper_noProviderAvailable.
@Test
public void testGetStepFieldMapper_noProviderAvailable() throws Exception {
IStepAnalyzerProvider provider = mock(IStepAnalyzerProvider.class);
when(provider.getAnalyzers(any(Set.class))).thenReturn(null);
serializer.setStepAnalyzerProvider(provider);
IFieldLineageMetadataProvider handler = serializer.getFieldLineageMetadataProvider(spyMeta);
assertTrue(handler instanceof GenericStepMetaAnalyzer);
}
Aggregations