• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java S3EventNotification类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.amazonaws.services.s3.event.S3EventNotification的典型用法代码示例。如果您正苦于以下问题:Java S3EventNotification类的具体用法?Java S3EventNotification怎么用?Java S3EventNotification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



S3EventNotification类属于com.amazonaws.services.s3.event包,在下文中一共展示了S3EventNotification类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:sherzberg,项目名称:graylog-plugin-s3,代码行数:25,代码来源:S3SNSNotificationParser.java


示例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();
	}
}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:34,代码来源:TestUtils.java


示例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());
}
 
开发者ID:visionarts,项目名称:power-jambda,代码行数:18,代码来源:S3EventExecutorTest.java


示例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());
}
 
开发者ID:visionarts,项目名称:power-jambda,代码行数:18,代码来源:S3EventHandlerTest.java


示例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);
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:25,代码来源:S3HandlerTest.java


示例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);
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:26,代码来源:S3HandlerTest.java


示例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);
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:27,代码来源:HerdJmsMessageListenerTest.java


示例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();
    } 
}
 
开发者ID:taichi,项目名称:sirusi,代码行数:28,代码来源:TestUtils.java


示例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;
}
 
开发者ID:awslabs,项目名称:serverless-cf-analysis,代码行数:31,代码来源:CreateAthenaPartitionsBasedOnS3Event.java


示例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;
}
 
开发者ID:awslabs,项目名称:serverless-cf-analysis,代码行数:29,代码来源:RemoveAthenaPartitionsBasedOnS3Event.java


示例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;
}
 
开发者ID:visionarts,项目名称:power-jambda,代码行数:14,代码来源:S3EventHandler.java


示例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());
}
 
开发者ID:visionarts,项目名称:power-jambda,代码行数:12,代码来源:S3EventExecutorTest.java


示例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);
    }
}
 
开发者ID:visionarts,项目名称:power-jambda,代码行数:8,代码来源:S3EventHandlerTest.java


示例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;
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:8,代码来源:S3HandlerTest.java


示例16: handler

import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Override
public void handler(SNSEvent event, Context context) throws HandlerException {
  if (!initialized) {
    init(context);
  }
  this.source = this.sources.get(0);
  this.inputFiles = new ArrayList<String>(0);

  for (SNSRecord record : event.getRecords()) {
    /*
     * Parse SNS as a S3 notification
     */
    String json = record.getSNS().getMessage();
    S3EventNotification s3Event = S3EventNotification.parseJson(json);

    /*
     * Validate the S3 file matches the regex
     */
    List<S3EventNotificationRecord> toProcess =
        new ArrayList<S3EventNotificationRecord>(s3Event.getRecords());
    for (S3EventNotificationRecord s3Record : s3Event.getRecords()) {
      String s3Path = String.format("s3://%s/%s", s3Record.getS3().getBucket().getName(),
          s3Record.getS3().getObject().getKey());
      try {
        this.source = SourceUtils.getSource(s3Path, this.sources);
      } catch (SourceNotFoundException e) {
        logger.warn("skipping processing " + s3Path);
        toProcess.remove(s3Record);
      }
    }

    if (toProcess.size() == 0) {
      logger.warn("Nothing to process");
      return;
    }

    this.inputFiles.addAll(toProcess.stream().map(m -> {
      return m.getS3().getObject().getKey();
    }).collect(Collectors.toList()));

    this.recordIterator = new S3EventIterator(context, toProcess, s3ClientFactory);

    super.process(context);
  }
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:46,代码来源:SNSS3Handler.java


示例17: handler

import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
public void handler(S3EventNotification event, Context context) throws HandlerException {
  if (!initialized) {
    init(context);
  }

  /*
   * Validate the S3 file matches the regex
   */
  List<S3EventNotificationRecord> toProcess =
      new ArrayList<S3EventNotificationRecord>(event.getRecords());
  for (S3EventNotificationRecord record : event.getRecords()) {
    String s3Path = String.format("s3://%s/%s", record.getS3().getBucket().getName(),
        record.getS3().getObject().getKey());
    try {
      this.source = SourceUtils.getSource(s3Path, this.sources);
    } catch (SourceNotFoundException e) {
      logger.warn("Skipping processing " + s3Path);
      toProcess.remove(record);
    }
  }

  if (toProcess.size() == 0) {
    logger.warn("Nothing to process");
    return;
  }

  this.recordIterator = new S3EventIterator(context, toProcess, s3ClientFactory);

  super.process(context);
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:31,代码来源:S3Handler.java


示例18: testSourceRegexFail

import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Test
public void testSourceRegexFail() throws Throwable {
  BaseHandler.CONFIG_FILE = "/com/nextdoor/bender/handler/config_s3_source.json";

  TestContext ctx = new TestContext();
  ctx.setFunctionName("unittest");
  ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");

  BaseHandler<S3EventNotification> handler = (BaseHandler) getHandler();
  handler.init(ctx);

  handler.handler(getTestEvent("foo", false), ctx);
  assertEquals(0, DummyTransportHelper.BufferedTransporter.output.size());
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:15,代码来源:S3HandlerTest.java


示例19: testSourceRegex

import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
@Test
public void testSourceRegex() throws Throwable {
  BaseHandler.CONFIG_FILE = "/com/nextdoor/bender/handler/config_s3_source.json";

  TestContext ctx = new TestContext();
  ctx.setFunctionName("unittest");
  ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");

  BaseHandler<S3EventNotification> handler = (BaseHandler) getHandler();
  handler.init(ctx);

  handler.handler(getTestEvent(), ctx);
  assertEquals(1, DummyTransportHelper.BufferedTransporter.output.size());
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:15,代码来源:S3HandlerTest.java


示例20: getS3Notification

import com.amazonaws.services.s3.event.S3EventNotification; //导入依赖的package包/类
public static S3EventNotification getS3Notification(String key, String bucket, long size) {
  S3ObjectEntity objEntity = new S3ObjectEntity(key, size, null, null);
  S3BucketEntity bucketEntity = new S3BucketEntity(bucket, null, null);
  S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);

  String timestamp = formatter.print(System.currentTimeMillis());
  S3EventNotificationRecord rec =
      new S3EventNotificationRecord(null, null, null, timestamp, null, null, null, entity, null);

  List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(1);
  notifications.add(rec);

  return new S3EventNotification(notifications);
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:15,代码来源:S3SnsNotifier.java



注:本文中的com.amazonaws.services.s3.event.S3EventNotification类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OnDiskAtomIterator类代码示例发布时间:2022-05-22
下一篇:
Java CQL3Type类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap