Back to index

nordugrid-arc-nox  1.1.0~rc6
test_client.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <iostream>
00006 #include <signal.h>
00007 
00008 #include <arc/ArcConfig.h>
00009 #include <arc/Logger.h>
00010 #include <arc/message/MCCLoader.h>
00011 #include <arc/message/SOAPEnvelope.h>
00012 #include <arc/message/PayloadSOAP.h>
00013 #ifdef WIN32
00014 #include <arc/win32.h>
00015 #endif
00016 
00017 int main(void) {  
00018   signal(SIGTTOU,SIG_IGN);
00019   signal(SIGTTIN,SIG_IGN);
00020   Arc::Logger logger(Arc::Logger::rootLogger, "CompilerTest");
00021   Arc::LogStream logcerr(std::cerr);
00022   Arc::Logger::rootLogger.addDestination(logcerr);
00023   logger.msg(Arc::INFO, "Creating client side chain");
00024   // Create client chain
00025   Arc::XMLNode client_doc("\
00026     <ArcConfig\
00027       xmlns=\"http://www.nordugrid.org/schemas/ArcConfig/2007\"\
00028       xmlns:tcp=\"http://www.nordugrid.org/schemas/ArcMCCTCP/2007\">\
00029      <ModuleManager>\
00030         <Path>.libs/</Path>\
00031         <Path>../../hed/mcc/http/.libs/</Path>\
00032         <Path>../../hed/mcc/soap/.libs/</Path>\
00033         <Path>../../hed/mcc/tls/.libs/</Path>\
00034         <Path>../../hed/mcc/tcp/.libs/</Path>\
00035      </ModuleManager>\
00036      <Plugins><Name>mcctcp</Name></Plugins>\
00037      <Plugins><Name>mcctls</Name></Plugins>\
00038      <Plugins><Name>mcchttp</Name></Plugins>\
00039      <Plugins><Name>mccsoap</Name></Plugins>\
00040      <Chain>\
00041       <Component name='tcp.client' id='tcp'><tcp:Connect><tcp:Host>127.0.0.1</tcp:Host><tcp:Port>50000</tcp:Port></tcp:Connect></Component>\
00042       <Component name='http.client' id='http'><next id='tcp'/><Method>POST</Method><Endpoint>/compiler</Endpoint></Component>\
00043       <Component name='soap.client' id='soap' entry='soap'><next id='http'/></Component>\
00044      </Chain>\
00045     </ArcConfig>");
00046   Arc::Config client_config(client_doc);
00047   if(!client_config) {
00048     logger.msg(Arc::ERROR, "Failed to load client configuration");
00049     return -1;
00050   };
00051   Arc::MCCLoader client_loader(client_config);
00052   logger.msg(Arc::INFO, "Client side MCCs are loaded");
00053   Arc::MCC* client_entry = client_loader["soap"];
00054   if(!client_entry) {
00055     logger.msg(Arc::ERROR, "Client chain does not have entry point");
00056     return -1;
00057   };
00058 
00059   // Create and send compiler request
00060   logger.msg(Arc::INFO, "Creating and sending request");
00061   Arc::NS echo_ns; echo_ns["compiler"]="urn:compiler";
00062   Arc::PayloadSOAP req(echo_ns);
00063 
00064   Arc::XMLNode make = req.NewChild("compiler").NewChild("make");
00065   make.NewChild("name")="ez egy fordito service";       // only [a-z,A-Z] or [0-9]
00066   make.NewChild("compiler_type")="gcc";                  //make, gcc
00067   make.NewChild("makefile")="Makefile";                   //empty (then use the default makefile) or the other Makefile's name
00068   make.NewChild("download_place")="/home/niif/tmp/s/";
00069   make.NewChild("gcc_parameters")="";                    //-Wall -O2
00070   make.NewChild("gcc_sequence")="http://knowarc1.grid.niif.hu/storage/lista";
00071   make.NewChild("compressed")="yess";                    //yes or no
00072   make.NewChild("cpu_architecture")="sparc4";           // empty string or JSDL CPU architecture
00073   //make.NewChild("sourcefile")="http://knowarc1.grid.niif.hu/storage/proba.tar";
00074   //or
00075   make.NewChild("sourcefile")="http://knowarc1.grid.niif.hu/storage/compilerhez/Makefile";
00076   make.NewChild("sourcefile")="http://knowarc1.grid.niif.hu/storage/compilerhez/lib.cpp";
00077   make.NewChild("sourcefile")="http://knowarc1.grid.niif.hu/storage/compilerhez/lib.h";
00078   make.NewChild("sourcefile")="http://knowarc1.grid.niif.hu/storage/compilerhez/project.cpp";
00079   
00080   Arc::Message reqmsg;
00081   Arc::Message repmsg;
00082   reqmsg.Payload(&req);
00083   // It is a responsibility of code initiating first Message to
00084   // provide Context and Attributes as well.
00085   Arc::MessageAttributes attributes_req;
00086   Arc::MessageAttributes attributes_rep;
00087   Arc::MessageContext context;
00088   reqmsg.Attributes(&attributes_req);
00089   reqmsg.Context(&context);
00090   repmsg.Attributes(&attributes_rep);
00091   repmsg.Context(&context);
00092 
00093   Arc::MCC_Status status;
00094   std::cout << " Job Submitted. Waiting to the request message." << std::endl;
00095   status= client_entry->process(reqmsg,repmsg);
00096   
00097   if(!status) {
00098     logger.msg(Arc::ERROR, "Request failed");
00099     std::cerr << "Status: " << std::string(status) << std::endl;
00100     return -1;
00101   };
00102   
00103   Arc::PayloadSOAP* resp = NULL;
00104   if(repmsg.Payload() == NULL) {
00105     logger.msg(Arc::ERROR, "There is no response");
00106     return -1;
00107   };
00108   try {
00109     resp = dynamic_cast<Arc::PayloadSOAP*>(repmsg.Payload());
00110   } catch(std::exception&) { };
00111   if(resp == NULL) {
00112     logger.msg(Arc::ERROR, "Response is not SOAP");
00113     return -1;
00114   };
00115   std::string xml;
00116   resp->GetDoc(xml, true);
00117   std::cout << "XML: "<< xml << std::endl;
00118   std::string response;
00119   int i=0;
00120   while ( (*resp)["compilerResponse"]["response"][i] != false ){
00121               response += (std::string)((*resp)["compilerResponse"]["response"][i]);
00122               response +="\n";
00123               i++;         
00124   }
00125   
00126    std::cout << "Response: " <<response << std::endl;
00127  
00128   return 0;
00129 }