darenwkt commented on code in PR #409:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/409#discussion_r1003775450


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/FlinkResourceExceptionUtils.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.kubernetes.operator.utils;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.flink.kubernetes.operator.crd.AbstractFlinkResource;
+import org.apache.flink.kubernetes.operator.crd.spec.AbstractFlinkSpec;
+import 
org.apache.flink.kubernetes.operator.exception.DeploymentFailedException;
+import org.apache.flink.kubernetes.operator.exception.FlinkResourceException;
+import org.apache.flink.kubernetes.operator.exception.ReconciliationException;
+import org.apache.flink.runtime.rest.util.RestClientException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/** Flink Resource Exception utilities. */
+public final class FlinkResourceExceptionUtils {
+
+    public static <R extends AbstractFlinkResource> void 
updateFlinkResourceException(
+            Throwable throwable, R resource) {
+
+        FlinkResourceException flinkResourceException =
+                getFlinkResourceException(throwable, 
getStackTraceEnabled(resource));
+
+        try {
+            ((AbstractFlinkResource<?, ?>) resource)
+                    .getStatus()
+                    .setError(convertToJson(flinkResourceException));
+        } catch (Exception e) {
+            // Rollback to setting error string/message to CRD
+            ((AbstractFlinkResource<?, ?>) resource)
+                    .getStatus()
+                    .setError(
+                            (e instanceof ReconciliationException)
+                                    ? e.getCause().toString()
+                                    : e.toString());
+        }
+    }
+
+    private static <R extends AbstractFlinkResource> boolean 
getStackTraceEnabled(R resource) {
+        return Optional.ofNullable((AbstractFlinkSpec) resource.getSpec())
+                .map(AbstractFlinkSpec::isStackTraceEnabled)
+                .orElse(false);
+    }
+
+    private static FlinkResourceException getFlinkResourceException(
+            Throwable throwable, boolean isStackTraceEnabled) {
+        FlinkResourceException flinkResourceException =
+                convertToFlinkResourceException(throwable, 
isStackTraceEnabled);
+
+        flinkResourceException.setThrowableList(
+                ExceptionUtils.getThrowableList(
+                                throwable.getCause())
+                        .stream()
+                        .map((t) -> convertToFlinkResourceException(t, false))
+                        .collect(Collectors.toList()));

Review Comment:
   I have added the default limit as ConfigOption and set it to 2



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