TS-2349: Move traffic_line to the cmd subdirectory
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/c83e1d84 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/c83e1d84 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/c83e1d84 Branch: refs/heads/master Commit: c83e1d847086c2b9ed4cf7b953409d24e9929bf4 Parents: 6917d8e Author: James Peach <[email protected]> Authored: Sat Nov 9 20:51:12 2013 -0800 Committer: James Peach <[email protected]> Committed: Thu Nov 14 12:30:41 2013 -0800 ---------------------------------------------------------------------- cmd/Makefile.am | 2 +- cmd/traffic_line/Makefile.am | 35 ++++++ cmd/traffic_line/traffic_line.cc | 218 ++++++++++++++++++++++++++++++++++ configure.ac | 1 + mgmt/cli/Makefile.am | 12 +- mgmt/cli/TrafficLine.cc | 218 ---------------------------------- 6 files changed, 256 insertions(+), 230 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c83e1d84/cmd/Makefile.am ---------------------------------------------------------------------- diff --git a/cmd/Makefile.am b/cmd/Makefile.am index 4d30867..58a8a68 100644 --- a/cmd/Makefile.am +++ b/cmd/Makefile.am @@ -15,4 +15,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -SUBDIRS = traffic_top traffic_cop +SUBDIRS = traffic_top traffic_cop traffic_line http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c83e1d84/cmd/traffic_line/Makefile.am ---------------------------------------------------------------------- diff --git a/cmd/traffic_line/Makefile.am b/cmd/traffic_line/Makefile.am new file mode 100644 index 0000000..6a2aec3 --- /dev/null +++ b/cmd/traffic_line/Makefile.am @@ -0,0 +1,35 @@ +# +# Makefile.am for the Enterprise Management module. +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +AM_CPPFLAGS = \ + $(iocore_include_dirs) \ + -I$(top_srcdir)/lib \ + -I$(top_srcdir)/lib/ts \ + -I$(top_srcdir)/mgmt/api/include + +bin_PROGRAMS = traffic_line + +traffic_line_SOURCES = \ + traffic_line.cc + +traffic_line_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@ +traffic_line_LDADD = \ + $(top_builddir)/mgmt/api/libtsmgmt.la \ + $(top_builddir)/lib/ts/libtsutil.la \ + @LIBRESOLV@ @LIBTCL@ @LIBSSL@ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c83e1d84/cmd/traffic_line/traffic_line.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_line/traffic_line.cc b/cmd/traffic_line/traffic_line.cc new file mode 100644 index 0000000..7f99f5b --- /dev/null +++ b/cmd/traffic_line/traffic_line.cc @@ -0,0 +1,218 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "libts.h" + +#include "ink_args.h" +#include "I_Version.h" +#include "Tokenizer.h" +#include "TextBuffer.h" +#include "mgmtapi.h" + +static const char *programName; + +static char ReadVar[1024]; +static char SetVar[1024]; +static char VarValue[1024]; +static int ReRead; +static int Shutdown; +static int BounceCluster; +static int BounceLocal; +static int QueryDeadhosts; +static int Startup; +static int ShutdownMgmtCluster; +static int ShutdownMgmtLocal; +static int ClearCluster; +static int ClearNode; +static char ZeroCluster[1024]; +static char ZeroNode[1024]; +static int VersionFlag; + +static TSError +handleArgInvocation() +{ + if (ReRead == 1) { + return TSReconfigure(); + } else if (ShutdownMgmtCluster == 1) { + return TSRestart(true); + } else if (ShutdownMgmtLocal == 1) { + return TSRestart(false); + } else if (Shutdown == 1) { + return TSProxyStateSet(TS_PROXY_OFF, TS_CACHE_CLEAR_OFF); + } else if (BounceCluster == 1) { + return TSBounce(true); + } else if (BounceLocal == 1) { + return TSBounce(false); + } else if (Startup == 1) { + return TSProxyStateSet(TS_PROXY_ON, TS_CACHE_CLEAR_OFF); + } else if (ClearCluster == 1) { + return TSStatsReset(true); + } else if (ClearNode == 1) { + return TSStatsReset(false); + } else if (*ZeroNode != '\0' || *ZeroCluster != '\0') { + TSError err; + TSRecordEle *rec_ele = TSRecordEleCreate(); + char *name = *ZeroNode ? ZeroNode : ZeroCluster; + if ((err = TSRecordGet(name, rec_ele)) != TS_ERR_OKAY) { + fprintf(stderr, "%s: %s\n", programName, TSGetErrorMessage(err)); + TSRecordEleDestroy(rec_ele); + return err; + } + TSRecordEleDestroy(rec_ele); + return TSStatsReset(*ZeroCluster ? true : false, name); + } else if (QueryDeadhosts == 1) { + fprintf(stderr, "Query Deadhosts is not implemented, it requires support for congestion control.\n"); + fprintf(stderr, "For more details, examine the old code in cli/CLI.cc: QueryDeadhosts()\n"); + return TS_ERR_FAIL; + } else if (*ReadVar != '\0') { // Handle a value read + if (*SetVar != '\0' || *VarValue != '\0') { + fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set values at the same time\n", programName); + return TS_ERR_FAIL; + } else { + TSError err; + TSRecordEle *rec_ele = TSRecordEleCreate(); + + if ((err = TSRecordGet(ReadVar, rec_ele)) != TS_ERR_OKAY) { + fprintf(stderr, "%s: %s\n", programName, TSGetErrorMessage(err)); + } else { + switch (rec_ele->rec_type) { + case TS_REC_INT: + printf("%" PRId64 "\n", rec_ele->int_val); + break; + case TS_REC_COUNTER: + printf("%" PRId64 "\n", rec_ele->counter_val); + break; + case TS_REC_FLOAT: + printf("%f\n", rec_ele->float_val); + break; + case TS_REC_STRING: + printf("%s\n", rec_ele->string_val); + break; + default: + fprintf(stderr, "%s: unknown record type (%d)\n", programName, rec_ele->rec_type); + err = TS_ERR_FAIL; + break; + } + } + TSRecordEleDestroy(rec_ele); + return err; + } + } else if (*SetVar != '\0') { // Setting a variable + if (*VarValue == '\0') { + fprintf(stderr, "%s: Set requires a -v argument\n", programName); + return TS_ERR_FAIL; + } else { + TSError err; + TSActionNeedT action; + + if ((err = TSRecordSet(SetVar, VarValue, &action)) != TS_ERR_OKAY) + fprintf(stderr, "%s: Please correct your variable name and|or value\n", programName); + return err; + } + } else if (*VarValue != '\0') { // We have a value but no variable to set + fprintf(stderr, "%s: Must specify variable to set with -s when using -v\n", programName); + return TS_ERR_FAIL; + } + + fprintf(stderr, "%s: No arguments specified\n", programName); + return TS_ERR_FAIL; +} + +int +main(int /* argc ATS_UNUSED */, char **argv) +{ + AppVersionInfo appVersionInfo; + TSError status; + + programName = argv[0]; + + ReadVar[0] = '\0'; + SetVar[0] = '\0'; + VarValue[0] = '\0'; + ReRead = 0; + Shutdown = 0; + BounceCluster = 0; + BounceLocal = 0; + QueryDeadhosts = 0; + Startup = 0; + ShutdownMgmtCluster = 0; + ShutdownMgmtLocal = 0; + ClearCluster = 0; + ClearNode = 0; + ZeroCluster[0] = '\0'; + ZeroNode[0] = '\0'; + VersionFlag = 0; + + // build the application information structure + appVersionInfo.setup(PACKAGE_NAME,"traffic_line", PACKAGE_VERSION, __DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, ""); + +/* Argument description table used to describe how to parse command line args, */ +/* see 'ink_args.h' for meanings of the various fields */ + ArgumentDescription argument_descriptions[] = { + {"query_deadhosts", 'q', "Query congested sites", "F", &QueryDeadhosts, NULL, NULL}, + {"read_var", 'r', "Read Variable", "S1024", &ReadVar, NULL, NULL}, + {"set_var", 's', "Set Variable (requires -v option)", "S1024", &SetVar, NULL, NULL}, + {"value", 'v', "Set Value (used with -s option)", "S1024", &VarValue, NULL, NULL}, + {"help", 'h', "Help", NULL, NULL, NULL, usage}, + {"reread_config", 'x', "Reread Config Files", "F", &ReRead, NULL, NULL}, + {"restart_cluster", 'M', "Restart traffic_manager (cluster wide)", "F", &ShutdownMgmtCluster, NULL, NULL}, + {"restart_local", 'L', "Restart traffic_manager (local node)", "F", &ShutdownMgmtLocal, NULL, NULL}, + {"shutdown", 'S', "Shutdown traffic_server (local node)", "F", &Shutdown, NULL, NULL}, + {"startup", 'U', "Start traffic_server (local node)", "F", &Startup, NULL, NULL}, + {"bounce_cluster", 'B', "Bounce traffic_server (cluster wide)", "F", &BounceCluster, NULL, NULL}, + {"bounce_local", 'b', "Bounce local traffic_server", "F", &BounceLocal, NULL, NULL}, + {"clear_cluster", 'C', "Clear Statistics (cluster wide)", "F", &ClearCluster, NULL, NULL}, + {"clear_node", 'c', "Clear Statistics (local node)", "F", &ClearNode, NULL, NULL}, + {"zero_cluster", 'Z', "Zero Specific Statistic (cluster wide)", "S1024", &ZeroCluster, NULL, NULL}, + {"zero_node", 'z', "Zero Specific Statistic (local node)", "S1024", &ZeroNode, NULL, NULL}, + {"version", 'V', "Print Version Id", "T", &VersionFlag, NULL, NULL}, + }; + + // Process command line arguments and dump into variables + process_args(argument_descriptions, countof(argument_descriptions), argv); + + // check for the version number request + if (VersionFlag) { + ink_fputln(stderr, appVersionInfo.FullVersionInfoStr); + exit(0); + } + + // Connect to Local Manager and do it. + if (TS_ERR_OKAY != TSInit(NULL, static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS | TS_MGMT_OPT_NO_SOCK_TESTS))) { + fprintf(stderr, "error: could not connect to management port, make sure traffic_manager is running\n"); + exit(1); + } + + status = handleArgInvocation(); + + // Done with the mgmt API. + TSTerminate(); + + if (TS_ERR_OKAY != status) { + if (ReadVar[0] == '\0' && SetVar[0] == '\0') + fprintf(stderr, "error: the requested command failed\n"); + exit(1); + } + + exit(0); +} http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c83e1d84/configure.ac ---------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index ef218c3..fe77e8d 100644 --- a/configure.ac +++ b/configure.ac @@ -1843,6 +1843,7 @@ AC_CONFIG_FILES([ Makefile cmd/Makefile cmd/traffic_cop/Makefile + cmd/traffic_line/Makefile cmd/traffic_top/Makefile doc/Doxyfile doc/Makefile http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c83e1d84/mgmt/cli/Makefile.am ---------------------------------------------------------------------- diff --git a/mgmt/cli/Makefile.am b/mgmt/cli/Makefile.am index 14c893e..b92caa2 100644 --- a/mgmt/cli/Makefile.am +++ b/mgmt/cli/Makefile.am @@ -25,8 +25,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/lib/ts \ -I$(top_srcdir)/mgmt/api/include - -bin_PROGRAMS = traffic_shell traffic_line +bin_PROGRAMS = traffic_shell traffic_shell_SOURCES = \ cliAppInit.cc \ CliCreateCommands.h \ @@ -39,9 +38,6 @@ traffic_shell_SOURCES = \ hashtable.h \ ShowCmd.h -traffic_line_SOURCES = \ - TrafficLine.cc - noinst_LIBRARIES = libtrafficshell.a libtrafficshell_a_SOURCES = \ CliCreateCommands.cc \ @@ -80,9 +76,3 @@ traffic_shell_LDADD = \ @LIBRESOLV@ @LIBEXPAT@ @LIBSSL@ \ @LIBPCRE@ @LIBREADLINE@ \ -lm - -traffic_line_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@ -traffic_line_LDADD = \ - $(top_builddir)/mgmt/api/libtsmgmt.la \ - $(top_builddir)/lib/ts/libtsutil.la \ - @LIBRESOLV@ @LIBTCL@ @LIBSSL@ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c83e1d84/mgmt/cli/TrafficLine.cc ---------------------------------------------------------------------- diff --git a/mgmt/cli/TrafficLine.cc b/mgmt/cli/TrafficLine.cc deleted file mode 100644 index 7f99f5b..0000000 --- a/mgmt/cli/TrafficLine.cc +++ /dev/null @@ -1,218 +0,0 @@ -/** @file - - A brief file description - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#include "libts.h" - -#include "ink_args.h" -#include "I_Version.h" -#include "Tokenizer.h" -#include "TextBuffer.h" -#include "mgmtapi.h" - -static const char *programName; - -static char ReadVar[1024]; -static char SetVar[1024]; -static char VarValue[1024]; -static int ReRead; -static int Shutdown; -static int BounceCluster; -static int BounceLocal; -static int QueryDeadhosts; -static int Startup; -static int ShutdownMgmtCluster; -static int ShutdownMgmtLocal; -static int ClearCluster; -static int ClearNode; -static char ZeroCluster[1024]; -static char ZeroNode[1024]; -static int VersionFlag; - -static TSError -handleArgInvocation() -{ - if (ReRead == 1) { - return TSReconfigure(); - } else if (ShutdownMgmtCluster == 1) { - return TSRestart(true); - } else if (ShutdownMgmtLocal == 1) { - return TSRestart(false); - } else if (Shutdown == 1) { - return TSProxyStateSet(TS_PROXY_OFF, TS_CACHE_CLEAR_OFF); - } else if (BounceCluster == 1) { - return TSBounce(true); - } else if (BounceLocal == 1) { - return TSBounce(false); - } else if (Startup == 1) { - return TSProxyStateSet(TS_PROXY_ON, TS_CACHE_CLEAR_OFF); - } else if (ClearCluster == 1) { - return TSStatsReset(true); - } else if (ClearNode == 1) { - return TSStatsReset(false); - } else if (*ZeroNode != '\0' || *ZeroCluster != '\0') { - TSError err; - TSRecordEle *rec_ele = TSRecordEleCreate(); - char *name = *ZeroNode ? ZeroNode : ZeroCluster; - if ((err = TSRecordGet(name, rec_ele)) != TS_ERR_OKAY) { - fprintf(stderr, "%s: %s\n", programName, TSGetErrorMessage(err)); - TSRecordEleDestroy(rec_ele); - return err; - } - TSRecordEleDestroy(rec_ele); - return TSStatsReset(*ZeroCluster ? true : false, name); - } else if (QueryDeadhosts == 1) { - fprintf(stderr, "Query Deadhosts is not implemented, it requires support for congestion control.\n"); - fprintf(stderr, "For more details, examine the old code in cli/CLI.cc: QueryDeadhosts()\n"); - return TS_ERR_FAIL; - } else if (*ReadVar != '\0') { // Handle a value read - if (*SetVar != '\0' || *VarValue != '\0') { - fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set values at the same time\n", programName); - return TS_ERR_FAIL; - } else { - TSError err; - TSRecordEle *rec_ele = TSRecordEleCreate(); - - if ((err = TSRecordGet(ReadVar, rec_ele)) != TS_ERR_OKAY) { - fprintf(stderr, "%s: %s\n", programName, TSGetErrorMessage(err)); - } else { - switch (rec_ele->rec_type) { - case TS_REC_INT: - printf("%" PRId64 "\n", rec_ele->int_val); - break; - case TS_REC_COUNTER: - printf("%" PRId64 "\n", rec_ele->counter_val); - break; - case TS_REC_FLOAT: - printf("%f\n", rec_ele->float_val); - break; - case TS_REC_STRING: - printf("%s\n", rec_ele->string_val); - break; - default: - fprintf(stderr, "%s: unknown record type (%d)\n", programName, rec_ele->rec_type); - err = TS_ERR_FAIL; - break; - } - } - TSRecordEleDestroy(rec_ele); - return err; - } - } else if (*SetVar != '\0') { // Setting a variable - if (*VarValue == '\0') { - fprintf(stderr, "%s: Set requires a -v argument\n", programName); - return TS_ERR_FAIL; - } else { - TSError err; - TSActionNeedT action; - - if ((err = TSRecordSet(SetVar, VarValue, &action)) != TS_ERR_OKAY) - fprintf(stderr, "%s: Please correct your variable name and|or value\n", programName); - return err; - } - } else if (*VarValue != '\0') { // We have a value but no variable to set - fprintf(stderr, "%s: Must specify variable to set with -s when using -v\n", programName); - return TS_ERR_FAIL; - } - - fprintf(stderr, "%s: No arguments specified\n", programName); - return TS_ERR_FAIL; -} - -int -main(int /* argc ATS_UNUSED */, char **argv) -{ - AppVersionInfo appVersionInfo; - TSError status; - - programName = argv[0]; - - ReadVar[0] = '\0'; - SetVar[0] = '\0'; - VarValue[0] = '\0'; - ReRead = 0; - Shutdown = 0; - BounceCluster = 0; - BounceLocal = 0; - QueryDeadhosts = 0; - Startup = 0; - ShutdownMgmtCluster = 0; - ShutdownMgmtLocal = 0; - ClearCluster = 0; - ClearNode = 0; - ZeroCluster[0] = '\0'; - ZeroNode[0] = '\0'; - VersionFlag = 0; - - // build the application information structure - appVersionInfo.setup(PACKAGE_NAME,"traffic_line", PACKAGE_VERSION, __DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, ""); - -/* Argument description table used to describe how to parse command line args, */ -/* see 'ink_args.h' for meanings of the various fields */ - ArgumentDescription argument_descriptions[] = { - {"query_deadhosts", 'q', "Query congested sites", "F", &QueryDeadhosts, NULL, NULL}, - {"read_var", 'r', "Read Variable", "S1024", &ReadVar, NULL, NULL}, - {"set_var", 's', "Set Variable (requires -v option)", "S1024", &SetVar, NULL, NULL}, - {"value", 'v', "Set Value (used with -s option)", "S1024", &VarValue, NULL, NULL}, - {"help", 'h', "Help", NULL, NULL, NULL, usage}, - {"reread_config", 'x', "Reread Config Files", "F", &ReRead, NULL, NULL}, - {"restart_cluster", 'M', "Restart traffic_manager (cluster wide)", "F", &ShutdownMgmtCluster, NULL, NULL}, - {"restart_local", 'L', "Restart traffic_manager (local node)", "F", &ShutdownMgmtLocal, NULL, NULL}, - {"shutdown", 'S', "Shutdown traffic_server (local node)", "F", &Shutdown, NULL, NULL}, - {"startup", 'U', "Start traffic_server (local node)", "F", &Startup, NULL, NULL}, - {"bounce_cluster", 'B', "Bounce traffic_server (cluster wide)", "F", &BounceCluster, NULL, NULL}, - {"bounce_local", 'b', "Bounce local traffic_server", "F", &BounceLocal, NULL, NULL}, - {"clear_cluster", 'C', "Clear Statistics (cluster wide)", "F", &ClearCluster, NULL, NULL}, - {"clear_node", 'c', "Clear Statistics (local node)", "F", &ClearNode, NULL, NULL}, - {"zero_cluster", 'Z', "Zero Specific Statistic (cluster wide)", "S1024", &ZeroCluster, NULL, NULL}, - {"zero_node", 'z', "Zero Specific Statistic (local node)", "S1024", &ZeroNode, NULL, NULL}, - {"version", 'V', "Print Version Id", "T", &VersionFlag, NULL, NULL}, - }; - - // Process command line arguments and dump into variables - process_args(argument_descriptions, countof(argument_descriptions), argv); - - // check for the version number request - if (VersionFlag) { - ink_fputln(stderr, appVersionInfo.FullVersionInfoStr); - exit(0); - } - - // Connect to Local Manager and do it. - if (TS_ERR_OKAY != TSInit(NULL, static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS | TS_MGMT_OPT_NO_SOCK_TESTS))) { - fprintf(stderr, "error: could not connect to management port, make sure traffic_manager is running\n"); - exit(1); - } - - status = handleArgInvocation(); - - // Done with the mgmt API. - TSTerminate(); - - if (TS_ERR_OKAY != status) { - if (ReadVar[0] == '\0' && SetVar[0] == '\0') - fprintf(stderr, "error: the requested command failed\n"); - exit(1); - } - - exit(0); -}
