Commit Graph

273 Commits

Author SHA1 Message Date
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
Artem Bilan
cdb68123db Upgrade to Gradle 3.4.1 and fix typo 2017-03-09 15:02:25 -05:00
Mike Girard
3e692f529a Update to spring-cloud-aws-1.1.3
Fixes GH-49 (https://github.com/spring-projects/spring-integration-aws/issues/49)
2017-02-07 13:35:58 -05:00
Marius Bogoevici
ace4055ed9 Remove amazon-kinesis-client
* Remove the `amazon-kinesis-client` dependency
* Use `CustomizableThreadFactory` instead of `NamedThreadFactory`
2017-01-25 09:46:57 -05:00
Artem Bilan
ef2f5f7aef GH-22: Add KinesisMessageDrivenChannelAdapter
Fixes GH-22 (https://github.com/spring-projects/spring-integration-aws/issues/22)

Rework logic to the `dispatching` and tasks

* Add `LimitExceededException` and configurable retry logic for the `describeStream`
* Skip `CLOSED` shards which has been read before according stored `checkpoint`. Will be useful for `after resharding` algorithm
* Add `adapt to resharding` logic
* Add `KinesisMessageDrivenChannelAdapterTests` based on mocks
* Add Thread Affinity for `ShardConsumer`s via `concurrency` option
* Introduce `concurrency` option and `ConsumerInvoker`.
  `ShardConsumer`s are now distributed between `ConsumerInvoker`s if `concurrency > 0`
  `ConsumerInvoker`s are scheduled to the `ConsumerExecutor` as a `isLongLived` tasks
  The concurrency is adjusted if there are no more `ShardConsumer`s to process (`STOP` state because of closed shard).
  At the same time newly populated `ShardConsumer`s (e.g. after resharding) is distributed evenly between existing `ConsumerExecutor`s if `maxConcurrency` is exceeded.
Otherwise fresh `ConsumerExecutor` is started for new `ShardConsumer`
2017-01-25 09:21:07 -05:00
Artem Bilan
0e31261545 GH-54: Rename S3StreamingMessageSource
Fixes GH-54 (https://github.com/spring-projects/spring-integration-aws/issues/54)

For consistency with other `AbstractRemoteFileStreamingMessageSource` implementations (e.g. `FtpStreamingMessageSource`) rename `S3InboundStreamingMessageSource` to the `S3StreamingMessageSource`

Since there was no any Milestones for the `1.1` version yet, it is safe to do this renaming breaking change
2016-11-28 15:27:48 -05:00
Artem Bilan
fa416e40f7 Add support for PutRecordRequest and PutRecordsRequest as payload 2016-10-13 14:27:05 -04:00
Artem Bilan
dda290f271 GH-22: Add KinesisMessageHandler
Fixes GH-22 (https://github.com/spring-projects/spring-integration-aws/issues/22)

* Add `KinesisMessageHandler` based on the `AmazonKinesisAsync.putRecordAsync()` operation.
The logic is fully similar to the `KafkaProducerMessageHandler` since both protocols pursue the same behavior
* Add some Kinesis specific `AwsHeaders`
* Upgrade to Gradle 2.14.1
2016-10-13 14:27:05 -04:00
Artem Bilan
b1a6b59dab Use S3PersistentAcceptOnceFLFilter by default
To avoid some local work with files, add `S3PersistentAcceptOnceFileListFilter` to the `S3InboundFileSynchronizer` as a default one

* Upgrade to Gradle 3.1
* Upgrade to SI-4.3.2
* Some `build.gradle` polishing
* Downgrade to Checkstyle-6.16.1 because of `RequireThis` bug
2016-09-19 17:22:42 -04:00
Artem Bilan
f5a6b1c44c Upgrade to AssertJ-2.5.2 and Checkstyle-7.1
According changes in the `RequireThis`, the `this.` modifier is required now only in case of overlapping:
https://github.com/checkstyle/checkstyle/issues/3418

* Add `validateOnlyOverlapping = false` to reinstate the previous behavior, but we should think one more time if we really should be so strict with this rule
2016-09-01 10:25:34 -04:00
Artem Bilan
985f888281 Fix S3InboundStreamingChannelAdapterTests
* Different OSs can return files in different order, so add `Comparator` to the test
* Also decrease poll timeout for `null` expectation
2016-08-31 23:29:43 -04:00
Artem Bilan
a3923c93e7 XSD refactoring to pull common attributes
Also introduce `remote-file-separator` since this option is available via Java Config
2016-08-31 23:10:47 -04:00
Christian Tzolov
da77e4b89e Issue #30 : Add S3 inbound streaming channel adapter.
Fixes GH-30 (https://github.com/spring-projects/spring-integration-aws/issues/30)

* Add S3InboundStreamingMessageSource and related S3FileInfo
* Extend spring-integration-aws-1.1.xsd with s3-inbound-streaming-channel-adapter tag.
* Add S3StreamingInboundChannelAdapterParser and s3-inbound-streaming-channel-adapter handler.
* Add S3 streaming spring tests.
* Add S3 streaming documentation to README.md.

Issue #30: Resolve code style and formatting issues

Polishing:
* Revert some `build.gradle` changes
* Add JavaDoc to the `S3FileInfo.getPermissions()`
2016-08-31 22:43:39 -04:00
Artem Bilan
de4dfed908 Rename XSD to 1.1 version 2016-08-31 18:00:35 -04:00
Artem Bilan
a9a7b26dbf Start version 1.1.0
* Upgrade to SI-4.3.1
* Upgrade to SC-AWS-1.1.1
* Fix compatibility
2016-08-31 09:38:36 -04:00
Artem Bilan
8b9922d16c The S3 keyExpression assertions improvement 2016-08-29 14:54:04 -04:00
Artem Bilan
8e2fb5e921 Add start/stop queues management for SQS Adapter
Provide delegates for the SC-AWS `SimpleMessageListenerContainer` `start/stop/isRunning` method for individual queues.

Mark `SqsMessageDrivenChannelAdapter` with `@ManagedResource` and `@IntegrationManagedResource` to make those operation accessible from JMX/ControlBus
Cover the change with test-case
Provide some upgrades
Fix test for NPE from AWS SDK around `lastModified`: https://github.com/aws/aws-sdk-java/issues/822
2016-08-23 19:28:51 -04:00
Jim Krygowski
72821bfb8c GH-45: Fix S3 hierarchy support
Fixes GH-45 (https://github.com/spring-projects/spring-integration-aws/issues/45)

S3InboundFileSynchronizer failing when processing through S3 directories - modified approach for splitPathToBucketAndKey to account for the fact that there will be more than one forward slash in the path when subdirectories are used in an S3 bucket. Set up split operation to use the limit parameter to force the bucket identifier into the first element and the remainder of the text (the key) into the second element.

* modified unit test to include subdirectories.
*fixed additional usages of the split operation without the match limit parameter. DRY'd up some code. Cleaned up unit tests.

* added @author annotation at project lead's request.

Add some polishing
2016-08-11 16:32:06 -04:00
Artem Bilan
b5292dc761 Introduce AwsHeaders.ACKNOWLEDGMENT for SQS 2016-07-14 17:31:23 -04:00
John Logan
b5e6cdaa95 GH-41: Fix broken S3 File upload
Fixes GH-41 (https://github.com/spring-projects/spring-integration-aws/issues/41)
Fixes GH-43 (https://github.com/spring-projects/spring-integration-aws/issues/43)

- Prior upload() code was trying to reset() a
  FileInputStream and then upload to S3, which
  resulted in zero uploaded bytes.
- Added dependency on spring-cloud-aws-core
  to resolve ResourceIdResolver reference.
- Fail if InputStream payload does not support
  mark/reset.
- Add metadata for byte array payload.

GH-41: Fix assert order per PR comments.
2016-07-13 16:48:53 -04:00
Kamil Przerwa
97988bdec5 GH-39: Allow text/plain for SNS Inbound
Fixes GH-39 (https://github.com/spring-projects/spring-integration-aws/issues/39)

Amazon SNS HTTP notifications are sent with the `content-type` header as `text/plain`, not `application/json` as it is expected by the `MappingJackson2HttpMessageConverter` by default.

*Added `text/plain` as supported content type for SNS inbound notification

* Corrections after review
2016-06-23 12:44:14 -04:00
Patrick Fitzsimons
7be94b7690 GH-36: Add SqsMessageDrivenCA.queueStopTimeout
Fixes GH-36 (https://github.com/spring-projects/spring-integration-aws/issues/36)

* Add ability to set `queueStopTimeout` for `SimpleMessageListenerContainer` in `SqsMessageDrivenChannelAdapter`
* Update unit tests to test `queueStopTimeout`
* Ensure that we don't override the default `queueStopTimeout` with `0` `long`
* Upgrade to `SI-4.2.8`
2016-06-14 17:19:14 -04:00
Patrick Fitzsimons
d2aa5224ec Adding auto start up setter on sqsMessageDrivenChannelAdapter.java
Update tests in SqsMessageDrivenChannelAdapterParserTests to invoke setAutoStartup

Change setAutoStartUp to invoke super in SqsMessageDrivenChannelAdapter

Add override to SqsMessageDrivenChannelAdapter

Remove call to setAutoStartup in SqsMessageDrivenChannelAdapterParserTests
2016-06-08 21:47:05 -04:00
Artem Bilan
6abc1210a1 Add ResourceIdResolver support
I many cases we deal in application just with simple logical name for the target AWS entities, e.g. `myQueue`, `testBucket`.
Actually they must be resolved into the physical resources against the current environment.
E.g. the same  S3 `testBucket` ca be fully different in different regions.
 The SQS queue must be resolved into the resources with the current `Stack` context.
2016-05-27 15:05:00 -04:00
Artem Bilan
175cc06e0b Fix NPE in the S3Session and validate bucket 2016-05-19 12:02:25 -04:00
Artem Bilan
5d4bcb37db INTEXT-221: Document S3 Gateway & CheckStyle
JIRA: https://jira.spring.io/browse/INTEXT-221

Also apply Checkstyle for the project
Move testing to the `AssertJ`
Adjust `.travis.yml` for Gradle 2.13
Add `CODE_OF_CONDUCT.adoc`
2016-05-18 18:44:38 -04:00
Artem Bilan
1c0b315462 Pre-release polishing 2016-04-13 16:33:26 -04:00
Artem Bilan
d73390191e Removed obsolete XSD types 2016-04-12 15:21:29 -04:00
Artem Bilan
29e255cc64 Add S3 MessageSource implementation
JIRA: https://jira.spring.io/browse/INTEXT-51,
https://jira.spring.io/browse/INTEXT-194,
https://jira.spring.io/browse/INTEXT-199

* Add S3 Inbound Channel Adapter fully based on the `AbstractInboundFileSynchronizer`,
`AbstractInboundFileSynchronizingMessageSource` implementation.
* Provide the standard SI `RemoteFileTemplate` and `SessionFactory` abstractions implementations.
* Upgrade to Gradle-2.12
* Provide Namespace support
* Ensure everything with tests
* Remove legacy, redundant implementation, infrastructure code for it and test-cases.
Everything in favor of the new implementation.
2016-04-04 19:59:02 -04:00