CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swissknife_notify.cc
Go to the documentation of this file.
1 
5 #include "swissknife_notify.h"
6 
7 #include "notify/cmd_pub.h"
8 #include "notify/cmd_sub.h"
9 
10 namespace {
11 
13  const bool publish = args.count('p') > 0;
14  const bool subscribe = args.count('s') > 0;
15 
16  if (publish == subscribe) {
18  "Either the \"publish\" (-p) or the \"subscribe\" (-s) option "
19  "must be provided");
20  return false;
21  }
22 
23  if (publish && (args.count('r') == 0)) {
25  "A repository URL (-r) needs to be provided when using the "
26  "publish command");
27  return false;
28  }
29 
30  if (subscribe && (args.count('t') == 0)) {
32  "A subscription topic (-t) needs to be provided when using the "
33  "subscribe command");
34  return false;
35  }
36 
37  return true;
38 }
39 
41  if (args.count('m') > 0) {
42  return std::atoi(args.find('m')->second->c_str());
43  } else {
44  return 0;
45  }
46 }
47 
48 } // namespace
49 
50 namespace swissknife {
51 
53 
55  ParameterList l;
56  l.push_back(Parameter::Switch('p', "publish"));
57  l.push_back(Parameter::Switch('s', "subscribe"));
58  l.push_back(Parameter::Mandatory('u', "notification server URL"));
59  l.push_back(
60  Parameter::Optional('r', "URL of repository with manifest to publish"));
61  l.push_back(Parameter::Optional('t', "subscription topic"));
62  l.push_back(Parameter::Optional('m', "minimum revision number of interest"));
63  l.push_back(Parameter::Switch(
64  'c', "run continuously (don't exit after first notification)"));
65  l.push_back(Parameter::Switch('v', "verbose output"));
66  return l;
67 }
68 
70  if (!ValidateArgs(args)) {
71  return 1;
72  }
73 
74  int ret = 0;
75  bool verbose = args.count('v') > 0;
76  std::string server_url = *args.find('u')->second;
77  bool publish = args.count('p') > 0;
78  if (publish) {
79  std::string repository_url = *args.find('r')->second;
80  ret = notify::DoPublish(server_url, repository_url, verbose);
81  } else { // subscribe
82  std::string topic = *args.find('t')->second;
83  bool continuous = args.count('c') > 0;
84  const uint64_t revision = GetMinRevision(args);
85  ret = notify::DoSubscribe(server_url, topic, revision, continuous, verbose);
86  }
87 
88  return ret;
89 }
90 
91 } // namespace swissknife
static Parameter Optional(const char key, const std::string &desc)
Definition: swissknife.h:41
static Parameter Switch(const char key, const std::string &desc)
Definition: swissknife.h:44
std::vector< Parameter > ParameterList
Definition: swissknife.h:71
int DoSubscribe(const std::string &server_url, const std::string &repo, uint64_t min_revision, bool continuous, bool verbose)
Definition: cmd_sub.cc:149
int DoPublish(const std::string &server_url, const std::string &repository_url, bool verbose)
Definition: cmd_pub.cc:33
static Parameter Mandatory(const char key, const std::string &desc)
Definition: swissknife.h:38
virtual int Main(const ArgumentList &args)
std::map< char, SharedPtr< std::string > > ArgumentList
Definition: swissknife.h:72
virtual ParameterList GetParams() const
bool ValidateArgs(const swissknife::ArgumentList &args)
uint64_t GetMinRevision(const swissknife::ArgumentList &args)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:528