Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kaushal Kumar <[email protected]>
  • Loading branch information
kaushalmahi12 committed Aug 30, 2024
1 parent fd8f3f5 commit d89422b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 4 additions & 2 deletions server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,10 @@ protected Node(

final QueryGroupService queryGroupService = new QueryGroupService(); // We will need to replace this with actual instance of the
// queryGroupService
final QueryGroupRequestOperationListener queryGroupRequestRejectionListener =
new QueryGroupRequestOperationListener(queryGroupService, threadPool);
final QueryGroupRequestOperationListener queryGroupRequestRejectionListener = new QueryGroupRequestOperationListener(
queryGroupService,
threadPool
);

// register all standard SearchRequestOperationsCompositeListenerFactory to the SearchRequestOperationsCompositeListenerFactory
final SearchRequestOperationsCompositeListenerFactory searchRequestOperationsCompositeListenerFactory =
Expand Down
7 changes: 7 additions & 0 deletions server/src/main/java/org/opensearch/wlm/ResourceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.opensearch.tasks.Task;

import java.io.IOException;
import java.util.List;
import java.util.function.Function;

/**
Expand All @@ -30,6 +31,8 @@ public enum ResourceType {
private final Function<Task, Long> getResourceUsage;
private final boolean statsEnabled;

private static List<ResourceType> sortedValues = List.of(CPU, MEMORY);

ResourceType(String name, Function<Task, Long> getResourceUsage, boolean statsEnabled) {
this.name = name;
this.getResourceUsage = getResourceUsage;
Expand Down Expand Up @@ -71,4 +74,8 @@ public long getResourceUsage(Task task) {
public boolean hasStatsEnabled() {
return statsEnabled;
}

public static List<ResourceType> getSortedValues() {
return sortedValues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field(FAILURES, failures);
builder.field(TOTAL_CANCELLATIONS, totalCancellations);

List<Map.Entry<ResourceType, ResourceStats>> entryList = new ArrayList<>(resourceStats.entrySet());
entryList.sort((k1, k2) -> k1.getKey().compareTo(k2.getKey()));

for (Map.Entry<ResourceType, ResourceStats> resourceStat : entryList) {
ResourceType resourceType = resourceStat.getKey();
ResourceStats resourceStats1 = resourceStat.getValue();
for (ResourceType resourceType : ResourceType.getSortedValues()) {
ResourceStats resourceStats1 = resourceStats.get(resourceType);
if (resourceStats1 == null) continue;
builder.startObject(resourceType.getName());
resourceStats1.toXContent(builder, params);
builder.endObject();
Expand Down

0 comments on commit d89422b

Please sign in to comment.