CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
repository.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_PUBLISH_REPOSITORY_H_
6 #define CVMFS_PUBLISH_REPOSITORY_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "gateway_util.h"
12 #include "history.h" // for History::Tag
13 #include "publish/settings.h"
14 #include "upload_spooler_result.h"
15 #include "util/pointer.h"
16 #include "util/single_copy.h"
17 
18 namespace catalog {
19 class DeltaCounters;
20 class DirectoryEntry;
21 class SimpleCatalogManager;
22 class WritableCatalogManager;
23 }
24 namespace download {
25 class DownloadManager;
26 }
27 namespace history {
28 class SqliteHistory;
29 }
30 namespace manifest {
31 class Manifest;
32 class Reflog;
33 }
34 namespace perf {
35 class Statistics;
36 class StatisticsTemplate;
37 }
38 namespace signature {
39 class SignatureManager;
40 }
41 class SyncParameters;
42 namespace upload {
43 class Spooler;
44 }
45 namespace whitelist {
46 class Whitelist;
47 }
48 
49 namespace publish {
50 
51 class SyncMediator;
52 class SyncUnion;
53 
57 class __attribute__((visibility("default"))) DiffListener {
58  public:
59  virtual ~DiffListener() {}
60  virtual void OnInit(const history::History::Tag &from_tag,
61  const history::History::Tag &to_tag) = 0;
62  virtual void OnStats(const catalog::DeltaCounters &delta) = 0;
63  virtual void OnAdd(const std::string &path,
64  const catalog::DirectoryEntry &entry) = 0;
65  virtual void OnRemove(const std::string &path,
66  const catalog::DirectoryEntry &entry) = 0;
67  virtual void OnModify(const std::string &path,
68  const catalog::DirectoryEntry &entry_from,
69  const catalog::DirectoryEntry &entry_to) = 0;
70 };
71 
72 
73 class __attribute__((visibility("default"))) Env {
74  public:
81  static void DropCapabilities();
82 
87  static std::string GetEnterSessionDir();
88 };
89 
90 
91 class __attribute__((visibility("default"))) Repository : SingleCopy {
92  public:
96  static const char kRawHashSymbol = '@';
97 
98  static std::string GetFqrnFromUrl(const std::string &url);
99 
100  explicit Repository(const SettingsRepository &settings);
101  virtual ~Repository();
102 
103  void Check();
104  void GarbageCollect();
105  void List();
106 
111  void Diff(const std::string &from, const std::string &to,
112  DiffListener *diff_listener);
113 
117  bool IsMasterReplica();
118 
120  return signature_mgr_;
121  }
122  const whitelist::Whitelist *whitelist() const { return whitelist_; }
123  const manifest::Manifest *manifest() const { return manifest_; }
124  // Inheritance of History and SqliteHistory unknown in the header
125  const history::History *history() const;
126  std::string meta_info() const { return meta_info_; }
127 
128  protected:
129  Repository();
130  void DownloadRootObjects(
131  const std::string &url,
132  const std::string &fqrn,
133  const std::string &tmp_dir);
135 
137 
149  // TODO(jblomer): make MetaInfo class
150  std::string meta_info_;
151 };
152 
153 class __attribute__((visibility("default"))) Publisher : public Repository {
154  public:
158  class ManagedNode {
159  public:
163  enum EFailures {
164  kFailOk = 0,
165  kFailRdOnlyBroken = 0x01,
166  kFailRdOnlyOutdated = 0x02,
167  kFailRdOnlyWrongRevision = 0x04,
168  kFailUnionBroken = 0x08,
169  kFailUnionWritable = 0x10,
170  kFailUnionLocked = 0x20,
171  };
172 
173  explicit ManagedNode(Publisher *p) : publisher_(p) {}
178  int Check(bool is_quiet = false);
182  void Open();
186  void Lock();
191  void Unmount();
195  void Mount();
199  void ClearScratch();
200 
201  private:
217  };
218 
219  void AlterMountpoint(EMountpointAlterations how, int log_level);
220  void SetRootHash(const shash::Any &hash);
221 
223  }; // class ManagedNode
224 
225 
230  public:
231  struct Settings {
232  Settings() : llvl(0) {}
233  std::string service_endpoint;
237  std::string repo_path;
238  std::string gw_key_path;
239  std::string token_path;
240  int llvl;
241  };
242 
247  Session() : keep_alive_(false), has_lease_(true) {}
248  explicit Session(const Settings &settings_session);
249  explicit Session(const SettingsPublisher &settings_publisher, int llvl = 0);
253  ~Session();
254 
255  void Acquire();
256  void Drop();
257  void SetKeepAlive(bool value);
258 
259  bool has_lease() const { return has_lease_; }
260 
261  private:
271  }; // class Session
272 
276  static const unsigned kRequiredLayoutRevision = 143;
277 
278  static Publisher *Create(const SettingsPublisher &settings);
279 
280  explicit Publisher(const SettingsPublisher &settings);
281  virtual ~Publisher();
282 
283  void UpdateMetaInfo();
284  void Transaction();
285  void Abort();
286  void Publish();
287  void Ingest();
288  void Sync();
289 
296  void ExitShell();
297 
303  void EditTags(const std::vector<history::History::Tag> &add_tags,
304  const std::vector<std::string> &rm_tags);
308  void MarkReplicatible(bool value);
309 
310  void Rollback();
311  void Resign();
312  void Migrate();
313 
314  const SettingsPublisher &settings() const { return settings_; }
315  bool in_transaction() const { return in_transaction_; }
316  bool is_publishing() const { return is_publishing_; }
317  Session *session() const { return session_.weak_ref(); }
318  const upload::Spooler *spooler_files() const { return spooler_files_; }
319  const upload::Spooler *spooler_catalogs() const { return spooler_catalogs_; }
320 
321  private:
322  Publisher();
323 
327  void ConstructSpoolers();
332  void ConstructSyncManagers();
333  void WipeScratchArea();
334 
335  void CreateKeychain();
336  void CreateStorage();
337  void CreateSpoolArea();
338  void CreateRootObjects();
339 
340  void ExportKeychain();
341  void CreateDirectoryAsOwner(const std::string &path, int mode);
342  void InitSpoolArea();
343 
344  void PushCertificate();
345  void PushHistory();
346  void PushManifest();
347  void PushMetainfo();
348  void PushReflog();
349  void PushWhitelist();
350 
351  void OnProcessCertificate(const upload::SpoolerResult &result);
352  void OnProcessHistory(const upload::SpoolerResult &result);
353  void OnProcessMetainfo(const upload::SpoolerResult &result);
354  void OnUploadManifest(const upload::SpoolerResult &result);
355  void OnUploadReflog(const upload::SpoolerResult &result);
356  void OnUploadWhitelist(const upload::SpoolerResult &result);
357 
358  void CheckTagName(const std::string &name);
359 
360  void TransactionRetry();
361  void TransactionImpl();
362  void CheckTransactionStatus();
363 
364  void SyncImpl();
365 
366  SettingsPublisher settings_;
371  int llvl_;
384 
385  upload::Spooler *spooler_files_;
386  upload::Spooler *spooler_catalogs_;
391 };
392 
393 class __attribute__((visibility("default"))) Replica : public Repository {
394  public:
395  static Replica *Create();
396  explicit Replica(const SettingsReplica &settings);
397  virtual ~Replica();
398 
399  void Snapshot();
400 };
401 
402 } // namespace publish
403 
404 #endif // CVMFS_PUBLISH_REPOSITORY_H_
void CheckTransactionStatus()
const SettingsRepository settings_
Definition: repository.h:136
void CreateRootObjects()
Definition: repository.cc:313
manifest::Reflog * reflog_
Definition: repository.h:146
const manifest::Manifest * manifest() const
Definition: repository.h:123
download::DownloadManager * download_mgr_
Definition: repository.h:140
Publisher * publisher_
Definition: repository.h:222
void ConstructSyncManagers()
Definition: repository.cc:713
void OnUploadReflog(const upload::SpoolerResult &result)
Definition: repository.cc:577
catalog::SimpleCatalogManager * GetSimpleCatalogManager()
Definition: repository.cc:131
UniquePtr< ManagedNode > managed_node_
Definition: repository.h:383
Session * session() const
Definition: repository.h:317
Repository(const SettingsRepository &settings)
Definition: repository.cc:63
void Ingest()
Definition: repository.cc:892
UniquePtr< perf::StatisticsTemplate > statistics_publish_
Definition: repository.h:367
static Publisher * Create(const SettingsPublisher &settings)
void Lock()
void OnProcessCertificate(const upload::SpoolerResult &result)
Definition: repository.cc:547
void Open()
const history::History * history() const
void CreateDirectoryAsOwner(const std::string &path, int mode)
Definition: repository.cc:589
void PushCertificate()
Definition: repository.cc:365
void OnUploadWhitelist(const upload::SpoolerResult &result)
Definition: repository.cc:583
void CreateStorage()
Definition: repository.cc:358
bool IsMasterReplica()
Definition: repository.cc:246
void AlterMountpoint(EMountpointAlterations how, int log_level)
const SettingsPublisher & settings() const
Definition: repository.h:314
perf::Statistics * statistics_
Definition: repository.h:138
bool is_publishing() const
Definition: repository.h:316
virtual ~Replica()
Definition: repository.cc:910
upload::Spooler * spooler_catalogs_
Definition: repository.h:386
gateway::GatewayKey gw_key_
Definition: repository.h:374
bool in_transaction_
Definition: repository.h:372
void PushMetainfo()
Definition: repository.cc:394
void List()
class __attribute__((visibility("default"))) DiffListener
Definition: repository.h:57
void Abort()
class __attribute__((visibility("default"))) Publisher ManagedNode(Publisher *p)
Definition: repository.h:173
void PushReflog()
Definition: repository.cc:440
void ExitShell()
Definition: repository.cc:814
bool is_publishing_
Definition: repository.h:373
catalog::WritableCatalogManager * catalog_mgr_
Definition: repository.h:387
void OnProcessMetainfo(const upload::SpoolerResult &result)
Definition: repository.cc:563
void CreateSpoolArea()
std::string meta_info_
Definition: repository.h:150
void PushHistory()
Definition: repository.cc:375
publish::SyncUnion * sync_union_
Definition: repository.h:390
void Check()
void Transaction()
void OnUploadManifest(const upload::SpoolerResult &result)
Definition: repository.cc:571
Settings settings_
Definition: repository.h:262
signature::SignatureManager * signature_mgr_
Definition: repository.h:139
void UpdateMetaInfo()
Definition: repository.cc:896
void DownloadRootObjects(const std::string &url, const std::string &fqrn, const std::string &tmp_dir)
Definition: repository.cc:146
const signature::SignatureManager * signature_mgr() const
Definition: repository.h:119
virtual ~Publisher()
void WipeScratchArea()
EMountpointAlterations
Definition: repository.h:206
string default
Definition: cvmfs_inject.py:25
void Sync()
Definition: repository.cc:795
void InitSpoolArea()
Definition: repository.cc:597
void PushManifest()
Definition: repository.cc:403
catalog::SimpleCatalogManager * simple_catalog_mgr_
Definition: repository.h:144
void EditTags(const std::vector< history::History::Tag > &add_tags, const std::vector< std::string > &rm_tags)
void Snapshot()
history::SqliteHistory * history_
Definition: repository.h:148
void Resign()
Definition: repository.cc:894
void Publish()
void ClearScratch()
UniquePtr< Session > session_
Definition: repository.h:382
manifest::Manifest * manifest_
Definition: repository.h:147
void OnProcessHistory(const upload::SpoolerResult &result)
Definition: repository.cc:555
upload::Spooler * spooler_files_
Definition: repository.h:385
const whitelist::Whitelist * whitelist() const
Definition: repository.h:122
void SyncImpl()
Definition: repository.cc:826
void MarkReplicatible(bool value)
Definition: repository.cc:879
Publisher(const SettingsPublisher &settings)
Definition: repository.cc:634
bool in_transaction() const
Definition: repository.h:315
class __attribute__((visibility("default"))) Replica Replica(const SettingsReplica &settings)
Definition: repository.cc:906
whitelist::Whitelist * whitelist_
Definition: repository.h:145
void GarbageCollect()
void Migrate()
std::string meta_info() const
Definition: repository.h:126
SyncMediator * sync_mediator_
Definition: repository.h:389
void ExportKeychain()
Definition: repository.cc:514
int llvl_
Definition: repository.h:371
const upload::Spooler * spooler_files() const
Definition: repository.h:318
void SetRootHash(const shash::Any &hash)
virtual ~Repository()
Definition: repository.cc:115
const upload::Spooler * spooler_catalogs() const
Definition: repository.h:319
void ConstructSpoolers()
Definition: repository.cc:261
void Rollback()
void CreateKeychain()
Definition: repository.cc:289
void PushWhitelist()
Definition: repository.cc:462
void Diff(const std::string &from, const std::string &to, DiffListener *diff_listener)
bool has_lease() const
Definition: repository.h:259
void CheckTagName(const std::string &name)
static const unsigned kRequiredLayoutRevision
Definition: repository.h:276
SyncParameters * sync_parameters_
Definition: repository.h:388
class static __attribute__((visibility("default"))) Repository std::string GetFqrnFromUrl(const std::string &url)
Definition: repository.cc:241
std::string service_endpoint
Definition: repository.h:233