@@ -130,6 +130,9 @@ public class RouterCLI extends Configured implements Tool {
130130 private static final String XML_TAG_AMRMPOLICYWEIGHTS = "amrmPolicyWeights" ;
131131 private static final String XML_TAG_ROUTERPOLICYWEIGHTS = "routerPolicyWeights" ;
132132 private static final String XML_TAG_HEADROOMALPHA = "headroomAlpha" ;
133+ private static final String XML_TAG_FEDERATION_WEIGHTS = "federationWeights" ;
134+ private static final String XML_TAG_QUEUE = "queue" ;
135+ private static final String XML_TAG_NAME = "name" ;
133136
134137 public RouterCLI () {
135138 super ();
@@ -341,10 +344,7 @@ private int handlePolicy(String[] args)
341344 "Currently, there are one supported file formats: XML." +
342345 "These files contain the policy information for storing queue policies." );
343346 Option fileOpt = new Option ("f" , "input-file" , true ,
344- // TODO: 格式
345- "Users can specify the file format using this option. " +
346- "Currently, there are two supported file formats: XML and JSON. " +
347- "These files contain the policy information for storing queue policies." );
347+ "The location of the input configuration file. " );
348348 formatOpt .setOptionalArg (true );
349349
350350 opts .addOption (saveOpt );
@@ -438,7 +438,7 @@ private int handBatchSavePolicies(String format, String policyFile) {
438438
439439 switch (format ) {
440440 case FORMAT_XML :
441- return parseXml2Policies (policyFile );
441+ return parseXml2PoliciesAndBatchSavePolicies (policyFile );
442442 default :
443443 System .out .println ("We currently only support XML formats." );
444444 return EXIT_ERROR ;
@@ -487,7 +487,19 @@ protected SaveFederationQueuePolicyRequest parsePolicy(String policy) throws Yar
487487 return request ;
488488 }
489489
490- protected int parseXml2Policies (String policiesXml ) {
490+ /**
491+ * Parse Policies from XML and save them in batches to FederationStateStore.
492+ *
493+ * We save 20 policies in one batch.
494+ * If the user needs to save 1000 policies, it will cycle 50 times.
495+ *
496+ * Every time a page is saved, we will print whether a page
497+ * has been saved successfully or failed.
498+ *
499+ * @param policiesXml Policies Xml Path.
500+ * @return 0, success; 1, failed.
501+ */
502+ protected int parseXml2PoliciesAndBatchSavePolicies (String policiesXml ) {
491503 try {
492504 List <FederationQueueWeight > federationQueueWeightsList = parsePoliciesByXml (policiesXml );
493505 MemoryPageUtils <FederationQueueWeight > memoryPageUtils = new MemoryPageUtils <>(20 );
@@ -502,7 +514,7 @@ protected int parseXml2Policies(String policiesXml) {
502514 ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol ();
503515 BatchSaveFederationQueuePoliciesResponse response =
504516 adminProtocol .batchSaveFederationQueuePolicies (request );
505- System .out .println ("page<" + i + "> : " + response .getMessage ());
517+ System .out .println ("page <" + ( i + 1 ) + "> : " + response .getMessage ());
506518 }
507519 } catch (Exception e ) {
508520 LOG .error ("BatchSaveFederationQueuePolicies error" , e );
@@ -512,15 +524,15 @@ protected int parseXml2Policies(String policiesXml) {
512524
513525 /**
514526 * Parse FederationQueueWeight from the xml configuration file.
515- *
527+ * <p>
516528 * We allow users to provide an xml configuration file,
517529 * which stores the weight information of the queue.
518530 *
519- * @param policiesXml
520- * @return
521- * @throws IOException
522- * @throws SAXException
523- * @throws ParserConfigurationException
531+ * @param policiesXml Policies Xml Path.
532+ * @return FederationQueueWeight List.
533+ * @throws IOException an I/O exception of some sort has occurred.
534+ * @throws SAXException Encapsulate a general SAX error or warning.
535+ * @throws ParserConfigurationException a serious configuration error..
524536 */
525537 protected List <FederationQueueWeight > parsePoliciesByXml (String policiesXml )
526538 throws IOException , SAXException , ParserConfigurationException {
@@ -532,23 +544,24 @@ protected List<FederationQueueWeight> parsePoliciesByXml(String policiesXml)
532544 DocumentBuilder builder = factory .newDocumentBuilder ();
533545 Document document = builder .parse (xmlFile );
534546
535- NodeList federationsList = document .getElementsByTagName ("federationWeights" );
547+ NodeList federationsList = document .getElementsByTagName (XML_TAG_FEDERATION_WEIGHTS );
536548
537549 for (int i = 0 ; i < federationsList .getLength (); i ++) {
538550
539551 Node federationNode = federationsList .item (i );
540552
541553 if (federationNode .getNodeType () == Node .ELEMENT_NODE ) {
542554 Element federationElement = (Element ) federationNode ;
543- NodeList queueList = federationElement .getElementsByTagName ("queue" );
555+ NodeList queueList = federationElement .getElementsByTagName (XML_TAG_QUEUE );
544556
545557 for (int j = 0 ; j < queueList .getLength (); j ++) {
546558
547559 Node queueNode = queueList .item (j );
548560 if (queueNode .getNodeType () == Node .ELEMENT_NODE ) {
549561 Element queueElement = (Element ) queueNode ;
550562 // parse queueName.
551- String queueName = queueElement .getElementsByTagName ("name" ).item (0 ).getTextContent ();
563+ String queueName = queueElement .getElementsByTagName (XML_TAG_NAME )
564+ .item (0 ).getTextContent ();
552565
553566 // parse amrmPolicyWeights / routerPolicyWeights.
554567 String amrmWeight = parsePolicyWeightsNode (queueElement , XML_TAG_AMRMPOLICYWEIGHTS );
@@ -561,7 +574,7 @@ protected List<FederationQueueWeight> parsePoliciesByXml(String policiesXml)
561574 String policyManager = getConf ().get (YarnConfiguration .FEDERATION_POLICY_MANAGER ,
562575 YarnConfiguration .DEFAULT_FEDERATION_POLICY_MANAGER );
563576
564- LOG .info ("Queue: {}, AmrmPolicyWeights: {}, RouterWeight: {}, HeadroomAlpha: {}." ,
577+ LOG .debug ("Queue: {}, AmrmPolicyWeights: {}, RouterWeight: {}, HeadroomAlpha: {}." ,
565578 queueName , amrmWeight , routerWeight , headroomAlpha );
566579
567580 FederationQueueWeight weight = FederationQueueWeight .newInstance (routerWeight ,
0 commit comments