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