hadoop FairQueuePlacementUtils 源码

  • 2022-10-20
  • 浏览 (207)

haddop FairQueuePlacementUtils 代码

文件路径:/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/FairQueuePlacementUtils.java

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.hadoop.yarn.server.resourcemanager.placement;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerUtilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Utility methods used by Fair scheduler placement rules.
 * {@link
 * org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler}
 */
@InterfaceAudience.Private
@InterfaceStability.Unstable
public final class FairQueuePlacementUtils {
  private static final Logger LOG =
      LoggerFactory.getLogger(FairQueuePlacementUtils.class);

  // Constants for name clean up and hierarchy checks
  protected static final String DOT = ".";
  protected static final String DOT_REPLACEMENT = "_dot_";
  protected static final String ROOT_QUEUE = "root";

  private FairQueuePlacementUtils() {
  }

  /**
   * Replace the periods in the username or group name with "_dot_" and
   * remove trailing and leading whitespace.
   *
   * @param name The name to clean
   * @return The name with {@link #DOT} replaced with {@link #DOT_REPLACEMENT}
   */
  protected static String cleanName(String name) {
    name = FairSchedulerUtilities.trimQueueName(name);
    if (name.contains(DOT)) {
      String converted = name.replaceAll("\\.", DOT_REPLACEMENT);
      LOG.warn("Name {} is converted to {} when it is used as a queue name.",
          name, converted);
      return converted;
    } else {
      return name;
    }
  }

  /**
   * Assure root prefix for a queue name.
   *
   * @param queueName The queue name to check for the root prefix
   * @return The root prefixed queue name
   */
  protected static String assureRoot(String queueName) {
    if (queueName != null && !queueName.isEmpty()) {
      if (!queueName.startsWith(ROOT_QUEUE + DOT) &&
          !queueName.equals(ROOT_QUEUE)) {
        queueName = ROOT_QUEUE + DOT + queueName;
      }
    } else {
      LOG.warn("AssureRoot: queueName is empty or null.");
    }
    return queueName;
  }

  /**
   * Validate the queue name: it may not start or end with a {@link #DOT}.
   *
   * @param queueName The queue name to validate
   * @return <code>false</code> if the queue name starts or ends with a
   * {@link #DOT}, <code>true</code>
   */
  protected static boolean isValidQueueName(String queueName) {
    if (queueName != null) {
      if (queueName.equals(FairSchedulerUtilities.trimQueueName(queueName)) &&
          !queueName.startsWith(DOT) &&
          !queueName.endsWith(DOT)) {
        return true;
      }
    }
    return false;
  }
}

相关信息

hadoop 源码目录

相关文章

hadoop ApplicationPlacementContext 源码

hadoop CSMappingPlacementRule 源码

hadoop DefaultPlacementRule 源码

hadoop FSPlacementRule 源码

hadoop PlacementFactory 源码

hadoop PlacementManager 源码

hadoop PlacementRule 源码

hadoop PrimaryGroupPlacementRule 源码

hadoop QueueMapping 源码

hadoop QueuePlacementRuleUtils 源码

0  赞