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 "repository_util.h"
15 #include "upload_spooler_result.h"
16 #include "util/pointer.h"
17 #include "util/single_copy.h"
18 
19 namespace catalog {
20 class DeltaCounters;
21 class DirectoryEntry;
22 class SimpleCatalogManager;
23 class WritableCatalogManager;
24 }
25 namespace download {
26 class DownloadManager;
27 }
28 namespace history {
29 class SqliteHistory;
30 }
31 namespace manifest {
32 class Manifest;
33 class Reflog;
34 }
35 namespace perf {
36 class Statistics;
37 class StatisticsTemplate;
38 }
39 namespace signature {
40 class SignatureManager;
41 }
42 class SyncParameters;
43 namespace upload {
44 class Spooler;
45 }
46 namespace whitelist {
47 class Whitelist;
48 }
49 
50 namespace publish {
51 
52 class SyncMediator;
53 class SyncUnion;
54 
58 class __attribute__((visibility("default"))) DiffListener {
59  public:
60  virtual ~DiffListener() {}
61  virtual void OnInit(const history::History::Tag &from_tag,
62  const history::History::Tag &to_tag) = 0;
63  virtual void OnStats(const catalog::DeltaCounters &delta) = 0;
64  virtual void OnAdd(const std::string &path,
65  const catalog::DirectoryEntry &entry) = 0;
66  virtual void OnRemove(const std::string &path,
67  const catalog::DirectoryEntry &entry) = 0;
68  virtual void OnModify(const std::string &path,
69  const catalog::DirectoryEntry &entry_from,
70  const catalog::DirectoryEntry &entry_to) = 0;
71 };
72 
73 
74 class __attribute__((visibility("default"))) Env {
75  public:
82  static void DropCapabilities();
83 
88  static std::string GetEnterSessionDir();
89 };
90 
91 
92 class __attribute__((visibility("default"))) Repository : SingleCopy {
93  public:
97  static const char kRawHashSymbol = '@';
98 
99  static std::string GetFqrnFromUrl(const std::string &url);
100 
101  explicit Repository(const SettingsRepository &settings,
102  const bool exists = true);
103  virtual ~Repository();
104 
105  void Check();
106  void GarbageCollect();
107  void List();
108 
113  void Diff(const std::string &from, const std::string &to,
114  DiffListener *diff_listener);
115 
119  bool IsMasterReplica();
120 
122  return signature_mgr_;
123  }
124  const whitelist::Whitelist *whitelist() const { return whitelist_; }
125  const manifest::Manifest *manifest() const { return manifest_; }
126  // Inheritance of History and SqliteHistory unknown in the header
127  const history::History *history() const;
128  std::string meta_info() const { return meta_info_; }
129 
130  protected:
131  void DownloadRootObjects(
132  const std::string &url,
133  const std::string &fqrn,
134  const std::string &tmp_dir);
136 
138 
150  // TODO(jblomer): make MetaInfo class
151  std::string meta_info_;
152 };
153 
154 class __attribute__((visibility("default"))) Publisher : public Repository {
155  public:
159  class ManagedNode {
160  public:
164  enum EFailures {
165  kFailOk = 0,
166  kFailRdOnlyBroken = 0x01,
167  kFailRdOnlyOutdated = 0x02,
168  kFailRdOnlyWrongRevision = 0x04,
169  kFailUnionBroken = 0x08,
170  kFailUnionWritable = 0x10,
171  kFailUnionLocked = 0x20,
172  };
173 
174  explicit ManagedNode(Publisher *p) : publisher_(p) {}
179  int Check(bool is_quiet = false);
183  void Open();
187  void Lock();
192  void Unmount();
196  void Mount();
200  void ClearScratch();
201 
202  private:
218  };
219 
220  void AlterMountpoint(EMountpointAlterations how, int log_level);
221  void SetRootHash(const shash::Any &hash);
222 
224  }; // class ManagedNode
225 
226 
231  public:
232  struct Settings {
233  Settings() : llvl(0) {}
234  std::string service_endpoint;
238  std::string repo_path;
239  std::string gw_key_path;
240  std::string token_path;
241  int llvl;
242  };
243 
248  Session() : keep_alive_(false), has_lease_(true) {}
249  explicit Session(const Settings &settings_session);
250  explicit Session(const SettingsPublisher &settings_publisher, int llvl = 0);
254  ~Session();
255 
256  void Acquire();
257  void Drop();
258  void SetKeepAlive(bool value);
259 
260  bool has_lease() const { return has_lease_; }
261 
262  private:
272  }; // class Session
273 
277  static const unsigned kRequiredLayoutRevision = 143;
278 
279  static Publisher *Create(const SettingsPublisher &settings);
280 
281  explicit Publisher(const SettingsPublisher &settings,
282  const bool exists = true);
283  virtual ~Publisher();
284 
285  void UpdateMetaInfo();
286  void Transaction();
287  void Abort();
288  void Publish();
289  void Ingest();
290  void Sync();
291 
298  void ExitShell();
299 
305  void EditTags(const std::vector<history::History::Tag> &add_tags,
306  const std::vector<std::string> &rm_tags);
310  void MarkReplicatible(bool value);
311 
312  void Rollback();
313  void Resign();
314  void Migrate();
315 
316  const SettingsPublisher &settings() const { return settings_; }
317  const ServerFlagFile &in_transaction() const { return in_transaction_; }
318  const ServerLockFile &is_publishing() const { return is_publishing_; }
319  Session *session() const { return session_.weak_ref(); }
320  const upload::Spooler *spooler_files() const { return spooler_files_; }
321  const upload::Spooler *spooler_catalogs() const { return spooler_catalogs_; }
322 
323  private:
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 
363  SettingsPublisher settings_;
368  int llvl_;
381 
382  upload::Spooler *spooler_files_;
383  upload::Spooler *spooler_catalogs_;
388 };
389 
390 class __attribute__((visibility("default"))) Replica : public Repository {
391  public:
392  static Replica *Create();
393  explicit Replica(const SettingsReplica &settings);
394  virtual ~Replica();
395 
396  void Snapshot();
397 };
398 
399 } // namespace publish
400 
401 #endif // CVMFS_PUBLISH_REPOSITORY_H_
const SettingsRepository settings_
Definition: repository.h:137
void CreateRootObjects()
Definition: repository.cc:303
manifest::Reflog * reflog_
Definition: repository.h:147
const manifest::Manifest * manifest() const
Definition: repository.h:125
download::DownloadManager * download_mgr_
Definition: repository.h:141
Publisher * publisher_
Definition: repository.h:223
void ConstructSyncManagers()
Definition: repository.cc:686
void OnUploadReflog(const upload::SpoolerResult &result)
Definition: repository.cc:560
catalog::SimpleCatalogManager * GetSimpleCatalogManager()
Definition: repository.cc:121
UniquePtr< ManagedNode > managed_node_
Definition: repository.h:380
Session * session() const
Definition: repository.h:319
void Ingest()
Definition: repository.cc:849
UniquePtr< perf::StatisticsTemplate > statistics_publish_
Definition: repository.h:364
static Publisher * Create(const SettingsPublisher &settings)
void Lock()
void OnProcessCertificate(const upload::SpoolerResult &result)
Definition: repository.cc:530
void Open()
const history::History * history() const
void CreateDirectoryAsOwner(const std::string &path, int mode)
Definition: repository.cc:572
void PushCertificate()
Definition: repository.cc:354
void OnUploadWhitelist(const upload::SpoolerResult &result)
Definition: repository.cc:566
void CreateStorage()
Definition: repository.cc:347
bool IsMasterReplica()
Definition: repository.cc:236
void AlterMountpoint(EMountpointAlterations how, int log_level)
const SettingsPublisher & settings() const
Definition: repository.h:316
perf::Statistics * statistics_
Definition: repository.h:139
virtual ~Replica()
Definition: repository.cc:869
upload::Spooler * spooler_catalogs_
Definition: repository.h:383
gateway::GatewayKey gw_key_
Definition: repository.h:371
void PushMetainfo()
Definition: repository.cc:383
void List()
class __attribute__((visibility("default"))) DiffListener
Definition: repository.h:58
void Abort()
class __attribute__((visibility("default"))) Publisher ManagedNode(Publisher *p)
Definition: repository.h:174
void PushReflog()
Definition: repository.cc:429
void ExitShell()
Definition: repository.cc:768
catalog::WritableCatalogManager * catalog_mgr_
Definition: repository.h:384
Repository(const SettingsRepository &settings, const bool exists=true)
Definition: repository.cc:49
void OnProcessMetainfo(const upload::SpoolerResult &result)
Definition: repository.cc:546
void CreateSpoolArea()
std::string meta_info_
Definition: repository.h:151
void PushHistory()
Definition: repository.cc:364
publish::SyncUnion * sync_union_
Definition: repository.h:387
void Check()
void Transaction()
void OnUploadManifest(const upload::SpoolerResult &result)
Definition: repository.cc:554
Settings settings_
Definition: repository.h:263
signature::SignatureManager * signature_mgr_
Definition: repository.h:140
void UpdateMetaInfo()
Definition: repository.cc:853
void DownloadRootObjects(const std::string &url, const std::string &fqrn, const std::string &tmp_dir)
Definition: repository.cc:136
const signature::SignatureManager * signature_mgr() const
Definition: repository.h:121
virtual ~Publisher()
void WipeScratchArea()
EMountpointAlterations
Definition: repository.h:207
string default
Definition: cvmfs_inject.py:25
ServerLockFile is_publishing_
Definition: repository.h:370
void Sync()
Definition: repository.cc:780
void InitSpoolArea()
Definition: repository.cc:580
void PushManifest()
Definition: repository.cc:392
catalog::SimpleCatalogManager * simple_catalog_mgr_
Definition: repository.h:145
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:149
void Resign()
Definition: repository.cc:851
void Publish()
void ClearScratch()
UniquePtr< Session > session_
Definition: repository.h:379
manifest::Manifest * manifest_
Definition: repository.h:148
void OnProcessHistory(const upload::SpoolerResult &result)
Definition: repository.cc:538
upload::Spooler * spooler_files_
Definition: repository.h:382
const whitelist::Whitelist * whitelist() const
Definition: repository.h:124
void MarkReplicatible(bool value)
Definition: repository.cc:836
class __attribute__((visibility("default"))) Replica Replica(const SettingsReplica &settings)
Definition: repository.cc:863
ServerFlagFile in_transaction_
Definition: repository.h:369
whitelist::Whitelist * whitelist_
Definition: repository.h:146
void GarbageCollect()
const ServerFlagFile & in_transaction() const
Definition: repository.h:317
void Migrate()
std::string meta_info() const
Definition: repository.h:128
SyncMediator * sync_mediator_
Definition: repository.h:386
void ExportKeychain()
Definition: repository.cc:497
int llvl_
Definition: repository.h:368
const upload::Spooler * spooler_files() const
Definition: repository.h:320
void SetRootHash(const shash::Any &hash)
const ServerLockFile & is_publishing() const
Definition: repository.h:318
Publisher(const SettingsPublisher &settings, const bool exists=true)
Definition: repository.cc:603
virtual ~Repository()
Definition: repository.cc:105
const upload::Spooler * spooler_catalogs() const
Definition: repository.h:321
void ConstructSpoolers()
Definition: repository.cc:251
void Rollback()
void CreateKeychain()
Definition: repository.cc:279
void PushWhitelist()
Definition: repository.cc:451
void Diff(const std::string &from, const std::string &to, DiffListener *diff_listener)
bool has_lease() const
Definition: repository.h:260
void CheckTagName(const std::string &name)
static const unsigned kRequiredLayoutRevision
Definition: repository.h:277
SyncParameters * sync_parameters_
Definition: repository.h:385
class static __attribute__((visibility("default"))) Repository std::string GetFqrnFromUrl(const std::string &url)
Definition: repository.cc:231
std::string service_endpoint
Definition: repository.h:234