ARC SDK
DTR.h
1 // Summary page of data staging for doxygen
2 namespace DataStaging {
37 } // namespace DataStaging
38 
39 #ifndef DTR_H_
40 #define DTR_H_
41 
42 #include <arc/data/DataHandle.h>
43 #include <arc/CheckSum.h>
44 #include <arc/data/URLMap.h>
45 #include <arc/DateTime.h>
46 #include <arc/Logger.h>
47 #include <arc/User.h>
48 #include <arc/UserConfig.h>
49 #include <arc/Thread.h>
50 #include "DTRStatus.h"
51 
52 #ifdef WIN32
53 #ifndef uid_t
54 #define uid_t int
55 #endif
56 #ifndef gid_t
57 #define gid_t int
58 #endif
59 #endif
60 
62 namespace DataStaging {
63 
64  class DTR;
65 
67 
69 
71 
73 
75 
82  };
83 
85 
86  enum ProcessState {
91  };
92 
94 
99  public:
101 
105  unsigned long long int min_average_bandwidth;
107 
110  unsigned int max_inactivity_time;
112 
117  unsigned long long int min_current_bandwidth;
119  unsigned int averaging_time;
123  };
124 
126 
131  public:
133  std::vector<std::string> cache_dirs;
135  std::vector<std::string> remote_cache_dirs;
137  std::vector<std::string> drain_cache_dirs;
141  DTRCacheParameters(std::vector<std::string> caches,
142  std::vector<std::string> remote_caches,
143  std::vector<std::string> drain_caches);
144  };
145 
147 
148  enum CacheState {
156  };
157 
159 
167  class DTRCallback {
168  public:
170  virtual ~DTRCallback() {};
172 
176  virtual void receiveDTR(DTR_ptr dtr) = 0;
177  // TODO
178  //virtual void suspendDTR(DTR& dtr) = 0;
179  //virtual void cancelDTR(DTR& dtr) = 0;
180  };
181 
183 
202  class DTR {
203 
204  private:
206  std::string DTR_ID;
207 
209  Arc::URL source_url;
210  Arc::URL destination_url;
211  Arc::UserConfig cfg;
212 
214  Arc::DataHandle source_endpoint;
216  Arc::DataHandle destination_endpoint;
217 
219  std::string source_url_str;
221  std::string destination_url_str;
222 
224  /* Kept as string so we don't need to duplicate DataHandle properties
225  * of destination. Delivery should check if this is set and if so use
226  * it as destination. */
227  std::string cache_file;
228 
230  DTRCacheParameters cache_parameters;
231 
233  CacheState cache_state;
234 
236  Arc::User user;
237 
240  bool rfc_proxy;
241 
243  std::string parent_job_id;
244 
246  int priority;
247 
249  std::string transfershare;
250 
252 
255  std::string sub_share;
256 
258  unsigned int tries_left;
259 
261  unsigned int initial_tries;
262 
264  bool replication;
265 
267 
271  bool force_registration;
272 
274 
275  std::string mapped_source;
276 
278  DTRStatus status;
279 
281  DTRErrorStatus error_status;
282 
284  unsigned long long int bytes_transferred; // TODO and/or offset?
285 
287 
288  Arc::Time timeout;
290  Arc::Time created;
292  Arc::Time last_modified;
294  Arc::Time next_process_time;
295 
297  bool cancel_request;
298 
300  bool bulk_start;
302  bool bulk_end;
304  bool source_supports_bulk;
305 
307 
308  Arc::URL delivery_endpoint;
309 
311  std::vector<Arc::URL> problematic_delivery_endpoints;
312 
314  bool use_host_cert_for_remote_delivery;
315 
317  StagingProcesses current_owner;
318 
320 
322  DTRLogger logger;
323 
325 
328  std::list<Arc::LogDestination*> log_destinations;
329 
331  std::map<StagingProcesses,std::list<DTRCallback*> > proc_callback;
332 
335 
339 
342 
346  /* Methods */
348  void mark_modification () { last_modified.SetTime(time(NULL)); };
349 
351  std::list<DTRCallback*> get_callbacks(const std::map<StagingProcesses, std::list<DTRCallback*> >& proc_callback,
352  StagingProcesses owner);
353 
355  DTR& operator=(const DTR& dtr);
356  DTR(const DTR& dtr);
357  DTR();
358 
359 
360  public:
361 
363  static const Arc::URL LOCAL_DELIVERY;
364 
367 
369 
380  DTR(const std::string& source,
381  const std::string& destination,
382  const Arc::UserConfig& usercfg,
383  const std::string& jobid,
384  const uid_t& uid,
385  DTRLogger log);
386 
388  ~DTR() {};
389 
391  operator bool() const {
392  return (!DTR_ID.empty());
393  }
395  bool operator!() const {
396  return (DTR_ID.empty());
397  }
398 
400 
406 
408 
411  void reset();
412 
414  void set_id(const std::string& id);
416  std::string get_id() const { return DTR_ID; };
418  std::string get_short_id() const;
419 
421  Arc::DataHandle& get_source() { return source_endpoint; };
423  Arc::DataHandle& get_destination() { return destination_endpoint; };
424 
426  std::string get_source_str() const { return source_url_str; };
428  std::string get_destination_str() const { return destination_url_str; };
429 
431  const Arc::UserConfig& get_usercfg() const { return cfg; };
432 
434  void set_timeout(time_t value) { timeout.SetTime(Arc::Time().GetTime() + value); };
436  Arc::Time get_timeout() const { return timeout; };
437 
439  void set_process_time(const Arc::Period& process_time);
441  Arc::Time get_process_time() const { return next_process_time; };
442 
444  Arc::Time get_creation_time() const { return created; };
445 
447  Arc::Time get_modification_time() const { return last_modified; };
448 
450  std::string get_parent_job_id() const { return parent_job_id; };
451 
453  void set_priority(int pri);
455  int get_priority() const { return priority; };
456 
458  void set_rfc_proxy(bool rfc) { rfc_proxy = rfc; };
460  bool is_rfc_proxy() const { return rfc_proxy; };
461 
463  void set_transfer_share(const std::string& share_name);
465  std::string get_transfer_share() const { return transfershare; };
466 
468  void set_sub_share(const std::string& share) { sub_share = share; };
470  std::string get_sub_share() const { return sub_share; };
471 
473  void set_tries_left(unsigned int tries);
475  unsigned int get_tries_left() const { return tries_left; };
477  unsigned int get_initial_tries() const { return initial_tries; }
479  void decrease_tries_left();
480 
482  void set_status(DTRStatus stat);
485 
487 
493  const std::string& desc="");
495  void reset_error_status();
498 
500  void set_bytes_transferred(unsigned long long int bytes);
502  unsigned long long int get_bytes_transferred() const { return bytes_transferred; };
503 
505  void set_cancel_request();
507  bool cancel_requested() const { return cancel_request; };
508 
510  void set_delivery_endpoint(const Arc::URL& endpoint) { delivery_endpoint = endpoint; };
512  const Arc::URL& get_delivery_endpoint() const { return delivery_endpoint; };
513 
515 
519  void add_problematic_delivery_service(const Arc::URL& endpoint) { problematic_delivery_endpoints.push_back(endpoint); };
521  const std::vector<Arc::URL>& get_problematic_delivery_services() const { return problematic_delivery_endpoints; };
522 
524  void host_cert_for_remote_delivery(bool host) { use_host_cert_for_remote_delivery = host; };
526  bool host_cert_for_remote_delivery() const { return use_host_cert_for_remote_delivery; };
527 
529  void set_cache_file(const std::string& filename);
531  std::string get_cache_file() const { return cache_file; };
532 
534  void set_cache_parameters(const DTRCacheParameters& param) { cache_parameters = param; };
536  const DTRCacheParameters& get_cache_parameters() const { return cache_parameters; };
537 
539  void set_cache_state(CacheState state);
541  CacheState get_cache_state() const { return cache_state; };
542 
544  void set_mapped_source(const std::string& file = "") { mapped_source = file; };
546  std::string get_mapped_source() const { return mapped_source; };
547 
549  StagingProcesses get_owner() const { return current_owner; };
550 
552  Arc::User get_local_user() const { return user; };
553 
555  void set_replication(bool rep) { replication = rep; };
557  bool is_replication() const { return replication; };
559  void set_force_registration(bool force) { force_registration = force; };
561  bool is_force_registration() const { return force_registration; };
562 
564  void set_bulk_start(bool value) { bulk_start = value; };
566  bool get_bulk_start() const { return bulk_start; };
568  void set_bulk_end(bool value) { bulk_end = value; };
570  bool get_bulk_end() const { return bulk_end; };
572  bool bulk_possible();
573 
575  const DTRLogger& get_logger() const { return logger; };
576 
578  void connect_logger() { if (logger) logger->setDestinations(log_destinations); };
580  void disconnect_logger() { if (logger) logger->removeDestinations(); };
581 
583  static void push(DTR_ptr dtr, StagingProcesses new_owner);
584 
586  bool suspend();
587 
589  bool error() const { return (error_status != DTRErrorStatus::NONE_ERROR); }
590 
592  bool is_destined_for_pre_processor() const;
594  bool is_destined_for_post_processor() const;
596  bool is_destined_for_delivery() const;
597 
599  bool came_from_pre_processor() const;
601  bool came_from_post_processor() const;
603  bool came_from_delivery() const;
605  bool came_from_generator() const;
607  bool is_in_final_state() const;
608  };
609 
611  DTR_ptr createDTRPtr(const std::string& source,
612  const std::string& destination,
613  const Arc::UserConfig& usercfg,
614  const std::string& jobid,
615  const uid_t& uid,
616  DTRLogger log);
617 
620  const std::string& subdomain);
621 
622 } // namespace DataStaging
623 #endif /*DTR_H_*/