use of com.amazonaws.services.dynamodbv2.model.Condition in project camel by apache.
the class DdbStreamConsumer method createExchanges.
private Queue<Exchange> createExchanges(List<Record> records, String lastSeenSequenceNumber) {
Queue<Exchange> exchanges = new ArrayDeque<>();
BigIntComparisons condition = null;
BigInteger providedSeqNum = null;
if (lastSeenSequenceNumber != null) {
providedSeqNum = new BigInteger(lastSeenSequenceNumber);
condition = BigIntComparisons.Conditions.LT;
}
switch(getEndpoint().getIteratorType()) {
case AFTER_SEQUENCE_NUMBER:
condition = BigIntComparisons.Conditions.LT;
providedSeqNum = new BigInteger(getEndpoint().getSequenceNumberProvider().getSequenceNumber());
break;
case AT_SEQUENCE_NUMBER:
condition = BigIntComparisons.Conditions.LTEQ;
providedSeqNum = new BigInteger(getEndpoint().getSequenceNumberProvider().getSequenceNumber());
break;
default:
}
for (Record record : records) {
BigInteger recordSeqNum = new BigInteger(record.getDynamodb().getSequenceNumber());
if (condition == null || condition.matches(providedSeqNum, recordSeqNum)) {
exchanges.add(getEndpoint().createExchange(record));
}
}
return exchanges;
}
use of com.amazonaws.services.dynamodbv2.model.Condition in project camel by apache.
the class ShardIteratorHandler method getShardIterator.
String getShardIterator(String resumeFromSequenceNumber) {
ShardIteratorType iteratorType = getEndpoint().getIteratorType();
String sequenceNumber = getEndpoint().getSequenceNumber();
if (resumeFromSequenceNumber != null) {
// Reset things as we're in an error condition.
currentShard = null;
currentShardIterator = null;
iteratorType = ShardIteratorType.AFTER_SEQUENCE_NUMBER;
sequenceNumber = resumeFromSequenceNumber;
}
// either return a cached one or get a new one via a GetShardIterator request.
if (currentShardIterator == null) {
ListStreamsResult streamsListResult = getClient().listStreams(new ListStreamsRequest().withTableName(getEndpoint().getTableName()));
// XXX assumes there is only one stream
final String streamArn = streamsListResult.getStreams().get(0).getStreamArn();
DescribeStreamResult streamDescriptionResult = getClient().describeStream(new DescribeStreamRequest().withStreamArn(streamArn));
shardList.addAll(streamDescriptionResult.getStreamDescription().getShards());
LOG.trace("Current shard is: {} (in {})", currentShard, shardList);
if (currentShard == null) {
currentShard = resolveNewShard(iteratorType, resumeFromSequenceNumber);
} else {
currentShard = shardList.nextAfter(currentShard);
}
shardList.removeOlderThan(currentShard);
LOG.trace("Next shard is: {} (in {})", currentShard, shardList);
GetShardIteratorResult result = getClient().getShardIterator(buildGetShardIteratorRequest(streamArn, iteratorType, sequenceNumber));
currentShardIterator = result.getShardIterator();
}
LOG.trace("Shard Iterator is: {}", currentShardIterator);
return currentShardIterator;
}
use of com.amazonaws.services.dynamodbv2.model.Condition in project openhab1-addons by openhab.
the class DynamoDBPersistenceService method constructTimeCondition.
private Condition constructTimeCondition(FilterCriteria filter) {
boolean hasBegin = filter.getBeginDate() != null;
boolean hasEnd = filter.getEndDate() != null;
final Condition timeCondition;
if (!hasBegin && !hasEnd) {
timeCondition = null;
} else if (!hasBegin && hasEnd) {
timeCondition = new Condition().withComparisonOperator(ComparisonOperator.LE).withAttributeValueList(new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getEndDate())));
} else if (hasBegin && !hasEnd) {
timeCondition = new Condition().withComparisonOperator(ComparisonOperator.GE).withAttributeValueList(new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getBeginDate())));
} else {
timeCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN).withAttributeValueList(new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getBeginDate())), new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getEndDate())));
}
return timeCondition;
}
use of com.amazonaws.services.dynamodbv2.model.Condition in project openhab1-addons by openhab.
the class DynamoDBPersistenceService method createQueryExpression.
/**
* Construct dynamodb query from filter
*
* @param filter
* @return DynamoDBQueryExpression corresponding to the given FilterCriteria
*/
private DynamoDBQueryExpression<DynamoDBItem<?>> createQueryExpression(Class<? extends DynamoDBItem<?>> dtoClass, FilterCriteria filter) {
DynamoDBItem<?> item = getDynamoDBHashKey(dtoClass, filter.getItemName());
final DynamoDBQueryExpression<DynamoDBItem<?>> queryExpression = new DynamoDBQueryExpression<DynamoDBItem<?>>().withHashKeyValues(item).withScanIndexForward(filter.getOrdering() == Ordering.ASCENDING).withLimit(filter.getPageSize());
Condition timeFilter = maybeAddTimeFilter(queryExpression, filter);
maybeAddStateFilter(filter, queryExpression);
logger.debug("Querying: {} with {}", filter.getItemName(), timeFilter);
return queryExpression;
}
use of com.amazonaws.services.dynamodbv2.model.Condition in project camel by apache.
the class ShardList method atAfterSeq.
Shard atAfterSeq(String sequenceNumber, BigIntComparisons condition) {
BigInteger atAfter = new BigInteger(sequenceNumber);
List<Shard> sorted = new ArrayList<>();
sorted.addAll(shards.values());
Collections.sort(sorted, StartingSequenceNumberComparator.INSTANCE);
for (Shard shard : sorted) {
if (shard.getSequenceNumberRange().getEndingSequenceNumber() != null) {
BigInteger end = new BigInteger(shard.getSequenceNumberRange().getEndingSequenceNumber());
// essentially: after < end or after <= end
if (condition.matches(atAfter, end)) {
return shard;
}
}
}
if (shards.size() > 0) {
return sorted.get(sorted.size() - 1);
}
throw new IllegalStateException("Unable to find a shard with appropriate sequence numbers for " + sequenceNumber + " in " + shards);
}
Aggregations