10 #ifndef WRENCH_LOGICALFILESYSTEM_H
11 #define WRENCH_LOGICALFILESYSTEM_H
20 #include <wrench/data_file/DataFile.h>
45 void reserveSpace(std::shared_ptr<DataFile>file, std::string absolute_path);
46 void unreserveSpace(std::shared_ptr<DataFile>file, std::string absolute_path);
63 void stageFile(std::shared_ptr<DataFile> file, std::string absolute_path);
65 static std::map<std::string, StorageService *> mount_points;
67 std::map<std::string, std::set<std::shared_ptr<DataFile>>> content;
71 std::string mount_point;
72 double total_capacity;
73 double occupied_space;
74 std::map<std::string, double> reserved_space;
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");
83 void assertDirectoryExist(std::string absolute_path) {
85 throw std::invalid_argument(
"LogicalFileSystem::assertDirectoryExists(): directory " + absolute_path +
" does not exist");
89 void assertDirectoryDoesNotExist(std::string absolute_path) {
91 throw std::invalid_argument(
"LogicalFileSystem::assertDirectoryExists(): directory " + absolute_path +
" already exists");
95 void assertDirectoryIsEmpty(std::string absolute_path) {
96 assertDirectoryExist(absolute_path);
98 throw std::invalid_argument(
"LogicalFileSystem::assertDirectoryIsEmpty(): directory " + absolute_path +
"is not empty");
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);
120 #endif //WRENCH_LOGICALFILESYSTEM_H
void init()
Initializes the Logical File System (must be called before any other operation on this file system)
Definition: LogicalFileSystem.cpp:53
bool isDirectoryEmpty(std::string absolute_path)
Checks whether a directory is empty.
Definition: LogicalFileSystem.cpp:100
std::set< std::shared_ptr< DataFile > > listFilesInDirectory(std::string absolute_path)
Get the files in a directory as a set.
Definition: LogicalFileSystem.cpp:198
double getFreeSpace()
Get the file system's free space.
Definition: LogicalFileSystem.cpp:227
void removeEmptyDirectory(std::string absolute_path)
Remove an empty directory.
Definition: LogicalFileSystem.cpp:113
bool doesDirectoryExist(std::string absolute_path)
Checks whether a directory exists.
Definition: LogicalFileSystem.cpp:88
LogicalFileSystem(std::string hostname, StorageService *storage_service, std::string mount_point)
Constructor.
Definition: LogicalFileSystem.cpp:26
bool isFileInDirectory(std::shared_ptr< DataFile >file, std::string absolute_path)
Checks whether a file is in a directory.
Definition: LogicalFileSystem.cpp:180
The storage service base class.
Definition: StorageService.h:36
Definition: Action.cpp:28
void createDirectory(std::string absolute_path)
Create a new directory.
Definition: LogicalFileSystem.cpp:76
void removeFileFromDirectory(std::shared_ptr< DataFile >file, std::string absolute_path)
Remove a file in a directory.
Definition: LogicalFileSystem.cpp:151
void unreserveSpace(std::shared_ptr< DataFile >file, std::string absolute_path)
Unreserve space that was saved for a file (likely a failed transfer)
Definition: LogicalFileSystem.cpp:260
void reserveSpace(std::shared_ptr< DataFile >file, std::string absolute_path)
Reserve space for a file that will be stored.
Definition: LogicalFileSystem.cpp:238
A class that implements a weak file system abstraction.
Definition: LogicalFileSystem.h:34
double getTotalCapacity()
Get the total capacity.
Definition: LogicalFileSystem.cpp:208
bool hasEnoughFreeSpace(double bytes)
Checks whether there is enough space to store some number of bytes.
Definition: LogicalFileSystem.cpp:218
void removeAllFilesInDirectory(std::string absolute_path)
Remove all files in a directory.
Definition: LogicalFileSystem.cpp:165
void storeFileInDirectory(std::shared_ptr< DataFile >file, std::string absolute_path)
Store file in directory.
Definition: LogicalFileSystem.cpp:128