Search in sources :

Example 1 with JobAnalyzer

use of org.pentaho.metaverse.analyzer.kettle.JobAnalyzer in project pentaho-metaverse by pentaho.

the class JobExecutorStepAnalyzer method customAnalyze.

@Override
protected void customAnalyze(JobExecutorMeta meta, IMetaverseNode node) throws MetaverseAnalyzerException {
    String jobPath = meta.getFileName();
    JobMeta subJobMeta = null;
    Repository repo = parentTransMeta.getRepository();
    MetaverseAnalyzerException exception = null;
    switch(meta.getSpecificationMethod()) {
        case FILENAME:
            jobPath = parentTransMeta.environmentSubstitute(meta.getFileName());
            try {
                String normalized = KettleAnalyzerUtil.normalizeFilePath(jobPath);
                subJobMeta = getSubJobMeta(parentTransMeta, normalized);
                jobPath = normalized;
            } catch (Exception e) {
                exception = new MetaverseAnalyzerException(Messages.getString("ERROR.SubJobNotFoundInParentTrans", jobPath, parentTransMeta.toString()), e);
            }
            break;
        case REPOSITORY_BY_NAME:
            if (repo != null) {
                String dir = parentTransMeta.environmentSubstitute(meta.getDirectoryPath());
                String file = parentTransMeta.environmentSubstitute(meta.getJobName());
                try {
                    RepositoryDirectoryInterface rdi = repo.findDirectory(dir);
                    subJobMeta = repo.loadJob(file, rdi, null, null);
                    String filename = subJobMeta.getFilename() == null ? subJobMeta.toString() : subJobMeta.getFilename();
                    jobPath = filename + "." + subJobMeta.getDefaultExtension();
                } catch (KettleException e) {
                    exception = new MetaverseAnalyzerException(Messages.getString("ERROR.SubJobNotFoundInParentTrans", file, parentTransMeta.toString()), e);
                }
            } else {
                exception = new MetaverseAnalyzerException(Messages.getString("ERROR.MissingConnectionForTransSubJob", parentTransMeta.toString()));
            }
            break;
        case REPOSITORY_BY_REFERENCE:
            if (repo != null) {
                try {
                    subJobMeta = repo.loadJob(meta.getJobObjectId(), null);
                    String filename = subJobMeta.getFilename() == null ? subJobMeta.toString() : subJobMeta.getFilename();
                    jobPath = filename + "." + subJobMeta.getDefaultExtension();
                } catch (KettleException e) {
                    exception = new MetaverseAnalyzerException(Messages.getString("ERROR.SubJobNotFoundInParentTrans", (meta.getJobObjectId() == null ? "N/A" : meta.getJobObjectId().toString()), parentTransMeta.toString()), e);
                }
            } else {
                exception = new MetaverseAnalyzerException(Messages.getString("ERROR.MissingConnectionForTransSubJob", parentTransMeta.toString()));
            }
            break;
    }
    rootNode.setProperty(DictionaryConst.PROPERTY_PATH, jobPath);
    if (exception != null) {
        throw exception;
    }
    subJobMeta.copyVariablesFrom(parentTransMeta);
    subJobMeta.setFilename(jobPath);
    // analyze the sub trans?
    IComponentDescriptor ds = new MetaverseComponentDescriptor(subJobMeta.getName(), DictionaryConst.NODE_TYPE_JOB, descriptor.getNamespace().getParentNamespace());
    IMetaverseNode jobNode = createNodeFromDescriptor(ds);
    jobNode.setProperty(DictionaryConst.PROPERTY_NAMESPACE, ds.getNamespaceId());
    jobNode.setProperty(DictionaryConst.PROPERTY_PATH, jobPath);
    jobNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DOCUMENT);
    metaverseBuilder.addLink(node, DictionaryConst.LINK_EXECUTES, jobNode);
    final IDocument subTransDocument = KettleAnalyzerUtil.buildDocument(getMetaverseBuilder(), subJobMeta, jobPath, getDocumentDescriptor().getNamespace());
    node.setProperty(JOB_TO_EXECUTE, jobPath);
    if (StringUtils.isNotEmpty(meta.getExecutionResultTargetStep())) {
        node.setProperty(EXECUTION_RESULTS_TARGET, meta.getExecutionResultTargetStep());
    }
    if (StringUtils.isNotEmpty(meta.getResultFilesTargetStep())) {
        node.setProperty(RESULT_FILES_TARGET, meta.getResultFilesTargetStep());
    }
    // pull in the sub-job lineage only if the consolidateGraphs flag is set to true
    if (MetaverseConfig.consolidateSubGraphs()) {
        final IComponentDescriptor subtransDocumentDescriptor = new MetaverseComponentDescriptor(subTransDocument.getStringID(), DictionaryConst.NODE_TYPE_TRANS, getDocumentDescriptor().getNamespace(), getDescriptor().getContext());
        // analyze the sub-job
        final JobAnalyzer jobAnalyzer = new JobAnalyzer();
        jobAnalyzer.setJobEntryAnalyzerProvider(PentahoSystem.get(IJobEntryAnalyzerProvider.class));
        jobAnalyzer.setMetaverseBuilder(getMetaverseBuilder());
        jobAnalyzer.analyze(subtransDocumentDescriptor, subJobMeta, jobNode, jobPath);
        connectToSubJobOutputFields(meta, subJobMeta, jobNode, descriptor);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) FileNotFoundException(java.io.FileNotFoundException) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor) Repository(org.pentaho.di.repository.Repository) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) JobAnalyzer(org.pentaho.metaverse.analyzer.kettle.JobAnalyzer) IJobEntryAnalyzerProvider(org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryAnalyzerProvider) IDocument(org.pentaho.metaverse.api.IDocument)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1 JobMeta (org.pentaho.di.job.JobMeta)1 Repository (org.pentaho.di.repository.Repository)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1 JobAnalyzer (org.pentaho.metaverse.analyzer.kettle.JobAnalyzer)1 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)1 IDocument (org.pentaho.metaverse.api.IDocument)1 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)1 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)1 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)1 IJobEntryAnalyzerProvider (org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryAnalyzerProvider)1