Example usage for org.apache.hadoop.fs Path isAbsoluteAndSchemeAuthorityNull

List of usage examples for org.apache.hadoop.fs Path isAbsoluteAndSchemeAuthorityNull

Introduction

In this page you can find the example usage for org.apache.hadoop.fs Path isAbsoluteAndSchemeAuthorityNull.

Prototype

public boolean isAbsoluteAndSchemeAuthorityNull() 

Source Link

Document

Returns true if the path component (i.e.

Usage

From source file:org.apache.sentry.binding.hive.authz.HiveAuthzBindingHookBase.java

License:Apache License

@VisibleForTesting
static public AccessURI parseURI(String uri, boolean isLocal) throws SemanticException {
    try {//from  w  w w. j a  v a 2  s  . c  o  m
        HiveConf conf = SessionState.get().getConf();
        String warehouseDir = conf.getVar(ConfVars.METASTOREWAREHOUSE);
        Path warehousePath = new Path(warehouseDir);

        // If warehousePath is an absolute path and a scheme is null and authority is null as well,
        // qualified it with default file system scheme and authority.
        if (warehousePath.isAbsoluteAndSchemeAuthorityNull()) {
            URI defaultUri = FileSystem.getDefaultUri(conf);
            warehousePath = warehousePath.makeQualified(defaultUri, warehousePath);
            warehouseDir = warehousePath.toUri().toString();
        }
        return new AccessURI(PathUtils.parseURI(warehouseDir, uri, isLocal));
    } catch (Exception e) {
        throw new SemanticException("Error parsing URI " + uri + ": " + e.getMessage(), e);
    }
}

From source file:org.apache.sentry.binding.hive.HiveAuthzBindingHookBase.java

License:Apache License

@VisibleForTesting
protected static AccessURI parseURI(String uri, boolean isLocal) throws SemanticException {
    try {/*from   w  w  w.  j a v  a  2 s  .  com*/
        HiveConf conf = SessionState.get().getConf();
        String warehouseDir = conf.getVar(ConfVars.METASTOREWAREHOUSE);
        Path warehousePath = new Path(warehouseDir);

        // If warehousePath is an absolute path and a scheme is null and authority is null as well,
        // qualified it with default file system scheme and authority.
        if (warehousePath.isAbsoluteAndSchemeAuthorityNull()) {
            URI defaultUri = FileSystem.getDefaultUri(conf);
            warehousePath = warehousePath.makeQualified(defaultUri, warehousePath);
            warehouseDir = warehousePath.toUri().toString();
        }
        return new AccessURI(PathUtils.parseURI(warehouseDir, uri, isLocal));
    } catch (Exception e) {
        throw new SemanticException("Error parsing URI " + uri + ": " + e.getMessage(), e);
    }
}

From source file:org.apache.sentry.core.common.utils.PathUtils.java

License:Apache License

/**
 * Parse a URI which can be HDFS, S3, SWIFT, WEBHDFS,etc. In either case it
 * should be on the same fs as the warehouse directory.
 *///from ww w.j a  va2  s .c om
public static String parseURI(String warehouseDir, String uri, boolean isLocal) throws URISyntaxException {
    Path warehouseDirPath = new Path(warehouseDir);
    Path uriPath = new Path(uri);

    if (uriPath.isAbsolute()) {
        // Merge warehouseDir and uri only when there is no scheme and authority
        // in uri.
        if (uriPath.isAbsoluteAndSchemeAuthorityNull()) {
            uriPath = uriPath.makeQualified(warehouseDirPath.toUri(), warehouseDirPath);
        }
        String uriScheme = uriPath.toUri().getScheme();
        String uriAuthority = uriPath.toUri().getAuthority();

        if (StringUtils.isEmpty(uriScheme) || isLocal) {
            uriScheme = LOCAL_FILE_SCHEMA;
            uriAuthority = "";
        }

        uriPath = new Path(uriScheme + AUTHORITY_PREFIX + StringUtils.trimToEmpty(uriAuthority)
                + Path.getPathWithoutSchemeAndAuthority(uriPath));
    } else {
        // don't support relative path
        throw new IllegalArgumentException("Invalid URI " + uri + ".");
    }
    return uriPath.toUri().toString();
}

From source file:org.apache.solr.hadoop.ForkedMapReduceIndexerTool.java

License:Apache License

private long addInputFiles(List<Path> inputFiles, List<Path> inputLists, Path fullInputList, Configuration conf)
        throws IOException {

    long numFiles = 0;
    FileSystem fs = fullInputList.getFileSystem(conf);
    FSDataOutputStream out = fs.create(fullInputList);
    try {/*  www  .ja  v  a  2  s . c  o  m*/
        Writer writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));

        for (Path inputFile : inputFiles) {
            FileSystem inputFileFs = inputFile.getFileSystem(conf);
            if (inputFileFs.exists(inputFile)) {
                PathFilter pathFilter = new PathFilter() {
                    @Override
                    public boolean accept(Path path) {
                        return !path.getName().startsWith("."); // ignore "hidden" files and dirs
                    }
                };
                numFiles += addInputFilesRecursively(inputFile, writer, inputFileFs, pathFilter);
            }
        }

        for (Path inputList : inputLists) {
            InputStream in;
            if (inputList.toString().equals("-")) {
                in = System.in;
            } else if (inputList.isAbsoluteAndSchemeAuthorityNull()) {
                in = new BufferedInputStream(new FileInputStream(inputList.toString()));
            } else {
                in = inputList.getFileSystem(conf).open(inputList);
            }
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
                String line;
                while ((line = reader.readLine()) != null) {
                    writer.write(line + "\n");
                    numFiles++;
                }
                reader.close();
            } finally {
                in.close();
            }
        }

        writer.close();
    } finally {
        out.close();
    }
    return numFiles;
}

From source file:org.datacleaner.windows.HdfsUrlChooser.java

License:Open Source License

HdfsUrlChooser(URI uri, final OpenType openType) {
    if (uri != null) {
        if (!HDFS_SCHEME.equals(uri.getScheme())) {
            throw new IllegalArgumentException("Only HDFS allowed");
        }/* w w w  . ja  v  a  2  s.  c  o m*/

        uri = UriBuilder.fromUri(uri).replaceQuery(null).fragment(null).build();
        HdfsUtils.getFileSystemFromUri(uri);
        _currentDirectory = new Path(uri);
    }

    _openType = openType;
    final DCLabel lookInLabel = DCLabel.dark("Look in:");
    final DCComboBox<Path> pathsComboBox = new DCComboBox<>(_directoryComboBoxModel);
    pathsComboBox.setRenderer(new ServerComboBoxRenderer());
    pathsComboBox.setMinimumSize(new Dimension(DEFAULT_WIDTH, 40));
    pathsComboBox.addListener(new DCComboBox.Listener<Path>() {
        @Override
        public void onItemSelected(final Path directory) {
            if (!directory.isAbsoluteAndSchemeAuthorityNull()) {
                _fileSystem = HdfsUtils.getFileSystemFromUri(directory.toUri());
            }
            _currentDirectory = directory;
            ((HdfsDirectoryModel) _fileList.getModel()).updateFileList();
        }
    });
    _fileList = new JList<>(new HdfsDirectoryModel());
    _fileList.setLayoutOrientation(JList.VERTICAL_WRAP);
    _fileList.setPreferredSize(new Dimension(DEFAULT_WIDTH, 350));
    _fileList.setBorder(WidgetUtils.BORDER_THIN);
    _fileList.setCellRenderer(new HdfsFileListRenderer());
    _fileList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(final MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                selectOrBrowsePath(false);
            }
        }

        @Override
        public void mousePressed(final MouseEvent e) {
            tryPopup(e);
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            tryPopup(e);
        }

        private void tryPopup(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                _fileList.setSelectedIndex(_fileList.locationToIndex(e.getPoint()));
                final JPopupMenu popupMenu = new JPopupMenu();
                if (_fileList.getModel().getElementAt(_fileList.getSelectedIndex()).isDirectory()) {
                    final JMenuItem browseMenuItem = new JMenuItem("Browse");
                    browseMenuItem.addActionListener(e1 -> selectOrBrowsePath(false));
                    popupMenu.add(browseMenuItem);
                }

                final JMenuItem selectMenuItem = new JMenuItem("Select");
                selectMenuItem.addActionListener(e1 -> selectOrBrowsePath(true));
                popupMenu.add(selectMenuItem);
                popupMenu.show(_fileList, e.getX(), e.getY());
            }
        }
    });
    setLayout(new BorderLayout());
    final DCPanel topPanel = new DCPanel();
    topPanel.setLayout(new GridBagLayout());
    topPanel.setPreferredSize(new Dimension(DEFAULT_WIDTH, 40));
    WidgetUtils.addToGridBag(lookInLabel, topPanel, 0, 0, 1, 1, GridBagConstraints.WEST, 5);
    WidgetUtils.addToGridBag(pathsComboBox, topPanel, 1, 0, 100, 40, GridBagConstraints.WEST, 5, 1, 1,
            GridBagConstraints.HORIZONTAL);

    add(topPanel, BorderLayout.NORTH);

    final DCPanel panel = DCPanel.around(_fileList);
    panel.setBorder(WidgetUtils.BORDER_EMPTY);
    add(panel, BorderLayout.CENTER);
}