Search in sources :

Example 1 with FileBasedHelperException

use of org.apache.gobblin.source.extractor.filebased.FileBasedHelperException in project incubator-gobblin by apache.

the class SftpFsHelper method getFileSize.

@Override
public long getFileSize(String filePath) throws FileBasedHelperException {
    try {
        ChannelSftp channelSftp = getSftpChannel();
        long fileSize = channelSftp.lstat(filePath).getSize();
        channelSftp.disconnect();
        return fileSize;
    } catch (SftpException e) {
        throw new FileBasedHelperException(String.format("Failed to get size for file at path %s due to error %s", filePath, e.getMessage()), e);
    }
}
Also used : ChannelSftp(com.jcraft.jsch.ChannelSftp) FileBasedHelperException(org.apache.gobblin.source.extractor.filebased.FileBasedHelperException) SftpException(com.jcraft.jsch.SftpException)

Example 2 with FileBasedHelperException

use of org.apache.gobblin.source.extractor.filebased.FileBasedHelperException in project incubator-gobblin by apache.

the class SftpFsHelper method ls.

@Override
public List<String> ls(String path) throws FileBasedHelperException {
    try {
        List<String> list = new ArrayList<>();
        ChannelSftp channel = getSftpChannel();
        Vector<LsEntry> vector = channel.ls(path);
        for (LsEntry entry : vector) {
            list.add(entry.getFilename());
        }
        channel.disconnect();
        return list;
    } catch (SftpException e) {
        throw new FileBasedHelperException("Cannot execute ls command on sftp connection", e);
    }
}
Also used : ChannelSftp(com.jcraft.jsch.ChannelSftp) FileBasedHelperException(org.apache.gobblin.source.extractor.filebased.FileBasedHelperException) SftpException(com.jcraft.jsch.SftpException) ArrayList(java.util.ArrayList) LsEntry(com.jcraft.jsch.ChannelSftp.LsEntry)

Example 3 with FileBasedHelperException

use of org.apache.gobblin.source.extractor.filebased.FileBasedHelperException in project incubator-gobblin by apache.

the class SftpLightWeightFileSystem method listStatus.

@Override
public FileStatus[] listStatus(Path path) throws IOException {
    try {
        List<String> fileNames = this.fsHelper.ls(HadoopUtils.toUriPath(path));
        List<FileStatus> status = Lists.newArrayListWithCapacity(fileNames.size());
        for (String name : fileNames) {
            Path filePath = new Path(name);
            if (VALID_PATH_FILTER.accept(filePath)) {
                status.add(getFileStatus(new Path(path, filePath)));
            }
        }
        return status.toArray(new FileStatus[status.size()]);
    } catch (FileBasedHelperException e) {
        throw new IOException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileBasedHelperException(org.apache.gobblin.source.extractor.filebased.FileBasedHelperException) IOException(java.io.IOException)

Example 4 with FileBasedHelperException

use of org.apache.gobblin.source.extractor.filebased.FileBasedHelperException in project incubator-gobblin by apache.

the class GoogleDriveFsHelper method getFileSize.

@Override
public long getFileSize(String fileId) throws FileBasedHelperException {
    Preconditions.checkNotNull(fileId, "fileId is required");
    Path p = new Path(fileId);
    try {
        FileStatus status = fileSystem.getFileStatus(p);
        return status.getLen();
    } catch (IOException e) {
        throw new FileBasedHelperException("Failed to get metadata on " + fileId, e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileBasedHelperException(org.apache.gobblin.source.extractor.filebased.FileBasedHelperException) IOException(java.io.IOException)

Example 5 with FileBasedHelperException

use of org.apache.gobblin.source.extractor.filebased.FileBasedHelperException in project incubator-gobblin by apache.

the class GoogleDriveFsHelper method ls.

/**
 * List files under folder ID recursively. Folder won't be included in the result. If there's no files under folder ID, it returns empty list.
 * If folder ID is not defined, it will provide files under root directory.
 * {@inheritDoc}
 * @see org.apache.gobblin.source.extractor.filebased.FileBasedHelper#ls(java.lang.String)
 */
@Override
public List<String> ls(String folderId) throws FileBasedHelperException {
    List<String> result = new ArrayList<>();
    if (StringUtils.isEmpty(folderId)) {
        folderId = "/";
    }
    Path p = new Path(folderId);
    FileStatus[] statusList = null;
    try {
        statusList = fileSystem.listStatus(p);
    } catch (FileNotFoundException e) {
        return result;
    } catch (IOException e) {
        throw new FileBasedHelperException("Falied to list status on path " + p + ", folderID: " + folderId, e);
    }
    for (FileStatus status : statusList) {
        if (status.isDirectory()) {
            result.addAll(ls(GoogleDriveFileSystem.toFileId(status.getPath())));
        } else {
            result.add(GoogleDriveFileSystem.toFileId(status.getPath()));
        }
    }
    return result;
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileBasedHelperException(org.apache.gobblin.source.extractor.filebased.FileBasedHelperException) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

FileBasedHelperException (org.apache.gobblin.source.extractor.filebased.FileBasedHelperException)15 IOException (java.io.IOException)10 Path (org.apache.hadoop.fs.Path)9 FileStatus (org.apache.hadoop.fs.FileStatus)6 ArrayList (java.util.ArrayList)4 ChannelSftp (com.jcraft.jsch.ChannelSftp)3 SftpException (com.jcraft.jsch.SftpException)3 DateTime (org.joda.time.DateTime)2 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)1 JSch (com.jcraft.jsch.JSch)1 JSchException (com.jcraft.jsch.JSchException)1 ProxyHTTP (com.jcraft.jsch.ProxyHTTP)1 UserInfo (com.jcraft.jsch.UserInfo)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 State (org.apache.gobblin.configuration.State)1 AvroFsHelper (org.apache.gobblin.source.extractor.hadoop.AvroFsHelper)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 CompressionCodec (org.apache.hadoop.io.compress.CompressionCodec)1 CompressionCodecFactory (org.apache.hadoop.io.compress.CompressionCodecFactory)1