Back to index

nordugrid-arc-nox  1.1.0~rc6
SRMClient.h
Go to the documentation of this file.
00001 #ifndef __HTTPSD_SRM_CLIENT_H__
00002 #define __HTTPSD_SRM_CLIENT_H__
00003 
00004 #include <string>
00005 #include <sstream>
00006 #include <list>
00007 #include <exception>
00008 
00009 #include <arc/Logger.h>
00010 
00011 #include "../https/HTTPSClient.h"
00012 
00013 #include "SRMURL.h"
00014 
00015 //namespace Arc {
00016   
00020   enum SRMVersion {
00021     SRM_V1,
00022     SRM_V2_2,
00023     SRM_VNULL,
00024   };
00025   
00029   enum SRMReturnCode {
00030     SRM_OK,
00031     SRM_ERROR_CONNECTION,
00032     SRM_ERROR_SOAP,
00033     // the next two only apply to valid repsonses from the service 
00034     SRM_ERROR_TEMPORARY, // eg SRM_INTERNAL_ERROR, SRM_FILE_BUSY
00035     SRM_ERROR_PERMANENT, // eg no such file, permission denied
00036     SRM_ERROR_NOT_SUPPORTED, // not supported by this version of the protocol
00037     SRM_ERROR_OTHER, // eg bad input parameters, unexpected result format
00038   };
00039   
00043   enum SRMFileLocality {
00044     SRM_ONLINE,
00045     SRM_NEARLINE,
00046     SRM_UNKNOWN,
00047     SRM_STAGE_ERROR,
00048   };
00049    
00053   enum SRMRetentionPolicy {
00054     SRM_REPLICA,
00055     SRM_OUTPUT,
00056     SRM_CUSTODIAL,
00057     SRM_RETENTION_UNKNOWN,
00058   };
00059   
00063   enum SRMFileStorageType {
00064     SRM_VOLATILE,
00065     SRM_DURABLE,
00066     SRM_PERMANENT,
00067     SRM_FILE_STORAGE_UNKNOWN,
00068   };
00069   
00073   enum SRMFileType {
00074     SRM_FILE,
00075     SRM_DIRECTORY,
00076     SRM_LINK,
00077     SRM_FILE_TYPE_UNKNOWN
00078   };
00079   
00083   enum SRMImplementation {
00084     SRM_IMPLEMENTATION_DCACHE,
00085     SRM_IMPLEMENTATION_CASTOR,
00086     SRM_IMPLEMENTATION_DPM,
00087     SRM_IMPLEMENTATION_STORM,
00088     SRM_IMPLEMENTATION_UNKNOWN,
00089   };
00090   
00094   struct SRMFileMetaData {
00095     std::string path;   // absolute dir and file path
00096     long long int size;
00097     time_t createdAtTime;
00098     time_t lastModificationTime;
00099     std::string checkSumType;
00100     std::string checkSumValue;
00101     SRMFileLocality fileLocality;
00102     SRMRetentionPolicy retentionPolicy;
00103     SRMFileStorageType fileStorageType;
00104     SRMFileType fileType;
00105     std::string arrayOfSpaceTokens;
00106     std::string owner;
00107     std::string group;
00108     std::string permission;
00109     int lifetimeLeft; // on the SURL    
00110     int lifetimeAssigned;
00111   };
00112   
00113   class SRMInvalidRequestException: public std::exception {};
00114   
00118   enum SRMRequestStatus {
00119     SRM_REQUEST_ONGOING,
00120     SRM_REQUEST_FINISHED_SUCCESS,
00121     SRM_REQUEST_FINISHED_PARTIAL_SUCCESS,
00122     SRM_REQUEST_FINISHED_ERROR,
00123     SRM_REQUEST_SHOULD_ABORT,
00124     SRM_REQUEST_CANCELLED,
00125   };
00126   
00132   class SRMClientRequest {
00133   
00134    private:
00135   
00139     std::map<std::string, SRMFileLocality> _surls;
00140   
00144     int _request_id;
00145   
00149     std::string _request_token;
00150   
00154     std::list<int> _file_ids;
00155   
00159     std::string _space_token;
00160   
00165     std::map<std::string, std::string> _surl_failures;
00166   
00171     int _waiting_time;
00172   
00176     SRMRequestStatus _status;
00177     
00181     bool _long_list;
00182     
00183    public:
00184     
00189     SRMClientRequest(std::list<std::string> urls) 
00190       throw (SRMInvalidRequestException):
00191       _space_token(""), 
00192       _waiting_time(1), 
00193       _status(SRM_REQUEST_ONGOING),
00194       _long_list(false) {
00195   
00196       if(urls.empty()) throw SRMInvalidRequestException();
00197       for (std::list<std::string>::iterator i = urls.begin();
00198          i != urls.end();
00199          ++i) _surls[*i] = SRM_UNKNOWN;
00200     };
00201     
00206     SRMClientRequest(std::string url="", std::string id="")
00207       throw (SRMInvalidRequestException):
00208       _space_token(""),
00209       _waiting_time(1),
00210       _status(SRM_REQUEST_ONGOING),
00211       _long_list(false) {
00212         
00213       if(url.compare("") == 0 && id.compare("") == 0) throw SRMInvalidRequestException();
00214       if(url.compare("") != 0) _surls[url] = SRM_UNKNOWN;
00215       else _request_token = (char*)id.c_str();
00216     };
00217   
00221     void request_id(int id) {_request_id = id;};
00222     int request_id() {return _request_id;};
00223     
00227     void request_token(char* token) {_request_token = token;};
00228     std::string request_token() {return _request_token;};
00229     
00233     void file_ids(std::list<int> ids) {_file_ids = ids;};
00234     std::list<int> file_ids() {return _file_ids;};
00235   
00239     void space_token(std::string token) {_space_token = token;};
00240     std::string space_token() {return _space_token;};
00241   
00245     std::list<std::string> surls() {
00246       std::list<std::string> surl_list;
00247       for (std::map<std::string,SRMFileLocality>::iterator it=_surls.begin() ; it != _surls.end(); it++ ) {
00248         surl_list.push_back((*it).first);
00249       };
00250       return surl_list;
00251     };
00252   
00256     void surl_statuses(std::string surl, SRMFileLocality locality) {_surls[surl] = locality;};
00257     std::map<std::string, SRMFileLocality> surl_statuses() {return _surls;};
00258   
00262     void surl_failures(std::string surl, std::string reason) {_surl_failures[surl] = reason;};
00263     std::map<std::string, std::string> surl_failures() {return _surl_failures;};
00264   
00268     void waiting_time(int wait_time) {_waiting_time = wait_time;};
00269     int waiting_time() {return _waiting_time;};
00270   
00274     void finished_success() {_status = SRM_REQUEST_FINISHED_SUCCESS;};
00275     void finished_partial_success() {_status = SRM_REQUEST_FINISHED_PARTIAL_SUCCESS;};
00276     void finished_error() {_status = SRM_REQUEST_FINISHED_ERROR;};
00277     void finished_abort() {_status = SRM_REQUEST_SHOULD_ABORT;};
00278     void cancelled() {_status = SRM_REQUEST_CANCELLED;};
00279     SRMRequestStatus status() {return _status;};
00280     
00284     void long_list(bool list) { _long_list = list; };
00285     bool long_list() { return _long_list; };
00286   };
00287   
00294   class SRMClient {
00295   
00296    protected:
00297   
00302     std::string service_endpoint;
00303   
00307     Arc::HTTPSClientSOAP * csoap;
00308   
00312     SRMImplementation implementation;
00313   
00317     static time_t request_timeout;
00318   
00322     std::string version;
00323     
00327     static Arc::Logger logger;
00328   
00329    public:
00330   
00335     SRMReturnCode connect(void);
00336   
00340     bool disconnect(void) { if(!csoap) return true; return (csoap->disconnect() == 0);};
00341   
00354     static SRMClient* getInstance(std::string url,
00355                                   bool& timedout,
00356                                   std::string utils_dir,
00357                                   time_t timeout=300);
00361     virtual ~SRMClient() {};
00362   
00366     void Timeout(int t) { request_timeout=t; };
00367   
00371     std::string getVersion() {return version;};
00372   
00383     virtual SRMReturnCode ping(std::string& version,
00384                                bool report_error = true) = 0;
00385   
00395     virtual SRMReturnCode getSpaceTokens(std::list<std::string>& tokens,
00396                                          std::string description = "") = 0;
00397   
00407     virtual SRMReturnCode getRequestTokens(std::list<std::string>& tokens,
00408                                            std::string description = "") = 0;
00409   
00410   
00418     virtual SRMReturnCode getTURLs(SRMClientRequest& req,
00419                                    std::list<std::string>& urls) = 0;
00420   
00429     virtual SRMReturnCode requestBringOnline(SRMClientRequest& req) = 0;
00430   
00437     virtual SRMReturnCode requestBringOnlineStatus(SRMClientRequest& req) = 0;
00438   
00447     virtual SRMReturnCode putTURLs(SRMClientRequest& req,
00448                                    std::list<std::string>& urls,
00449                                    unsigned long long size = 0) = 0;
00450   
00456     virtual SRMReturnCode releaseGet(SRMClientRequest& req) = 0;
00457   
00463     virtual SRMReturnCode releasePut(SRMClientRequest& req) = 0;
00464   
00470     virtual SRMReturnCode release(SRMClientRequest& req) = 0;
00471   
00478     virtual SRMReturnCode abort(SRMClientRequest& req) = 0;
00479   
00491     virtual SRMReturnCode info(SRMClientRequest& req,
00492                                std::list<struct SRMFileMetaData>& metadata,
00493                                const int recursive = 0,
00494                                bool report_error = true) = 0;
00495   
00501     virtual SRMReturnCode remove(SRMClientRequest& req) = 0;
00502   
00509     virtual SRMReturnCode copy(SRMClientRequest& req,
00510                                const std::string& source) = 0;
00511   
00517     virtual SRMReturnCode mkDir(SRMClientRequest& req) = 0;
00518 
00519     operator bool(void) { return csoap; };
00520     bool operator!(void) { return !csoap; };
00521   };
00522 
00523 //} // namespace Arc
00524   
00525 #endif // __HTTPSD_SRM_CLIENT_H__