Back to index

nordugrid-arc-nox  1.1.0~rc6
janitorClient.cpp
Go to the documentation of this file.
00001 #include <arc/ArcConfig.h>
00002 #include <arc/ArcLocation.h>
00003 #include <arc/client/ClientInterface.h>
00004 #include <arc/message/MCCLoader.h>
00005 #include <arc/message/MCC.h>
00006 
00007 #include <iostream>
00008 #include <string>
00009 #include <fstream>
00010 
00011 using namespace Arc;
00012 
00021 static int printhelp() {
00022        printf("Usage:\n");
00023        printf("\n");
00024        printf("  janitor [config-file] [command] [arg0] [arg1] [arg2] ...\n");
00025        printf("\n");
00026        printf("config-file   - specifies the URL and the security attributes.\n");
00027        printf("                \n");
00028        printf("command       - REGISTER [jobid] [rte0] [rte1] ...\n");
00029        printf("                DEPLOY   [jobid]\n");
00030        printf("                REMOVE   [jobid]\n");
00031        printf("                INFO     [jobid]\n");
00032        printf("                LIST\n");
00033        printf("                SETSTATE [newstate] [rte0] [rte1] ...\n");
00034        printf("                SEARCH   [string] [string] ...\n");
00035        printf("\n");
00036        printf("Examples:\n");
00037        printf("\n");
00038        printf("  janitor REGISTER 1919 APPS/BIO/GRID ENV/JAVA/JRE1.5\n");
00039        printf("  janitor DEPLOY 1919\n");
00040        printf("  janitor INFO 1919\n");
00041        printf("  janitor REMOVE 1919\n");
00042        printf("  janitor SETSTATE REMOVAL_PENDING ENV/JAVA/JRE1.5\n");
00043        printf("\n");
00044        return -1;
00045 }
00046 
00047 int main(int argc, char** argv) {
00048 
00049        std::string command;
00050        std::string jobid;
00051        std::string newstate;
00052        std::vector <std::string> rtes;
00053 
00054        if(2 >= argc){
00055               printf("Not enough arguments.\n\n",argv[1]);
00056               return(printhelp());
00057        }
00058 
00059        // argc >= 3
00060 
00062        std::string xmlstring;
00063        std::ifstream file(argv[1]);
00064        if (!file.good())
00065        {
00066               printf("File %s not found.\n\n",argv[1]);
00067               return(printhelp());
00068        }
00069 
00070        // file.good() is true
00071 
00072        printf("Reading XML configuration from %s\n",argv[1]);
00073        file.seekg(0,std::ios::end);
00074        std::ifstream::pos_type size = file.tellg();
00075        file.seekg(0,std::ios::beg);
00076        std::ifstream::char_type *buf = new std::ifstream::char_type[size];
00077        file.read(buf,size);
00078        xmlstring = buf;
00079        delete []buf; 
00080        file.close(); 
00081 
00082        command.assign(argv[2]);
00083 
00084        std::string commands[] = {  std::string("REGISTER"),
00085                                    std::string("DEPLOY"),
00086                                    std::string("REMOVE"),
00087                                    std::string("INFO"),
00088                                    std::string("LIST"),
00089                                    std::string("SETSTATE"),
00090                                    std::string("SEARCH") };
00091 
00092        // find  position of string that matches argument
00093        unsigned n;
00094        for(n = 0; n < 7 && strncmp(commands[n].c_str(), command.c_str(),8); n++); 
00095        printf("Found command #%d.\n",n);
00096                      
00097        switch(n) {
00098        case 0: // REGISTER
00099               if(argc > 3){
00100                      jobid.assign(argv[3]);
00101                      for(int i = 4; i < argc; i++){
00102                             rtes.push_back(std::string(argv[i]));
00103                      }
00104               }else{
00105                      printf("Jobid was not specified, missing argument.\n\n");
00106                      return(printhelp()); 
00107               }
00108               break;
00109        case 1: // DEPLOY
00110        case 2: // REMOVE
00111        case 3: // INFO      - they all expect a single job id
00112               if(argc < 4){
00113                      printf("Jobid was not specified, missing argument.\n\n");
00114                      return(printhelp()); 
00115               }else if (argc > 4) {
00116                      printf("Too many jobids specified, no more than one accepted.\n\n");
00117                      return(printhelp()); 
00118               }else{
00119                      jobid.assign(argv[3]);
00120               }
00121               break;
00122        case 4: // LIST - takes no arguments
00123               break;
00124        case 5: // SETSTATE
00125               if(argc > 3){
00126                      newstate.assign(argv[3]);
00127                      for(int i = 4; i < argc; i++){
00128                             rtes.push_back(std::string(argv[i]));
00129                      }
00130               }else{
00131                      printf("New state not specified, missing argument.\n\n");
00132                      return(printhelp()); 
00133               }
00134               break;
00135        case 6: // SEARCH
00136               for(int i = 3; i < argc; i++){
00137                      rtes.push_back(std::string(argv[i]));
00138               }
00139               break;
00140        default:
00141               printf("Unknown janitor command: '%s'\n\n",argv[2]);
00142               return(printhelp()); 
00143               break;
00144        };
00145 
00148        printf("Command:  %s\n",command.c_str());
00149        printf("jobid:    %s\n",jobid.c_str());
00150        printf("newstate  %s\n",newstate.c_str());
00151 
00152        for(int i=0;i < rtes.size(); i++)  {
00153               printf("RTE:      %s\n",rtes.at(i).c_str());
00154        }
00155 
00156         return 0; // program terminates successfully
00157 
00158        // Initiate the Logger and set it to the standard error stream
00159 /*     Arc::Logger logger(Arc::Logger::getRootLogger(), "arcecho");
00160        Arc::LogStream logcerr(std::cerr);
00161        Arc::Logger::getRootLogger().addDestination(logcerr);
00162        Arc::Logger::rootLogger.setThreshold(Arc::WARNING);
00163 
00164        // Set the ARC installation directory
00165        std::string arclib("/usr/lib/arc");
00166        Arc::ArcLocation::Init(arclib);  
00167 */
00169 /*     Arc::XMLNode clientXml(xmlstring);
00170        Arc::Config clientConfig(clientXml);
00171        if(!clientConfig) {
00172          logger.msg(Arc::ERROR, "Failed to load client configuration");
00173          return -1;
00174        };
00175 
00176        Arc::MCCLoader loader(clientConfig);
00177        logger.msg(Arc::INFO, "Client side MCCs are loaded");
00178        Arc::MCC* clientEntry = loader["soap"];
00179        if(!clientEntry) {
00180          logger.msg(Arc::ERROR, "Client chain does not have entry point");
00181          return -1;
00182        };
00183 */
00188 /*     Arc::NS ns("sececho", "urn:sececho");
00189        Arc::PayloadSOAP  request(ns);
00190        Arc::PayloadSOAP* response = NULL;
00191        
00192        // Due to the fact that the class ClientSOAP isn't used anymore,
00193        // one has to prepare the messages which envelope the payload oneself.
00194        Arc::Message reqmsg;
00195        Arc::Message repmsg;
00196        Arc::MessageAttributes attributes_req;
00197        Arc::MessageAttributes attributes_rep;
00198        Arc::MessageContext context;
00199        repmsg.Attributes(&attributes_rep);
00200        reqmsg.Attributes(&attributes_req);
00201        reqmsg.Context(&context);
00202        repmsg.Context(&context);  
00203 
00204        XMLNode sayNode = request.NewChild("sececho:secechoRequest").NewChild("sececho:say") = message;
00205        sayNode.NewAttribute("operation") = type;
00206        reqmsg.Payload(&request);
00207 */
00208        //(@*\drain{std::string xml;  request.GetXML(xml, true); printf("Request message:\n\%s\n\n\n", xml.c_str());/*Remove backslashes and drain*/}*@)
00209 /*     Arc::MCC_Status status = clientEntry->process(reqmsg,repmsg);
00210        response = dynamic_cast<Arc::PayloadSOAP*>(repmsg.Payload());
00211 */
00213 /*
00214        if (!response) {
00215               printf("No SOAP response");
00216               return 1;
00217        }else if(response->IsFault()){
00218               printf("A SOAP fault occured:\n");
00219         std::string hoff = (std::string) response->Fault()->Reason();
00220               printf("  Fault code:   %d\n", (response->Fault()->Code()));
00221               printf("  Fault string: \"%s\"\n", (response->Fault()->Reason()).c_str());
00222 */
00228               //(@*\drain{std::string xmlFault;response->GetXML(xmlFault, true);  printf("\%s\n\n", xmlFault.c_str());}*@)
00229 /*            std::string xmlFault;response->GetXML(xmlFault, true);  printf("\%s\n\n", xmlFault.c_str());
00230               return 1;
00231        }
00232 
00233        // Test for possible errors
00234        if (!status) {
00235               printf("Error %s",((std::string)status).c_str());
00236               if (response)
00237                      delete response;
00238               return 1;
00239        }
00240 */
00241        //(@*\drain{response->GetXML(xml, true);  printf("Response message:\n\%s\n\n\n", xml.c_str());/*Remove backslashes and drain*/}*@)
00242 /*
00243        std::string answer = (std::string)((*response)["sececho:secechoResponse"]["sececho:hear"]);
00244        std::cout << answer <<std::endl;
00245 
00246        delete response;
00247 */
00248 }
00249