@@ -584,25 +584,24 @@ public AppInfo getApp(HttpServletRequest hsr, String appId, Set<String> unselect
584584
585585 long startTime = clock .getTime ();
586586
587- ApplicationId applicationId = null ;
587+ ApplicationId applicationId ;
588588 try {
589589 applicationId = ApplicationId .fromString (appId );
590590 } catch (IllegalArgumentException e ) {
591591 routerMetrics .incrAppsFailedRetrieved ();
592592 return null ;
593593 }
594594
595- SubClusterInfo subClusterInfo = null ;
596- SubClusterId subClusterId = null ;
595+ SubClusterInfo subClusterInfo ;
597596 try {
598- subClusterId = federationFacade . getApplicationHomeSubCluster ( applicationId );
599- if (subClusterId == null ) {
597+ subClusterInfo = getHomeSubClusterInfoByAppId ( appId );
598+ if (subClusterInfo == null ) {
600599 routerMetrics .incrAppsFailedRetrieved ();
601600 return null ;
602601 }
603- subClusterInfo = federationFacade .getSubCluster (subClusterId );
604602 } catch (YarnException e ) {
605603 routerMetrics .incrAppsFailedRetrieved ();
604+ LOG .error ("getApp Error, applicationId = {}." , appId , e );
606605 return null ;
607606 }
608607
@@ -637,7 +636,7 @@ public Response updateAppState(AppState targetState, HttpServletRequest hsr, Str
637636
638637 long startTime = clock .getTime ();
639638
640- ApplicationId applicationId = null ;
639+ ApplicationId applicationId ;
641640 try {
642641 applicationId = ApplicationId .fromString (appId );
643642 } catch (IllegalArgumentException e ) {
@@ -648,8 +647,8 @@ public Response updateAppState(AppState targetState, HttpServletRequest hsr, Str
648647 .build ();
649648 }
650649
651- SubClusterInfo subClusterInfo = null ;
652- SubClusterId subClusterId = null ;
650+ SubClusterInfo subClusterInfo ;
651+ SubClusterId subClusterId ;
653652 try {
654653 subClusterId =
655654 federationFacade .getApplicationHomeSubCluster (applicationId );
@@ -795,14 +794,12 @@ private HttpServletRequestWrapper clone(final HttpServletRequest hsr) {
795794 return null ;
796795 }
797796 @ SuppressWarnings ("unchecked" )
798- final Map <String , String []> parameterMap =
799- (Map <String , String []>) hsr .getParameterMap ();
797+ final Map <String , String []> parameterMap = hsr .getParameterMap ();
800798 final String pathInfo = hsr .getPathInfo ();
801799 final String user = hsr .getRemoteUser ();
802800 final Principal principal = hsr .getUserPrincipal ();
803- final String mediaType =
804- RouterWebServiceUtil .getMediaTypeFromHttpServletRequest (
805- hsr , AppsInfo .class );
801+ final String mediaType = RouterWebServiceUtil .getMediaTypeFromHttpServletRequest (
802+ hsr , AppsInfo .class );
806803 return new HttpServletRequestWrapper (hsr ) {
807804 public Map <String , String []> getParameterMap () {
808805 return parameterMap ;
@@ -914,6 +911,7 @@ private Map<SubClusterInfo, NodeInfo> getNode(Collection<SubClusterInfo> subClus
914911
915912 /**
916913 * Get the subcluster a node belongs to.
914+ *
917915 * @param nodeId Identifier of the node we are looking for.
918916 * @return The subcluster containing the node.
919917 * @throws NotFoundException If the node cannot be found.
@@ -988,6 +986,17 @@ public NodesInfo getNodes(String states) {
988986 return RouterWebServiceUtil .deleteDuplicateNodesInfo (nodes .getNodes ());
989987 }
990988
989+ /**
990+ * This method changes the resources of a specific node, and it is reachable
991+ * by using {@link RMWSConsts#NODE_RESOURCE}.
992+ *
993+ * @param hsr The servlet request.
994+ * @param nodeId The node we want to retrieve the information for.
995+ * It is a PathParam.
996+ * @param resourceOption The resource change.
997+ * @throws AuthorizationException If the user is not authorized.
998+ * @return the resources of a specific node.
999+ */
9911000 @ Override
9921001 public ResourceInfo updateNodeResource (HttpServletRequest hsr ,
9931002 String nodeId , ResourceOptionInfo resourceOption ) {
@@ -1048,29 +1057,24 @@ public ClusterMetricsInfo getClusterMetricsInfo() {
10481057 public AppState getAppState (HttpServletRequest hsr , String appId )
10491058 throws AuthorizationException {
10501059
1051- ApplicationId applicationId = null ;
1060+ // Check that the appId format is accurate
10521061 try {
1053- applicationId = ApplicationId . fromString (appId );
1062+ RouterServerUtil . validateApplicationId (appId );
10541063 } catch (IllegalArgumentException e ) {
1055- return null ;
1064+ throw e ;
10561065 }
10571066
1058- SubClusterInfo subClusterInfo = null ;
1059- SubClusterId subClusterId = null ;
1067+ // Get SubCluster according to appId.
1068+ SubClusterInfo subClusterInfo ;
10601069 try {
1061- subClusterId =
1062- federationFacade .getApplicationHomeSubCluster (applicationId );
1063- if (subClusterId == null ) {
1064- return null ;
1065- }
1066- subClusterInfo = federationFacade .getSubCluster (subClusterId );
1070+ subClusterInfo = getHomeSubClusterInfoByAppId (appId );
10671071 } catch (YarnException e ) {
1072+ LOG .error ("getHomeSubClusterInfoByAppId error, applicationId = {}." , appId , e );
10681073 return null ;
10691074 }
10701075
1071- DefaultRequestInterceptorREST interceptor =
1072- getOrCreateInterceptorForSubCluster (subClusterId ,
1073- subClusterInfo .getRMWebServiceAddress ());
1076+ // Call the appState interface.
1077+ DefaultRequestInterceptorREST interceptor = getOrCreateInterceptorForSubCluster (subClusterInfo );
10741078 return interceptor .getAppState (hsr , appId );
10751079 }
10761080
@@ -1321,7 +1325,7 @@ public AppActivitiesInfo getAppActivities(HttpServletRequest hsr,
13211325 long startTime = clock .getTime ();
13221326 SubClusterInfo subClusterInfo = getHomeSubClusterInfoByAppId (appId );
13231327 DefaultRequestInterceptorREST interceptor = getOrCreateInterceptorForSubCluster (
1324- subClusterInfo . getSubClusterId (), subClusterInfo . getRMWebServiceAddress () );
1328+ subClusterInfo );
13251329 final HttpServletRequest hsrCopy = clone (hsr );
13261330 AppActivitiesInfo appActivitiesInfo = interceptor .getAppActivities (hsrCopy , appId , time ,
13271331 requestPriorities , allocationRequestIds , groupBy , limit , actions , summarize );
@@ -1552,13 +1556,13 @@ public Response addToClusterNodeLabels(NodeLabelsInfo newNodeLabels,
15521556
15531557 try {
15541558 long startTime = clock .getTime ();
1555- Map < SubClusterId , SubClusterInfo > subClustersActive = getActiveSubclusters ();
1559+ Collection < SubClusterInfo > subClustersActives = federationFacade . getActiveSubClusters ();
15561560 final HttpServletRequest hsrCopy = clone (hsr );
15571561 Class [] argsClasses = new Class []{NodeLabelsInfo .class , HttpServletRequest .class };
15581562 Object [] args = new Object []{newNodeLabels , hsrCopy };
15591563 ClientMethod remoteMethod = new ClientMethod ("addToClusterNodeLabels" , argsClasses , args );
15601564 Map <SubClusterInfo , Response > responseInfoMap =
1561- invokeConcurrent (subClustersActive . values () , remoteMethod , Response .class );
1565+ invokeConcurrent (subClustersActives , remoteMethod , Response .class );
15621566 StringBuffer buffer = new StringBuffer ();
15631567 // SubCluster-0:SUCCESS,SubCluster-1:SUCCESS
15641568 responseInfoMap .forEach ((subClusterInfo , response ) -> {
@@ -1600,14 +1604,14 @@ public Response removeFromClusterNodeLabels(Set<String> oldNodeLabels,
16001604
16011605 try {
16021606 long startTime = clock .getTime ();
1603- Map < SubClusterId , SubClusterInfo > subClustersActive = getActiveSubclusters ();
1607+ Collection < SubClusterInfo > subClustersActives = federationFacade . getActiveSubClusters ();
16041608 final HttpServletRequest hsrCopy = clone (hsr );
16051609 Class [] argsClasses = new Class []{Set .class , HttpServletRequest .class };
16061610 Object [] args = new Object []{oldNodeLabels , hsrCopy };
16071611 ClientMethod remoteMethod =
16081612 new ClientMethod ("removeFromClusterNodeLabels" , argsClasses , args );
16091613 Map <SubClusterInfo , Response > responseInfoMap =
1610- invokeConcurrent (subClustersActive . values () , remoteMethod , Response .class );
1614+ invokeConcurrent (subClustersActives , remoteMethod , Response .class );
16111615 StringBuffer buffer = new StringBuffer ();
16121616 // SubCluster-0:SUCCESS,SubCluster-1:SUCCESS
16131617 responseInfoMap .forEach ((subClusterInfo , response ) -> {
@@ -1629,7 +1633,7 @@ public Response removeFromClusterNodeLabels(Set<String> oldNodeLabels,
16291633 }
16301634
16311635 /**
1632- * Bbulid Append information.
1636+ * Build Append information.
16331637 *
16341638 * @param subClusterInfo subCluster information.
16351639 * @param buffer StringBuffer.
0 commit comments