use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class StaticSelector method match.
@Override
public Optional<SelectionContext<VariableMap>> match(SelectionCriteria criteria) {
Map<String, String> variables = new HashMap<>();
if (userRegex.isPresent()) {
Matcher userMatcher = userRegex.get().matcher(criteria.getUser());
if (!userMatcher.matches()) {
return Optional.empty();
}
addVariableValues(userRegex.get(), criteria.getUser(), variables);
}
if (sourceRegex.isPresent()) {
String source = criteria.getSource().orElse("");
if (!sourceRegex.get().matcher(source).matches()) {
return Optional.empty();
}
addVariableValues(sourceRegex.get(), source, variables);
}
if (!clientTags.isEmpty() && !criteria.getTags().containsAll(clientTags)) {
return Optional.empty();
}
if (selectorResourceEstimate.isPresent() && !selectorResourceEstimate.get().match(criteria.getResourceEstimates())) {
return Optional.empty();
}
if (queryType.isPresent()) {
String contextQueryType = criteria.getQueryType().orElse("");
if (!queryType.get().equalsIgnoreCase(contextQueryType)) {
return Optional.empty();
}
}
variables.putIfAbsent(USER_VARIABLE, criteria.getUser());
// Special handling for source, which is an optional field that is part of the standard variables
variables.putIfAbsent(SOURCE_VARIABLE, criteria.getSource().orElse(""));
VariableMap map = new VariableMap(variables);
ResourceGroupId id = group.expandTemplate(map);
OptionalInt firstDynamicSegment = group.getFirstDynamicSegment();
return Optional.of(new SelectionContext<>(id, map, firstDynamicSegment));
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
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(), 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 com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestFileResourceGroupConfigurationManager method testLegacyConfiguration.
@Test
public void testLegacyConfiguration() {
ResourceGroupConfigurationManager<VariableMap> manager = parse("resource_groups_config_legacy.json");
ResourceGroupId globalId = new ResourceGroupId("global");
ResourceGroup global = new TestingResourceGroup(globalId);
manager.configure(global, new SelectionContext<>(globalId, new VariableMap(ImmutableMap.of("USER", "user"))));
assertEquals(global.getSoftMemoryLimit(), new DataSize(3, MEGABYTE));
assertEquals(global.getMaxQueuedQueries(), 99);
assertEquals(global.getHardConcurrencyLimit(), 42);
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestStaticSelector method testSourceRegex.
@Test
public void testSourceRegex() {
ResourceGroupId resourceGroupId = new ResourceGroupId(new ResourceGroupId("global"), "foo");
StaticSelector selector = new StaticSelector(Optional.empty(), Optional.of(Pattern.compile(".*source.*")), Optional.empty(), Optional.empty(), Optional.empty(), new ResourceGroupIdTemplate("global.foo"));
assertEquals(selector.match(newSelectionCriteria("userA", null, ImmutableSet.of("tag1"), EMPTY_RESOURCE_ESTIMATES)), Optional.empty());
assertEquals(selector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES)).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
assertEquals(selector.match(newSelectionCriteria("A.user", "a source b", ImmutableSet.of("tag1"), EMPTY_RESOURCE_ESTIMATES)).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestStaticSelector method testSelectorResourceEstimate.
@Test
public void testSelectorResourceEstimate() {
ResourceGroupId resourceGroupId = new ResourceGroupId(new ResourceGroupId("global"), "foo");
StaticSelector smallQuerySelector = new StaticSelector(Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new SelectorResourceEstimate(Optional.of(new Range<>(Optional.empty(), Optional.of(Duration.valueOf("5m")))), Optional.empty(), Optional.of(new Range<>(Optional.empty(), Optional.of(DataSize.valueOf("500MB")))))), Optional.empty(), new ResourceGroupIdTemplate("global.foo"));
assertEquals(smallQuerySelector.match(newSelectionCriteria("userA", null, ImmutableSet.of("tag1", "tag2"), new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.of(DataSize.valueOf("400MB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
assertEquals(smallQuerySelector.match(newSelectionCriteria("A.user", "a source b", ImmutableSet.of("tag1"), new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.of(DataSize.valueOf("600MB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.empty());
assertEquals(smallQuerySelector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), new ResourceEstimates(Optional.of(Duration.valueOf("4m")), Optional.empty(), Optional.empty(), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.empty());
StaticSelector largeQuerySelector = new StaticSelector(Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new SelectorResourceEstimate(Optional.empty(), Optional.empty(), Optional.of(new Range<>(Optional.of(DataSize.valueOf("5TB")), Optional.empty())))), Optional.empty(), new ResourceGroupIdTemplate("global.foo"));
assertEquals(largeQuerySelector.match(newSelectionCriteria("userA", null, ImmutableSet.of("tag1", "tag2"), new ResourceEstimates(Optional.of(Duration.valueOf("100h")), Optional.empty(), Optional.of(DataSize.valueOf("4TB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.empty());
assertEquals(largeQuerySelector.match(newSelectionCriteria("A.user", "a source b", ImmutableSet.of("tag1"), new ResourceEstimates(Optional.empty(), Optional.empty(), Optional.of(DataSize.valueOf("6TB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
assertEquals(largeQuerySelector.match(newSelectionCriteria("userB", "source", ImmutableSet.of(), new ResourceEstimates(Optional.of(Duration.valueOf("1s")), Optional.of(Duration.valueOf("1s")), Optional.of(DataSize.valueOf("6TB")), Optional.empty()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId));
}
Aggregations