dannycranmer commented on a change in pull request #18553:
URL: https://github.com/apache/flink/pull/18553#discussion_r799775583



##########
File path: flink-connectors/flink-connector-kinesis/pom.xml
##########
@@ -316,6 +316,7 @@ under the License.
                                                        
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
                                                        <artifactSet 
combine.children="append">
                                                                <includes>
+                                                                       
<include>org.apache.flink:flink-core:*</include>

Review comment:
       Why shade flink-core? We do not want to do this, it is provided

##########
File path: flink-core/src/main/java/org/apache/flink/util/ThrowableWrapper.java
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.util;
+
+import org.apache.flink.annotation.Internal;
+
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+/** Util class acting as a classifier for exception to suppress. */
+@Internal
+public class ThrowableWrapper {
+    private final Function<Throwable, Exception> throwableMapper;
+    private final Predicate<Throwable> validator;
+    private ThrowableWrapper chainedWrapper;
+
+    public ThrowableWrapper(
+            Predicate<Throwable> validator, Function<Throwable, Exception> 
throwableMapper) {
+        this.throwableMapper = throwableMapper;
+        this.validator = validator;
+        this.chainedWrapper = null;
+    }
+
+    public boolean shouldSuppress(Throwable err, Consumer<Exception> 
throwableConsumer) {
+        if (validator.test(err)) {
+            throwableConsumer.accept(throwableMapper.apply(err));
+            return false;
+        }
+
+        if (chainedWrapper != null) {
+            return chainedWrapper.shouldSuppress(err, throwableConsumer);
+        } else {
+            return true;
+        }
+    }
+
+    @Override
+    public ThrowableWrapper clone() {
+        ThrowableWrapper clonedSuppressor = new ThrowableWrapper(validator, 
throwableMapper);
+        Optional.ofNullable(this.chainedWrapper)
+                .ifPresent(wrapper -> clonedSuppressor.chainedWrapper = 
wrapper.clone());
+        return clonedSuppressor;
+    }
+
+    public static ThrowableWrapper withRootCauseOfType(
+            Class<? extends Throwable> type, Function<Throwable, Exception> 
mapper) {
+        return new ThrowableWrapper(
+                err -> ExceptionUtils.findThrowable(err, type).isPresent(), 
mapper);
+    }
+
+    public static ThrowableWrapper withRootCauseWithMessage(
+            String message, Function<Throwable, Exception> mapper) {
+        return new ThrowableWrapper(
+                err -> ExceptionUtils.findThrowableWithMessage(err, 
message).isPresent(), mapper);
+    }
+
+    public static ThrowableWrapper build(ThrowableWrapper... classifiers) {

Review comment:
       Semantically the name of this method is wrong. It does not build anything

##########
File path: 
flink-connectors/flink-connector-aws-kinesis-data-streams/src/main/java/org/apache/flink/connector/kinesis/sink/KinesisDataStreamsSinkWriter.java
##########
@@ -56,6 +62,61 @@
 class KinesisDataStreamsSinkWriter<InputT> extends AsyncSinkWriter<InputT, 
PutRecordsRequestEntry> {
     private static final Logger LOG = 
LoggerFactory.getLogger(KinesisDataStreamsSinkWriter.class);
 
+    private static final RetryValidationStrategy INVALID_CREDENTIALS_STRATEGY =
+            new RetryValidationStrategy(
+                    err -> ExceptionUtils.findThrowable(err, 
StsException.class).isPresent(),
+                    err ->
+                            new KinesisDataStreamsException(
+                                    "Encountered non-recoverable exception 
relating to the provided credentials.",
+                                    err));
+    private static final RetryValidationStrategy RESOURCE_NOT_FOUND_STRATEGY =
+            new RetryValidationStrategy(
+                    err ->
+                            ExceptionUtils.findThrowable(err, 
ResourceNotFoundException.class)
+                                    .isPresent(),
+                    err ->
+                            new KinesisDataStreamsException(
+                                    "Encountered non-recoverable exception 
relating to not being able to find the specified resources",
+                                    err));
+    private static final RetryValidationStrategy 
SDK_CLIENT_MISCONFIGURED_STRATEGY =
+            new RetryValidationStrategy(
+                    err -> ExceptionUtils.findThrowable(err, 
SdkClientException.class).isPresent(),
+                    err ->
+                            new KinesisDataStreamsException(
+                                    "Encountered non-recoverable exception 
relating to mis-configured client",
+                                    err));
+    private static final RetryValidationStrategy 
MISSING_ACCESS_KEY_ID_STRATEGY =
+            new RetryValidationStrategy(
+                    err ->
+                            ExceptionUtils.findThrowableWithMessage(
+                                                    err, "Access key ID cannot 
be blank.")
+                                            .isPresent()
+                                    || ExceptionUtils.findThrowableWithMessage(
+                                                    err,
+                                                    "Either the environment 
variable AWS_WEB_IDENTITY_TOKEN_FILE or the javaproperty 
aws.webIdentityTokenFile must be set.")
+                                            .isPresent(),

Review comment:
       Bump

##########
File path: flink-core/src/main/java/org/apache/flink/util/ThrowableWrapper.java
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.util;
+
+import org.apache.flink.annotation.Internal;
+
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+/** Util class acting as a classifier for exception to suppress. */
+@Internal
+public class ThrowableWrapper {
+    private final Function<Throwable, Exception> throwableMapper;
+    private final Predicate<Throwable> validator;
+    private ThrowableWrapper chainedWrapper;
+
+    public ThrowableWrapper(
+            Predicate<Throwable> validator, Function<Throwable, Exception> 
throwableMapper) {
+        this.throwableMapper = throwableMapper;
+        this.validator = validator;
+        this.chainedWrapper = null;
+    }
+
+    public boolean shouldSuppress(Throwable err, Consumer<Exception> 
throwableConsumer) {
+        if (validator.test(err)) {
+            throwableConsumer.accept(throwableMapper.apply(err));
+            return false;
+        }
+
+        if (chainedWrapper != null) {
+            return chainedWrapper.shouldSuppress(err, throwableConsumer);
+        } else {
+            return true;
+        }
+    }
+
+    @Override
+    public ThrowableWrapper clone() {
+        ThrowableWrapper clonedSuppressor = new ThrowableWrapper(validator, 
throwableMapper);
+        Optional.ofNullable(this.chainedWrapper)
+                .ifPresent(wrapper -> clonedSuppressor.chainedWrapper = 
wrapper.clone());
+        return clonedSuppressor;
+    }
+
+    public static ThrowableWrapper withRootCauseOfType(
+            Class<? extends Throwable> type, Function<Throwable, Exception> 
mapper) {
+        return new ThrowableWrapper(
+                err -> ExceptionUtils.findThrowable(err, type).isPresent(), 
mapper);
+    }
+
+    public static ThrowableWrapper withRootCauseWithMessage(
+            String message, Function<Throwable, Exception> mapper) {
+        return new ThrowableWrapper(
+                err -> ExceptionUtils.findThrowableWithMessage(err, 
message).isPresent(), mapper);
+    }
+
+    public static ThrowableWrapper build(ThrowableWrapper... classifiers) {
+        for (int i = 1; i < classifiers.length; ++i) {
+            classifiers[i - 1].chainedWrapper = classifiers[i];

Review comment:
       There is a chance that chained wrappers can form a loop here. Unlikely, 
but possible (if `classifiers[length-1].chainedWrapper == classifiers[0]`)

##########
File path: flink-core/src/main/java/org/apache/flink/util/ThrowableWrapper.java
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.util;
+
+import org.apache.flink.annotation.Internal;
+
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+/** Util class acting as a classifier for exception to suppress. */
+@Internal
+public class ThrowableWrapper {
+    private final Function<Throwable, Exception> throwableMapper;
+    private final Predicate<Throwable> validator;
+    private ThrowableWrapper chainedWrapper;
+
+    public ThrowableWrapper(
+            Predicate<Throwable> validator, Function<Throwable, Exception> 
throwableMapper) {
+        this.throwableMapper = throwableMapper;
+        this.validator = validator;
+        this.chainedWrapper = null;
+    }
+
+    public boolean shouldSuppress(Throwable err, Consumer<Exception> 
throwableConsumer) {
+        if (validator.test(err)) {
+            throwableConsumer.accept(throwableMapper.apply(err));
+            return false;
+        }
+
+        if (chainedWrapper != null) {
+            return chainedWrapper.shouldSuppress(err, throwableConsumer);
+        } else {
+            return true;
+        }
+    }
+
+    @Override
+    public ThrowableWrapper clone() {
+        ThrowableWrapper clonedSuppressor = new ThrowableWrapper(validator, 
throwableMapper);
+        Optional.ofNullable(this.chainedWrapper)
+                .ifPresent(wrapper -> clonedSuppressor.chainedWrapper = 
wrapper.clone());
+        return clonedSuppressor;
+    }

Review comment:
       Why do we need a deep clone here? I see you using this to create the 
chains, but the chain will overwrite the `chainedWrapper` reference

##########
File path: flink-core/src/main/java/org/apache/flink/util/ThrowableWrapper.java
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.util;
+
+import org.apache.flink.annotation.Internal;
+
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+/** Util class acting as a classifier for exception to suppress. */
+@Internal
+public class ThrowableWrapper {

Review comment:
       I am not keen on the name `ThrowableWrapper`. It is a bit too generic to 
not be too meaningful. Given that it is in `flink-core` module it is hard to 
understand when to use this

##########
File path: flink-connectors/flink-sql-connector-aws-kinesis-data-streams/pom.xml
##########
@@ -55,6 +55,7 @@
                                                <configuration>
                                                        <artifactSet>
                                                                <includes>
+                                                                       
<include>org.apache.flink:flink-core</include>

Review comment:
       Why shade flink-core? We do not want to do this, it is provided




-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to