From 681194f9d9c869b9b431045857d921505773fb34 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Wed, 18 Sep 2024 15:00:53 -0400 Subject: [PATCH] Fix breaking API changes introduced during the release window (#15980) Signed-off-by: Andriy Redko --- .../java/org/opensearch/wlm/ResourceType.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/main/java/org/opensearch/wlm/ResourceType.java b/server/src/main/java/org/opensearch/wlm/ResourceType.java index 01d1d1fb63880..186f4b671ade1 100644 --- a/server/src/main/java/org/opensearch/wlm/ResourceType.java +++ b/server/src/main/java/org/opensearch/wlm/ResourceType.java @@ -10,6 +10,7 @@ import org.opensearch.common.annotation.PublicApi; import org.opensearch.core.common.io.stream.StreamOutput; +import org.opensearch.tasks.Task; import org.opensearch.wlm.tracker.CpuUsageCalculator; import org.opensearch.wlm.tracker.MemoryUsageCalculator; import org.opensearch.wlm.tracker.ResourceUsageCalculator; @@ -69,6 +70,21 @@ public String getName() { return name; } + /** + * Gets the resource usage for a given resource type and task. + * + * @param task the task for which to calculate resource usage + * @return the resource usage + */ + @Deprecated(forRemoval = true) + public long getResourceUsage(Task task) { + if (name.equals(CPU.name)) { + return task.getTotalResourceStats().getCpuTimeInNanos(); + } else { + return task.getTotalResourceStats().getMemoryInBytes(); + } + } + public boolean hasStatsEnabled() { return statsEnabled; }