YARN-9996. Code cleanup in QueueAdminConfigurationMutationACLPolicy. Contributed by Siddharth Ahuja

This commit is contained in:
Szilard Nemeth 2020-04-23 14:55:50 +02:00
parent 47b330dc34
commit 1340518cd8

View File

@ -75,36 +75,68 @@ public boolean isMutationAllowed(UserGroupInformation user,
for (QueueConfigInfo updateQueueInfo : confUpdate.getUpdateQueueInfo()) { for (QueueConfigInfo updateQueueInfo : confUpdate.getUpdateQueueInfo()) {
queues.add(updateQueueInfo.getQueue()); queues.add(updateQueueInfo.getQueue());
} }
// Loop through all the queues.
for (String queuePath : queues) { for (String queuePath : queues) {
String queueName = queuePath.lastIndexOf('.') != -1 ?
queuePath.substring(queuePath.lastIndexOf('.') + 1) : queuePath;
QueueInfo queueInfo = null; QueueInfo queueInfo = null;
String parentPath = queuePath;
// For this queue, check if queue information exists for its children
// starting at the end of the queue.
// Keep this check going by moving up in the queue hierarchy until
// queue information has been found for one of its children.
String queueName;
while (queueInfo == null) {
queueName = queueHasAChild(parentPath) ?
getLastChildForQueue(parentPath) : parentPath;
try { try {
queueInfo = rmContext.getScheduler() queueInfo = rmContext.getScheduler()
.getQueueInfo(queueName, false, false); .getQueueInfo(queueName, false, false);
} catch (IOException e) { } catch (IOException e) {
// Queue is not found, do nothing. // Queue is not found, do nothing.
} }
String parentPath = queuePath;
while (queueInfo == null) { // Keep going up in the queue hierarchy.
// We are adding a queue (whose parent we are possibly also adding). parentPath = queueHasAChild(parentPath) ?
// Check ACL of lowest parent queue which already exists. getQueueBeforeLastChild(parentPath) : parentPath;
parentPath = parentPath.substring(0, parentPath.lastIndexOf('.'));
String parentName = parentPath.lastIndexOf('.') != -1 ?
parentPath.substring(parentPath.lastIndexOf('.') + 1) : parentPath;
try {
queueInfo = rmContext.getScheduler()
.getQueueInfo(parentName, false, false);
} catch (IOException e) {
// Queue is not found, do nothing.
}
} }
// check if user has Admin access to this queue.
Queue queue = ((MutableConfScheduler) rmContext.getScheduler()) Queue queue = ((MutableConfScheduler) rmContext.getScheduler())
.getQueue(queueInfo.getQueueName()); .getQueue(queueInfo.getQueueName());
if (queue != null && !queue.hasAccess(QueueACL.ADMINISTER_QUEUE, user)) { if (queue != null && !queue.hasAccess(QueueACL.ADMINISTER_QUEUE, user)) {
return false; return false;
} }
} }
return true; return true;
} }
/**
* Does the queue have a child?
* @param queue The queue that needs to be checked for a child.
* @return True if a "." exists in the queue name, signalling hierarchy.
*/
private boolean queueHasAChild(String queue) {
return queue.lastIndexOf('.') != -1;
}
/**
* Get the last child name from a queue name.
* @param queue The queue that is checked for the last child.
* @return The last child of the queue.
*/
private String getLastChildForQueue(String queue) {
return queue.substring(queue.lastIndexOf('.') + 1);
}
/**
* Get a queue name minus the last child.
* @param queue The queue that needs to be trimmed of its last child.
* @return Remaining queue name after its last child has been taken out.
*/
private String getQueueBeforeLastChild(String queue) {
return queue.substring(0, queue.lastIndexOf('.'));
}
} }