protected SaveFederationQueuePolicyRequest parsePolicy(String policy) throws YarnException {

    String[] policyItems = policy.split(SEMICOLON);
    if (policyItems == null || policyItems.length != 4) {
      throw new YarnException("The policy cannot be empty or the policy is incorrect. \n" +
          " Required information to provide: queue,router weight,amrm weight,headroomalpha \n" +
          " eg. root.a;SC-1:0.7,SC-2:0.3;SC-1:0.7,SC-2:0.3;1.0");
    }

    String queue = policyItems[0];
    String routerWeight = policyItems[1];
    String amrmWeight = policyItems[2];
    String headroomalpha = policyItems[3];

    LOG.info("Policy: [Queue = {}, RouterWeight = {}, AmRmWeight = {}, Headroomalpha = {}]",
        queue, routerWeight, amrmWeight, headroomalpha);

    checkSubClusterQueueWeightRatioValid(routerWeight);
    checkSubClusterQueueWeightRatioValid(amrmWeight);
    checkHeadRoomAlphaValid(headroomalpha);

    FederationQueueWeight federationQueueWeight =
        FederationQueueWeight.newInstance(routerWeight, amrmWeight, headroomalpha);
    String policyManager = getConf().get(YarnConfiguration.FEDERATION_POLICY_MANAGER,
        YarnConfiguration.DEFAULT_FEDERATION_POLICY_MANAGER);
    SaveFederationQueuePolicyRequest request = SaveFederationQueuePolicyRequest.newInstance(
        queue, federationQueueWeight, policyManager);

    return request;
  }
@Test
  public void testParsePolicy() throws Exception {
    // Case1, If policy is empty.
    String errMsg1 = "The policy cannot be empty or the policy is incorrect. \n" +
        " Required information to provide: queue,router weight,amrm weight,headroomalpha \n" +
        " eg. root.a;SC-1:0.7,SC-2:0.3;SC-1:0.7,SC-2:0.3;1.0";
    LambdaTestUtils.intercept(YarnException.class, errMsg1, () ->  rmAdminCLI.parsePolicy(""));

    // Case2, If policy is incomplete, We need 4 items, but only 2 of them are provided.
    LambdaTestUtils.intercept(YarnException.class, errMsg1,
        () ->  rmAdminCLI.parsePolicy("root.a;SC-1:0.1,SC-2:0.9;"));

    // Case3, If policy is incomplete, The weight of a subcluster is missing.
    String errMsg2 = "The subClusterWeight cannot be empty, " +
        "and the subClusterWeight size must be 2. (eg.SC-1,0.2)";
    LambdaTestUtils.intercept(YarnException.class, errMsg2,
        () ->  rmAdminCLI.parsePolicy("root.a;SC-1:0.1,SC-2;SC-1:0.1,SC-2;0.3,1.0"));

    // Case4, The policy is complete, but the sum of weights for each subcluster is not equal to 1.
    String errMsg3 = "The sum of ratios for all subClusters must be equal to 1.";
    LambdaTestUtils.intercept(YarnException.class, errMsg3,
        () ->  rmAdminCLI.parsePolicy("root.a;SC-1:0.1,SC-2:0.8;SC-1:0.1,SC-2;0.3,1.0"));

    // If policy is root.a;SC-1:0.7,SC-2:0.3;SC-1:0.7,SC-2:0.3;1.0
    String policy = "root.a;SC-1:0.7,SC-2:0.3;SC-1:0.6,SC-2:0.4;1.0";
    SaveFederationQueuePolicyRequest request = rmAdminCLI.parsePolicy(policy);
    FederationQueueWeight federationQueueWeight = request.getFederationQueueWeight();
    assertNotNull(federationQueueWeight);
    assertEquals("SC-1:0.7,SC-2:0.3", federationQueueWeight.getRouterWeight());
    assertEquals("SC-1:0.6,SC-2:0.4", federationQueueWeight.getAmrmWeight());
    assertEquals("1.0", federationQueueWeight.getHeadRoomAlpha());
  }