CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
jobinfo.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_NETWORK_JOBINFO_H_
6 #define CVMFS_NETWORK_JOBINFO_H_
7 
8 #include <poll.h>
9 #include <pthread.h>
10 #include <stdint.h>
11 #include <unistd.h>
12 
13 #include <cstdio>
14 #include <map>
15 #include <set>
16 #include <string>
17 #include <vector>
18 
20 #include "crypto/hash.h"
21 #include "duplex_curl.h"
22 #include "network/network_errors.h"
23 #include "network/sink.h"
24 #include "network/sink_file.h"
25 #include "network/sink_mem.h"
26 #include "network/sink_path.h"
27 #include "util/pipe.h"
28 #include "util/tube.h"
29 
30 class InterruptCue;
31 
32 namespace download {
33 
38 };
39 
47  char* data;
48  size_t size;
50 
52  data(NULL), size(0), action(xact) { }
53  DataTubeElement(char* mov_data, size_t xsize, DataTubeAction xact) :
54  data(mov_data), size(xsize), action(xact) { }
55 
57  delete data;
58  }
59 };
60 
64 class JobInfo {
65  private:
67  int64_t id_;
73  const std::string *url_;
79  pid_t pid_;
80  uid_t uid_;
81  gid_t gid_;
82  void *cred_data_; // Per-transfer credential data
86  const std::string *extra_info_;
87 
88  // Allow byte ranges to be specified.
90  off_t range_size_;
91 
92  // Internal state
93  CURL *curl_handle_;
94  curl_slist *headers_;
95  char *info_header_;
99  z_stream zstream_;
101  std::string proxy_;
102  std::string link_;
103  bool nocache_;
106  unsigned char num_used_proxies_;
107  unsigned char num_used_metalinks_;
108  unsigned char num_used_hosts_;
109  unsigned char num_retries_;
110  unsigned backoff_ms_;
113 
114  // Don't fail-over proxies on download errors. default = false
116 
117  // TODO(heretherebedragons) c++11 allows to delegate constructors (N1986)
118  // Replace Init() with JobInfo() that is called by the other constructors
119  void Init();
120 
121  public:
125  JobInfo(const std::string *u, const bool c, const bool ph,
126  const shash::Any *h, cvmfs::Sink *s);
127 
131  JobInfo(const std::string *u, const bool ph);
132 
135  data_tube_.Destroy();
136  }
137 
140  }
141 
143  return pipe_job_results.IsValid();
144  }
145 
146  void CreateDataTube() {
147  // TODO(heretherebedragons) change to weighted queue
149  }
150 
152  return data_tube_.IsValid();
153  }
154 
159  bool IsFileNotFound();
160 
161  pid_t *GetPidPtr() { return &pid_; }
162  uid_t *GetUidPtr() { return &uid_; }
163  gid_t *GetGidPtr() { return &gid_; }
165  z_stream *GetZstreamPtr() { return &zstream_; }
167  void **GetCredDataPtr() { return &cred_data_; }
168  curl_slist **GetHeadersPtr() { return &headers_; }
169  CURL **GetCurlHandle() { return &curl_handle_; }
172  return pipe_job_results.weak_ref(); }
174 
175  const std::string* url() const { return url_; }
176  bool compressed() const { return compressed_; }
177  bool probe_hosts() const { return probe_hosts_; }
178  bool head_request() const { return head_request_; }
179  bool follow_redirects() const { return follow_redirects_; }
180  bool force_nocache() const { return force_nocache_; }
181  pid_t pid() const { return pid_; }
182  uid_t uid() const { return uid_; }
183  gid_t gid() const { return gid_; }
184  void *cred_data() const { return cred_data_; }
186  cvmfs::Sink *sink() const { return sink_; }
187  const shash::Any *expected_hash() const { return expected_hash_; }
188  const std::string *extra_info() const { return extra_info_; }
189 
190  off_t range_offset() const { return range_offset_; }
191  off_t range_size() const { return range_size_; }
192 
193  CURL *curl_handle() const { return curl_handle_; }
194  curl_slist *headers() const { return headers_; }
195  char *info_header() const { return info_header_; }
196  char *tracing_header_pid() const { return tracing_header_pid_; }
197  char *tracing_header_gid() const { return tracing_header_gid_; }
198  char *tracing_header_uid() const { return tracing_header_uid_; }
199  z_stream zstream() const { return zstream_; }
201  std::string proxy() const { return proxy_; }
202  std::string link() const { return link_; }
203  bool nocache() const { return nocache_; }
204  Failures error_code() const { return error_code_; }
205  int http_code() const { return http_code_; }
206  unsigned char num_used_proxies() const { return num_used_proxies_; }
207  unsigned char num_used_metalinks() const { return num_used_metalinks_; }
208  unsigned char num_used_hosts() const { return num_used_hosts_; }
209  unsigned char num_retries() const { return num_retries_; }
210  unsigned backoff_ms() const { return backoff_ms_; }
214 
215  bool allow_failure() const { return allow_failure_; }
216  int64_t id() const { return id_; }
217 
218 
219  void SetUrl(const std::string *url) { url_ = url; }
226  void SetPid(pid_t pid) { pid_ = pid; }
227  void SetUid(uid_t uid) { uid_ = uid; }
228  void SetGid(gid_t gid) { gid_ = gid; }
233  { sink_ = sink; }
236  void SetExtraInfo(const std::string *extra_info)
237  { extra_info_ = extra_info; }
238 
241 
243  void SetHeaders(curl_slist *headers) { headers_ = headers; }
251  void SetZstream(z_stream zstream) { zstream_ = zstream; }
254  void SetProxy(const std::string &proxy) { proxy_ = proxy; }
255  void SetLink(const std::string &link) { link_ = link; }
256  void SetNocache(bool nocache) { nocache_ = nocache; }
263  void SetNumUsedHosts(unsigned char num_used_hosts)
271 
273 
274  // needed for fetch.h ThreadLocalStorage
275  JobInfo() { Init(); }
276 }; // JobInfo
277 
278 } // namespace download
279 
280 #endif // CVMFS_NETWORK_JOBINFO_H_
const std::string * extra_info_
Definition: jobinfo.h:86
const std::string * url_
Definition: jobinfo.h:73
z_stream * GetZstreamPtr()
Definition: jobinfo.h:165
void SetInfoHeader(char *info_header)
Definition: jobinfo.h:244
void SetHashContext(shash::ContextPtr hash_context)
Definition: jobinfo.h:252
shash::ContextPtr * GetHashContextPtr()
Definition: jobinfo.h:170
uid_t uid() const
Definition: jobinfo.h:182
UniquePtr< Pipe< kPipeDownloadJobsResults > > pipe_job_results
Pipe used for the return value.
Definition: jobinfo.h:69
int64_t atomic_int64
Definition: atomic.h:18
bool follow_redirects_
Definition: jobinfo.h:77
bool head_request_
Definition: jobinfo.h:76
bool probe_hosts() const
Definition: jobinfo.h:177
std::string link_
Definition: jobinfo.h:102
T * weak_ref() const
Definition: pointer.h:42
uid_t * GetUidPtr()
Definition: jobinfo.h:162
unsigned backoff_ms_
Definition: jobinfo.h:110
int64_t id() const
Definition: jobinfo.h:216
const shash::Any * expected_hash_
Definition: jobinfo.h:85
curl_slist ** GetHeadersPtr()
Definition: jobinfo.h:168
void SetCurrentHostChainIndex(int current_host_chain_index)
Definition: jobinfo.h:269
UniquePtr< Tube< DataTubeElement > > data_tube_
Definition: jobinfo.h:72
const std::string * url() const
Definition: jobinfo.h:175
void * cred_data() const
Definition: jobinfo.h:184
curl_slist * headers_
Definition: jobinfo.h:94
bool allow_failure() const
Definition: jobinfo.h:215
CURL * curl_handle() const
Definition: jobinfo.h:193
unsigned char num_used_hosts_
Definition: jobinfo.h:108
void SetRangeOffset(off_t range_offset)
Definition: jobinfo.h:239
void SetTracingHeaderGid(char *tracing_header_gid)
Definition: jobinfo.h:247
z_stream zstream_
Definition: jobinfo.h:99
void SetNocache(bool nocache)
Definition: jobinfo.h:256
bool IsValidDataTube()
Definition: jobinfo.h:151
void SetTracingHeaderPid(char *tracing_header_pid)
Definition: jobinfo.h:245
shash::ContextPtr hash_context_
Definition: jobinfo.h:100
Tube< DataTubeElement > * GetDataTubePtr()
Definition: jobinfo.h:173
int64_t id_
Definition: jobinfo.h:67
char * tracing_header_gid() const
Definition: jobinfo.h:197
char * info_header() const
Definition: jobinfo.h:195
static atomic_int64 next_uuid
Definition: jobinfo.h:66
unsigned char num_used_proxies_
Definition: jobinfo.h:106
bool force_nocache() const
Definition: jobinfo.h:180
void SetZstream(z_stream zstream)
Definition: jobinfo.h:251
int current_metalink_chain_index_
Definition: jobinfo.h:111
void SetLink(const std::string &link)
Definition: jobinfo.h:255
off_t range_offset() const
Definition: jobinfo.h:190
bool force_nocache_
Definition: jobinfo.h:78
void SetInterruptCue(InterruptCue *interrupt_cue)
Definition: jobinfo.h:230
bool nocache() const
Definition: jobinfo.h:203
bool IsFileNotFound()
Definition: jobinfo.cc:32
unsigned char num_used_hosts() const
Definition: jobinfo.h:208
bool follow_redirects() const
Definition: jobinfo.h:179
std::string proxy_
Definition: jobinfo.h:101
int http_code() const
Definition: jobinfo.h:205
void CreateDataTube()
Definition: jobinfo.h:146
void SetNumUsedMetalinks(unsigned char num_used_metalinks)
Definition: jobinfo.h:261
Pipe< kPipeDownloadJobsResults > * GetPipeJobResultPtr()
Definition: jobinfo.h:171
void SetHttpCode(int http_code)
Definition: jobinfo.h:258
DataTubeAction action
Definition: jobinfo.h:49
bool head_request() const
Definition: jobinfo.h:178
unsigned char num_retries() const
Definition: jobinfo.h:209
bool IsValidPipeJobResults()
Definition: jobinfo.h:142
off_t range_size() const
Definition: jobinfo.h:191
void SetCurrentMetalinkChainIndex(int current_metalink_chain_index)
Definition: jobinfo.h:267
bool compressed() const
Definition: jobinfo.h:176
cvmfs::Sink * sink() const
Definition: jobinfo.h:186
char * tracing_header_uid_
Definition: jobinfo.h:98
cvmfs::Sink * sink_
Definition: jobinfo.h:84
gid_t gid() const
Definition: jobinfo.h:183
DataTubeElement(char *mov_data, size_t xsize, DataTubeAction xact)
Definition: jobinfo.h:53
void SetForceNocache(bool force_nocache)
Definition: jobinfo.h:225
char * tracing_header_pid_
Definition: jobinfo.h:96
std::string proxy() const
Definition: jobinfo.h:201
void SetUid(uid_t uid)
Definition: jobinfo.h:227
void SetPid(pid_t pid)
Definition: jobinfo.h:226
std::string link() const
Definition: jobinfo.h:202
bool compressed_
Definition: jobinfo.h:74
void SetNumRetries(unsigned char num_retries)
Definition: jobinfo.h:265
void SetExpectedHash(const shash::Any *expected_hash)
Definition: jobinfo.h:234
void * cred_data_
Definition: jobinfo.h:82
InterruptCue * interrupt_cue() const
Definition: jobinfo.h:185
InterruptCue ** GetInterruptCuePtr()
Definition: jobinfo.h:164
shash::ContextPtr hash_context() const
Definition: jobinfo.h:200
char * tracing_header_gid_
Definition: jobinfo.h:97
bool allow_failure_
Definition: jobinfo.h:115
DataTubeAction
Definition: jobinfo.h:34
Failures error_code_
Definition: jobinfo.h:104
void SetRangeSize(off_t range_size)
Definition: jobinfo.h:240
DataTubeElement(DataTubeAction xact)
Definition: jobinfo.h:51
void SetCompressed(bool compressed)
Definition: jobinfo.h:220
char * tracing_header_uid() const
Definition: jobinfo.h:198
off_t range_offset_
Definition: jobinfo.h:89
Failures error_code() const
Definition: jobinfo.h:204
bool IsValid() const
Definition: pointer.h:43
void ** GetCredDataPtr()
Definition: jobinfo.h:167
off_t range_size_
Definition: jobinfo.h:90
pid_t * GetPidPtr()
Definition: jobinfo.h:161
char * info_header_
Definition: jobinfo.h:95
void SetErrorCode(Failures error_code)
Definition: jobinfo.h:257
void SetNumUsedProxies(unsigned char num_used_proxies)
Definition: jobinfo.h:259
void SetGid(gid_t gid)
Definition: jobinfo.h:228
void SetHeadRequest(bool head_request)
Definition: jobinfo.h:222
int current_metalink_chain_index() const
Definition: jobinfo.h:211
void SetSink(cvmfs::Sink *sink)
Definition: jobinfo.h:232
unsigned char num_retries_
Definition: jobinfo.h:109
void SetExtraInfo(const std::string *extra_info)
Definition: jobinfo.h:236
CURL ** GetCurlHandle()
Definition: jobinfo.h:169
InterruptCue * interrupt_cue_
Definition: jobinfo.h:83
void CreatePipeJobResults()
Definition: jobinfo.h:138
unsigned char num_used_metalinks() const
Definition: jobinfo.h:207
void SetCurlHandle(CURL *curl_handle)
Definition: jobinfo.h:242
void SetTracingHeaderUid(char *tracing_header_uid)
Definition: jobinfo.h:249
int current_host_chain_index_
Definition: jobinfo.h:112
curl_slist * headers() const
Definition: jobinfo.h:194
const shash::Any * expected_hash() const
Definition: jobinfo.h:187
void SetUrl(const std::string *url)
Definition: jobinfo.h:219
void SetCredData(void *cred_data)
Definition: jobinfo.h:229
CURL * curl_handle_
Definition: jobinfo.h:93
const std::string * extra_info() const
Definition: jobinfo.h:188
Definition: tube.h:39
void SetProxy(const std::string &proxy)
Definition: jobinfo.h:254
z_stream zstream() const
Definition: jobinfo.h:199
unsigned backoff_ms() const
Definition: jobinfo.h:210
pid_t pid() const
Definition: jobinfo.h:181
unsigned char num_used_proxies() const
Definition: jobinfo.h:206
int current_host_chain_index() const
Definition: jobinfo.h:213
void SetAllowFailure(bool allow_failure)
Definition: jobinfo.h:272
void SetProbeHosts(bool probe_hosts)
Definition: jobinfo.h:221
void SetNumUsedHosts(unsigned char num_used_hosts)
Definition: jobinfo.h:263
bool probe_hosts_
Definition: jobinfo.h:75
void SetHeaders(curl_slist *headers)
Definition: jobinfo.h:243
char * tracing_header_pid() const
Definition: jobinfo.h:196
void SetBackoffMs(unsigned backoff_ms)
Definition: jobinfo.h:266
void SetFollowRedirects(bool follow_redirects)
Definition: jobinfo.h:223
unsigned char num_used_metalinks_
Definition: jobinfo.h:107
void Destroy()
Definition: pointer.h:45
Failures * GetErrorCodePtr()
Definition: jobinfo.h:166
gid_t * GetGidPtr()
Definition: jobinfo.h:163