From afcd00f2701d8892bec0e8e8eacf406f9145b926 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Thu, 18 Mar 2021 11:02:29 +0100 Subject: Add 'vespa-zkflw' wrapping ZK's four-letter-word utility --- zookeeper-command-line-client/CMakeLists.txt | 1 + .../vespa/zookeeper/cli/FourLetterWordMain.java | 33 +++++++++ .../src/main/sh/vespa-zkflw | 79 ++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 zookeeper-command-line-client/src/main/java/com/yahoo/vespa/zookeeper/cli/FourLetterWordMain.java create mode 100644 zookeeper-command-line-client/src/main/sh/vespa-zkflw diff --git a/zookeeper-command-line-client/CMakeLists.txt b/zookeeper-command-line-client/CMakeLists.txt index 679383c73cc..2ecbef9ed05 100644 --- a/zookeeper-command-line-client/CMakeLists.txt +++ b/zookeeper-command-line-client/CMakeLists.txt @@ -4,5 +4,6 @@ install_fat_java_artifact(zookeeper-command-line-client) vespa_install_script(src/main/sh/vespa-zkcat vespa-zkcat bin) vespa_install_script(src/main/sh/vespa-zkcli vespa-zkcli bin) vespa_install_script(src/main/sh/vespa-zkctl vespa-zkctl bin) +vespa_install_script(src/main/sh/vespa-zkflw vespa-zkflw bin) vespa_install_script(src/main/sh/vespa-zkls vespa-zkls bin) vespa_install_script(src/main/sh/vespa-zktxnlog vespa-zktxnlog bin) diff --git a/zookeeper-command-line-client/src/main/java/com/yahoo/vespa/zookeeper/cli/FourLetterWordMain.java b/zookeeper-command-line-client/src/main/java/com/yahoo/vespa/zookeeper/cli/FourLetterWordMain.java new file mode 100644 index 00000000000..b54fd9ead25 --- /dev/null +++ b/zookeeper-command-line-client/src/main/java/com/yahoo/vespa/zookeeper/cli/FourLetterWordMain.java @@ -0,0 +1,33 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.zookeeper.cli; + +import com.yahoo.vespa.zookeeper.client.ZkClientConfigBuilder; +import org.apache.zookeeper.common.X509Exception; + +import java.io.IOException; +import java.util.Map; + +/** + * Wraps {@link org.apache.zookeeper.client.FourLetterWordMain} with SSL configuration from Vespa. + * + * @author bjorncs + */ +public class FourLetterWordMain { + + public static void main(String[] args) throws X509Exception.SSLContextException, IOException { + Map zkClientConfig = new ZkClientConfigBuilder().toConfigProperties(); + zkClientConfig.forEach(System::setProperty); + String[] rewrittenArgs = overrideSecureClientArgument(args, zkClientConfig); + org.apache.zookeeper.client.FourLetterWordMain.main(rewrittenArgs); + } + + // Override secure cli argument based on Vespa TLS configuration + // Secure flag is the 4th parameter (optional) to FourLetterWordMain + private static String[] overrideSecureClientArgument(String[] args, Map zkClientConfig) { + String secureClientArgument = zkClientConfig.getOrDefault(ZkClientConfigBuilder.CLIENT_SECURE_PROPERTY, Boolean.FALSE.toString()); + return args.length == 3 || args.length == 4 + ? new String[] {args[0], args[1], args[2], secureClientArgument} + : args; + } + +} diff --git a/zookeeper-command-line-client/src/main/sh/vespa-zkflw b/zookeeper-command-line-client/src/main/sh/vespa-zkflw new file mode 100644 index 00000000000..e543bd4e69d --- /dev/null +++ b/zookeeper-command-line-client/src/main/sh/vespa-zkflw @@ -0,0 +1,79 @@ +#!/bin/sh +# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +# BEGIN environment bootstrap section +# Do not edit between here and END as this section should stay identical in all scripts + +findpath () { + myname=${0} + mypath=${myname%/*} + myname=${myname##*/} + empty_if_start_slash=${mypath%%/*} + if [ "${empty_if_start_slash}" ]; then + mypath=$(pwd)/${mypath} + fi + if [ "$mypath" ] && [ -d "$mypath" ]; then + return + fi + mypath=$(pwd) + if [ -f "${mypath}/${myname}" ]; then + return + fi + echo "FATAL: Could not figure out the path where $myname lives from $0" + exit 1 +} + +COMMON_ENV=libexec/vespa/common-env.sh + +source_common_env () { + if [ "$VESPA_HOME" ] && [ -d "$VESPA_HOME" ]; then + export VESPA_HOME + common_env=$VESPA_HOME/$COMMON_ENV + if [ -f "$common_env" ]; then + . $common_env + return + fi + fi + return 1 +} + +findroot () { + source_common_env && return + if [ "$VESPA_HOME" ]; then + echo "FATAL: bad VESPA_HOME value '$VESPA_HOME'" + exit 1 + fi + if [ "$ROOT" ] && [ -d "$ROOT" ]; then + VESPA_HOME="$ROOT" + source_common_env && return + fi + findpath + while [ "$mypath" ]; do + VESPA_HOME=${mypath} + source_common_env && return + mypath=${mypath%/*} + done + echo "FATAL: missing VESPA_HOME environment variable" + echo "Could not locate $COMMON_ENV anywhere" + exit 1 +} + +findhost () { + if [ "${VESPA_HOSTNAME}" = "" ]; then + VESPA_HOSTNAME=$(vespa-detect-hostname || hostname -f || hostname || echo "localhost") || exit 1 + fi + validate="${VESPA_HOME}/bin/vespa-validate-hostname" + if [ -f "$validate" ]; then + "$validate" "${VESPA_HOSTNAME}" || exit 1 + fi + export VESPA_HOSTNAME +} + +findroot +findhost + +# END environment bootstrap section + +java -cp $VESPA_HOME/lib/jars/zookeeper-command-line-client-jar-with-dependencies.jar \ + -Dlog4j.configuration="log4j-vespa.properties" -Xms32m -Xmx512m \ + com.yahoo.vespa.zookeeper.cli.FourLetterWordMain "$@" -- cgit v1.2.3