10 #ifndef WRENCH_LOGICALFILESYSTEM_H
11 #define WRENCH_LOGICALFILESYSTEM_H
19 #include "wrench/workflow/WorkflowFile.h"
33 class LogicalFileSystem {
37 explicit LogicalFileSystem(std::string hostname, StorageService *storage_service, std::string mount_point);
41 double getTotalCapacity();
42 bool hasEnoughFreeSpace(
double bytes);
43 double getFreeSpace();
44 void reserveSpace(WorkflowFile *file, std::string absolute_path);
45 void unreserveSpace(WorkflowFile *file, std::string absolute_path);
47 void createDirectory(std::string absolute_path);
48 bool doesDirectoryExist(std::string absolute_path);
49 bool isDirectoryEmpty(std::string absolute_path);
50 void removeEmptyDirectory(std::string absolute_path);
51 void storeFileInDirectory(WorkflowFile *file, std::string absolute_path);
52 void removeFileFromDirectory(WorkflowFile *file, std::string absolute_path);
53 void removeAllFilesInDirectory(std::string absolute_path);
54 bool isFileInDirectory(WorkflowFile *file, std::string absolute_path);
55 std::set<WorkflowFile *> listFilesInDirectory(std::string absolute_path);
60 friend class StorageService;
62 void stageFile(WorkflowFile *file, std::string absolute_path);
64 static std::map<std::string, StorageService*> mount_points;
66 std::map<std::string, std::set<WorkflowFile*>> content;
69 StorageService *storage_service;
70 std::string mount_point;
71 double total_capacity;
72 double occupied_space;
73 std::map<std::string, double> reserved_space;
77 void assertInitHasBeenCalled() {
78 if (not this->initialized) {
79 throw std::runtime_error(
"LogicalFileSystem::assertInitHasBeenCalled(): A logical file system needs to be initialized before it's been called");
82 void assertDirectoryExist(std::string absolute_path) {
83 if (not this->doesDirectoryExist(absolute_path)) {
84 throw std::invalid_argument(
"LogicalFileSystem::assertDirectoryExists(): directory " + absolute_path +
" does not exist");
88 void assertDirectoryDoesNotExist(std::string absolute_path) {
89 if (this->doesDirectoryExist(absolute_path)) {
90 throw std::invalid_argument(
"LogicalFileSystem::assertDirectoryExists(): directory " + absolute_path +
" already exists");
94 void assertDirectoryIsEmpty(std::string absolute_path) {
95 assertDirectoryExist(absolute_path);
96 if (not this->isDirectoryEmpty(absolute_path)) {
97 throw std::invalid_argument(
"LogicalFileSystem::assertDirectoryIsEmpty(): directory " + absolute_path +
"is not empty");
101 void assertFileIsInDirectory(WorkflowFile *file, std::string absolute_path) {
102 assertDirectoryExist(absolute_path);
103 if (this->content[absolute_path].find(file) == this->content[absolute_path].end()) {
104 throw std::invalid_argument(
"LogicalFileSystem::assertFileIsInDirectory(): File " + file->getID() +
105 " is not in directory " + absolute_path);
119 #endif //WRENCH_LOGICALFILESYSTEM_H