Back to index

nordugrid-arc-nox  1.1.0~rc6
client.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <arc/Logger.h>
00006 #include <arc/message/MCC.h>
00007 
00008 #include "client.h"
00009 
00010 #define olog (std::cerr)
00011 #define odlog(LEVEL) (std::cerr)
00012  
00013 namespace ARex {
00014 
00015 LoggerClient::LoggerClient(void):client(NULL) {
00016 }
00017 
00018 LoggerClient::~LoggerClient(void) {
00019   if(client) delete client;
00020 }
00021 
00022 bool LoggerClient::Initialized(void) {
00023   return (client != NULL);
00024 }
00025 
00026 bool LoggerClient::SameContact(const char* url_) {
00027   if(!url) return false;
00028   try {
00029     Arc::URL u(url_);
00030     return((u.Protocol() == url.Protocol()) && 
00031            (u.Host() == url.Host()) && 
00032            (u.Port() == url.Port()));
00033   } catch (std::exception e) {
00034     return false;
00035   };
00036 }
00037 
00038 bool LoggerClient::NewURL(const char* url_) {
00039   if(url_ == NULL) return false;
00040   try {
00041     if(url) {
00042       Arc::URL u(url_);
00043       if((u.Protocol() == url.Protocol()) &&
00044          (u.Host() == url.Host()) &&
00045          (u.Port() == url.Port()) &&
00046          (u.Path() == url.Path())) {
00047         url=u;
00048       } else { // reinitialize for different server
00049         url=u; if(client) delete client; client=NULL;
00050       };
00051     } else { // initialize for first connection
00052       url=Arc::URL(url_); if(client) delete client; client=NULL;
00053     };
00054   } catch (std::exception e) {
00055     if(client) delete client; client=NULL;
00056     return false;
00057   };
00058   if(client == NULL) {
00059 //    std::string soap_url = url->Protocol()+"://"+url->Host()+":"+tostring(url->Port());
00060     Arc::MCCConfig cfg;
00061     client = new Arc::ClientSOAP(cfg,url,60);
00062   };
00063   return true;
00064 }
00065 
00066 bool LoggerClient::ReportV2(const char* url_,std::list<JobRecord>& info) {
00067   if(!NewURL(url_)) return false;
00068   if(info.size() <= 0) return true;
00069   Arc::NS ns;
00070   ns[""]="http://www.nordugrid.org/ws/schemas/ARCLoggerV2";
00071   Arc::PayloadSOAP req(ns);
00072   req.NewChild("add");
00073   for(std::list<JobRecord>::iterator i = info.begin();i!=info.end();++i) {
00074     req.NewChild(*i);
00075   };
00076 Arc::Logger::rootLogger.setThreshold(Arc::DEBUG);
00077   Arc::PayloadSOAP* resp = NULL;
00078   Arc::MCC_Status r = client->process(&req,&resp);
00079 Arc::Logger::rootLogger.setThreshold(Arc::WARNING);
00080   if((!r) || (!resp)) {
00081     odlog(INFO)<<"Failed to pass information to database"<<std::endl;
00082 //    if(LogTime::Level() > FATAL) soap_print_fault(&soap, stderr);
00083 //    client->disconnect();
00084     return false;;
00085   } else if( (!((*resp)["addResponse"]["result"])) ||
00086              (!((*resp)["addResponse"]["result"]["Code"])) ) {
00087     std::string s; resp->Child().GetXML(s);
00088     if(s.empty()) {
00089       odlog(INFO)<<"Record refused."<<std::endl;
00090     } else {
00091       odlog(INFO)<<"Record refused. Response: "<<s<<std::endl;
00092     };
00093     return false;
00094   } else if((*resp)["addResponse"]["result"]["Code"] != "NoError") {
00095     odlog(INFO)<<"Record refused. Error code: "<<(*resp)["addResponse"]["result"]["Code"]<<std::endl;
00096     return false;
00097   };
00098   return true;
00099 }
00100 /*
00101 bool LoggerClient::Report(const char* url_,std::list<nl2__UsageRecord>& info) {
00102   // Try V2, if it fails try V1
00103   if(ReportV2(url_,info)) return true;
00104   return ReportV1(url_,info);
00105 }
00106 */
00107 
00108 }
00109