Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 333E7200C4E for ; Fri, 21 Apr 2017 17:04:01 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 31A3A160BA2; Fri, 21 Apr 2017 15:04:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7675B160B97 for ; Fri, 21 Apr 2017 17:04:00 +0200 (CEST) Received: (qmail 30015 invoked by uid 500); 21 Apr 2017 15:03:59 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 30006 invoked by uid 99); 21 Apr 2017 15:03:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Apr 2017 15:03:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 71A19F2173; Fri, 21 Apr 2017 15:03:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dmitriusan@apache.org To: commits@ambari.apache.org Message-Id: <69bd96e3909f4688ad3a669043a0c31a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ambari git commit: AMBARI-20805. Autofix db leads to dangling entries in ClusterConfigMapping table (dlysnichenko) Date: Fri, 21 Apr 2017 15:03:59 +0000 (UTC) archived-at: Fri, 21 Apr 2017 15:04:01 -0000 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 Authored: Fri Apr 21 18:02:47 2017 +0300 Committer: Lisnichenko Dmitro 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 notMappedClusterConfigs = getNotMappedClusterConfigsToService(); for (ClusterConfigEntity clusterConfigEntity : notMappedClusterConfigs){ - List 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 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