CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
upload.cc
Go to the documentation of this file.
1 
5 #include "upload.h"
6 #include "cvmfs_config.h"
7 
8 #include <vector>
9 
10 #include "util/concurrency.h"
11 #include "util/shared_ptr.h"
12 
13 namespace upload {
14 
15 Spooler *Spooler::Construct(const SpoolerDefinition &spooler_definition,
16  perf::StatisticsTemplate *statistics) {
17  Spooler *result = new Spooler(spooler_definition);
18  if (!result->Initialize(statistics)) {
19  delete result;
20  result = NULL;
21  }
22  return result;
23 }
24 
25 Spooler::Spooler(const SpoolerDefinition &spooler_definition)
26  : spooler_definition_(spooler_definition) {}
27 
28 Spooler::~Spooler() {
29  FinalizeSession(false);
30  if (uploader_.IsValid()) {
31  uploader_->TearDown();
32  }
33 }
34 
35 std::string Spooler::backend_name() const { return uploader_->name(); }
36 
37 bool Spooler::Initialize(perf::StatisticsTemplate *statistics) {
38  // configure the uploader environment
39  uploader_ = AbstractUploader::Construct(spooler_definition_);
40  if (!uploader_.IsValid()) {
42  "Failed to initialize backend upload "
43  "facility in Spooler.");
44  return false;
45  }
46 
47  if (statistics != NULL) {
48  uploader_->InitCounters(statistics);
49  }
50 
51  // configure the file processor context
52  ingestion_pipeline_ =
53  new IngestionPipeline(uploader_.weak_ref(), spooler_definition_);
54  ingestion_pipeline_->RegisterListener(&Spooler::ProcessingCallback, this);
55  ingestion_pipeline_->Spawn();
56 
57  // all done...
58  return true;
59 }
60 
61 bool Spooler::Create() {
62  return uploader_->Create();
63 }
64 
65 void Spooler::Process(IngestionSource *source, const bool allow_chunking) {
66  ingestion_pipeline_->Process(source, allow_chunking);
67 }
68 
69 void Spooler::ProcessCatalog(const std::string &local_path) {
70  ingestion_pipeline_->Process(new FileIngestionSource(local_path), false,
72 }
73 
74 void Spooler::ProcessHistory(const std::string &local_path) {
75  ingestion_pipeline_->Process(new FileIngestionSource(local_path), false,
77 }
78 
79 void Spooler::ProcessCertificate(const std::string &local_path) {
80  ingestion_pipeline_->Process(new FileIngestionSource(local_path), false,
82 }
83 
84 void Spooler::ProcessCertificate(IngestionSource *source) {
85  ingestion_pipeline_->Process(source, false, shash::kSuffixCertificate);
86 }
87 
88 void Spooler::ProcessMetainfo(const std::string &local_path) {
89  ingestion_pipeline_->Process(new FileIngestionSource(local_path), false,
91 }
92 
93 void Spooler::ProcessMetainfo(IngestionSource *source) {
94  ingestion_pipeline_->Process(source, false, shash::kSuffixMetainfo);
95 }
96 
97 void Spooler::Upload(const std::string &local_path,
98  const std::string &remote_path) {
99  uploader_->UploadFile(
100  local_path, remote_path,
101  AbstractUploader::MakeCallback(&Spooler::UploadingCallback, this));
102 }
103 
104 void Spooler::Upload(const std::string &remote_path, IngestionSource *source) {
105  uploader_->UploadIngestionSource(
106  remote_path, source,
107  AbstractUploader::MakeCallback(&Spooler::UploadingCallback, this));
108  delete source;
109 }
110 
111 
112 void Spooler::UploadManifest(const std::string &local_path) {
113  Upload(local_path, ".cvmfspublished");
114 }
115 
116 void Spooler::UploadReflog(const std::string &local_path) {
117  Upload(local_path, ".cvmfsreflog");
118 }
119 
120 void Spooler::RemoveAsync(const std::string &file_to_delete) {
121  uploader_->RemoveAsync(file_to_delete);
122 }
123 
124 bool Spooler::Peek(const std::string &path) const {
125  return uploader_->Peek(path);
126 }
127 
128 bool Spooler::Mkdir(const std::string &path) {
129  return uploader_->Mkdir(path);
130 }
131 
132 bool Spooler::PlaceBootstrappingShortcut(const shash::Any &object) const {
133  assert(!object.IsNull());
134  return uploader_->PlaceBootstrappingShortcut(object);
135 }
136 
137 void Spooler::ProcessingCallback(const SpoolerResult &data) {
138  NotifyListeners(data);
139 }
140 
141 void Spooler::UploadingCallback(const UploaderResults &data) {
142  NotifyListeners(SpoolerResult(data.return_code, data.local_path));
143 }
144 
145 void Spooler::WaitForUpload() const {
146  ingestion_pipeline_->WaitFor();
147  uploader_->WaitForUpload();
148 }
149 
150 bool Spooler::FinalizeSession(bool commit, const std::string &old_root_hash,
151  const std::string &new_root_hash,
152  const RepositoryTag &tag) const {
153  return uploader_->FinalizeSession(commit, old_root_hash,
154  new_root_hash, tag);
155 }
156 
157 unsigned int Spooler::GetNumberOfErrors() const {
158  return uploader_->GetNumberOfErrors();
159 }
160 
161 } // namespace upload
CallbackPtr RegisterListener(typename BoundClosure< ParamT, DelegateT, ClosureDataT >::CallbackMethod method, DelegateT *delegate, ClosureDataT data)
static Publisher * Create(const SettingsPublisher &settings)
const char kSuffixCertificate
Definition: hash.h:59
const int kLogWarning
assert((mem||(size==0))&&"Out Of Memory")
const char kSuffixCatalog
Definition: hash.h:54
const char kSuffixMetainfo
Definition: hash.h:60
const char kSuffixHistory
Definition: hash.h:55
static bool Peek(const string &remote_path)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:528