@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getApproximateCreationDateTime() == null) ? 0 : getApproximateCreationDateTime().hashCode()); hashCode = prime * hashCode + ((getKeys() == null) ? 0 : getKeys().hashCode()); hashCode = prime * hashCode + ((getNewImage() == null) ? 0 : getNewImage().hashCode()); hashCode = prime * hashCode + ((getOldImage() == null) ? 0 : getOldImage().hashCode()); hashCode = prime * hashCode + ((getSequenceNumber() == null) ? 0 : getSequenceNumber().hashCode()); hashCode = prime * hashCode + ((getSizeBytes() == null) ? 0 : getSizeBytes().hashCode()); hashCode = prime * hashCode + ((getStreamViewType() == null) ? 0 : getStreamViewType().hashCode()); return hashCode; }
/** * <p> * The approximate date and time when the stream record was created, in <a * href="http://www.epochconverter.com/">UNIX epoch time</a> format. * </p> * * @param approximateCreationDateTime * The approximate date and time when the stream record was created, in <a * href="http://www.epochconverter.com/">UNIX epoch time</a> format. * @return Returns a reference to this object so that method calls can be chained together. */ public StreamRecord withApproximateCreationDateTime(java.util.Date approximateCreationDateTime) { setApproximateCreationDateTime(approximateCreationDateTime); return this; }
@Override public void processRecords(List<Record> records, IRecordProcessorCheckpointer checkpointer) { for(Record record : records) { String data = new String(record.getData().array(), Charset.forName("UTF-8")); System.out.println(data); if(record instanceof RecordAdapter) { com.amazonaws.services.dynamodbv2.model.Record streamRecord = ((RecordAdapter) record).getInternalObject(); switch(streamRecord.getEventName()) { case "INSERT" : case "MODIFY" : StreamsAdapterDemoHelper.putItem(dynamoDBClient, tableName, streamRecord.getDynamodb().getNewImage()); break; case "REMOVE" : StreamsAdapterDemoHelper.deleteItem(dynamoDBClient, tableName, streamRecord.getDynamodb().getKeys().get("Id").getN()); } } checkpointCounter += 1; if(checkpointCounter % 10 == 0) { try { checkpointer.checkpoint(); } catch(Exception e) { e.printStackTrace(); } } } }
@Override public void process(final DynamodbStreamRecord record) throws InvalidRecordStructureException { if (record.getEventName().equals(INSERT)) { final Map<String, AttributeValue> recordKeys = record.getDynamodb().getKeys(); if (!recordKeys.containsKey(DEPLOYMENTS_HASH_KEY)) { throw new InvalidRecordStructureException( String.format("Record keys %s do not contain deploymentId", recordKeys)); } final String deploymentId = recordKeys.get(DEPLOYMENTS_HASH_KEY).getS(); log.debug(String.format("DeploymentId %s", deploymentId)); //TODO: get and verify deployment from DDB //TODO: start deployment workflow } else { //TODO: add metrics on modify and remove? } } }
public StreamRecord unmarshall(JsonUnmarshallerContext context) throws Exception { StreamRecord streamRecord = new StreamRecord(); if (context.testExpression("ApproximateCreationDateTime", targetDepth)) { context.nextToken(); streamRecord.setApproximateCreationDateTime(DateJsonUnmarshallerFactory.getInstance("unixTimestamp").unmarshall(context)); streamRecord.setKeys(new MapUnmarshaller<String, AttributeValue>(context.getUnmarshaller(String.class), AttributeValueJsonUnmarshaller .getInstance()).unmarshall(context)); streamRecord.setNewImage(new MapUnmarshaller<String, AttributeValue>(context.getUnmarshaller(String.class), AttributeValueJsonUnmarshaller .getInstance()).unmarshall(context)); streamRecord.setOldImage(new MapUnmarshaller<String, AttributeValue>(context.getUnmarshaller(String.class), AttributeValueJsonUnmarshaller .getInstance()).unmarshall(context)); streamRecord.setSequenceNumber(context.getUnmarshaller(String.class).unmarshall(context)); streamRecord.setSizeBytes(context.getUnmarshaller(Long.class).unmarshall(context)); streamRecord.setStreamViewType(context.getUnmarshaller(String.class).unmarshall(context));
public DynamodbInternalEvent( DynamodbStreamRecord record, String stringKeys, String stringRecord, LambdaContext context) { super(stringRecord, context, record.getDynamodb().getApproximateCreationDateTime().getTime()); super.addMetadata("eventName", record.getEventName()); super.addMetadata("eventSource", record.getEventSource()); super.addMetadata("eventSourceArn", record.getEventSourceARN()); super.addMetadata("eventID", record.getEventID()); super.addMetadata("awsRegion", record.getAwsRegion()); super.addMetadata("sequenceNumber", record.getDynamodb().getSequenceNumber()); this.record = record; this.stringKeys = stringKeys; }
/** * @return The unique identifier for the record in the DynamoDB stream. */ @Override public String getSequenceNumber() { return internalRecord.getDynamodb().getSequenceNumber(); }
@Override public Date getApproximateArrivalTimestamp() { return internalRecord.getDynamodb().getApproximateCreationDateTime(); }
if (other.getDynamodb() == null ^ this.getDynamodb() == null) return false; if (other.getDynamodb() != null && other.getDynamodb().equals(this.getDynamodb()) == false) return false; if (other.getUserIdentity() == null ^ this.getUserIdentity() == null)
for (Record dynamoRecord : records) { StreamRecord streamRecord = dynamoRecord.getDynamodb(); Map<String,AttributeValue> item = streamRecord.getNewImage(); case "INSERT": case "MODIFY": Map<String,AttributeValue> dynamoItem = streamRecord.getNewImage(); break; case "REMOVE": Map<String,AttributeValue> dynamoKeys = streamRecord.getKeys(); PrimaryKeyValue keyValue = primaryKeyValueFromDynamoKeys(dynamoKeys); emitter.delete(keyValue);
@Override public InternalEvent next() { DynamodbStreamRecord record = this.iterator.next(); String stringKeys = this.serializer.serialize(record.getDynamodb().getKeys()); String stringRecord = this.serializer.serialize(record); return new DynamodbInternalEvent(record, stringKeys, stringRecord, this.context); }
public StreamRecord unmarshall(JsonUnmarshallerContext context) throws Exception { StreamRecord streamRecord = new StreamRecord(); if (context.testExpression("ApproximateCreationDateTime", targetDepth)) { context.nextToken(); streamRecord.setApproximateCreationDateTime(DateJsonUnmarshallerFactory.getInstance("unixTimestamp").unmarshall(context)); streamRecord.setKeys(new MapUnmarshaller<String, AttributeValue>(context.getUnmarshaller(String.class), AttributeValueJsonUnmarshaller .getInstance()).unmarshall(context)); streamRecord.setNewImage(new MapUnmarshaller<String, AttributeValue>(context.getUnmarshaller(String.class), AttributeValueJsonUnmarshaller .getInstance()).unmarshall(context)); streamRecord.setOldImage(new MapUnmarshaller<String, AttributeValue>(context.getUnmarshaller(String.class), AttributeValueJsonUnmarshaller .getInstance()).unmarshall(context)); streamRecord.setSequenceNumber(context.getUnmarshaller(String.class).unmarshall(context)); streamRecord.setSizeBytes(context.getUnmarshaller(Long.class).unmarshall(context)); streamRecord.setStreamViewType(context.getUnmarshaller(String.class).unmarshall(context));
public DynamodbInternalEvent( DynamodbStreamRecord record, String stringKeys, String stringRecord, LambdaContext context) { super(stringRecord, context, record.getDynamodb().getApproximateCreationDateTime().getTime()); super.addMetadata("eventName", record.getEventName()); super.addMetadata("eventSource", record.getEventSource()); super.addMetadata("eventSourceArn", record.getEventSourceARN()); super.addMetadata("eventID", record.getEventID()); super.addMetadata("awsRegion", record.getAwsRegion()); super.addMetadata("sequenceNumber", record.getDynamodb().getSequenceNumber()); this.record = record; this.stringKeys = stringKeys; }
/** * @return The unique identifier for the record in the DynamoDB stream. */ @Override public String getSequenceNumber() { return internalRecord.getDynamodb().getSequenceNumber(); }
@Override public Date getApproximateArrivalTimestamp() { return internalRecord.getDynamodb().getApproximateCreationDateTime(); }
if (other.getDynamodb() == null ^ this.getDynamodb() == null) return false; if (other.getDynamodb() != null && other.getDynamodb().equals(this.getDynamodb()) == false) return false; if (other.getUserIdentity() == null ^ this.getUserIdentity() == null)
return false; StreamRecord other = (StreamRecord) obj; if (other.getApproximateCreationDateTime() == null ^ this.getApproximateCreationDateTime() == null) return false; if (other.getApproximateCreationDateTime() != null && other.getApproximateCreationDateTime().equals(this.getApproximateCreationDateTime()) == false) return false; if (other.getKeys() == null ^ this.getKeys() == null) return false; if (other.getKeys() != null && other.getKeys().equals(this.getKeys()) == false) return false; if (other.getNewImage() == null ^ this.getNewImage() == null) return false; if (other.getNewImage() != null && other.getNewImage().equals(this.getNewImage()) == false) return false; if (other.getOldImage() == null ^ this.getOldImage() == null) return false; if (other.getOldImage() != null && other.getOldImage().equals(this.getOldImage()) == false) return false; if (other.getSequenceNumber() == null ^ this.getSequenceNumber() == null) return false; if (other.getSequenceNumber() != null && other.getSequenceNumber().equals(this.getSequenceNumber()) == false) return false; if (other.getSizeBytes() == null ^ this.getSizeBytes() == null) return false; if (other.getSizeBytes() != null && other.getSizeBytes().equals(this.getSizeBytes()) == false) return false; if (other.getStreamViewType() == null ^ this.getStreamViewType() == null) return false; if (other.getStreamViewType() != null && other.getStreamViewType().equals(this.getStreamViewType()) == false)
putItemRequest.setItem(record.getDynamodb().getNewImage()); putItemRequest.setTableName(getTableName()); request = putItemRequest; deleteItemRequest.setKey(record.getDynamodb().getKeys()); deleteItemRequest.setTableName(getTableName()); request = deleteItemRequest;
@Override public InternalEvent next() { DynamodbStreamRecord record = this.iterator.next(); String stringKeys = this.serializer.serialize(record.getDynamodb().getKeys()); String stringRecord = this.serializer.serialize(record); return new DynamodbInternalEvent(record, stringKeys, stringRecord, this.context); }
@Override public void onSuccess(AmazonWebServiceRequest request, Object result) { log.trace("Record emitted successfully: " + record.getDynamodb().getSequenceNumber()); doneSignal.countDown(); } };