Search in sources :

Example 31 with FileSystemOptions

use of org.apache.commons.vfs2.FileSystemOptions in project pentaho-kettle by pentaho.

the class KettleVFS method buildFsOptions.

private static FileSystemOptions buildFsOptions(VariableSpace varSpace, FileSystemOptions sourceOptions, String vfsFilename, String scheme) throws IOException {
    if (varSpace == null || vfsFilename == null) {
        // We cannot extract settings from a non-existant variable space
        return null;
    }
    IKettleFileSystemConfigBuilder configBuilder = KettleFileSystemConfigBuilderFactory.getConfigBuilder(varSpace, scheme);
    FileSystemOptions fsOptions = (sourceOptions == null) ? new FileSystemOptions() : sourceOptions;
    String[] varList = varSpace.listVariables();
    for (String var : varList) {
        if (var.equalsIgnoreCase(CONNECTION) && varSpace.getVariable(var) != null) {
            FileSystemOptions fileSystemOptions = VFSHelper.getOpts(vfsFilename, varSpace.getVariable(var));
            if (fileSystemOptions != null) {
                return fileSystemOptions;
            }
        }
        if (var.startsWith("vfs.")) {
            String param = configBuilder.parseParameterName(var, scheme);
            String varScheme = KettleGenericFileSystemConfigBuilder.extractScheme(var);
            if (param != null) {
                if (varScheme == null || varScheme.equals("sftp") || varScheme.equals(scheme)) {
                    configBuilder.setParameter(fsOptions, param, varSpace.getVariable(var), var, vfsFilename);
                }
            } else {
                throw new IOException("FileSystemConfigBuilder could not parse parameter: " + var);
            }
        }
    }
    return fsOptions;
}
Also used : IKettleFileSystemConfigBuilder(org.pentaho.di.core.vfs.configuration.IKettleFileSystemConfigBuilder) IOException(java.io.IOException) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 32 with FileSystemOptions

use of org.apache.commons.vfs2.FileSystemOptions in project pentaho-kettle by pentaho.

the class KettleSftpFileSystemConfigBuilderTest method recognizesAndSetsUserHomeDirProperty.

@Test
public void recognizesAndSetsUserHomeDirProperty() throws Exception {
    final String fullName = Const.VFS_USER_DIR_IS_ROOT;
    final String name = fullName.substring("vfs.sftp.".length());
    final String vfsInternalName = SftpFileSystemConfigBuilder.class.getName() + ".USER_DIR_IS_ROOT";
    final FileSystemOptions opts = new FileSystemOptions();
    KettleSftpFileSystemConfigBuilder builder = KettleSftpFileSystemConfigBuilder.getInstance();
    builder.setParameter(opts, name, "true", fullName, "sftp://fake-url:22");
    Method getOption = ReflectionUtils.findMethod(opts.getClass(), "getOption", Class.class, String.class);
    getOption.setAccessible(true);
    Object value = ReflectionUtils.invokeMethod(getOption, opts, builder.getConfigClass(), vfsInternalName);
    assertEquals(true, value);
}
Also used : SftpFileSystemConfigBuilder(org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder) Method(java.lang.reflect.Method) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test)

Example 33 with FileSystemOptions

use of org.apache.commons.vfs2.FileSystemOptions in project pentaho-kettle by pentaho.

the class KettleSftpFileSystemConfigBuilderTest method recognizesAndSetsIdentityKeyFile.

@Test
public void recognizesAndSetsIdentityKeyFile() throws Exception {
    File tempFile = File.createTempFile("KettleSftpFileSystemConfigBuilderTest", ".tmp");
    tempFile.deleteOnExit();
    final String fullName = "vfs.sftp.identity";
    final String name = fullName.substring("vfs.sftp.".length());
    final String vfsInternalName = SftpFileSystemConfigBuilder.class.getName() + ".IDENTITIES";
    final FileSystemOptions opts = new FileSystemOptions();
    KettleSftpFileSystemConfigBuilder builder = KettleSftpFileSystemConfigBuilder.getInstance();
    builder.setParameter(opts, name, tempFile.getAbsolutePath(), fullName, "sftp://fake-url:22");
    Method getOption = ReflectionUtils.findMethod(opts.getClass(), "getOption", Class.class, String.class);
    getOption.setAccessible(true);
    Object value = ReflectionUtils.invokeMethod(getOption, opts, builder.getConfigClass(), vfsInternalName);
    assertEquals(IdentityInfo[].class, value.getClass());
    assertEquals(tempFile.getAbsolutePath(), ((IdentityInfo[]) value)[0].getPrivateKey().getAbsolutePath());
}
Also used : IdentityInfo(org.apache.commons.vfs2.provider.sftp.IdentityInfo) SftpFileSystemConfigBuilder(org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder) Method(java.lang.reflect.Method) File(java.io.File) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test)

Example 34 with FileSystemOptions

use of org.apache.commons.vfs2.FileSystemOptions in project pentaho-metaverse by pentaho.

the class VfsLineageCollector method listArtifacts.

@Override
public List<String> listArtifacts(final String startingDate, final String endingDate) throws IllegalArgumentException {
    List<String> paths = new ArrayList<>();
    try {
        FileSystemOptions opts = new FileSystemOptions();
        FileObject lineageRootFolder = KettleVFS.getFileObject(getOutputFolder(), opts);
        FileSelector dateRangeFilter = new VfsDateRangeFilter(format, startingDate, endingDate);
        FileSelector depthFilter = new FileDepthSelector(1, 256);
        if (lineageRootFolder.exists() && lineageRootFolder.getType() == FileType.FOLDER) {
            // get the folders that come on or after the startingDate
            FileObject[] dayFolders = lineageRootFolder.findFiles(dateRangeFilter);
            for (FileObject dayFolder : dayFolders) {
                FileObject[] listThisFolder = dayFolder.findFiles(depthFilter);
                for (FileObject currentFile : listThisFolder) {
                    if (currentFile.getType() == FileType.FILE) {
                        paths.add(currentFile.getName().getPath());
                    }
                }
            }
        }
        return paths;
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : VfsDateRangeFilter(org.pentaho.metaverse.util.VfsDateRangeFilter) FileSelector(org.apache.commons.vfs2.FileSelector) ArrayList(java.util.ArrayList) FileDepthSelector(org.apache.commons.vfs2.FileDepthSelector) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 35 with FileSystemOptions

use of org.apache.commons.vfs2.FileSystemOptions in project pentaho-metaverse by pentaho.

the class VfsLineageCollector method listArtifactsForFile.

@Override
public List<String> listArtifactsForFile(String pathToArtifact, String startingDate, String endingDate) throws IllegalArgumentException {
    List<String> paths = new ArrayList<>();
    try {
        FileSystemOptions opts = new FileSystemOptions();
        FileObject lineageRootFolder = KettleVFS.getFileObject(getOutputFolder(), opts);
        FileSelector dateRangeFilter = new VfsDateRangeFilter(format, startingDate, endingDate);
        FileSelector depthFilter = new FileDepthSelector(1, 256);
        if (lineageRootFolder.exists() && lineageRootFolder.getType() == FileType.FOLDER) {
            // get all of the date folders of lineage we have
            FileObject[] dayFolders = lineageRootFolder.findFiles(dateRangeFilter);
            for (FileObject dayFolder : dayFolders) {
                FileObject[] listThisFolder = dayFolder.findFiles(depthFilter);
                for (FileObject currentFile : listThisFolder) {
                    FileObject requested = currentFile.resolveFile(pathToArtifact);
                    if (requested.exists() && requested.getType() == FileType.FOLDER) {
                        FileObject[] requestedChildren = requested.getChildren();
                        for (FileObject requestedChild : requestedChildren) {
                            if (requestedChild.getType() == FileType.FILE) {
                                paths.add(requestedChild.getName().getPath());
                            }
                        }
                    }
                }
            }
        }
        return paths;
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : VfsDateRangeFilter(org.pentaho.metaverse.util.VfsDateRangeFilter) FileSelector(org.apache.commons.vfs2.FileSelector) ArrayList(java.util.ArrayList) FileDepthSelector(org.apache.commons.vfs2.FileDepthSelector) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Aggregations

FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)97 FileObject (org.apache.commons.vfs2.FileObject)46 FileSystemException (org.apache.commons.vfs2.FileSystemException)29 Test (org.junit.Test)25 IOException (java.io.IOException)16 FileName (org.apache.commons.vfs2.FileName)16 URL (java.net.URL)13 File (java.io.File)12 GenericFileName (org.apache.commons.vfs2.provider.GenericFileName)12 UserAuthenticationData (org.apache.commons.vfs2.UserAuthenticationData)11 StaticUserAuthenticator (org.apache.commons.vfs2.auth.StaticUserAuthenticator)9 FileSystem (org.apache.commons.vfs2.FileSystem)8 ArrayList (java.util.ArrayList)7 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)7 FileNotFolderException (org.apache.commons.vfs2.FileNotFolderException)6 Test (org.junit.jupiter.api.Test)6 OutputStream (java.io.OutputStream)5 UserAuthenticator (org.apache.commons.vfs2.UserAuthenticator)5 Before (org.junit.Before)5 AmazonS3 (com.amazonaws.services.s3.AmazonS3)4