CernVM-FS  2.13.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 "crypto/hash.h"
12 #include "history_sqlite.h"
13 #include "swissknife.h"
14 #include "util/future.h"
15 
16 namespace manifest {
17 class Manifest;
18 }
19 
20 namespace catalog {
21 class Catalog;
22 class WritableCatalog;
23 } // namespace catalog
24 
25 namespace upload {
26 struct SpoolerDefinition;
27 struct SpoolerResult;
28 class Spooler;
29 } // namespace upload
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, const std::string &tmp_path)
48  : repository_url(repository_url), tmp_path(tmp_path) { }
49 
50  const std::string repository_url;
51  const std::string tmp_path;
52 
59  };
60 
61 
63  const bool read_write);
64  bool CloseAndPublishHistory(Environment *environment);
66  catalog::WritableCatalog *catalog);
67  void UploadClosure(const upload::SpoolerResult &result,
68  Future<shash::Any> *hash);
69 
70  bool UpdateUndoTags(Environment *env,
71  const history::History::Tag &current_head_template,
72  const bool undo_rollback = false);
73 
74  // TODO(jblomer): replace by swissknife::Assistant
75  bool FetchObject(const std::string &repository_url,
76  const shash::Any &object_hash,
77  const std::string &destination_path) const;
79  const std::string &repository_url,
80  const std::string &history_path,
81  const bool read_write) const;
82 
83  catalog::Catalog *GetCatalog(const std::string &repository_url,
84  const shash::Any &catalog_hash,
85  const std::string catalog_path,
86  const bool read_write) const;
87 
88  void PrintTagMachineReadable(const history::History::Tag &tag) const;
89 
90  std::string AddPadding(const std::string &str,
91  const size_t padding,
92  const bool align_right = false,
93  const std::string &fill_char = " ") const;
94 
95  bool IsUndoTagName(const std::string &tag_name) const;
96 };
97 
98 
99 //------------------------------------------------------------------------------
100 
101 
106 class CommandEditTag : public CommandTag {
107  public:
108  virtual std::string GetName() const { return "tag_edit"; }
109  virtual std::string GetDescription() const {
110  return "Create a tag and/or remove tags.";
111  }
112 
113  virtual ParameterList GetParams() const;
114  int Main(const ArgumentList &args);
115 
116  protected:
117  int RemoveTags(const ArgumentList &args, Environment *env);
118  int AddNewTag(const ArgumentList &args, Environment *env);
119 
120  shash::Any GetTagRootHash(Environment *env,
121  const std::string &root_hash_string) const;
122  bool ManipulateTag(Environment *env,
123  const history::History::Tag &tag_template,
124  const bool user_provided_hash);
125  bool MoveTag(Environment *env, const history::History::Tag &tag_template);
126  bool CreateTag(Environment *env, const history::History::Tag &new_tag);
127 };
128 
129 
130 //------------------------------------------------------------------------------
131 
132 
133 class CommandListTags : public CommandTag {
134  public:
135  virtual std::string GetName() const { return "tag_list"; }
136  virtual std::string GetDescription() const {
137  return "List tags in the tag database.";
138  }
139 
140  virtual ParameterList GetParams() const;
141  int Main(const ArgumentList &args);
142 
143  protected:
144  struct BranchLevel {
145  BranchLevel() : branch(), level(0) { }
146  BranchLevel(const history::History::Branch &b, unsigned l)
147  : branch(b), level(l) { }
149  unsigned level;
150  };
151  typedef std::vector<BranchLevel> BranchHierarchy;
152 
153  void SortBranchesRecursively(unsigned level,
154  const std::string &parent_branch,
155  const BranchList &branches,
156  BranchHierarchy *hierarchy) const;
157  BranchHierarchy SortBranches(const BranchList &branches) const;
158 
159  void PrintHumanReadableTagList(const TagList &tags) const;
160  void PrintMachineReadableTagList(const TagList &tags) const;
161  void PrintHumanReadableBranchList(const BranchHierarchy &branches) const;
162  void PrintMachineReadableBranchList(const BranchHierarchy &branches) const;
163 };
164 
165 
166 //------------------------------------------------------------------------------
167 
168 
169 class CommandInfoTag : public CommandTag {
170  public:
171  virtual std::string GetName() const { return "tag_info"; }
172  virtual std::string GetDescription() const {
173  return "Obtain detailed information about a tag.";
174  }
175 
176  virtual ParameterList GetParams() const;
177  int Main(const ArgumentList &args);
178 
179  protected:
180  std::string HumanReadableFilesize(const size_t filesize) const;
181  void PrintHumanReadableInfo(const history::History::Tag &tag) const;
182 };
183 
184 
185 //------------------------------------------------------------------------------
186 
187 
189  public:
190  virtual std::string GetName() const { return "tag_rollback"; }
191  virtual std::string GetDescription() const {
192  return "Rollback repository to a given tag.";
193  }
194 
195  virtual ParameterList GetParams() const;
196  int Main(const ArgumentList &args);
197 
198  protected:
199  void PrintDeletedTagList(const TagList &tags) const;
200 };
201 
202 
203 //------------------------------------------------------------------------------
204 
205 
207  public:
208  virtual std::string GetName() const { return "tag_empty_bin"; }
209  virtual std::string GetDescription() const {
210  return "Empty the internal recycle bin of the history database.";
211  }
212 
213  virtual ParameterList GetParams() const;
214  int Main(const ArgumentList &args);
215 };
216 
217 } // namespace swissknife
218 
219 #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:125
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