| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
*/ |
| 4 |
|
|
|
| 5 |
|
|
#ifndef CVMFS_RECEIVER_PAYLOAD_PROCESSOR_H_ |
| 6 |
|
|
#define CVMFS_RECEIVER_PAYLOAD_PROCESSOR_H_ |
| 7 |
|
|
|
| 8 |
|
|
#include <stdint.h> |
| 9 |
|
|
|
| 10 |
|
|
#include <map> |
| 11 |
|
|
#include <string> |
| 12 |
|
|
#include <vector> |
| 13 |
|
|
|
| 14 |
|
|
#include "pack.h" |
| 15 |
|
|
#include "upload.h" |
| 16 |
|
|
#include "util/raii_temp_dir.h" |
| 17 |
|
|
|
| 18 |
|
|
namespace receiver { |
| 19 |
|
|
|
| 20 |
|
|
struct FileInfo { |
| 21 |
|
|
FileInfo(); |
| 22 |
|
|
explicit FileInfo(const ObjectPackBuild::Event &event); |
| 23 |
|
|
FileInfo(const FileInfo &other); |
| 24 |
|
|
FileInfo &operator=(const FileInfo &other); |
| 25 |
|
|
|
| 26 |
|
|
upload::UploadStreamHandle *handle; |
| 27 |
|
|
size_t total_size; |
| 28 |
|
|
size_t current_size; |
| 29 |
|
|
shash::ContextPtr hash_context; |
| 30 |
|
|
std::vector<unsigned char> hash_buffer; |
| 31 |
|
|
}; |
| 32 |
|
|
|
| 33 |
|
|
/** |
| 34 |
|
|
* This class is used in the `cvmfs_receiver` tool, on repository gateway |
| 35 |
|
|
* machines. The receiver::Reactor class, implementing the event loop of the |
| 36 |
|
|
* `cvmfs_receiver` tool, dispatches the handling of the kSubmitPayload events |
| 37 |
|
|
* to this class. |
| 38 |
|
|
* |
| 39 |
|
|
* Its responsibility is reading the payload - containing a serialized |
| 40 |
|
|
* ObjectPack - from a file descriptor, and unpacking it into the repository. |
| 41 |
|
|
*/ |
| 42 |
|
|
class PayloadProcessor { |
| 43 |
|
|
public: |
| 44 |
|
|
enum Result { |
| 45 |
|
|
kSuccess, |
| 46 |
|
|
kPathViolation, |
| 47 |
|
|
kUploaderError, |
| 48 |
|
|
kOtherError |
| 49 |
|
|
}; |
| 50 |
|
|
|
| 51 |
|
|
PayloadProcessor(); |
| 52 |
|
|
virtual ~PayloadProcessor(); |
| 53 |
|
|
|
| 54 |
|
|
Result Process(int fdin, const std::string &header_digest, |
| 55 |
|
|
const std::string &path, uint64_t header_size); |
| 56 |
|
|
|
| 57 |
|
|
virtual void ConsumerEventCallback(const ObjectPackBuild::Event &event); |
| 58 |
|
|
|
| 59 |
|
|
virtual void OnUploadJobComplete(const upload::UploaderResults &results, |
| 60 |
|
|
void *buffer); |
| 61 |
|
|
|
| 62 |
|
✗ |
int GetNumErrors() const { return num_errors_; } |
| 63 |
|
|
|
| 64 |
|
|
void SetStatistics(perf::Statistics *st); |
| 65 |
|
|
|
| 66 |
|
|
protected: |
| 67 |
|
|
// NOTE: These methods are made virtual such that they can be mocked for |
| 68 |
|
|
// the purpose of unit testing |
| 69 |
|
|
virtual Result Initialize(); |
| 70 |
|
|
virtual Result Finalize(); |
| 71 |
|
|
|
| 72 |
|
|
private: |
| 73 |
|
|
typedef std::map<shash::Any, FileInfo>::iterator FileIterator; |
| 74 |
|
|
std::map<shash::Any, FileInfo> pending_files_; |
| 75 |
|
|
std::string current_repo_; |
| 76 |
|
|
UniquePtr<upload::AbstractUploader> uploader_; |
| 77 |
|
|
UniquePtr<RaiiTempDir> temp_dir_; |
| 78 |
|
|
int num_errors_; |
| 79 |
|
|
UniquePtr<perf::StatisticsTemplate> statistics_; |
| 80 |
|
|
}; |
| 81 |
|
|
|
| 82 |
|
|
} // namespace receiver |
| 83 |
|
|
|
| 84 |
|
|
#endif // CVMFS_RECEIVER_PAYLOAD_PROCESSOR_H_ |
| 85 |
|
|
|