XComp commented on a change in pull request #15049:
URL: https://github.com/apache/flink/pull/15049#discussion_r592601381



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/JobExceptionsInfoWithHistory.java
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.runtime.rest.messages;
+
+import org.apache.flink.runtime.rest.handler.job.JobExceptionsHandler;
+
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnore;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.StringJoiner;
+
+/**
+ * {@code JobExceptionsInfoWithHistory} extends {@link JobExceptionsInfo} 
providing a history of
+ * previously caused failures. It's the response type of the {@link 
JobExceptionsHandler}.
+ */
+public class JobExceptionsInfoWithHistory extends JobExceptionsInfo implements 
ResponseBody {
+
+    public static final String FIELD_NAME_EXCEPTION_HISTORY = 
"exception-history";
+
+    @JsonProperty(FIELD_NAME_EXCEPTION_HISTORY)
+    private final JobExceptionHistory exceptionHistory;
+
+    @JsonCreator
+    public JobExceptionsInfoWithHistory(
+            @JsonProperty(FIELD_NAME_ROOT_EXCEPTION_NAME) String 
rootExceptionName,
+            @JsonProperty(FIELD_NAME_ROOT_EXCEPTION) String rootException,
+            @JsonProperty(FIELD_NAME_TIMESTAMP) Long rootTimestamp,
+            @JsonProperty(FIELD_NAME_ALL_EXCEPTIONS) 
List<ExecutionExceptionInfo> allExceptions,
+            @JsonProperty(FIELD_NAME_TRUNCATED) boolean truncated,
+            @JsonProperty(FIELD_NAME_EXCEPTION_HISTORY) JobExceptionHistory 
exceptionHistory) {
+        super(rootExceptionName, rootException, rootTimestamp, allExceptions, 
truncated);
+        this.exceptionHistory = exceptionHistory;
+    }
+
+    public JobExceptionsInfoWithHistory() {
+        this(
+                null,
+                null,
+                null,
+                Collections.emptyList(),
+                false,
+                new JobExceptionHistory(Collections.emptyList(), false));
+    }
+
+    @JsonIgnore
+    public JobExceptionHistory getExceptionHistory() {
+        return exceptionHistory;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        JobExceptionsInfoWithHistory that = (JobExceptionsInfoWithHistory) o;
+        return this.isTruncated() == that.isTruncated()
+                && Objects.equals(this.getRootExceptionName(), 
that.getRootExceptionName())
+                && Objects.equals(this.getRootException(), 
that.getRootException())
+                && Objects.equals(this.getRootTimestamp(), 
that.getRootTimestamp())
+                && Objects.equals(this.getAllExceptions(), 
that.getAllExceptions())
+                && Objects.equals(exceptionHistory, that.exceptionHistory);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(
+                isTruncated(),
+                getRootExceptionName(),
+                getRootException(),
+                getRootTimestamp(),
+                getAllExceptions(),
+                exceptionHistory);
+    }
+
+    @Override
+    public String toString() {
+        return new StringJoiner(", ", 
JobExceptionsInfoWithHistory.class.getSimpleName() + "[", "]")
+                .add("exceptionHistory=" + exceptionHistory)
+                .toString();
+    }
+
+    /** {@code JobExceptionHistory} collects all previously caught errors. */
+    public static final class JobExceptionHistory {
+
+        public static final String FIELD_NAME_ENTRIES = "entries";
+        public static final String FIELD_NAME_MAX_SIZE_REACHED = 
"max-size-reached";
+        public static final String FIELD_NAME_TRUNCATED = "truncated";
+
+        @JsonProperty(FIELD_NAME_ENTRIES)
+        private final List<JobExceptionsInfo> entries;
+
+        @JsonProperty(FIELD_NAME_TRUNCATED)
+        private final boolean truncated;
+
+        @JsonCreator
+        public JobExceptionHistory(
+                @JsonProperty(FIELD_NAME_ENTRIES) List<JobExceptionsInfo> 
entries,
+                @JsonProperty(FIELD_NAME_TRUNCATED) boolean truncated) {
+            this.entries = entries;
+            this.truncated = truncated;
+        }
+
+        @JsonIgnore
+        public List<JobExceptionsInfo> getEntries() {
+            return entries;
+        }
+
+        @JsonIgnore
+        public boolean isTruncated() {
+            return truncated;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+            JobExceptionHistory that = (JobExceptionHistory) o;
+            return this.isTruncated() == that.isTruncated()
+                    && Objects.equals(entries, that.entries);
+        }
+
+        @Override
+        public int hashCode() {

Review comment:
       You're right. The `RestResponseMarshallingTestBase` asserts the 
unmarshalled object using 
[equals](https://github.com/apache/flink/blob/c6997c97c575d334679915c328792b8a3067cfb5/flink-runtime/src/test/java/org/apache/flink/runtime/rest/messages/RestResponseMarshallingTestBase.java#L37).
 I included `hashCode` for the sole purpose of complying to the 
`equals/hashCode` contract. I still prefer keeping it like that for consistency 
reasons, though.




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


Reply via email to