本文整理汇总了Java中com.amazonaws.services.s3.event.S3EventNotification类的典型用法代码示例。如果您正苦于以下问题:Java S3EventNotification类的具体用法?Java S3EventNotification怎么用?Java S3EventNotification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
S3EventNotification类属于com.amazonaws.services.s3.event包,在下文中一共展示了S3EventNotification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
public List<S3SNSNotification> parse(Message message) {
List<S3SNSNotification> notifications = Lists.newArrayList();
try {
SQSMessage envelope = om.readValue(message.getBody(), SQSMessage.class);
if (envelope.message == null) {
return Collections.emptyList();
}
S3EventNotification s3EventNotification = S3EventNotification.parseJson(envelope.message);
notifications.addAll(s3EventNotification.getRecords().stream().map(record -> new S3SNSNotification(
message.getReceiptHandle(),
record.getS3().getBucket().getName(),
record.getS3().getObject().getUrlDecodedKey()
)).collect(Collectors.toList()));
} catch (Exception e) {
LOG.error("Could not parse SNS notification: " + message.getBody(), e);
throw new RuntimeException("Could not parse SNS notification: " + message.getBody(), e);
}
return notifications;
}
示例2: parse
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
/**
* Helper method that parses a JSON object from a resource on the classpath
* as an instance of the provided type.
*
* @param resource
* the path to the resource (relative to this class)
* @param clazz
* the type to parse the JSON into
*/
public static <T> T parse(String resource, Class<T> clazz)
throws IOException {
InputStream stream = TestUtils.class.getResourceAsStream(resource);
try {
if (clazz == S3Event.class) {
String json = IOUtils.toString(stream);
S3EventNotification event = S3EventNotification.parseJson(json);
@SuppressWarnings("unchecked")
T result = (T) new S3Event(event.getRecords());
return result;
} else if (clazz == SNSEvent.class) {
return snsEventMapper.readValue(stream, clazz);
} else if (clazz == DynamodbEvent.class) {
return dynamodbEventMapper.readValue(stream, clazz);
} else {
return mapper.readValue(stream, clazz);
}
} finally {
stream.close();
}
}
示例3: testS3EventViaSNSEventHandlerSuccessfully
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testS3EventViaSNSEventHandlerSuccessfully() throws Exception {
InputStream input = this.getClass().getClassLoader().getResourceAsStream(S3_VIA_SNS_REQUEST_JSON_TEMPLATE);
new Expectations(S3EventAction.class) {
{
new S3EventAction().handle((EventActionRequest<S3EventNotification>)any, (Context)any);
times = 1;
}
};
Optional<S3EventResult> result = executor.apply(readJson(input), mockContext);
assertEquals(1, result.get().getSuccessItems().size());
assertEquals(0, result.get().getFailureItems().size());
assertEquals(0, result.get().getSkippedItems().size());
}
示例4: testS3EventViaSNSEventHandlerSuccessfully
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testS3EventViaSNSEventHandlerSuccessfully() throws Exception {
InputStream input = this.getClass().getClassLoader().getResourceAsStream(S3_REQUEST_JSON_TEMPLATE);
new Expectations(S3EventAction.class) {
{
new S3EventAction().handle((EventActionRequest<S3EventNotification>)any, (Context)any);
times = 1;
}
};
S3EventResult result = handler.handleRequest(supplyEvent(input), mockContext);
assertEquals(1, result.getSuccessItems().size());
assertEquals(0, result.getFailureItems().size());
assertEquals(0, result.getSkippedItems().size());
}
示例5: getTestEvent
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Override
public S3EventNotification getTestEvent() throws Exception {
/*
* Upload a test resoruce to the mock S3
*/
String payload = IOUtils.toString(
new InputStreamReader(this.getClass().getResourceAsStream("basic_input.log"), "UTF-8"));
this.client.putObject(S3_BUCKET, "basic_input.log", payload);
/*
* Create a S3EventNotification event
*/
S3ObjectEntity objEntity = new S3ObjectEntity("basic_input.log", 1L, null, null);
S3BucketEntity bucketEntity = new S3BucketEntity(S3_BUCKET, null, null);
S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null,
"1970-01-01T00:00:00.000Z", null, null, null, entity, null);
List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(2);
notifications.add(rec);
return new S3EventNotification(notifications);
}
示例6: getTestEvent
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
private S3EventNotification getTestEvent(String bucket, boolean doPut) throws Exception {
/*
* Upload a test resoruce to the mock S3
*/
if (doPut) {
String payload = IOUtils.toString(
new InputStreamReader(this.getClass().getResourceAsStream("basic_input.log"), "UTF-8"));
this.client.putObject(bucket, "basic_input.log", payload);
}
/*
* Create a S3EventNotification event
*/
S3ObjectEntity objEntity = new S3ObjectEntity("basic_input.log", 1L, null, null);
S3BucketEntity bucketEntity = new S3BucketEntity(bucket, null, null);
S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null,
"1970-01-01T00:00:00.000Z", null, null, null, entity, null);
List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(2);
notifications.add(rec);
return new S3EventNotification(notifications);
}
示例7: testS3MessageS3FileNoExists
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Test
public void testS3MessageS3FileNoExists() throws Exception
{
setLogLevel(UploadDownloadHelperServiceImpl.class, LogLevel.OFF);
uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper
.createUploadSingleInitiationRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2,
FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, TARGET_S3_KEY));
String filePath = resultUploadSingleInitiationResponse.getSourceBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath();
S3Entity s3Entity = new S3Entity(null, null, new S3ObjectEntity(filePath, 0L, null, null), null);
List<S3EventNotificationRecord> records = new ArrayList<>();
records.add(new S3EventNotificationRecord(null, null, null, null, null, null, null, s3Entity, null));
S3EventNotification s3EventNotification = new S3EventNotification(records);
setLogLevel(UploadDownloadServiceImpl.class, LogLevel.OFF);
setLogLevel(HerdJmsMessageListener.class, LogLevel.OFF);
// Try to process an S3 JMS message, when source S3 file does not exist.
herdJmsMessageListener.processMessage(jsonHelper.objectToJson(s3EventNotification), null);
}
示例8: parse
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
/**
* Helper method that parses a JSON object from a resource on the classpath
* as an instance of the provided type.
*
* @param resource the path to the resource (relative to this class)
* @param clazz the type to parse the JSON into
*/
public static <T> T parse(String resource, Class<T> clazz)
throws IOException {
InputStream stream = TestUtils.class.getResourceAsStream(resource);
try {
if (clazz == S3Event.class) {
String json = IOUtils.toString(stream);
S3EventNotification event = S3EventNotification.parseJson(json);
@SuppressWarnings("unchecked")
T result = (T) new S3Event(event.getRecords());
return result;
} else {
return mapper.readValue(stream, clazz);
}
} finally {
stream.close();
}
}
示例9: handleRequest
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Override
public Void handleRequest(S3Event s3Event, Context context) {
Collection<Partition> requiredPartitions = new HashSet<>();
TableService tableService = new TableService();
for (S3EventNotification.S3EventNotificationRecord record : s3Event.getRecords()) {
String bucket = record.getS3().getBucket().getName();
String key = record.getS3().getObject().getKey();
System.out.printf("S3 event [Event: %s, Bucket: %s, Key: %s]%n", record.getEventName(), bucket, key);
S3Object s3Object = new S3Object(bucket, key);
if (s3Object.hasDateTimeKey()) {
requiredPartitions.add(partitionConfig.createPartitionFor(s3Object));
}
}
if (!requiredPartitions.isEmpty()) {
Collection<Partition> missingPartitions = determineMissingPartitions(
partitionConfig.tableName(),
requiredPartitions,
tableService);
tableService.addPartitions(partitionConfig.tableName(), missingPartitions);
}
return null;
}
示例10: handleRequest
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Override
public Void handleRequest(S3Event s3Event, Context context) {
Collection<Partition> partitionsToRemove = new HashSet<>();
TableService tableService = new TableService();
for (S3EventNotification.S3EventNotificationRecord record : s3Event.getRecords()) {
String bucket = record.getS3().getBucket().getName();
String key = record.getS3().getObject().getKey();
System.out.printf("S3 event [Event: %s, Bucket: %s, Key: %s]%n", record.getEventName(), bucket, key);
S3Object s3Object = new S3Object(bucket, key);
if (s3Object.hasDateTimeKey()) {
partitionsToRemove.add(partitionConfig.createPartitionFor(s3Object));
}
}
if (!partitionsToRemove.isEmpty()) {
tableService.removePartitions(
partitionConfig.tableName(),
partitionsToRemove.stream().map(Partition::spec).collect(Collectors.toList()));
}
return null;
}
示例11: handleRequest
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Override
public Void handleRequest(S3Event s3Event, Context context){
Collection<Partition>requiredPartitions = new HashSet<>();
TableService tableService = new TableService();
DynamoDB dynamoDBClient=new DynamoDB(new AmazonDynamoDBClient(new EnvironmentVariableCredentialsProvider()));
for(S3EventNotification.S3EventNotificationRecord record:s3Event.getRecords()){
String bucket=record.getS3().getBucket().getName();
String key=record.getS3().getObject().getKey();
System.out.printf("S3event[Event:%s,Bucket:%s,Key:%s]%n",record.getEventName(),bucket,key);
S3Object s3Object=new S3Object(bucket,key);
if(s3Object.hasDateTimeKey()){
Partition partition = partitionConfig.createPartitionFor(s3Object);
//Check if the partition exists in DynamoDBtable, if not add the partition details to the table, skip otherwise
if (tryAddMissingPartition(partitionConfig.dynamoDBTableName(), dynamoDBClient, partition)) {
requiredPartitions.add(partition);
}
}
}
if(!requiredPartitions.isEmpty()){
tableService.addPartitions(partitionConfig.tableName(),requiredPartitions, true);
}
return null;
}
开发者ID:awslabs,项目名称:serverless-cf-analysis,代码行数:33,代码来源:CreateAthenaPartitionsBasedOnS3EventWithDDB.java
示例12: handleEvent
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Override
protected S3EventResult handleEvent(S3EventNotification event, Context context) {
AwsEventRequest request = readEvent(event);
S3EventResult result = new S3EventResult();
AwsEventResponse res = actionRouterHandle(request, context);
if (res.isSuccessful()) {
result.addSuccessItem(request);
} else {
logger.error("Failed processing S3Event", res.getCause());
result.addFailureItem(request);
}
return result;
}
示例13: testResolveS3EventViaSNSEventSuccessfully
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Test
public void testResolveS3EventViaSNSEventSuccessfully() throws Exception {
InputStream input = this.getClass().getClassLoader().getResourceAsStream(S3_VIA_SNS_REQUEST_JSON_TEMPLATE);
Optional<S3EventNotification> event = executor.resolve(readJson(input));
assertEquals(1, event.get().getRecords().size());
assertEquals("aws:s3", event.get().getRecords().get(0).getEventSource());
assertEquals("us-east-1", event.get().getRecords().get(0).getAwsRegion());
assertEquals("dev-nsmg-logs-temp", event.get().getRecords().get(0).getS3().getBucket().getName());
assertEquals("transformed_sample_logs.json", event.get().getRecords().get(0).getS3().getObject().getKey());
}
示例14: supplyEvent
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
private S3EventNotification supplyEvent(InputStream input) {
try {
return om.readValue(input, S3EventNotification.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例15: getHandler
import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Override
public Handler<S3EventNotification> getHandler() {
S3Handler handler = new S3Handler();
handler.s3ClientFactory = this.clientFactory;
return handler;
}