1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#include "upload.h" |
6 |
|
|
#include "cvmfs_config.h" |
7 |
|
|
|
8 |
|
|
#include <vector> |
9 |
|
|
|
10 |
|
|
#include "util/shared_ptr.h" |
11 |
|
|
#include "util_concurrency.h" |
12 |
|
|
|
13 |
|
|
namespace upload { |
14 |
|
|
|
15 |
|
21 |
Spooler *Spooler::Construct(const SpoolerDefinition &spooler_definition, |
16 |
|
|
perf::StatisticsTemplate *statistics) { |
17 |
|
21 |
Spooler *result = new Spooler(spooler_definition); |
18 |
✗✓ |
21 |
if (!result->Initialize(statistics)) { |
19 |
|
|
delete result; |
20 |
|
|
result = NULL; |
21 |
|
|
} |
22 |
|
21 |
return result; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
21 |
Spooler::Spooler(const SpoolerDefinition &spooler_definition) |
26 |
|
21 |
: spooler_definition_(spooler_definition) {} |
27 |
|
|
|
28 |
|
42 |
Spooler::~Spooler() { |
29 |
✓✗ |
21 |
if (uploader_) { |
30 |
|
21 |
uploader_->TearDown(); |
31 |
|
|
} |
32 |
✗✓✗✗
|
21 |
} |
33 |
|
|
|
34 |
|
|
std::string Spooler::backend_name() const { return uploader_->name(); } |
35 |
|
|
|
36 |
|
21 |
bool Spooler::Initialize(perf::StatisticsTemplate *statistics) { |
37 |
|
|
// configure the uploader environment |
38 |
|
21 |
uploader_ = AbstractUploader::Construct(spooler_definition_); |
39 |
✗✓ |
21 |
if (!uploader_) { |
40 |
|
|
LogCvmfs(kLogSpooler, kLogWarning, |
41 |
|
|
"Failed to initialize backend upload " |
42 |
|
|
"facility in Spooler."); |
43 |
|
|
return false; |
44 |
|
|
} |
45 |
|
|
|
46 |
✗✓ |
21 |
if (statistics != NULL) { |
47 |
|
|
uploader_->InitCounters(statistics); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
// configure the file processor context |
51 |
|
|
ingestion_pipeline_ = |
52 |
|
21 |
new IngestionPipeline(uploader_.weak_ref(), spooler_definition_); |
53 |
|
21 |
ingestion_pipeline_->RegisterListener(&Spooler::ProcessingCallback, this); |
54 |
|
21 |
ingestion_pipeline_->Spawn(); |
55 |
|
|
|
56 |
|
|
// all done... |
57 |
|
21 |
return true; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
void Spooler::Process(IngestionSource *source, const bool allow_chunking) { |
61 |
|
|
ingestion_pipeline_->Process(source, allow_chunking); |
62 |
|
|
} |
63 |
|
|
|
64 |
|
15 |
void Spooler::ProcessCatalog(const std::string &local_path) { |
65 |
|
|
ingestion_pipeline_->Process(new FileIngestionSource(local_path), false, |
66 |
|
15 |
shash::kSuffixCatalog); |
67 |
|
15 |
} |
68 |
|
|
|
69 |
|
|
void Spooler::ProcessHistory(const std::string &local_path) { |
70 |
|
|
ingestion_pipeline_->Process(new FileIngestionSource(local_path), false, |
71 |
|
|
shash::kSuffixHistory); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
void Spooler::ProcessCertificate(const std::string &local_path) { |
75 |
|
|
ingestion_pipeline_->Process(new FileIngestionSource(local_path), false, |
76 |
|
|
shash::kSuffixCertificate); |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
void Spooler::ProcessMetainfo(const std::string &local_path) { |
80 |
|
|
ingestion_pipeline_->Process(new FileIngestionSource(local_path), false, |
81 |
|
|
shash::kSuffixMetainfo); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
20 |
void Spooler::Upload(const std::string &local_path, |
85 |
|
|
const std::string &remote_path) { |
86 |
|
|
uploader_->Upload( |
87 |
|
|
local_path, remote_path, |
88 |
|
20 |
AbstractUploader::MakeCallback(&Spooler::UploadingCallback, this)); |
89 |
|
20 |
} |
90 |
|
|
|
91 |
|
|
void Spooler::UploadManifest(const std::string &local_path) { |
92 |
|
|
Upload(local_path, ".cvmfspublished"); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
void Spooler::UploadReflog(const std::string &local_path) { |
96 |
|
|
Upload(local_path, ".cvmfsreflog"); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
void Spooler::RemoveAsync(const std::string &file_to_delete) { |
100 |
|
|
uploader_->RemoveAsync(file_to_delete); |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
bool Spooler::Peek(const std::string &path) const { |
104 |
|
|
return uploader_->Peek(path); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
bool Spooler::PlaceBootstrappingShortcut(const shash::Any &object) const { |
108 |
|
|
assert(!object.IsNull()); |
109 |
|
|
return uploader_->PlaceBootstrappingShortcut(object); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
15 |
void Spooler::ProcessingCallback(const SpoolerResult &data) { |
113 |
|
15 |
NotifyListeners(data); |
114 |
|
15 |
} |
115 |
|
|
|
116 |
|
20 |
void Spooler::UploadingCallback(const UploaderResults &data) { |
117 |
|
20 |
NotifyListeners(SpoolerResult(data.return_code, data.local_path)); |
118 |
|
20 |
} |
119 |
|
|
|
120 |
|
28 |
void Spooler::WaitForUpload() const { |
121 |
|
28 |
ingestion_pipeline_->WaitFor(); |
122 |
|
28 |
uploader_->WaitForUpload(); |
123 |
|
28 |
} |
124 |
|
|
|
125 |
|
|
bool Spooler::FinalizeSession(bool commit, const std::string &old_root_hash, |
126 |
|
|
const std::string &new_root_hash, |
127 |
|
|
const RepositoryTag &tag) const { |
128 |
|
|
return uploader_->FinalizeSession(commit, old_root_hash, |
129 |
|
|
new_root_hash, tag); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
48 |
unsigned int Spooler::GetNumberOfErrors() const { |
133 |
|
48 |
return uploader_->GetNumberOfErrors(); |
134 |
|
|
} |
135 |
|
|
|
136 |
✓✗✓✗
|
45 |
} // namespace upload |