tpalfy commented on a change in pull request #3612: NIFI-6486 Add option to use
built-in retry mechanism in AWS processors
URL: https://github.com/apache/nifi/pull/3612#discussion_r319981528
##########
File path:
nifi-nar-bundles/nifi-aws-bundle/nifi-aws-abstract-processors/src/main/java/org/apache/nifi/processors/aws/AbstractAWSProcessor.java
##########
@@ -262,6 +350,81 @@ protected ClientConfiguration createConfiguration(final
ProcessContext context)
return config;
}
+ private void setRetryPolicy(ClientConfiguration config, ProcessContext
context) {
+ PropertyValue property = context.getProperty(AWS_RETRY_POLICY);
+ if (property.isSet()) {
+ switch (property.getValue()){
+ case RETRY_POLICY_CUSTOM:
+ config.setRetryPolicy(new RetryPolicy(
+ getRetryCondition(context),
+ getBackoffStrategy(context),
+ getMaxErrorRetry(context),
+ true
+ ));
+ break;
+ case RETRY_POLICY_DYNAMODB_DEFAULT:
+
config.setRetryPolicy(PredefinedRetryPolicies.DYNAMODB_DEFAULT);
+ break;
+ case RETRY_POLICY_DEFAULT:
+ default:
+ break;
+ }
+ }
+ }
+
+ private RetryCondition getRetryCondition(ProcessContext context) {
+ PropertyValue property = context.getProperty(AWS_RETRY_CONDITION);
+
+ if (!property.isSet()) {
+ return DEFAULT_RETRY_CONDITION;
+ }
+
+ switch (property.getValue()) {
+ case RETRY_CONDITION_COMPLETE_MULTIPART_UPLOAD:
+ return new CompleteMultipartUploadRetryCondition();
+ case RETRY_CONDITION_NO_RETRY:
+ return RetryCondition.NO_RETRY_CONDITION;
+ case RETRY_CONDITION_SDKDEFAULT:
+ default:
+ return DEFAULT_RETRY_CONDITION;
+ }
+ }
+
+ private BackoffStrategy getBackoffStrategy(ProcessContext context) {
+ PropertyValue property = context.getProperty(AWS_BACKOFF_STRATEGY);
+ if (property.isSet()) {
+ int baseDelay = getPropertyValueOrDefault(context,
AWS_BACKOFF_BASE_DELAY, 100);
+ int maxBackoffTime = getPropertyValueOrDefault(context,
AWS_BACKOFF_MAX_BACKOFF_TIME, 20000);
+ int throttledBaseDelay = getPropertyValueOrDefault(context,
AWS_BACKOFF_THROTTLED_BASE_DELAY, 500);
+ switch (property.getValue()) {
+ case BACKOFF_STRATEGY_EQUAL_JITTER:
+ return new EqualJitterBackoffStrategy(baseDelay,
maxBackoffTime);
+ case BACKOFF_STRATEGY_EXPONENTIAL:
+ return new ExponentialBackoffStrategy(baseDelay,
maxBackoffTime);
+ case BACKOFF_STRATEGY_FULL_JITTER:
+ return new FullJitterBackoffStrategy(baseDelay,
maxBackoffTime);
+ case BACKOFF_STRATEGY_NO_DELAY:
+ return BackoffStrategy.NO_DELAY;
+ case BACKOFF_STRATEGY_SDKDEFAULT:
+ default:
+ return new SDKDefaultBackoffStrategy(baseDelay,
throttledBaseDelay, maxBackoffTime);
+ }
+ }
+
+ return DEFAULT_BACKOFF_STRATEGY;
+ }
+
+ private int getMaxErrorRetry(ProcessContext context) {
+ return getPropertyValueOrDefault(context, AWS_MAX_ERROR_RETRY, 0);
Review comment:
This magic number could move to a constant and referenced by the property
descriptor as well.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services