Browse Source

AMBARI-1504. Hosts show physical CPUs, instead of cores. (Sumit Mohanty via swagle)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1459981 13f79535-47bb-0310-9956-ffa450edef68
Siddharth Wagle 12 years ago
parent
commit
f75189b60f

+ 3 - 0
CHANGES.txt

@@ -509,6 +509,9 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1504. Hosts show physical CPUs, instead of cores. (Sumit Mohanty 
+ via swagle)
+
  AMBARI-1685. Remove running of smoke tests by default when services or 
  master components are started. (Sumit Mohanty via swagle)
 

+ 26 - 3
ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java

@@ -49,7 +49,13 @@ public class HostResponse {
    * Count of cores on Host
    */
   private int cpuCount;
-
+  
+  /**
+   * Count of physical cores on Host
+   */
+  private int phCpuCount;
+  
+  
   /**
    * Os Architecture
    */
@@ -128,7 +134,7 @@ public class HostResponse {
   private Map<String, DesiredConfig> desiredConfigs;
 
   public HostResponse(String hostname, String clusterName,
-                      String ipv4, String ipv6, int cpuCount, String osArch, String osType,
+                      String ipv4, String ipv6, int cpuCount, int phCpuCount, String osArch, String osType,
                       String osInfo, long availableMemBytes, long totalMemBytes,
                       List<DiskInfo> disksInfo, long lastHeartbeatTime,
                       long lastRegistrationTime, String rackInfo,
@@ -140,6 +146,7 @@ public class HostResponse {
     this.ipv4 = ipv4;
     this.ipv6 = ipv6;
     this.cpuCount = cpuCount;
+    this.phCpuCount = phCpuCount;
     this.osArch = osArch;
     this.osType = osType;
     this.osInfo = osInfo;
@@ -158,7 +165,7 @@ public class HostResponse {
   //todo: why are we passing in empty strings for host/cluster name instead of null?
   public HostResponse(String hostname) {
     this(hostname, "", "", "",
-        0, "", "",
+        0, 0, "", "",
         "", 0, 0, new ArrayList<DiskInfo>(),
         0, 0, "",
         new HashMap<String, String>(),
@@ -235,6 +242,22 @@ public class HostResponse {
     this.cpuCount = cpuCount;
   }
 
+  /**
+  * @return the phCpuCount
+  */
+  public int getPhCpuCount() {
+    return phCpuCount;
+  }
+
+  /**
+  * @param phCpuCount the physical cpu count to set
+  */
+  public void setPhCpuCount(int phCpuCount) {
+    this.phCpuCount = phCpuCount;
+  }
+
+  
+  
   /**
    * @return the osArch
    */

+ 4 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java

@@ -59,6 +59,8 @@ class HostResourceProvider extends AbstractControllerResourceProvider {
       PropertyHelper.getPropertyId("Hosts", "total_mem");
   protected static final String HOST_CPU_COUNT_PROPERTY_ID =
       PropertyHelper.getPropertyId("Hosts", "cpu_count");
+  protected static final String HOST_PHYSICAL_CPU_COUNT_PROPERTY_ID =
+      PropertyHelper.getPropertyId("Hosts", "ph_cpu_count");  
   protected static final String HOST_OS_ARCH_PROPERTY_ID =
       PropertyHelper.getPropertyId("Hosts", "os_arch");
   protected static final String HOST_OS_TYPE_PROPERTY_ID =
@@ -172,6 +174,8 @@ class HostResourceProvider extends AbstractControllerResourceProvider {
           response.getTotalMemBytes(), requestedIds);
       setResourceProperty(resource, HOST_CPU_COUNT_PROPERTY_ID,
           (long) response.getCpuCount(), requestedIds);
+      setResourceProperty(resource, HOST_PHYSICAL_CPU_COUNT_PROPERTY_ID,
+          (long) response.getPhCpuCount(), requestedIds);      
       setResourceProperty(resource, HOST_OS_ARCH_PROPERTY_ID,
           response.getOsArch(), requestedIds);
       setResourceProperty(resource, HOST_OS_TYPE_PROPERTY_ID,

+ 14 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java

@@ -95,6 +95,20 @@ public class HostEntity {
     this.cpuCount = cpuCount;
   }
 
+  private Integer phCpuCount = 0;
+
+  @javax.persistence.Column(name = "ph_cpu_count", nullable = false, insertable = true, updatable = true, length = 10)
+  @Basic
+  public Integer getPhCpuCount() {
+    return phCpuCount;
+  }
+
+  public void setPhCpuCount(Integer phCpuCount) {
+    this.phCpuCount = phCpuCount;
+  }
+  
+  
+  
   private String cpuInfo = "";
 
   @javax.persistence.Column(name = "cpu_info", nullable = false, insertable = true, updatable = true)

+ 10 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/Host.java

@@ -81,6 +81,16 @@ public interface Host {
    */
   public void setCpuCount(int cpuCount);
 
+  /**
+   * @return the physical cpu cores
+   */  
+  public int getPhCpuCount();
+
+  /**
+   * @param phCpuCount the physical cpu cores to set
+   */  
+  public void setPhCpuCount(int phCpuCount);
+  
   /**
    * Get the Amount of physical memory for the Host.
    * @return the totalMemBytes

+ 25 - 1
ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java

@@ -367,7 +367,8 @@ public class HostImpl implements Host {
         setIPv6(hostInfo.getIPAddress());
       }
 
-      setCpuCount(hostInfo.getPhysicalProcessorCount());
+      setCpuCount(hostInfo.getProcessorCount());
+      setPhCpuCount(hostInfo.getPhysicalProcessorCount());
       setTotalMemBytes(hostInfo.getMemoryTotal());
       setAvailableMemBytes(hostInfo.getFreeMemory());
 
@@ -641,6 +642,28 @@ public class HostImpl implements Host {
     }
   }
 
+  @Override
+  public int getPhCpuCount() {
+    try {
+      readLock.lock();
+      return hostEntity.getPhCpuCount();
+    } finally {
+      readLock.unlock();
+    }
+  }
+
+  @Override
+  public void setPhCpuCount(int phCpuCount) {
+    try {
+      writeLock.lock();
+      hostEntity.setPhCpuCount(phCpuCount);
+      saveIfPersisted();
+    } finally {
+      writeLock.unlock();
+    }
+  }
+  
+  
   @Override
   public long getTotalMemBytes() {
     try {
@@ -934,6 +957,7 @@ public class HostImpl implements Host {
 
       r.setAgentVersion(getAgentVersion());
       r.setAvailableMemBytes(getAvailableMemBytes());
+      r.setPhCpuCount(getPhCpuCount());
       r.setCpuCount(getCpuCount());
       r.setDisksInfo(getDisksInfo());
       r.setHealthStatus(getHealthStatus());

+ 1 - 1
ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql

@@ -64,7 +64,7 @@ CREATE TABLE ambari.hostcomponentstate (cluster_id BIGINT NOT NULL, component_na
 
 GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentstate TO :username;
 
-CREATE TABLE ambari.hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, disks_info VARCHAR(10000) NOT NULL, host_attributes VARCHAR(20000) NOT NULL, ipv4 VARCHAR(255), ipv6 VARCHAR(255), public_host_name VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
+CREATE TABLE ambari.hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, ph_cpu_count INTEGER NOT NULL, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, disks_info VARCHAR(10000) NOT NULL, host_attributes VARCHAR(20000) NOT NULL, ipv4 VARCHAR(255), ipv6 VARCHAR(255), public_host_name VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
 
 GRANT ALL PRIVILEGES ON TABLE ambari.hosts TO :username;
 

+ 1 - 0
ambari-server/src/main/resources/Ambari-DDL.sql

@@ -74,6 +74,7 @@ ipv4 VARCHAR UNIQUE,
 ipv6 VARCHAR UNIQUE,
 total_mem BIGINT DEFAULT '0' NOT NULL,
 cpu_count INTEGER DEFAULT '0' NOT NULL,
+ph_cpu_count INTEGER DEFAULT '0' NOT NULL,
 cpu_info VARCHAR DEFAULT '' NOT NULL,
 os_arch VARCHAR DEFAULT '' NOT NULL,
 disks_info VARCHAR DEFAULT '' NOT NULL,

+ 1 - 0
ambari-server/src/main/resources/properties.json

@@ -26,6 +26,7 @@
         "Hosts/attributes",
         "Hosts/total_mem",
         "Hosts/cpu_count",
+        "Hosts/ph_cpu_count",
         "Hosts/os_arch",
         "Hosts/os_type",
         "Hosts/rack_info",

+ 5 - 5
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java

@@ -96,15 +96,15 @@ public class HostResourceProviderTest {
 
     Set<HostResponse> allResponse = new HashSet<HostResponse>();
     allResponse.add(new HostResponse("Host100", "Cluster100",
-        "", "", 2, "", "", "", 100000L, 200000L, null, 10L,
+        "", "", 2, 1, "", "", "", 100000L, 200000L, null, 10L,
         0L, "rack info", null, null,
         new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, "HEALTHY"), "HEALTHY"));
     allResponse.add(new HostResponse("Host101", "Cluster100",
-        "", "", 2, "", "", "", 100000L, 200000L, null, 10L,
+        "", "", 2, 1, "", "", "", 100000L, 200000L, null, 10L,
         0L, "rack info", null, null,
         new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, "HEALTHY"), "HEALTHY"));
     allResponse.add(new HostResponse("Host102", "Cluster100",
-        "", "", 2, "", "", "", 100000L, 200000L, null, 10L,
+        "", "", 2, 1, "", "", "", 100000L, 200000L, null, 10L,
         0L, "rack info", null, null,
         new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, "HEALTHY"), "HEALTHY"));
 
@@ -156,7 +156,7 @@ public class HostResourceProviderTest {
     RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
 
     HostResponse hr = new HostResponse("Host100", "Cluster100",
-        "", "", 2, "", "", "", 100000L, 200000L, null, 10L,
+        "", "", 2, 1, "", "", "", 100000L, 200000L, null, 10L,
         0L, "rack info", null, null,
         new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, "HEALTHY"), "HEALTHY");
     
@@ -211,7 +211,7 @@ public class HostResourceProviderTest {
 
     Set<HostResponse> hostResponseSet = new HashSet<HostResponse>();
     hostResponseSet.add(new HostResponse("Host100", "Cluster100",
-        "", "", 2, "", "", "", 100000L, 200000L, null, 10L,
+        "", "", 2, 1, "", "", "", 100000L, 200000L, null, 10L,
         0L, "rack info", null, null,
         new HostHealthStatus(HostHealthStatus.HealthStatus.HEALTHY, "HEALTHY"), "HEALTHY"));
 

+ 4 - 2
ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java

@@ -86,7 +86,8 @@ public class HostTest {
   public void testHostInfoImport() throws AmbariException{
     HostInfo info = new HostInfo();
     info.setMemorySize(100);
-    info.setPhysicalProcessorCount(10);
+    info.setProcessorCount(10);
+    info.setPhysicalProcessorCount(2);
     List<DiskInfo> mounts = new ArrayList<DiskInfo>();
     mounts.add(new DiskInfo("/dev/sda", "/mnt/disk1",
         "5000000", "4000000", "10%", "size", "fstype"));
@@ -106,7 +107,8 @@ public class HostTest {
     Assert.assertEquals(info.getHostName(), host.getHostName());
     Assert.assertEquals(info.getFreeMemory(), host.getAvailableMemBytes());
     Assert.assertEquals(info.getMemoryTotal(), host.getTotalMemBytes());
-    Assert.assertEquals(info.getPhysicalProcessorCount(), host.getCpuCount());
+    Assert.assertEquals(info.getProcessorCount(), host.getCpuCount());
+    Assert.assertEquals(info.getPhysicalProcessorCount(), host.getPhCpuCount());
     Assert.assertEquals(info.getMounts().size(), host.getDisksInfo().size());
     Assert.assertEquals(info.getArchitecture(), host.getOsArch());
     Assert.assertEquals(info.getOS(), host.getOsType());