From 72231250ed81e10d66bfe70701e64fa5fe50f712 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 15 Jun 2016 23:09:44 +0200 Subject: Publish --- configutil/src/apps/configstatus/.gitignore | 4 + configutil/src/apps/configstatus/CMakeLists.txt | 9 ++ configutil/src/apps/configstatus/main.cpp | 104 +++++++++++++++++++ configutil/src/apps/modelinspect/.gitignore | 4 + configutil/src/apps/modelinspect/CMakeLists.txt | 9 ++ configutil/src/apps/modelinspect/main.cpp | 131 ++++++++++++++++++++++++ 6 files changed, 261 insertions(+) create mode 100644 configutil/src/apps/configstatus/.gitignore create mode 100644 configutil/src/apps/configstatus/CMakeLists.txt create mode 100644 configutil/src/apps/configstatus/main.cpp create mode 100644 configutil/src/apps/modelinspect/.gitignore create mode 100644 configutil/src/apps/modelinspect/CMakeLists.txt create mode 100644 configutil/src/apps/modelinspect/main.cpp (limited to 'configutil/src/apps') diff --git a/configutil/src/apps/configstatus/.gitignore b/configutil/src/apps/configstatus/.gitignore new file mode 100644 index 00000000000..5d04dfe43bd --- /dev/null +++ b/configutil/src/apps/configstatus/.gitignore @@ -0,0 +1,4 @@ +/.depend +/Makefile +/vespa-config-status +vespa-config-status-bin diff --git a/configutil/src/apps/configstatus/CMakeLists.txt b/configutil/src/apps/configstatus/CMakeLists.txt new file mode 100644 index 00000000000..58bea4e0d70 --- /dev/null +++ b/configutil/src/apps/configstatus/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(configutil_vespa-config-status_app + SOURCES + main.cpp + OUTPUT_NAME vespa-config-status-bin + INSTALL bin + DEPENDS + configutil_util +) diff --git a/configutil/src/apps/configstatus/main.cpp b/configutil/src/apps/configstatus/main.cpp new file mode 100644 index 00000000000..b3fb611ffa4 --- /dev/null +++ b/configutil/src/apps/configstatus/main.cpp @@ -0,0 +1,104 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include +#include +#include +LOG_SETUP("vespa-config-status"); +#include +#include + +class Application : public FastOS_Application +{ + ConfigStatus::Flags _flags; + vespalib::string _cfgId; + vespalib::string _specString; + int parseOpts(); + vespalib::string getSources(); +public: + void usage(void); + int Main(void); + + Application() : _flags(), _cfgId("admin/model"), _specString("") {} +}; + +int +Application::parseOpts() +{ + char c = '?'; + const char *optArg = NULL; + int optInd = 0; + while ((c = GetOpt("c:s:vC:", optArg, optInd)) != -1) { + switch (c) { + case 'v': + _flags.verbose = true; + break; + case 'C': + _cfgId = optArg; + break; + case 'c': + _specString = optArg; + break; + case 'h': + usage(); + exit(0); + default: + usage(); + exit(1); + } + } + if (_specString.empty()) { + _specString = getSources(); + } + return optInd; +} + + +void +Application::usage(void) +{ + std::cerr << + "vespa-config-status version 1.0" << std::endl << + "Usage: " << _argv[0] << " [options] " << std::endl << + "options: [-v] for verbose" << std::endl << + " [-c host] or [-c host:port] to specify config server" << std::endl << + std::endl; +} + +int +Application::Main(void) +{ + parseOpts(); + + config::ServerSpec spec(_specString); + config::ConfigUri uri = config::ConfigUri::createFromSpec(_cfgId, spec); + ConfigStatus status(_flags, uri); + + return status.action(); +} + +vespalib::string +Application::getSources(void) +{ + vespalib::string cmd = vespa::Defaults::vespaHome(); + cmd.append("libexec/vespa/vespa-config.pl -configsources"); + FILE* fp = popen(cmd.c_str(), "r"); + if (fp == 0) { + std::cerr << "Failed to run " << cmd << " (" + << errno << "): " << strerror(errno) << "\n"; + return ""; + } + vespalib::asciistream specs; + char data[500]; + while (fgets(data, 500, fp) != 0) { + specs << &data[0] << "\n"; + } + pclose(fp); + return specs.str(); +} + +int +main(int argc, char **argv) +{ + Application app; + return app.Entry(argc, argv); +} diff --git a/configutil/src/apps/modelinspect/.gitignore b/configutil/src/apps/modelinspect/.gitignore new file mode 100644 index 00000000000..89d2d6112b6 --- /dev/null +++ b/configutil/src/apps/modelinspect/.gitignore @@ -0,0 +1,4 @@ +/.depend +/Makefile +/vespa-model-inspect +vespa-model-inspect-bin diff --git a/configutil/src/apps/modelinspect/CMakeLists.txt b/configutil/src/apps/modelinspect/CMakeLists.txt new file mode 100644 index 00000000000..be65aa67701 --- /dev/null +++ b/configutil/src/apps/modelinspect/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(configutil_vespa-model-inspect_app + SOURCES + main.cpp + OUTPUT_NAME vespa-model-inspect-bin + INSTALL bin + DEPENDS + configutil_util +) diff --git a/configutil/src/apps/modelinspect/main.cpp b/configutil/src/apps/modelinspect/main.cpp new file mode 100644 index 00000000000..f5a1e28e218 --- /dev/null +++ b/configutil/src/apps/modelinspect/main.cpp @@ -0,0 +1,131 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include +#include +#include +LOG_SETUP("vespa-model-inspect"); +#include +#include +#include +#include + +class Application : public FastOS_Application +{ + ModelInspect::Flags _flags; + vespalib::string _cfgId; + vespalib::string _specString; + int parseOpts(); + vespalib::string getSources(); +public: + void usage(void); + int Main(void); + + Application() : _flags(), _cfgId("admin/model"), _specString("") {} +}; + +int +Application::parseOpts() +{ + char c = '?'; + const char *optArg = NULL; + int optInd = 0; + while ((c = GetOpt("hvut:c:C:", optArg, optInd)) != -1) { + switch (c) { + case 'v': + _flags.verbose = true; + break; + case 'u': + _flags.makeuri = true; + break; + case 't': + _flags.tagFilter.push_back(optArg); + _flags.tagfilt = true; + break; + case 'C': + _cfgId = optArg; + break; + case 'c': + _specString = optArg; + break; + case 'h': + return _argc; + default: + usage(); + exit(1); + } + } + if (_specString.empty()) { + _specString = getSources(); + } + return optInd; +} + +vespalib::string +Application::getSources(void) +{ + vespalib::string cmd = vespa::Defaults::vespaHome(); + cmd.append("libexec/vespa/vespa-config.pl -configsources"); + FILE* fp = popen(cmd.c_str(), "r"); + if (fp == 0) { + std::cerr << "Failed to run " << cmd << " (" + << errno << "): " << strerror(errno) << "\n"; + return ""; + } + vespalib::asciistream specs; + char data[500]; + while (fgets(data, 500, fp) != 0) { + specs << &data[0] << "\n"; + } + pclose(fp); + return specs.str(); +} + +void +Application::usage(void) +{ + std::cerr << + "vespa-model-inspect version 2.0" << std::endl << + "Usage: " << _argv[0] << " [options] " << std::endl << + "options: [-u] for URLs, [-v] for verbose" << std::endl << + " [-c host] or [-c host:port] to specify server" << std::endl << + " [-t tag] to filter on a port tag" << std::endl << + "Where command is:" << std::endl << + " hosts - show all hosts" << std::endl << + " services - show all services" << std::endl << + " clusters - show all cluster names" << std::endl << + " configids - show all config IDs" << std::endl << + " filter:ports - list ports matching filter options" << std::endl << + " host - show services on a given host" << std::endl << + " service [cluster:]" << + " - show all instances of a given servicetype" << std::endl << + " cluster " << + " - show all services associated with the cluster" << std::endl << + " configid " << + " - show service using configid" << std::endl << + " get-index-of " << + " - show all indexes for instances of the servicetype on the host" << std::endl << + std::endl; +} + +int +Application::Main(void) +{ + int cnt = parseOpts(); + if (_argc == cnt) { + usage(); + return 0; + } + + config::ServerSpec spec(_specString); + config::ConfigUri uri = config::ConfigUri::createFromSpec(_cfgId, spec); + ModelInspect model(_flags, uri, std::cout); + return model.action(_argc - cnt, &_argv[cnt]); +} + +int +main(int argc, char** argv) +{ + vespa::Defaults::bootstrap(argv[0]); + Application app; + return app.Entry(argc, argv); +} -- cgit v1.2.3