directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject directory-kerby git commit: DIRKRB-208 Deleting the identity in zookeeper backend. Contributed by Jiajia
Date Fri, 10 Apr 2015 06:10:12 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 86aca8e7c -> 6928f99b4


DIRKRB-208 Deleting the identity in zookeeper backend. Contributed by Jiajia


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/6928f99b
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/6928f99b
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/6928f99b

Branch: refs/heads/master
Commit: 6928f99b4c50d2965138235d7209728ad681f833
Parents: 86aca8e
Author: Lin <linchen7@foxmail.com>
Authored: Fri Apr 10 14:10:01 2015 +0800
Committer: Lin <linchen7@foxmail.com>
Committed: Fri Apr 10 14:10:01 2015 +0800

----------------------------------------------------------------------
 .../kdc/identitybackend/IdentityZNode.java      |  4 ++++
 .../kerberos/kdc/identitybackend/ZKUtil.java    | 23 ++++++++++++++++++++
 .../ZookeeperIdentityBackend.java               |  7 +++++-
 .../identity/backend/ZookeeperBackendTest.java  |  5 +++++
 4 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6928f99b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/IdentityZNode.java
----------------------------------------------------------------------
diff --git a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/IdentityZNode.java
b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/IdentityZNode.java
index dce5746..4acd1d7 100644
--- a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/IdentityZNode.java
+++ b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/IdentityZNode.java
@@ -335,4 +335,8 @@ public class IdentityZNode {
                     BytesUtil.int2bytes(value.getKvno(), true));
         }
     }
+
+    public void deleteIdentity() throws KeeperException {
+        ZKUtil.deleteNodeRecursively(this.zk, IdentityZNodeHelper.getIndentityZNode(this.identityName));
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6928f99b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZKUtil.java
----------------------------------------------------------------------
diff --git a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZKUtil.java
b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZKUtil.java
index 9f9d2a8..514574c 100644
--- a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZKUtil.java
+++ b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZKUtil.java
@@ -166,4 +166,27 @@ public class ZKUtil {
         }
         return children;
     }
+
+    /**
+     * Delete the specified node and all of it's children.
+     * <p/>
+     * If the node does not exist, just returns.
+     * <p/>
+     * Sets no watches. Throws all exceptions besides dealing with deletion of
+     * children.
+     */
+    public static void deleteNodeRecursively(ZooKeeper zk, String node) throws KeeperException
{
+        List<String> children = ZKUtil.listChildrenNoWatch(zk, node);
+        if (children == null) return;
+        if (!children.isEmpty()) {
+            for (String child : children) {
+                deleteNodeRecursively(zk, joinZNode(node, child));
+            }
+        }
+        try {
+            zk.delete(node, -1);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6928f99b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
index 203447a..def02ad 100644
--- a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
+++ b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
@@ -179,7 +179,12 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
 
     @Override
     protected void doDeleteIdentity(String principalName) {
-
+        IdentityZNode identityZNode = new IdentityZNode(zooKeeper, principalName);
+        try {
+            identityZNode.deleteIdentity();
+        } catch (KeeperException e) {
+            LOG.error("Fail to delete identity in zookeeper", e);
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6928f99b/kerby-backend/zookeeper-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/ZookeeperBackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/zookeeper-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/ZookeeperBackendTest.java
b/kerby-backend/zookeeper-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/ZookeeperBackendTest.java
index d2ffc38..6225845 100644
--- a/kerby-backend/zookeeper-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/ZookeeperBackendTest.java
+++ b/kerby-backend/zookeeper-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/ZookeeperBackendTest.java
@@ -73,4 +73,9 @@ public class ZookeeperBackendTest extends BackendTest {
     public void testUpdate() {
         super.testUpdate(backend);
     }
+
+    @Test
+    public void testDelete() {
+        super.testDelete(backend);
+    }
 }


Mime
View raw message