WRENCH  1.11
Cyberinfrastructure Simulation Workbench
Overview Installation Getting Started WRENCH 101 WRENCH 102
LogicalFileSystem.h
1 
10 #ifndef WRENCH_LOGICALFILESYSTEM_H
11 #define WRENCH_LOGICALFILESYSTEM_H
12 
13 #include <stdexcept>
14 #include <string>
15 #include <map>
16 #include <set>
17 #include <memory>
18 
19 
20 #include <wrench/data_file/DataFile.h>
21 
22 namespace wrench {
23 
24  /***********************/
26  /***********************/
27 
28 
29  class StorageService;
30 
34  class LogicalFileSystem {
35 
36  public:
37 
38  explicit LogicalFileSystem(std::string hostname, StorageService *storage_service, std::string mount_point);
39 
40  void init();
41 
42  double getTotalCapacity();
43  bool hasEnoughFreeSpace(double bytes);
44  double getFreeSpace();
45  void reserveSpace(std::shared_ptr<DataFile>file, std::string absolute_path);
46  void unreserveSpace(std::shared_ptr<DataFile>file, std::string absolute_path);
47 
48  void createDirectory(std::string absolute_path);
49  bool doesDirectoryExist(std::string absolute_path);
50  bool isDirectoryEmpty(std::string absolute_path);
51  void removeEmptyDirectory(std::string absolute_path);
52  void storeFileInDirectory(std::shared_ptr<DataFile>file, std::string absolute_path);
53  void removeFileFromDirectory(std::shared_ptr<DataFile>file, std::string absolute_path);
54  void removeAllFilesInDirectory(std::string absolute_path);
55  bool isFileInDirectory(std::shared_ptr<DataFile>file, std::string absolute_path);
56  std::set<std::shared_ptr<DataFile>> listFilesInDirectory(std::string absolute_path);
57 
58 
59  private:
60 
61  friend class StorageService;
62 
63  void stageFile(std::shared_ptr<DataFile> file, std::string absolute_path);
64 
65  static std::map<std::string, StorageService *> mount_points;
66 
67  std::map<std::string, std::set<std::shared_ptr<DataFile>>> content;
68 
69  std::string hostname;
70  StorageService *storage_service;
71  std::string mount_point;
72  double total_capacity;
73  double occupied_space;
74  std::map<std::string, double> reserved_space;
75 
76  bool initialized;
77 
78  void assertInitHasBeenCalled() {
79  if (not this->initialized) {
80  throw std::runtime_error("LogicalFileSystem::assertInitHasBeenCalled(): A logical file system needs to be initialized before it's been called");
81  }
82  }
83  void assertDirectoryExist(std::string absolute_path) {
84  if (not this->doesDirectoryExist(absolute_path)) {
85  throw std::invalid_argument("LogicalFileSystem::assertDirectoryExists(): directory " + absolute_path + " does not exist");
86  }
87  }
88 
89  void assertDirectoryDoesNotExist(std::string absolute_path) {
90  if (this->doesDirectoryExist(absolute_path)) {
91  throw std::invalid_argument("LogicalFileSystem::assertDirectoryExists(): directory " + absolute_path + " already exists");
92  }
93  }
94 
95  void assertDirectoryIsEmpty(std::string absolute_path) {
96  assertDirectoryExist(absolute_path);
97  if (not this->isDirectoryEmpty(absolute_path)) {
98  throw std::invalid_argument("LogicalFileSystem::assertDirectoryIsEmpty(): directory " + absolute_path + "is not empty");
99  }
100  }
101 
102  void assertFileIsInDirectory(std::shared_ptr<DataFile>file, std::string absolute_path) {
103  assertDirectoryExist(absolute_path);
104  if (this->content[absolute_path].find(file) == this->content[absolute_path].end()) {
105  throw std::invalid_argument("LogicalFileSystem::assertFileIsInDirectory(): File " + file->getID() +
106  " is not in directory " + absolute_path);
107  }
108  }
109 
110  };
111 
112 
113  /***********************/
115  /***********************/
116 
117 }
118 
119 
120 #endif //WRENCH_LOGICALFILESYSTEM_H
wrench
Definition: Action.cpp:28