source: trunk/FACT++/src/triggerschedule.cc @ 10683

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