CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swissknife_sync.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_SWISSKNIFE_SYNC_H_
6 #define CVMFS_SWISSKNIFE_SYNC_H_
7 
8 #include <string>
9 #include <vector>
10 
12 #include "repository_tag.h"
13 #include "swissknife.h"
14 #include "upload.h"
15 
17  static const unsigned kDefaultMaxWeight = 100000;
18  static const unsigned kDefaultMinWeight = 1000;
19  static const size_t kDefaultMinFileChunkSize = 4 * 1024 * 1024;
20  static const size_t kDefaultAvgFileChunkSize = 8 * 1024 * 1024;
21  static const size_t kDefaultMaxFileChunkSize = 16 * 1024 * 1024;
22  static const unsigned kDefaultNestedKcatalogLimit = 500;
23  static const unsigned kDefaultRootKcatalogLimit = 200;
24  static const unsigned kDefaultFileMbyteLimit = 1024;
25 
27  : spooler(NULL),
28  union_fs_type("aufs"),
29  to_delete(""),
30  cache_dir(""),
31  print_changeset(false),
32  dry_run(false),
33  mucatalogs(false),
34  use_file_chunking(false),
36  ignore_xdir_hardlinks(false),
38  include_xattrs(false),
39  external_data(false),
40  direct_io(false),
41  voms_authz(false),
43  ignore_special_files(false),
44  branched_catalog(false),
46  enforce_limits(false),
53  manual_revision(0),
54  ttl_seconds(0),
57  is_balanced(false),
60  gid(-1u),
61  uid(-1u),
63  key_file(),
64  repo_tag() {}
65 
66  upload::Spooler *spooler;
67  std::string repo_name;
68  std::string dir_union;
69  std::string dir_scratch;
70  std::string dir_rdonly;
71  std::string dir_temp;
73  std::string stratum0;
74  std::string manifest_path;
75  std::string spooler_definition;
76  std::string union_fs_type;
77  std::string public_keys;
78  std::string authz_file;
79  std::string tar_file;
80  std::string base_directory;
81  std::string to_delete;
82  std::string cache_dir;
84  bool dry_run;
85  bool mucatalogs;
92  bool direct_io;
93  bool voms_authz;
94  int virtual_dir_actions; // bit field
105  uint64_t manual_revision;
106  uint64_t ttl_seconds;
110  unsigned max_weight;
111  unsigned min_weight;
112  gid_t gid;
113  uid_t uid;
114 
115  // Parameters for when upstream type is HTTP
116  std::string session_token_file;
117  std::string key_file;
119 };
120 
121 namespace catalog {
122 class Dirtab;
123 class SimpleCatalogManager;
124 } // namespace catalog
125 
126 namespace swissknife {
127 
128 class CommandCreate : public Command {
129  public:
131  virtual std::string GetName() const { return "create"; }
132  virtual std::string GetDescription() const {
133  return "Bootstraps a fresh repository.";
134  }
135  virtual ParameterList GetParams() const {
136  ParameterList r;
137  r.push_back(Parameter::Mandatory('o', "manifest output file"));
138  r.push_back(Parameter::Mandatory('t', "directory for temporary storage"));
139  r.push_back(Parameter::Mandatory('r', "spooler definition"));
140  r.push_back(Parameter::Mandatory('n', "repository name"));
141  r.push_back(Parameter::Mandatory('R', "path to reflog.chksum file"));
142  r.push_back(Parameter::Optional('l', "log level (0-4, default: 2)"));
143  r.push_back(Parameter::Optional('a', "hash algorithm (default: SHA-1)"));
144  r.push_back(Parameter::Optional('V',
145  "VOMS authz requirement "
146  "(default: none)"));
147  r.push_back(Parameter::Switch('v', "repository containing volatile files"));
148  r.push_back(
149  Parameter::Switch('z', "mark new repository as garbage collectable"));
150  r.push_back(Parameter::Optional('V',
151  "VOMS authz requirement "
152  "(default: none)"));
153  return r;
154  }
155  int Main(const ArgumentList &args);
156 };
157 
158 class CommandUpload : public Command {
159  public:
161  virtual std::string GetName() const { return "upload"; }
162  virtual std::string GetDescription() const {
163  return "Uploads a local file to the repository.";
164  }
165  virtual ParameterList GetParams() const {
166  ParameterList r;
167  r.push_back(Parameter::Mandatory('i', "local file"));
168  r.push_back(Parameter::Mandatory('o', "destination path"));
169  r.push_back(Parameter::Mandatory('r', "spooler definition"));
170  r.push_back(Parameter::Optional('a', "hash algorithm (default: SHA-1)"));
171  return r;
172  }
173  int Main(const ArgumentList &args);
174 };
175 
176 class CommandPeek : public Command {
177  public:
179  virtual std::string GetName() const { return "peek"; }
180  virtual std::string GetDescription() const {
181  return "Checks whether a file exists in the repository.";
182  }
183  virtual ParameterList GetParams() const {
184  ParameterList r;
185  r.push_back(Parameter::Mandatory('d', "destination path"));
186  r.push_back(Parameter::Mandatory('r', "spooler definition"));
187  return r;
188  }
189  int Main(const ArgumentList &args);
190 };
191 
192 class CommandRemove : public Command {
193  public:
195  virtual std::string GetName() const { return "remove"; }
196  virtual std::string GetDescription() const {
197  return "Removes a file in the repository storage.";
198  }
199  virtual ParameterList GetParams() const {
200  ParameterList r;
201  r.push_back(Parameter::Mandatory('o', "path to file"));
202  r.push_back(Parameter::Mandatory('r', "spooler definition"));
203  return r;
204  }
205  int Main(const ArgumentList &args);
206 };
207 
208 class CommandApplyDirtab : public Command {
209  public:
212  virtual std::string GetName() const { return "dirtab"; }
213  virtual std::string GetDescription() const {
214  return "Parses the dirtab file and produces nested catalog markers.";
215  }
216  virtual ParameterList GetParams() const {
217  ParameterList r;
218  r.push_back(Parameter::Mandatory('d', "path to dirtab file"));
219  r.push_back(Parameter::Mandatory('u', "union volume"));
220  r.push_back(Parameter::Mandatory('s', "scratch directory"));
221  r.push_back(Parameter::Mandatory('b', "base hash"));
222  r.push_back(Parameter::Mandatory('w', "stratum 0 base url"));
223  r.push_back(Parameter::Mandatory('t', "directory for temporary storage"));
224  r.push_back(Parameter::Optional('@', "proxy url"));
225  r.push_back(Parameter::Switch('x', "verbose mode"));
226  return r;
227  }
228  int Main(const ArgumentList &args);
229 
230  protected:
232  const catalog::Dirtab &dirtab,
233  catalog::SimpleCatalogManager *catalog_manager,
234  std::vector<std::string> *nested_catalog_candidates);
236  const catalog::Dirtab &dirtab, char **paths, const size_t npaths,
237  catalog::SimpleCatalogManager *catalog_manager,
238  std::vector<std::string> *nested_catalog_candidates);
240  const std::vector<std::string> &new_nested_catalogs);
241 
242  private:
243  std::string union_dir_;
244  std::string scratch_dir_;
245  bool verbose_;
246 };
247 
248 class CommandSync : public Command {
249  public:
251  virtual std::string GetName() const { return "sync"; }
252  virtual std::string GetDescription() const {
253  return "Pushes changes from scratch area back to the repository.";
254  }
255  virtual ParameterList GetParams() const {
256  // unused characters: j, J, 1-9, all special characters but @
257  ParameterList r;
258  r.push_back(Parameter::Mandatory('b', "base hash"));
259  r.push_back(Parameter::Mandatory('c', "r/o volume"));
260  r.push_back(Parameter::Mandatory('o', "manifest output file"));
261  r.push_back(Parameter::Mandatory('r', "spooler definition"));
262  r.push_back(Parameter::Mandatory('s', "scratch directory"));
263  r.push_back(Parameter::Mandatory('t', "directory for tee"));
264  r.push_back(Parameter::Mandatory('u', "union volume"));
265  r.push_back(Parameter::Mandatory('w', "stratum 0 base url"));
266  r.push_back(Parameter::Mandatory('K', "public key(s) for repo"));
267  r.push_back(Parameter::Mandatory('N', "fully qualified repository name"));
268 
269  r.push_back(Parameter::Optional('a', "desired average chunk size (bytes)"));
270  r.push_back(Parameter::Optional('e', "hash algorithm (default: SHA-1)"));
271  r.push_back(Parameter::Optional('f', "union filesystem type"));
272  r.push_back(Parameter::Optional('h', "maximal file chunk size in bytes"));
273  r.push_back(Parameter::Optional('l', "minimal file chunk size in bytes"));
274  r.push_back(Parameter::Optional('q', "number of concurrent write jobs"));
275  r.push_back(Parameter::Optional('0', "number of upload tasks"));
276  r.push_back(Parameter::Optional('v', "manual revision number"));
277  r.push_back(Parameter::Optional('z', "log level (0-4, default: 2)"));
278  r.push_back(Parameter::Optional('F', "Authz file listing (default: none)"));
279  r.push_back(Parameter::Optional('M', "minimum weight of the autocatalogs"));
280  r.push_back(
281  Parameter::Optional('Q', "nested catalog limit in kilo-entries"));
282  r.push_back(Parameter::Optional('R', "root catalog limit in kilo-entries"));
283  r.push_back(Parameter::Optional('T', "Root catalog TTL in seconds"));
284  r.push_back(Parameter::Optional('U', "file size limit in megabytes"));
285  r.push_back(
286  Parameter::Optional('D', "tag name (only used when upstream is GW)"));
287  r.push_back(Parameter::Optional(
288  'J', "tag description (only used when upstream is GW)"));
289  r.push_back(Parameter::Optional('X', "maximum weight of the autocatalogs"));
290  r.push_back(Parameter::Optional('Z',
291  "compression algorithm "
292  "(default: zlib)"));
293  r.push_back(Parameter::Optional('S',
294  "virtual directory options "
295  "[snapshots, remove]"));
296 
297 
298  r.push_back(
299  Parameter::Switch('G', "Use persistent caching for all catalogs "
300  "used during the publishing process"
301  " Warning: No automatic garbage collection!"));
302  r.push_back(Parameter::Switch('d',
303  "pause publishing to allow for catalog "
304  "tweaks"));
305  r.push_back(Parameter::Switch('i', "ignore x-directory hardlinks"));
306  r.push_back(Parameter::Switch('g', "ignore special files"));
307  r.push_back(Parameter::Switch('k', "include extended attributes"));
308  r.push_back(Parameter::Switch('m', "create micro catalogs"));
309  r.push_back(Parameter::Switch('n', "create new repository"));
310  r.push_back(Parameter::Switch('p', "enable file chunking"));
311  r.push_back(Parameter::Switch('O', "generate legacy bulk chunks"));
312  r.push_back(Parameter::Switch('x', "print change set"));
313  r.push_back(Parameter::Switch('y', "dry run"));
314  r.push_back(Parameter::Switch('A', "autocatalog enabled/disabled"));
315  r.push_back(Parameter::Switch('E', "enforce limits instead of warning"));
316  r.push_back(Parameter::Switch('L', "enable HTTP redirects"));
317  r.push_back(Parameter::Switch('V',
318  "Publish format compatible with "
319  "authenticated repos"));
320  r.push_back(Parameter::Switch('Y', "enable external data"));
321  r.push_back(Parameter::Switch('W', "set direct I/O for regular files"));
322  r.push_back(Parameter::Switch('B', "branched catalog (no manifest)"));
323  r.push_back(Parameter::Switch('I', "upload updated statistics DB file"));
324 
325  r.push_back(Parameter::Optional('P', "session_token_file"));
326  r.push_back(Parameter::Optional('H', "key file for HTTP API"));
327  r.push_back(Parameter::Optional('@', "proxy URL"));
328 
329  return r;
330  }
331  int Main(const ArgumentList &args);
332 
333  protected:
335  SyncParameters *params);
336  bool CheckParams(const SyncParameters &p);
337 };
338 
339 } // namespace swissknife
340 
341 #endif // CVMFS_SWISSKNIFE_SYNC_H_
static Parameter Optional(const char key, const std::string &desc)
Definition: swissknife.h:41
virtual std::string GetName() const
static const size_t kDefaultMaxFileChunkSize
size_t avg_file_chunk_size
virtual std::string GetName() const
virtual ParameterList GetParams() const
std::string stratum0
static Parameter Switch(const char key, const std::string &desc)
Definition: swissknife.h:44
int Main(const ArgumentList &args)
std::string cache_dir
virtual ParameterList GetParams() const
virtual std::string GetDescription() const
static const unsigned kDefaultMaxWeight
bool generate_legacy_bulk_chunks
unsigned file_mbyte_limit
virtual std::string GetName() const
uint64_t max_concurrent_write_jobs
static const unsigned kDefaultFileMbyteLimit
std::vector< Parameter > ParameterList
Definition: swissknife.h:71
std::string to_delete
virtual std::string GetDescription() const
static const unsigned kDefaultNestedKcatalogLimit
static const unsigned kDefaultRootKcatalogLimit
int Main(const ArgumentList &args)
size_t min_file_chunk_size
unsigned num_upload_tasks
virtual std::string GetDescription() const
std::string spooler_definition
std::string manifest_path
bool ReadFileChunkingArgs(const swissknife::ArgumentList &args, SyncParameters *params)
bool CheckParams(const SyncParameters &p)
virtual std::string GetName() const
zlib::Algorithms compression_alg
unsigned nested_kcatalog_limit
std::string repo_name
std::string union_fs_type
std::string dir_scratch
static const size_t kDefaultMinFileChunkSize
int Main(const ArgumentList &args)
virtual std::string GetDescription() const
std::string key_file
std::string dir_temp
int Main(const ArgumentList &args)
virtual std::string GetName() const
Algorithms
Definition: compression.h:44
std::string base_directory
virtual std::string GetDescription() const
void FilterCandidatesFromGlobResult(const catalog::Dirtab &dirtab, char **paths, const size_t npaths, catalog::SimpleCatalogManager *catalog_manager, std::vector< std::string > *nested_catalog_candidates)
std::string dir_rdonly
static Parameter Mandatory(const char key, const std::string &desc)
Definition: swissknife.h:38
static const unsigned kDefaultMinWeight
shash::Any base_hash
upload::Spooler * spooler
virtual std::string GetName() const
int Main(const ArgumentList &args)
std::string dir_union
virtual ParameterList GetParams() const
virtual ParameterList GetParams() const
int Main(const ArgumentList &args)
bool stop_for_catalog_tweaks
unsigned root_kcatalog_limit
size_t max_file_chunk_size
uint64_t manual_revision
std::string session_token_file
std::map< char, SharedPtr< std::string > > ArgumentList
Definition: swissknife.h:72
uint64_t ttl_seconds
static const size_t kDefaultAvgFileChunkSize
std::string authz_file
virtual std::string GetDescription() const
void DetermineNestedCatalogCandidates(const catalog::Dirtab &dirtab, catalog::SimpleCatalogManager *catalog_manager, std::vector< std::string > *nested_catalog_candidates)
RepositoryTag repo_tag
bool ignore_xdir_hardlinks
std::string tar_file
virtual ParameterList GetParams() const
bool CreateCatalogMarkers(const std::vector< std::string > &new_nested_catalogs)
virtual ParameterList GetParams() const
std::string public_keys