use of io.prestosql.spi.resourcegroups.SelectionCriteria in project hetu-core by openlookeng.
the class TestDbResourceGroupConfigurationManager method testEnvironments.
@Test
public void testEnvironments() {
H2DaoProvider daoProvider = setup("test_configuration");
H2ResourceGroupsDao dao = daoProvider.get();
dao.createResourceGroupsGlobalPropertiesTable();
dao.createResourceGroupsTable();
dao.createSelectorsTable();
String prodEnvironment = "prod";
String devEnvironment = "dev";
dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
// two resource groups are the same except the group for the prod environment has a larger softMemoryLimit
// Hetu: add values for new parameters softReservedMemory and hardReservedConcurrency
dao.insertResourceGroup(1, "prod_global", "10MB", "5MB", 1000, 100, 100, 50, "weighted", null, true, "1h", "1d", "RECENT_QUERIES", null, prodEnvironment);
dao.insertResourceGroup(2, "dev_global", "1MB", "5MB", 1000, 100, 100, 50, "weighted", null, true, "1h", "1d", "RECENT_QUERIES", null, devEnvironment);
dao.insertSelector(1, 1, ".*prod_user.*", null, null, null, null);
dao.insertSelector(2, 2, ".*dev_user.*", null, null, null, null);
// check the prod configuration
DbResourceGroupConfigurationManager manager = new DbResourceGroupConfigurationManager((poolId, listener) -> {
}, new DbResourceGroupConfig(), daoProvider.get(), prodEnvironment);
List<ResourceGroupSpec> groups = manager.getRootGroups();
assertEquals(groups.size(), 1);
InternalResourceGroup prodGlobal = new InternalResourceGroup(Optional.empty(), "prod_global", (group, export) -> {
}, directExecutor());
manager.configure(prodGlobal, new SelectionContext<>(prodGlobal.getId(), new ResourceGroupIdTemplate("prod_global")));
// Hetu: add values for new parameters softReservedMemory and hardReservedConcurrency
assertEqualsResourceGroup(prodGlobal, "10MB", 1000, 100, 100, WEIGHTED, DEFAULT_WEIGHT, true, new Duration(1, HOURS), new Duration(1, DAYS));
assertEquals(manager.getSelectors().size(), 1);
ResourceGroupSelector prodSelector = manager.getSelectors().get(0);
ResourceGroupId prodResourceGroupId = prodSelector.match(new SelectionCriteria(true, "prod_user", Optional.empty(), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty())).get().getResourceGroupId();
assertEquals(prodResourceGroupId.toString(), "prod_global");
// check the dev configuration
manager = new DbResourceGroupConfigurationManager((poolId, listener) -> {
}, new DbResourceGroupConfig(), daoProvider.get(), devEnvironment);
assertEquals(groups.size(), 1);
InternalResourceGroup devGlobal = new InternalResourceGroup(Optional.empty(), "dev_global", (group, export) -> {
}, directExecutor());
manager.configure(devGlobal, new SelectionContext<>(prodGlobal.getId(), new ResourceGroupIdTemplate("dev_global")));
assertEqualsResourceGroup(devGlobal, "1MB", 1000, 100, 100, WEIGHTED, DEFAULT_WEIGHT, true, new Duration(1, HOURS), new Duration(1, DAYS));
assertEquals(manager.getSelectors().size(), 1);
ResourceGroupSelector devSelector = manager.getSelectors().get(0);
ResourceGroupId devResourceGroupId = devSelector.match(new SelectionCriteria(true, "dev_user", Optional.empty(), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty())).get().getResourceGroupId();
assertEquals(devResourceGroupId.toString(), "dev_global");
}
use of io.prestosql.spi.resourcegroups.SelectionCriteria in project hetu-core by openlookeng.
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 io.prestosql.spi.resourcegroups.SelectionCriteria in project hetu-core by openlookeng.
the class TestResourceGroupIdTemplate method testUnresolvedVariableLoadTime.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "unresolved variables \\[user\\] in resource group ID.*")
public void testUnresolvedVariableLoadTime() {
ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.${pipeline}.${user}");
StaticSelector selector = new StaticSelector(Optional.empty(), Optional.of(SOURCE_PATTERN), Optional.empty(), Optional.empty(), Optional.empty(), template);
SelectionCriteria context = new SelectionCriteria(true, "user", Optional.of("scheduler.important.testpipeline[5]"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
selector.match(context);
}
use of io.prestosql.spi.resourcegroups.SelectionCriteria in project hetu-core by openlookeng.
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");
StaticSelector selector = new StaticSelector(Optional.of(SOURCE_PATTERN), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), template);
SelectionCriteria context = new SelectionCriteria(true, "scheduler.important.testpipeline[5]", Optional.empty(), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
assertEquals(selector.match(context).map(SelectionContext::getResourceGroupId), Optional.of(expected));
}
use of io.prestosql.spi.resourcegroups.SelectionCriteria in project hetu-core by openlookeng.
the class TestResourceGroupIdTemplate method testNoMatch.
@Test
public void testNoMatch() {
ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.${pipeline}.${USER}");
StaticSelector selector = new StaticSelector(Optional.empty(), Optional.of(SOURCE_PATTERN), Optional.empty(), Optional.empty(), Optional.empty(), template);
SelectionCriteria context = new SelectionCriteria(true, "user", Optional.of("scheduler.testpipeline[5]"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
assertFalse(selector.match(context).isPresent());
}
Aggregations