CernVM-FS  2.9.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 SyncMediator;
42 class SyncParameters;
43 namespace upload {
44 class Spooler;
45 }
46 namespace whitelist {
47 class Whitelist;
48 }
49 
50 namespace publish {
51 
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 = 142;
277 
278  static Publisher *Create(const SettingsPublisher &settings);
279 
280  explicit Publisher(const SettingsPublisher &settings);
281  virtual ~Publisher();
282 
283  void UpdateMetaInfo();
285  void Abort();
286  void Publish();
287  void Ingest();
288  void Sync();
289 
295  void EditTags(const std::vector<history::History::Tag> &add_tags,
296  const std::vector<std::string> &rm_tags);
300  void MarkReplicatible(bool value);
301 
302  void Rollback();
303  void Resign();
304  void Migrate();
305 
306  const SettingsPublisher &settings() const { return settings_; }
307  bool in_transaction() const { return in_transaction_; }
308  bool is_publishing() const { return is_publishing_; }
309  Session *session() const { return session_.weak_ref(); }
310  const upload::Spooler *spooler_files() const { return spooler_files_; }
311  const upload::Spooler *spooler_catalogs() const { return spooler_catalogs_; }
312 
313  private:
314  Publisher();
315 
319  void ConstructSpoolers();
324  void ConstructSyncManagers();
325  void WipeScratchArea();
326 
327  void CreateKeychain();
328  void CreateStorage();
329  void CreateSpoolArea();
330  void CreateRootObjects();
331 
332  void ExportKeychain();
333  void CreateDirectoryAsOwner(const std::string &path, int mode);
334  void InitSpoolArea();
335 
336  void PushCertificate();
337  void PushHistory();
338  void PushManifest();
339  void PushMetainfo();
340  void PushReflog();
341  void PushWhitelist();
342 
343  void OnProcessCertificate(const upload::SpoolerResult &result);
344  void OnProcessHistory(const upload::SpoolerResult &result);
345  void OnProcessMetainfo(const upload::SpoolerResult &result);
346  void OnUploadManifest(const upload::SpoolerResult &result);
347  void OnUploadReflog(const upload::SpoolerResult &result);
348  void OnUploadWhitelist(const upload::SpoolerResult &result);
349 
350  void CheckTagName(const std::string &name);
351 
352  void TransactionRetry();
353  void TransactionImpl();
354  void CheckTransactionStatus();
355 
356  void SyncImpl();
357 
358  SettingsPublisher settings_;
363  int llvl_;
376 
377  upload::Spooler *spooler_files_;
378  upload::Spooler *spooler_catalogs_;
383 };
384 
385 class __attribute__((visibility("default"))) Replica : public Repository {
386  public:
387  static Replica *Create();
388  explicit Replica(const SettingsReplica &settings);
389  virtual ~Replica();
390 
391  void Snapshot();
392 };
393 
394 } // namespace publish
395 
396 #endif // CVMFS_PUBLISH_REPOSITORY_H_
void CheckTransactionStatus()
const SettingsRepository settings_
Definition: repository.h:136
void CreateRootObjects()
Definition: repository.cc:299
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:703
void OnUploadReflog(const upload::SpoolerResult &result)
Definition: repository.cc:563
catalog::SimpleCatalogManager * GetSimpleCatalogManager()
Definition: repository.cc:118
UniquePtr< ManagedNode > managed_node_
Definition: repository.h:375
Session * session() const
Definition: repository.h:309
Repository(const SettingsRepository &settings)
Definition: repository.cc:63
void Ingest()
Definition: repository.cc:870
UniquePtr< perf::StatisticsTemplate > statistics_publish_
Definition: repository.h:359
static Publisher * Create(const SettingsPublisher &settings)
void Lock()
void OnProcessCertificate(const upload::SpoolerResult &result)
Definition: repository.cc:533
void Open()
const history::History * history() const
void CreateDirectoryAsOwner(const std::string &path, int mode)
Definition: repository.cc:575
void PushCertificate()
Definition: repository.cc:351
void OnUploadWhitelist(const upload::SpoolerResult &result)
Definition: repository.cc:569
void CreateStorage()
Definition: repository.cc:344
bool IsMasterReplica()
Definition: repository.cc:233
void AlterMountpoint(EMountpointAlterations how, int log_level)
const SettingsPublisher & settings() const
Definition: repository.h:306
perf::Statistics * statistics_
Definition: repository.h:138
bool is_publishing() const
Definition: repository.h:308
virtual ~Replica()
Definition: repository.cc:884
upload::Spooler * spooler_catalogs_
Definition: repository.h:378
gateway::GatewayKey gw_key_
Definition: repository.h:366
bool in_transaction_
Definition: repository.h:364
void PushMetainfo()
Definition: repository.cc:380
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:426
bool is_publishing_
Definition: repository.h:365
catalog::WritableCatalogManager * catalog_mgr_
Definition: repository.h:379
void OnProcessMetainfo(const upload::SpoolerResult &result)
Definition: repository.cc:549
void CreateSpoolArea()
std::string meta_info_
Definition: repository.h:150
void PushHistory()
Definition: repository.cc:361
publish::SyncUnion * sync_union_
Definition: repository.h:382
void Check()
void Transaction()
Definition: repository.h:284
void OnUploadManifest(const upload::SpoolerResult &result)
Definition: repository.cc:557
Settings settings_
Definition: repository.h:262
signature::SignatureManager * signature_mgr_
Definition: repository.h:139
void UpdateMetaInfo()
Definition: repository.cc:874
void DownloadRootObjects(const std::string &url, const std::string &fqrn, const std::string &tmp_dir)
Definition: repository.cc:133
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:785
void InitSpoolArea()
Definition: repository.cc:583
void PushManifest()
Definition: repository.cc:389
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:872
void Publish()
void ClearScratch()
UniquePtr< Session > session_
Definition: repository.h:374
manifest::Manifest * manifest_
Definition: repository.h:147
void OnProcessHistory(const upload::SpoolerResult &result)
Definition: repository.cc:541
upload::Spooler * spooler_files_
Definition: repository.h:377
const whitelist::Whitelist * whitelist() const
Definition: repository.h:122
void SyncImpl()
Definition: repository.cc:804
void MarkReplicatible(bool value)
Definition: repository.cc:857
Publisher(const SettingsPublisher &settings)
Definition: repository.cc:620
bool in_transaction() const
Definition: repository.h:307
class __attribute__((visibility("default"))) Replica Replica(const SettingsReplica &settings)
Definition: repository.cc:880
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:381
void ExportKeychain()
Definition: repository.cc:500
int llvl_
Definition: repository.h:363
const upload::Spooler * spooler_files() const
Definition: repository.h:310
void SetRootHash(const shash::Any &hash)
virtual ~Repository()
Definition: repository.cc:102
const upload::Spooler * spooler_catalogs() const
Definition: repository.h:311
void ConstructSpoolers()
Definition: repository.cc:248
void Rollback()
void CreateKeychain()
Definition: repository.cc:275
void PushWhitelist()
Definition: repository.cc:448
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:380
class static __attribute__((visibility("default"))) Repository std::string GetFqrnFromUrl(const std::string &url)
Definition: repository.cc:228
std::string service_endpoint
Definition: repository.h:233