1#ifndef CAPIO_CL_ENGINE_H
2#define CAPIO_CL_ENGINE_H
6#include "capiocl/monitor.h"
7#include "capiocl/serializer.h"
8#include "capiocl/webapi.h"
29 bool store_all_in_memory =
false;
38 std::string node_name;
41 std::string workflow_name;
44 std::unique_ptr<webapi::CapioClWebApiServer> webapi_server;
49 struct CapioCLEntry final {
50 std::vector<std::string> producers;
51 std::vector<std::string> consumers;
52 std::vector<std::filesystem::path> file_dependencies;
55 long directory_children_count = 0;
56 long commit_on_close_count = 0;
57 bool enable_directory_count_update =
true;
58 bool store_in_memory =
false;
59 bool permanent =
false;
60 bool excluded =
false;
67 mutable std::unordered_map<std::string, CapioCLEntry> _capio_cl_entries;
79 static std::string truncateLastN(
const std::string &str,
const std::size_t n) {
80 if (str.length() > n) {
81 return "[..] " + str.substr(str.length() - n);
90 void _newFile(
const std::filesystem::path &path)
const;
104 void compute_directory_entry_count(
const std::filesystem::path &path)
const;
108 explicit Engine(
bool use_default_settings =
true);
120 bool contains(
const std::filesystem::path &file)
const;
137 void add(std::filesystem::path &path, std::vector<std::string> &producers,
138 std::vector<std::string> &consumers,
const std::string &commit_rule,
139 const std::string &fire_rule,
bool permanent,
bool exclude,
140 std::vector<std::filesystem::path> &dependencies);
148 void addProducer(
const std::filesystem::path &path, std::string &producer);
156 void addConsumer(
const std::filesystem::path &path, std::string &consumer);
166 std::filesystem::path &file_dependency);
174 void newFile(
const std::filesystem::path &path);
180 void remove(
const std::filesystem::path &path)
const;
188 void setCommitRule(
const std::filesystem::path &path,
const std::string &commit_rule);
196 void setFireRule(
const std::filesystem::path &path,
const std::string &fire_rule);
203 void setPermanent(
const std::filesystem::path &path,
bool value);
210 void setExclude(
const std::filesystem::path &path,
bool value);
222 void setFile(
const std::filesystem::path &path);
253 void setFileDeps(
const std::filesystem::path &path,
254 const std::vector<std::filesystem::path> &dependencies);
287 std::string
getCommitRule(
const std::filesystem::path &path)
const;
290 std::string
getFireRule(
const std::filesystem::path &path)
const;
293 std::vector<std::string>
getProducers(
const std::filesystem::path &path)
const;
296 std::vector<std::string>
getConsumers(
const std::filesystem::path &path)
const;
302 std::vector<std::filesystem::path>
309 std::set<std::string>
getHomeNode(
const std::filesystem::path &path)
const;
312 void setHomeNode(
const std::filesystem::path &path)
const;
323 bool isProducer(
const std::filesystem::path &path,
const std::string &app_name)
const;
331 bool isConsumer(
const std::filesystem::path &path,
const std::string &app_name)
const;
338 bool isFirable(
const std::filesystem::path &path)
const;
345 bool isFile(
const std::filesystem::path &path)
const;
352 bool isExcluded(
const std::filesystem::path &path)
const;
359 bool isDirectory(
const std::filesystem::path &path)
const;
373 bool isPermanent(
const std::filesystem::path &path)
const;
380 bool isCommitted(
const std::filesystem::path &path)
const;
386 void setCommitted(
const std::filesystem::path &path)
const;
392 std::vector<std::string>
getPaths()
const;
417 void startApiServer(
const std::string &address =
"127.0.0.1",
int port = 5520);
Load configuration and store it from a CAPIO-CL TOML configuration file.
Definition configuration.h:31
bool isDirectory(const std::filesystem::path &path) const
Check if a path is a directory.
Definition Engine.cpp:468
void setStoreFileInFileSystem(const std::filesystem::path &path)
Store the file on the file system.
Definition Engine.cpp:642
void setDirectory(const std::filesystem::path &path)
Mark a path as a directory.
Definition Engine.cpp:430
std::set< std::string > getHomeNode(const std::filesystem::path &path) const
Get the home node of a file.
Definition Engine.cpp:681
bool isStoredInMemory(const std::filesystem::path &path) const
Check if a file is stored in memory.
Definition Engine.cpp:655
void setCommitted(const std::filesystem::path &path) const
Definition Engine.cpp:405
const std::string & getWorkflowName() const
Get current workflow name loaded from memory.
Definition Engine.cpp:640
bool contains(const std::filesystem::path &file) const
Check whether a file is contained in the configuration. The lookup is performed by exact match or by ...
Definition Engine.cpp:204
bool isProducer(const std::filesystem::path &path, const std::string &app_name) const
Check if a process is a producer for a file.
Definition Engine.cpp:553
void loadConfiguration(const std::string &path)
Definition Engine.cpp:762
void setCommitedCloseNumber(const std::filesystem::path &path, long num)
Set the commit-on-close counter. The file will be committed after num close operations.
Definition Engine.cpp:476
std::vector< std::filesystem::path > getCommitOnFileDependencies(const std::filesystem::path &path) const
Get file dependencies.
Definition Engine.cpp:609
bool isPermanent(const std::filesystem::path &path) const
Check if file should remain on file system after workflow terminates.
Definition Engine.cpp:388
long getCommitCloseCount(const std::filesystem::path::iterator::reference &path) const
Get the commit-on-close counter for a file.
Definition Engine.cpp:594
std::vector< std::string > getPaths() const
Definition Engine.cpp:409
void addFileDependency(const std::filesystem::path &path, std::filesystem::path &file_dependency)
Add a new file dependency, when rule is commit_on_file As a side effect, the file identified by path,...
Definition Engine.cpp:286
bool isCommitted(const std::filesystem::path &path) const
Definition Engine.cpp:401
std::vector< std::string > getConsumers(const std::filesystem::path &path) const
Get the consumers of a file.
Definition Engine.cpp:514
void addProducer(const std::filesystem::path &path, std::string &producer)
Add a new producer to a file entry.
Definition Engine.cpp:247
void startApiServer(const std::string &address="127.0.0.1", int port=5520)
Definition Engine.cpp:776
std::string getCommitRule(const std::filesystem::path &path) const
Get the commit rule of a file.
Definition Engine.cpp:320
void setStoreFileInMemory(const std::filesystem::path &path)
Store the file in memory only.
Definition Engine.cpp:616
size_t size() const
return the number of entries in the current configuration
Definition Engine.cpp:210
void setFireRule(const std::filesystem::path &path, const std::string &fire_rule)
Set the fire rule of a file.
Definition Engine.cpp:346
std::vector< std::string > getProducers(const std::filesystem::path &path) const
Get the producers of a file.
Definition Engine.cpp:541
std::vector< std::string > getFileToStoreInMemory() const
Get the list of files stored in memory.
Definition Engine.cpp:668
bool isFile(const std::filesystem::path &path) const
Check if a path refers to a file.
Definition Engine.cpp:456
std::string getFireRule(const std::filesystem::path &path) const
Get the fire rule of a file.
Definition Engine.cpp:333
long getDirectoryFileCount(const std::filesystem::path &path) const
Get the expected number of files in a directory.
Definition Engine.cpp:235
void setDirectoryFileCount(const std::filesystem::path &path, long num)
Sets the expected number of files in a directory.
Definition Engine.cpp:490
void newFile(const std::filesystem::path &path)
Create a new CAPIO file entry. Commit and fire rules are automatically computed using the longest pre...
Definition Engine.cpp:233
void setFile(const std::filesystem::path &path)
Mark a path as a file.
Definition Engine.cpp:443
void remove(const std::filesystem::path &path) const
Remove a file from the configuration.
Definition Engine.cpp:506
void useDefaultConfiguration()
Definition Engine.cpp:768
void setWorkflowName(const std::string &name)
Definition Engine.cpp:636
bool isConsumer(const std::filesystem::path &path, const std::string &app_name) const
Check if a process is a consumer for a file.
Definition Engine.cpp:521
void setPermanent(const std::filesystem::path &path, bool value)
Mark a file as permanent or not.
Definition Engine.cpp:375
bool isExcluded(const std::filesystem::path &path) const
Check if a path is excluded.
Definition Engine.cpp:689
bool operator==(const Engine &other) const
Check for equality between two instances of Engine.
Definition Engine.cpp:702
bool isFirable(const std::filesystem::path &path) const
Check if a file is firable, that is fire rule is no_update.
Definition Engine.cpp:362
void addConsumer(const std::filesystem::path &path, std::string &consumer)
Add a new consumer to a file entry.
Definition Engine.cpp:268
void add(std::filesystem::path &path, std::vector< std::string > &producers, std::vector< std::string > &consumers, const std::string &commit_rule, const std::string &fire_rule, bool permanent, bool exclude, std::vector< std::filesystem::path > &dependencies)
Add a new CAPIO-CL configuration entry.
Definition Engine.cpp:212
void print() const
Print the current CAPIO-CL configuration.
Definition Engine.cpp:11
void setAllStoreInMemory()
set all files to be stored in memory. Once this method is called, all new files will be stored in mem...
Definition Engine.cpp:629
void setCommitRule(const std::filesystem::path &path, const std::string &commit_rule)
Set the commit rule of a file.
Definition Engine.cpp:304
Engine(bool use_default_settings=true)
Class constructor.
Definition Engine.cpp:130
void setFileDeps(const std::filesystem::path &path, const std::vector< std::filesystem::path > &dependencies)
Set the dependencies of a file. This method as a side effect sets the commit rule to Commit on Files.
Definition Engine.cpp:572
void setHomeNode(const std::filesystem::path &path) const
Set the home node for a given path.
Definition Engine.cpp:685
void setExclude(const std::filesystem::path &path, bool value)
Mark a file as excluded or not.
Definition Engine.cpp:417
Class to monitor runtime dependent information on CAPIO-CL related paths, such as commitment status a...
Definition monitor.h:295
Dump the current loaded CAPIO-CL configuration from class Engine to a CAPIO-CL configuration file.
Definition serializer.h:30
constexpr char ON_TERMINATION[]
CoT Streaming Rule.
Definition capiocl.hpp:45
Namespace containing the CAPIO-CL Engine.
Definition engine.h:11
constexpr char UPDATE[]
FoC Streaming Rule.
Definition capiocl.hpp:18