我试图通过groovy在zookeeper中创建一个新节点,但是在系统重启后,该节点消失了,就像从未创建过一样。
此代码是Jenkins管道的一部分,在某些Windows VM的后期构建groovy脚本中。然后管道在此计算机上执行重新启动,节点消失。
我已经在其他几个Windows VM上发生了
这是我的代码:
@Grab('org.apache.zookeeper:zookeeper:3.4.6')
import org.apache.zookeeper.*
import static org.apache.zookeeper.ZooKeeper.States.*
import org.apache.zookeeper.ZooDefs.Ids;
final int TIMEOUT_MSEC = 5000
final int RETRY_MSEC = 100
def num_retries enter code here= 0
PATH_TO_NODE = "/some/path/to/node"
noOpWatcher = { event -> } as Watcher
zk = new ZooKeeper('myIP', TIMEOUT_MSEC, noOpWatcher)
def addNode() {
if (zk.exists(PATH_TO_NODE, true) == null) {
/*create node*/
println("creating nodes")
zk.create(PATH_TO_NODE, new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT)
zk.create(PATH_TO_NODE + "myNode", "someData".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT)
} else {
println("node already exists")
}
}
while (zk.state != CONNECTED && num_retries < (TIMEOUT_MSEC / RETRY_MSEC)) {
Thread.sleep(RETRY_MSEC)
num_retries++
}
if (zk.state != CONNECTED) {
println("could not connect to zookeeper")
System.exit(1)
} else {
addNode()
}
zk.close()