Search in sources :

Example 6 with SelectionCriteria

use of io.trino.spi.resourcegroups.SelectionCriteria in project trino by trinodb.

the class TestFileResourceGroupConfigurationManager method testDocsExample.

@Test
public void testDocsExample() {
    // arbitrary uneven value for testing
    long memoryPoolSize = 31415926535900L;
    FileResourceGroupConfigurationManager manager = new FileResourceGroupConfigurationManager((listener) -> listener.accept(new MemoryPoolInfo(memoryPoolSize, 0, 0, ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of())), new FileResourceGroupConfig().setConfigFile("../../docs/src/main/sphinx/admin/resource-groups-example.json"));
    SelectionContext<ResourceGroupIdTemplate> selectionContext = match(manager, new SelectionCriteria(true, "Alice", ImmutableSet.of(), Optional.of("jdbc#powerfulbi"), ImmutableSet.of("hipri"), EMPTY_RESOURCE_ESTIMATES, Optional.of("select")));
    assertEquals(selectionContext.getResourceGroupId().toString(), "global.adhoc.bi-powerfulbi.Alice");
    TestingResourceGroup resourceGroup = new TestingResourceGroup(selectionContext.getResourceGroupId());
    manager.configure(resourceGroup, selectionContext);
    assertEquals(resourceGroup.getHardConcurrencyLimit(), 3);
    assertEquals(resourceGroup.getMaxQueuedQueries(), 10);
    assertEquals(resourceGroup.getSoftMemoryLimitBytes(), memoryPoolSize / 10);
}
Also used : SelectionCriteria(io.trino.spi.resourcegroups.SelectionCriteria) MemoryPoolInfo(io.trino.spi.memory.MemoryPoolInfo) Test(org.testng.annotations.Test)

Example 7 with SelectionCriteria

use of io.trino.spi.resourcegroups.SelectionCriteria in project trino by trinodb.

the class TestResourceGroupIdTemplate method testUnresolvedVariableRunTime.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "unresolved variable 'pipeline' in resource group '\\$\\{pipeline\\}', available.*")
public void testUnresolvedVariableRunTime() {
    ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.${pipeline}.${USER}");
    Pattern sourcePattern = Pattern.compile("scheduler.important.(testpipeline\\[|(?<pipeline>[^\\[]*)).*");
    StaticSelector selector = new StaticSelector(Optional.empty(), Optional.empty(), Optional.of(sourcePattern), Optional.empty(), Optional.empty(), Optional.empty(), template);
    SelectionCriteria context = new SelectionCriteria(true, "user", ImmutableSet.of(), Optional.of("scheduler.important.testpipeline[5]"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
    selector.match(context);
}
Also used : Pattern(java.util.regex.Pattern) SelectionCriteria(io.trino.spi.resourcegroups.SelectionCriteria) Test(org.testng.annotations.Test)

Example 8 with SelectionCriteria

use of io.trino.spi.resourcegroups.SelectionCriteria in project trino by trinodb.

the class TestResourceGroupIdTemplate method testExtraction.

@Test
public void testExtraction() {
    ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.job_${pipeline}_user:${USER}.${USER}");
    ResourceGroupId expected = new ResourceGroupId(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("test"), "pipeline"), "job_testpipeline_user:user"), "user");
    Pattern sourcePattern = Pattern.compile("scheduler.important.(?<pipeline>[^\\[]*).*");
    StaticSelector selector = new StaticSelector(Optional.empty(), Optional.empty(), Optional.of(sourcePattern), Optional.empty(), Optional.empty(), Optional.empty(), template);
    SelectionCriteria context = new SelectionCriteria(true, "user", ImmutableSet.of(), Optional.of("scheduler.important.testpipeline[5]"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
    assertEquals(selector.match(context).map(SelectionContext::getResourceGroupId), Optional.of(expected));
}
Also used : Pattern(java.util.regex.Pattern) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) SelectionCriteria(io.trino.spi.resourcegroups.SelectionCriteria) Test(org.testng.annotations.Test)

Example 9 with SelectionCriteria

use of io.trino.spi.resourcegroups.SelectionCriteria in project trino by trinodb.

the class TestResourceGroupIdTemplate method testNoSource.

@Test
public void testNoSource() {
    ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.${pipeline}.${SOURCE}_s");
    ResourceGroupId expected = new ResourceGroupId(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("test"), "pipeline"), "testpipeline"), "_s");
    Pattern userPattern = Pattern.compile("scheduler.important.(?<pipeline>[^\\[]*).*");
    StaticSelector selector = new StaticSelector(Optional.of(userPattern), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), template);
    SelectionCriteria context = new SelectionCriteria(true, "scheduler.important.testpipeline[5]", ImmutableSet.of(), Optional.empty(), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
    assertEquals(selector.match(context).map(SelectionContext::getResourceGroupId), Optional.of(expected));
}
Also used : Pattern(java.util.regex.Pattern) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) SelectionCriteria(io.trino.spi.resourcegroups.SelectionCriteria) Test(org.testng.annotations.Test)

Example 10 with SelectionCriteria

use of io.trino.spi.resourcegroups.SelectionCriteria in project trino by trinodb.

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", ImmutableSet.of(), Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.empty())), Optional.empty());
    assertEquals(selector.match(new SelectionCriteria(true, "testuser", ImmutableSet.of(), 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", ImmutableSet.of(), 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", ImmutableSet.of(), Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.of(DELETE.name()))), Optional.empty());
    assertEquals(selector.match(new SelectionCriteria(true, "testuser", ImmutableSet.of(), Optional.of("@test@test_new"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.of(INSERT.name()))), Optional.empty());
}
Also used : ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) SelectionCriteria(io.trino.spi.resourcegroups.SelectionCriteria) Test(org.testng.annotations.Test)

Aggregations

SelectionCriteria (io.trino.spi.resourcegroups.SelectionCriteria)10 Test (org.testng.annotations.Test)8 Pattern (java.util.regex.Pattern)7 ResourceGroupId (io.trino.spi.resourcegroups.ResourceGroupId)5 Optional (java.util.Optional)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 TrinoException (io.trino.spi.TrinoException)2 SelectionContext (io.trino.spi.resourcegroups.SelectionContext)2 List (java.util.List)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableList (com.google.common.collect.ImmutableList)1 Sets (com.google.common.collect.Sets)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 DataSize (io.airlift.units.DataSize)1 Session (io.trino.Session)1 PreparedQuery (io.trino.execution.QueryPreparer.PreparedQuery)1 InternalResourceGroup (io.trino.execution.resourcegroups.InternalResourceGroup)1 DEFAULT_WEIGHT (io.trino.execution.resourcegroups.InternalResourceGroup.DEFAULT_WEIGHT)1 ResourceGroupIdTemplate (io.trino.plugin.resourcegroups.ResourceGroupIdTemplate)1