public static void uploadFile()

in bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/utils/HdfsUtil.java [92:124]


    public static void uploadFile(String user, String localFilePath, String destDir, String destFilename) {
        UserGroupInformation ugi = UserGroupInformation.createRemoteUser(user);
        try {
            ugi.doAs((PrivilegedAction<Void>) () -> {
                try (FileSystem fs = getFileSystem()) {
                    // Create dest dir if not exist
                    Path destDirPath = new Path(destDir);
                    if (!fs.exists(destDirPath)) {
                        log.info("Creating directory [{}] on hdfs", destDirPath);
                        fs.mkdirs(destDirPath);
                    }

                    // upload file
                    String filename = destFilename == null
                            ? localFilePath.substring(localFilePath.lastIndexOf(File.separator) + 1)
                            : destFilename;
                    Path destFilePath = new Path(destDir, filename);
                    if (!fs.exists(destFilePath)) {
                        log.info("Uploading [{}] to hdfs [{}]", localFilePath, destFilePath);
                        fs.copyFromLocalFile(new Path(localFilePath), destFilePath);
                    }
                } catch (Exception e) {
                    log.error("Error while uploading file to hdfs", e);
                    throw new StackException(e);
                }

                return null;
            });
        } catch (Exception e) {
            log.error("Error while uploading file to hdfs", e);
            throw new StackException(e);
        }
    }