Search in sources :

Example 1 with MetaverseComponentDescriptor

use of org.pentaho.metaverse.api.MetaverseComponentDescriptor 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();
    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) {
                throw new MetaverseAnalyzerException("Sub transformation can not be found - " + jobPath, 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) {
                    throw new MetaverseAnalyzerException("Sub transformation can not be found in repository - " + file, e);
                }
            } else {
                throw new MetaverseAnalyzerException("Not connected to a repository, can't get the transformation");
            }
            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) {
                    throw new MetaverseAnalyzerException("Sub transformation can not be found by reference - " + meta.getJobObjectId(), e);
                }
            } else {
                throw new MetaverseAnalyzerException("Not connected to a repository, can't get the transformation");
            }
            break;
    }
    // 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);
    connectToSubJobOutputFields(meta, subJobMeta, jobNode, descriptor);
    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());
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) Repository(org.pentaho.di.repository.Repository) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) 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)

Example 2 with MetaverseComponentDescriptor

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

the class MongoDbInputStepAnalyzer method createTableNode.

@Override
protected IMetaverseNode createTableNode(IExternalResourceInfo resource) throws MetaverseAnalyzerException {
    MongoDbResourceInfo resourceInfo = (MongoDbResourceInfo) resource;
    // create a node for the collection
    MetaverseComponentDescriptor componentDescriptor = new MetaverseComponentDescriptor(resourceInfo.getCollection(), DictionaryConst.NODE_TYPE_MONGODB_COLLECTION, getConnectionNode(), getDescriptor().getContext());
    // set the namespace to be the id of the connection node.
    IMetaverseNode node = createNodeFromDescriptor(componentDescriptor);
    node.setProperty(DictionaryConst.PROPERTY_NAMESPACE, componentDescriptor.getNamespace().getNamespaceId());
    node.setProperty(COLLECTION, resourceInfo.getCollection());
    node.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DEFAULT);
    return node;
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MongoDbResourceInfo(org.pentaho.metaverse.impl.model.MongoDbResourceInfo) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 3 with MetaverseComponentDescriptor

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

the class TableOutputStepAnalyzer method createTableNode.

@Override
protected IMetaverseNode createTableNode(IExternalResourceInfo resource) throws MetaverseAnalyzerException {
    BaseDatabaseResourceInfo resourceInfo = (BaseDatabaseResourceInfo) resource;
    Object obj = resourceInfo.getAttributes().get(DictionaryConst.PROPERTY_TABLE);
    String tableName = obj == null ? null : obj.toString();
    obj = resourceInfo.getAttributes().get(DictionaryConst.PROPERTY_SCHEMA);
    String schema = obj == null ? null : obj.toString();
    // create a node for the table
    MetaverseComponentDescriptor componentDescriptor = new MetaverseComponentDescriptor(tableName, DictionaryConst.NODE_TYPE_DATA_TABLE, getConnectionNode(), getDescriptor().getContext());
    // set the namespace to be the id of the connection node.
    IMetaverseNode tableNode = createNodeFromDescriptor(componentDescriptor);
    tableNode.setProperty(DictionaryConst.PROPERTY_NAMESPACE, componentDescriptor.getNamespace().getNamespaceId());
    tableNode.setProperty(DictionaryConst.PROPERTY_TABLE, tableName);
    tableNode.setProperty(DictionaryConst.PROPERTY_SCHEMA, schema);
    tableNode.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DB_TABLE);
    return tableNode;
}
Also used : BaseDatabaseResourceInfo(org.pentaho.metaverse.api.model.BaseDatabaseResourceInfo) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 4 with MetaverseComponentDescriptor

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

the class TransExecutorStepAnalyzer method linkResultFieldToSubTrans.

/**
 * Checks to see if the sub trans has any RowToResult steps in it.
 * If so, it will link the fields it outputs to the fields created by this step and are sent to the
 * "target step for output rows".
 *
 * @param streamFieldNode stream field node sent to the step defined as "target step for output rows"
 * @param subTransMeta TransMeta of the transformation to be executed by the TransExecutor step
 * @param subTransNode IMetaverseNode representing the sub-transformation to be executed
 * @param descriptor Descriptor to use as a basis for any nodes created
 */
protected void linkResultFieldToSubTrans(IMetaverseNode streamFieldNode, TransMeta subTransMeta, IMetaverseNode subTransNode, IComponentDescriptor descriptor) {
    List<StepMeta> steps = subTransMeta.getSteps();
    if (!CollectionUtils.isEmpty(steps)) {
        for (StepMeta step : steps) {
            if (step.getStepMetaInterface() instanceof RowsToResultMeta) {
                RowsToResultMeta rtrm = (RowsToResultMeta) step.getStepMetaInterface();
                // Create a new descriptor for the RowsToResult step.
                IComponentDescriptor stepDescriptor = new MetaverseComponentDescriptor(step.getName(), DictionaryConst.NODE_TYPE_TRANS_STEP, subTransNode, descriptor.getContext());
                // Create a new node for the step, to be used as the parent of the the field we want to link to
                IMetaverseNode subTransStepNode = createNodeFromDescriptor(stepDescriptor);
                try {
                    RowMetaInterface rowMetaInterface = rtrm.getParentStepMeta().getParentTransMeta().getStepFields(step);
                    for (int i = 0; i < rowMetaInterface.getFieldNames().length; i++) {
                        String field = rowMetaInterface.getFieldNames()[i];
                        if (streamFieldNode.getName().equals(field)) {
                            // Create the descriptor for the trans field that is derived from the incoming result field
                            IComponentDescriptor stepFieldDescriptor = new MetaverseComponentDescriptor(field, DictionaryConst.NODE_TYPE_TRANS_FIELD, subTransStepNode, descriptor.getContext());
                            // Create the node
                            // IMetaverseNode subTransField = createNodeFromDescriptor( stepFieldDescriptor );
                            IMetaverseNode subTransField = createFieldNode(stepFieldDescriptor, rowMetaInterface.getValueMeta(i), StepAnalyzer.NONE, false);
                            // Add the link
                            metaverseBuilder.addLink(subTransField, DictionaryConst.LINK_DERIVES, streamFieldNode);
                            // no need to keep looking for a match on field name, we just handled it.
                            continue;
                        }
                    }
                } catch (KettleStepException e) {
                    log.warn("Could not get step fields of RowsToResult step in sub transformation - " + subTransMeta.getName(), e);
                }
            }
        }
    }
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) RowsToResultMeta(org.pentaho.di.trans.steps.rowstoresult.RowsToResultMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 5 with MetaverseComponentDescriptor

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

the class TransExecutorStepAnalyzer method linkUsedFieldToSubTrans.

/**
 * Checks to see if the sub trans has any RowFromResult steps in it.
 * If so, it will link the original field node to the fields created in the RowFromResult step in the sub trans
 *
 * @param originalFieldNode incoming stream field node to the TransExecutorStep
 * @param subTransMeta TransMeta of the transformation to be executed by the TransExecutor step
 * @param subTransNode IMetaverseNode representing the sub-transformation to be executed
 * @param descriptor Descriptor to use as a basis
 */
protected void linkUsedFieldToSubTrans(IMetaverseNode originalFieldNode, TransMeta subTransMeta, IMetaverseNode subTransNode, IComponentDescriptor descriptor) {
    List<StepMeta> steps = subTransMeta.getSteps();
    if (!CollectionUtils.isEmpty(steps)) {
        for (StepMeta step : steps) {
            if (step.getStepMetaInterface() instanceof RowsFromResultMeta) {
                RowsFromResultMeta rfrm = (RowsFromResultMeta) step.getStepMetaInterface();
                // Create a new descriptor for the RowsFromResult step.
                IComponentDescriptor stepDescriptor = new MetaverseComponentDescriptor(StepAnalyzer.NONE, DictionaryConst.NODE_TYPE_TRANS_STEP, subTransNode, descriptor.getContext());
                // Create a new node for the step, to be used as the parent of the the field we want to link to
                IMetaverseNode subTransStepNode = createNodeFromDescriptor(stepDescriptor);
                try {
                    RowMetaInterface rowMetaInterface = rfrm.getParentStepMeta().getParentTransMeta().getStepFields(step);
                    for (int i = 0; i < rowMetaInterface.getFieldNames().length; i++) {
                        String field = rowMetaInterface.getFieldNames()[i];
                        if (originalFieldNode.getName().equals(field)) {
                            // Create the descriptor for the trans field that is derived from the incoming result field
                            IComponentDescriptor stepFieldDescriptor = new MetaverseComponentDescriptor(field, DictionaryConst.NODE_TYPE_TRANS_FIELD, subTransStepNode, descriptor.getContext());
                            // Create the node
                            IMetaverseNode subTransField = createFieldNode(stepFieldDescriptor, rowMetaInterface.getValueMeta(i), step.getName(), false);
                            // Add the link
                            metaverseBuilder.addLink(originalFieldNode, DictionaryConst.LINK_DERIVES, subTransField);
                            // no need to keep looking for a match on field name, we just handled it.
                            continue;
                        }
                    }
                } catch (KettleStepException e) {
                    log.warn("Could not get step fields of RowsFromResult step in sub transformation - " + subTransMeta.getName(), e);
                }
            }
        }
    }
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) RowsFromResultMeta(org.pentaho.di.trans.steps.rowsfromresult.RowsFromResultMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Aggregations

MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)36 Before (org.junit.Before)19 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)16 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)9 MetaverseAnalyzerException (org.pentaho.metaverse.api.MetaverseAnalyzerException)8 IMetaverseObjectFactory (org.pentaho.metaverse.api.IMetaverseObjectFactory)6 KettleException (org.pentaho.di.core.exception.KettleException)5 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)5 INamespace (org.pentaho.metaverse.api.INamespace)5 FileNotFoundException (java.io.FileNotFoundException)4 Matchers.anyString (org.mockito.Matchers.anyString)4 KettleMissingPluginsException (org.pentaho.di.core.exception.KettleMissingPluginsException)4 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 JobMeta (org.pentaho.di.job.JobMeta)4 Repository (org.pentaho.di.repository.Repository)4 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)4 Namespace (org.pentaho.metaverse.api.Namespace)4 TransMeta (org.pentaho.di.trans.TransMeta)3 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3