Skip to content

Commit

Permalink
add rename changes
Browse files Browse the repository at this point in the history
Signed-off-by: Kaushal Kumar <[email protected]>
  • Loading branch information
kaushalmahi12 committed Sep 9, 2024
1 parent 91893e7 commit 66e43b2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>The cancellation process is initiated by evaluating the resource usage of each QueryGroup against its
Expand All @@ -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.</p>
*
* @see HighestResourceConsumingTaskFirstSelectionStrategy
* @see MaximumResourceTaskSelectionStrategy
* @see QueryGroup
* @see ResourceType
*/
Expand All @@ -57,7 +57,7 @@ public class TaskCanceller {

public TaskCanceller(
WorkloadManagementSettings workloadManagementSettings,
HighestResourceConsumingTaskFirstSelectionStrategy taskSelectionStrategy,
MaximumResourceTaskSelectionStrategy taskSelectionStrategy,
Map<String, QueryGroupLevelResourceUsageView> queryGroupLevelResourceUsageViews,
Collection<QueryGroup> activeQueryGroups,
Collection<QueryGroup> deletedQueryGroups,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,14 +50,17 @@ public Map<String, QueryGroupLevelResourceUsageView> constructQueryGroupLevelUsa
// Iterate over each QueryGroup entry
for (Map.Entry<String, List<QueryGroupTask>> queryGroupEntry : tasksByQueryGroup.entrySet()) {
// Compute the QueryGroup resource usage
final Map<ResourceType, Double> resourceUsage = new HashMap<>();
final Map<ResourceType, Double> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<QueryGroupTask> tasks = getListOfTasks(100);
Expand All @@ -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<QueryGroupTask> tasks = getListOfTasks(3);
Expand All @@ -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<QueryGroupTask> tasks = getListOfTasks(50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static class TestTaskCancellerImpl extends TaskCanceller {

public TestTaskCancellerImpl(
WorkloadManagementSettings workloadManagementSettings,
HighestResourceConsumingTaskFirstSelectionStrategy highestResourceConsumingTaskFirstSelectionStrategy,
MaximumResourceTaskSelectionStrategy highestResourceConsumingTaskFirstSelectionStrategy,
Map<String, QueryGroupLevelResourceUsageView> queryGroupLevelViews,
Set<QueryGroup> activeQueryGroups,
Set<QueryGroup> deletedQueryGroups,
Expand Down Expand Up @@ -81,7 +81,7 @@ public void setup() {
when(workloadManagementSettings.getNodeLevelMemoryCancellationThreshold()).thenReturn(0.9);
taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
new HighestResourceConsumingTaskFirstSelectionStrategy(),
new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
Expand Down Expand Up @@ -208,7 +208,7 @@ public void testGetCancellableTasksFrom_filtersQueryGroupCorrectly() {

TestTaskCancellerImpl taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
new HighestResourceConsumingTaskFirstSelectionStrategy(),
new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
Expand Down Expand Up @@ -241,7 +241,7 @@ public void testCancelTasks_cancelsGivenTasks() {

TestTaskCancellerImpl taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
new HighestResourceConsumingTaskFirstSelectionStrategy(),
new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
Expand Down Expand Up @@ -301,7 +301,7 @@ public void testCancelTasks_cancelsTasksFromDeletedQueryGroups() {

TestTaskCancellerImpl taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
new HighestResourceConsumingTaskFirstSelectionStrategy(),
new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
Expand Down Expand Up @@ -372,7 +372,7 @@ public void testCancelTasks_does_not_cancelTasksFromDeletedQueryGroups_whenNodeN

TestTaskCancellerImpl taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
new HighestResourceConsumingTaskFirstSelectionStrategy(),
new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
Expand Down Expand Up @@ -432,7 +432,7 @@ public void testCancelTasks_cancelsGivenTasks_WhenNodeInDuress() {

TestTaskCancellerImpl taskCancellation = new TestTaskCancellerImpl(
workloadManagementSettings,
new HighestResourceConsumingTaskFirstSelectionStrategy(),
new MaximumResourceTaskSelectionStrategy(),
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups,
Expand Down

0 comments on commit 66e43b2

Please sign in to comment.