WRENCH  1.10
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 
18 
19 #include "wrench/workflow/WorkflowFile.h"
20 
21 namespace wrench {
22 
23  /***********************/
25  /***********************/
26 
27 
28  class StorageService;
29 
34 
35  public:
36 
37  explicit LogicalFileSystem(std::string hostname, StorageService *storage_service, std::string mount_point);
38 
39  void init();
40 
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);
46 
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);
56 
57 
58  private:
59 
60  friend class StorageService;
61 
62  void stageFile(WorkflowFile *file, std::string absolute_path);
63 
64  static std::map<std::string, StorageService*> mount_points;
65 
66  std::map<std::string, std::set<WorkflowFile*>> content;
67 
68  std::string hostname;
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;
74 
75  bool initialized;
76 
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");
80  }
81  }
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");
85  }
86  }
87 
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");
91  }
92  }
93 
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");
98  }
99  }
100 
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);
106  }
107  }
108 
109  };
110 
111 
112  /***********************/
114  /***********************/
115 
116 }
117 
118 
119 #endif //WRENCH_LOGICALFILESYSTEM_H
wrench::LogicalFileSystem::init
void init()
Initializes the Logical File System (must be called before any other operation on this file system)
Definition: LogicalFileSystem.cpp:53
wrench::LogicalFileSystem::listFilesInDirectory
std::set< WorkflowFile * > listFilesInDirectory(std::string absolute_path)
Get the files in a directory as a set.
Definition: LogicalFileSystem.cpp:198
wrench::LogicalFileSystem::isDirectoryEmpty
bool isDirectoryEmpty(std::string absolute_path)
Checks whether a directory is empty.
Definition: LogicalFileSystem.cpp:100
wrench::LogicalFileSystem::getFreeSpace
double getFreeSpace()
Get the file system's free space.
Definition: LogicalFileSystem.cpp:227
wrench::LogicalFileSystem::removeEmptyDirectory
void removeEmptyDirectory(std::string absolute_path)
Remove an empty directory.
Definition: LogicalFileSystem.cpp:113
wrench::LogicalFileSystem::isFileInDirectory
bool isFileInDirectory(WorkflowFile *file, std::string absolute_path)
Checks whether a file is in a directory.
Definition: LogicalFileSystem.cpp:180
wrench::LogicalFileSystem::doesDirectoryExist
bool doesDirectoryExist(std::string absolute_path)
Checks whether a directory exists.
Definition: LogicalFileSystem.cpp:88
wrench::LogicalFileSystem::LogicalFileSystem
LogicalFileSystem(std::string hostname, StorageService *storage_service, std::string mount_point)
Constructor.
Definition: LogicalFileSystem.cpp:26
wrench::StorageService
The storage service base class.
Definition: StorageService.h:36
wrench
Definition: Alarm.cpp:20
wrench::LogicalFileSystem::createDirectory
void createDirectory(std::string absolute_path)
Create a new directory.
Definition: LogicalFileSystem.cpp:76
wrench::LogicalFileSystem::reserveSpace
void reserveSpace(WorkflowFile *file, std::string absolute_path)
Reserve space for a file that will be stored.
Definition: LogicalFileSystem.cpp:238
wrench::WorkflowFile::getID
std::string getID()
Get the file id.
Definition: WorkflowFile.cpp:44
wrench::LogicalFileSystem::storeFileInDirectory
void storeFileInDirectory(WorkflowFile *file, std::string absolute_path)
Store file in directory.
Definition: LogicalFileSystem.cpp:128
wrench::LogicalFileSystem::unreserveSpace
void unreserveSpace(WorkflowFile *file, std::string absolute_path)
Unreserve space that was saved for a file (likely a failed transfer)
Definition: LogicalFileSystem.cpp:260
wrench::LogicalFileSystem
A class that implements a weak file system abstraction.
Definition: LogicalFileSystem.h:33
wrench::LogicalFileSystem::getTotalCapacity
double getTotalCapacity()
Get the total capacity.
Definition: LogicalFileSystem.cpp:208
wrench::LogicalFileSystem::hasEnoughFreeSpace
bool hasEnoughFreeSpace(double bytes)
Checks whether there is enough space to store some number of bytes.
Definition: LogicalFileSystem.cpp:218
wrench::LogicalFileSystem::removeFileFromDirectory
void removeFileFromDirectory(WorkflowFile *file, std::string absolute_path)
Remove a file in a directory.
Definition: LogicalFileSystem.cpp:151
wrench::WorkflowFile
A data file used/produced by a WorkflowTask in a Workflow.
Definition: WorkflowFile.h:26
wrench::LogicalFileSystem::removeAllFilesInDirectory
void removeAllFilesInDirectory(std::string absolute_path)
Remove all files in a directory.
Definition: LogicalFileSystem.cpp:165