slfan1989 commented on code in PR #4946: URL: https://github.com/apache/hadoop/pull/4946#discussion_r988468315
########## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/dao/RouterClusterMetrics.java: ########## @@ -0,0 +1,310 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.yarn.server.router.webapp.dao; + +import org.apache.hadoop.util.StringUtils; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterMetricsInfo; +import org.apache.hadoop.yarn.util.resource.Resources; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class RouterClusterMetrics { + + protected static final long BYTES_IN_MB = 1024 * 1024; + private static final Logger LOG = LoggerFactory.getLogger(RouterClusterMetrics.class); + + /** Application Information. **/ + private String appsSubmitted = "N/A"; + private String appsCompleted = "N/A"; + private String appsPending = "N/A"; + private String appsRunning = "N/A"; + private String appsFailed = "N/A"; + private String appsKilled = "N/A"; + + /** Memory Information. **/ + private String totalMemory = "N/A"; + private String reservedMemory = "N/A"; + private String availableMemory = "N/A"; + private String allocatedMemory = "N/A"; + private String pendingMemory = "N/A"; + + /** VirtualCores Information. **/ + private String reservedVirtualCores = "N/A"; + private String availableVirtualCores = "N/A"; + private String allocatedVirtualCores = "N/A"; + private String pendingVirtualCores = "N/A"; + private String totalVirtualCores = "N/A"; + + /** Resources Information. **/ + private String usedResources = "N/A"; + private String totalResources = "N/A"; + private String reservedResources = "N/A"; + private String allocatedContainers = "N/A"; + + /** Resource Percent Information. **/ + private String utilizedMBPercent = "N/A"; + private String utilizedVirtualCoresPercent = "N/A"; + + /** Node Information. **/ + private String activeNodes = "N/A"; + private String decommissioningNodes = "N/A"; + private String decommissionedNodes = "N/A"; + private String lostNodes = "N/A"; + private String unhealthyNodes = "N/A"; + private String rebootedNodes = "N/A"; + private String shutdownNodes = "N/A"; + + public RouterClusterMetrics() { + + } + + public RouterClusterMetrics(ClusterMetricsInfo metrics) { + if (metrics != null) { + /** Application Information Conversion. **/ + conversionApplicationInformation(metrics); + + /** Memory Information Conversion. **/ + conversionMemoryInformation(metrics); + + /** Resources Information Conversion. **/ + conversionResourcesInformation(metrics); + + /** Percent Information Conversion. **/ + conversionResourcesPercent(metrics); + + /** Node Information Conversion. **/ + conversionNodeInformation(metrics); + } + } + + // Get Key Metric Information + public String getAppsSubmitted() { + return appsSubmitted; + } + + public String getAppsCompleted() { + return appsCompleted; + } + + public String getAppsPending() { + return appsPending; + } + + public String getAppsRunning() { + return appsRunning; + } + + public String getAppsFailed() { + return appsFailed; + } + + public String getAppsKilled() { + return appsKilled; + } + + public String getTotalMemory() { + return totalMemory; + } + + public String getReservedMemory() { + return reservedMemory; + } + + public String getAvailableMemory() { + return availableMemory; + } + + public String getAllocatedMemory() { + return allocatedMemory; + } + + public String getPendingMemory() { + return pendingMemory; + } + + public String getReservedVirtualCores() { + return reservedVirtualCores; + } + + public String getAvailableVirtualCores() { + return availableVirtualCores; + } + + public String getAllocatedVirtualCores() { + return allocatedVirtualCores; + } + + public String getPendingVirtualCores() { + return pendingVirtualCores; + } + + public String getTotalVirtualCores() { + return totalVirtualCores; + } + + public String getUsedResources() { + return usedResources; + } + + public String getTotalResources() { + return totalResources; + } + + public String getReservedResources() { + return reservedResources; + } + + public String getAllocatedContainers() { + return allocatedContainers; + } + + public String getUtilizedMBPercent() { + return utilizedMBPercent; + } + + public String getUtilizedVirtualCoresPercent() { + return utilizedVirtualCoresPercent; + } + + public String getActiveNodes() { + return activeNodes; + } + + public String getDecommissioningNodes() { + return decommissioningNodes; + } + + public String getDecommissionedNodes() { + return decommissionedNodes; + } + + public String getLostNodes() { + return lostNodes; + } + + public String getUnhealthyNodes() { + return unhealthyNodes; + } + + public String getRebootedNodes() { + return rebootedNodes; + } + + public String getShutdownNodes() { + return shutdownNodes; + } + + // Metric Information Conversion + public void conversionApplicationInformation(ClusterMetricsInfo metrics) { + try { + /** Application Information. **/ + this.appsSubmitted = String.valueOf(metrics.getAppsSubmitted()); + this.appsCompleted = String.valueOf(metrics.getAppsCompleted() + + metrics.getAppsFailed() + metrics.getAppsKilled()); + this.appsPending = String.valueOf(metrics.getAppsPending()); + this.appsRunning = String.valueOf(metrics.getAppsRunning()); + this.appsFailed = String.valueOf(metrics.getAppsFailed()); + this.appsKilled = String.valueOf(metrics.getAppsKilled()); + } catch (Exception e) { + LOG.error("conversionApplicationInformation error.", e); + } + } + + // Metric Memory Information + public void conversionMemoryInformation(ClusterMetricsInfo metrics) { + try { + /** Memory Information. **/ Review Comment: I will fix it. ########## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/dao/RouterInfo.java: ########## @@ -0,0 +1,104 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.yarn.server.router.webapp.dao; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.service.Service; +import org.apache.hadoop.util.VersionInfo; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.server.router.Router; +import org.apache.hadoop.yarn.util.YarnVersionInfo; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class RouterInfo { + private long id; + private long startedOn; + private Service.STATE state; + private String routerStateStoreName; + private String routerVersion; + private String routerBuildVersion; + private String routerVersionBuiltOn; + private String hadoopVersion; + private String hadoopBuildVersion; + private String hadoopVersionBuiltOn; + + public RouterInfo() { + } // JAXB needs this + + public RouterInfo(Router router) { + long ts = Router.getClusterTimeStamp(); + this.id = ts; + this.state = router.getServiceState(); + Configuration configuration = router.getConfig(); + this.routerStateStoreName = Review Comment: I will fix it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
