diff --git a/server/src/main/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategy.java b/server/src/main/java/org/opensearch/wlm/cancellation/MaximumResourceTaskSelectionStrategy.java
similarity index 94%
rename from server/src/main/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategy.java
rename to server/src/main/java/org/opensearch/wlm/cancellation/MaximumResourceTaskSelectionStrategy.java
index 3bceae9c8ffb1..9407fc32114d0 100644
--- a/server/src/main/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategy.java
+++ b/server/src/main/java/org/opensearch/wlm/cancellation/MaximumResourceTaskSelectionStrategy.java
@@ -22,9 +22,9 @@
/**
* Represents the highest resource consuming task first selection strategy.
*/
-public class HighestResourceConsumingTaskFirstSelectionStrategy implements TaskSelectionStrategy {
+public class MaximumResourceTaskSelectionStrategy implements TaskSelectionStrategy {
- public HighestResourceConsumingTaskFirstSelectionStrategy() {}
+ public MaximumResourceTaskSelectionStrategy() {}
/**
* Returns a comparator that defines the sorting condition for tasks.
diff --git a/server/src/main/java/org/opensearch/wlm/cancellation/TaskCanceller.java b/server/src/main/java/org/opensearch/wlm/cancellation/TaskCanceller.java
index f86e4291eb181..355ebfb838a05 100644
--- a/server/src/main/java/org/opensearch/wlm/cancellation/TaskCanceller.java
+++ b/server/src/main/java/org/opensearch/wlm/cancellation/TaskCanceller.java
@@ -29,7 +29,7 @@
/**
* Manages the cancellation of tasks enforced by QueryGroup thresholds on resource usage criteria.
- * This class utilizes a strategy pattern through {@link HighestResourceConsumingTaskFirstSelectionStrategy} to identify tasks that exceed
+ * This class utilizes a strategy pattern through {@link MaximumResourceTaskSelectionStrategy} to identify tasks that exceed
* predefined resource usage limits and are therefore eligible for cancellation.
*
*
The cancellation process is initiated by evaluating the resource usage of each QueryGroup against its
@@ -40,7 +40,7 @@
* views, a set of active QueryGroups, and a task selection strategy. These components collectively facilitate the
* identification and cancellation of tasks that threaten to breach QueryGroup resource limits.
*
- * @see HighestResourceConsumingTaskFirstSelectionStrategy
+ * @see MaximumResourceTaskSelectionStrategy
* @see QueryGroup
* @see ResourceType
*/
@@ -57,7 +57,7 @@ public class TaskCanceller {
public TaskCanceller(
WorkloadManagementSettings workloadManagementSettings,
- HighestResourceConsumingTaskFirstSelectionStrategy taskSelectionStrategy,
+ MaximumResourceTaskSelectionStrategy taskSelectionStrategy,
Map queryGroupLevelResourceUsageViews,
Collection activeQueryGroups,
Collection deletedQueryGroups,
diff --git a/server/src/main/java/org/opensearch/wlm/tracker/QueryGroupResourceUsageTrackerService.java b/server/src/main/java/org/opensearch/wlm/tracker/QueryGroupResourceUsageTrackerService.java
index f616f29a4d031..ddf65e61a1275 100644
--- a/server/src/main/java/org/opensearch/wlm/tracker/QueryGroupResourceUsageTrackerService.java
+++ b/server/src/main/java/org/opensearch/wlm/tracker/QueryGroupResourceUsageTrackerService.java
@@ -13,6 +13,7 @@
import org.opensearch.wlm.QueryGroupTask;
import org.opensearch.wlm.ResourceType;
+import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
@@ -49,14 +50,17 @@ public Map constructQueryGroupLevelUsa
// Iterate over each QueryGroup entry
for (Map.Entry> queryGroupEntry : tasksByQueryGroup.entrySet()) {
// Compute the QueryGroup resource usage
- final Map resourceUsage = new HashMap<>();
+ final Map queryGroupUsage = new EnumMap<>(ResourceType.class);
for (ResourceType resourceType : TRACKED_RESOURCES) {
double usage = resourceType.getResourceUsageCalculator().calculateResourceUsage(queryGroupEntry.getValue());
- resourceUsage.put(resourceType, usage);
+ queryGroupUsage.put(resourceType, usage);
}
// Add to the QueryGroup View
- queryGroupViews.put(queryGroupEntry.getKey(), new QueryGroupLevelResourceUsageView(resourceUsage, queryGroupEntry.getValue()));
+ queryGroupViews.put(
+ queryGroupEntry.getKey(),
+ new QueryGroupLevelResourceUsageView(queryGroupUsage, queryGroupEntry.getValue())
+ );
}
return queryGroupViews;
}
diff --git a/server/src/test/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategyTests.java b/server/src/test/java/org/opensearch/wlm/cancellation/MaximumResourceTaskSelectionStrategyTests.java
similarity index 88%
rename from server/src/test/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategyTests.java
rename to server/src/test/java/org/opensearch/wlm/cancellation/MaximumResourceTaskSelectionStrategyTests.java
index 96fe0f0462c77..d522a71b630a5 100644
--- a/server/src/test/java/org/opensearch/wlm/cancellation/HighestResourceConsumingTaskFirstSelectionStrategyTests.java
+++ b/server/src/test/java/org/opensearch/wlm/cancellation/MaximumResourceTaskSelectionStrategyTests.java
@@ -26,11 +26,11 @@
import static org.opensearch.wlm.cancellation.TaskCanceller.MIN_VALUE;
import static org.opensearch.wlm.tracker.MemoryUsageCalculator.HEAP_SIZE_BYTES;
-public class HighestResourceConsumingTaskFirstSelectionStrategyTests extends OpenSearchTestCase {
+public class MaximumResourceTaskSelectionStrategyTests extends OpenSearchTestCase {
public void testSelectTasksToCancelSelectsTasksMeetingThreshold_ifReduceByIsGreaterThanZero() {
- HighestResourceConsumingTaskFirstSelectionStrategy testHighestResourceConsumingTaskFirstSelectionStrategy =
- new HighestResourceConsumingTaskFirstSelectionStrategy();
+ MaximumResourceTaskSelectionStrategy testHighestResourceConsumingTaskFirstSelectionStrategy =
+ new MaximumResourceTaskSelectionStrategy();
double reduceBy = 50000.0 / HEAP_SIZE_BYTES;
ResourceType resourceType = ResourceType.MEMORY;
List tasks = getListOfTasks(100);
@@ -51,8 +51,8 @@ public void testSelectTasksToCancelSelectsTasksMeetingThreshold_ifReduceByIsGrea
}
public void testSelectTasksToCancelSelectsTasksMeetingThreshold_ifReduceByIsLesserThanZero() {
- HighestResourceConsumingTaskFirstSelectionStrategy testHighestResourceConsumingTaskFirstSelectionStrategy =
- new HighestResourceConsumingTaskFirstSelectionStrategy();
+ MaximumResourceTaskSelectionStrategy testHighestResourceConsumingTaskFirstSelectionStrategy =
+ new MaximumResourceTaskSelectionStrategy();
double reduceBy = -50.0 / HEAP_SIZE_BYTES;
ResourceType resourceType = ResourceType.MEMORY;
List tasks = getListOfTasks(3);
@@ -65,8 +65,8 @@ public void testSelectTasksToCancelSelectsTasksMeetingThreshold_ifReduceByIsLess
}
public void testSelectTasksToCancelSelectsTasksMeetingThreshold_ifReduceByIsEqualToZero() {
- HighestResourceConsumingTaskFirstSelectionStrategy testHighestResourceConsumingTaskFirstSelectionStrategy =
- new HighestResourceConsumingTaskFirstSelectionStrategy();
+ MaximumResourceTaskSelectionStrategy testHighestResourceConsumingTaskFirstSelectionStrategy =
+ new MaximumResourceTaskSelectionStrategy();
double reduceBy = 0.0;
ResourceType resourceType = ResourceType.MEMORY;
List tasks = getListOfTasks(50);
diff --git a/server/src/test/java/org/opensearch/wlm/cancellation/TaskCancellerTests.java b/server/src/test/java/org/opensearch/wlm/cancellation/TaskCancellerTests.java
index 655d3aea9d5d7..8291b6c4b5b1f 100644
--- a/server/src/test/java/org/opensearch/wlm/cancellation/TaskCancellerTests.java
+++ b/server/src/test/java/org/opensearch/wlm/cancellation/TaskCancellerTests.java
@@ -46,7 +46,7 @@ private static class TestTaskCancellerImpl extends TaskCanceller {
public TestTaskCancellerImpl(
WorkloadManagementSettings workloadManagementSettings,
- HighestResourceConsumingTaskFirstSelectionStrategy highestResourceConsumingTaskFirstSelectionStrategy,
+ MaximumResourceTaskSelectionStrategy highestResourceConsumingTaskFirstSelectionStrategy,
Map queryGroupLevelViews,
Set activeQueryGroups,
Set deletedQueryGroups,
@@ -81,7 +81,7 @@ public void setup() {
when(workloadManagementSettings.getNodeLevelMemoryCancellationThreshold()).thenReturn(0.9);
taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
- new HighestResourceConsumingTaskFirstSelectionStrategy(),
+ new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
@@ -208,7 +208,7 @@ public void testGetCancellableTasksFrom_filtersQueryGroupCorrectly() {
TestTaskCancellerImpl taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
- new HighestResourceConsumingTaskFirstSelectionStrategy(),
+ new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
@@ -241,7 +241,7 @@ public void testCancelTasks_cancelsGivenTasks() {
TestTaskCancellerImpl taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
- new HighestResourceConsumingTaskFirstSelectionStrategy(),
+ new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
@@ -301,7 +301,7 @@ public void testCancelTasks_cancelsTasksFromDeletedQueryGroups() {
TestTaskCancellerImpl taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
- new HighestResourceConsumingTaskFirstSelectionStrategy(),
+ new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
@@ -372,7 +372,7 @@ public void testCancelTasks_does_not_cancelTasksFromDeletedQueryGroups_whenNodeN
TestTaskCancellerImpl taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
- new HighestResourceConsumingTaskFirstSelectionStrategy(),
+ new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
@@ -432,7 +432,7 @@ public void testCancelTasks_cancelsGivenTasks_WhenNodeInDuress() {
TestTaskCancellerImpl taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
- new HighestResourceConsumingTaskFirstSelectionStrategy(),
+ new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,