Search in sources :

Example 1 with RUNNING

use of com.facebook.presto.execution.QueryState.RUNNING in project presto by prestodb.

the class TestQueryStateInfoResource method setup.

@BeforeClass
public void setup() {
    Request request1 = preparePost().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build()).setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8)).setHeader(PRESTO_USER, "user1").build();
    queryResults = client.execute(request1, createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    Request request2 = preparePost().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build()).setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8)).setHeader(PRESTO_USER, "user2").build();
    QueryResults queryResults2 = client.execute(request2, createJsonResponseHandler(jsonCodec(QueryResults.class)));
    client.execute(prepareGet().setUri(queryResults2.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
    // queries are started in the background, so they may not all be immediately visible
    while (true) {
        List<BasicQueryInfo> queryInfos = client.execute(prepareGet().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/query").build()).build(), createJsonResponseHandler(listJsonCodec(BasicQueryInfo.class)));
        if ((queryInfos.size() == 2) && queryInfos.stream().allMatch(info -> info.getState() == RUNNING)) {
            break;
        }
    }
}
Also used : JsonCodec(com.facebook.airlift.json.JsonCodec) Assert.assertEquals(com.facebook.presto.testing.assertions.Assert.assertEquals) Builder.preparePost(com.facebook.airlift.http.client.Request.Builder.preparePost) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) QueryResults(com.facebook.presto.client.QueryResults) Test(org.testng.annotations.Test) JettyHttpClient(com.facebook.airlift.http.client.jetty.JettyHttpClient) JsonCodec.listJsonCodec(com.facebook.airlift.json.JsonCodec.listJsonCodec) UnexpectedResponseException(com.facebook.airlift.http.client.UnexpectedResponseException) JsonResponseHandler.createJsonResponseHandler(com.facebook.airlift.http.client.JsonResponseHandler.createJsonResponseHandler) StaticBodyGenerator.createStaticBodyGenerator(com.facebook.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator) AfterClass(org.testng.annotations.AfterClass) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) PRESTO_USER(com.facebook.presto.client.PrestoHeaders.PRESTO_USER) UTF_8(java.nio.charset.StandardCharsets.UTF_8) BeforeClass(org.testng.annotations.BeforeClass) Assert.assertNotNull(org.testng.Assert.assertNotNull) JsonCodec.jsonCodec(com.facebook.airlift.json.JsonCodec.jsonCodec) HttpClient(com.facebook.airlift.http.client.HttpClient) Closeables.closeQuietly(com.facebook.airlift.testing.Closeables.closeQuietly) HttpUriBuilder.uriBuilderFrom(com.facebook.airlift.http.client.HttpUriBuilder.uriBuilderFrom) List(java.util.List) Request(com.facebook.airlift.http.client.Request) Assert.assertTrue(org.testng.Assert.assertTrue) Builder.prepareGet(com.facebook.airlift.http.client.Request.Builder.prepareGet) Request(com.facebook.airlift.http.client.Request) QueryResults(com.facebook.presto.client.QueryResults) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with RUNNING

use of com.facebook.presto.execution.QueryState.RUNNING in project presto by prestodb.

the class TestResourceManagerClusterStateProvider method assertResourceGroup.

private void assertResourceGroup(ResourceManagerClusterStateProvider provider, String excludingNode, String resourceGroupId, int queuedQueries, int runningQueries, DataSize userMemoryReservation) throws ResourceManagerInconsistentException {
    ResourceGroupId currResourceGroupId = new ResourceGroupId(Arrays.asList(resourceGroupId.split("\\.")));
    List<ResourceGroupRuntimeInfo> list = provider.getClusterResourceGroups(excludingNode);
    Optional<ResourceGroupRuntimeInfo> resourceGroupRuntimeInfo = list.stream().filter(resourceGroupInfo -> currResourceGroupId.equals(resourceGroupInfo.getResourceGroupId())).findFirst();
    assertTrue(resourceGroupRuntimeInfo.isPresent(), "Resource group " + resourceGroupId + " not found");
    ResourceGroupRuntimeInfo info = resourceGroupRuntimeInfo.get();
    ResourceGroupId rg = new ResourceGroupId(Arrays.asList(resourceGroupId.split("\\.")));
    assertEquals(info.getQueuedQueries(), queuedQueries, format("Expected %s queued queries, found %s", queuedQueries, info.getQueuedQueries()));
    assertEquals(info.getRunningQueries(), runningQueries, format("Expected %s running queries, found %s", runningQueries, info.getRunningQueries()));
    assertEquals(info.getResourceGroupId(), rg, format("Expected resource group id %s, found %s", resourceGroupId, info.getResourceGroupId()));
    assertEquals(info.getMemoryUsageBytes(), userMemoryReservation.toBytes(), format("Expected %s user memory reservation found %s", userMemoryReservation, DataSize.succinctBytes(info.getMemoryUsageBytes())));
}
Also used : Arrays(java.util.Arrays) Test(org.testng.annotations.Test) NodeVersion(com.facebook.presto.client.NodeVersion) FINISHING(com.facebook.presto.execution.QueryState.FINISHING) Duration(io.airlift.units.Duration) PLANNING(com.facebook.presto.execution.QueryState.PLANNING) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) WAITING_FOR_MEMORY(com.facebook.presto.operator.BlockedReason.WAITING_FOR_MEMORY) Map(java.util.Map) FAILED(com.facebook.presto.execution.QueryState.FAILED) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DISPATCHING(com.facebook.presto.execution.QueryState.DISPATCHING) WAITING_FOR_RESOURCES(com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Assert.assertNotNull(org.testng.Assert.assertNotNull) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) String.format(java.lang.String.format) DataSize(io.airlift.units.DataSize) List(java.util.List) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) NodeStatus(com.facebook.presto.server.NodeStatus) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) OptionalDouble(java.util.OptionalDouble) Assert.assertEquals(org.testng.Assert.assertEquals) MemoryInfo(com.facebook.presto.memory.MemoryInfo) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) DateTime(org.joda.time.DateTime) FINISHED(com.facebook.presto.execution.QueryState.FINISHED) InternalNode(com.facebook.presto.metadata.InternalNode) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) Assert.assertTrue(org.testng.Assert.assertTrue) STARTING(com.facebook.presto.execution.QueryState.STARTING) QueryState(com.facebook.presto.execution.QueryState) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)

Example 3 with RUNNING

use of com.facebook.presto.execution.QueryState.RUNNING in project presto by prestodb.

the class TestResourceManagerClusterStateProvider method assertNonLeafResourceGroup.

private void assertNonLeafResourceGroup(ResourceManagerClusterStateProvider provider, String excludingNode, String resourceGroupId, int queuedQueries, int runningQueries, int descendantQueuedQueries, int descendantRunningQueries) throws ResourceManagerInconsistentException {
    List<ResourceGroupRuntimeInfo> resourceGroupRuntimeInfos = provider.getClusterResourceGroups(excludingNode);
    Optional<ResourceGroupRuntimeInfo> resourceGroupRuntimeInfo = provider.getClusterResourceGroups(excludingNode).stream().filter(resourceGroupInfo -> new ResourceGroupId(resourceGroupId).equals(resourceGroupInfo.getResourceGroupId())).findFirst();
    assertTrue(resourceGroupRuntimeInfo.isPresent(), "Resource group " + resourceGroupId + " not found");
    ResourceGroupRuntimeInfo info = resourceGroupRuntimeInfo.get();
    assertEquals(info.getQueuedQueries(), queuedQueries, format("Expected %s queued queries, found %s", queuedQueries, info.getQueuedQueries()));
    assertEquals(info.getRunningQueries(), runningQueries, format("Expected %s running queries, found %s", runningQueries, info.getRunningQueries()));
    assertEquals(info.getDescendantQueuedQueries(), descendantQueuedQueries, format("Expected %s descendant queued queries, found %s", descendantQueuedQueries, info.getDescendantQueuedQueries()));
    assertEquals(info.getDescendantRunningQueries(), descendantRunningQueries, format("Expected %s descendant running queries, found %s", descendantRunningQueries, info.getDescendantRunningQueries()));
    assertEquals(info.getResourceGroupId(), new ResourceGroupId(resourceGroupId), format("Expected resource group id %s, found %s", resourceGroupId, info.getResourceGroupId()));
}
Also used : Arrays(java.util.Arrays) Test(org.testng.annotations.Test) NodeVersion(com.facebook.presto.client.NodeVersion) FINISHING(com.facebook.presto.execution.QueryState.FINISHING) Duration(io.airlift.units.Duration) PLANNING(com.facebook.presto.execution.QueryState.PLANNING) RESERVED_POOL(com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) WAITING_FOR_MEMORY(com.facebook.presto.operator.BlockedReason.WAITING_FOR_MEMORY) Map(java.util.Map) FAILED(com.facebook.presto.execution.QueryState.FAILED) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DISPATCHING(com.facebook.presto.execution.QueryState.DISPATCHING) WAITING_FOR_RESOURCES(com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Assert.assertNotNull(org.testng.Assert.assertNotNull) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo) String.format(java.lang.String.format) DataSize(io.airlift.units.DataSize) List(java.util.List) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) NodeStatus(com.facebook.presto.server.NodeStatus) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) OptionalDouble(java.util.OptionalDouble) Assert.assertEquals(org.testng.Assert.assertEquals) MemoryInfo(com.facebook.presto.memory.MemoryInfo) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) MemoryPoolInfo(com.facebook.presto.spi.memory.MemoryPoolInfo) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) DateTime(org.joda.time.DateTime) FINISHED(com.facebook.presto.execution.QueryState.FINISHED) InternalNode(com.facebook.presto.metadata.InternalNode) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) ClusterMemoryPoolInfo(com.facebook.presto.spi.memory.ClusterMemoryPoolInfo) QueryId(com.facebook.presto.spi.QueryId) Assert.assertTrue(org.testng.Assert.assertTrue) STARTING(com.facebook.presto.execution.QueryState.STARTING) QueryState(com.facebook.presto.execution.QueryState) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupRuntimeInfo(com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)

Aggregations

RUNNING (com.facebook.presto.execution.QueryState.RUNNING)3 List (java.util.List)3 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)2 NodeVersion (com.facebook.presto.client.NodeVersion)2 QueryState (com.facebook.presto.execution.QueryState)2 DISPATCHING (com.facebook.presto.execution.QueryState.DISPATCHING)2 FAILED (com.facebook.presto.execution.QueryState.FAILED)2 FINISHED (com.facebook.presto.execution.QueryState.FINISHED)2 FINISHING (com.facebook.presto.execution.QueryState.FINISHING)2 PLANNING (com.facebook.presto.execution.QueryState.PLANNING)2 QUEUED (com.facebook.presto.execution.QueryState.QUEUED)2 STARTING (com.facebook.presto.execution.QueryState.STARTING)2 WAITING_FOR_RESOURCES (com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES)2 ResourceGroupRuntimeInfo (com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)2 GENERAL_POOL (com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL)2 RESERVED_POOL (com.facebook.presto.memory.LocalMemoryManager.RESERVED_POOL)2 MemoryInfo (com.facebook.presto.memory.MemoryInfo)2 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)2 InternalNode (com.facebook.presto.metadata.InternalNode)2 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)2