Search in sources :

Example 1 with IExecutionProfile

use of org.pentaho.metaverse.api.model.IExecutionProfile in project pentaho-metaverse by pentaho.

the class JobEntryExternalResourceListener method afterExecution.

@Override
public void afterExecution(Job job, JobEntryCopy jobEntryCopy, JobEntryInterface jobEntryInterface, Result result) {
    IExecutionProfile executionProfile = JobLineageHolderMap.getInstance().getLineageHolder(job).getExecutionProfile();
    IExecutionData executionData = executionProfile.getExecutionData();
    // Get input files (aka Resource Dependencies)
    JobMeta jobMeta = job.getJobMeta();
    if (jobMeta != null) {
        List<ResourceReference> dependencies = jobEntryInterface.getResourceDependencies(jobMeta);
        if (dependencies != null) {
            for (ResourceReference ref : dependencies) {
                List<ResourceEntry> resourceEntries = ref.getEntries();
                if (resourceEntries != null) {
                    for (ResourceEntry entry : resourceEntries) {
                        executionData.addExternalResource(jobEntryInterface.getName(), ExternalResourceInfoFactory.createResource(entry, true));
                    }
                }
            }
        }
    }
    // Get output files (aka result files)
    if (result != null) {
        List<ResultFile> resultFiles = result.getResultFilesList();
        if (resultFiles != null) {
            for (ResultFile resultFile : resultFiles) {
                executionData.addExternalResource(jobEntryInterface.getName(), ExternalResourceInfoFactory.createFileResource(resultFile.getFile(), false));
            }
        }
    }
}
Also used : IExecutionData(org.pentaho.metaverse.api.model.IExecutionData) JobMeta(org.pentaho.di.job.JobMeta) ResourceEntry(org.pentaho.di.resource.ResourceEntry) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) ResourceReference(org.pentaho.di.resource.ResourceReference) ResultFile(org.pentaho.di.core.ResultFile)

Example 2 with IExecutionProfile

use of org.pentaho.metaverse.api.model.IExecutionProfile in project pentaho-metaverse by pentaho.

the class TransformationRuntimeExtensionPoint method createLineGraph.

protected void createLineGraph(final Trans trans) {
    log.info(Messages.getString("INFO.WrittingGraphForTransformation", trans.getName()));
    try {
        // Get the current execution profile for this transformation
        LineageHolder holder = TransLineageHolderMap.getInstance().getLineageHolder(trans);
        Future lineageTask = holder.getLineageTask();
        if (lineageTask != null) {
            try {
                lineageTask.get();
            } catch (InterruptedException e) {
            // Do nothing
            } catch (ExecutionException e) {
                log.warn(Messages.getString("ERROR.CouldNotWriteLineageGraph", trans.getName(), Const.NVL(e.getLocalizedMessage(), "Unspecified")));
                log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), e);
            }
        }
        IExecutionProfile executionProfile = holder.getExecutionProfile();
        if (executionProfile == null) {
            // Note that this should NEVER happen, this is purely a preventative measure...
            // Something's wrong here, the transStarted method didn't properly store the execution profile. We should know
            // the same info, so populate a new ExecutionProfile using the current Trans
            // TODO: Beware duplicate profiles!
            executionProfile = new ExecutionProfile();
        }
        populateExecutionProfile(executionProfile, trans);
        removeSensitiveDataFromHolder(holder);
        // Export the lineage info (execution profile, lineage graph, etc.)
        try {
            if (lineageWriter != null && !"none".equals(lineageWriter.getOutputStrategy())) {
                // clearOutput right before the first call to outputXYZ().
                if ("latest".equals(lineageWriter.getOutputStrategy())) {
                    lineageWriter.cleanOutput(holder);
                }
                lineageWriter.outputExecutionProfile(holder);
            }
        } catch (IOException e) {
            log.warn(Messages.getString("ERROR.CouldNotWriteExecutionProfile", trans.getName(), Const.NVL(e.getLocalizedMessage(), "Unspecified")));
            log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), e);
        }
        try {
            if (shouldCreateGraph(trans)) {
                // Add the execution profile information to the lineage graph
                addRuntimeLineageInfo(holder);
                if (lineageWriter != null && !"none".equals(lineageWriter.getOutputStrategy())) {
                    lineageWriter.outputLineageGraph(holder);
                    // lineage has been written - call the appropriate extension point
                    ExtensionPointHandler.callExtensionPoint(trans.getLogChannel(), MetaverseExtensionPoint.TransLineageWriteEnd.id, trans);
                }
            }
        } catch (IOException e) {
            log.warn(Messages.getString("ERROR.CouldNotWriteExecutionProfile", trans.getName(), Const.NVL(e.getLocalizedMessage(), "Unspecified")));
            log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), e);
        }
    } catch (Throwable t) {
        log.warn(Messages.getString("ERROR.ErrorDuringAnalysis", trans.getName(), Const.NVL(t.getLocalizedMessage(), "Unspecified")));
        log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), t);
    }
    // cleanup to prevent unnecessary memory usage - we no longer need this Trans in the TransLineageHolderMap
    TransLineageHolderMap.getInstance().removeLineageHolder(trans);
    log.warn(Messages.getString("INFO.TransformationAnalyzeFinished", trans.getName()));
    logMinimal(Messages.getString("INFO.TransformationAnalyzeFinished", trans.getName()));
}
Also used : IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) Future(java.util.concurrent.Future) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ExecutionProfile(org.pentaho.metaverse.impl.model.ExecutionProfile) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder)

Example 3 with IExecutionProfile

use of org.pentaho.metaverse.api.model.IExecutionProfile in project pentaho-metaverse by pentaho.

the class StepExternalResourceConsumerListener method addExternalResources.

protected void addExternalResources(Collection<IExternalResourceInfo> resources, StepInterface step) {
    if (resources != null) {
        // Add the resources to the execution profile
        IExecutionProfile executionProfile = TransLineageHolderMap.getInstance().getLineageHolder(step.getTrans()).getExecutionProfile();
        if (executionProfile != null) {
            String stepName = step.getStepname();
            Map<String, List<IExternalResourceInfo>> resourceMap = executionProfile.getExecutionData().getExternalResources();
            List<IExternalResourceInfo> externalResources = resourceMap.get(stepName);
            if (externalResources == null) {
                externalResources = new LinkedList<IExternalResourceInfo>();
            }
            externalResources.addAll(resources);
            resourceMap.put(stepName, externalResources);
        }
    }
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) List(java.util.List) LinkedList(java.util.LinkedList)

Example 4 with IExecutionProfile

use of org.pentaho.metaverse.api.model.IExecutionProfile in project pentaho-metaverse by pentaho.

the class FileSystemLineageWriter method getDateFolder.

protected File getDateFolder(String parentDir, LineageHolder holder) {
    String dir = (parentDir == null) ? "" : parentDir + File.separator;
    if (holder != null && holder.getExecutionProfile() != null) {
        IExecutionProfile profile = holder.getExecutionProfile();
        dir += dateFolderFormat.format(profile.getExecutionData().getStartTime());
    } else {
        dir += dateFolderFormat.format(new Date());
    }
    return new File(dir);
}
Also used : IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) File(java.io.File) Date(java.util.Date)

Example 5 with IExecutionProfile

use of org.pentaho.metaverse.api.model.IExecutionProfile in project pentaho-metaverse by pentaho.

the class StepExternalConsumerRowListener method rowReadEvent.

/**
 * Called when rows are read by the step to which this listener is attached
 *
 * @param rowMeta The metadata (value types, e.g.) of the associated row data
 * @param row     An array of Objects corresponding to the row data
 * @see org.pentaho.di.trans.step.RowListener#rowReadEvent(org.pentaho.di.core.row.RowMetaInterface,
 * Object[])
 */
@Override
@SuppressWarnings("unchecked")
public void rowReadEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
    Collection<IExternalResourceInfo> resources = stepExternalResourceConsumer.getResourcesFromRow((BaseStep) step, rowMeta, row);
    if (resources != null) {
        // Add the resources to the execution profile
        IExecutionProfile executionProfile = TransLineageHolderMap.getInstance().getLineageHolder(step.getTrans()).getExecutionProfile();
        if (executionProfile != null) {
            String stepName = step.getStepname();
            Map<String, List<IExternalResourceInfo>> resourceMap = executionProfile.getExecutionData().getExternalResources();
            final List<IExternalResourceInfo> existingResources = resourceMap.get(stepName);
            Set<IExternalResourceInfo> externalResources = existingResources == null ? new HashSet() : new HashSet(resourceMap.get(stepName));
            if (externalResources == null) {
                externalResources = new HashSet();
            }
            // avoid adding duplicates
            externalResources.addAll(new HashSet<>(resources));
            resourceMap.put(stepName, new ArrayList(externalResources));
        }
    }
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)24 LineageHolder (org.pentaho.metaverse.api.model.LineageHolder)9 IExecutionData (org.pentaho.metaverse.api.model.IExecutionData)8 ExecutionProfile (org.pentaho.metaverse.impl.model.ExecutionProfile)8 Test (org.junit.Test)7 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)6 IOException (java.io.IOException)5 File (java.io.File)4 List (java.util.List)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 FileObject (org.apache.commons.vfs2.FileObject)3 Before (org.junit.Before)3 Job (org.pentaho.di.job.Job)3 Trans (org.pentaho.di.trans.Trans)3 ExecutionData (org.pentaho.metaverse.impl.model.ExecutionData)3 FileNotFoundException (java.io.FileNotFoundException)2 LinkedList (java.util.LinkedList)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2