use of com.facebook.presto.spi.resourceGroups.SelectionContext in project presto by prestodb.
the class TestDbResourceGroupConfigurationManager method testConfiguration.
@Test
public void testConfiguration() {
H2DaoProvider daoProvider = setup("test_configuration");
H2ResourceGroupsDao dao = daoProvider.get();
dao.createResourceGroupsGlobalPropertiesTable();
dao.createResourceGroupsTable();
dao.createSelectorsTable();
dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
dao.insertResourceGroup(1, "global", "1MB", 1000, 100, "weighted", null, true, "1h", "1d", null);
dao.insertResourceGroup(2, "sub", "2MB", 4, 3, null, 5, null, null, null, 1L);
dao.insertSelector(2, null, null);
DbResourceGroupConfigurationManager manager = new DbResourceGroupConfigurationManager((poolId, listener) -> {
}, daoProvider.get());
AtomicBoolean exported = new AtomicBoolean();
InternalResourceGroup global = new InternalResourceGroup.RootInternalResourceGroup("global", (group, export) -> exported.set(export), directExecutor());
manager.configure(global, new SelectionContext(true, "user", Optional.empty(), 1));
assertEqualsResourceGroup(global, "1MB", 1000, 100, WEIGHTED, DEFAULT_WEIGHT, true, new Duration(1, HOURS), new Duration(1, DAYS));
exported.set(false);
InternalResourceGroup sub = global.getOrCreateSubGroup("sub");
manager.configure(sub, new SelectionContext(true, "user", Optional.empty(), 1));
assertEqualsResourceGroup(sub, "2MB", 4, 3, FAIR, 5, false, new Duration(Long.MAX_VALUE, MILLISECONDS), new Duration(Long.MAX_VALUE, MILLISECONDS));
}
use of com.facebook.presto.spi.resourceGroups.SelectionContext in project presto by prestodb.
the class TestDbResourceGroupConfigurationManager method testReconfig.
@Test(timeOut = 60_000)
public void testReconfig() throws Exception {
H2DaoProvider daoProvider = setup("test_reconfig");
H2ResourceGroupsDao dao = daoProvider.get();
dao.createResourceGroupsGlobalPropertiesTable();
dao.createResourceGroupsTable();
dao.createSelectorsTable();
dao.insertResourceGroup(1, "global", "1MB", 1000, 100, "weighted", null, true, "1h", "1d", null);
dao.insertResourceGroup(2, "sub", "2MB", 4, 3, null, 5, null, null, null, 1L);
dao.insertSelector(2, null, null);
dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
DbResourceGroupConfigurationManager manager = new DbResourceGroupConfigurationManager((poolId, listener) -> {
}, daoProvider.get());
manager.start();
AtomicBoolean exported = new AtomicBoolean();
InternalResourceGroup global = new InternalResourceGroup.RootInternalResourceGroup("global", (group, export) -> exported.set(export), directExecutor());
manager.configure(global, new SelectionContext(true, "user", Optional.empty(), 1));
InternalResourceGroup globalSub = global.getOrCreateSubGroup("sub");
manager.configure(globalSub, new SelectionContext(true, "user", Optional.empty(), 1));
// Verify record exists
assertEqualsResourceGroup(globalSub, "2MB", 4, 3, FAIR, 5, false, new Duration(Long.MAX_VALUE, MILLISECONDS), new Duration(Long.MAX_VALUE, MILLISECONDS));
dao.updateResourceGroup(2, "sub", "3MB", 2, 1, "weighted", 6, true, "1h", "1d", 1L);
do {
MILLISECONDS.sleep(500);
} while (globalSub.getJmxExport() == false);
// Verify update
assertEqualsResourceGroup(globalSub, "3MB", 2, 1, WEIGHTED, 6, true, new Duration(1, HOURS), new Duration(1, DAYS));
// Verify delete
dao.deleteSelectors(2);
dao.deleteResourceGroup(2);
do {
MILLISECONDS.sleep(500);
} while (globalSub.getMaxQueuedQueries() != 0 || globalSub.getMaxRunningQueries() != 0);
}
use of com.facebook.presto.spi.resourceGroups.SelectionContext in project presto by prestodb.
the class InternalResourceGroupManager method createGroupIfNecessary.
private synchronized void createGroupIfNecessary(ResourceGroupId id, Session session, Executor executor) {
SelectionContext context = new SelectionContext(session.getIdentity().getPrincipal().isPresent(), session.getUser(), session.getSource(), getQueryPriority(session));
if (!groups.containsKey(id)) {
InternalResourceGroup group;
if (id.getParent().isPresent()) {
createGroupIfNecessary(id.getParent().get(), session, executor);
InternalResourceGroup parent = groups.get(id.getParent().get());
requireNonNull(parent, "parent is null");
group = parent.getOrCreateSubGroup(id.getLastSegment());
} else {
RootInternalResourceGroup root = new RootInternalResourceGroup(id.getSegments().get(0), this::exportGroup, executor);
group = root;
rootGroups.add(root);
}
configurationManager.get().configure(group, context);
checkState(groups.put(id, group) == null, "Unexpected existing resource group");
}
}
use of com.facebook.presto.spi.resourceGroups.SelectionContext in project presto by prestodb.
the class TestFileResourceGroupConfigurationManager method testConfiguration.
@Test
public void testConfiguration() {
ResourceGroupConfigurationManager manager = parse("resource_groups_config.json");
ResourceGroup global = new TestingResourceGroup(new ResourceGroupId("global"));
manager.configure(global, new SelectionContext(true, "user", Optional.empty(), 1));
assertEquals(global.getSoftMemoryLimit(), new DataSize(1, MEGABYTE));
assertEquals(global.getSoftCpuLimit(), new Duration(1, HOURS));
assertEquals(global.getHardCpuLimit(), new Duration(1, DAYS));
assertEquals(global.getCpuQuotaGenerationMillisPerSecond(), 1000 * 24);
assertEquals(global.getMaxQueuedQueries(), 1000);
assertEquals(global.getMaxRunningQueries(), 100);
assertEquals(global.getSchedulingPolicy(), WEIGHTED);
assertEquals(global.getSchedulingWeight(), 0);
assertEquals(global.getJmxExport(), true);
ResourceGroup sub = new TestingResourceGroup(new ResourceGroupId(new ResourceGroupId("global"), "sub"));
manager.configure(sub, new SelectionContext(true, "user", Optional.empty(), 1));
assertEquals(sub.getSoftMemoryLimit(), new DataSize(2, MEGABYTE));
assertEquals(sub.getMaxRunningQueries(), 3);
assertEquals(sub.getMaxQueuedQueries(), 4);
assertEquals(sub.getSchedulingPolicy(), null);
assertEquals(sub.getSchedulingWeight(), 5);
assertEquals(sub.getJmxExport(), false);
}
use of com.facebook.presto.spi.resourceGroups.SelectionContext in project presto by prestodb.
the class TestFileResourceGroupConfigurationManager method testMissing.
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No matching configuration found for: missing")
public void testMissing() {
ResourceGroupConfigurationManager manager = parse("resource_groups_config.json");
ResourceGroup missing = new TestingResourceGroup(new ResourceGroupId("missing"));
manager.configure(missing, new SelectionContext(true, "user", Optional.empty(), 1));
}
Aggregations