Search in sources :

Example 36 with FileSystemManager

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;
}
Also used : HdfsFileProvider(org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider) UniqueFileReplicator(org.apache.accumulo.start.classloader.vfs.UniqueFileReplicator) FileContentInfoFilenameFactory(org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) File(java.io.File)

Example 37 with FileSystemManager

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());
}
Also used : GoogleDriveFileObject(org.pentaho.googledrive.vfs.GoogleDriveFileObject) GoogleDriveFileObject(org.pentaho.googledrive.vfs.GoogleDriveFileObject) FileObject(org.apache.commons.vfs2.FileObject) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) Test(org.junit.Test)

Example 38 with FileSystemManager

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);
        }
    }
}
Also used : Spoon(org.pentaho.di.ui.spoon.Spoon) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) FileSystemException(org.apache.commons.vfs2.FileSystemException) NotImplementedException(org.apache.commons.lang.NotImplementedException)

Example 39 with FileSystemManager

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());
    }
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) URI(java.net.URI) FileObject(org.apache.commons.vfs2.FileObject) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 40 with FileSystemManager

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();
}
Also used : FileSystemManager(org.apache.commons.vfs2.FileSystemManager) After(org.junit.After)

Aggregations

FileSystemManager (org.apache.commons.vfs2.FileSystemManager)30 FileObject (org.apache.commons.vfs2.FileObject)29 FileSystemException (org.apache.commons.vfs2.FileSystemException)21 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)17 File (java.io.File)12 IOException (java.io.IOException)11 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)7 Test (org.junit.Test)6 FileContent (org.apache.commons.vfs2.FileContent)4 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)4 OutputStream (java.io.OutputStream)3 RepositoryException (javax.jcr.RepositoryException)3 FileName (org.apache.commons.vfs2.FileName)3 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)3 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Map (java.util.Map)2