You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2015/10/09 13:53:29 UTC

[2/2] ambari git commit: AMBARI-13358. Ambari throwing ganglia errors after upgrade (aonishuk)

AMBARI-13358. Ambari throwing ganglia errors after upgrade (aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/811d2316
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/811d2316
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/811d2316

Branch: refs/heads/branch-2.1
Commit: 811d2316ef824543c2a3ea2908e8993f1560c52a
Parents: 40242bc
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Fri Oct 9 14:52:40 2015 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Fri Oct 9 14:52:40 2015 +0300

----------------------------------------------------------------------
 .../ambari/server/orm/dao/ClusterDAO.java       | 14 ++++++++++++++
 .../apache/ambari/server/state/ServiceImpl.java | 20 +++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/811d2316/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
index 6e55128..3085747 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.orm.dao;
 
+import java.util.Collections;
 import java.util.List;
 
 import javax.persistence.EntityManager;
@@ -127,6 +128,19 @@ public class ClusterDAO {
     TypedQuery<ClusterConfigEntity> query = entityManagerProvider.get().createQuery(cq);
     return daoUtils.selectOne(query);
   }
+  
+  @RequiresSession
+  public List<ClusterConfigMappingEntity> findClusterConfigMappingEntitiesByType(Long clusterId, String type) {
+    CriteriaBuilder cb = entityManagerProvider.get().getCriteriaBuilder();
+    CriteriaQuery<ClusterConfigMappingEntity> cq = cb.createQuery(ClusterConfigMappingEntity.class);
+    Root<ClusterConfigMappingEntity> config = cq.from(ClusterConfigMappingEntity.class);
+    cq.where(cb.and(
+        cb.equal(config.get("clusterId"), clusterId)),
+      cb.equal(config.get("typeName"), type)
+    );
+    TypedQuery<ClusterConfigMappingEntity> query = entityManagerProvider.get().createQuery(cq);
+    return daoUtils.selectList(query);
+  }
 
   /**
    * Gets the next version that will be created for a given

http://git-wip-us.apache.org/repos/asf/ambari/blob/811d2316/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
index c210557..7b1d0d8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.state;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -37,6 +38,8 @@ import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
 import org.apache.ambari.server.orm.dao.ServiceConfigDAO;
 import org.apache.ambari.server.orm.dao.ServiceDesiredStateDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
+import org.apache.ambari.server.orm.entities.ClusterConfigMappingEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntityPK;
@@ -550,10 +553,25 @@ public class ServiceImpl implements Service {
     
     List<ServiceConfigEntity> serviceConfigEntities = serviceConfigDAO.findByService(cluster.getClusterId(), getName());
 
+    Long maxServiceConfigEntityId = -1L;
+    ServiceConfigEntity lastServiceConfigEntity = null; // last service config by id, should have all needed clusterConfigEntities
+    
     for (ServiceConfigEntity serviceConfigEntity : serviceConfigEntities) {
+      if(serviceConfigEntity.getServiceConfigId() > maxServiceConfigEntityId) {
+        maxServiceConfigEntityId = serviceConfigEntity.getServiceConfigId();
+        lastServiceConfigEntity = serviceConfigEntity;
+      }
       serviceConfigDAO.remove(serviceConfigEntity);
     }
-
+    
+    if(lastServiceConfigEntity != null) {
+      for(ClusterConfigEntity clusterConfigEntity:lastServiceConfigEntity.getClusterConfigEntities()) {
+        List<ClusterConfigMappingEntity> clusterConfigMappingEntities = clusterDAO.findClusterConfigMappingEntitiesByType(cluster.getClusterId() ,clusterConfigEntity.getType());
+        for(ClusterConfigMappingEntity clusterConfigMappingEntity:clusterConfigMappingEntities) {
+          clusterDAO.removeConfigMapping(clusterConfigMappingEntity);
+        }
+      }
+    }
   }
   
   @Override