From 5f2fec6c18813f7a8de3fc6a4ab1ac54d90d4c75 Mon Sep 17 00:00:00 2001 From: cawright-rh Date: Wed, 14 Aug 2024 08:43:08 -0400 Subject: [PATCH] Adding SEED_PORT to have a port override alongside the existing SEED_NODE. (#31) * adding SEED_PORT as a potential override to clientport for zookeeper management scripts * Make zu.jar run over ssl * updating zookeeperStart.sh * taking out debug echo's and fixing zookeeper readyness check to have ssl_options if 2182 is used * removing debug echos --------- Co-authored-by: Cameron Wright Co-authored-by: Razvan Dobre --- docker/bin/zookeeperFunctions.sh | 7 ++++++- docker/bin/zookeeperReady.sh | 13 +++++++++---- docker/bin/zookeeperStart.sh | 12 ++++++++++-- .../zu/src/main/java/io/pravega/zookeeper/Main.kt | 3 +++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/docker/bin/zookeeperFunctions.sh b/docker/bin/zookeeperFunctions.sh index ad1965edf..8c7f0baf9 100644 --- a/docker/bin/zookeeperFunctions.sh +++ b/docker/bin/zookeeperFunctions.sh @@ -29,7 +29,12 @@ function zkConnectionString() { set -e echo "localhost:${CLIENT_PORT}" else + if [ -z "${SEED_PORT}" ]; then + PORT=${CLIENT_PORT} + else + PORT=${SEED_PORT} + fi set -e - echo "${CLIENT_HOST}:${CLIENT_PORT}" + echo "${CLIENT_HOST}:${PORT}" fi } diff --git a/docker/bin/zookeeperReady.sh b/docker/bin/zookeeperReady.sh index c4179ae72..036a40409 100755 --- a/docker/bin/zookeeperReady.sh +++ b/docker/bin/zookeeperReady.sh @@ -27,7 +27,6 @@ OFFSET=${OFFSET:-1} # CLIENT_HOST is used in zkConnectionString function already to create zkURL CLIENT_HOST=${SEED_NODE:-$CLIENT_HOST} - OK=$(echo ruok | socat stdio tcp:localhost:$CLIENT_PORT) # Check to see if zookeeper service answers @@ -88,12 +87,18 @@ if [[ "$OK" == "imok" ]]; then exit 0 elif [[ "$ROLE" == "observer" ]]; then echo "Zookeeper service is ready to be upgraded from observer to participant." - ROLE=participant + SSL_OPTIONS="-Dzookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty -Dzookeeper.client.secure=true" ZKURL=$(zkConnectionString) + ROLE=participant ZKCONFIG=$(zkConfig $OUTSIDE_NAME) - java -Dlog4j.configuration=file:"$LOG4J_CONF" -jar /opt/libs/zu.jar remove $ZKURL $MYID + if [[ "$ZKURL" =~ :2182$ ]]; then + ZK_OPTIONS="$SSL_OPTIONS" + else + ZK_OPTIONS="" + fi + java -Dlog4j.configuration=file:"$LOG4J_CONF" $ZK_OPTIONS -jar /opt/libs/zu.jar remove $ZKURL $MYID sleep 1 - java -Dlog4j.configuration=file:"$LOG4J_CONF" -jar /opt/libs/zu.jar add $ZKURL $MYID $ZKCONFIG + java -Dlog4j.configuration=file:"$LOG4J_CONF" $ZK_OPTIONS -jar /opt/libs/zu.jar add $ZKURL $MYID $ZKCONFIG exit 0 else echo "Something has gone wrong. Unable to determine zookeeper role." diff --git a/docker/bin/zookeeperStart.sh b/docker/bin/zookeeperStart.sh index b32615863..5813b0246 100755 --- a/docker/bin/zookeeperStart.sh +++ b/docker/bin/zookeeperStart.sh @@ -73,7 +73,7 @@ if [ -f $MYID_FILE ]; then fi fi -if [ -f $DYNCONFIG ]; then +if [ -f $DYNCONFIG ] && [ -z $SEED_NODE ]; then ONDISK_DYN_CONFIG=true fi @@ -137,6 +137,7 @@ else fi fi + if [[ "$WRITE_CONFIGURATION" == true ]]; then echo "Writing myid: $MYID to: $MYID_FILE." echo $MYID > $MYID_FILE @@ -151,13 +152,20 @@ if [[ "$WRITE_CONFIGURATION" == true ]]; then fi fi + if [[ "$REGISTER_NODE" == true ]]; then ROLE=observer ZKURL=$(zkConnectionString) ZKCONFIG=$(zkConfig $OUTSIDE_NAME) set -e echo Registering node and writing local configuration to disk. - java -Dlog4j.configuration=file:"$LOG4J_CONF" -jar /opt/libs/zu.jar add $ZKURL $MYID $ZKCONFIG $DYNCONFIG + SSL_OPTIONS="-Dzookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty -Dzookeeper.client.secure=true" + if [[ "$ZKURL" =~ :2182$ ]]; then + ZK_OPTIONS="$SSL_OPTIONS" + else + ZK_OPTIONS="" + fi + java -Dlog4j.configuration=file:"$LOG4J_CONF" $ZK_OPTIONS -jar /opt/libs/zu.jar add $ZKURL $MYID $ZKCONFIG $DYNCONFIG set +e fi diff --git a/docker/zu/src/main/java/io/pravega/zookeeper/Main.kt b/docker/zu/src/main/java/io/pravega/zookeeper/Main.kt index 7442ffb62..651f703a1 100644 --- a/docker/zu/src/main/java/io/pravega/zookeeper/Main.kt +++ b/docker/zu/src/main/java/io/pravega/zookeeper/Main.kt @@ -50,6 +50,7 @@ fun runSync(args: Array, suppressOutput: Boolean = false): String { if (! suppressOutput) { print(clusterSize) } + zk.close() clusterSize } catch (e: Exception) { System.err.println("Error performing zookeeper sync operation:") @@ -71,6 +72,7 @@ fun runGetAll(args: Array, suppressOutput: Boolean = false): String { if (! suppressOutput) { print(zkCfg) } + zk.close() zkCfg } catch (e: Exception) { System.err.println("Error getting server config") @@ -129,6 +131,7 @@ fun reconfigure(zkUrl: String, joining: String?, leaving: String?, outputFile: S } else { File(outputFile).bufferedWriter().use {it.write(cfgStr + "\n")} } + zk.close() } catch (e: Exception) { System.err.println("Error performing zookeeper reconfiguration:") e.printStackTrace(System.err)