Java Code Examples for org.apache.hadoop.fs.FileSystem.access()

The following are Jave code examples for showing how to use access() of the org.apache.hadoop.fs.FileSystem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: hadoop   File:   Source Code and License Vote up 6 votes
 * Asserts that permission is granted to the given fs/user for the given
 * directory.
 * @param fs FileSystem to check
 * @param user UserGroupInformation owner of fs
 * @param pathToCheck Path directory to check
 * @throws Exception if there is an unexpected error
private static void assertDirPermissionGranted(FileSystem fs,
    UserGroupInformation user, Path pathToCheck) throws Exception {
  try {
    fs.access(pathToCheck, FsAction.READ);
  } catch (AccessControlException e) {
    fail("expected permission granted for user " + user + ", path = " +
Example 2
Project: dataSqueeze   File:   Source Code and License Vote up 5 votes
 * {@inheritDoc}
public CompactionResponse compact() throws Exception {
    Validate.notNull(criteria, "Criteria cannot be null");"In place compaction requested for input path {}", criteria.getSourcePath());
    final URI uri = URI.create(criteria.getSourcePath());
    final FileSystem fileSystem = FileSystem.get(uri, configuration);

    final String tempCompactedLocation = TEMP_OUTPUT_LOCATION + "compacted-" + UUID.randomUUID().toString() + "/";
    final Path tempLocation = new Path(TEMP_OUTPUT_LOCATION + UUID.randomUUID().toString() + "/");
    try {
        fileSystem.access(new Path(criteria.getSourcePath()), FsAction.WRITE);
    } catch (AccessControlException e) {
        throw new IllegalStateException(String.format("User does not have permissions to perform move/delete for location %s", criteria.getSourcePath()));
    // Perform normal compaction from Source --> TempTargetLocation"Performing Normal Compaction from Source {} to Temp Target {}", criteria.getSourcePath(), tempCompactedLocation);
    final CompactionCriteria compactionCriteria = new CompactionCriteria(criteria.getSourcePath(), tempCompactedLocation, criteria.getThresholdInBytes());
    final CompactionManager compactionManager = new CompactionManagerImpl(configuration, compactionCriteria);
    final CompactionResponse response = compactionManager.compact();"Moving files from input path {} to temp path {}", criteria.getSourcePath(), tempLocation.toString());
    fileSystem.rename(new Path(criteria.getSourcePath()), tempLocation);"Moving compacted files from temp compacted path {} to final location {}", tempCompactedLocation, criteria.getSourcePath());
    fileSystem.rename(new Path(tempCompactedLocation), new Path(criteria.getSourcePath()));
    return response;