Changeset 10624


Ignore:
Timestamp:
May 8, 2011, 9:48:24 PM (8 years ago)
Author:
dorner
Message:
implemented --dbname and its evaluation for the scheduler
Location:
trunk/FACT++
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/Makefile.am

    r10608 r10624  
    229229scheduler_LDADD   = libStateMachine.la libTools.la libTime.la libDim.la libDim++.la libConfiguration.la
    230230
    231 sendcommand_SOURCES = src/sendcommand.cc
    232 sendcommand_LDADD   = libDim.la libDim++.la
     231sendcommand_SOURCES = src/sendcommand.cc 
     232sendcommand_LDADD   = libDim.la libDim++.la libConfiguration.la
    233233
    234234#fitsgrep_SOURCES = src/fitsgrep.cc
  • trunk/FACT++/src/scheduler.cc

    r10618 r10624  
    5858
    5959
    60 // config parameters
    61 // mintime
    62 // runtimec
    63 // runtimep
    64 // repostime
     60// config parameters:
     61//   mintime
     62//   runtimec
     63//   runtimep
     64//   repostime
    6565
    6666// missing:
     
    6969// calculate sun set/rise
    7070//
    71 // check for double std sources
    72 //
    73 // return errors
    74 // get input from sendcommand
     71// return errors and other otherput from sendcommand to webinterface
    7572
    7673// in which cases should the scheduler go in error state?
     
    173170
    174171    int fSessionId;
     172    string fDBName;
    175173
    176174
     
    189187        cout << "Scheduling for the period from " << startsched << " to " << stopsched << endl;
    190188
    191         stringstream str;
    192         str << "Scheduling started -> Preview (id=" << fSessionId << ")";
    193         T::Message(str);
    194 
    195189        static const boost::regex expr("(([[:word:].-]+)(:(.+))?@)?([[:word:].-]+)(:([[:digit:]]+))?(/([[:word:].-]+))");
    196190        // 2: user
     
    216210        const string passwd = what[4];
    217211        const string server = what[5];
    218         const string db     = what[9];
     212        string db = what[9];
     213        if (fDBName.size()!=0)
     214            db = fDBName;
    219215        const int port      = atoi(string(what[7]).c_str());
     216
     217        stringstream dbnamemsg;
     218        dbnamemsg << "Scheduling started -> using database " << fDBName << ".";
     219        T::Message(dbnamemsg);
    220220
    221221        cout << "Connecting to '";
     
    633633    */
    634634
    635     AutoScheduler(ostream &out=cout) : T(out, "SCHEDULER"), fNextIsPreview(true), fSessionId(-1)
     635    AutoScheduler(ostream &out=cout) : T(out, "SCHEDULER"), fNextIsPreview(true), fSessionId(-1), fDBName("")
    636636    {
    637637        AddStateName(kSM_Scheduling,  "Scheduling");
     
    662662        {
    663663        case kSM_Scheduling:
     664            if (evt.GetSize()>0)
     665                fDBName = evt.GetString();
    664666        //case kSM_Comitting:
    665667            //fSessionId = evt.GetInt();
     
    674676    }
    675677};
     678
    676679
    677680// ------------------------------------------------------------------------
     
    771774    }
    772775
    773     //if (conf.Has("mintime"))
    774     //    cout << "has mintime --------------------+" << conf.Get<int>("mintime")<< "+------------" << endl;
    775 
    776776    if (conf.Has("database"))
     777    {
    777778        database = conf.Get<string>("database").c_str();
     779    }
    778780    else
    779781    {
     
    781783        return -1;
    782784    }
    783 
    784785
    785786    if (conf.HasHelp() || conf.HasPrint())
  • trunk/FACT++/src/sendcommand.cc

    r10589 r10624  
    22#include <dic.hxx>
    33
     4#include "Configuration.h"
     5
    46using namespace std;
    57
    6 int main () {
    78
    8 int value;
    99
    10 value = DimClient::sendCommand("SCHEDULER/SCHEDULE", NULL, 0);
     10void SetupConfiguration(Configuration &conf)
     11{
     12    const string n = conf.GetName()+".log";
    1113
    12 cout << "\n";
    13 cout << " The method sendCommand(...) will wait for the command to be actualy sent to the Server and return a completion code of : " << endl;
    14 cout << "                                   1 - if it was successfully sent  " << endl;
    15 cout << "                                   0 - if it couldn't be delivered. " << endl;
     14    //po::options_description config("Program options");
     15    po::options_description config("Configuration");
     16    config.add_options()
     17        ("dns",       var<string>("localhost"),  "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)")
     18        ("log,l",     var<string>(n), "Write log-file")
     19        //("no-dim,d",  po_switch(),    "Disable dim services")
     20        //("console,c", var<int>(),     "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
     21        ("dbname",    var<string>(),      "database name for scheduling preview")
     22        ;
    1623
    17 cout << "\n";
    18 cout << " The completion code is now:       " << value << endl;
     24    conf.AddEnv("dns", "DIM_DNS_NODE");
    1925
    20 return 0;
     26    conf.AddOptions(config);
     27}
     28
     29
     30
     31int main(int argc, const char* argv[])
     32{
     33    Configuration conf(argv[0]);
     34    SetupConfiguration(conf);
     35
     36    po::variables_map vm;
     37    try
     38    {
     39        vm = conf.Parse(argc, argv);
     40    }
     41    catch (std::exception &e)
     42    {
     43#if BOOST_VERSION > 104000
     44        po::multiple_occurrences *MO = dynamic_cast<po::multiple_occurrences*>(&e);
     45        if (MO)
     46            cout << "Error: " << e.what() << " of '" << MO->get_option_name() << "' option." << endl;
     47        else
     48#endif
     49            cout << "Error: " << e.what() << endl;
     50        cout << endl;
     51
     52        return -1;
     53    }
     54
     55    const char* dbname;
     56    if (conf.Has("dbname"))
     57        dbname = conf.Get<string>("dbname").c_str();
     58    else
     59    {
     60        cout << "Please provide which database you want to use for scheduling using --dbname=<dbname>." << endl;
     61        return -1;
     62    }
     63
     64
     65    if (conf.HasHelp() || conf.HasPrint())
     66        return -1;
     67
     68    // To allow overwriting of DIM_DNS_NODE set 0 to 1
     69    setenv("DIM_DNS_NODE", conf.Get<string>("dns").c_str(), 1);
     70
     71//int main ()
     72//{
     73
     74    int value;
     75
     76    value = DimClient::sendCommand("SCHEDULER/SCHEDULE", dbname);
     77    //value = DimClient::sendCommand("SCHEDULER/SCHEDULE", NULL, 0);
     78
     79    cout << "\n";
     80    cout << " The method sendCommand(...) will wait for the command to be actualy sent to the Server and return a completion code of : " << endl;
     81    cout << "                                   1 - if it was successfully sent  " << endl;
     82    cout << "                                   0 - if it couldn't be delivered. " << endl;
     83
     84    cout << "\n";
     85    cout << " The completion code is now:       " << value << endl;
     86
     87    return 0;
    2188
    2289}
Note: See TracChangeset for help on using the changeset viewer.