Class FederationPolicyUtils

java.lang.Object
org.apache.hadoop.yarn.server.federation.policies.FederationPolicyUtils

@Private public final class FederationPolicyUtils extends Object
Utility class for Federation policy.
  • Field Details

  • Method Details

    • instantiatePolicyManager

      public static FederationPolicyManager instantiatePolicyManager(String newType) throws FederationPolicyInitializationException
      A utilize method to instantiate a policy manager class given the type (class name) from SubClusterPolicyConfiguration.
      Parameters:
      newType - class name of the policy manager to create
      Returns:
      Policy manager
      Throws:
      FederationPolicyInitializationException - if fails
    • loadPolicyConfiguration

      public static SubClusterPolicyConfiguration loadPolicyConfiguration(String queue, org.apache.hadoop.conf.Configuration conf, FederationStateStoreFacade federationFacade)
      Get Federation policy configuration from state store, using default queue and configuration as fallback.
      Parameters:
      queue - the queue of the application
      conf - the YARN configuration
      federationFacade - state store facade
      Returns:
      SubClusterPolicyConfiguration recreated
    • loadAMRMPolicy

      public static FederationAMRMProxyPolicy loadAMRMPolicy(String queue, FederationAMRMProxyPolicy oldPolicy, org.apache.hadoop.conf.Configuration conf, FederationStateStoreFacade federationFacade, SubClusterId homeSubClusterId) throws FederationPolicyInitializationException
      Get AMRMProxy policy from state store, using default queue and configuration as fallback.
      Parameters:
      queue - the queue of the application
      oldPolicy - the previous policy instance (can be null)
      conf - the YARN configuration
      federationFacade - state store facade
      homeSubClusterId - home sub-cluster id
      Returns:
      FederationAMRMProxyPolicy recreated
      Throws:
      FederationPolicyInitializationException - if fails
    • validateSubClusterAvailability

      public static void validateSubClusterAvailability(Collection<SubClusterId> activeSubClusters, Collection<SubClusterId> blackListSubClusters) throws FederationPolicyException
      Validate if there is any active subcluster that is not blacklisted, it will throw an exception if there are no usable subclusters.
      Parameters:
      activeSubClusters - the list of subClusters as identified by SubClusterId currently active.
      blackListSubClusters - the list of subClusters as identified by SubClusterId to blackList from the selection of the home subCluster.
      Throws:
      FederationPolicyException - if there are no usable subclusters.
    • getWeightedRandom

      public static int getWeightedRandom(ArrayList<Float> weights)
      Select a random bin according to the weight array for the bins. Only bins with positive weights will be considered. If no positive weight found, return -1.
      Parameters:
      weights - the weight array
      Returns:
      the index of the sample in the array
    • setRand

      @VisibleForTesting public static void setRand(long seed)