5050import org .apache .hadoop .util .concurrent .HadoopExecutors ;
5151import org .apache .hadoop .yarn .api .records .ApplicationId ;
5252import org .apache .hadoop .yarn .api .records .ApplicationSubmissionContext ;
53+ import org .apache .hadoop .yarn .api .records .ContainerId ;
5354import org .apache .hadoop .yarn .api .records .NodeLabel ;
5455import org .apache .hadoop .yarn .conf .YarnConfiguration ;
5556import org .apache .hadoop .yarn .exceptions .YarnException ;
@@ -1415,7 +1416,39 @@ public ContainersInfo getContainers(HttpServletRequest req,
14151416 public ContainerInfo getContainer (HttpServletRequest req ,
14161417 HttpServletResponse res , String appId , String appAttemptId ,
14171418 String containerId ) {
1418- throw new NotImplementedException ("Code is not implemented" );
1419+
1420+ if (appId == null || appId .isEmpty ()) {
1421+ throw new IllegalArgumentException ("Parameter error, the appId is empty or null." );
1422+ }
1423+ if (appAttemptId == null || appAttemptId .isEmpty ()) {
1424+ throw new IllegalArgumentException ("Parameter error, the appAttemptId is empty or null." );
1425+ }
1426+ if (containerId == null || containerId .isEmpty ()) {
1427+ throw new IllegalArgumentException ("Parameter error, the containerId is empty or null." );
1428+ }
1429+
1430+ try {
1431+ ApplicationId applicationId = ApplicationId .fromString (appId );
1432+ SubClusterInfo subClusterInfo = getHomeSubClusterInfoByAppId (applicationId );
1433+
1434+ if (subClusterInfo == null ) {
1435+ RouterServerUtil .logAndThrowRunTimeException ("Unable to get subCluster by applicationId = " +
1436+ applicationId , null );
1437+ }
1438+
1439+ DefaultRequestInterceptorREST interceptor = getOrCreateInterceptorForSubCluster (
1440+ subClusterInfo .getSubClusterId (), subClusterInfo .getRMWebServiceAddress ());
1441+ return interceptor .getContainer (req , res , appId , appAttemptId , containerId );
1442+ } catch (IllegalArgumentException e ) {
1443+ String msg = String .format (
1444+ "Unable to get the AppAttempt appId: %s, appAttemptId: %s, containerId: %s." , appId ,
1445+ appAttemptId , containerId );
1446+ RouterServerUtil .logAndThrowRunTimeException (msg , e );
1447+ } catch (YarnException e ) {
1448+ RouterServerUtil .logAndThrowRunTimeException ("getContainer Failed." , e );
1449+ }
1450+
1451+ return null ;
14191452 }
14201453
14211454 @ Override
@@ -1442,7 +1475,37 @@ public void setNextInterceptor(RESTRequestInterceptor next) {
14421475 @ Override
14431476 public Response signalToContainer (String containerId , String command ,
14441477 HttpServletRequest req ) {
1445- throw new NotImplementedException ("Code is not implemented" );
1478+
1479+ if (containerId == null || containerId .isEmpty ()) {
1480+ throw new IllegalArgumentException ("Parameter error, the containerId is empty or null." );
1481+ }
1482+
1483+ if (command == null || command .isEmpty ()) {
1484+ throw new IllegalArgumentException ("Parameter error, the command is empty or null." );
1485+ }
1486+
1487+ try {
1488+ ContainerId containerIdObj = ContainerId .fromString (containerId );
1489+ ApplicationId applicationId = containerIdObj .getApplicationAttemptId ().getApplicationId ();
1490+
1491+ SubClusterInfo subClusterInfo = getHomeSubClusterInfoByAppId (applicationId );
1492+
1493+ if (subClusterInfo == null ) {
1494+ RouterServerUtil .logAndThrowRunTimeException ("Unable to get subCluster by applicationId = " +
1495+ applicationId , null );
1496+ }
1497+
1498+ DefaultRequestInterceptorREST interceptor = getOrCreateInterceptorForSubCluster (
1499+ subClusterInfo .getSubClusterId (), subClusterInfo .getRMWebServiceAddress ());
1500+ return interceptor .signalToContainer (containerId , command , req );
1501+
1502+ } catch (YarnException e ) {
1503+ RouterServerUtil .logAndThrowRunTimeException ("signalToContainer Failed." , e );
1504+ } catch (AuthorizationException e ) {
1505+ RouterServerUtil .logAndThrowRunTimeException ("signalToContainer Author Failed." , e );
1506+ }
1507+
1508+ return null ;
14461509 }
14471510
14481511 @ Override
@@ -1494,4 +1557,28 @@ private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> c
14941557 });
14951558 return results ;
14961559 }
1560+
1561+ /**
1562+ * get the HomeSubCluster according to ApplicationId.
1563+ *
1564+ * @param applicationId applicationId
1565+ * @return HomeSubCluster
1566+ * @throws YarnException on failure
1567+ */
1568+ private SubClusterInfo getHomeSubClusterInfoByAppId (ApplicationId applicationId ) throws YarnException {
1569+ SubClusterInfo subClusterInfo = null ;
1570+ SubClusterId subClusterId = null ;
1571+ try {
1572+ subClusterId = federationFacade .getApplicationHomeSubCluster (applicationId );
1573+ if (subClusterId == null ) {
1574+ RouterServerUtil .logAndThrowException ("Can't get HomeSubCluster by applicationId "
1575+ + applicationId , null );
1576+ }
1577+ subClusterInfo = federationFacade .getSubCluster (subClusterId );
1578+ } catch (YarnException e ) {
1579+ RouterServerUtil .logAndThrowException ("Get HomeSubClusterInfo by applicationId "
1580+ + applicationId + " failed." , e );
1581+ }
1582+ return subClusterInfo ;
1583+ }
14971584}
0 commit comments