diff options
Diffstat (limited to 'filedistribution/src/apps/status')
4 files changed, 0 insertions, 279 deletions
diff --git a/filedistribution/src/apps/status/.gitignore b/filedistribution/src/apps/status/.gitignore deleted file mode 100644 index 2105a3c7051..00000000000 --- a/filedistribution/src/apps/status/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/vespa-status-filedistribution-bin -filedistribution_status-filedistribution_app diff --git a/filedistribution/src/apps/status/CMakeLists.txt b/filedistribution/src/apps/status/CMakeLists.txt deleted file mode 100644 index e666bc2cecc..00000000000 --- a/filedistribution/src/apps/status/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(filedistribution_status-filedistribution_app - SOURCES - status-filedistribution.cpp - INSTALL bin - OUTPUT_NAME vespa-status-filedistribution-bin - DEPENDS - filedistribution_filedistributionmodel - filedistribution_common -) -target_compile_options(filedistribution_status-filedistribution_app PRIVATE -DTORRENT_DISABLE_ENCRYPTION -DTORRENT_DISABLE_DHT -DWITH_SHIPPED_GEOIP_H -DBOOST_ASIO_HASH_MAP_BUCKETS=1021 -DBOOST_EXCEPTION_DISABLE -DBOOST_ASIO_ENABLE_CANCELIO -DBOOST_ASIO_DYN_LINK -DTORRENT_LINKING_SHARED) -vespa_add_target_system_dependency(filedistribution_status-filedistribution_app boost boost_system${VESPA_BOOST_LIB_SUFFIX}) -vespa_add_target_system_dependency(filedistribution_status-filedistribution_app boost boost_thread${VESPA_BOOST_LIB_SUFFIX}) -vespa_add_target_system_dependency(filedistribution_status-filedistribution_app boost boost_program_options${VESPA_BOOST_LIB_SUFFIX}) -vespa_add_target_system_dependency(filedistribution_status-filedistribution_app boost boost_filesystem${VESPA_BOOST_LIB_SUFFIX}) -vespa_install_script(vespa-status-filedistribution.sh vespa-status-filedistribution bin) diff --git a/filedistribution/src/apps/status/status-filedistribution.cpp b/filedistribution/src/apps/status/status-filedistribution.cpp deleted file mode 100644 index 52cabdfcb2d..00000000000 --- a/filedistribution/src/apps/status/status-filedistribution.cpp +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/filedistribution/model/zkfacade.h> -#include <vespa/filedistribution/model/filedistributionmodel.h> -#include <vespa/filedistribution/model/filedistributionmodelimpl.h> -#include <zookeeper/zookeeper.h> -#include <boost/program_options.hpp> - -#include <vespa/log/log.h> -#include <iostream> -#include <map> -#include <thread> - -LOG_SETUP("status-filedistribution"); - -using namespace filedistribution; -using namespace std::literals; -namespace po = boost::program_options; - -std::string -plural(size_t size) -{ - if (size == 1) - return ""; - else - return "s"; -} - -template <class CONT> -std::string -plural(const CONT& cont) -{ - size_t size = cont.size(); - return plural(size); -} - -typedef FileDBModel::HostStatus HostStatus; -typedef std::map<std::string, HostStatus> StatusByHostName; - -void -printWaitingForHosts(const StatusByHostName& notFinishedHosts) -{ - std::cout <<"Waiting for the following host" <<plural(notFinishedHosts) <<":" <<std::endl; - for (const StatusByHostName::value_type & hostNameAndStatus : notFinishedHosts) { - std::cout <<hostNameAndStatus.first <<" ("; - - const HostStatus& hostStatus = hostNameAndStatus.second; - if (hostStatus._state == HostStatus::notStarted) { - std::cout <<"Not started"; - } else { - std::cout <<"Downloading, " - <<hostStatus._numFilesFinished <<"/" <<hostStatus._numFilesToDownload - <<" file" <<plural(hostStatus._numFilesToDownload) <<" completed"; - } - std::cout <<")" <<std::endl; - } -} - -//TODO:refactor -int printStatus(const std::string& zkservers) -{ - std::shared_ptr<ZKFacade> zk(new ZKFacade(zkservers, true)); - - std::shared_ptr<FileDBModel> model(new ZKFileDBModel(zk)); - - std::vector<std::string> hosts = model->getHosts(); - - StatusByHostName notFinishedHosts; - StatusByHostName finishedHosts; - bool hasStarted = false; - - for (const std::string & host : hosts) { - HostStatus hostStatus = model->getHostStatus(host); - switch (hostStatus._state) { - case HostStatus::finished: - hasStarted = true; - finishedHosts[host] = hostStatus; - break; - case HostStatus::inProgress: - hasStarted = true; - //@fallthrough@ - case HostStatus::notStarted: - notFinishedHosts[host] = hostStatus; - break; - } - } - - if (notFinishedHosts.empty()) { - std::cout <<"Finished distributing files to all hosts." <<std::endl; - return 0; - } else if (!hasStarted) { - std::cout <<"File distribution has not yet started." <<std::endl; - return 0; - } else { - printWaitingForHosts(notFinishedHosts); - return 5; - } -} - -int -printStatusRetryIfZKProblem(const std::string& zkservers, const std::string& zkLogFile) -{ - FILE* file = fopen(zkLogFile.c_str(), "w"); - if (file == NULL) { - std::cerr <<"Could not open file " <<zkLogFile <<std::endl; - } else { - zoo_set_log_stream(file); - } - zoo_set_debug_level(ZOO_LOG_LEVEL_ERROR); - - for (int i = 0; i < 5; ++i) { - try { - return printStatus(zkservers); - } catch (ZKNodeDoesNotExistsException& e) { - LOG(debug, "Node does not exists, assuming concurrent update. %s", e.what()); - - } catch (ZKSessionExpired& e) { - LOG(debug, "Session expired."); - } - std::this_thread::sleep_for(500ms); - } - return 4; -} - - -//TODO: move to common -struct ProgramOptionException { - std::string _msg; - ProgramOptionException(const std::string & msg) - : _msg(msg) - {} -}; - -bool exists(const std::string& optionName, const po::variables_map& map) { - return map.find(optionName) != map.end(); -} - -void ensureExists(const std::string& optionName, const po::variables_map& map) { - if (!exists(optionName, map)) { - throw ProgramOptionException("Error: Missing option " + optionName); - } -} -//END: move to common - - -int -main(int argc, char** argv) { - const char - *zkstring = "zkstring", - *zkLogFile = "zkLogFile", - *help = "help"; - - po::options_description description; - description.add_options() - (zkstring, po::value<std::string > (), "The zookeeper servers to connect to, separated by comma") - (zkLogFile, po::value<std::string >() -> default_value("/dev/null"), "Zookeeper log file") - (help, "help"); - - try { - po::variables_map values; - po::store(po::parse_command_line(argc, argv, description), values); - - if (exists(help, values)) { - std::cout <<description; - return 0; - } - - ensureExists(zkstring, values); - - return printStatusRetryIfZKProblem( - values[zkstring] .as<std::string>(), - values[zkLogFile].as<std::string>()); - } catch (const ProgramOptionException& e) { - std::cerr <<e._msg <<std::endl; - return 3; - } catch(const std::exception& e) { - std::cerr <<"Error: " <<e.what() <<std::endl; - return 3; - } -} diff --git a/filedistribution/src/apps/status/vespa-status-filedistribution.sh b/filedistribution/src/apps/status/vespa-status-filedistribution.sh deleted file mode 100644 index 65a6da89b56..00000000000 --- a/filedistribution/src/apps/status/vespa-status-filedistribution.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/sh -# Copyright 2017 Yahoo Holdings. 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##*/} - 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 -} - -findroot - -# END environment bootstrap section - -ROOT=${VESPA_HOME%/} - -if [ "$cloudconfig_server__disable_filedistributor" = "" ] || [ "$cloudconfig_server__disable_filedistributor" != "true" ]; then - ZKSTRING=$($ROOT/libexec/vespa/vespa-config.pl -zkstring) - test -z "$VESPA_LOG_LEVEL" && VESPA_LOG_LEVEL=warning - export VESPA_LOG_LEVEL - exec $ROOT/bin/vespa-status-filedistribution-bin --zkstring "$ZKSTRING" $@ -else - if [ "$cloudconfig_server__environment" != "" ]; then - environment="--environment $cloudconfig_server__environment" - fi - if [ "$cloudconfig_server__region" != "" ]; then - region="--region $cloudconfig_server__region" - fi - - defaults="--tenant default --application default --instance default" - jvmoptions="-XX:MaxJavaStackTraceDepth=-1 $(getJavaOptionsIPV46) -Xms48m -Xmx48m" - jar="-cp $VESPA_HOME/lib/jars/filedistribution-jar-with-dependencies.jar" - - exec java $jvmoptions $jar com.yahoo.vespa.filedistribution.status.FileDistributionStatusClient $defaults $environment $region "$@" -fi |