ARC SDK
DTR.h
1 // Summary page of data staging for doxygen
2 namespace DataStaging {
47 } // namespace DataStaging
48 
49 #ifndef DTR_H_
50 #define DTR_H_
51 
52 #include <arc/data/DataHandle.h>
53 #include <arc/CheckSum.h>
54 #include <arc/data/URLMap.h>
55 #include <arc/DateTime.h>
56 #include <arc/Logger.h>
57 #include <arc/User.h>
58 #include <arc/UserConfig.h>
59 #include <arc/Thread.h>
60 #include "DTRStatus.h"
61 
62 #ifdef WIN32
63 #ifndef uid_t
64 #define uid_t int
65 #endif
66 #ifndef gid_t
67 #define gid_t int
68 #endif
69 #endif
70 
72 namespace DataStaging {
73 
74  class DTR;
75 
77 
79 
81 
83 
85 
92  };
93 
95 
96  enum ProcessState {
101  };
102 
104 
109  public:
111 
115  unsigned long long int min_average_bandwidth;
117 
120  unsigned int max_inactivity_time;
122 
127  unsigned long long int min_current_bandwidth;
129  unsigned int averaging_time;
133  };
134 
136 
141  public:
143  std::vector<std::string> cache_dirs;
145  std::vector<std::string> remote_cache_dirs;
147  std::vector<std::string> drain_cache_dirs;
151  DTRCacheParameters(std::vector<std::string> caches,
152  std::vector<std::string> remote_caches,
153  std::vector<std::string> drain_caches);
154  };
155 
157 
158  enum CacheState {
166  };
167 
169 
177  class DTRCallback {
178  public:
180  virtual ~DTRCallback() {};
182 
186  virtual void receiveDTR(DTR_ptr dtr) = 0;
187  // TODO
188  //virtual void suspendDTR(DTR& dtr) = 0;
189  //virtual void cancelDTR(DTR& dtr) = 0;
190  };
191 
193 
212  class DTR {
213 
214  private:
216  std::string DTR_ID;
217 
219  Arc::URL source_url;
220  Arc::URL destination_url;
221  Arc::UserConfig cfg;
222 
224  Arc::DataHandle source_endpoint;
226  Arc::DataHandle destination_endpoint;
227 
229  std::string source_url_str;
231  std::string destination_url_str;
232 
234  /* Kept as string so we don't need to duplicate DataHandle properties
235  * of destination. Delivery should check if this is set and if so use
236  * it as destination. */
237  std::string cache_file;
238 
240  DTRCacheParameters cache_parameters;
241 
243  CacheState cache_state;
244 
246  Arc::User user;
247 
250  bool rfc_proxy;
251 
253  std::string parent_job_id;
254 
256  int priority;
257 
259  std::string transfershare;
260 
262 
265  std::string sub_share;
266 
268  unsigned int tries_left;
269 
271  unsigned int initial_tries;
272 
274  bool replication;
275 
277 
281  bool force_registration;
282 
284 
285  std::string mapped_source;
286 
288  DTRStatus status;
289 
291  DTRErrorStatus error_status;
292 
294  unsigned long long int bytes_transferred; // TODO and/or offset?
295 
297 
298  Arc::Time timeout;
300  Arc::Time created;
302  Arc::Time last_modified;
304  Arc::Time next_process_time;
305 
307  bool cancel_request;
308 
310  bool bulk_start;
312  bool bulk_end;
314  bool source_supports_bulk;
315 
317 
318  Arc::URL delivery_endpoint;
319 
321  std::vector<Arc::URL> problematic_delivery_endpoints;
322 
324  bool use_host_cert_for_remote_delivery;
325 
327  StagingProcesses current_owner;
328 
330 
332  DTRLogger logger;
333 
335 
338  std::list<Arc::LogDestination*> log_destinations;
339 
341  std::map<StagingProcesses,std::list<DTRCallback*> > proc_callback;
342 
345 
349 
352 
356  /* Methods */
358  void mark_modification () { last_modified.SetTime(time(NULL)); };
359 
361  std::list<DTRCallback*> get_callbacks(const std::map<StagingProcesses, std::list<DTRCallback*> >& proc_callback,
362  StagingProcesses owner);
363 
365  DTR& operator=(const DTR& dtr);
366  DTR(const DTR& dtr);
367  DTR();
368 
369 
370  public:
371 
373  static const Arc::URL LOCAL_DELIVERY;
374 
377 
379 
390  DTR(const std::string& source,
391  const std::string& destination,
392  const Arc::UserConfig& usercfg,
393  const std::string& jobid,
394  const uid_t& uid,
395  DTRLogger log);
396 
398  ~DTR() {};
399 
401  operator bool() const {
402  return (!DTR_ID.empty());
403  }
405  bool operator!() const {
406  return (DTR_ID.empty());
407  }
408 
410 
416 
418 
421  void reset();
422 
424  void set_id(const std::string& id);
426  std::string get_id() const { return DTR_ID; };
428  std::string get_short_id() const;
429 
431  Arc::DataHandle& get_source() { return source_endpoint; };
433  Arc::DataHandle& get_destination() { return destination_endpoint; };
434 
436  std::string get_source_str() const { return source_url_str; };
438  std::string get_destination_str() const { return destination_url_str; };
439 
441  const Arc::UserConfig& get_usercfg() const { return cfg; };
442 
444  void set_timeout(time_t value) { timeout.SetTime(Arc::Time().GetTime() + value); };
446  Arc::Time get_timeout() const { return timeout; };
447 
449  void set_process_time(const Arc::Period& process_time);
451  Arc::Time get_process_time() const { return next_process_time; };
452 
454  Arc::Time get_creation_time() const { return created; };
455 
457  Arc::Time get_modification_time() const { return last_modified; };
458 
460  std::string get_parent_job_id() const { return parent_job_id; };
461 
463  void set_priority(int pri);
465  int get_priority() const { return priority; };
466 
468  void set_rfc_proxy(bool rfc) { rfc_proxy = rfc; };
470  bool is_rfc_proxy() const { return rfc_proxy; };
471 
473  void set_transfer_share(const std::string& share_name);
475  std::string get_transfer_share() const { return transfershare; };
476 
478  void set_sub_share(const std::string& share) { sub_share = share; };
480  std::string get_sub_share() const { return sub_share; };
481 
483  void set_tries_left(unsigned int tries);
485  unsigned int get_tries_left() const { return tries_left; };
487  unsigned int get_initial_tries() const { return initial_tries; }
489  void decrease_tries_left();
490 
492  void set_status(DTRStatus stat);
495 
497 
503  const std::string& desc="");
505  void reset_error_status();
508 
510  void set_bytes_transferred(unsigned long long int bytes);
512  unsigned long long int get_bytes_transferred() const { return bytes_transferred; };
513 
515  void set_cancel_request();
517  bool cancel_requested() const { return cancel_request; };
518 
520  void set_delivery_endpoint(const Arc::URL& endpoint) { delivery_endpoint = endpoint; };
522  const Arc::URL& get_delivery_endpoint() const { return delivery_endpoint; };
523 
525 
529  void add_problematic_delivery_service(const Arc::URL& endpoint) { problematic_delivery_endpoints.push_back(endpoint); };
531  const std::vector<Arc::URL>& get_problematic_delivery_services() const { return problematic_delivery_endpoints; };
532 
534  void host_cert_for_remote_delivery(bool host) { use_host_cert_for_remote_delivery = host; };
536  bool host_cert_for_remote_delivery() const { return use_host_cert_for_remote_delivery; };
537 
539  void set_cache_file(const std::string& filename);
541  std::string get_cache_file() const { return cache_file; };
542 
544  void set_cache_parameters(const DTRCacheParameters& param) { cache_parameters = param; };
546  const DTRCacheParameters& get_cache_parameters() const { return cache_parameters; };
547 
549  void set_cache_state(CacheState state);
551  CacheState get_cache_state() const { return cache_state; };
552 
554  void set_mapped_source(const std::string& file = "") { mapped_source = file; };
556  std::string get_mapped_source() const { return mapped_source; };
557 
559  StagingProcesses get_owner() const { return current_owner; };
560 
562  Arc::User get_local_user() const { return user; };
563 
565  void set_replication(bool rep) { replication = rep; };
567  bool is_replication() const { return replication; };
569  void set_force_registration(bool force) { force_registration = force; };
571  bool is_force_registration() const { return force_registration; };
572 
574  void set_bulk_start(bool value) { bulk_start = value; };
576  bool get_bulk_start() const { return bulk_start; };
578  void set_bulk_end(bool value) { bulk_end = value; };
580  bool get_bulk_end() const { return bulk_end; };
582  bool bulk_possible();
583 
585  const DTRLogger& get_logger() const { return logger; };
586 
588  void connect_logger() { if (logger) logger->setDestinations(log_destinations); };
590  void disconnect_logger() { if (logger) logger->removeDestinations(); };
591 
593  static void push(DTR_ptr dtr, StagingProcesses new_owner);
594 
596  bool suspend();
597 
599  bool error() const { return (error_status != DTRErrorStatus::NONE_ERROR); }
600 
602  bool is_destined_for_pre_processor() const;
604  bool is_destined_for_post_processor() const;
606  bool is_destined_for_delivery() const;
607 
609  bool came_from_pre_processor() const;
611  bool came_from_post_processor() const;
613  bool came_from_delivery() const;
615  bool came_from_generator() const;
617  bool is_in_final_state() const;
618  };
619 
621  DTR_ptr createDTRPtr(const std::string& source,
622  const std::string& destination,
623  const Arc::UserConfig& usercfg,
624  const std::string& jobid,
625  const uid_t& uid,
626  DTRLogger log);
627 
630  const std::string& subdomain);
631 
632 } // namespace DataStaging
633 #endif /*DTR_H_*/