Search in sources :

Example 36 with ResourceGroupId

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());
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) SelectionCriteria(com.facebook.presto.spi.resourceGroups.SelectionCriteria) Test(org.testng.annotations.Test)

Example 37 with ResourceGroupId

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()));
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) QueryId(com.facebook.presto.spi.QueryId)

Example 38 with ResourceGroupId

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);
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)

Example 39 with ResourceGroupId

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);
    }
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupInfo(com.facebook.presto.server.ResourceGroupInfo)

Example 40 with ResourceGroupId

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")));
}
Also used : JsonCodec(com.facebook.airlift.json.JsonCodec) ResourceGroupInfo(com.facebook.presto.server.ResourceGroupInfo) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) TimeoutException(java.util.concurrent.TimeoutException) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) JettyHttpClient(com.facebook.airlift.http.client.jetty.JettyHttpClient) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) FileResourceGroupConfigurationManagerFactory(com.facebook.presto.resourceGroups.FileResourceGroupConfigurationManagerFactory) UnexpectedResponseException(com.facebook.airlift.http.client.UnexpectedResponseException) Thread.sleep(java.lang.Thread.sleep) AfterClass(org.testng.annotations.AfterClass) ImmutableMap(com.google.common.collect.ImmutableMap) ResourceUtils.getResourceFilePath(com.facebook.presto.utils.ResourceUtils.getResourceFilePath) BeforeClass(org.testng.annotations.BeforeClass) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Set(java.util.Set) QueryExecutionClientUtil.runToCompletion(com.facebook.presto.utils.QueryExecutionClientUtil.runToCompletion) Collectors(java.util.stream.Collectors) Closeables.closeQuietly(com.facebook.airlift.testing.Closeables.closeQuietly) AllNodes(com.facebook.presto.metadata.AllNodes) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) QueryExecutionClientUtil.runToFirstResult(com.facebook.presto.utils.QueryExecutionClientUtil.runToFirstResult) QueryExecutionClientUtil.getResponseEntity(com.facebook.presto.utils.QueryExecutionClientUtil.getResponseEntity) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) TpchQueryRunner.createQueryRunner(com.facebook.presto.tests.tpch.TpchQueryRunner.createQueryRunner) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupInfo(com.facebook.presto.server.ResourceGroupInfo) Test(org.testng.annotations.Test)

Aggregations

ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)41 Test (org.testng.annotations.Test)31 QueryId (com.facebook.presto.spi.QueryId)12 ResourceGroupRuntimeInfo (com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)9 ResourceGroupInfo (com.facebook.presto.server.ResourceGroupInfo)5 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Duration (io.airlift.units.Duration)5 String.format (java.lang.String.format)5 Optional (java.util.Optional)5 TestQueues.createResourceGroupId (com.facebook.presto.execution.TestQueues.createResourceGroupId)4 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)4 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)3 DataSize (io.airlift.units.DataSize)3 HashMap (java.util.HashMap)3 SECONDS (java.util.concurrent.TimeUnit.SECONDS)3 Assert.assertEquals (org.testng.Assert.assertEquals)3 Assert.assertTrue (org.testng.Assert.assertTrue)3 Session (com.facebook.presto.Session)2 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)2