use of org.apache.commons.vfs2.FileSystemManager in project metron by apache.
the class VFSClassloaderUtil method generateVfs.
/**
* Create a FileSystem manager suitable for our purposes.
* This manager supports files of the following types:
* * res - resource files
* * jar
* * tar
* * bz2
* * tgz
* * zip
* * HDFS
* * FTP
* * HTTP/S
* * file
* @return vfs
* @throws FileSystemException
*/
public static FileSystemManager generateVfs() throws FileSystemException {
DefaultFileSystemManager vfs = new DefaultFileSystemManager();
vfs.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
vfs.addProvider("zip", new org.apache.commons.vfs2.provider.zip.ZipFileProvider());
vfs.addProvider("gz", new org.apache.commons.vfs2.provider.gzip.GzipFileProvider());
vfs.addProvider("ram", new org.apache.commons.vfs2.provider.ram.RamFileProvider());
vfs.addProvider("file", new org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider());
vfs.addProvider("jar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("http", new org.apache.commons.vfs2.provider.http.HttpFileProvider());
vfs.addProvider("https", new org.apache.commons.vfs2.provider.https.HttpsFileProvider());
vfs.addProvider("ftp", new org.apache.commons.vfs2.provider.ftp.FtpFileProvider());
vfs.addProvider("ftps", new org.apache.commons.vfs2.provider.ftps.FtpsFileProvider());
vfs.addProvider("war", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("par", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("ear", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("sar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("ejb3", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
vfs.addProvider("tmp", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
vfs.addProvider("tar", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
vfs.addProvider("tbz2", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
vfs.addProvider("tgz", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
vfs.addProvider("bz2", new org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider());
vfs.addProvider("hdfs", new HdfsFileProvider());
vfs.addExtensionMap("jar", "jar");
vfs.addExtensionMap("zip", "zip");
vfs.addExtensionMap("gz", "gz");
vfs.addExtensionMap("tar", "tar");
vfs.addExtensionMap("tbz2", "tar");
vfs.addExtensionMap("tgz", "tar");
vfs.addExtensionMap("bz2", "bz2");
vfs.addMimeTypeMap("application/x-tar", "tar");
vfs.addMimeTypeMap("application/x-gzip", "gz");
vfs.addMimeTypeMap("application/zip", "zip");
vfs.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
vfs.setFilesCache(new SoftRefFilesCache());
vfs.setReplicator(new UniqueFileReplicator(new File(System.getProperty("java.io.tmpdir"))));
vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
vfs.init();
return vfs;
}
use of org.apache.commons.vfs2.FileSystemManager in project pentaho-kettle by pentaho.
the class GoogleDriveFileObjectTest method testFileObject.
@Test
public void testFileObject() throws Exception {
FileSystemManager manager = mock(FileSystemManager.class);
GoogleDriveFileObject fileObjectMock = mock(GoogleDriveFileObject.class);
when(manager.resolveFile(FOLDER)).thenReturn(fileObjectMock);
when(fileObjectMock.isFolder()).thenReturn(true);
when(fileObjectMock.exists()).thenReturn(true);
when(fileObjectMock.delete()).thenReturn(true);
FileObject fileObject = manager.resolveFile(FOLDER);
fileObject.createFolder();
assertTrue(fileObject.isFolder());
assertTrue(fileObject.exists());
assertTrue(fileObject.delete());
assertNull(fileObject.getChildren());
}
use of org.apache.commons.vfs2.FileSystemManager in project pentaho-kettle by pentaho.
the class RepositoryVfsProvider method registerRepoVFS.
private void registerRepoVFS() {
FileSystemManager fsm = KettleVFS.getInstance().getFileSystemManager();
if (fsm instanceof DefaultFileSystemManager) {
try {
((DefaultFileSystemManager) fsm).addProvider(SCHEME, this);
final Spoon spoon = Spoon.getInstance();
System.out.println();
} catch (Exception ex) {
throw new RuntimeException("Error initialize repo:// VFS", ex);
}
}
}
use of org.apache.commons.vfs2.FileSystemManager in project scheduling by ow2-proactive.
the class TestUserSpace method testUserSpace.
@Test
public void testUserSpace() throws Throwable {
File in = tmpFolder.newFolder("input_space");
String inPath = in.getAbsolutePath();
File out = tmpFolder.newFolder("output_space");
String outPath = out.getAbsolutePath();
FileSystemManager fsManager = VFSFactory.createDefaultFileSystemManager();
Scheduler sched = schedulerHelper.getSchedulerInterface();
String userURI = sched.getUserSpaceURIs().get(0);
assertTrue(userURI.startsWith("file:"));
log("User URI is " + userURI);
String userPath = new File(new URI(userURI)).getAbsolutePath();
FileObject pathReplaceFO = fsManager.resolveFile(userURI + "/" + pathReplaceFile);
if (pathReplaceFO.exists()) {
pathReplaceFO.delete();
}
/**
* Writes inFiles in INPUT
*/
writeFiles(inFiles, inPath);
File testPathRepl = new File(inPath + File.separator + pathReplaceFile);
testPathRepl.createNewFile();
PrintWriter out2 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(testPathRepl))));
out2.print(pathReplaceFile);
out2.close();
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName());
job.setInputSpace(in.toURI().toURL().toString());
job.setOutputSpace(out.toURI().toURL().toString());
JavaTask A = new JavaTask();
A.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
A.setForkEnvironment(new ForkEnvironment());
A.setName("A");
for (String[] file : inFiles) {
A.addInputFiles(file[0], InputAccessMode.TransferFromInputSpace);
A.addOutputFiles(file[0] + ".glob.A", OutputAccessMode.TransferToUserSpace);
}
A.setPreScript(new SimpleScript(scriptA, "groovy"));
job.addTask(A);
JavaTask B = new JavaTask();
B.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
B.setForkEnvironment(new ForkEnvironment());
B.setName("B");
B.addDependence(A);
for (String[] file : inFiles) {
B.addInputFiles(file[0] + ".glob.A", InputAccessMode.TransferFromUserSpace);
B.addOutputFiles(file[0] + ".out", OutputAccessMode.TransferToOutputSpace);
}
B.setPreScript(new SimpleScript(scriptB, "groovy"));
job.addTask(B);
JobId id = sched.submit(job);
schedulerHelper.waitForEventJobFinished(id);
JobResult jr = schedulerHelper.getJobResult(id);
Assert.assertFalse(jr.hadException());
/**
* check: inFiles > IN > LOCAL A > GLOBAL > LOCAL B > OUT
*/
for (String[] inFile : inFiles) {
File f = new File(outPath + File.separator + inFile[0] + ".out");
assertTrue("File does not exist: " + f.getAbsolutePath(), f.exists());
Assert.assertEquals("Original and copied files differ", inFile[1], FileUtils.readFileToString(f));
File inf = new File(inPath + File.separator + inFile[0]);
}
for (String[] file : inFiles) {
FileObject outFile = fsManager.resolveFile(userURI + "/" + file[0] + ".glob.A");
log("Checking existence of " + outFile.getURL());
assertTrue(outFile.getURL() + " exists", outFile.exists());
File outFile2 = new File(userPath, file[0] + ".glob.A");
log("Checking existence of " + outFile2);
assertTrue(outFile2 + " exists", outFile2.exists());
}
}
use of org.apache.commons.vfs2.FileSystemManager in project pentaho-metaverse by pentaho.
the class VfsLineageWriterTest method tearDown.
@After
public void tearDown() throws FileSystemException {
FileSystemManager fsManager = VFS.getManager();
fsManager.resolveFile(BAD_OUTPUT_FOLDER).deleteAll();
fsManager.resolveFile(GOOD_OUTPUT_FOLDER).deleteAll();
}
Aggregations