You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2017/04/21 15:03:59 UTC

ambari git commit: AMBARI-20805. Autofix db leads to dangling entries in ClusterConfigMapping table (dlysnichenko)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 712b3d21c -> 23f8b85b8


AMBARI-20805. Autofix db leads to dangling entries in ClusterConfigMapping table (dlysnichenko)


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

Branch: refs/heads/branch-2.5
Commit: 23f8b85b8b6175b57086f2ec20f614ed40ba4274
Parents: 712b3d2
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri Apr 21 18:02:47 2017 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri Apr 21 18:02:47 2017 +0300

----------------------------------------------------------------------
 .../checks/DatabaseConsistencyCheckHelper.java       |  9 +++------
 .../org/apache/ambari/server/orm/dao/ClusterDAO.java | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/23f8b85b/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java
index 4cdeecb..c33c4e3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java
@@ -527,12 +527,9 @@ public class DatabaseConsistencyCheckHelper {
     List<ClusterConfigEntity> notMappedClusterConfigs = getNotMappedClusterConfigsToService();
 
     for (ClusterConfigEntity clusterConfigEntity : notMappedClusterConfigs){
-      List<String> types = new ArrayList<>();
-      String type = clusterConfigEntity.getType();
-      types.add(type);
-      LOG.error("Removing cluster config mapping of type {} that is not mapped to any service", type);
-      clusterDAO.removeClusterConfigMappingEntityByTypes(clusterConfigEntity.getClusterId(),types);
-      LOG.error("Removing config that is not mapped to any service", clusterConfigEntity);
+      LOG.info("Removing cluster config mapping of clusterConfigEntity {} that is not mapped to any service", clusterConfigEntity);
+      clusterDAO.removeClusterConfigMappingEntityByConfig(clusterConfigEntity);
+      LOG.info("Removing config that is not mapped to any service {}", clusterConfigEntity);
       clusterDAO.removeConfig(clusterConfigEntity);
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/23f8b85b/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 b727c72..b21aeff 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
@@ -364,6 +364,21 @@ public class ClusterDAO {
       daoUtils.executeUpdate(query, clusterId, types);
     }
 
+  /**
+   * Delete ClusterConfigMappingEntity corresponds to clusterConfigEntity
+   *
+   * @param clusterConfigEntity
+   *          clusterConfigEntity to match.
+   */
+  @Transactional
+  public void removeClusterConfigMappingEntityByConfig(ClusterConfigEntity clusterConfigEntity) {
+
+    TypedQuery<Long> query = entityManagerProvider.get().createQuery
+        ("DELETE FROM ClusterConfigMappingEntity configs WHERE configs" +
+            ".clusterId=?1 AND configs.typeName= ?2 AND configs.tag=?3 ", Long.class);
+
+    daoUtils.executeUpdate(query, clusterConfigEntity.getClusterId(), clusterConfigEntity.getType(), clusterConfigEntity.getTag());
+  }
 
   /**
    * Retrieve entity data from DB