1 | #include <iostream>
|
---|
2 | #include <dic.hxx>
|
---|
3 |
|
---|
4 | #include "Dim.h"
|
---|
5 | #include "Configuration.h"
|
---|
6 |
|
---|
7 | using namespace std;
|
---|
8 |
|
---|
9 | void SetupConfiguration(Configuration &conf)
|
---|
10 | {
|
---|
11 | po::options_description config("Configuration");
|
---|
12 | config.add_options()
|
---|
13 | ("dns", var<string>("localhost"), "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)")
|
---|
14 | ("schedule-database-name", var<string>(), "Database name for scheduling")
|
---|
15 | ;
|
---|
16 |
|
---|
17 | po::positional_options_description p;
|
---|
18 | p.add("schedule-database-name", 1); // The first positional options
|
---|
19 |
|
---|
20 | conf.AddEnv("dns", "DIM_DNS_NODE");
|
---|
21 | conf.AddOptions(config);
|
---|
22 | conf.SetArgumentPositions(p);
|
---|
23 | }
|
---|
24 |
|
---|
25 | void PrintUsage()
|
---|
26 | {
|
---|
27 | cout <<
|
---|
28 | "The triggerschedule triggers the scheduler.\n"
|
---|
29 | "\n"
|
---|
30 | "The default is that the program is started without user intercation. "
|
---|
31 | "All actions are supposed to arrive as DimCommands. Using the -c "
|
---|
32 | "option, a local shell can be initialized. With h or help a short "
|
---|
33 | "help message about the usuage can be brought to the screen.\n"
|
---|
34 | "\n"
|
---|
35 | "Usage: triggerschedule [-c type] [OPTIONS] <schedule-database-name>\n"
|
---|
36 | " or: triggerschedule [OPTIONS] <schedule-database-name>\n";
|
---|
37 | cout << endl;
|
---|
38 | }
|
---|
39 |
|
---|
40 | void PrintHelp()
|
---|
41 | {
|
---|
42 | cout <<
|
---|
43 | "\n"
|
---|
44 | "The method sendCommand(...) will wait for the command to "
|
---|
45 | "be actualy sent to the server and return a completion code "
|
---|
46 | "of:\n"
|
---|
47 | " 0 - if it was successfully sent.\n"
|
---|
48 | " 1 - if it couldn't be delivered.\n "
|
---|
49 | << endl;
|
---|
50 | /* Additional help text which is printed after the configuration
|
---|
51 | options goes here */
|
---|
52 | }
|
---|
53 |
|
---|
54 | int main(int argc, const char* argv[])
|
---|
55 | {
|
---|
56 | Configuration conf(argv[0]);
|
---|
57 | conf.SetPrintUsage(PrintUsage);
|
---|
58 | SetupConfiguration(conf);
|
---|
59 |
|
---|
60 | po::variables_map vm;
|
---|
61 | try
|
---|
62 | {
|
---|
63 | vm = conf.Parse(argc, argv);
|
---|
64 | }
|
---|
65 | #if BOOST_VERSION > 104000
|
---|
66 | catch (po::multiple_occurrences &e)
|
---|
67 | {
|
---|
68 | cout << "Error: " << e.what() << " of '" << e.get_option_name() << "' option." << endl;
|
---|
69 | cout << endl;
|
---|
70 | return -1;
|
---|
71 | }
|
---|
72 | #endif
|
---|
73 | catch (std::exception &e)
|
---|
74 | {
|
---|
75 | cout << "Error: " << e.what() << endl;
|
---|
76 | cout << endl;
|
---|
77 |
|
---|
78 | return -1;
|
---|
79 | }
|
---|
80 |
|
---|
81 | if (conf.HasVersion() || conf.HasPrint())
|
---|
82 | return -1;
|
---|
83 |
|
---|
84 | if (conf.HasHelp())
|
---|
85 | {
|
---|
86 | PrintHelp();
|
---|
87 | return -1;
|
---|
88 | }
|
---|
89 |
|
---|
90 | const string dbname = conf.Get<string>("schedule-database-name");
|
---|
91 |
|
---|
92 | Dim::Setup(conf.Get<string>("dns"));
|
---|
93 |
|
---|
94 | const int rc = DimClient::sendCommand("SCHEDULER/SCHEDULE", dbname.c_str());
|
---|
95 | if (!rc)
|
---|
96 | cerr << "Sending failed!" << endl;
|
---|
97 | else
|
---|
98 | cout << "Command issued successfully." << endl;
|
---|
99 |
|
---|
100 | return !rc;
|
---|
101 | }
|
---|