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