Search in sources :

Example 21 with MetaverseAnalyzerException

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

the class TransformationAnalyzer method analyze.

@Override
public synchronized IMetaverseNode analyze(final IComponentDescriptor documentDescriptor, final AbstractMeta meta, final IMetaverseNode node, final String documentPath) throws MetaverseAnalyzerException {
    final TransMeta transMeta = (TransMeta) meta;
    Trans t = new Trans(transMeta);
    t.setInternalKettleVariables(transMeta);
    // 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, documentPath);
    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);
            }
        }
    }
    final List<AnalyzerHolder> analyzerHolders = new ArrayList();
    // 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);
                final BaseStepMeta baseStepMeta = getBaseStepMetaFromStepMeta(stepMeta);
                if (stepAnalyzers != null && !stepAnalyzers.isEmpty()) {
                    for (IStepAnalyzer stepAnalyzer : stepAnalyzers) {
                        // transformation execution and does not change while the transformation is being analyzed
                        if (stepAnalyzer instanceof IClonableStepAnalyzer) {
                            stepAnalyzer = ((IClonableStepAnalyzer) stepAnalyzer).cloneAnalyzer();
                            ((IClonableStepAnalyzer) stepAnalyzer).setDocumentAnalyzer(this);
                            ((IClonableStepAnalyzer) stepAnalyzer).setDocumentDescriptor(documentDescriptor);
                            ((IClonableStepAnalyzer) stepAnalyzer).setDocumentPath(documentPath);
                        } else {
                            log.debug(Messages.getString("WARNING.CannotCloneAnalyzer"), stepAnalyzer);
                        }
                        stepAnalyzer.setMetaverseBuilder(metaverseBuilder);
                        stepNode = (IMetaverseNode) stepAnalyzer.analyze(stepDescriptor, baseStepMeta);
                        analyzerHolders.add(new AnalyzerHolder(stepAnalyzer, baseStepMeta, stepNode));
                    }
                } else if ((new AnnotatedClassFields(baseStepMeta)).hasMetaverseAnnotations()) {
                    AnnotationDrivenStepMetaAnalyzer annotationDrivenStepMetaAnalyzer = new AnnotationDrivenStepMetaAnalyzer(baseStepMeta);
                    annotationDrivenStepMetaAnalyzer.setMetaverseBuilder(metaverseBuilder);
                    annotationDrivenStepMetaAnalyzer.setDocumentAnalyzer(this);
                    annotationDrivenStepMetaAnalyzer.setDocumentDescriptor(documentDescriptor);
                    annotationDrivenStepMetaAnalyzer.setDocumentPath(documentPath);
                    stepNode = annotationDrivenStepMetaAnalyzer.analyze(stepDescriptor, baseStepMeta);
                    analyzerHolders.add(new AnalyzerHolder(annotationDrivenStepMetaAnalyzer, baseStepMeta, stepNode));
                } 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);
    // perform any necessary post processing - currently only supported on IClonableStepAnalyzers
    for (final AnalyzerHolder analyzerHolder : analyzerHolders) {
        if (analyzerHolder.getAnalyzer() instanceof IClonableStepAnalyzer) {
            final IClonableStepAnalyzer clonableAnalyzer = (IClonableStepAnalyzer) analyzerHolder.getAnalyzer();
            clonableAnalyzer.postAnalyze(analyzerHolder.getMeta());
        }
    }
    return node;
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) AnnotatedClassFields(org.pentaho.metaverse.api.analyzer.kettle.annotations.AnnotatedClassFields) INamespace(org.pentaho.metaverse.api.INamespace) Trans(org.pentaho.di.trans.Trans) PropertiesHolder(org.pentaho.metaverse.api.PropertiesHolder) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Date(java.util.Date) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor) IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) IClonableStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IClonableStepAnalyzer) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) AnnotationDrivenStepMetaAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.annotations.AnnotationDrivenStepMetaAnalyzer) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) TransHopMeta(org.pentaho.di.trans.TransHopMeta) GenericStepMetaAnalyzer(org.pentaho.metaverse.analyzer.kettle.step.GenericStepMetaAnalyzer)

Example 22 with MetaverseAnalyzerException

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

the class KettleAnalyzerUtil method getSubTransMeta.

public static TransMeta getSubTransMeta(final ISubTransAwareMeta meta) throws MetaverseAnalyzerException {
    final TransMeta parentTransMeta = meta.getParentStepMeta().getParentTransMeta();
    final Repository repo = parentTransMeta.getRepository();
    TransMeta subTransMeta = null;
    switch(meta.getSpecificationMethod()) {
        case FILENAME:
            subTransMeta = getSubTransByFilename(meta, parentTransMeta, repo, subTransMeta);
            break;
        case REPOSITORY_BY_NAME:
            if (repo != null) {
                subTransMeta = getTransMetaFromRepo(meta, parentTransMeta, repo);
            } else {
                throw new MetaverseAnalyzerException(Messages.getString("ERROR.MissingConnectionForTransSubTrans", parentTransMeta.toString()));
            }
            break;
        case REPOSITORY_BY_REFERENCE:
            if (repo != null) {
                try {
                    subTransMeta = repo.loadTransformation(meta.getTransObjectId(), null);
                } catch (KettleException e) {
                    throw new MetaverseAnalyzerException(Messages.getString("ERROR.SubTransNotFoundInParentTrans", (meta.getTransObjectId() == null ? "N/A" : meta.getTransObjectId().toString()), parentTransMeta.toString()), e);
                }
            } else {
                throw new MetaverseAnalyzerException(Messages.getString("ERROR.MissingConnectionForTransSubTrans", parentTransMeta.toString()));
            }
            break;
    }
    subTransMeta.setFilename(KettleAnalyzerUtil.getSubTransMetaPath(meta, subTransMeta));
    return subTransMeta;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) TransMeta(org.pentaho.di.trans.TransMeta)

Example 23 with MetaverseAnalyzerException

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

the class JobEntryAnalyzer method addConnectionNodes.

/**
 * Adds any used database connections to the metaverse using the appropriate analyzer
 *
 * @throws MetaverseAnalyzerException
 */
protected void addConnectionNodes(IComponentDescriptor descriptor) throws MetaverseAnalyzerException {
    if (jobEntryInterface == null) {
        throw new MetaverseAnalyzerException(Messages.getString("ERROR.JobEntryInterface.IsNull"));
    }
    if (connectionAnalyzer != null) {
        List<? extends Object> connections = connectionAnalyzer.getUsedConnections(jobEntryInterface);
        for (Object connection : connections) {
            String connName = null;
            // see if the connection object has a getName method
            try {
                Method getNameMethod = connection.getClass().getMethod("getName", null);
                connName = (String) getNameMethod.invoke(connection, null);
            } catch (Exception e) {
            // doesn't have a getName method, will try to get it from the descriptor later
            }
            try {
                IComponentDescriptor connDescriptor = connectionAnalyzer.buildComponentDescriptor(descriptor, connection);
                connName = connName == null ? descriptor.getName() : connName;
                IMetaverseNode connNode = connectionAnalyzer.analyze(connDescriptor, connection);
                metaverseBuilder.addLink(connNode, DictionaryConst.LINK_DEPENDENCYOF, rootNode);
            } catch (Throwable t) {
                // Don't throw the exception if a DB connection couldn't be analyzed, just log it and move on
                LOGGER.warn(Messages.getString("WARNING.AnalyzingDatabaseConnection", connName), t);
            }
        }
    }
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Method(java.lang.reflect.Method) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException)

Aggregations

MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)23 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)13 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)9 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)9 KettleException (org.pentaho.di.core.exception.KettleException)7 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 TransMeta (org.pentaho.di.trans.TransMeta)6 JobMeta (org.pentaho.di.job.JobMeta)5 INamespace (org.pentaho.metaverse.api.INamespace)5 Namespace (org.pentaho.metaverse.api.Namespace)5 FileNotFoundException (java.io.FileNotFoundException)4 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)4 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)4 Repository (org.pentaho.di.repository.Repository)4 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)4 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)4 HashSet (java.util.HashSet)3 ProgressNullMonitorListener (org.pentaho.di.core.ProgressNullMonitorListener)3 KettleStepException (org.pentaho.di.core.exception.KettleStepException)3 IDocument (org.pentaho.metaverse.api.IDocument)3