AMBARI-15031. Duplicate key violation during ldap sync  (Oliver Szabo via 
rlevas)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: e18755393326d10564f7d68c2d025572fed25d63
Parents: ed55354
Author: Oliver Szabo <osz...@hortonworks.com>
Authored: Fri Feb 12 16:26:31 2016 -0500
Committer: Robert Levas <rle...@hortonworks.com>
Committed: Fri Feb 12 16:26:35 2016 -0500

----------------------------------------------------------------------
 .../ambari/server/security/ldap/AmbariLdapDataPopulator.java    | 5 ++++-
 .../org/apache/ambari/server/security/ldap/LdapBatchDto.java    | 5 +++++
 .../server/security/ldap/AmbariLdapDataPopulatorTest.java       | 4 ++++
 3 files changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e1875539/ambari-server/src/main/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulator.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulator.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulator.java
index 21492cf..801e43e 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulator.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulator.java
@@ -485,8 +485,11 @@ public class AmbariLdapDataPopulator {
         batchInfo.getGroupsToBecomeLdap().add(groupName);
       }
       internalGroupsMap.remove(groupName);
+      batchInfo.getGroupsProcessedInternal().add(groupName);
     } else {
-      batchInfo.getGroupsToBeCreated().add(groupName);
+      if (!batchInfo.getGroupsProcessedInternal().contains(groupName)) {
+        batchInfo.getGroupsToBeCreated().add(groupName);
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/e1875539/ambari-server/src/main/java/org/apache/ambari/server/security/ldap/LdapBatchDto.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/security/ldap/LdapBatchDto.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/security/ldap/LdapBatchDto.java
index 9247f38..bb9c5ee 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/security/ldap/LdapBatchDto.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/security/ldap/LdapBatchDto.java
@@ -27,6 +27,7 @@ public class LdapBatchDto {
   private final Set<String> groupsToBecomeLdap = new HashSet<String>();
   private final Set<String> groupsToBeCreated = new HashSet<String>();
   private final Set<String> groupsToBeRemoved = new HashSet<String>();
+  private final Set<String> groupsProcessedInternal = new HashSet<>();
   private final Set<String> usersToBecomeLdap = new HashSet<String>();
   private final Set<String> usersToBeCreated = new HashSet<String>();
   private final Set<String> usersToBeRemoved = new HashSet<String>();
@@ -64,4 +65,8 @@ public class LdapBatchDto {
   public Set<String> getUsersToBeRemoved() {
     return usersToBeRemoved;
   }
+
+  public Set<String> getGroupsProcessedInternal() {
+    return groupsProcessedInternal;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/e1875539/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java
index be92871..8ce6c5b 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java
@@ -348,6 +348,10 @@ public class AmbariLdapDataPopulatorTest {
     assertTrue(result.getMembershipToRemove().isEmpty());
     assertTrue(result.getUsersToBecomeLdap().isEmpty());
     assertTrue(result.getUsersToBeRemoved().isEmpty());
+    assertTrue(result.getGroupsProcessedInternal().contains("group1"));
+    assertTrue(result.getGroupsProcessedInternal().contains("group2"));
+    assertTrue(!result.getGroupsProcessedInternal().contains("xgroup1"));
+    assertTrue(!result.getGroupsProcessedInternal().contains("xgroup2"));
     verify(populator.loadLdapTemplate(), populator);
   }
 

Reply via email to