Search in sources :

Example 11 with AccessDeniedException

use of java.nio.file.AccessDeniedException in project buck by facebook.

the class ThrowableConsoleEventTest method throwableClassNameIsIncludedInDescription.

@Test
public void throwableClassNameIsIncludedInDescription() {
    ThrowableConsoleEvent event = new ThrowableConsoleEvent(new AccessDeniedException("somefile"), "message");
    assertTrue(event.getMessage().contains("AccessDeniedException"));
}
Also used : AccessDeniedException(java.nio.file.AccessDeniedException) Test(org.junit.Test)

Example 12 with AccessDeniedException

use of java.nio.file.AccessDeniedException in project hadoop by apache.

the class ITestS3AAWSCredentialsProvider method testBadCredentials.

@Test
public void testBadCredentials() throws Exception {
    Configuration conf = new Configuration();
    conf.set(AWS_CREDENTIALS_PROVIDER, BadCredentialsProvider.class.getName());
    try {
        createFailingFS(conf);
    } catch (AccessDeniedException e) {
    // expected
    }
}
Also used : AccessDeniedException(java.nio.file.AccessDeniedException) Configuration(org.apache.hadoop.conf.Configuration) Test(org.junit.Test)

Example 13 with AccessDeniedException

use of java.nio.file.AccessDeniedException in project hadoop by apache.

the class LogCLIHelpers method getOwnerForAppIdOrNull.

@Private
@VisibleForTesting
public static /**
   * Return the owner for a given AppId
   * @param remoteRootLogDir
   * @param appId
   * @param bestGuess
   * @param conf
   * @return the owner or null
   * @throws IOException
   */
String getOwnerForAppIdOrNull(ApplicationId appId, String bestGuess, Configuration conf) throws IOException {
    Path remoteRootLogDir = new Path(conf.get(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR));
    String suffix = LogAggregationUtils.getRemoteNodeLogDirSuffix(conf);
    Path fullPath = LogAggregationUtils.getRemoteAppLogDir(remoteRootLogDir, appId, bestGuess, suffix);
    FileContext fc = FileContext.getFileContext(remoteRootLogDir.toUri(), conf);
    String pathAccess = fullPath.toString();
    try {
        if (fc.util().exists(fullPath)) {
            return bestGuess;
        }
        Path toMatch = LogAggregationUtils.getRemoteAppLogDir(remoteRootLogDir, appId, "*", suffix);
        pathAccess = toMatch.toString();
        FileStatus[] matching = fc.util().globStatus(toMatch);
        if (matching == null || matching.length != 1) {
            return null;
        }
        //fetch the user from the full path /app-logs/user[/suffix]/app_id
        Path parent = matching[0].getPath().getParent();
        //skip the suffix too
        if (suffix != null && !StringUtils.isEmpty(suffix)) {
            parent = parent.getParent();
        }
        return parent.getName();
    } catch (AccessControlException | AccessDeniedException ex) {
        logDirNoAccessPermission(pathAccess, bestGuess, ex.getMessage());
        return null;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AccessDeniedException(java.nio.file.AccessDeniedException) FileStatus(org.apache.hadoop.fs.FileStatus) AccessControlException(org.apache.hadoop.security.AccessControlException) FileContext(org.apache.hadoop.fs.FileContext) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Example 14 with AccessDeniedException

use of java.nio.file.AccessDeniedException in project neo4j by neo4j.

the class LoaderTest method shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsNotWritable.

@Test
public void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsNotWritable() throws IOException, IncorrectFormat {
    assumeFalse("We haven't found a way to reliably tests permissions on Windows", SystemUtils.IS_OS_WINDOWS);
    Path archive = testDirectory.file("the-archive.dump").toPath();
    Path destination = testDirectory.directory("subdir/the-destination").toPath();
    Files.createDirectories(destination.getParent());
    try (Closeable ignored = withPermissions(destination.getParent(), emptySet())) {
        new Loader().load(archive, destination);
        fail("Expected an exception");
    } catch (AccessDeniedException e) {
        assertEquals(destination.getParent().toString(), e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) AccessDeniedException(java.nio.file.AccessDeniedException) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 15 with AccessDeniedException

use of java.nio.file.AccessDeniedException in project beam by apache.

the class GcsUtil method createBucket.

@VisibleForTesting
void createBucket(String projectId, Bucket bucket, BackOff backoff, Sleeper sleeper) throws IOException {
    Storage.Buckets.Insert insertBucket = storageClient.buckets().insert(projectId, bucket);
    insertBucket.setPredefinedAcl("projectPrivate");
    insertBucket.setPredefinedDefaultObjectAcl("projectPrivate");
    try {
        ResilientOperation.retry(ResilientOperation.getGoogleRequestCallable(insertBucket), backoff, new RetryDeterminer<IOException>() {

            @Override
            public boolean shouldRetry(IOException e) {
                if (errorExtractor.itemAlreadyExists(e) || errorExtractor.accessDenied(e)) {
                    return false;
                }
                return RetryDeterminer.SOCKET_ERRORS.shouldRetry(e);
            }
        }, IOException.class, sleeper);
        return;
    } catch (GoogleJsonResponseException e) {
        if (errorExtractor.accessDenied(e)) {
            throw new AccessDeniedException(bucket.getName(), null, e.getMessage());
        }
        if (errorExtractor.itemAlreadyExists(e)) {
            throw new FileAlreadyExistsException(bucket.getName(), null, e.getMessage());
        }
        throw e;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException(String.format("Error while attempting to create bucket gs://%s for rproject %s", bucket.getName(), projectId), e);
    }
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) AccessDeniedException(java.nio.file.AccessDeniedException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

AccessDeniedException (java.nio.file.AccessDeniedException)16 Test (org.junit.Test)6 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)5 IOException (java.io.IOException)4 NoSuchFileException (java.nio.file.NoSuchFileException)4 Path (java.nio.file.Path)4 EOFException (java.io.EOFException)3 FileNotFoundException (java.io.FileNotFoundException)3 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)3 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)3 FileSystemException (java.nio.file.FileSystemException)3 FileSystemLoopException (java.nio.file.FileSystemLoopException)3 NotDirectoryException (java.nio.file.NotDirectoryException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Closeable (java.io.Closeable)2 Configuration (org.apache.hadoop.conf.Configuration)2 Path (org.apache.hadoop.fs.Path)2 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)2 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)2 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)2