|
46 | 46 | import org.apache.commons.lang3.NotImplementedException; |
47 | 47 | import org.apache.commons.lang3.StringUtils; |
48 | 48 | import org.apache.hadoop.conf.Configuration; |
| 49 | +import org.apache.hadoop.fs.impl.prefetch.Validate; |
49 | 50 | import org.apache.hadoop.io.Text; |
50 | 51 | import org.apache.hadoop.security.UserGroupInformation; |
51 | 52 | import org.apache.hadoop.security.authorize.AuthorizationException; |
|
121 | 122 | import org.apache.hadoop.yarn.server.router.clientrm.RouterClientRMService; |
122 | 123 | import org.apache.hadoop.yarn.server.router.security.RouterDelegationTokenSecretManager; |
123 | 124 | import org.apache.hadoop.yarn.server.router.webapp.cache.RouterAppInfoCacheKey; |
| 125 | +import org.apache.hadoop.yarn.server.router.webapp.dao.FederationBulkActivitiesInfo; |
124 | 126 | import org.apache.hadoop.yarn.server.router.webapp.dao.FederationRMQueueAclInfo; |
125 | 127 | import org.apache.hadoop.yarn.server.router.webapp.dao.SubClusterResult; |
126 | 128 | import org.apache.hadoop.yarn.server.router.webapp.dao.FederationSchedulerTypeInfo; |
@@ -1187,16 +1189,110 @@ public String dumpSchedulerLogs(String time, HttpServletRequest hsr) |
1187 | 1189 | throw new NotImplementedException("Code is not implemented"); |
1188 | 1190 | } |
1189 | 1191 |
|
| 1192 | + /** |
| 1193 | + * This method retrieve all the activities in a specific node, and it is |
| 1194 | + * reachable by using {@link RMWSConsts#SCHEDULER_ACTIVITIES}. |
| 1195 | + * |
| 1196 | + * @param hsr the servlet request |
| 1197 | + * @param nodeId the node we want to retrieve the activities. It is a |
| 1198 | + * QueryParam. |
| 1199 | + * @param groupBy the groupBy type by which the activities should be |
| 1200 | + * aggregated. It is a QueryParam. |
| 1201 | + * @return all the activities in the specific node |
| 1202 | + */ |
1190 | 1203 | @Override |
1191 | 1204 | public ActivitiesInfo getActivities(HttpServletRequest hsr, String nodeId, |
1192 | 1205 | String groupBy) { |
1193 | | - throw new NotImplementedException("Code is not implemented"); |
| 1206 | + try { |
| 1207 | + // Check the parameters to ensure that the parameters are not empty |
| 1208 | + Validate.checkNotNullAndNotEmpty(nodeId, "nodeId"); |
| 1209 | + Validate.checkNotNullAndNotEmpty(groupBy, "groupBy"); |
| 1210 | + |
| 1211 | + // Query SubClusterInfo according to id, |
| 1212 | + // if the nodeId cannot get SubClusterInfo, an exception will be thrown directly. |
| 1213 | + SubClusterInfo subClusterInfo = getNodeSubcluster(nodeId); |
| 1214 | + |
| 1215 | + // Call the corresponding subCluster to get ActivitiesInfo. |
| 1216 | + long startTime = clock.getTime(); |
| 1217 | + DefaultRequestInterceptorREST interceptor = getOrCreateInterceptorForSubCluster( |
| 1218 | + subClusterInfo.getSubClusterId(), subClusterInfo.getRMWebServiceAddress()); |
| 1219 | + final HttpServletRequest hsrCopy = clone(hsr); |
| 1220 | + ActivitiesInfo activitiesInfo = interceptor.getActivities(hsrCopy, nodeId, groupBy); |
| 1221 | + if (activitiesInfo != null) { |
| 1222 | + long stopTime = clock.getTime(); |
| 1223 | + routerMetrics.succeededGetActivitiesLatencyRetrieved(stopTime - startTime); |
| 1224 | + return activitiesInfo; |
| 1225 | + } |
| 1226 | + } catch (IllegalArgumentException e) { |
| 1227 | + routerMetrics.incrGetActivitiesFailedRetrieved(); |
| 1228 | + throw e; |
| 1229 | + } catch (NotFoundException e) { |
| 1230 | + routerMetrics.incrGetActivitiesFailedRetrieved(); |
| 1231 | + throw e; |
| 1232 | + } |
| 1233 | + |
| 1234 | + routerMetrics.incrGetActivitiesFailedRetrieved(); |
| 1235 | + throw new RuntimeException("getActivities Failed."); |
1194 | 1236 | } |
1195 | 1237 |
|
| 1238 | + /** |
| 1239 | + * This method retrieve the last n activities inside scheduler, and it is |
| 1240 | + * reachable by using {@link RMWSConsts#SCHEDULER_BULK_ACTIVITIES}. |
| 1241 | + * |
| 1242 | + * @param hsr the servlet request |
| 1243 | + * @param groupBy the groupBy type by which the activities should be |
| 1244 | + * aggregated. It is a QueryParam. |
| 1245 | + * @param activitiesCount number of activities |
| 1246 | + * @return last n activities |
| 1247 | + */ |
1196 | 1248 | @Override |
1197 | 1249 | public BulkActivitiesInfo getBulkActivities(HttpServletRequest hsr, |
1198 | 1250 | String groupBy, int activitiesCount) throws InterruptedException { |
1199 | | - throw new NotImplementedException("Code is not implemented"); |
| 1251 | + try { |
| 1252 | + // Step1. Check the parameters to ensure that the parameters are not empty |
| 1253 | + Validate.checkNotNullAndNotEmpty(groupBy, "groupBy"); |
| 1254 | + Validate.checkNotNegative(activitiesCount, "activitiesCount"); |
| 1255 | + |
| 1256 | + // Step2. Call the interface of subCluster concurrently and get the returned result. |
| 1257 | + Map<SubClusterId, SubClusterInfo> subClustersActive = getActiveSubclusters(); |
| 1258 | + final HttpServletRequest hsrCopy = clone(hsr); |
| 1259 | + Class[] argsClasses = new Class[]{HttpServletRequest.class, String.class, int.class}; |
| 1260 | + Object[] args = new Object[]{hsrCopy, groupBy, activitiesCount}; |
| 1261 | + ClientMethod remoteMethod = new ClientMethod("getBulkActivities", argsClasses, args); |
| 1262 | + Map<SubClusterInfo, BulkActivitiesInfo> appStatisticsMap = invokeConcurrent( |
| 1263 | + subClustersActive.values(), remoteMethod, BulkActivitiesInfo.class); |
| 1264 | + |
| 1265 | + // Step3. Generate Federation objects and set subCluster information. |
| 1266 | + long startTime = clock.getTime(); |
| 1267 | + FederationBulkActivitiesInfo fedBulkActivitiesInfo = new FederationBulkActivitiesInfo(); |
| 1268 | + appStatisticsMap.forEach((subClusterInfo, bulkActivitiesInfo) -> { |
| 1269 | + SubClusterId subClusterId = subClusterInfo.getSubClusterId(); |
| 1270 | + bulkActivitiesInfo.setSubClusterId(subClusterId.getId()); |
| 1271 | + fedBulkActivitiesInfo.getList().add(bulkActivitiesInfo); |
| 1272 | + }); |
| 1273 | + long stopTime = clock.getTime(); |
| 1274 | + routerMetrics.succeededGetBulkActivitiesRetrieved(stopTime - startTime); |
| 1275 | + return fedBulkActivitiesInfo; |
| 1276 | + } catch (IllegalArgumentException e) { |
| 1277 | + routerMetrics.incrGetBulkActivitiesFailedRetrieved(); |
| 1278 | + throw e; |
| 1279 | + } catch (NotFoundException e) { |
| 1280 | + routerMetrics.incrGetBulkActivitiesFailedRetrieved(); |
| 1281 | + RouterServerUtil.logAndThrowRunTimeException("get all active sub cluster(s) error.", e); |
| 1282 | + } catch (IOException e) { |
| 1283 | + routerMetrics.incrGetBulkActivitiesFailedRetrieved(); |
| 1284 | + RouterServerUtil.logAndThrowRunTimeException(e, |
| 1285 | + "getBulkActivities by groupBy = %s, activitiesCount = %s with io error.", |
| 1286 | + groupBy, String.valueOf(activitiesCount)); |
| 1287 | + } catch (YarnException e) { |
| 1288 | + routerMetrics.incrGetBulkActivitiesFailedRetrieved(); |
| 1289 | + RouterServerUtil.logAndThrowRunTimeException(e, |
| 1290 | + "getBulkActivities by groupBy = %s, activitiesCount = %s with yarn error.", |
| 1291 | + groupBy, String.valueOf(activitiesCount)); |
| 1292 | + } |
| 1293 | + |
| 1294 | + routerMetrics.incrGetBulkActivitiesFailedRetrieved(); |
| 1295 | + throw new RuntimeException("getBulkActivities Failed."); |
1200 | 1296 | } |
1201 | 1297 |
|
1202 | 1298 | @Override |
|
0 commit comments