Package io.fathom.cloud.sftp

Examples of io.fathom.cloud.sftp.RemoteFile


    public boolean hasImage(ImageKey imageId) throws IOException, CloudException {
        return hostFilesystem.hasImage(imageId);
    }

    private RemoteFile getSystemTempDir() {
        return new RemoteFile(new File("/tmp"));
    }
View Full Code Here


        super(sshConfig);
    }

    @Override
    public void copyImageToRootfs(ImageKey imageId, File rootfsPath) throws IOException {
        RemoteFile tar = getImagePath(imageId);

        ShellCommand cmd = ShellCommand.create("/bin/tar");
        cmd.literal("--numeric-owner");
        cmd.literal("-f").arg(tar.getSshPath());
        cmd.literal("-C").arg(rootfsPath);
        cmd.literal("-xz");
        cmd.useSudo();

        SshCommand sshCommand = cmd.withSsh(sshConfig);
View Full Code Here

            try (RemoteTempFile tar = sftp.buildRemoteTemp()) {
                try (OutputStream os = sftp.writeFile(tar.getSshPath(), WriteMode.Overwrite)) {
                    imageData.copyTo(os);
                }

                RemoteFile imageFile = getImagePath(imageId);
                tar.renameTo(imageFile);
            }
        }
    }
View Full Code Here

    @Override
    public MessageQueueWriter getWriter(SshConfig sshConfig, String queue) throws IOException {
        if (queue.startsWith("sftp://")) {
            File path = new File(queue.substring(7));
            return new SftpMessageQueueWriter(sshConfig, new RemoteFile(path));
        } else {
            throw new IllegalArgumentException();
        }
    }
View Full Code Here

                char firstChar = name.charAt(0);
                if (firstChar == '_' || firstChar == '.') {
                    continue;
                }
                byte[] data;
                RemoteFile file = new RemoteFile(queueDir, name);
                try (InputStream is = sftp.open(file.getSshPath())) {
                    data = ByteStreams.toByteArray(is);
                }

                sftp.delete(file.getSshPath());

                return data;
            }
        }
View Full Code Here

    public SftpMessageQueueWriter(SshConfig sshConfig, RemoteFile queueDir) throws IOException {
        this.sshConfig = sshConfig;
        this.queueDir = queueDir;

        this.tmpDir = new RemoteFile(queueDir, "_tmp");
        try (Sftp sftp = buildSftp()) {
            sftp.mkdirs(tmpDir.getSshPath());
        }
    }
View Full Code Here

    @Override
    public void enqueue(byte[] data) throws IOException {
        String name = System.currentTimeMillis() + "_" + UUID.randomUUID().toString();

        try (Sftp sftp = buildSftp()) {
            RemoteFile remoteFile = new RemoteFile(queueDir, name);

            sftp.writeAtomic(remoteFile, data);
        }
    }
View Full Code Here

        super();
        this.sshConfig = sshConfig;
        this.remoteBaseDir = remoteBaseDir;
        this.localCacheDir = localCacheDir;

        this.tmpDir = new RemoteFile(remoteBaseDir, "_tmp");
        mkdirs(tmpDir);

        localCacheDirTmp = new File(localCacheDir, "_tmp");
        IoUtils.mkdirs(localCacheDirTmp);
    }
View Full Code Here

        return new Sftp(sftp, tmpDir);
    }

    @Override
    public BlobData find(ByteString key) throws IOException {
        RemoteFile remoteFile = buildRemoteFile(key);

        File localCache;
        try {
            localCache = buildCacheFile(key, true);
        } catch (IOException e) {
            throw new IOException("Error creating local cache file", e);
        }

        if (localCache.exists()) {
            // TODO: Verify?
            log.debug("Using local cache file: {}", localCache);
        } else {
            try (TempFile localTemp = TempFile.in(this.localCacheDirTmp)) {
                HashCode md5;

                try (Sftp sftp = buildSftp(); InputStream is = sftp.open(remoteFile.getSshPath())) {
                    try (OutputStream os = new FileOutputStream(localTemp.getFile())) {
                        Hasher hasher = Hashing.md5().newHasher();
                        byte[] buffer = new byte[8192];
                        while (true) {
                            int n = is.read(buffer);
View Full Code Here

            if (localCache.exists()) {
                return true;
            }
        }

        RemoteFile remoteFile = buildRemoteFile(key);

        try (Sftp sftp = buildSftp()) {
            return sftp.exists(remoteFile.getSshPath());
        }
    }
View Full Code Here

TOP

Related Classes of io.fathom.cloud.sftp.RemoteFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.