StorageService.h
1 
11 #ifndef WRENCH_STORAGESERVICE_H
12 #define WRENCH_STORAGESERVICE_H
13 
14 
15 #include <string>
16 #include <set>
17 #include <wrench/workflow/job/StandardJob.h>
18 
19 #include "wrench/services/Service.h"
20 #include "wrench/workflow/execution_events/FailureCause.h"
21 
22 namespace wrench {
23 
24  class Simulation;
25 
26  class WorkflowFile;
27 
28  class FailureCause;
29 
30  class FileRegistryService;
31 
35  class StorageService : public Service {
36 
37  public:
38 
39  /***********************/
41  /***********************/
42 
43  void stop();
44 
45  virtual double getFreeSpace();
46 
47  double getTotalSpace();
48 
49  virtual bool lookupFile(WorkflowFile *file);
50 
51  virtual bool lookupFile(WorkflowFile *file, std::string dst_dir);
52 
53  virtual void deleteFile(WorkflowFile *file, FileRegistryService *file_registry_service=nullptr);
54 
55  virtual void deleteFile(WorkflowFile *file, std::string dst_dir, FileRegistryService *file_registry_service=nullptr);
56 
57  /***********************/
59  /***********************/
60 
61 
62  virtual void readFile(WorkflowFile *file, std::string src_dir);
63 
64  virtual void writeFile(WorkflowFile *file, std::string dst_dir);
65 
66  virtual void deleteFile(WorkflowFile *file, WorkflowJob* job, FileRegistryService *file_registry_service=nullptr);
67 
68  virtual bool lookupFile(WorkflowFile *file, WorkflowJob*);
69 
70  virtual void copyFile(WorkflowFile *file, StorageService *src, std::string src_dir, std::string dst_dir);
71 
72  virtual void copyFile(WorkflowFile *file, StorageService *src);
73 
74  virtual void copyFile(WorkflowFile *file, StorageService *src, WorkflowJob* src_job, WorkflowJob* dst_job);
75 
76  virtual void initiateFileCopy(std::string answer_mailbox,
77  WorkflowFile *file,
78  StorageService *src,
79  std::string src_dir,
80  std::string dst_dir);
81 
82  virtual void readFile(WorkflowFile *file);
83 
84  virtual void readFile(WorkflowFile *file, WorkflowJob* job);
85 
86  virtual void initiateFileRead(std::string mailbox_that_should_receive_file_content, WorkflowFile *file, std::string src_dir);
87 
88  virtual void writeFile(WorkflowFile *file);
89 
90  virtual void writeFile(WorkflowFile *file, WorkflowJob* job);
91 
92  static void readFiles(std::set<WorkflowFile *> files,
93  std::map<WorkflowFile *, StorageService *> file_locations,
94  StorageService *default_storage_service,
95  std::set<WorkflowFile*>& files_in_scratch,
96  WorkflowJob* job = nullptr);
97 
98  static void writeFiles(std::set<WorkflowFile *> files,
99  std::map<WorkflowFile *, StorageService *> file_locations,
100  StorageService *default_storage_service,
101  std::set<WorkflowFile*>& files_in_scratch,
102  WorkflowJob* job = nullptr);
103 
104  static void deleteFiles(std::set<WorkflowFile *> files,
105  std::map<WorkflowFile *, StorageService *> file_locations,
106  StorageService *default_storage_service);
107 
108  StorageService(const std::string &hostname,
109  const std::string &service_name,
110  const std::string &data_mailbox_name_prefix,
111  double capacity);
112 
113 
114  protected:
115 
116  friend class Simulation;
117  friend class FileRegistryService;
118 
119 
120  void stageFile(WorkflowFile *);
121 
122  void removeFileFromStorage(WorkflowFile *, std::string);
123 
125  std::map<std::string, std::set<WorkflowFile *>> stored_files;
127  double capacity;
129  double occupied_space = 0;
130 
131  /***********************/
133  /***********************/
134 
135  private:
136 
137  enum FileOperation {
138  READ,
139  WRITE,
140  };
141 
142  static void writeOrReadFiles(FileOperation action, std::set<WorkflowFile *> files,
143  std::map<WorkflowFile *, StorageService *> file_locations,
144  StorageService *default_storage_service, std::set<WorkflowFile*>& files_in_scratch,
145  WorkflowJob* job);
146 
147 
148  };
149 
150  /***********************/
152  /***********************/
153 
154 };
155 
156 
157 #endif //WRENCH_STORAGESERVICE_H
static void deleteFiles(std::set< WorkflowFile *> files, std::map< WorkflowFile *, StorageService *> file_locations, StorageService *default_storage_service)
Synchronously and sequentially delete a set of files from storage services.
Definition: StorageService.cpp:749
virtual void copyFile(WorkflowFile *file, StorageService *src, std::string src_dir, std::string dst_dir)
Synchronously ask the storage service to read a file from another storage service.
Definition: StorageService.cpp:859
virtual void readFile(WorkflowFile *file, std::string src_dir)
Synchronously read a file from the storage service.
Definition: StorageService.cpp:317
A service that can be added to the simulation and that can be used by a WMS when executing a workflow...
Definition: Service.h:26
static void readFiles(std::set< WorkflowFile *> files, std::map< WorkflowFile *, StorageService *> file_locations, StorageService *default_storage_service, std::set< WorkflowFile *> &files_in_scratch, WorkflowJob *job=nullptr)
Synchronously and sequentially read a set of files from storage services.
Definition: StorageService.cpp:494
Abstraction of a job used for executing tasks in a Workflow.
Definition: WorkflowJob.h:31
A data file used/produced by a WorkflowTask in a Workflow.
Definition: WorkflowFile.h:26
void stop()
Stop the service.
Definition: StorageService.cpp:115
virtual bool lookupFile(WorkflowFile *file)
Synchronously asks the storage service whether it holds a file.
Definition: StorageService.cpp:176
std::string hostname
The name of the host on which the daemon is running.
Definition: S4U_Daemon.h:47
virtual void initiateFileCopy(std::string answer_mailbox, WorkflowFile *file, StorageService *src, std::string src_dir, std::string dst_dir)
Asynchronously ask the storage service to read a file from another storage service.
Definition: StorageService.cpp:926
A class that provides basic simulation methods.
Definition: Simulation.h:34
virtual void writeFile(WorkflowFile *file, std::string dst_dir)
Synchronously write a file to the storage service.
Definition: StorageService.cpp:424
virtual void initiateFileRead(std::string mailbox_that_should_receive_file_content, WorkflowFile *file, std::string src_dir)
Asynchronously read a file from the storage service.
Definition: StorageService.cpp:982
void stageFile(WorkflowFile *)
Store a file on the storage service BEFORE the simulation is launched.
Definition: StorageService.cpp:51
double occupied_space
The storage service&#39;s occupied space.
Definition: StorageService.h:129
void removeFileFromStorage(WorkflowFile *, std::string)
Remove a file from storage (internal method)
Definition: StorageService.cpp:85
static void writeFiles(std::set< WorkflowFile *> files, std::map< WorkflowFile *, StorageService *> file_locations, StorageService *default_storage_service, std::set< WorkflowFile *> &files_in_scratch, WorkflowJob *job=nullptr)
Synchronously and sequentially upload a set of files from storage services.
Definition: StorageService.cpp:522
virtual double getFreeSpace()
Synchronously asks the storage service for its capacity.
Definition: StorageService.cpp:134
A file registry service (a.k.a. replica catalog) that holds a database of which files are available a...
Definition: FileRegistryService.h:33
double getTotalSpace()
Get the total static capacity of the storage service (in zero simulation time)
Definition: StorageService.cpp:1046
double capacity
The storage service&#39;s capacity.
Definition: StorageService.h:127
The storage service base class.
Definition: StorageService.h:35
std::map< std::string, std::set< WorkflowFile * > > stored_files
The map of file directories and the set of files stored on those directories inside the storage servi...
Definition: StorageService.h:125
Definition: TerminalOutput.cpp:15
virtual void deleteFile(WorkflowFile *file, FileRegistryService *file_registry_service=nullptr)
Synchronously asks the storage service to delete a file copy.
Definition: StorageService.cpp:638
StorageService(const std::string &hostname, const std::string &service_name, const std::string &data_mailbox_name_prefix, double capacity)
Constructor.
Definition: StorageService.cpp:31