You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/11/08 11:40:24 UTC

ignite git commit: zk

Repository: ignite
Updated Branches:
  refs/heads/ignite-zk [created] d151e402a


zk


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

Branch: refs/heads/ignite-zk
Commit: d151e402a330fb6477b91dc5a01bc829bfbbd950
Parents: f52f8f9
Author: sboikov <sb...@gridgain.com>
Authored: Wed Nov 8 14:40:07 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Nov 8 14:40:07 2017 +0300

----------------------------------------------------------------------
 .../src/main/resources/log4j.properties         |  58 ++++++++
 .../tcp/ipfinder/zk/ZKClusterNode.java          | 144 +++++++++++++++++++
 2 files changed, 202 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d151e402/modules/zookeeper/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/modules/zookeeper/src/main/resources/log4j.properties b/modules/zookeeper/src/main/resources/log4j.properties
new file mode 100644
index 0000000..9825970
--- /dev/null
+++ b/modules/zookeeper/src/main/resources/log4j.properties
@@ -0,0 +1,58 @@
+# Define some default values that can be overridden by system properties
+zookeeper.root.logger=INFO, CONSOLE
+zookeeper.console.threshold=INFO
+zookeeper.log.dir=.
+zookeeper.log.file=zookeeper.log
+zookeeper.log.threshold=DEBUG
+zookeeper.tracelog.dir=.
+zookeeper.tracelog.file=zookeeper_trace.log
+
+#
+# ZooKeeper Logging Configuration
+#
+
+# Format is "<default threshold> (, <appender>)+
+
+# DEFAULT: console appender only
+log4j.rootLogger=${zookeeper.root.logger}
+
+# Example with rolling log file
+#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE
+
+# Example with rolling log file and tracing
+#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE
+
+#
+# Log INFO level and above messages to the console
+#
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
+
+#
+# Add ROLLINGFILE to rootLogger to get log file output
+#    Log DEBUG level and above messages to a log file
+log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
+log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}
+log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
+
+# Max log file size of 10MB
+log4j.appender.ROLLINGFILE.MaxFileSize=10MB
+# uncomment the next line to limit number of backup files
+#log4j.appender.ROLLINGFILE.MaxBackupIndex=10
+
+log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
+
+
+#
+# Add TRACEFILE to rootLogger to get log file output
+#    Log DEBUG level and above messages to a log file
+log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
+log4j.appender.TRACEFILE.Threshold=TRACE
+log4j.appender.TRACEFILE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}
+
+log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout
+### Notice we are including log4j's NDC here (%x)
+log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L][%x] - %m%n

http://git-wip-us.apache.org/repos/asf/ignite/blob/d151e402/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZKClusterNode.java
----------------------------------------------------------------------
diff --git a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZKClusterNode.java b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZKClusterNode.java
new file mode 100644
index 0000000..459df23
--- /dev/null
+++ b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/zk/ZKClusterNode.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.spi.discovery.tcp.ipfinder.zk;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import org.apache.zookeeper.AsyncCallback;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.data.Stat;
+
+/**
+ *
+ */
+public class ZKClusterNode implements Watcher {
+    /** */
+    static final String CLUSTER_PATH = "/cluster";
+
+    /** */
+    private ZooKeeper zk;
+
+    /** */
+    volatile String nodePath;
+
+    /** */
+    List<String> curNodes;
+
+    /** */
+    private NodesUpdateCallback nodesUpdateCallback;
+
+    /** */
+    final String nodeName;
+
+    /** */
+    final CountDownLatch connectLatch = new CountDownLatch(1);
+
+    public ZKClusterNode(String nodeName) {
+        this.nodeName = nodeName;
+
+        nodesUpdateCallback = new NodesUpdateCallback();
+    }
+
+    private void log(String msg) {
+        System.out.println(nodeName + ": " + msg);
+    }
+
+    @Override public void process(WatchedEvent event) {
+        log("Process event: " + event.getType() + " " + event.getPath());
+
+        if (event.getType() == Event.EventType.NodeChildrenChanged && event.getPath().equals(CLUSTER_PATH)) {
+            zk.getChildren(CLUSTER_PATH, true, nodesUpdateCallback, null);
+        }
+    }
+
+    /**
+     *
+     */
+    class NodesUpdateCallback implements AsyncCallback.Children2Callback {
+        @Override public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
+            log("Nodes changed: " + children);
+
+            curNodes = children;
+        }
+    }
+
+    public void join(String connectString) throws Exception {
+        log("Start connect " + connectString);
+
+        zk = new ZooKeeper(connectString, 1000, this);
+
+        if (zk.exists(CLUSTER_PATH, false) == null) {
+            try {
+                zk.create(CLUSTER_PATH, new byte[]{}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+            }
+            catch (KeeperException.NodeExistsException e) {
+                // Ignore.
+            }
+        }
+
+        zk.getChildren(CLUSTER_PATH, true, nodesUpdateCallback, null);
+
+
+        zk.create(CLUSTER_PATH + "/node-", new byte[]{}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL,
+            new AsyncCallback.StringCallback() {
+                @Override public void processResult(int rc, String path, Object ctx, String name) {
+                    nodePath = name;
+
+                    log("Node created: " + name);
+
+//                        if (name.endsWith("0000000001")) {
+//                            try {
+//                                Thread.sleep(10_000);
+//                            }
+//                            catch (Exception e) {
+//                                e.printStackTrace();
+//                            }
+//                        }
+
+                    connectLatch.countDown();
+                }
+            },
+            null);
+
+        connectLatch.await();
+    }
+
+    /**
+     *
+     */
+    public void stop() {
+        try {
+            if (zk != null)
+                zk.close();
+        }
+        catch (Exception e) {
+            log("Closed failed: " + e);
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        new ZKClusterNode(args[0]).join(args[1]);
+
+        Thread.sleep(Long.MAX_VALUE);
+    }
+}