15 package com.cloudera.impala.util;
18 import java.io.IOException;
19 import java.lang.reflect.Field;
20 import java.net.URISyntaxException;
22 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.AllocationFileLoaderService;
23 import org.junit.After;
24 import org.junit.Assert;
25 import org.junit.Rule;
27 import org.junit.rules.TemporaryFolder;
30 import com.cloudera.impala.thrift.TErrorCode;
31 import com.cloudera.impala.thrift.TPoolConfigResult;
32 import com.cloudera.impala.thrift.TResolveRequestPoolParams;
33 import com.cloudera.impala.thrift.TResolveRequestPoolResult;
34 import com.google.common.collect.Iterables;
35 import com.google.common.io.Files;
69 public TemporaryFolder
tempFolder =
new TemporaryFolder();
87 String llamaConfPath = null;
88 if (llamaConfFile != null) {
91 llamaConfPath = llamaConfFile_.getAbsolutePath();
98 Field f = AllocationFileLoaderService.class.getDeclaredField(
"reloadIntervalMs");
99 f.setAccessible(
true);
101 if (llamaConfFile != null) {
104 poolService_.start();
116 return new File(getClass().getClassLoader().getResource(filename).toURI());
122 Assert.assertEquals(
"root.queueA", poolService_.assignToPool(
"root.queueA",
"userA"));
123 Assert.assertNull(poolService_.assignToPool(
"queueC",
"userA"));
130 TResolveRequestPoolResult result = poolService_.resolveRequestPool(
131 new TResolveRequestPoolParams(
"userA@abc.com",
"root.queueA"));
132 Assert.assertEquals(
TErrorCode.OK, result.getStatus().getStatus_code());
133 Assert.assertEquals(
"root.queueA", result.getResolved_pool());
135 result = poolService_.resolveRequestPool(
136 new TResolveRequestPoolParams(
"userA/a.qualified.domain@abc.com",
"root.queueA"));
137 Assert.assertEquals(
TErrorCode.OK, result.getStatus().getStatus_code());
138 Assert.assertEquals(
"root.queueA", result.getResolved_pool());
145 TResolveRequestPoolResult result = poolService_.resolveRequestPool(
146 new TResolveRequestPoolParams(
"userA",
"root.NOT_A_POOL"));
147 Assert.assertEquals(
false, result.isSetResolved_pool());
148 Assert.assertEquals(
false, result.isSetHas_access());
149 Assert.assertEquals(TErrorCode.INTERNAL_ERROR, result.getStatus().getStatus_code());
151 String expectedMessage =
"Failed to resolve user 'userA' to a pool while " +
152 "evaluating the 'primaryGroup' or 'secondaryGroup' queue placement rules because " +
153 "no groups were found for the user. This is likely because the user does not " +
154 "exist on the local operating system.";
155 Assert.assertEquals(expectedMessage,
156 Iterables.getOnlyElement(result.getStatus().getError_msgs()));
162 Assert.assertTrue(poolService_.hasAccess(
"root.queueA",
"userA"));
163 Assert.assertTrue(poolService_.hasAccess(
"root.queueB",
"userB"));
164 Assert.assertFalse(poolService_.hasAccess(
"root.queueB",
"userA"));
165 Assert.assertTrue(poolService_.hasAccess(
"root.queueB",
"root"));
179 Assert.assertEquals(
"root.userA", poolService_.assignToPool(
"",
"userA"));
180 Assert.assertTrue(poolService_.hasAccess(
"root.userA",
"userA"));
200 AllocationFileLoaderService.ALLOC_RELOAD_WAIT_MS);
217 Assert.assertEquals(
"root.queueA", poolService_.assignToPool(
"queueA",
"userA"));
218 Assert.assertNull(poolService_.assignToPool(
"queueX",
"userA"));
219 Assert.assertEquals(
"root.queueC", poolService_.assignToPool(
"queueC",
"userA"));
222 Assert.assertTrue(poolService_.hasAccess(
"root.queueA",
"userA"));
223 Assert.assertTrue(poolService_.hasAccess(
"root.queueB",
"userB"));
224 Assert.assertTrue(poolService_.hasAccess(
"root.queueB",
"userA"));
225 Assert.assertFalse(poolService_.hasAccess(
"root.queueC",
"userA"));
226 Assert.assertTrue(poolService_.hasAccess(
"root.queueC",
"root"));
237 Assert.assertEquals(
"root.queueA", poolService_.assignToPool(
"queueA",
"userA"));
238 Assert.assertNull(poolService_.assignToPool(
"queueX",
"userA"));
239 Assert.assertEquals(
"root.queueC", poolService_.assignToPool(
"queueC",
"userA"));
242 Assert.assertTrue(poolService_.hasAccess(
"root.queueA",
"userA"));
243 Assert.assertTrue(poolService_.hasAccess(
"root.queueB",
"userB"));
244 Assert.assertTrue(poolService_.hasAccess(
"root.queueB",
"userA"));
245 Assert.assertFalse(poolService_.hasAccess(
"root.queueC",
"userA"));
246 Assert.assertTrue(poolService_.hasAccess(
"root.queueC",
"root"));
259 long expectedMaxQueued,
long expectedMaxMemUsage) {
260 TPoolConfigResult expectedResult =
new TPoolConfigResult();
261 expectedResult.setMax_requests(expectedMaxRequests);
262 expectedResult.setMax_queued(expectedMaxQueued);
263 expectedResult.setMem_limit(expectedMaxMemUsage);
264 Assert.assertEquals(
"Unexpected config values for pool " +
pool,
265 expectedResult, poolService_.getPoolConfig(
pool));
static final long CHECK_INTERVAL_MS
void checkPoolConfigResult(String pool, long expectedMaxRequests, long expectedMaxQueued, long expectedMaxMemUsage)
static final String ALLOCATION_FILE
static final String LLAMA_CONFIG_FILE
void testUserNoGroupsError()
static final String ALLOCATION_FILE_MODIFIED
RequestPoolService poolService_
void testPoolLimitConfigs()
static final String ALLOCATION_FILE_EMPTY
static final String LLAMA_CONFIG_FILE_EMPTY
static final long MEGABYTE
void createPoolService(String allocationFile, String llamaConfFile)
void testDefaultConfigs()
static final String LLAMA_CONFIG_FILE_MODIFIED
void testResolvePrincipalName()
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
TemporaryFolder tempFolder
void testPoolResolution()
static final String ALLOCATION_FILE_GROUP_RULE
void testUpdatingConfigs()
File getClasspathFile(String filename)
void checkModifiedConfigResults()
void testModifiedConfigs()