CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swissknife_history.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_SWISSKNIFE_HISTORY_H_
6 #define CVMFS_SWISSKNIFE_HISTORY_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "hash.h"
12 #include "history_sqlite.h"
13 #include "swissknife.h"
14 #include "util_concurrency.h"
15 
16 namespace manifest {
17 class Manifest;
18 }
19 
20 namespace catalog {
21 class Catalog;
22 class WritableCatalog;
23 }
24 
25 namespace upload {
26 struct SpoolerDefinition;
27 struct SpoolerResult;
28 class Spooler;
29 }
30 
31 namespace swissknife {
32 
33 class CommandTag : public Command {
34  public:
35  static const std::string kHeadTag;
36  static const std::string kHeadTagDescription;
37  static const std::string kPreviousHeadTag;
38  static const std::string kPreviousHeadTagDescription;
39 
40  CommandTag() { }
41 
42  protected:
43  typedef std::vector<history::History::Tag> TagList;
44  typedef std::vector<history::History::Branch> BranchList;
45 
46  struct Environment {
47  Environment(const std::string &repository_url,
48  const std::string &tmp_path) :
49  repository_url(repository_url), tmp_path(tmp_path) {}
50 
51  const std::string repository_url;
52  const std::string tmp_path;
53 
60  };
61 
62 
64  const bool read_write);
65  bool CloseAndPublishHistory(Environment *environment);
67  catalog::WritableCatalog *catalog);
68  void UploadClosure(const upload::SpoolerResult &result,
69  Future<shash::Any> *hash);
70 
71  bool UpdateUndoTags(Environment *env,
72  const history::History::Tag &current_head_template,
73  const bool undo_rollback = false);
74 
75  // TODO(jblomer): replace by swissknife::Assistant
76  bool FetchObject(const std::string &repository_url,
77  const shash::Any &object_hash,
78  const std::string &destination_path) const;
80  const std::string &repository_url,
81  const std::string &history_path,
82  const bool read_write) const;
83 
84  catalog::Catalog* GetCatalog(const std::string &repository_url,
85  const shash::Any &catalog_hash,
86  const std::string catalog_path,
87  const bool read_write) const;
88 
89  void PrintTagMachineReadable(const history::History::Tag &tag) const;
90 
91  std::string AddPadding(const std::string &str,
92  const size_t padding,
93  const bool align_right = false,
94  const std::string &fill_char = " ") const;
95 
96  bool IsUndoTagName(const std::string &tag_name) const;
97 };
98 
99 
100 //------------------------------------------------------------------------------
101 
102 
107 class CommandEditTag : public CommandTag {
108  public:
109  virtual std::string GetName() const { return "tag_edit"; }
110  virtual std::string GetDescription() const {
111  return "Create a tag and/or remove tags.";
112  }
113 
114  virtual ParameterList GetParams() const;
115  int Main(const ArgumentList &args);
116 
117  protected:
118  int RemoveTags(const ArgumentList &args, Environment *env);
119  int AddNewTag(const ArgumentList &args, Environment *env);
120 
121  shash::Any GetTagRootHash(Environment *env,
122  const std::string &root_hash_string) const;
123  bool ManipulateTag(Environment *env,
124  const history::History::Tag &tag_template,
125  const bool user_provided_hash);
126  bool MoveTag(Environment *env,
127  const history::History::Tag &tag_template);
128  bool CreateTag(Environment *env,
129  const history::History::Tag &new_tag);
130 };
131 
132 
133 //------------------------------------------------------------------------------
134 
135 
136 class CommandListTags : public CommandTag {
137  public:
138  virtual std::string GetName() const { return "tag_list"; }
139  virtual std::string GetDescription() const {
140  return "List tags in the tag database.";
141  }
142 
143  virtual ParameterList GetParams() const;
144  int Main(const ArgumentList &args);
145 
146  protected:
147  struct BranchLevel {
148  BranchLevel() : branch(), level(0) { }
149  BranchLevel(const history::History::Branch &b, unsigned l)
150  : branch(b), level(l) { }
152  unsigned level;
153  };
154  typedef std::vector<BranchLevel> BranchHierarchy;
155 
156  void SortBranchesRecursively(unsigned level,
157  const std::string &parent_branch,
158  const BranchList &branches,
159  BranchHierarchy *hierarchy) const;
160  BranchHierarchy SortBranches(const BranchList &branches) const;
161 
162  void PrintHumanReadableTagList(const TagList &tags) const;
163  void PrintMachineReadableTagList(const TagList &tags) const;
164  void PrintHumanReadableBranchList(const BranchHierarchy &branches) const;
165  void PrintMachineReadableBranchList(const BranchHierarchy &branches) const;
166 };
167 
168 
169 //------------------------------------------------------------------------------
170 
171 
172 class CommandInfoTag : public CommandTag {
173  public:
174  virtual std::string GetName() const { return "tag_info"; }
175  virtual std::string GetDescription() const {
176  return "Obtain detailed information about a tag.";
177  }
178 
179  virtual ParameterList GetParams() const;
180  int Main(const ArgumentList &args);
181 
182  protected:
183  std::string HumanReadableFilesize(const size_t filesize) const;
184  void PrintHumanReadableInfo(const history::History::Tag &tag) const;
185 };
186 
187 
188 //------------------------------------------------------------------------------
189 
190 
192  public:
193  virtual std::string GetName() const { return "tag_rollback"; }
194  virtual std::string GetDescription() const {
195  return "Rollback repository to a given tag.";
196  }
197 
198  virtual ParameterList GetParams() const;
199  int Main(const ArgumentList &args);
200 
201  protected:
202  void PrintDeletedTagList(const TagList &tags) const;
203 };
204 
205 
206 //------------------------------------------------------------------------------
207 
208 
210  public:
211  virtual std::string GetName() const { return "tag_empty_bin"; }
212  virtual std::string GetDescription() const {
213  return "Empty the internal recycle bin of the history database.";
214  }
215 
216  virtual ParameterList GetParams() const;
217  int Main(const ArgumentList &args);
218 };
219 
220 } // namespace swissknife
221 
222 #endif // CVMFS_SWISSKNIFE_HISTORY_H_
BranchLevel(const history::History::Branch &b, unsigned l)
virtual std::string GetDescription() const
virtual ParameterList GetParams() const
void SortBranchesRecursively(unsigned level, const std::string &parent_branch, const BranchList &branches, BranchHierarchy *hierarchy) const
const manifest::Manifest * manifest() const
Definition: repository.h:123
virtual std::string GetName() const
bool CloseAndPublishHistory(Environment *environment)
bool UpdateUndoTags(Environment *env, const history::History::Tag &current_head_template, const bool undo_rollback=false)
static const std::string kPreviousHeadTag
Definition: repository.cc:41
std::vector< Parameter > ParameterList
Definition: swissknife.h:71
UniquePtr< manifest::Manifest > manifest
int Main(const ArgumentList &args)
std::string HumanReadableFilesize(const size_t filesize) const
std::vector< BranchLevel > BranchHierarchy
virtual std::string GetDescription() const
int Main(const ArgumentList &args)
void PrintHumanReadableTagList(const TagList &tags) const
virtual ParameterList GetParams() const
bool MoveTag(Environment *env, const history::History::Tag &tag_template)
Environment(const std::string &repository_url, const std::string &tmp_path)
virtual std::string GetDescription() const
static const std::string kHeadTagDescription
void PrintTagMachineReadable(const history::History::Tag &tag) const
std::string AddPadding(const std::string &str, const size_t padding, const bool align_right=false, const std::string &fill_char=" ") const
std::vector< history::History::Tag > TagList
virtual ParameterList GetParams() const
bool UploadCatalogAndUpdateManifest(Environment *env, catalog::WritableCatalog *catalog)
int Main(const ArgumentList &args)
std::vector< history::History::Branch > BranchList
virtual std::string GetName() const
int Main(const ArgumentList &args)
history::History * GetHistory(const manifest::Manifest *manifest, const std::string &repository_url, const std::string &history_path, const bool read_write) const
bool IsUndoTagName(const std::string &tag_name) const
static const std::string kPreviousHeadTagDescription
virtual std::string GetName() const
int AddNewTag(const ArgumentList &args, Environment *env)
bool FetchObject(const std::string &repository_url, const shash::Any &object_hash, const std::string &destination_path) const
void PrintHumanReadableInfo(const history::History::Tag &tag) const
bool CreateTag(Environment *env, const history::History::Tag &new_tag)
static const std::string kHeadTag
Definition: repository.cc:40
void PrintDeletedTagList(const TagList &tags) const
virtual std::string GetName() const
bool ManipulateTag(Environment *env, const history::History::Tag &tag_template, const bool user_provided_hash)
virtual std::string GetDescription() const
catalog::Catalog * GetCatalog(const std::string &repository_url, const shash::Any &catalog_hash, const std::string catalog_path, const bool read_write) const
void PrintHumanReadableBranchList(const BranchHierarchy &branches) const
int Main(const ArgumentList &args)
void UploadClosure(const upload::SpoolerResult &result, Future< shash::Any > *hash)
std::map< char, SharedPtr< std::string > > ArgumentList
Definition: swissknife.h:72
virtual ParameterList GetParams() const
virtual ParameterList GetParams() const
virtual std::string GetName() const
UniquePtr< history::History > history
void PrintMachineReadableBranchList(const BranchHierarchy &branches) const
Environment * InitializeEnvironment(const ArgumentList &args, const bool read_write)
int RemoveTags(const ArgumentList &args, Environment *env)
UniquePtr< manifest::Manifest > previous_manifest
void PrintMachineReadableTagList(const TagList &tags) const
shash::Any GetTagRootHash(Environment *env, const std::string &root_hash_string) const
BranchHierarchy SortBranches(const BranchList &branches) const
UniquePtr< upload::Spooler > spooler
virtual std::string GetDescription() const