@Override public void close() throws IOException { closeCurrentReader(); }
public void handler(S3EventNotification event, Context context) throws HandlerException { if (!initialized) { init(context); S3HandlerConfig handlerConfig = (S3HandlerConfig) this.config.getHandlerConfig(); this.logTrigger = handlerConfig.getLogS3Trigger(); new S3EventIterator(new LambdaContext(context), toProcess, s3ClientFactory);
@Override public void onException(Exception e) { /* * Always close the iterator to prevent connection leaking */ try { if (this.recordIterator != null) { this.recordIterator.close(); } } catch (IOException e1) { logger.error("unable to close record iterator", e); } if (this.config == null || this.config.getHandlerConfig() == null) { return; } /* * Notify SNS topic */ SNSS3HandlerConfig handlerConfig = (SNSS3HandlerConfig) this.config.getHandlerConfig(); if (handlerConfig.getSnsNotificationArn() != null) { AmazonSNSClient snsClient = this.snsClientFactory.newInstance(); snsClient.publish(handlerConfig.getSnsNotificationArn(), this.inputFiles.stream().map(Object::toString).collect(Collectors.joining(",")), "SNSS3Handler Failed"); } }
private S3Wrapper(final InternalEvent internal) { S3InternalEvent s3Event = ((S3InternalEvent) internal); this.s3Key = s3Event.getS3Key(); this.s3Bucket = s3Event.getS3Bucket(); this.s3KeyVersion = s3Event.getS3KeyVersion(); this.functionName = internal.getCtx().getContext().getFunctionName(); this.functionVersion = internal.getCtx().getContext().getFunctionVersion(); this.processingTime = System.currentTimeMillis(); this.timestamp = internal.getEventTime(); this.processingDelay = processingTime - timestamp; this.sha1Hash = internal.getEventSha1Hash(); if (internal.getEventObj() != null) { this.payload = internal.getEventObj().getPayload(); } else { this.payload = null; } }
@Override public void handler(SNSEvent event, Context context) throws HandlerException { if (!initialized) { init(context); SNSS3HandlerConfig handlerConfig = (SNSS3HandlerConfig) this.config.getHandlerConfig(); this.logTrigger = handlerConfig.getLogSnsTrigger(); new S3EventIterator(new LambdaContext(context), toProcess, s3ClientFactory);
@Override public InternalEvent next() { updateCursor(); /* * Wrap reading next row in retry logic. This is because there is intermittent socket timeouts * when reading from S3 that cause the function to hang/fail. */ Callable<String> callable = () -> { return this.lineIterator.next(); }; String nextRow; try { CallResults<Object> results = new CallExecutor(this.config).execute(callable); nextRow = (String) results.getResult(); } catch (RetriesExhaustedException ree) { throw new RuntimeException(ree.getCallResults().getLastExceptionThatCausedRetry()); } catch (UnexpectedException ue) { throw ue; } /* * Construct the internal event */ return new S3InternalEvent(nextRow, this.context, this.arrivalTime, currentS3Entity.getObject().getKey(), currentS3Entity.getBucket().getName(), currentS3Entity.getObject().getVersionId()); }
private S3Wrapper(final InternalEvent internal) { S3InternalEvent s3Event = ((S3InternalEvent) internal); this.s3Key = s3Event.getS3Key(); this.s3Bucket = s3Event.getS3Bucket(); this.s3KeyVersion = s3Event.getS3KeyVersion(); this.functionName = internal.getCtx().getContext().getFunctionName(); this.functionVersion = internal.getCtx().getContext().getFunctionVersion(); this.processingTime = System.currentTimeMillis(); this.timestamp = internal.getEventTime(); this.processingDelay = processingTime - timestamp; this.sha1Hash = internal.getEventSha1Hash(); if (internal.getEventObj() != null) { this.payload = internal.getEventObj().getPayload(); } else { this.payload = null; } }
public void handler(S3EventNotification event, Context context) throws HandlerException { if (!initialized) { init(context); S3HandlerConfig handlerConfig = (S3HandlerConfig) this.config.getHandlerConfig(); this.logTrigger = handlerConfig.getLogS3Trigger(); new S3EventIterator(new LambdaContext(context), toProcess, s3ClientFactory);
@Override public void handler(SNSEvent event, Context context) throws HandlerException { if (!initialized) { init(context); SNSS3HandlerConfig handlerConfig = (SNSS3HandlerConfig) this.config.getHandlerConfig(); this.logTrigger = handlerConfig.getLogSnsTrigger(); new S3EventIterator(new LambdaContext(context), toProcess, s3ClientFactory);
@Override public InternalEvent next() { updateCursor(); /* * Wrap reading next row in retry logic. This is because there is intermittent socket timeouts * when reading from S3 that cause the function to hang/fail. */ Callable<String> callable = () -> { return this.lineIterator.next(); }; String nextRow; try { CallResults<Object> results = new CallExecutor(this.config).execute(callable); nextRow = (String) results.getResult(); } catch (RetriesExhaustedException ree) { throw new RuntimeException(ree.getCallResults().getLastExceptionThatCausedRetry()); } catch (UnexpectedException ue) { throw ue; } /* * Construct the internal event */ return new S3InternalEvent(nextRow, this.context, this.arrivalTime, currentS3Entity.getObject().getKey(), currentS3Entity.getBucket().getName(), currentS3Entity.getObject().getVersionId()); }
@Override public void close() throws IOException { closeCurrentReader(); }
@Override public void onException(Exception e) { /* * Always close the iterator to prevent connection leaking */ try { if (this.recordIterator != null) { this.recordIterator.close(); } } catch (IOException e1) { logger.error("unable to close record iterator", e); } if (this.config == null || this.config.getHandlerConfig() == null) { return; } /* * Notify SNS topic */ SNSS3HandlerConfig handlerConfig = (SNSS3HandlerConfig) this.config.getHandlerConfig(); if (handlerConfig.getSnsNotificationArn() != null) { AmazonSNSClient snsClient = this.snsClientFactory.newInstance(); snsClient.publish(handlerConfig.getSnsNotificationArn(), this.inputFiles.stream().map(Object::toString).collect(Collectors.joining(",")), "SNSS3Handler Failed"); } }
@Override public boolean hasNext() { if (this.currentIndex < this.records.size()) { return true; } /* * Wrap has next row in retry logic. This is because there is intermittent socket timeouts when * reading from S3 that cause the function to hang/fail. */ Callable<Boolean> callable = () -> { return this.lineIterator.hasNext(); }; boolean hasNext; try { CallResults<Object> results = new CallExecutor(this.config).execute(callable); hasNext = (boolean) results.getResult(); } catch (RetriesExhaustedException ree) { throw new RuntimeException(ree.getCallResults().getLastExceptionThatCausedRetry()); } catch (UnexpectedException ue) { throw ue; } /* * If there are no lines then the reader from which the lines came from should be closed. */ if (!hasNext) { closeCurrentReader(); } return hasNext; }
@Override public boolean hasNext() { if (this.currentIndex < this.records.size()) { return true; } /* * Wrap has next row in retry logic. This is because there is intermittent socket timeouts when * reading from S3 that cause the function to hang/fail. */ Callable<Boolean> callable = () -> { return this.lineIterator.hasNext(); }; boolean hasNext; try { CallResults<Object> results = new CallExecutor(this.config).execute(callable); hasNext = (boolean) results.getResult(); } catch (RetriesExhaustedException ree) { throw new RuntimeException(ree.getCallResults().getLastExceptionThatCausedRetry()); } catch (UnexpectedException ue) { throw ue; } /* * If there are no lines then the reader from which the lines came from should be closed. */ if (!hasNext) { closeCurrentReader(); } return hasNext; }