From d2576584a082be33cc540be57a9b33798aeed50e Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Mon, 11 Jul 2022 07:25:22 -0700 Subject: [PATCH] Consolidate the two TaskStatus classes. (#12765) * Consolidate the two TaskStatus classes. There are two, but we don't need more than one. * Fix import order. --- .../org/apache/druid/indexer/TaskStatus.java | 4 +- .../shuffle/LocalIntermediaryDataManager.java | 2 +- ...ntermediaryDataManagerAutoCleanupTest.java | 4 +- .../worker/shuffle/ShuffleResourceTest.java | 4 +- .../druid/client/indexing/TaskStatus.java | 101 ------------------ .../druid/rpc/indexing/OverlordClient.java | 2 +- .../rpc/indexing/OverlordClientImpl.java | 2 +- .../client/indexing/NoopOverlordClient.java | 1 + 8 files changed, 10 insertions(+), 110 deletions(-) delete mode 100644 server/src/main/java/org/apache/druid/client/indexing/TaskStatus.java diff --git a/core/src/main/java/org/apache/druid/indexer/TaskStatus.java b/core/src/main/java/org/apache/druid/indexer/TaskStatus.java index c6b17bc1e00..d3290bd88b1 100644 --- a/core/src/main/java/org/apache/druid/indexer/TaskStatus.java +++ b/core/src/main/java/org/apache/druid/indexer/TaskStatus.java @@ -96,11 +96,11 @@ public class TaskStatus private final TaskLocation location; @JsonCreator - protected TaskStatus( + public TaskStatus( @JsonProperty("id") String id, @JsonProperty("status") TaskState status, @JsonProperty("duration") long duration, - @JsonProperty("errorMsg") @Nullable String errorMsg, + @Nullable @JsonProperty("errorMsg") String errorMsg, @Nullable @JsonProperty("location") TaskLocation location ) { diff --git a/indexing-service/src/main/java/org/apache/druid/indexing/worker/shuffle/LocalIntermediaryDataManager.java b/indexing-service/src/main/java/org/apache/druid/indexing/worker/shuffle/LocalIntermediaryDataManager.java index 175b7c9eb83..d94516f9cae 100644 --- a/indexing-service/src/main/java/org/apache/druid/indexing/worker/shuffle/LocalIntermediaryDataManager.java +++ b/indexing-service/src/main/java/org/apache/druid/indexing/worker/shuffle/LocalIntermediaryDataManager.java @@ -25,10 +25,10 @@ import com.google.common.io.ByteSource; import com.google.common.io.Files; import com.google.inject.Inject; import org.apache.commons.lang3.mutable.MutableInt; -import org.apache.druid.client.indexing.TaskStatus; import org.apache.druid.common.guava.FutureUtils; import org.apache.druid.common.utils.IdUtils; import org.apache.druid.guice.ManageLifecycle; +import org.apache.druid.indexer.TaskStatus; import org.apache.druid.indexing.common.TaskToolbox; import org.apache.druid.indexing.common.config.TaskConfig; import org.apache.druid.indexing.common.task.batch.parallel.GenericPartitionStat; diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/worker/shuffle/LocalIntermediaryDataManagerAutoCleanupTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/worker/shuffle/LocalIntermediaryDataManagerAutoCleanupTest.java index 9b3a258df6d..41508cb2d6b 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/worker/shuffle/LocalIntermediaryDataManagerAutoCleanupTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/worker/shuffle/LocalIntermediaryDataManagerAutoCleanupTest.java @@ -25,8 +25,8 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import org.apache.commons.io.FileUtils; import org.apache.druid.client.indexing.NoopOverlordClient; -import org.apache.druid.client.indexing.TaskStatus; import org.apache.druid.indexer.TaskState; +import org.apache.druid.indexer.TaskStatus; import org.apache.druid.indexing.common.config.TaskConfig; import org.apache.druid.indexing.worker.config.WorkerConfig; import org.apache.druid.java.util.common.Intervals; @@ -87,7 +87,7 @@ public class LocalIntermediaryDataManagerAutoCleanupTest final Map result = new HashMap<>(); for (String taskId : taskIds) { TaskState state = taskId.startsWith("running_") ? TaskState.RUNNING : TaskState.SUCCESS; - result.put(taskId, new TaskStatus(taskId, state, 10)); + result.put(taskId, new TaskStatus(taskId, state, 10, null, null)); } return Futures.immediateFuture(result); } diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/worker/shuffle/ShuffleResourceTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/worker/shuffle/ShuffleResourceTest.java index c795c473dad..af8bef4e875 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/worker/shuffle/ShuffleResourceTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/worker/shuffle/ShuffleResourceTest.java @@ -25,8 +25,8 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import org.apache.commons.io.FileUtils; import org.apache.druid.client.indexing.NoopOverlordClient; -import org.apache.druid.client.indexing.TaskStatus; import org.apache.druid.indexer.TaskState; +import org.apache.druid.indexer.TaskStatus; import org.apache.druid.indexing.common.config.TaskConfig; import org.apache.druid.indexing.worker.config.WorkerConfig; import org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics; @@ -112,7 +112,7 @@ public class ShuffleResourceTest { final Map result = new HashMap<>(); for (String taskId : taskIds) { - result.put(taskId, new TaskStatus(taskId, TaskState.SUCCESS, 10)); + result.put(taskId, new TaskStatus(taskId, TaskState.SUCCESS, 10, null, null)); } return Futures.immediateFuture(result); } diff --git a/server/src/main/java/org/apache/druid/client/indexing/TaskStatus.java b/server/src/main/java/org/apache/druid/client/indexing/TaskStatus.java deleted file mode 100644 index cb506876cd3..00000000000 --- a/server/src/main/java/org/apache/druid/client/indexing/TaskStatus.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.druid.client.indexing; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; -import org.apache.druid.indexer.TaskState; - -/** - * Should be synced with org.apache.druid.indexing.common.TaskStatus - */ -public class TaskStatus -{ - private final String id; - private final TaskState status; - private final long duration; - - @JsonCreator - public TaskStatus( - @JsonProperty("id") String id, - @JsonProperty("status") TaskState status, - @JsonProperty("duration") long duration - ) - { - this.id = id; - this.status = status; - this.duration = duration; - - // Check class invariants. - Preconditions.checkNotNull(id, "id"); - Preconditions.checkNotNull(status, "status"); - } - - @JsonProperty("id") - public String getId() - { - return id; - } - - @JsonProperty("status") - public TaskState getStatusCode() - { - return status; - } - - @JsonProperty("duration") - public long getDuration() - { - return duration; - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TaskStatus that = (TaskStatus) o; - return duration == that.duration && - java.util.Objects.equals(id, that.id) && - status == that.status; - } - - @Override - public int hashCode() - { - return java.util.Objects.hash(id, status, duration); - } - - @Override - public String toString() - { - return Objects.toStringHelper(this) - .add("id", id) - .add("status", status) - .add("duration", duration) - .toString(); - } -} diff --git a/server/src/main/java/org/apache/druid/rpc/indexing/OverlordClient.java b/server/src/main/java/org/apache/druid/rpc/indexing/OverlordClient.java index 9429c120b4f..85344e8cdbd 100644 --- a/server/src/main/java/org/apache/druid/rpc/indexing/OverlordClient.java +++ b/server/src/main/java/org/apache/druid/rpc/indexing/OverlordClient.java @@ -20,8 +20,8 @@ package org.apache.druid.rpc.indexing; import com.google.common.util.concurrent.ListenableFuture; -import org.apache.druid.client.indexing.TaskStatus; import org.apache.druid.client.indexing.TaskStatusResponse; +import org.apache.druid.indexer.TaskStatus; import org.apache.druid.rpc.ServiceRetryPolicy; import java.util.Map; diff --git a/server/src/main/java/org/apache/druid/rpc/indexing/OverlordClientImpl.java b/server/src/main/java/org/apache/druid/rpc/indexing/OverlordClientImpl.java index 5be78f92a63..4b9cfd7433f 100644 --- a/server/src/main/java/org/apache/druid/rpc/indexing/OverlordClientImpl.java +++ b/server/src/main/java/org/apache/druid/rpc/indexing/OverlordClientImpl.java @@ -23,9 +23,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.ListenableFuture; -import org.apache.druid.client.indexing.TaskStatus; import org.apache.druid.client.indexing.TaskStatusResponse; import org.apache.druid.common.guava.FutureUtils; +import org.apache.druid.indexer.TaskStatus; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.jackson.JacksonUtils; import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler; diff --git a/server/src/test/java/org/apache/druid/client/indexing/NoopOverlordClient.java b/server/src/test/java/org/apache/druid/client/indexing/NoopOverlordClient.java index eb39ff65ece..907973edcf7 100644 --- a/server/src/test/java/org/apache/druid/client/indexing/NoopOverlordClient.java +++ b/server/src/test/java/org/apache/druid/client/indexing/NoopOverlordClient.java @@ -20,6 +20,7 @@ package org.apache.druid.client.indexing; import com.google.common.util.concurrent.ListenableFuture; +import org.apache.druid.indexer.TaskStatus; import org.apache.druid.rpc.ServiceRetryPolicy; import org.apache.druid.rpc.indexing.OverlordClient;