From 7dfa37e8f0833b04d8e75d9f778b72bf57d4c89e Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Thu, 27 Feb 2020 10:36:49 +0900 Subject: [PATCH] YARN-10152. Fix findbugs warnings in hadoop-yarn-applications-mawo-core module (#1852) --- .../mawo/server/common/TaskStatus.java | 36 +++++++++++++++++++ .../mawo/server/worker/WorkerId.java | 6 ++++ 2 files changed, 42 insertions(+) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-mawo/hadoop-yarn-applications-mawo-core/src/main/java/org/apache/hadoop/applications/mawo/server/common/TaskStatus.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-mawo/hadoop-yarn-applications-mawo-core/src/main/java/org/apache/hadoop/applications/mawo/server/common/TaskStatus.java index 4f780d8dc3..3529077d87 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-mawo/hadoop-yarn-applications-mawo-core/src/main/java/org/apache/hadoop/applications/mawo/server/common/TaskStatus.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-mawo/hadoop-yarn-applications-mawo-core/src/main/java/org/apache/hadoop/applications/mawo/server/common/TaskStatus.java @@ -22,6 +22,7 @@ import java.io.DataOutput; import java.io.IOException; +import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.hadoop.applications.mawo.server.worker.WorkerId; import org.apache.hadoop.io.Writable; import org.apache.hadoop.io.WritableUtils; @@ -344,4 +345,39 @@ public final WorkerId getWorkerId() { public final void setWorkerId(final WorkerId localworkerId) { this.workerId = localworkerId; } + + @Override + public boolean equals(Object obj) { + if (obj == null || obj.getClass() != this.getClass()) { + return false; + } + TaskStatus other = (TaskStatus) obj; + return (getWorkerId().equals(other.getWorkerId()) && + getTaskId().equals(other.getTaskId()) && + getRunState().equals(other.getRunState()) && + getStartTime() == other.getStartTime() && + getEndTime() == other.getEndTime() && + getTaskCMD().equals(other.getTaskCMD()) && + getTaskType().equals(other.getTaskType()) && + getExitCode() == other.getExitCode()); + } + + @Override + public int hashCode() { + HashCodeBuilder builder = new HashCodeBuilder(); + builder.append(getWorkerId()) + .append(getTaskId()) + .append(getRunState()) + .append(getStartTime()) + .append(getEndTime()) + .append(getTaskCMD()) + .append(getTaskType()) + .append(getExitCode()); + return builder.hashCode(); + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-mawo/hadoop-yarn-applications-mawo-core/src/main/java/org/apache/hadoop/applications/mawo/server/worker/WorkerId.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-mawo/hadoop-yarn-applications-mawo-core/src/main/java/org/apache/hadoop/applications/mawo/server/worker/WorkerId.java index dfb356b105..cefc8641e4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-mawo/hadoop-yarn-applications-mawo-core/src/main/java/org/apache/hadoop/applications/mawo/server/worker/WorkerId.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-mawo/hadoop-yarn-applications-mawo-core/src/main/java/org/apache/hadoop/applications/mawo/server/worker/WorkerId.java @@ -86,6 +86,7 @@ public final String getIPAddress() { * Print workerId. * @return workeId in string */ + @Override public final String toString() { return workerId.toString(); } @@ -111,11 +112,15 @@ public final void setWorkerId(final String localworkerId) { * Implememt equals method for WorkerId. */ public final boolean equals(final Object o) { + if (o == null || this.getClass() != o.getClass()) { + return false; + } WorkerId x = (WorkerId) o; return x.getHostname().equals(this.hostname); } /** {@inheritDoc} */ + @Override public final void write(final DataOutput dataOutput) throws IOException { workerId.write(dataOutput); hostname.write(dataOutput); @@ -123,6 +128,7 @@ public final void write(final DataOutput dataOutput) throws IOException { } /** {@inheritDoc} */ + @Override public final void readFields(final DataInput dataInput) throws IOException { workerId.readFields(dataInput); hostname.readFields(dataInput);