Package io.fathom.cloud.sftp

Examples of io.fathom.cloud.sftp.RemoteFile


            SftpBlobStore.Factory blobStoreFactory;
            String store = nodeData.getStore();
            if (store.startsWith("sftp://")) {
                File path = new File(store.substring(7));
                blobStoreFactory = new SftpBlobStore.Factory(sshConfig, new RemoteFile(path), localCacheDir);
            } else {
                throw new IllegalArgumentException();
            }

            String queue = nodeData.getQueue();
View Full Code Here


        super(sshConfig);
    }

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

        List<String> cmd = Lists.newArrayList();
        cmd.add("sudo /sbin/btrfs");
        cmd.add("subvolume");
        cmd.add("snapshot");
        cmd.add(imageVolume.getSshPath().getAbsolutePath());
        cmd.add(rootfsPath.getAbsolutePath());

        SshCommand sshCommand = new SshCommand(sshConfig, Joiner.on(" ").join(cmd));
        sshCommand.run();
    }
View Full Code Here

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

                RemoteFile tempVolume = getImagePath(tempImageId);

                {
                    String cmd = "sudo btrfs subvolume create " + tempVolume.getSshPath();
                    SshCommand sshCommand = new SshCommand(sshConfig, cmd);
                    sshCommand.run();
                }

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

                    SshCommand sshCommand = cmd.withSsh(sshConfig);
                    sshCommand.run();
                }

                RemoteFile imageVolume = getImagePath(imageId);
                {
                    String cmd = "sudo btrfs subvolume snapshot -r " + tempVolume.getSshPath() + " "
                            + imageVolume.getSshPath();
                    SshCommand sshCommand = new SshCommand(sshConfig, cmd);
                    sshCommand.run();
                }
            }
        }
View Full Code Here

            try {
                if (sudo || atomic) {
                    if (atomicTempPath != null) {
                        tempFile = RemoteTempFile.create(sftp, atomicTempPath);
                    } else {
                        tempFile = RemoteTempFile.create(sftp, new RemoteFile(new File("/tmp")));
                    }
                    remoteDest = tempFile.getSshPath();
                }

                try (OutputStream os = sftp.writeFile(remoteDest, WriteMode.Overwrite)) {
                    source.copyTo(os);
                }

                if (chmod != null) {
                    sftp.chmod(remoteDest, chmod);
                }

                // chown and chgrp require CAP_CHOWN / root
                if (chownGroup != null) {
                    sftp.chgrp(remoteDest, chownGroup);
                }

                if (chownUser != null) {
                    sftp.chown(remoteDest, chownUser);
                }

                if (tempFile != null) {
                    if (atomic) {
                        if (sudo) {
                            throw new UnsupportedOperationException("Atomic sudo move not yet implemented");
                        }

                        tempFile.renameTo(new RemoteFile(dest));
                    } else {
                        ShellCommand command = ShellCommand.create("/bin/cp");

                        command.arg(remoteDest);
                        command.arg(dest);
View Full Code Here

        }
        return new Sftp(sftpChannel, tempDir);
    }

    protected RemoteFile getImagePath(ImageKey imageId) {
        RemoteFile imageDir = getImageBaseDir();
        String name = imageId.getKey() + getImageExtension();
        RemoteFile imageFile = new RemoteFile(imageDir, name);
        return imageFile;
    }
View Full Code Here

    protected File getVolumePath(VolumeType volumeType, UUID volumeId) {
        return new File("/volumes/" + volumeType.name().toLowerCase() + "/" + volumeId + "/");
    }

    private RemoteFile getImageBaseDir() {
        RemoteFile imageDir = new RemoteFile(new File("/var/fathomcloud/images"));
        return imageDir;
    }
View Full Code Here

        RemoteFile imageDir = new RemoteFile(new File("/var/fathomcloud/images"));
        return imageDir;
    }

    protected RemoteFile getImageTmpdir() {
        RemoteFile imageDir = getImageBaseDir();
        return new RemoteFile(imageDir, "tmp");
    }
View Full Code Here

    }

    public abstract void uploadImage(ImageKey imageId, BlobData imageData) throws IOException, CloudException;

    public boolean hasImage(ImageKey imageId) throws IOException, CloudException {
        RemoteFile imageFile = getImagePath(imageId);

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

                    return false;
                }
            }

            int mode = 0660;
            sftp.writeAtomic(new RemoteFile(confFile), ByteStreams.asByteSource(data), mode);
        } catch (IOException e) {
            throw new CloudException("Error updating applyd configuration", e);
        }
        return true;
    }
View Full Code Here

            process.Args = args;

            process.Dir = hostFilesystem.getRootFs(containerId).getAbsolutePath();

            String json = new Gson().toJson(process);
            sftp.writeAtomic(new RemoteFile(processFile), json.getBytes(Charsets.UTF_8));
        } catch (IOException e) {
            throw new CloudException("Error starting container", e);
        }
    }
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.