directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [06/44] directory-kerby git commit: DIRKRB-557 KDC backend connect to the zookeeper cluster.
Date Thu, 30 Jun 2016 08:53:53 GMT
DIRKRB-557 KDC backend connect to the zookeeper cluster.


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

Branch: refs/heads/gssapi
Commit: 7b5f7432cf101ac5732341f71d2ef71cfc1d0f41
Parents: c724d32
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Fri Apr 22 15:43:14 2016 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Fri Apr 22 15:43:14 2016 +0800

----------------------------------------------------------------------
 .../kerberos/kdc/identitybackend/ZKConfKey.java |  6 ++--
 .../ZookeeperIdentityBackend.java               | 36 ++++++--------------
 .../identity/backend/ZookeeperBackendTest.java  | 26 ++++++++++----
 kerby-dist/kdc-dist/conf/backend.conf           |  6 ++--
 .../kerberos/kdc/ZookeeperBackendKdcTest.java   | 27 ++-------------
 5 files changed, 41 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7b5f7432/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZKConfKey.java
----------------------------------------------------------------------
diff --git a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZKConfKey.java
b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZKConfKey.java
index 96f5ced..b82b1a0 100644
--- a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZKConfKey.java
+++ b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZKConfKey.java
@@ -25,10 +25,10 @@ import org.apache.kerby.config.ConfigKey;
  * Define all the ZK backend related configuration items with default values.
  */
 public enum ZKConfKey implements ConfigKey {
+    EMBEDDED_ZK(true),
     ZK_HOST("127.0.0.1"),
-    ZK_PORT(2181),
-    DATA_DIR,
-    DATA_LOG_DIR;
+    ZK_PORT(2180),
+    DATA_DIR("/tmp/kerby/zookeeper/data");
 
     private Object defaultValue;
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7b5f7432/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 95d14a5..810b271 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
@@ -51,7 +51,6 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend {
     private String zkHost;
     private int zkPort;
     private File dataDir;
-    private File dataLogDir;
     private ZooKeeper zooKeeper;
     private static final Logger LOG = LoggerFactory.getLogger(ZookeeperIdentityBackend.class);
 
@@ -111,19 +110,9 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
 
         LOG.info("Data dir: " + dataDir);
 
-        String dataLogDirString = getConfig().getString(ZKConfKey.DATA_LOG_DIR, true);
-        if (dataLogDirString == null || dataLogDirString.isEmpty()) {
-            File zooKeeperDir = new File(getBackendConfig().getConfDir(), "zookeeper");
-            dataLogDir = new File(zooKeeperDir, "datalog");
-        } else {
-            dataLogDir = new File(dataLogDirString);
-        }
-
-        if (!dataLogDir.exists() && !dataLogDir.mkdirs()) {
-            throw new KrbException("could not create data log file dir " + dataLogDir);
+        if (getConfig().getBoolean(ZKConfKey.EMBEDDED_ZK, true)) {
+            startEmbeddedZookeeper();
         }
-
-        startEmbeddedZookeeper();
         connectZK();
     }
 
@@ -132,7 +121,8 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
      */
     private void connectZK() throws KrbException {
         try {
-            zooKeeper = new ZooKeeper(zkHost, 10000, null);
+            String serverStr = zkHost + ":" + zkPort;
+            zooKeeper = new ZooKeeper(serverStr, 10000, new MyWatcher());
             while (true) {
                 if (!zooKeeper.getState().isConnected()) {
                     try {
@@ -158,7 +148,6 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
     private void startEmbeddedZookeeper() throws KrbException {
         Properties startupProperties = new Properties();
         startupProperties.put("dataDir", dataDir.getAbsolutePath());
-        startupProperties.put("dataLogDir", dataLogDir.getAbsolutePath());
         startupProperties.put("clientPort", zkPort);
 
         QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
@@ -188,14 +177,6 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
     }
 
     /**
-     * This will watch all the kdb update event so that it's timely synced.
-     * @param event The kdb update event ot watch.
-     */
-    private void process(WatchedEvent event) {
-        System.out.print("I got an event: " + event);
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override
@@ -323,9 +304,14 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
     }
 
     class MyWatcher implements Watcher {
-        @Override
+
+        /**
+         * This will watch all the kdb update event so that it's timely synced.
+         * @param event The kdb update event ot watch.
+         */
         public void process(WatchedEvent event) {
-            ZookeeperIdentityBackend.this.process(event);
+//            System.out.println("I got an event: " + event.getPath());
         }
+
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7b5f7432/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 b5dab1d..8f34123 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
@@ -23,6 +23,7 @@ import org.apache.kerby.config.Conf;
 import org.apache.kerby.kerberos.kdc.identitybackend.ZKConfKey;
 import org.apache.kerby.kerberos.kdc.identitybackend.ZookeeperIdentityBackend;
 import org.apache.kerby.kerberos.kerb.KrbException;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
 import java.io.File;
@@ -31,22 +32,35 @@ import java.io.File;
  * Zookeeper backend test
  */
 public class ZookeeperBackendTest extends BackendTestBase {
+    private static File instanceDir;
+    private static File dataDir;
+
     @BeforeClass
     public static void setup() throws KrbException {
         Conf config = new Conf();
-
         File testdir = new File(System.getProperty("test.dir", "target"));
-        File instanceDir = new File(testdir, "zookeeper");
+        instanceDir = new File(testdir, "zookeeper");
         instanceDir.mkdirs();
-        File dataDir = new File(instanceDir, "data");
+        dataDir = new File(instanceDir, "data");
         dataDir.mkdirs();
         config.setString(ZKConfKey.DATA_DIR.getPropertyKey(), dataDir.getAbsolutePath());
-        File dataLogDir = new File(instanceDir, "log");
-        dataLogDir.mkdirs();
-        config.setString(ZKConfKey.DATA_LOG_DIR.getPropertyKey(), dataLogDir.getAbsolutePath());
 
         backend = new ZookeeperIdentityBackend(config);
         backend.initialize();
         backend.start();
     }
+
+    @AfterClass
+    public static void tearDown() throws KrbException {
+        if (dataDir.exists()) {
+            dataDir.delete();
+        }
+        if (instanceDir.exists()) {
+            instanceDir.delete();
+        }
+        if (backend != null) {
+            backend.stop();
+            backend.release();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7b5f7432/kerby-dist/kdc-dist/conf/backend.conf
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/conf/backend.conf b/kerby-dist/kdc-dist/conf/backend.conf
index 28c2632..2ead268 100644
--- a/kerby-dist/kdc-dist/conf/backend.conf
+++ b/kerby-dist/kdc-dist/conf/backend.conf
@@ -18,5 +18,7 @@
 
 kdc_identity_backend = org.apache.kerby.kerberos.kdc.identitybackend.JsonIdentityBackend
 backend.json.dir = /tmp/kerby/jsonbackend
-data_dir = /tmp/kerby/zookeeper/data
-data_log_dir = /tmp/kerby/zookeeper/datalog
+embedded_zk = false
+zk_host = 127.0.0.1
+zk_port = 2181
+data_dir = /tmp/zookeeper/data

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7b5f7432/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/ZookeeperBackendKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/ZookeeperBackendKdcTest.java
b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/ZookeeperBackendKdcTest.java
index bface94..f0634e7 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/ZookeeperBackendKdcTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/ZookeeperBackendKdcTest.java
@@ -23,43 +23,22 @@ import org.apache.kerby.kerberos.kdc.identitybackend.ZKConfKey;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.identity.backend.BackendConfig;
 import org.apache.kerby.kerberos.kerb.server.KdcConfigKey;
-import org.junit.AfterClass;
 import org.junit.Test;
 
 import java.io.File;
 
 public class ZookeeperBackendKdcTest extends KerbyKdcTest {
 
-    private static File instanceDir;
-    private static File dataDir;
-    private static File dataLogDir;
-
-    @AfterClass
-    public static void rmJsonBackendFile() {
-        if (instanceDir.exists()) {
-            instanceDir.delete();
-        }
-        if (dataDir.exists()) {
-            dataDir.delete();
-        }
-        if (dataLogDir.exists()) {
-            dataLogDir.delete();
-        }
-    }
-
     @Override
     protected void prepareKdc() throws KrbException {
         BackendConfig backendConfig = getKdcServer().getBackendConfig();
 
-        File testDir = new File(System.getProperty("test.dir", "target"));
-        instanceDir = new File(testDir, "zookeeper");
+        File testDir = getTestDir();
+        File instanceDir = new File(testDir, "zookeeper");
         instanceDir.mkdirs();
-        dataDir = new File(instanceDir, "data");
+        File dataDir = new File(instanceDir, "data");
         dataDir.mkdirs();
         backendConfig.setString(ZKConfKey.DATA_DIR.getPropertyKey(), dataDir.getAbsolutePath());
-        dataLogDir = new File(instanceDir, "log");
-        dataLogDir.mkdirs();
-        backendConfig.setString(ZKConfKey.DATA_LOG_DIR.getPropertyKey(), dataLogDir.getAbsolutePath());
         backendConfig.setString(KdcConfigKey.KDC_IDENTITY_BACKEND,
             "org.apache.kerby.kerberos.kdc.identitybackend.ZookeeperIdentityBackend");
 


Mime
View raw message