Search in sources :

Example 11 with IExecutionProfile

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

the class LineageWriterTest method setUp.

@Before
public void setUp() throws Exception {
    LineageWriter fslw = new LineageWriter();
    writer = spy(fslw);
    holder = new LineageHolder();
    IExecutionProfile profile = new ExecutionProfile();
    profile.setName("test");
    IExecutionData data = new ExecutionData();
    data.setStartTime(now);
    profile.setExecutionData(data);
    holder.setExecutionProfile(profile);
}
Also used : IExecutionData(org.pentaho.metaverse.api.model.IExecutionData) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) ExecutionProfile(org.pentaho.metaverse.impl.model.ExecutionProfile) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder) IExecutionData(org.pentaho.metaverse.api.model.IExecutionData) ExecutionData(org.pentaho.metaverse.impl.model.ExecutionData) Before(org.junit.Before)

Example 12 with IExecutionProfile

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

the class VfsLineageWriterTest method setUp.

@Before
public void setUp() throws Exception {
    String basePath = new File(".").getCanonicalPath();
    writer = new VfsLineageWriter();
    writer = spy(writer);
    holder = new LineageHolder();
    IExecutionProfile profile = new ExecutionProfile();
    profile.setName("test");
    IExecutionData data = new ExecutionData();
    data.setStartTime(now);
    profile.setExecutionData(data);
    holder.setExecutionProfile(profile);
    BAD_OUTPUT_FOLDER = FilenameUtils.separatorsToSystem("file://" + basePath + BAD_OUTPUT_FOLDER_DEFAULT + random.nextInt());
    GOOD_OUTPUT_FOLDER = FilenameUtils.separatorsToSystem("file://" + basePath + GOOD_OUTPUT_FOLDER_DEFAULT + random.nextInt());
    writer.setOutputFolder(GOOD_OUTPUT_FOLDER);
}
Also used : IExecutionData(org.pentaho.metaverse.api.model.IExecutionData) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) File(java.io.File) ExecutionProfile(org.pentaho.metaverse.impl.model.ExecutionProfile) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder) IExecutionData(org.pentaho.metaverse.api.model.IExecutionData) ExecutionData(org.pentaho.metaverse.impl.model.ExecutionData) Before(org.junit.Before)

Example 13 with IExecutionProfile

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

the class FileSystemLineageWriter method getOutputDirectoryAsFile.

protected File getOutputDirectoryAsFile(LineageHolder holder) {
    File rootFolder = getDateFolder(outputFolder, holder);
    boolean rootFolderExists = rootFolder.exists();
    if (!rootFolderExists) {
        rootFolderExists = rootFolder.mkdirs();
    }
    if (rootFolderExists) {
        IExecutionProfile profile = holder.getExecutionProfile();
        String id = holder.getId() == null ? "unknown_artifact" : holder.getId();
        try {
            // strip off the colon from C:\path\to\file on windows
            if (isWindows()) {
                id = replaceColonInPath(id);
            }
            File folder = new File(rootFolder, id);
            if (!folder.exists()) {
                boolean result = folder.mkdirs();
                if (!result) {
                    log.error("Couldn't create folder: " + folder.getAbsolutePath());
                }
            } else if (folder.isFile()) {
                // must be a folder
                throw new IllegalStateException("Output folder must be a folder, not a file. [" + folder.getAbsolutePath() + "]");
            }
            return folder;
        } catch (Exception e) {
            log.error("Couldn't create output file", e);
            return null;
        }
    }
    return null;
}
Also used : IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 14 with IExecutionProfile

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

the class FileSystemLineageWriter method createOutputStream.

protected OutputStream createOutputStream(LineageHolder holder, String extension) {
    if (holder != null) {
        try {
            IExecutionProfile profile = holder.getExecutionProfile();
            String timestampString = Long.toString(profile.getExecutionData().getStartTime().getTime());
            File destFolder = getOutputDirectoryAsFile(holder);
            String name = Const.NVL(profile.getName(), "unknown");
            File file = new File(destFolder, timestampString + "_" + name + extension);
            try {
                return new FileOutputStream(file);
            } catch (FileNotFoundException e) {
                log.error("Couldn't find file: " + file.getAbsolutePath(), e);
                return null;
            }
        } catch (Exception e) {
            log.error("Couldn't get output stream", e);
            return null;
        }
    } else {
        return null;
    }
}
Also used : IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 15 with IExecutionProfile

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

the class VfsLineageWriter method getDateFolder.

protected FileObject getDateFolder(LineageHolder holder) throws KettleFileException, FileSystemException {
    String dir = "";
    if (holder != null && holder.getExecutionProfile() != null) {
        IExecutionProfile profile = holder.getExecutionProfile();
        dir += dateFolderFormat.format(profile.getExecutionData().getStartTime());
    } else {
        dir += dateFolderFormat.format(new Date());
    }
    FileObject lineageRootFolder = KettleVFS.getFileObject(getOutputFolder());
    FileObject dateFolder = lineageRootFolder.resolveFile(dir);
    return dateFolder;
}
Also used : IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) FileObject(org.apache.commons.vfs2.FileObject) Date(java.util.Date)

Aggregations

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