Commit Graph

101 Commits

Author SHA1 Message Date
Artem Bilan
662416cd7b Fix DynamoDbLock.tryLock() for the real timeout
Since the contract of the `tryLock()` to wait as close to the provided
timeout as possible, then we should not wait for the `leasePeriod` as
minimum.
Also we should sleep in between attempts not more then provided timeout
2018-06-28 12:43:35 -04:00
Artem Bilan
d192e17007 Protect DynamoLockReg & DynamoMDS from hanging
If `DynamoDbLockRegistry` and `DynamoDbMetaDataStore` are not declared
as beans (or their `afterPropertiesSet()` is not called), they hanging on
the `awaitForActive()`
2018-06-28 11:47:59 -04:00
Artem Bilan
9e14e86880 Fix DynamoDbLockRegistry.tryLock for fair time
When we try to lock the DynamoDB item we need to iterate at least
the lease time, but we still don't need to sleep too much - maximum
the time requested for `tryLock()`
2018-06-26 20:46:46 -04:00
Artem Bilan
3e603185a7 Fix race condition in KinesisMDCA.doStop()
https://build.spring.io/browse/INTEXT-AWS-158
2018-06-26 16:44:05 -04:00
Artem Bilan
4fe8e4c6a5 Fix timing issue in the KinesisMDChATests
https://build.spring.io/browse/INTEXT-AWS-157
2018-06-26 15:21:56 -04:00
Artem Bilan
133731f288 Fix race condition in the KinesisMDChATests 2018-06-26 13:34:01 -04:00
Artem Bilan
8247d0df1b Fix S3 Channel Adapters to use filter by default 2018-06-26 13:14:25 -04:00
Artem Bilan
6f39406309 Fix race condition: KinesisMDCA.consumerInvokers
https://build.spring.io/browse/INTEXT-AWS-JOB1-154
2018-06-25 21:58:19 -04:00
Artem Bilan
c655a8c4e2 Fix some locking issues in the KinesisMDChAdapter
Related to https://github.com/spring-projects/spring-integration-aws/issues/90
2018-06-25 21:42:24 -04:00
Artem Bilan
66e208f4f7 Try..catch updateTimeToLive in DynamoDbMetaDataSt
Related to https://github.com/spring-projects/spring-integration-aws/issues/90

The `dynamoDB.updateTimeToLive()` throws an exception if TTL is already
enabled on the table

* Wrap such a call to `try...catch()` and just log an error to let
the application to proceed
2018-06-25 21:29:11 -04:00
Artem Bilan
ebd562d6da GH-90: Add shard locking support to KinesisMDChA
Fixes https://github.com/spring-projects/spring-integration-aws/issues/90

* The `KinesisMessageDrivenChannelAdapter` can now be supplied with the
`LockRegistry` (e.g. `DynamoDbLockRegistry`) and when stream-based
configuration is used, the channel adapter performs `tryLock()` for the
shard in the channel adapter consumer group.
Therefor only one listener in the group is able to consume from the shard

Note: there is no yet full support for rebalance functionality.
And such a feature can be implemented using Spring Cloud Bus with the
command to stop and start channel adapters when a new
`KinesisMessageDrivenChannelAdapter` arrives to the cluster
2018-06-19 13:05:00 -04:00
Artem Bilan
fca661404a Upgrade to the latest SC-AWS and fix tests 2018-06-14 13:42:43 -04:00
Artem Bilan
5c262f1d3c GH-66: Add DynamoDbLockRegistry implementation (#93)
* GH-66: Add DynamoDbLockRegistry implementation

Fixes https://github.com/spring-projects/spring-integration-aws/issues/66

* * Remove `Lifecycle` from `DynamoDbLockRegistry` in favor of a thread
execution in the `afterPropertiesSet()`
* Fix `lock()` interruptibility logic

* * Remove `mavenLocal()` since the upstream PR is merged
* decrease an amount of expectations in the Kinesis test

* * Upgrade to SC-AWS-2.0.0.RC2

* * Add Docs for the `DynamoDbLockRegistry`
2018-06-08 16:49:23 -04:00
Artem Bilan
ffb4a6afe6 Fix JavaDocs for DynamoDbMetaDataStore
https://build.spring.io/browse/INTEXT-AWS-JOB1-148
2018-05-22 17:03:11 -04:00
Artem Bilan
598384bc8c Add TTL to DynamoDbMetaDataStore
Fixes https://github.com/spring-projects/spring-integration-aws/issues/92
2018-05-22 16:51:50 -04:00
Artem Bilan
2c58a6925e Add records conversion support in batch mode
https://stackoverflow.com/questions/49730808/unable-to-consume-messages-as-batch-mode-in-kinesis-binder
2018-04-12 18:11:57 -04:00
Artem Bilan
6a999b2873 GH-51: Add headers mapping to channel adapters
Fixes spring-projects/spring-integration-aws#51
2018-04-06 16:51:47 -04:00
Artem Bilan
2b57f34801 Use ConcurrentMetadataStore for checkpointer
https://stackoverflow.com/questions/49315062/spring-cloud-aws-stream-messages-are-consumed-by-multiple-instances-in-consumer

There is a race condition when we check if the checkpoint exists or not
and then we perform `put` unconditionally

* Change the checkpointer logic to perform `replace()` if the entry
exists or `putIfAbsent()` if not.
In both cases check for the result to determine if the current
sequence number if the biggest and therefore we are good to process
record(s)
2018-03-19 15:51:20 -04:00
Artem Bilan
a50135c354 GH-85: Add SqsMDChannelAdapter.getQueue()
Fixes spring-projects/spring-integration-aws#85

* For better component management add
`SqsMessageDrivenChannelAdapter.getQueue()` to return what queues this
channel adapter is subscribed
* Upgrade to Gradle 4.6 and Checkstyle 8.8
2018-03-12 13:34:49 -04:00
Artem Bilan
54b7220459 GH-84: Kinesis Inbound: errors immunity
Fixes spring-projects/spring-integration-aws#84
Fixes spring-cloud/spring-cloud-stream-binder-aws-kinesis#38
Fixes spring-cloud/spring-cloud-stream-binder-aws-kinesis#36

Even if AWS Client has some reconnect and retry mechanism, it can be
exhausted and no connection error is rethrown to the `KinesisMessageDrivenChannelAdapter`
anyway.

On the other hand the error can be thrown from the record processor -
the flow on the `outputChannel`.

* log the exception around AWS Client calls and let background process
to restore/retry
* log the exception around message to send to let the processor to move
to the next record or perform the next task
* null the current `task` in the `ShardConsumer` in the `finally` block
to avoid hanging the thread without ability to moving to some other state
without end-user interaction
* When perform the `batch` checkpoint, check the result and if it is
negative, consider such a situation as processed and skip records from
sending downstream
* Upgrade dependencies
* Use Log4J2 for tests logging
2018-03-01 15:22:02 -05:00
Artem Bilan
8981384b26 Fix KinesisMessageHandler.sequenceNumber SpEL 2018-02-10 18:57:43 -05:00
Artem Bilan
7d283fea87 Handle errors in KinesisMessageDrivenChAdapter
Relates spring-cloud-stream-binder-aws-kinesis/#34

* Introduce `KinesisMessageHeaderErrorMessageStrategy` to populate
`AwsHeaders.RAW_RECORD` to the `ErrorMessage` headers
* Improve `KinesisMessageDrivenChannelAdapter` for the `AttributeAccessor`.
Also `try...finally` the `processRecords()` to perform important tasks
independently of the `processRecords()` result
2018-01-25 17:32:59 -05:00
Artem Bilan
2e63b2c682 GH-62: Align Message Handlers for common API
Fixes: spring-projects/spring-integration-aws#62

* Make `SnsMessageHandler extends AbstractAwsMessageHandler`
* Remove SNS Outbound Gateway variant since `SnsMessageHandler` covers
that part via `successChannel` and `failureChannel`
* Fix XSD for SQS and SNS
* Fix SQS and SNS tests according their logic changes
* Fix README for new changes
2017-12-22 16:59:48 -05:00
Artem Bilan
b4c7690cf1 Fix SqsMessageDrivenChannelAdapterTests
https://build.spring.io/browse/INTEXT-AWS-JOB1-132
2017-12-22 12:35:09 -05:00
Artem Bilan
3940a8fb6a Kinesis-Binder-29: Add RECEIVED headers
Fixes: spring-cloud/spring-cloud-stream-binder-aws-kinesis#29

Previously the same header name has been used for sending and receiving
operations (e.g. Kinesis `stream`).
This causes collisions in streaming processes when we receive message
from the AWS and send it downstream to AWS.
The header presence has a precedence over configured property/expression.
Therefore we send message to the AWS (e.g. Kinesis) using wrong
destination or other correlation properties

* Add `AwsHeaders.RECEIVED_*` headers to avoid collisions
* Remove Jackson dependency since it is managed now properly by SC-AWS
2017-12-22 12:21:22 -05:00
Artem Bilan
42a4a45de8 Start version 2.0
* Upgrade to SI-5.0, SC-AWS-2.0, Gradle-4.4.1 and some Gradle plugins
* Add `Jackson` dependency for compatibility with SF
* Implement new API of super classes
* Fix deprecations
* Fix tests for new state of classes under test
* Rename XSD to version 2.0
2017-12-20 17:14:08 -05:00
Artem Bilan
d07441134b Polishing:
* Always call provided `AsyncHandler` from the internal instance
in the `KinesisMessageHandler`
* Make the `KinesisMessageHandler.obtainAsyncHandler()` as generic method
* Rename `sendFailureChannel` property just to the `failureChannel`
since the real operation is `put` not send
* Add `AwsHeaders.SERVICE_RESULT` to represent the service result, e.g.
in case of `PutRecordsRequest` in the `KinesisMessageHandler` to
send on success the whole `PutRecordsResult`
* Fix README to reflect the current reality of the code
* Fix `KinesisMessageHandlerTests` for provided `AsyncHandler` verification
2017-11-16 11:44:15 -05:00
Jacob Severson
281fad8330 Adding error handling to KinesisMessageHandler
This is groundwork to allow usage of a failure channel within the Kinesis binder per.
This implementation is intended to be backward-compatible with respect to the current handling
of `AsyncHandler`. Client code can still provide an `AsyncHandler`,
but doing so precludes the usage of channels for successful or unsuccessful sends.

Renaming to AwsRequestFailureException

generic getasynchandler method

always delegate or build handler

Added readme docs and using channel for tests
2017-11-16 11:44:13 -05:00
Artem Bilan
41b389e574 Move Kinesis batch checkpoint before sending
Since the listener may take some time for records processing,
there is a possibility that checkpoint will be stored too late
after the process and thus we are able to get the same records
in different channel adapter for the same shard, even if they are
in the same consumer group and use shared `MetadataStore`

This solution is some compromise for the current state of things and
has to be reconsidered in the future in favor of proper rebalance and
shard leader election solution

As a workaround for the duplicate records an additional
`@IdempotentReceiver` approach can be used

* Upgrade to Gradle 4.2.1, Checkstyle 8.3, AssertJ 3.8.0
* Fix race condition in the `KinesisMessageDrivenChannelAdapterTests`
2017-10-19 13:43:06 -04:00
Artem Bilan
43754e19c6 GH-76: DynamoDbMDStore: add create retry options
Resolves spring-projects/spring-integration-aws#77
Resolves spring-projects/spring-integration-aws#76

Add configuration options in the `DynamoDbMetaDataStore`
for the retry policy for the `DescribeTableRequest`
Change the `createTableLatch` to wait for the whole retry time
2017-09-15 16:53:25 -04:00
Artem Bilan
0898f6e64c Upgrade to Checkstyle 8.1 and fix violations 2017-08-02 21:19:52 -04:00
Artem Bilan
c4a3fcdee2 GH-72: Add KinesisLocalRunning and tests
Fixes spring-projects/spring-integration-aws#72

* Document Kinesis Channel Adapters
* Fix some inconsistency in the `KinesisMessageHandler`
* Add integration test against `KinesisLocalRunning` `@Rule`
* Document testing against Kinesalite
2017-08-02 20:01:13 -04:00
Artem Bilan
638d5e6f75 GH-64: Add DynamoDbMetaDataStore implementation
Fixes spring-projects/spring-integration-aws#64

* Add `DynamoDbRunning` for testing against locally ran DynamoDB
* Upgrade to Gradle 4.0.1, SI-4.3.11
* Switch on some Checkstyle rules for tests
2017-08-01 12:33:40 -04:00
Artem Bilan
d187c838b6 GH-75: Fix remote directory representation
Resolves spring-projects/spring-integration-aws#75

Since we can build S3 entity key any deep path,
e.g. `my_bucket/foo/bar/baz/file.name` and S3 Object `key` representation
is exactly the whole path without bucket name, we should treat only bucket
as a remote dir; the key should be as a file name

* Change `S3InboundFileSynchronizer` logic to extract bucket name before
performing `copyFileToLocalDirectory()`
* Change `S3StreamingMessageSource` to override the `S3FileInfo.remoteDirectory`
to the only bucket name after `poll()`.
* Use for both cases a new `S3Session.normalizeBucketName()` method
* Upgrade to Gradle 4.0 and some other `build.gradle` polishing
2017-07-10 20:32:39 -04:00
Artem Bilan
d76ca1be91 Upgrade to SC-AWS-1.2.1 and SI-4.3.10 2017-06-07 18:34:50 -04:00
Artem Bilan
409bfd9533 GH-70: KinesisMDCA: Add idleBetweenPolls option
Fixes spring-projects/spring-integration-aws#70

* Following the AWS Kinesis recommendation about some sleep interval in
between request to the Kinesis service, add `idleBetweenPolls` option
to the `KinesisMessageDrivenChannelAdapter` to sleep in the
`ConsumerDispatcher` main loop after each execution cycle
* Make default `recordLimit` as `10000` - to fetch as much as possible
data per one GetRecords request
* Change `Lock` and `Condition` in the `ConsumerInvoker` to the
`Semaphore`.
We really may release permit from the `ShardConsumer` to perform
the `ConsumerInvoker` cycle before stepping in that cycle
2017-06-01 13:06:37 -04:00
Artem Bilan
a8d370ff4c GH-70: KinesisMDCA: Get rid of busy-spin CPU
Fixes spring-projects/spring-integration-aws#70

* The `ConsumerDispatcher` is infinite, non-blocking loop:
add short `Thread.sleep(1)` to the loop to yield the CPU
* The `ConsumerInvoker` is infinite loop, too, but can be blocked:
add `Condition` to wait to the particular notification from the
`ShardConsumer` when it changes its state
2017-05-31 17:45:32 -04:00
Artem Bilan
4a0201f29d GH-71: Kinesis Adapters: Handle byte[] directly
Fixes spring-projects/spring-integration-aws#71

It isn't correct to call `converter.convert()` in the
`KinesisMessageHandler` if `payload` is already `ByteBuffer` or `byte[]`
On the other hand an application might be interested in the `byte[]`
payload on the consumer side.
The `KinesisMessageDrivenChannelAdapter` must be able to produce
`byte[]` `payload` without any conversion.

* Add logic into `KinesisMessageHandler` to check the `payload` type
before calling `converter.convert()`
* Allow to configure `converter` to `null` for the
`KinesisMessageDrivenChannelAdapter`.
 The body of the consumed record is presented in the `payload` as is -
 `byte[]`
* Add JavaDoc to the `KinesisMessageHandler.setConverter()`
2017-05-31 13:19:33 -04:00
Anwar Chirakkattil
1e016972ce GH-67: Ignore starting slashes in S3 bucket name
Fixes: spring-projects/spring-integration-aws#67

* Use `org.springframework.util.StringUtils#trimLeadingCharacter()`
to remove any useless leading `/` in the bucket name
2017-05-30 11:29:51 -04:00
Artem Bilan
9b5a5e38bc Fix KinesisMessageDrivenChannelAdapterTests
* Upgrade to Gradle 3.5
* Make S3 test Java 8 based
2017-05-30 11:08:28 -04:00
Artem Bilan
d65fbebc31 GH-63: Kinesis: Add diagnostics for closed shards
Fixes spring-projects/spring-integration-aws#63
2017-04-06 13:37:35 -04:00
Artem Bilan
8e7e1a02b6 GH-63: Kinesis: fix logic to skip closed shards
Fixes spring-projects/spring-integration-aws#63

The `CLOSED` shards have `endingSequenceNumber` value and they can't be
considered for consuming independently of the value in the `checkpoint`

* Introduce local `shardsToConsume` variable in the
`KinesisMessageDrivenChannelAdapter#populateShardsForStream()` to
store only `OPEN` shards for future consumption
* Fix the logic to determine the last `shardId` for a subsequent
`describeStream()` request based on the shards result exactly from
the `describeStreamResult.getStreamDescription().getShards()`, not
already filtered `shardsToConsume`
2017-04-04 19:54:57 -04:00
Artem Bilan
c8195fb9b5 GH-56: Upgrade to SC-AWS-1.2 RC1
Fixes: spring-projects/spring-integration-aws#56

The upgrade to SC-AWS-1.2 RC1 resolves US_East_2 Region concern
since AWS SDK is polled in version `1.1.98`

Also fix deprecation warnings in S3 support components
2017-03-30 14:42:07 -04:00
Krzysztof Witkowski
b552a0892c Handle expired and throttling in ShardConsumer
When shard iterator is expired (`ExpiredIteratorException`),
we have to restart from the stored sequence number

When shard iterator is throttled (`ProvisionedThroughputExceededException`),
 we have to "sleep" for backoff period

* Catch `ExpiredIteratorException` on the `.amazonKinesis.getRecords()` request
and move `ShardConsumer` to the `ConsumerState.EXPIRED`.
This state is treated as `NEW`, therefore a fresh `amazonKinesis.getShardIterator()`
is performed

* Catch `ProvisionedThroughputExceededException` on the `.amazonKinesis.getRecords()`
request and move `ShardConsumer` to the `ConsumerState.SLEEP`
for the `KinesisMessageDrivenChannelAdapter.this.consumerBackoff` period
2017-03-30 14:20:26 -04:00
Artem Bilan
8d120e020c GH-61: Use shutdown for executors in KinesisMDCA
Fixes: spring-projects/spring-integration-aws#61

With the `shutdownNow()` the currently ran task are marked with the
`Thread.interrupt()`.
The AWS SDK catch this situation and throws `AbortedException`

* To let currently ran task finish properly switch from the
`shutdownNow()` to the `shutdown()` for internal executors

The external Spring-based executors (`ExecutorConfigurationSupport`)
must be supplied with the `waitForTasksToCompleteOnShutdown` option
2017-03-28 20:12:24 -04:00
Artem Bilan
041290dbb8 GH-60: Fix NPE in KinesisMessageDrivenChAdapter
Fixes: spring-projects/spring-integration-aws#60

The attempts to extract `this.consumerInvokers.get(0)` when the `concurrency == 0` lead to the NPE

* Wrap `this.consumerInvokers.get(0)` block to the `if(concurrency != 0)`
2017-03-28 14:51:42 -04:00
Krzysztof Witkowski
8d1839980b Fix concurrent modification in ConsumerInvoker
`ConsumerInvoker` uses iterator over `consumers` property, which can be
concurrently modified in the `populateConsumer()`` method, thus triggering
`ConcurrentModificationException`:

```
Exception in thread "kinesisChannel-kinesis-consumer-1" java.util.ConcurrentModificationException
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
	at java.util.ArrayList$Itr.next(ArrayList.java:851)
	at org.springframework.integration.aws.inbound.kinesis.KinesisMessageDrivenChannelAdapter$ConsumerInvoker.run(KinesisMessageDrivenChannelAdapter.java:866)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
```

* Use a `ConcurrentLinkedQueue` instead of `ArrayList`  to fix a concurrent Modification problem.
2017-03-25 18:14:50 -04:00
Artem Bilan
0c81e4d791 Add @DirtiesContext to test classes 2017-03-09 17:37:20 -05:00
Artem Bilan
085548b71d UnIgnore KinesisMessageDrivenChannelAdapterTests 2017-03-09 15:47:03 -05:00
Artem Bilan
bd23958330 Ignore KinesisMessageDrivenChannelAdapterTests 2017-03-09 15:27:37 -05:00