Forráskód Böngészése

AMBARI-6585. Deleted hosts come back to life after ambari-server restart. (Alejandro Fernandez via swagle)

Siddharth Wagle 11 éve
szülő
commit
fb16c640cf

+ 4 - 12
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java

@@ -162,24 +162,16 @@ public class ClusterEntity {
 
     ClusterEntity that = (ClusterEntity) o;
 
-    if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId != null) return false;
-    if (clusterInfo != null ? !clusterInfo.equals(that.clusterInfo) : that.clusterInfo != null) return false;
-    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
-    if (desiredClusterState != null ? !desiredClusterState.equals(that.desiredClusterState) : that.desiredClusterState != null)
-      return false;
-    if (desiredStackVersion != null ? !desiredStackVersion.equals(that.desiredStackVersion) : that.desiredStackVersion != null)
-      return false;
+    if (!clusterId.equals(that.clusterId)) return false;
+    if (!clusterName.equals(that.clusterName)) return false;
 
     return true;
   }
 
   @Override
   public int hashCode() {
-    int result = clusterId != null ? clusterId.intValue() : 0;
-    result = 31 * result + (clusterName != null ? clusterName.hashCode() : 0);
-    result = 31 * result + (desiredClusterState != null ? desiredClusterState.hashCode() : 0);
-    result = 31 * result + (clusterInfo != null ? clusterInfo.hashCode() : 0);
-    result = 31 * result + (desiredStackVersion != null ? desiredStackVersion.hashCode() : 0);
+    int result = clusterId.hashCode();
+    result = 31 * result + clusterName.hashCode();
     return result;
   }
 

+ 2 - 27
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java

@@ -237,39 +237,14 @@ public class HostEntity {
 
     HostEntity that = (HostEntity) o;
 
-    if (cpuCount != null ? !cpuCount.equals(that.cpuCount) : that.cpuCount != null) return false;
-    if (lastRegistrationTime != null ? !lastRegistrationTime.equals(that.lastRegistrationTime) : that.lastRegistrationTime != null) return false;
-    if (totalMem != null ? !totalMem.equals(that.totalMem) : that.totalMem != null) return false;
-    if (cpuInfo != null ? !cpuInfo.equals(that.cpuInfo) : that.cpuInfo != null) return false;
-    if (discoveryStatus != null ? !discoveryStatus.equals(that.discoveryStatus) : that.discoveryStatus != null)
-      return false;
-    if (hostAttributes != null ? !hostAttributes.equals(that.hostAttributes) : that.hostAttributes != null)
-      return false;
-    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
-    if (ipv4 != null ? !ipv4.equals(that.ipv4) : that.ipv4 != null) return false;
-    if (osArch != null ? !osArch.equals(that.osArch) : that.osArch != null) return false;
-    if (osInfo != null ? !osInfo.equals(that.osInfo) : that.osInfo != null) return false;
-    if (osType != null ? !osType.equals(that.osType) : that.osType != null) return false;
-    if (rackInfo != null ? !rackInfo.equals(that.rackInfo) : that.rackInfo != null) return false;
+    if (!hostName.equals(that.hostName)) return false;
 
     return true;
   }
 
   @Override
   public int hashCode() {
-    int result = hostName != null ? hostName.hashCode() : 0;
-    result = 31 * result + (ipv4 != null ? ipv4.hashCode() : 0);
-    result = 31 * result + (totalMem != null ? totalMem.intValue() : 0);
-    result = 31 * result + cpuCount;
-    result = 31 * result + (cpuInfo != null ? cpuInfo.hashCode() : 0);
-    result = 31 * result + (osArch != null ? osArch.hashCode() : 0);
-    result = 31 * result + (osInfo != null ? osInfo.hashCode() : 0);
-    result = 31 * result + (osType != null ? osType.hashCode() : 0);
-    result = 31 * result + (discoveryStatus != null ? discoveryStatus.hashCode() : 0);
-    result = 31 * result + (lastRegistrationTime != null ? lastRegistrationTime.intValue() : 0);
-    result = 31 * result + (rackInfo != null ? rackInfo.hashCode() : 0);
-    result = 31 * result + (hostAttributes != null ? hostAttributes.hashCode() : 0);
-    return result;
+    return hostName.hashCode();
   }
 
   public Collection<HostComponentDesiredStateEntity> getHostComponentDesiredStateEntities() {

+ 8 - 5
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java

@@ -324,7 +324,6 @@ public class ClustersImpl implements Clusters {
   }
 
   @Override
-  @Transactional
   public void updateHostWithClusterAndAttributes(Map<String, Set<String>> hostClusters, Map<String,
       Map<String, String>> hostAttributes)
       throws AmbariException {
@@ -370,7 +369,8 @@ public class ClustersImpl implements Clusters {
               }
 
               mapHostClusterEntities(hostname, cluster.getClusterId());
-
+              host.refresh();
+              cluster.refresh();
               hostClusterMap.get(hostname).add(cluster);
               clusterHostMap.get(clusterName).add(host);
 
@@ -458,7 +458,8 @@ public class ClustersImpl implements Clusters {
       }
 
       mapHostClusterEntities(hostname, cluster.getClusterId());
-
+      host.refresh();
+      cluster.refresh();
       hostClusterMap.get(hostname).add(cluster);
       clusterHostMap.get(clusterName).add(host);
 
@@ -472,7 +473,7 @@ public class ClustersImpl implements Clusters {
       w.unlock();
     }
   }
-  
+
   @Transactional
   void mapHostClusterEntities(String hostName, Long clusterId) {
     HostEntity hostEntity = hostDAO.findByName(hostName);
@@ -607,8 +608,10 @@ public class ClustersImpl implements Clusters {
             + ", clusterId=" + cluster.getClusterId()
             + ", hostname=" + hostname);
       }
-      
+
       unmapHostClusterEntities(hostname, cluster.getClusterId());
+      host.refresh();
+      cluster.refresh();
 
       hostClusterMap.get(hostname).remove(cluster);
       clusterHostMap.get(clusterName).remove(host);