@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? } } }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getApproximateCreationDateTime() != null) sb.append("ApproximateCreationDateTime: ").append(getApproximateCreationDateTime()).append(","); if (getKeys() != null) sb.append("Keys: ").append(getKeys()).append(","); if (getNewImage() != null) sb.append("NewImage: ").append(getNewImage()).append(","); if (getOldImage() != null) sb.append("OldImage: ").append(getOldImage()).append(","); if (getSequenceNumber() != null) sb.append("SequenceNumber: ").append(getSequenceNumber()).append(","); if (getSizeBytes() != null) sb.append("SizeBytes: ").append(getSizeBytes()).append(","); if (getStreamViewType() != null) sb.append("StreamViewType: ").append(getStreamViewType()); sb.append("}"); return sb.toString(); }
@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; }
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)
/** * Marshall the given parameter object. */ public void marshall(StreamRecord streamRecord, ProtocolMarshaller protocolMarshaller) { if (streamRecord == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(streamRecord.getApproximateCreationDateTime(), APPROXIMATECREATIONDATETIME_BINDING); protocolMarshaller.marshall(streamRecord.getKeys(), KEYS_BINDING); protocolMarshaller.marshall(streamRecord.getNewImage(), NEWIMAGE_BINDING); protocolMarshaller.marshall(streamRecord.getOldImage(), OLDIMAGE_BINDING); protocolMarshaller.marshall(streamRecord.getSequenceNumber(), SEQUENCENUMBER_BINDING); protocolMarshaller.marshall(streamRecord.getSizeBytes(), SIZEBYTES_BINDING); protocolMarshaller.marshall(streamRecord.getStreamViewType(), STREAMVIEWTYPE_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getApproximateCreationDateTime() != null) sb.append("ApproximateCreationDateTime: ").append(getApproximateCreationDateTime()).append(","); if (getKeys() != null) sb.append("Keys: ").append(getKeys()).append(","); if (getNewImage() != null) sb.append("NewImage: ").append(getNewImage()).append(","); if (getOldImage() != null) sb.append("OldImage: ").append(getOldImage()).append(","); if (getSequenceNumber() != null) sb.append("SequenceNumber: ").append(getSequenceNumber()).append(","); if (getSizeBytes() != null) sb.append("SizeBytes: ").append(getSizeBytes()).append(","); if (getStreamViewType() != null) sb.append("StreamViewType: ").append(getStreamViewType()); sb.append("}"); return sb.toString(); }
@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; }
@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 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 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(); } } } }
break; case "REMOVE": Map<String,AttributeValue> dynamoKeys = streamRecord.getKeys(); PrimaryKeyValue keyValue = primaryKeyValueFromDynamoKeys(dynamoKeys); emitter.delete(keyValue);
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)
deleteItemRequest.setKey(record.getDynamodb().getKeys()); deleteItemRequest.setTableName(getTableName()); request = deleteItemRequest;
/** * {@inheritDoc} */ @Override public void consumeRecord(final Record record, final int recordBytes, final String sequenceNumber) { // Use HashMap to deduplicate using the DynamoDB key as the key. getBuffer().put(record.getDynamodb().getKeys(), record); // Sequence number bound maintenance setLastSequenceNumber(sequenceNumber); if (getFirstSequenceNumber() == null) { setFirstSequenceNumber(getLastSequenceNumber()); } setProcessedRecords(getProcessedRecords() + 1); emitCloudWatchMetrics(); }
/** * Marshall the given parameter object. */ public void marshall(StreamRecord streamRecord, ProtocolMarshaller protocolMarshaller) { if (streamRecord == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(streamRecord.getApproximateCreationDateTime(), APPROXIMATECREATIONDATETIME_BINDING); protocolMarshaller.marshall(streamRecord.getKeys(), KEYS_BINDING); protocolMarshaller.marshall(streamRecord.getNewImage(), NEWIMAGE_BINDING); protocolMarshaller.marshall(streamRecord.getOldImage(), OLDIMAGE_BINDING); protocolMarshaller.marshall(streamRecord.getSequenceNumber(), SEQUENCENUMBER_BINDING); protocolMarshaller.marshall(streamRecord.getSizeBytes(), SIZEBYTES_BINDING); protocolMarshaller.marshall(streamRecord.getStreamViewType(), STREAMVIEWTYPE_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }