Search in sources :

Example 1 with GetObjectRequest

use of com.amazonaws.services.s3.model.GetObjectRequest in project zeppelin by apache.

the class S3NotebookRepo method getNote.

private Note getNote(String key) throws IOException {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setPrettyPrinting();
    Gson gson = gsonBuilder.registerTypeAdapter(Date.class, new NotebookImportDeserializer()).create();
    S3Object s3object;
    try {
        s3object = s3client.getObject(new GetObjectRequest(bucketName, key));
    } catch (AmazonClientException ace) {
        throw new IOException("Unable to retrieve object from S3: " + ace, ace);
    }
    Note note;
    try (InputStream ins = s3object.getObjectContent()) {
        String json = IOUtils.toString(ins, conf.getString(ConfVars.ZEPPELIN_ENCODING));
        note = gson.fromJson(json, Note.class);
    }
    for (Paragraph p : note.getParagraphs()) {
        if (p.getStatus() == Status.PENDING || p.getStatus() == Status.RUNNING) {
            p.setStatus(Status.ABORT);
        }
    }
    return note;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) InputStream(java.io.InputStream) AmazonClientException(com.amazonaws.AmazonClientException) Note(org.apache.zeppelin.notebook.Note) Gson(com.google.gson.Gson) S3Object(com.amazonaws.services.s3.model.S3Object) IOException(java.io.IOException) NotebookImportDeserializer(org.apache.zeppelin.notebook.NotebookImportDeserializer) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) Date(java.util.Date) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 2 with GetObjectRequest

use of com.amazonaws.services.s3.model.GetObjectRequest in project elasticsearch by elastic.

the class MockAmazonS3 method getObject.

@Override
public S3Object getObject(GetObjectRequest getObjectRequest) throws AmazonClientException, AmazonServiceException {
    // in ESBlobStoreContainerTestCase.java, the prefix is empty,
    // so the key and blobName are equivalent to each other
    String blobName = getObjectRequest.getKey();
    if (!blobs.containsKey(blobName)) {
        throw new AmazonS3Exception("[" + blobName + "] does not exist.");
    }
    // the HTTP request attribute is irrelevant for reading
    S3ObjectInputStream stream = new S3ObjectInputStream(blobs.get(blobName), null, false);
    S3Object s3Object = new S3Object();
    s3Object.setObjectContent(stream);
    return s3Object;
}
Also used : S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) S3Object(com.amazonaws.services.s3.model.S3Object)

Example 3 with GetObjectRequest

use of com.amazonaws.services.s3.model.GetObjectRequest in project airpal by airbnb.

the class ResultsPreviewResource method getS3Preview.

private Response getS3Preview(URI fileURI, int numLines) {
    val filename = getFilename(fileURI);
    val outputKey = getOutputKey(filename);
    // download ~100 kb (depending on your definition) of the file
    val request = new GetObjectRequest(outputBucket, outputKey).withRange(0, 100 * 1024);
    val object = s3Client.getObject(request);
    ObjectMetadata objectMetadata = object.getObjectMetadata();
    boolean gzip = "gzip".equalsIgnoreCase(objectMetadata.getContentEncoding());
    try (InputStream input = object.getObjectContent()) {
        InputStreamReader reader;
        if (gzip) {
            reader = new InputStreamReader(new GZIPInputStream(input));
        } else {
            reader = new InputStreamReader(input);
        }
        return getPreviewFromCSV(new CSVReader(reader), numLines);
    } catch (IOException e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : lombok.val(lombok.val) GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 4 with GetObjectRequest

use of com.amazonaws.services.s3.model.GetObjectRequest in project XRTB by benmfaul.

the class Configuration method processDirectory.

public void processDirectory(AmazonS3Client s3, ObjectListing listing, String bucket) throws Exception {
    for (S3ObjectSummary objectSummary : listing.getObjectSummaries()) {
        long size = objectSummary.getSize();
        System.out.println("*** Processing S3 " + objectSummary.getKey() + ", size = " + size);
        S3Object object = s3.getObject(new GetObjectRequest(bucket, objectSummary.getKey()));
        String bucketName = object.getBucketName();
        String keyName = object.getKey();
        if (keyName.contains("Darren")) {
            System.out.println("HERE");
        }
        GetObjectTaggingRequest request = new GetObjectTaggingRequest(bucketName, keyName);
        GetObjectTaggingResult result = s3.getObjectTagging(request);
        List<Tag> tags = result.getTagSet();
        String type = null;
        String name = null;
        if (tags.isEmpty()) {
            System.err.println("Error: " + keyName + " has no tags");
        } else {
            for (Tag tag : tags) {
                String key = tag.getKey();
                String value = tag.getValue();
                if (key.equals("type")) {
                    type = value;
                }
                if (key.equals("name")) {
                    name = value;
                }
            }
            if (name == null)
                throw new Exception("Error: " + keyName + " is missing a name tag");
            if (name.contains(" "))
                throw new Exception("Error: " + keyName + " has a name attribute with a space in it");
            if (type == null)
                throw new Exception("Error: " + keyName + " has no type tag");
            if (!name.startsWith("$"))
                name = "$" + name;
            readData(type, name, object, size);
        }
    }
}
Also used : GetObjectTaggingRequest(com.amazonaws.services.s3.model.GetObjectTaggingRequest) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) S3Object(com.amazonaws.services.s3.model.S3Object) GeoTag(com.xrtb.geo.GeoTag) Tag(com.amazonaws.services.s3.model.Tag) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) GetObjectTaggingResult(com.amazonaws.services.s3.model.GetObjectTaggingResult)

Example 5 with GetObjectRequest

use of com.amazonaws.services.s3.model.GetObjectRequest in project YCSB by brianfrankcooper.

the class S3Client method getS3ObjectAndMetadata.

private Map.Entry<S3Object, ObjectMetadata> getS3ObjectAndMetadata(String bucket, String key, SSECustomerKey ssecLocal) {
    GetObjectRequest getObjectRequest;
    GetObjectMetadataRequest getObjectMetadataRequest;
    if (ssecLocal != null) {
        getObjectRequest = new GetObjectRequest(bucket, key).withSSECustomerKey(ssecLocal);
        getObjectMetadataRequest = new GetObjectMetadataRequest(bucket, key).withSSECustomerKey(ssecLocal);
    } else {
        getObjectRequest = new GetObjectRequest(bucket, key);
        getObjectMetadataRequest = new GetObjectMetadataRequest(bucket, key);
    }
    return new AbstractMap.SimpleEntry<>(s3Client.getObject(getObjectRequest), s3Client.getObjectMetadata(getObjectMetadataRequest));
}
Also used : GetObjectMetadataRequest(com.amazonaws.services.s3.model.GetObjectMetadataRequest) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Aggregations

GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)11 S3Object (com.amazonaws.services.s3.model.S3Object)6 InputStream (java.io.InputStream)4 IOException (java.io.IOException)3 AmazonClientException (com.amazonaws.AmazonClientException)2 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)2 lombok.val (lombok.val)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 GetObjectMetadataRequest (com.amazonaws.services.s3.model.GetObjectMetadataRequest)1 GetObjectTaggingRequest (com.amazonaws.services.s3.model.GetObjectTaggingRequest)1 GetObjectTaggingResult (com.amazonaws.services.s3.model.GetObjectTaggingResult)1 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)1 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)1 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)1 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)1 SSECustomerKey (com.amazonaws.services.s3.model.SSECustomerKey)1 Tag (com.amazonaws.services.s3.model.Tag)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1