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

2015-10-12 Thread aonishuk
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1.2 39b964a7d -> afe7fa365


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/afe7fa36
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/afe7fa36
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/afe7fa36

Branch: refs/heads/branch-2.1.2
Commit: afe7fa3653c79b3630c5317f17cc7e9c62b04399
Parents: 39b964a
Author: Andrew Onishuk 
Authored: Fri Oct 9 16:51:30 2015 +0300
Committer: Andrew Onishuk 
Committed: Fri Oct 9 16:51:30 2015 +0300

--
 .../ambari/server/orm/dao/ClusterDAO.java   | 24 
 .../apache/ambari/server/state/ServiceImpl.java | 19 +++-
 2 files changed, 42 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/ambari/blob/afe7fa36/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..6ab3b4f 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;
@@ -234,6 +235,29 @@ public class ClusterDAO {
   public void removeConfigMapping(ClusterConfigMappingEntity entity) {
 entityManagerProvider.get().remove(entity);
   }
+  
+  
+  /**
+   * Sets selected = 0, for clusterConfigEntities which has type_name which is 
in the given types list
+   * 
+   * @param clusterId
+   *  the cluster that the service is a part of.
+   * @param types
+   *  the names of the configuration types.
+   */
+@Transactional
+public void removeClusterConfigMappingEntityByTypes(Long clusterId, 
List types) {
+  if(types.isEmpty()) {
+return;
+  }
+  
+  TypedQuery query = entityManagerProvider.get().createQuery
+  ("DELETE FROM ClusterConfigMappingEntity configs WHERE configs" +
+".clusterId=?1 AND configs.typeName IN ?2", Long.class);
+
+  daoUtils.executeUpdate(query, clusterId, types);
+}
+
 
   /**
* Retrieve entity data from DB

http://git-wip-us.apache.org/repos/asf/ambari/blob/afe7fa36/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..bbe2f62 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,24 @@ public class ServiceImpl implements Service {
 
 List 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) {
+  List configTypesToDisable = new ArrayList();
+  for(ClusterConfigEntity 
clusterConfigEntity:lastServiceConfigEntity.getClusterConfigEntities()) 

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

2015-10-09 Thread aonishuk
Repository: ambari
Updated Branches:
  refs/heads/trunk 9ea0ffd0f -> a64c46971


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/a64c4697
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a64c4697
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a64c4697

Branch: refs/heads/trunk
Commit: a64c469718a5395e9adfdabf46fe15b7040adf89
Parents: 9ea0ffd
Author: Andrew Onishuk 
Authored: Fri Oct 9 15:21:38 2015 +0300
Committer: Andrew Onishuk 
Committed: Fri Oct 9 15:21:38 2015 +0300

--
 .../ambari/server/orm/dao/ClusterDAO.java   | 36 +---
 .../apache/ambari/server/state/ServiceImpl.java |  7 ++--
 2 files changed, 26 insertions(+), 17 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/ambari/blob/a64c4697/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 1523f3a..b79d5e3 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
@@ -128,19 +128,6 @@ public class ClusterDAO {
 TypedQuery query = 
entityManagerProvider.get().createQuery(cq);
 return daoUtils.selectOne(query);
   }
-  
-  @RequiresSession
-  public List 
findClusterConfigMappingEntitiesByType(Long clusterId, String type) {
-CriteriaBuilder cb = entityManagerProvider.get().getCriteriaBuilder();
-CriteriaQuery cq = 
cb.createQuery(ClusterConfigMappingEntity.class);
-Root config = 
cq.from(ClusterConfigMappingEntity.class);
-cq.where(cb.and(
-cb.equal(config.get("clusterId"), clusterId)),
-  cb.equal(config.get("typeName"), type)
-);
-TypedQuery query = 
entityManagerProvider.get().createQuery(cq);
-return daoUtils.selectList(query);
-  }
 
   /**
* Gets the next version that will be created for a given
@@ -274,6 +261,29 @@ public class ClusterDAO {
   public void removeConfigMapping(ClusterConfigMappingEntity entity) {
 entityManagerProvider.get().remove(entity);
   }
+  
+  
+  /**
+   * Sets selected = 0, for clusterConfigEntities which has type_name which is 
in the given types list
+   * 
+   * @param clusterId
+   *  the cluster that the service is a part of.
+   * @param types
+   *  the names of the configuration types.
+   */
+@Transactional
+public void removeClusterConfigMappingEntityByTypes(Long clusterId, 
List types) {
+  if(types.isEmpty()) {
+return;
+  }
+  
+  TypedQuery query = entityManagerProvider.get().createQuery
+  ("DELETE FROM ClusterConfigMappingEntity configs WHERE configs" +
+".clusterId=?1 AND configs.typeName IN ?2", Long.class);
+
+  daoUtils.executeUpdate(query, clusterId, types);
+}
+
 
   /**
* Retrieve entity data from DB

http://git-wip-us.apache.org/repos/asf/ambari/blob/a64c4697/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 1d3f051..9d5fa85 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
@@ -566,12 +566,11 @@ public class ServiceImpl implements Service {
 }
 
 if(lastServiceConfigEntity != null) {
+  List configTypesToDisable = new ArrayList();
   for(ClusterConfigEntity 
clusterConfigEntity:lastServiceConfigEntity.getClusterConfigEntities()) {
-List clusterConfigMappingEntities = 
clusterDAO.findClusterConfigMappingEntitiesByType(cluster.getClusterId() 
,clusterConfigEntity.getType());
-for(ClusterConfigMappingEntity 
clusterConfigMappingEntity:clusterConfigMappingEntities) {
-  clusterDAO.removeConfigMapping(clusterConfigMappingEntity);
-}
+configTypesToDisable.add(clusterConfigEntity.getType());
   }
+  
clusterDAO.removeClusterConfigMappingEntityByTypes(cluster.getClusterId(), 
configTypesToDisable);
 }
   }
   



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

2015-10-09 Thread aonishuk
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 40242bcfa -> 811d2316e
  refs/heads/trunk 800e42597 -> 9ea0ffd0f


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/9ea0ffd0
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9ea0ffd0
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9ea0ffd0

Branch: refs/heads/trunk
Commit: 9ea0ffd0f41f510d683da7da9e3fb32605f15033
Parents: 800e425
Author: Andrew Onishuk 
Authored: Fri Oct 9 14:52:37 2015 +0300
Committer: Andrew Onishuk 
Committed: Fri Oct 9 14:52:37 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/9ea0ffd0/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 609d0de..1523f3a 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 query = 
entityManagerProvider.get().createQuery(cq);
 return daoUtils.selectOne(query);
   }
+  
+  @RequiresSession
+  public List 
findClusterConfigMappingEntitiesByType(Long clusterId, String type) {
+CriteriaBuilder cb = entityManagerProvider.get().getCriteriaBuilder();
+CriteriaQuery cq = 
cb.createQuery(ClusterConfigMappingEntity.class);
+Root config = 
cq.from(ClusterConfigMappingEntity.class);
+cq.where(cb.and(
+cb.equal(config.get("clusterId"), clusterId)),
+  cb.equal(config.get("typeName"), type)
+);
+TypedQuery 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/9ea0ffd0/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 9a91e4c..1d3f051 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;
@@ -551,10 +554,25 @@ public class ServiceImpl implements Service {
 
 List 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 clusterConfigMappingEntities = 
clusterDAO.findClusterConfigMappingEntitiesByType(cluster.getClusterId() 
,clusterConfigEntity.getType());
+

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

2015-10-09 Thread 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 
Authored: Fri Oct 9 14:52:40 2015 +0300
Committer: Andrew Onishuk 
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 query = 
entityManagerProvider.get().createQuery(cq);
 return daoUtils.selectOne(query);
   }
+  
+  @RequiresSession
+  public List 
findClusterConfigMappingEntitiesByType(Long clusterId, String type) {
+CriteriaBuilder cb = entityManagerProvider.get().getCriteriaBuilder();
+CriteriaQuery cq = 
cb.createQuery(ClusterConfigMappingEntity.class);
+Root config = 
cq.from(ClusterConfigMappingEntity.class);
+cq.where(cb.and(
+cb.equal(config.get("clusterId"), clusterId)),
+  cb.equal(config.get("typeName"), type)
+);
+TypedQuery 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 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 clusterConfigMappingEntities = 
clusterDAO.findClusterConfigMappingEntitiesByType(cluster.getClusterId() 
,clusterConfigEntity.getType());
+for(ClusterConfigMappingEntity 
clusterConfigMappingEntity:clusterConfigMappingEntities) {
+  

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

2015-10-09 Thread aonishuk
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 811d2316e -> c06a8ab75


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/c06a8ab7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c06a8ab7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c06a8ab7

Branch: refs/heads/branch-2.1
Commit: c06a8ab759b9c1e5fa9eba0cd91b172bf2739ce2
Parents: 811d231
Author: Andrew Onishuk 
Authored: Fri Oct 9 15:29:36 2015 +0300
Committer: Andrew Onishuk 
Committed: Fri Oct 9 15:29:36 2015 +0300

--
 .../ambari/server/orm/dao/ClusterDAO.java   | 36 +---
 .../apache/ambari/server/state/ServiceImpl.java |  7 ++--
 2 files changed, 26 insertions(+), 17 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/ambari/blob/c06a8ab7/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 3085747..6ab3b4f 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
@@ -128,19 +128,6 @@ public class ClusterDAO {
 TypedQuery query = 
entityManagerProvider.get().createQuery(cq);
 return daoUtils.selectOne(query);
   }
-  
-  @RequiresSession
-  public List 
findClusterConfigMappingEntitiesByType(Long clusterId, String type) {
-CriteriaBuilder cb = entityManagerProvider.get().getCriteriaBuilder();
-CriteriaQuery cq = 
cb.createQuery(ClusterConfigMappingEntity.class);
-Root config = 
cq.from(ClusterConfigMappingEntity.class);
-cq.where(cb.and(
-cb.equal(config.get("clusterId"), clusterId)),
-  cb.equal(config.get("typeName"), type)
-);
-TypedQuery query = 
entityManagerProvider.get().createQuery(cq);
-return daoUtils.selectList(query);
-  }
 
   /**
* Gets the next version that will be created for a given
@@ -248,6 +235,29 @@ public class ClusterDAO {
   public void removeConfigMapping(ClusterConfigMappingEntity entity) {
 entityManagerProvider.get().remove(entity);
   }
+  
+  
+  /**
+   * Sets selected = 0, for clusterConfigEntities which has type_name which is 
in the given types list
+   * 
+   * @param clusterId
+   *  the cluster that the service is a part of.
+   * @param types
+   *  the names of the configuration types.
+   */
+@Transactional
+public void removeClusterConfigMappingEntityByTypes(Long clusterId, 
List types) {
+  if(types.isEmpty()) {
+return;
+  }
+  
+  TypedQuery query = entityManagerProvider.get().createQuery
+  ("DELETE FROM ClusterConfigMappingEntity configs WHERE configs" +
+".clusterId=?1 AND configs.typeName IN ?2", Long.class);
+
+  daoUtils.executeUpdate(query, clusterId, types);
+}
+
 
   /**
* Retrieve entity data from DB

http://git-wip-us.apache.org/repos/asf/ambari/blob/c06a8ab7/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 7b1d0d8..bbe2f62 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
@@ -565,12 +565,11 @@ public class ServiceImpl implements Service {
 }
 
 if(lastServiceConfigEntity != null) {
+  List configTypesToDisable = new ArrayList();
   for(ClusterConfigEntity 
clusterConfigEntity:lastServiceConfigEntity.getClusterConfigEntities()) {
-List clusterConfigMappingEntities = 
clusterDAO.findClusterConfigMappingEntitiesByType(cluster.getClusterId() 
,clusterConfigEntity.getType());
-for(ClusterConfigMappingEntity 
clusterConfigMappingEntity:clusterConfigMappingEntities) {
-  clusterDAO.removeConfigMapping(clusterConfigMappingEntity);
-}
+configTypesToDisable.add(clusterConfigEntity.getType());
   }
+  
clusterDAO.removeClusterConfigMappingEntityByTypes(cluster.getClusterId(), 
configTypesToDisable);
 }
   }