// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include #include #include #include #include #include LOG_SETUP("vespa-model-inspect"); class Application : public FastOS_Application { ModelInspect::Flags _flags; vespalib::string _cfgId; vespalib::string _specString; int parseOpts(); vespalib::string getSources(); public: void usage(); int Main() override; Application(); ~Application(); }; Application::Application() : _flags(), _cfgId("admin/model"), _specString("") {} Application::~Application() { } 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 specs; for (std::string v : vespa::Defaults::vespaConfigSourcesRpcAddrs()) { if (! specs.empty()) specs += ","; specs += v; } return specs; } 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); }