Search in sources :

Example 81 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project hadoop by apache.

the class S3AFileSystem method getFileStatus.

/**
   * Return a file status object that represents the path.
   * @param f The path we want information from
   * @return a FileStatus object
   * @throws java.io.FileNotFoundException when the path does not exist;
   * @throws IOException on other problems.
   */
public S3AFileStatus getFileStatus(final Path f) throws IOException {
    incrementStatistic(INVOCATION_GET_FILE_STATUS);
    final Path path = qualify(f);
    String key = pathToKey(path);
    LOG.debug("Getting path status for {}  ({})", path, key);
    if (!key.isEmpty()) {
        try {
            ObjectMetadata meta = getObjectMetadata(key);
            if (objectRepresentsDirectory(key, meta.getContentLength())) {
                LOG.debug("Found exact file: fake directory");
                return new S3AFileStatus(true, path, username);
            } else {
                LOG.debug("Found exact file: normal file");
                return new S3AFileStatus(meta.getContentLength(), dateToLong(meta.getLastModified()), path, getDefaultBlockSize(path), username);
            }
        } catch (AmazonServiceException e) {
            if (e.getStatusCode() != 404) {
                throw translateException("getFileStatus", path, e);
            }
        } catch (AmazonClientException e) {
            throw translateException("getFileStatus", path, e);
        }
        // Necessary?
        if (!key.endsWith("/")) {
            String newKey = key + "/";
            try {
                ObjectMetadata meta = getObjectMetadata(newKey);
                if (objectRepresentsDirectory(newKey, meta.getContentLength())) {
                    LOG.debug("Found file (with /): fake directory");
                    return new S3AFileStatus(true, path, username);
                } else {
                    LOG.warn("Found file (with /): real file? should not happen: {}", key);
                    return new S3AFileStatus(meta.getContentLength(), dateToLong(meta.getLastModified()), path, getDefaultBlockSize(path), username);
                }
            } catch (AmazonServiceException e) {
                if (e.getStatusCode() != 404) {
                    throw translateException("getFileStatus", newKey, e);
                }
            } catch (AmazonClientException e) {
                throw translateException("getFileStatus", newKey, e);
            }
        }
    }
    try {
        key = maybeAddTrailingSlash(key);
        ListObjectsRequest request = new ListObjectsRequest();
        request.setBucketName(bucket);
        request.setPrefix(key);
        request.setDelimiter("/");
        request.setMaxKeys(1);
        ObjectListing objects = listObjects(request);
        if (!objects.getCommonPrefixes().isEmpty() || !objects.getObjectSummaries().isEmpty()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found path as directory (with /): {}/{}", objects.getCommonPrefixes().size(), objects.getObjectSummaries().size());
                for (S3ObjectSummary summary : objects.getObjectSummaries()) {
                    LOG.debug("Summary: {} {}", summary.getKey(), summary.getSize());
                }
                for (String prefix : objects.getCommonPrefixes()) {
                    LOG.debug("Prefix: {}", prefix);
                }
            }
            return new S3AFileStatus(false, path, username);
        } else if (key.isEmpty()) {
            LOG.debug("Found root directory");
            return new S3AFileStatus(true, path, username);
        }
    } catch (AmazonServiceException e) {
        if (e.getStatusCode() != 404) {
            throw translateException("getFileStatus", key, e);
        }
    } catch (AmazonClientException e) {
        throw translateException("getFileStatus", key, e);
    }
    LOG.debug("Not Found: {}", path);
    throw new FileNotFoundException("No such file or directory: " + path);
}
Also used : Path(org.apache.hadoop.fs.Path) ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) FileNotFoundException(java.io.FileNotFoundException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 82 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project hadoop by apache.

the class S3AFileSystem method initMultipartUploads.

private void initMultipartUploads(Configuration conf) throws IOException {
    boolean purgeExistingMultipart = conf.getBoolean(PURGE_EXISTING_MULTIPART, DEFAULT_PURGE_EXISTING_MULTIPART);
    long purgeExistingMultipartAge = longOption(conf, PURGE_EXISTING_MULTIPART_AGE, DEFAULT_PURGE_EXISTING_MULTIPART_AGE, 0);
    if (purgeExistingMultipart) {
        Date purgeBefore = new Date(new Date().getTime() - purgeExistingMultipartAge * 1000);
        try {
            transfers.abortMultipartUploads(bucket, purgeBefore);
        } catch (AmazonServiceException e) {
            if (e.getStatusCode() == 403) {
                instrumentation.errorIgnored();
                LOG.debug("Failed to purging multipart uploads against {}," + " FS may be read only", bucket, e);
            } else {
                throw translateException("purging multipart uploads", bucket, e);
            }
        }
    }
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) Date(java.util.Date)

Example 83 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.

the class CreateTableCompositeKey method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    CreateTable <table>\n\n" + "Where:\n" + "    table - the table to create.\n\n" + "Example:\n" + "    CreateTable GreetingsTable\n";
    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    /* Read the name from command args */
    String table_name = args[0];
    System.out.format("Creating table %s\n with a composite primary key:\n");
    System.out.format("* Language - partition key\n");
    System.out.format("* Greeting - sort key\n");
    CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition("Language", ScalarAttributeType.S), new AttributeDefinition("Greeting", ScalarAttributeType.S)).withKeySchema(new KeySchemaElement("Language", KeyType.HASH), new KeySchemaElement("Greeting", KeyType.RANGE)).withProvisionedThroughput(new ProvisionedThroughput(new Long(10), new Long(10))).withTableName(table_name);
    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
    try {
        CreateTableResult result = ddb.createTable(request);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) CreateTableResult(com.amazonaws.services.dynamodbv2.model.CreateTableResult)

Example 84 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.

the class XferMgrProgress method uploadDirWithSubprogress.

public static void uploadDirWithSubprogress(String dir_path, String bucket_name, String key_prefix, boolean recursive, boolean pause) {
    System.out.println("directory: " + dir_path + (recursive ? " (recursive)" : "") + (pause ? " (pause)" : ""));
    TransferManager xfer_mgr = new TransferManager();
    try {
        MultipleFileUpload multi_upload = xfer_mgr.uploadDirectory(bucket_name, key_prefix, new File(dir_path), recursive);
        // loop with Transfer.isDone()
        XferMgrProgress.showMultiUploadProgress(multi_upload);
        // or block with Transfer.waitForCompletion()
        XferMgrProgress.waitForCompletion(multi_upload);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    xfer_mgr.shutdownNow();
}
Also used : TransferManager(com.amazonaws.services.s3.transfer.TransferManager) AmazonServiceException(com.amazonaws.AmazonServiceException) File(java.io.File) MultipleFileUpload(com.amazonaws.services.s3.transfer.MultipleFileUpload)

Example 85 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.

the class XferMgrUpload method uploadFile.

public static void uploadFile(String file_path, String bucket_name, String key_prefix, boolean pause) {
    System.out.println("file: " + file_path + (pause ? " (pause)" : ""));
    String key_name = null;
    if (key_prefix != null) {
        key_name = key_prefix + '/' + file_path;
    } else {
        key_name = file_path;
    }
    File f = new File(file_path);
    TransferManager xfer_mgr = new TransferManager();
    try {
        Upload xfer = xfer_mgr.upload(bucket_name, key_name, f);
        // loop with Transfer.isDone()
        XferMgrProgress.showTransferProgress(xfer);
        //  or block with Transfer.waitForCompletion()
        XferMgrProgress.waitForCompletion(xfer);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    xfer_mgr.shutdownNow();
}
Also used : TransferManager(com.amazonaws.services.s3.transfer.TransferManager) AmazonServiceException(com.amazonaws.AmazonServiceException) Upload(com.amazonaws.services.s3.transfer.Upload) MultipleFileUpload(com.amazonaws.services.s3.transfer.MultipleFileUpload) File(java.io.File)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)109 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)21 AmazonS3 (com.amazonaws.services.s3.AmazonS3)15 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)15 AmazonClientException (com.amazonaws.AmazonClientException)13 IOException (java.io.IOException)12 Collection (java.util.Collection)12 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)11 File (java.io.File)10 Message (org.apache.camel.Message)10 ArrayList (java.util.ArrayList)8 S3Object (com.amazonaws.services.s3.model.S3Object)7 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)7 FileNotFoundException (java.io.FileNotFoundException)7 Copy (com.amazonaws.services.s3.transfer.Copy)6 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)5 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)5 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)5 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)4