Skip to content

Commit

Permalink
Remove @nullable usage from ResourceGroupInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Aug 28, 2019
1 parent 57e18a2 commit b2482b4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ public ResourceGroupInfo getFullInfo()
getQueuedQueries(),
getRunningQueries(),
eligibleSubGroups.size(),
subGroups.values().stream()
Optional.of(subGroups.values().stream()
.filter(group -> group.getRunningQueries() + group.getQueuedQueries() > 0)
.map(InternalResourceGroup::getSummaryInfo)
.collect(toImmutableList()),
getAggregatedRunningQueriesInfo());
.collect(toImmutableList())),
Optional.of(getAggregatedRunningQueriesInfo()));
}
}

Expand All @@ -193,11 +193,11 @@ public ResourceGroupInfo getInfo()
getQueuedQueries(),
getRunningQueries(),
eligibleSubGroups.size(),
subGroups.values().stream()
Optional.of(subGroups.values().stream()
.filter(group -> group.getRunningQueries() + group.getQueuedQueries() > 0)
.map(InternalResourceGroup::getSummaryInfo)
.collect(toImmutableList()),
null);
.collect(toImmutableList())),
Optional.empty());
}
}

Expand All @@ -218,8 +218,8 @@ private ResourceGroupInfo getSummaryInfo()
getQueuedQueries(),
getRunningQueries(),
eligibleSubGroups.size(),
null,
null);
Optional.empty(),
Optional.empty());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.prestosql.server;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import io.airlift.units.DataSize;
import io.airlift.units.Duration;
import io.prestosql.spi.resourcegroups.ResourceGroupId;
Expand All @@ -23,6 +24,7 @@
import javax.annotation.Nullable;

import java.util.List;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

Expand All @@ -49,9 +51,8 @@ public class ResourceGroupInfo
private final int numRunningQueries;
private final int numEligibleSubGroups;

// Summaries do not include the following fields
private final List<ResourceGroupInfo> subGroups;
private final List<QueryStateInfo> runningQueries;
private final Optional<List<ResourceGroupInfo>> subGroups;
private final Optional<List<QueryStateInfo>> runningQueries;

public ResourceGroupInfo(
ResourceGroupId id,
Expand All @@ -71,8 +72,8 @@ public ResourceGroupInfo(
int numRunningQueries,
int numEligibleSubGroups,

@Nullable List<ResourceGroupInfo> subGroups,
@Nullable List<QueryStateInfo> runningQueries)
Optional<List<ResourceGroupInfo>> subGroups,
Optional<List<QueryStateInfo>> runningQueries)
{
this.id = requireNonNull(id, "id is null");
this.state = requireNonNull(state, "state is null");
Expand All @@ -92,8 +93,8 @@ public ResourceGroupInfo(
this.numRunningQueries = numRunningQueries;
this.numEligibleSubGroups = numEligibleSubGroups;

this.subGroups = subGroups;
this.runningQueries = runningQueries;
this.subGroups = requireNonNull(subGroups, "subGroups is null").map(ImmutableList::copyOf);
this.runningQueries = requireNonNull(runningQueries, "runningQueries is null").map(ImmutableList::copyOf);
}

@JsonProperty
Expand Down Expand Up @@ -175,15 +176,14 @@ public int getNumEligibleSubGroups()
}

@JsonProperty
@Nullable
public List<ResourceGroupInfo> getSubGroups()
public Optional<List<ResourceGroupInfo>> getSubGroups()
{
return subGroups;
}

@JsonProperty
@Nullable
public List<QueryStateInfo> getRunningQueries()
public Optional<List<QueryStateInfo>> getRunningQueries()
{
return runningQueries;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,31 +1078,33 @@ public void testGetResourceGroupStateInfo()
assertEquals(rootInfo.getSoftMemoryLimit(), root.getSoftMemoryLimit());
assertEquals(rootInfo.getMemoryUsage(), new DataSize(0, BYTE));
assertEquals(rootInfo.getCpuUsage(), new Duration(0, MILLISECONDS));
assertEquals(rootInfo.getSubGroups().size(), 2);
assertGroupInfoEquals(rootInfo.getSubGroups().get(0), rootA.getInfo());
assertEquals(rootInfo.getSubGroups().get(0).getId(), rootA.getId());
assertEquals(rootInfo.getSubGroups().get(0).getState(), CAN_QUEUE);
assertEquals(rootInfo.getSubGroups().get(0).getSoftMemoryLimit(), rootA.getSoftMemoryLimit());
assertEquals(rootInfo.getSubGroups().get(0).getHardConcurrencyLimit(), rootA.getHardConcurrencyLimit());
assertEquals(rootInfo.getSubGroups().get(0).getMaxQueuedQueries(), rootA.getMaxQueuedQueries());
assertEquals(rootInfo.getSubGroups().get(0).getNumEligibleSubGroups(), 2);
assertEquals(rootInfo.getSubGroups().get(0).getNumRunningQueries(), 0);
assertEquals(rootInfo.getSubGroups().get(0).getNumQueuedQueries(), 10);
assertGroupInfoEquals(rootInfo.getSubGroups().get(1), rootB.getInfo());
assertEquals(rootInfo.getSubGroups().get(1).getId(), rootB.getId());
assertEquals(rootInfo.getSubGroups().get(1).getState(), CAN_QUEUE);
assertEquals(rootInfo.getSubGroups().get(1).getSoftMemoryLimit(), rootB.getSoftMemoryLimit());
assertEquals(rootInfo.getSubGroups().get(1).getHardConcurrencyLimit(), rootB.getHardConcurrencyLimit());
assertEquals(rootInfo.getSubGroups().get(1).getMaxQueuedQueries(), rootB.getMaxQueuedQueries());
assertEquals(rootInfo.getSubGroups().get(1).getNumEligibleSubGroups(), 0);
assertEquals(rootInfo.getSubGroups().get(1).getNumRunningQueries(), 1);
assertEquals(rootInfo.getSubGroups().get(1).getNumQueuedQueries(), 9);
List<ResourceGroupInfo> subGroups = rootInfo.getSubGroups().get();
assertEquals(subGroups.size(), 2);
assertGroupInfoEquals(subGroups.get(0), rootA.getInfo());
assertEquals(subGroups.get(0).getId(), rootA.getId());
assertEquals(subGroups.get(0).getState(), CAN_QUEUE);
assertEquals(subGroups.get(0).getSoftMemoryLimit(), rootA.getSoftMemoryLimit());
assertEquals(subGroups.get(0).getHardConcurrencyLimit(), rootA.getHardConcurrencyLimit());
assertEquals(subGroups.get(0).getMaxQueuedQueries(), rootA.getMaxQueuedQueries());
assertEquals(subGroups.get(0).getNumEligibleSubGroups(), 2);
assertEquals(subGroups.get(0).getNumRunningQueries(), 0);
assertEquals(subGroups.get(0).getNumQueuedQueries(), 10);
assertGroupInfoEquals(subGroups.get(1), rootB.getInfo());
assertEquals(subGroups.get(1).getId(), rootB.getId());
assertEquals(subGroups.get(1).getState(), CAN_QUEUE);
assertEquals(subGroups.get(1).getSoftMemoryLimit(), rootB.getSoftMemoryLimit());
assertEquals(subGroups.get(1).getHardConcurrencyLimit(), rootB.getHardConcurrencyLimit());
assertEquals(subGroups.get(1).getMaxQueuedQueries(), rootB.getMaxQueuedQueries());
assertEquals(subGroups.get(1).getNumEligibleSubGroups(), 0);
assertEquals(subGroups.get(1).getNumRunningQueries(), 1);
assertEquals(subGroups.get(1).getNumQueuedQueries(), 9);
assertEquals(rootInfo.getSoftConcurrencyLimit(), root.getSoftConcurrencyLimit());
assertEquals(rootInfo.getHardConcurrencyLimit(), root.getHardConcurrencyLimit());
assertEquals(rootInfo.getMaxQueuedQueries(), root.getMaxQueuedQueries());
assertEquals(rootInfo.getNumQueuedQueries(), 19);
assertEquals(rootInfo.getRunningQueries().size(), 1);
QueryStateInfo queryInfo = rootInfo.getRunningQueries().get(0);
List<QueryStateInfo> runningQueries = rootInfo.getRunningQueries().get();
assertEquals(runningQueries.size(), 1);
QueryStateInfo queryInfo = runningQueries.get(0);
assertEquals(queryInfo.getResourceGroupId(), Optional.of(rootB.getId()));
}

Expand Down

0 comments on commit b2482b4

Please sign in to comment.