Search in sources :

Example 1 with DefaultFileReplicator

use of org.apache.commons.vfs2.impl.DefaultFileReplicator in project spoofax by metaborg.

the class DefaultFileSystemManagerProvider method get.

@Override
public FileSystemManager get() {
    try {
        final DefaultFileSystemManager manager = new DefaultFileSystemManager();
        manager.setFilesCache(new DefaultFilesCache());
        manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
        final String baseTmpDir = System.getProperty("java.io.tmpdir");
        final File tempDir = new File(baseTmpDir, "vfs_cache" + new Random().nextLong()).getAbsoluteFile();
        final DefaultFileReplicator replicator = new DefaultFileReplicator(tempDir);
        manager.setTemporaryFileStore(replicator);
        manager.setReplicator(replicator);
        addDefaultProvider(manager);
        addProviders(manager);
        setBaseFile(manager);
        manager.init();
        return manager;
    } catch (FileSystemException e) {
        throw new RuntimeException("Cannot initialize resource service: " + e.getMessage(), e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) Random(java.util.Random) DefaultFilesCache(org.apache.commons.vfs2.cache.DefaultFilesCache) DefaultFileReplicator(org.apache.commons.vfs2.impl.DefaultFileReplicator) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) File(java.io.File)

Example 2 with DefaultFileReplicator

use of org.apache.commons.vfs2.impl.DefaultFileReplicator in project spoofax by metaborg.

the class ResourceService method close.

@Override
public void close() throws Exception {
    if (fileSystemManager instanceof DefaultFileSystemManager) {
        final DefaultFileSystemManager defaultFileSystemManager = (DefaultFileSystemManager) fileSystemManager;
        final FileReplicator replicator = defaultFileSystemManager.getReplicator();
        if (replicator instanceof DefaultFileReplicator) {
            final DefaultFileReplicator defaultFileReplicator = (DefaultFileReplicator) replicator;
            defaultFileReplicator.close();
        } else {
            logger.warn("File replicator {} does not support cleaning up generated temporary files", replicator);
        }
    } else {
        logger.warn("File system manager {} does not support cleaning up generated temporary files", fileSystemManager);
    }
}
Also used : DefaultFileReplicator(org.apache.commons.vfs2.impl.DefaultFileReplicator) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileReplicator(org.apache.commons.vfs2.provider.FileReplicator) DefaultFileReplicator(org.apache.commons.vfs2.impl.DefaultFileReplicator)

Example 3 with DefaultFileReplicator

use of org.apache.commons.vfs2.impl.DefaultFileReplicator in project accumulo by apache.

the class AccumuloDFSBase method miniDfsClusterSetup.

@BeforeClass
public static void miniDfsClusterSetup() {
    System.setProperty("java.io.tmpdir", System.getProperty("user.dir") + "/target");
    // System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
    // Logger.getRootLogger().setLevel(Level.ERROR);
    // Put the MiniDFSCluster directory in the target directory
    System.setProperty("test.build.data", "target/build/test/data");
    // Setup HDFS
    conf = new Configuration();
    conf.set("hadoop.security.token.service.use_ip", "true");
    conf.set("dfs.datanode.data.dir.perm", MiniDFSUtil.computeDatanodeDirectoryPermission());
    // 1M blocksize
    conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1024 * 1024);
    try {
        cluster = new MiniDFSCluster.Builder(conf).build();
        cluster.waitClusterUp();
        // We can't assume that the hostname of "localhost" will still be "localhost" after
        // starting up the NameNode. We may get mapped into a FQDN via settings in /etc/hosts.
        HDFS_URI = cluster.getFileSystem().getUri();
    } catch (IOException e) {
        throw new RuntimeException("Error setting up mini cluster", e);
    }
    // Set up the VFS
    vfs = new DefaultFileSystemManager();
    try {
        vfs.setFilesCache(new DefaultFilesCache());
        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 DefaultFileReplicator(new File(System.getProperty("java.io.tmpdir"), "accumulo-vfs-cache-" + System.getProperty("user.name", "nouser"))));
        vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
        vfs.init();
    } catch (FileSystemException e) {
        throw new RuntimeException("Error setting up VFS", e);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HdfsFileProvider(org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileContentInfoFilenameFactory(org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) DefaultFilesCache(org.apache.commons.vfs2.cache.DefaultFilesCache) IOException(java.io.IOException) DefaultFileReplicator(org.apache.commons.vfs2.impl.DefaultFileReplicator) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Aggregations

DefaultFileReplicator (org.apache.commons.vfs2.impl.DefaultFileReplicator)3 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)3 File (java.io.File)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 DefaultFilesCache (org.apache.commons.vfs2.cache.DefaultFilesCache)2 IOException (java.io.IOException)1 Random (java.util.Random)1 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)1 FileContentInfoFilenameFactory (org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory)1 FileReplicator (org.apache.commons.vfs2.provider.FileReplicator)1 HdfsFileProvider (org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider)1 Configuration (org.apache.hadoop.conf.Configuration)1 BeforeClass (org.junit.BeforeClass)1