use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestDbSourceExactMatchSelector method testMatch.
@Test
public void testMatch() {
ResourceGroupId resourceGroupId1 = new ResourceGroupId(ImmutableList.of("global", "test", "user", "insert"));
ResourceGroupId resourceGroupId2 = new ResourceGroupId(ImmutableList.of("global", "test", "user", "select"));
dao.insertExactMatchSelector("test", "@test@test_pipeline", INSERT.name(), CODEC.toJson(resourceGroupId1));
dao.insertExactMatchSelector("test", "@test@test_pipeline", SELECT.name(), CODEC.toJson(resourceGroupId2));
DbSourceExactMatchSelector selector = new DbSourceExactMatchSelector("test", dao);
assertEquals(selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.empty())), Optional.empty());
assertEquals(selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.of(INSERT.name()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId1));
assertEquals(selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.of(SELECT.name()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId2));
assertEquals(selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.of(DELETE.name()))), Optional.empty());
assertEquals(selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_new"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.of(INSERT.name()))), Optional.empty());
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestQueues method assertResourceGroup.
private void assertResourceGroup(DistributedQueryRunner queryRunner, Session session, String query, ResourceGroupId expectedResourceGroup) throws InterruptedException {
QueryId queryId = createQuery(queryRunner, session, query);
waitForQueryState(queryRunner, queryId, ImmutableSet.of(RUNNING, FINISHED));
Optional<ResourceGroupId> resourceGroupId = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(queryId).getResourceGroupId();
assertTrue(resourceGroupId.isPresent(), "Query should have a resource group");
assertEquals(resourceGroupId.get(), expectedResourceGroup, format("Expected: '%s' resource group, found: %s", expectedResourceGroup, resourceGroupId.get()));
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestDistributedClusterStatsResource method getGlobalQueryCountIfAvailable.
private Optional<Integer> getGlobalQueryCountIfAvailable(QueryState state, TestingPrestoServer coordinator) {
Map<ResourceGroupId, ResourceGroupRuntimeInfo> resourceGroupRuntimeInfoSnapshot = coordinator.getResourceGroupManager().get().getResourceGroupRuntimeInfosSnapshot();
ResourceGroupRuntimeInfo resourceGroupRuntimeInfo = resourceGroupRuntimeInfoSnapshot.get(new ResourceGroupId(RESOURCE_GROUP_GLOBAL));
if (resourceGroupRuntimeInfo == null) {
return Optional.empty();
}
int queryCount = 0;
switch(state) {
case RUNNING:
queryCount = resourceGroupRuntimeInfo.getDescendantRunningQueries();
break;
case QUEUED:
queryCount = resourceGroupRuntimeInfo.getDescendantQueuedQueries();
break;
default:
fail(format("Unexpected query state %s", state));
}
return Optional.of(queryCount);
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestResourceGroupIntegration method waitForGlobalResourceGroup.
public static void waitForGlobalResourceGroup(DistributedQueryRunner queryRunner) throws InterruptedException {
long startTime = System.nanoTime();
while (true) {
SECONDS.sleep(1);
ResourceGroupInfo global = getResourceGroupManager(queryRunner).getResourceGroupInfo(new ResourceGroupId("global"), true, true, true);
if (global.getSoftMemoryLimit().toBytes() > 0) {
break;
}
assertLessThan(nanosSince(startTime).roundTo(SECONDS), 60L);
}
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestDistributedResourceGroupInfoResource method testGetResourceGroupInfo.
@Test(timeOut = 220_000)
public void testGetResourceGroupInfo() throws InterruptedException, TimeoutException {
runToCompletion(client, coordinator1, "SELECT 1", "user1");
runToFirstResult(client, coordinator2, "SELECT * from tpch.sf100.orders", "user1");
runToFirstResult(client, coordinator1, "SELECT * from tpch.sf101.orders", "user2");
waitUntilCoordinatorsDiscoveredHealthyInRM(SECONDS.toMillis(15));
ResourceGroupInfo resourceGroupInfo = getResponseEntity(client, coordinator1, "/v1/resourceGroupState/global", JsonCodec.jsonCodec(ResourceGroupInfo.class));
assertEquals(resourceGroupInfo.getNumRunningQueries(), 2);
Set<ResourceGroupId> subGroupResourceIdSet = resourceGroupInfo.getSubGroups().stream().map(a -> a.getId()).collect(Collectors.toSet());
assertEquals(subGroupResourceIdSet.size(), 2);
assertTrue(subGroupResourceIdSet.contains(new ResourceGroupId(resourceGroupInfo.getId(), "user-user1")));
assertTrue(subGroupResourceIdSet.contains(new ResourceGroupId(resourceGroupInfo.getId(), "user-user2")));
}
Aggregations