diff --git a/include/wrench/managers/DataMovementManager.h b/include/wrench/managers/DataMovementManager.h index f2997614eb..7e1562606f 100644 --- a/include/wrench/managers/DataMovementManager.h +++ b/include/wrench/managers/DataMovementManager.h @@ -84,8 +84,7 @@ namespace wrench { bool operator==(const CopyRequestSpecs &rhs) const { return (file == rhs.file) && (dst->getStorageService() == rhs.dst->getStorageService()) && - (dst->getMountPoint() == rhs.dst->getMountPoint()) && - (dst->getDirectory() == rhs.dst->getDirectory()); + (dst->getAbsolutePathAtMountPoint() == rhs.dst->getAbsolutePathAtMountPoint()); } }; diff --git a/include/wrench/services/storage/storage_helpers/FileLocation.h b/include/wrench/services/storage/storage_helpers/FileLocation.h index 2e3fedbee0..425c71e266 100644 --- a/include/wrench/services/storage/storage_helpers/FileLocation.h +++ b/include/wrench/services/storage/storage_helpers/FileLocation.h @@ -29,23 +29,18 @@ namespace wrench { static std::shared_ptr LOCATION(std::shared_ptr ss); static std::shared_ptr LOCATION(std::shared_ptr ss, - std::string mp); - - static std::shared_ptr LOCATION(std::shared_ptr ss, - std::string mp, - std::string dir); + std::string absolute_path); std::shared_ptr getStorageService(); std::string getMountPoint(); - std::string getDirectory(); + std::string getAbsolutePathAtMountPoint(); std::string toString(); bool operator==(const std::shared_ptr &rhs) { return ((this->getStorageService() == rhs->getStorageService()) and - (this->getMountPoint() == rhs->getMountPoint()) and - (this->getDirectory() == rhs->getDirectory())); + (this->getAbsolutePathAtMountPoint() == rhs->getAbsolutePathAtMountPoint())); } /** @@ -57,20 +52,24 @@ namespace wrench { return not FileLocation::operator==(rhs); } + private: + friend class LogicalFileSystem; + /** * @brief Constructor * @param ss: the storage service - * @param mp: the mount point - * @param dir: the directory + * @param ap: the absolute path */ - FileLocation(std::shared_ptr ss, std::string mp, std::string dir) : - storage_service(ss), mount_point(mp), directory(dir) { } + FileLocation(std::shared_ptr ss, std::string mp, std::string apamp) : + storage_service(ss), mount_point(mp), absolute_path_at_mount_point(apamp) { } std::shared_ptr storage_service; std::string mount_point; - std::string directory; + std::string absolute_path_at_mount_point; + + static std::string sanitizePath(std::string path); }; diff --git a/include/wrench/simulation/Simulation.h b/include/wrench/simulation/Simulation.h index 7164c97a71..3903a3f94f 100644 --- a/include/wrench/simulation/Simulation.h +++ b/include/wrench/simulation/Simulation.h @@ -58,16 +58,8 @@ namespace wrench { static double getHostMemoryCapacity(std::string hostname); static unsigned long getHostNumCores(std::string hostname); static double getHostFlopRate(std::string hostname); - static bool isHostOn(std::string hostname); - static void turnOnHost(std::string hostname); - static void turnOffHost(std::string hostname); - static bool isLinkOn(std::string linkname); - static void turnOnLink(std::string linkname); - static void turnOffLink(std::string linkname); void launch(); - bool isRunning(); - /** * @brief Method to add a service to the simulation @@ -82,14 +74,8 @@ namespace wrench { return s; } - void addService(std::shared_ptr service); - void addService(std::shared_ptr service); - void addService(std::shared_ptr service); - void addService(std::shared_ptr service); - void addService(std::shared_ptr service); - void stageFile(WorkflowFile *file, std::shared_ptr location); - void stageFiles(std::map> file_locations); + void stageFile(WorkflowFile *file, std::shared_ptr storage_service, std::string absolute_path); SimulationOutput &getOutput(); @@ -99,19 +85,29 @@ namespace wrench { // double getEnergyTimestamp(const std::string &hostname, bool can_record = false); // pstate related calls - void setPstate(const std::string &hostname, int pstate); static int getNumberofPstates(const std::string &hostname); - static int getCurrentPstate(const std::string &hostname); static double getMinPowerConsumption(const std::string &hostname); static double getMaxPowerConsumption(const std::string &hostname); static std::vector getListOfPstates(const std::string &hostname); + void stageFile(WorkflowFile *file, std::shared_ptr location); /***********************/ /** \cond DEVELOPER */ /***********************/ + static bool isHostOn(std::string hostname); + static void turnOnHost(std::string hostname); + static void turnOffHost(std::string hostname); + static bool isLinkOn(std::string linkname); + static void turnOnLink(std::string linkname); + static void turnOffLink(std::string linkname); + + // pstate related calls + void setPstate(const std::string &hostname, int pstate); + static int getCurrentPstate(const std::string &hostname); + std::shared_ptr startNewService(ComputeService *service); std::shared_ptr startNewService(StorageService *service); @@ -151,8 +147,14 @@ namespace wrench { std::set> storage_services; void checkSimulationSetup(); + bool isRunning(); void startAllProcesses(); + void addService(std::shared_ptr service); + void addService(std::shared_ptr service); + void addService(std::shared_ptr service); + void addService(std::shared_ptr service); + void addService(std::shared_ptr service); std::string getWRENCHVersionString() { return WRENCH_VERSION_STRING; } @@ -161,7 +163,7 @@ namespace wrench { unsigned int on_state_change_callback_id; - }; + }; }; diff --git a/src/wrench/services/compute/bare_metal/BareMetalComputeService.cpp b/src/wrench/services/compute/bare_metal/BareMetalComputeService.cpp index b70dff5d2a..3da5e70e99 100644 --- a/src/wrench/services/compute/bare_metal/BareMetalComputeService.cpp +++ b/src/wrench/services/compute/bare_metal/BareMetalComputeService.cpp @@ -977,8 +977,8 @@ namespace wrench { try { StorageService::deleteFile(f, FileLocation::LOCATION(this->getScratch(), - this->getScratch()->getMountPoint(), - job->getName()), + this->getScratch()->getMountPoint() + + "/" + job->getName()), nullptr); } catch (WorkflowExecutionException &e) { // ignore (perhaps it was never written) @@ -1166,8 +1166,7 @@ namespace wrench { for (auto const &f : this->files_in_scratch[job]) { StorageService::deleteFile(f, FileLocation::LOCATION(this->getScratch(), - this->getScratch()->getMountPoint(), - job->getName()), + this->getScratch()->getMountPoint() + job->getName()), nullptr); } this->files_in_scratch[job].clear(); @@ -1523,11 +1522,7 @@ namespace wrench { dict, this->getMessagePayloadValue( ComputeServiceMessagePayload::RESOURCE_DESCRIPTION_ANSWER_MESSAGE_PAYLOAD)); -// try { S4U_Mailbox::dputMessage(answer_mailbox, answer_message); -// } catch (std::shared_ptr &cause) { -// return; -// } } /** @@ -1541,7 +1536,7 @@ namespace wrench { try { StorageService::deleteFile(f, FileLocation::LOCATION(this->getScratch(), - this->getScratch()->getMountPoint(), + this->getScratch()->getMountPoint() + j.first->getName())); } catch (WorkflowExecutionException &e) { throw; diff --git a/src/wrench/services/file_registry/FileRegistryService.cpp b/src/wrench/services/file_registry/FileRegistryService.cpp index 50a5b9f621..2570cd3e54 100644 --- a/src/wrench/services/file_registry/FileRegistryService.cpp +++ b/src/wrench/services/file_registry/FileRegistryService.cpp @@ -391,7 +391,7 @@ namespace wrench { for (auto const &l : this->entries[file]) { if ((l->getStorageService() == location->getStorageService()) && (l->getMountPoint() == location->getMountPoint()) && - (l->getDirectory() == location->getDirectory())) { + (l->getAbsolutePathAtMountPoint() == location->getAbsolutePathAtMountPoint())) { this->entries[file].erase(l); return true; } diff --git a/src/wrench/services/storage/StorageService.cpp b/src/wrench/services/storage/StorageService.cpp index f45fd48fc0..f78f5f4c73 100644 --- a/src/wrench/services/storage/StorageService.cpp +++ b/src/wrench/services/storage/StorageService.cpp @@ -83,7 +83,7 @@ namespace wrench { */ void StorageService::stageFile(WorkflowFile *file, std::shared_ptr location) { - location->getStorageService()->stageFile(file, location->getMountPoint(), location->getDirectory()); + location->getStorageService()->stageFile(file, location->getMountPoint(), location->getAbsolutePathAtMountPoint()); } /** @@ -630,7 +630,7 @@ namespace wrench { */ std::string StorageService::getMountPoint() { if (this->hasMultipleMountPoints()) { - throw std::invalid_argument("StorageService::getMountPoint(): The storage service has more than one mount point"); + throw std::invalid_argument("StorageService::getAbsolutePath(): The storage service has more than one mount point"); } return this->file_systems.begin()->first; } diff --git a/src/wrench/services/storage/simple/SimpleStorageService.cpp b/src/wrench/services/storage/simple/SimpleStorageService.cpp index 1dc21d5ec2..5310c190f4 100644 --- a/src/wrench/services/storage/simple/SimpleStorageService.cpp +++ b/src/wrench/services/storage/simple/SimpleStorageService.cpp @@ -179,7 +179,7 @@ namespace wrench { } else if (auto msg = std::dynamic_pointer_cast(message)) { auto fs = this->file_systems[msg->location->getMountPoint()].get(); - bool file_found = fs->isFileInDirectory(msg->file, msg->location->getDirectory()); + bool file_found = fs->isFileInDirectory(msg->file, msg->location->getAbsolutePathAtMountPoint()); S4U_Mailbox::dputMessage(msg->answer_mailbox, new StorageServiceFileLookupAnswerMessage(msg->file, file_found, @@ -230,15 +230,15 @@ namespace wrench { bool SimpleStorageService::processFileWriteRequest(WorkflowFile *file, std::shared_ptr location, std::string answer_mailbox, unsigned long buffer_size) { - auto fs = this->file_systems[location->getMountPoint()].get(); + auto fs = this->file_systems[location->getAbsolutePathAtMountPoint()].get(); // If the file is not already there, do a capacity check/update // (If the file is already there, then there will just be an overwrite. Note that // if the overwrite fails, then the file will disappear, which is expected) - if ((not fs->doesDirectoryExist(location->getDirectory())) or - (not fs->isFileInDirectory(file, location->getDirectory()))) { + if ((not fs->doesDirectoryExist(location->getAbsolutePathAtMountPoint())) or + (not fs->isFileInDirectory(file, location->getAbsolutePathAtMountPoint()))) { if (not fs->hasEnoughFreeSpace(file->getSize())) { try { @@ -315,10 +315,10 @@ namespace wrench { // Figure out whether this succeeds or not std::shared_ptr failure_cause = nullptr; - auto fs = this->file_systems[location->getMountPoint()].get(); + auto fs = this->file_systems[location->getAbsolutePathAtMountPoint()].get(); - if ((not fs->doesDirectoryExist(location->getDirectory())) or - (not fs->isFileInDirectory(file, location->getDirectory()))) { + if ((not fs->doesDirectoryExist(location->getAbsolutePathAtMountPoint())) or + (not fs->isFileInDirectory(file, location->getAbsolutePathAtMountPoint()))) { WRENCH_INFO("Received a a read request for a file I don't have (%s)", location->toString().c_str()); failure_cause = std::shared_ptr( new FileNotFound(file, location)); @@ -378,11 +378,11 @@ namespace wrench { // if the overwrite fails, then the file will disappear, which is expected) // File System at the destination - auto fs = this->file_systems[dst_location->getMountPoint()].get(); + auto fs = this->file_systems[dst_location->getAbsolutePathAtMountPoint()].get(); - if ((not fs->doesDirectoryExist(dst_location->getDirectory())) or - (not fs->isFileInDirectory(file, dst_location->getDirectory()))) { + if ((not fs->doesDirectoryExist(dst_location->getAbsolutePathAtMountPoint())) or + (not fs->isFileInDirectory(file, dst_location->getAbsolutePathAtMountPoint()))) { if (not fs->hasEnoughFreeSpace(file->getSize())) { @@ -484,7 +484,7 @@ namespace wrench { if (dst_location and (dst_location->getStorageService().get() == this)) { if (success) { this->file_systems[dst_location->getMountPoint()]->storeFileInDirectory( - file, dst_location->getDirectory()); + file, dst_location->getAbsolutePathAtMountPoint()); // Deal with time stamps if (start_timestamp != nullptr) { this->simulation->getOutput().addTimestamp( @@ -492,7 +492,7 @@ namespace wrench { } } else { // Process the failure, meaning, just un-decrease the free space - this->file_systems[dst_location->getMountPoint()]->increaseFreeSpace(file->getSize()); + this->file_systems[dst_location->getAbsolutePathAtMountPoint()]->increaseFreeSpace(file->getSize()); } } @@ -532,14 +532,14 @@ namespace wrench { std::string answer_mailbox) { std::shared_ptr failure_cause = nullptr; - auto fs = this->file_systems[location->getMountPoint()].get(); + auto fs = this->file_systems[location->getAbsolutePathAtMountPoint()].get(); - if ((not fs->doesDirectoryExist(location->getDirectory())) or - (not fs->isFileInDirectory(file, location->getDirectory()))) { + if ((not fs->doesDirectoryExist(location->getAbsolutePathAtMountPoint())) or + (not fs->isFileInDirectory(file, location->getAbsolutePathAtMountPoint()))) { failure_cause = std::shared_ptr( new FileNotFound(file, location)); } else { - fs->removeFileFromDirectory(file, location->getDirectory()); + fs->removeFileFromDirectory(file, location->getAbsolutePathAtMountPoint()); } S4U_Mailbox::dputMessage(answer_mailbox, diff --git a/src/wrench/services/storage/storage_helpers/FileLocation.cpp b/src/wrench/services/storage/storage_helpers/FileLocation.cpp index 3fba49e5d6..e44878e5cf 100644 --- a/src/wrench/services/storage/storage_helpers/FileLocation.cpp +++ b/src/wrench/services/storage/storage_helpers/FileLocation.cpp @@ -10,12 +10,15 @@ #include #include #include +#include +#include namespace wrench { + /** - * @brief File location specifier (directory "/") + * @brief File location specifier for a storage service's (single) mount point root * * @param ss: a storage service (that has a single mount point) * @return a file location specification @@ -30,64 +33,58 @@ namespace wrench { throw std::invalid_argument("FileLocation::LOCATION(): Storage Service has multiple mount points. " "Call the version of this method that takes a mount point argument"); } - return LOCATION(ss, *(ss->getMountPoints().begin()), "/"); + return LOCATION(ss, *(ss->getMountPoints().begin())); } /** - * @brief File location specifier (directory = "/") + * @brief File location specifier given an absolute path at a storage service * * @param ss: a storage service - * @param mp: a mount point of the storage service + * @param absolute_path: an absolute path at the storage service to a directory (that may contain files) * @return a file location specification * * @throw std::invalid_argument */ std::shared_ptr FileLocation::LOCATION(std::shared_ptr ss, - std::string mp) { - if (ss == nullptr) { - throw std::invalid_argument("FileLocation::LOCATION(): Cannot pass nullptr storage service"); + std::string absolute_path) { + if ((ss == nullptr) or (absolute_path.empty())) { + throw std::invalid_argument("FileLocation::LOCATION(): Invalid arguments"); } - return LOCATION(ss, mp, "/"); - } - - /** - * @brief File location specifier - * - * @param ss: a storage service - * @param mp: a mount point of the storage service - * @param dir: a directory - * @return a file location specification - * - * @throw std::invalid_argument - */ - std::shared_ptr FileLocation::LOCATION(std::shared_ptr ss, - std::string mp, - std::string dir) { - if (ss == nullptr) { - throw std::invalid_argument("FileLocation::LOCATION(): Cannot pass nullptr storage service"); - } - if (not ss->hasMountPoint(mp)) { - throw std::invalid_argument("FileLocation::LOCATION(): Storage service " + ss->getName() + - " does not have mount point " + mp); + try { + absolute_path = FileLocation::sanitizePath(absolute_path); + } catch (std::invalid_argument &e) { + throw; } - if ((dir != "/") and ss->isScratch()) { - throw std::invalid_argument("FileLocation::LOCATION(): Cannot specify a non-\"/\" directory for a scratch storage service"); - } - if (dir.empty()) { - dir = "/"; + std::string mount_point = ""; + for (auto const &mp : ss->getMountPoints()) { + // This works because we disallowed two mounts from being proper prefixes of each other + if ((mp != "/") and (absolute_path.find(mp) == 0)) { + mount_point = mp; + break; + } + } + if (mount_point.empty()) { + if (ss->hasMountPoint("/")) { + mount_point = "/"; + } else { + throw std::invalid_argument("FileLocation::LOCATION(): Invalid path '" + + absolute_path +"' at storage service '" + ss->getName() + "'"); + } } - return std::shared_ptr(new FileLocation(ss, mp, dir)); + absolute_path.replace(0, mount_point.length(), "/"); + + return std::shared_ptr(new FileLocation(ss, mount_point, absolute_path)); } /** * @brief Give a ::" string for the location */ std::string FileLocation::toString() { - return this->storage_service->getName() + ":" + this->mount_point + ":" + this->directory; + return this->storage_service->getName() + ":" + this->mount_point + this->absolute_path_at_mount_point; } /** @@ -99,20 +96,81 @@ namespace wrench { } /** - * @brief Get the location's storage service's mount point - * @return + * @brief Get the location's mount point + * @return a mount point */ std::string FileLocation::getMountPoint() { return this->mount_point; } + /** + * @brief Get the location's storage service's mount point + * @return + */ + std::string FileLocation::getAbsolutePathAtMountPoint() { + return this->absolute_path_at_mount_point; + } + /** - * @brief Get the location's directory + * @brief Method to sanitize an absolute path + * @param path * @return */ - std::string FileLocation::getDirectory() { - return this->directory; + std::string FileLocation::sanitizePath(std::string path) { + + + if (path.empty()) { + throw std::invalid_argument("FileLocation::sanitizePath(): path cannot be empty"); + } + + // Must terminate with a / + if (path.at(0) != '/') { + throw std::invalid_argument("FileLocation::sanitizePath(): An absolute path must start with '/' (" + path + ")"); + } + + // Cannot have certain substring (why not) + std::string unallowed_characters[] = {"\\", " ", "~", "`", "\"", "&", "*", "?"}; + for (auto const &c : unallowed_characters) { + if (path.find(c) != std::string::npos) { + throw std::invalid_argument("FileLocation::sanitizePath(): Unallowed character '" + c + "' in path (" + path + ")"); + } + } + + // Make it /-terminated + if (path.at(path.length()-1) != '/') { + path = path + "/"; + } + + // Deal with "", "." and ".." + std::vector tokens; + boost::split(tokens, path, boost::is_any_of("/")); + tokens.erase(tokens.begin()); + tokens.pop_back(); + std::vector new_tokens; + + for (auto t : tokens) { + if ((t == ".") or t.empty()) { + // do nothing + } else if (t == "..") { + if (new_tokens.empty()) { + throw std::invalid_argument("FileLocation::sanitizePath(): Invalid path (" + path + ")"); + } else { + new_tokens.pop_back(); + } + } else { + new_tokens.push_back(t); + } + } + + // Reconstruct sanitized path + std::string sanitized = ""; + for (auto const & t : new_tokens) { + sanitized += "/" + t; + } + sanitized += "/"; + + return sanitized; } diff --git a/src/wrench/services/storage/storage_helpers/FileTransferThread.cpp b/src/wrench/services/storage/storage_helpers/FileTransferThread.cpp index 0be90a38cd..35ec8e26f8 100644 --- a/src/wrench/services/storage/storage_helpers/FileTransferThread.cpp +++ b/src/wrench/services/storage/storage_helpers/FileTransferThread.cpp @@ -252,7 +252,8 @@ namespace wrench { // Issue the receive auto req = S4U_Mailbox::igetMessage(mailbox); // Write to disk - S4U_Simulation::writeToDisk(msg->payload, location->getStorageService()->hostname, location->getMountPoint()); + S4U_Simulation::writeToDisk(msg->payload, location->getStorageService()->hostname, + location->getAbsolutePathAtMountPoint()); // Wait for the comm to finish msg = req->wait(); if (auto file_content_chunk_msg = @@ -265,7 +266,8 @@ namespace wrench { } } // I/O for the last chunk - S4U_Simulation::writeToDisk(msg->payload, location->getStorageService()->hostname, location->getMountPoint()); + S4U_Simulation::writeToDisk(msg->payload, location->getStorageService()->hostname, + location->getAbsolutePathAtMountPoint()); } catch (std::shared_ptr &e) { throw; } @@ -300,7 +302,8 @@ namespace wrench { while (remaining > 0) { double chunk_size = std::min(this->buffer_size, remaining); - S4U_Simulation::readFromDisk(chunk_size, location->getStorageService()->hostname, location->getMountPoint()); + S4U_Simulation::readFromDisk(chunk_size, location->getStorageService()->hostname, + location->getAbsolutePathAtMountPoint()); remaining -= this->buffer_size; if (req) { req->wait(); @@ -339,17 +342,21 @@ namespace wrench { } else { // Read the first chunk - S4U_Simulation::readFromDisk(to_send, src_location->getStorageService()->hostname, src_location->getMountPoint()); + S4U_Simulation::readFromDisk(to_send, src_location->getStorageService()->hostname, + src_location->getAbsolutePathAtMountPoint()); // start the pipeline while (remaining > this->buffer_size) { // Write to disk. TODO: Make this asynchronous! - S4U_Simulation::writeToDisk(this->buffer_size, dst_location->getStorageService()->hostname, dst_location->getMountPoint()); - S4U_Simulation::readFromDisk(this->buffer_size, src_location->getStorageService()->hostname, src_location->getMountPoint()); + S4U_Simulation::writeToDisk(this->buffer_size, dst_location->getStorageService()->hostname, + dst_location->getAbsolutePathAtMountPoint()); + S4U_Simulation::readFromDisk(this->buffer_size, src_location->getStorageService()->hostname, + src_location->getAbsolutePathAtMountPoint()); remaining -= this->buffer_size; } // Write the last chunk - S4U_Simulation::writeToDisk(remaining, dst_location->getStorageService()->hostname, dst_location->getMountPoint()); + S4U_Simulation::writeToDisk(remaining, dst_location->getStorageService()->hostname, + dst_location->getAbsolutePathAtMountPoint()); } } @@ -445,7 +452,7 @@ namespace wrench { // Do the I/O S4U_Simulation::writeToDisk(msg->payload, dst_location->getStorageService()->getHostname(), - dst_location->getMountPoint()); + dst_location->getAbsolutePathAtMountPoint()); // Wait for the comm to finish msg = req->wait(); @@ -460,7 +467,7 @@ namespace wrench { // Do the I/O for the last chunk S4U_Simulation::writeToDisk(msg->payload, dst_location->getStorageService()->getHostname(), - dst_location->getMountPoint()); + dst_location->getAbsolutePathAtMountPoint()); } catch (std::shared_ptr &e) { throw WorkflowExecutionException(e); } diff --git a/src/wrench/services/storage/storage_helpers/LocicalFileSystem.cpp b/src/wrench/services/storage/storage_helpers/LocicalFileSystem.cpp index bd536029a0..280f24c526 100644 --- a/src/wrench/services/storage/storage_helpers/LocicalFileSystem.cpp +++ b/src/wrench/services/storage/storage_helpers/LocicalFileSystem.cpp @@ -12,7 +12,6 @@ namespace wrench { - std::set LogicalFileSystem::mount_points; /** @@ -21,11 +20,31 @@ namespace wrench { */ LogicalFileSystem::LogicalFileSystem(std::string hostname, std::string mount_point) { + // Sanitize the mount_point + if (mount_point.at(0) != '/') { + mount_point = "/" + mount_point; + } + if (mount_point.at(mount_point.length()) != '/') { + mount_point += "/"; + } + + mount_point = FileLocation::sanitizePath(mount_point); + // Check uniqueness if (LogicalFileSystem::mount_points.find(hostname+":"+mount_point) != LogicalFileSystem::mount_points.end()) { throw std::invalid_argument("LogicalFileSystem::LogicalFileSystem(): A FileSystem with mount point " + - mount_point + " at host " + hostname + " already exists"); + mount_point + " at host " + hostname + " already exists"); } + // Check non-proper-prefixness + for (auto const &mp : LogicalFileSystem::mount_points) { + if ((mp.find(hostname+":"+mount_point) == 0) or ((hostname+":"+mount_point).find(mp) == 0)) { + throw std::invalid_argument("LogicalFileSystem::LogicalFileSystem(): An existing mount point that " + "has as prefix or is a prefix of '" + mount_point + + "' already exists at" + "host " + hostname); + } + } + + LogicalFileSystem::mount_points.insert(hostname+":"+mount_point); this->mount_point = mount_point; @@ -35,141 +54,141 @@ namespace wrench { } - /** - * @brief Create a new directory - * - * @param absolute_path: the directory's absolute path - * @throw std::invalid_argument - */ +/** + * @brief Create a new directory + * + * @param absolute_path: the directory's absolute path + * @throw std::invalid_argument + */ void LogicalFileSystem::createDirectory(std::string absolute_path) { assertDirectoryDoesNotExist(absolute_path); this->content[absolute_path] = {}; } - /** - * @brief Checks whether a directory exists - * @param absolute_path the directory's absolute path - * @return true if the directory exists - */ +/** + * @brief Checks whether a directory exists + * @param absolute_path the directory's absolute path + * @return true if the directory exists + */ bool LogicalFileSystem::doesDirectoryExist(std::string absolute_path) { return (this->content.find(absolute_path) != this->content.end()); } - /** - * @brief Checks whether a directory is empty - * @param absolute_path: the directory's absolute path - * @return true if the directory is empty - * - * @throw std::invalid_argument - */ +/** + * @brief Checks whether a directory is empty + * @param absolute_path: the directory's absolute path + * @return true if the directory is empty + * + * @throw std::invalid_argument + */ bool LogicalFileSystem::isDirectoryEmpty(std::string absolute_path) { assertDirectoryExist(absolute_path); return (this->content[absolute_path].empty()); } - /** - * @brief Remove an empty directory - * @param absolute_path: the directory's absolute path - * - * @throw std::invalid_argument - */ +/** + * @brief Remove an empty directory + * @param absolute_path: the directory's absolute path + * + * @throw std::invalid_argument + */ void LogicalFileSystem::removeEmptyDirectory(std::string absolute_path) { assertDirectoryExist(absolute_path); assertDirectoryIsEmpty(absolute_path); this->content.erase(absolute_path); } - /** - * @brief Store file in directory - * @param absolute_path: the directory's absolute path - * - * @throw std::invalid_argument - */ +/** + * @brief Store file in directory + * @param absolute_path: the directory's absolute path + * + * @throw std::invalid_argument + */ void LogicalFileSystem::storeFileInDirectory(WorkflowFile *file, std::string absolute_path) { assertDirectoryExist(absolute_path); this->content[absolute_path].insert(file); } - /** - * @brief Remove a file in a directory - * @param file: the file to remove - * @param absolute_path: the directory's absolute path - * - * @throw std::invalid_argument - */ +/** + * @brief Remove a file in a directory + * @param file: the file to remove + * @param absolute_path: the directory's absolute path + * + * @throw std::invalid_argument + */ void LogicalFileSystem::removeFileFromDirectory(WorkflowFile *file, std::string absolute_path) { assertDirectoryExist(absolute_path); assertFileIsInDirectory(file, absolute_path); } - /** - * @brief Remove all files in a directory - * @param absolute_path: the directory's absolute path - * - * @throw std::invalid_argument - */ +/** + * @brief Remove all files in a directory + * @param absolute_path: the directory's absolute path + * + * @throw std::invalid_argument + */ void LogicalFileSystem::removeAllFilesInDirectory(std::string absolute_path) { assertDirectoryExist(absolute_path); this->content[absolute_path].clear(); } - /** - * @brief Checks whether a file is in a directory - * @param file: the file - * @param absolute_path: the directory's absolute path - * - * @return true if the file is present - * - * @throw std::invalid_argument - */ +/** + * @brief Checks whether a file is in a directory + * @param file: the file + * @param absolute_path: the directory's absolute path + * + * @return true if the file is present + * + * @throw std::invalid_argument + */ bool LogicalFileSystem::isFileInDirectory(WorkflowFile *file, std::string absolute_path) { assertDirectoryExist(absolute_path); return (this->content[absolute_path].find(file) != this->content[absolute_path].end()); } - /** - * @brief Get the files in a directory as a set - * @param absolute_path: the directory's absolute path - * - * @return a set of files - * - * @throw std::invalid_argument - */ +/** + * @brief Get the files in a directory as a set + * @param absolute_path: the directory's absolute path + * + * @return a set of files + * + * @throw std::invalid_argument + */ std::set LogicalFileSystem::listFilesInDirectory(std::string absolute_path) { assertDirectoryExist(absolute_path); return this->content[absolute_path]; } - /** - * @brief Get the total capacity - * @return the total capacity - */ +/** + * @brief Get the total capacity + * @return the total capacity + */ double LogicalFileSystem::getTotalCapacity() { return this->total_capacity; } - /** - * @brief Checks whether there is enough space to store some number of bytes - * @param bytes: a number of bytes - * @return true if the number of bytes can fit - */ +/** + * @brief Checks whether there is enough space to store some number of bytes + * @param bytes: a number of bytes + * @return true if the number of bytes can fit + */ bool LogicalFileSystem::hasEnoughFreeSpace(double bytes) { return (this->total_capacity - this->occupied_space) >= bytes; } - /** - * @brief Get the file system's free space - * @return the free space in bytes - */ +/** + * @brief Get the file system's free space + * @return the free space in bytes + */ double LogicalFileSystem::getFreeSpace() { return (this->total_capacity - this->occupied_space); } - /** - * @brief Decrease the amount of free space the service "thinks" it has - * @param num_bytes: the number of bytes by which to decrease - * @throw std::invalid_argument - */ +/** + * @brief Decrease the amount of free space the service "thinks" it has + * @param num_bytes: the number of bytes by which to decrease + * @throw std::invalid_argument + */ void LogicalFileSystem::decreaseFreeSpace(double num_bytes) { if (this->total_capacity - this->occupied_space < num_bytes) { throw std::invalid_argument("LogicalFileSystem::decrementFreeSpace(): Not enough free space"); @@ -177,11 +196,11 @@ namespace wrench { this->occupied_space += num_bytes; } - /** - * @brief Increase the amount of free space the service "thinks" it has - * @param num_bytes: the number of bytes by which to increase - * @throw std::invalid_argument - */ +/** + * @brief Increase the amount of free space the service "thinks" it has + * @param num_bytes: the number of bytes by which to increase + * @throw std::invalid_argument + */ void LogicalFileSystem::increaseFreeSpace(double num_bytes) { if (this->occupied_space + num_bytes > this->total_capacity) { throw std::invalid_argument("LogicalFileSystem::decrementFreeSpace(): No enough capacity"); diff --git a/src/wrench/simulation/Simulation.cpp b/src/wrench/simulation/Simulation.cpp index 63e46b5750..812923bff3 100644 --- a/src/wrench/simulation/Simulation.cpp +++ b/src/wrench/simulation/Simulation.cpp @@ -477,15 +477,29 @@ namespace wrench { } + + + /** + * @brief Stage a copy of a file at the root of a mount point + * of a disk of a storage service + * + * @param file: a file to stage on a storage service + * @param storage_service: a storage service + * @param absolute_path: the absolute path of the directory where the file should be stored + * + * @throw std::runtime_error + * @throw std::invalid_argument + */ + void Simulation::stageFile(WorkflowFile *file, std::shared_ptr storage_service, std::string absolute_path) { + Simulation::stageFile(file, FileLocation::LOCATION(storage_service, absolute_path)); + } + + /** - * @brief Stage a copy of a file on a storage service (to the "/" partition) - * - * @param file: a file to stage on a storage service - * @param storage_service: the storage service - * - * @throw std::runtime_error - * @throw std::invalid_argument - */ + * @brief State a copy of a file on a storage service (to the "/" partition) + * @param file + * @param location + */ void Simulation::stageFile(WorkflowFile *file, std::shared_ptr location) { if (file == nullptr) { @@ -517,26 +531,6 @@ namespace wrench { } } - /** - * @brief Stage file copies on a storage service (to the "/" partition) - * - * @param files: a map of files (indexed by file ids) to stage on a storage service - * @param storage_service: the storage service - * - * @throw std::runtime_error - * @throw std::invalid_argument - */ - void Simulation::stageFiles(std::map> file_locations) { - - try { - for (auto const &fl : file_locations) { - this->stageFile(fl.first, fl.second); - } - } catch (std::invalid_argument &e) { - throw; - } - } - /** * @brief Get the current simulated date * @return a date