GutoVeronezi commented on a change in pull request #5588:
URL: https://github.com/apache/cloudstack/pull/5588#discussion_r736463244



##########
File path: 
framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java
##########
@@ -1141,7 +1183,10 @@ private boolean pingManagementNode(final 
ManagementServerHostVO mshost) {
                 return true;
             } catch (final IOException e) {
                 if (e instanceof ConnectException) {
-                    s_logger.error("Unable to ping management server at " + 
targetIp + ":" + mshost.getServicePort() + " due to ConnectException", e);
+                    s_logger.error("Unable to ping management server at " + 
targetIp + ":" + mshost.getServicePort() + " due to ConnectException");
+                    if (s_logger.isDebugEnabled()) {
+                        s_logger.debug("Unable to ping management server at " 
+ targetIp + ":" + mshost.getServicePort() + " due to ConnectException", e);

Review comment:
       Wouldn't be better to pass the exception in the `s_logger.error` call?

##########
File path: 
plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java
##########
@@ -344,52 +355,107 @@ public InfrastructureResponse listInfrastructure() {
             // CPU and memory capacities
             final CapacityDaoImpl.SummedCapacity cpuCapacity = 
getCapacity((int) Capacity.CAPACITY_TYPE_CPU, null, clusterId);
             final CapacityDaoImpl.SummedCapacity memoryCapacity = 
getCapacity((int) Capacity.CAPACITY_TYPE_MEMORY, null, clusterId);
-            final Metrics metrics = new Metrics(cpuCapacity, memoryCapacity);
+            final org.apache.cloudstack.metrics.MetricsServiceImpl.HostMetrics 
hostMetrics = new 
org.apache.cloudstack.metrics.MetricsServiceImpl.HostMetrics(cpuCapacity, 
memoryCapacity);
 
             for (final Host host: hostDao.findByClusterId(clusterId)) {
                 if (host == null || host.getType() != Host.Type.Routing) {
                     continue;
                 }
                 if (host.getStatus() == Status.Up) {
-                    metrics.incrUpResources();
+                    hostMetrics.incrUpResources();
                 }
-                metrics.incrTotalResources();
-                updateHostMetrics(metrics, hostJoinDao.findById(host.getId()));
+                hostMetrics.incrTotalResources();
+                updateHostMetrics(hostMetrics, 
hostJoinDao.findById(host.getId()));
             }
 
             metricsResponse.setState(clusterResponse.getAllocationState(), 
clusterResponse.getManagedState());
-            metricsResponse.setResources(metrics.getUpResources(), 
metrics.getTotalResources());
+            metricsResponse.setResources(hostMetrics.getUpResources(), 
hostMetrics.getTotalResources());
             // CPU
-            metricsResponse.setCpuTotal(metrics.getTotalCpu());
-            metricsResponse.setCpuAllocated(metrics.getCpuAllocated(), 
metrics.getTotalCpu());
-            if (metrics.getCpuUsedPercentage() > 0L) {
-                metricsResponse.setCpuUsed(metrics.getCpuUsedPercentage(), 
metrics.getTotalHosts());
-                
metricsResponse.setCpuMaxDeviation(metrics.getMaximumCpuUsage(), 
metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
+            metricsResponse.setCpuTotal(hostMetrics.getTotalCpu());
+            metricsResponse.setCpuAllocated(hostMetrics.getCpuAllocated(), 
hostMetrics.getTotalCpu());
+            if (hostMetrics.getCpuUsedPercentage() > 0L) {
+                metricsResponse.setCpuUsed(hostMetrics.getCpuUsedPercentage(), 
hostMetrics.getTotalHosts());
+                
metricsResponse.setCpuMaxDeviation(hostMetrics.getMaximumCpuUsage(), 
hostMetrics.getCpuUsedPercentage(), hostMetrics.getTotalHosts());
             }
             // Memory
-            metricsResponse.setMemTotal(metrics.getTotalMemory());
-            metricsResponse.setMemAllocated(metrics.getMemoryAllocated(), 
metrics.getTotalMemory());
-            if (metrics.getMemoryUsed() > 0L) {
-                metricsResponse.setMemUsed(metrics.getMemoryUsed(), 
metrics.getTotalMemory());
-                
metricsResponse.setMemMaxDeviation(metrics.getMaximumMemoryUsage(), 
metrics.getMemoryUsed(), metrics.getTotalHosts());
+            metricsResponse.setMemTotal(hostMetrics.getTotalMemory());
+            metricsResponse.setMemAllocated(hostMetrics.getMemoryAllocated(), 
hostMetrics.getTotalMemory());
+            if (hostMetrics.getMemoryUsed() > 0L) {
+                metricsResponse.setMemUsed(hostMetrics.getMemoryUsed(), 
hostMetrics.getTotalMemory());
+                
metricsResponse.setMemMaxDeviation(hostMetrics.getMaximumMemoryUsage(), 
hostMetrics.getMemoryUsed(), hostMetrics.getTotalHosts());
             }
             // CPU thresholds
-            
metricsResponse.setCpuUsageThreshold(metrics.getCpuUsedPercentage(), 
metrics.getTotalHosts(), cpuThreshold);
-            
metricsResponse.setCpuUsageDisableThreshold(metrics.getCpuUsedPercentage(), 
metrics.getTotalHosts(), cpuDisableThreshold);
-            
metricsResponse.setCpuAllocatedThreshold(metrics.getCpuAllocated(), 
metrics.getTotalCpu(), cpuThreshold);
-            
metricsResponse.setCpuAllocatedDisableThreshold(metrics.getCpuAllocated(), 
metrics.getTotalCpu(), cpuDisableThreshold);
+            
metricsResponse.setCpuUsageThreshold(hostMetrics.getCpuUsedPercentage(), 
hostMetrics.getTotalHosts(), cpuThreshold);
+            
metricsResponse.setCpuUsageDisableThreshold(hostMetrics.getCpuUsedPercentage(), 
hostMetrics.getTotalHosts(), cpuDisableThreshold);
+            
metricsResponse.setCpuAllocatedThreshold(hostMetrics.getCpuAllocated(), 
hostMetrics.getTotalCpu(), cpuThreshold);
+            
metricsResponse.setCpuAllocatedDisableThreshold(hostMetrics.getCpuAllocated(), 
hostMetrics.getTotalCpu(), cpuDisableThreshold);
             // Memory thresholds
-            metricsResponse.setMemoryUsageThreshold(metrics.getMemoryUsed(), 
metrics.getTotalMemory(), memoryThreshold);
-            
metricsResponse.setMemoryUsageDisableThreshold(metrics.getMemoryUsed(), 
metrics.getTotalMemory(), memoryDisableThreshold);
-            
metricsResponse.setMemoryAllocatedThreshold(metrics.getMemoryAllocated(), 
metrics.getTotalMemory(), memoryThreshold);
-            
metricsResponse.setMemoryAllocatedDisableThreshold(metrics.getMemoryAllocated(),
 metrics.getTotalMemory(), memoryDisableThreshold);
+            
metricsResponse.setMemoryUsageThreshold(hostMetrics.getMemoryUsed(), 
hostMetrics.getTotalMemory(), memoryThreshold);
+            
metricsResponse.setMemoryUsageDisableThreshold(hostMetrics.getMemoryUsed(), 
hostMetrics.getTotalMemory(), memoryDisableThreshold);
+            
metricsResponse.setMemoryAllocatedThreshold(hostMetrics.getMemoryAllocated(), 
hostMetrics.getTotalMemory(), memoryThreshold);
+            
metricsResponse.setMemoryAllocatedDisableThreshold(hostMetrics.getMemoryAllocated(),
 hostMetrics.getTotalMemory(), memoryDisableThreshold);

Review comment:
       We could split this code in several methods  with proper names, avoiding 
long methods and comments.

##########
File path: 
framework/cluster/src/main/java/com/cloud/cluster/ManagementServerStatusVO.java
##########
@@ -0,0 +1,195 @@
+// 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
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// 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 com.cloud.cluster;
+
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.management.ManagementServerStatus;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import java.util.Date;
+
+@Entity
+@Table(name = "mshost_status")
+public class ManagementServerStatusVO implements ManagementServerStatus {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "ms_id", nullable = false)
+    private String msId;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name="last_start")
+    private Date lastStart;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name="last_stop")
+    private Date lastStop;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name="last_boot")
+    private Date lastBoot;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name="last_down")
+    private Date lastDown;
+
+    @Column(name="os_distribution")
+    private String osDistribution;
+
+    @Column(name="java_name")
+    private String javaName;
+
+    @Column(name="java_version")
+    private String javaVersion;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name = "updated")
+    private Date updated;
+
+    @Column(name = GenericDao.CREATED_COLUMN)
+    private Date created;
+
+    @Column(name = GenericDao.REMOVED_COLUMN)
+    private Date removed;
+
+
+    public ManagementServerStatusVO() {
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    @Override
+    public String getMsId() {
+        return msId;
+    }
+
+    public void setMsId(String msId) {
+        this.msId = msId;
+    }
+
+    @Override
+    public Date getLastStart() {
+        return lastStart;
+    }
+
+    public void setLastStart(Date lastStart) {
+        this.lastStart = lastStart;
+    }
+
+    @Override
+    public Date getLastStop() {
+        return lastStop;
+    }
+
+    public void setLastStop(Date lastStop) {
+        this.lastStop = lastStop;
+    }
+
+    @Override
+    public Date getLastBoot() {
+        return lastBoot;
+    }
+
+    public void setLastBoot(Date lastBoot) {
+        this.lastBoot = lastBoot;
+    }
+
+    @Override
+    public Date getLastDown() {
+        return lastDown;
+    }
+
+    public void setLastDown(Date lastDown) {
+        this.lastDown = lastDown;
+    }
+
+    @Override
+    public String getOsDistribution() {
+        return osDistribution;
+    }
+
+    public void setOsDistribution(String osDistribution) {
+        this.osDistribution = osDistribution;
+    }
+
+    @Override
+    public String getJavaName() {
+        return javaName;
+    }
+
+    public void setJavaName(String javaName) {
+        this.javaName = javaName;
+    }
+
+    @Override
+    public String getJavaVersion() {
+        return javaVersion;
+    }
+
+    public void setJavaVersion(String javaVersion) {
+        this.javaVersion = javaVersion;
+    }
+
+    @Override
+    public Date getUpdated() {
+        return updated;
+    }
+
+    public void setUpdated(Date updated) {
+        this.updated = updated;
+    }
+
+    @Override
+    public Date getCreated() {
+        return created;
+    }
+
+    public void setCreated(Date created) {
+        this.created = created;
+    }
+
+    @Override
+    public Date getRemoved() {
+        return removed;
+    }
+
+    public void setRemoved(Date removedTime) {
+        removed = removedTime;
+    }
+
+    @Override
+    public String toString() {
+        return new 
org.apache.commons.lang3.builder.ReflectionToStringBuilder(this, 
org.apache.commons.lang3.builder.ToStringStyle.SIMPLE_STYLE).toString();

Review comment:
       Could we reference the path in the import and only use the method here?

##########
File path: 
plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java
##########
@@ -122,16 +133,16 @@ private Double findRatioValue(final String value) {
         return 1.0;
     }
 
-    private void updateHostMetrics(final Metrics metrics, final HostJoinVO 
host) {
-        metrics.incrTotalHosts();
-        metrics.addCpuAllocated(host.getCpuReservedCapacity() + 
host.getCpuUsedCapacity());
-        metrics.addMemoryAllocated(host.getMemReservedCapacity() + 
host.getMemUsedCapacity());
+    private void updateHostMetrics(final 
org.apache.cloudstack.metrics.MetricsServiceImpl.HostMetrics hostMetrics, final 
HostJoinVO host) {

Review comment:
       @DaanHoogland, is there any technical reason to use the full path of 
this subclass, along this class?




-- 
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]


Reply via email to