Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ killall -USR1 capio_server
> CAPIO-CL configuration file), CAPIO will not be able to operate correctly!

> [!tip]
> To gracefully shhut down the capio server instance, just send the SIGUSR1 signal.
> To gracefully shut down the capio server instance, just send the SIGUSR1 signal.
> the capio_server process will then automatically clean up and terminate itself!

---
Expand Down
30 changes: 14 additions & 16 deletions src/common/capio/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ constexpr int CAPIO_CACHE_LINE_SIZE_DEFAULT = 32768; // 32K of default
// TODO: use that in communication only uses the file descriptor instead of the path to save on the
// PATH_MAX
constexpr size_t CAPIO_REQ_MAX_SIZE = (PATH_MAX + 256) * sizeof(char);
constexpr char CAPIO_SERVER_CLI_LOG_SERVER[] = "[ \033[1;32m SERVER \033[0m ] ";
constexpr char CAPIO_SERVER_CLI_LOG_SERVER_WARNING[] = "[ \033[1;33m SERVER \033[0m ] ";
constexpr char CAPIO_SERVER_CLI_LOG_SERVER_ERROR[] = "[ \033[1;31m SERVER \033[0m ] ";
constexpr char CAPIO_SERVER_CLI_LOG_SERVER[] = "[\033[1;32mSERVER\033[0m";
constexpr char CAPIO_SERVER_CLI_LOG_SERVER_WARNING[] = "[\033[1;33mSERVER\033[0m";
constexpr char CAPIO_SERVER_CLI_LOG_SERVER_ERROR[] = "[\033[1;31mSERVER\033[0m";
constexpr char LOG_CAPIO_START_REQUEST[] = "\n+++++++++++ SYSCALL %s (%d) +++++++++++";
constexpr char LOG_CAPIO_END_REQUEST[] = "----------- END SYSCALL ----------\n";
constexpr char CAPIO_SERVER_LOG_START_REQUEST_MSG[] = "\n+++++++++++++++++REQUEST+++++++++++++++++";
Expand Down Expand Up @@ -103,22 +103,20 @@ constexpr char CAPIO_LOG_SERVER_BANNER[] =
"\\______/\n\n"
"\033[0m CAPIO - Cross Application Programmable IO \n"
" V. " CAPIO_VERSION "\n\n";
constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_INFO[] = "[ \033[1;32m SERVER \033[0m ] ";
constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_WARNING[] = "[ \033[1;33m SERVER \033[0m ] ";
constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_ERROR[] = "[ \033[1;31m SERVER \033[0m ] ";
constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_JSON[] = "[ \033[1;34m SERVER \033[0m ] ";
constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_INFO[] = "[\033[1;32mSERVER\033[0m";
constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_WARNING[] = "[\033[1;33mSERVER\033[0m";
constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_ERROR[] = "[\033[1;31mSERVER\033[0m";
constexpr char CAPIO_LOG_SERVER_CLI_LEVEL_JSON[] = "[\033[1;34mSERVER\033[0m";
constexpr char CAPIO_LOG_SERVER_CLI_LOGGING_ENABLED_WARNING[] =
"[ \033[1;33m SERVER \033[0m ] "
"[\033[1;33mSERVER\033[0m] "
"|==================================================================|\n"
"[ \033[1;33m SERVER \033[0m ] | you are running a build of CAPIO with "
"[\033[1;33mSERVER\033[0m] | you are running a build of CAPIO with "
"logging enabled. |\n"
"[ \033[1;33m SERVER \033[0m ] | this will have impact on performance. "
"you "
"should recompile CAPIO |\n"
"[ \033[1;33m SERVER \033[0m ] | with -DCAPIO_LOG=FALSE "
" "
" |\n"
"[ \033[1;33m SERVER \033[0m ] "
"[\033[1;33mSERVER\033[0m] | this will have impact on performance. "
"you should recompile CAPIO |\n"
"[\033[1;33mSERVER\033[0m] | with -DCAPIO_LOG=FALSE "
" |\n"
"[\033[1;33mSERVER\033[0m] "
"|==================================================================|\n";
constexpr char CAPIO_LOG_SERVER_CLI_LOGGING_NOT_AVAILABLE[] =
"CAPIO_LOG set but log support was not compiled into CAPIO!";
Expand Down
2 changes: 1 addition & 1 deletion src/common/capio/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ inline std::string get_capio_workflow_name() {
}
#else
LOG("fetching name from workflow_name");
name = workflow_name;
name = capio_global_configuration->workflow_name;
if (name.size() == 0) {
LOG("Falling back to default workflow name");
name = CAPIO_DEFAULT_WORKFLOW_NAME;
Expand Down
18 changes: 8 additions & 10 deletions src/common/capio/shm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@

#define SHM_DESTROY_CHECK(source_name) \
if (shm_unlink(source_name) == -1) { \
std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << " [ " << node_name << " ] " \
<< "Unable to destroy shared mem: '" << source_name << "' (" << strerror(errno) \
<< ")" << std::endl; \
server_println(CAPIO_LOG_SERVER_CLI_LEVEL_ERROR, "Unable to destroy shared mem: '" + \
std::string(source_name) + "' (" + \
strerror(errno) + ")"); \
};

#define SHM_CREATE_CHECK(condition, source) \
if (condition) { \
LOG("error while creating %s", source); \
std::cout << CAPIO_SERVER_CLI_LOG_SERVER_ERROR << " [ " << node_name << " ] " \
<< "Unable to create shm: " << source << std::endl; \
server_println(CAPIO_LOG_SERVER_CLI_LEVEL_ERROR, "Unable to create shared mem: '" + \
std::string(source) + "' (" + \
strerror(errno) + ")"); \
ERR_EXIT("Unable to open shm %s: %s", source, strerror(errno)); \
};

Expand Down Expand Up @@ -75,8 +75,7 @@ class CapioShmCanary {
~CapioShmCanary() {
START_LOG(capio_syscall(SYS_gettid), "call()");
#ifndef __CAPIO_POSIX
std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_WARNING << " [ " << node_name << " ] "
<< "Removing shared memory canary flag" << std::endl;
server_println(CAPIO_LOG_SERVER_CLI_LEVEL_INFO, "Removing shared memory canary flag");
#endif

#ifdef __CAPIO_POSIX
Expand All @@ -89,8 +88,7 @@ class CapioShmCanary {
#endif

#ifndef __CAPIO_POSIX
std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_INFO << " [ " << node_name << " ] "
<< "shutdown completed" << std::endl;
server_println(CAPIO_LOG_SERVER_CLI_LEVEL_INFO, "Shutdown completed");
#endif
}
};
Expand Down
152 changes: 91 additions & 61 deletions src/server/capio-cl-engine/capio_cl_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
class CapioCLEngine {
friend class CapioFileManager;

private:
std::unordered_map<std::string, // path name
std::tuple<std::vector<std::string>, // Vector for producers [0]
std::vector<std::string>, // Vector for consumers [1]
Expand All @@ -34,103 +33,134 @@ class CapioCLEngine {

public:
void print() const {
std::cout << CAPIO_LOG_SERVER_CLI_LEVEL_JSON << " [ " << node_name << " ] "
<< "Composition of expected CAPIO FS: " << std::endl
<< std::endl
<< "|============================================================================"
"==========================================================|"
<< std::endl
<< "|" << std::setw(135) << "|" << std::endl
<< "| Parsed configuration file for workflow: \033[1;36m" << workflow_name
<< std::setw(94 - workflow_name.length()) << "\033[0m |" << std::endl
<< "|" << std::setw(135) << "|" << std::endl
<< "| File color legend: \033[48;5;034m \033[0m File stored in memory"
<< std::setw(83) << "|" << std::endl
<< "| "
<< "\033[48;5;172m \033[0m File stored on file system" << std::setw(78) << "|"
<< std::endl
<< "|============================================================================"
"==========================================================|"
<< std::endl
<< "|======|===================|===================|====================|========"
"============|============|===========|=========|==========|"
<< std::endl
<< "| Kind | Filename | Producer step | Consumer step | "
"Commit Rule | Fire Rule | Permanent | Exclude | n_files |"
<< std::endl
<< "|======|===================|===================|====================|========"
"============|============|===========|=========|==========|"
<< std::endl;

for (auto itm : _locations) {
// First message
server_println(CAPIO_LOG_SERVER_CLI_LEVEL_JSON, "");
server_println(CAPIO_LOG_SERVER_CLI_LEVEL_JSON, "Composition of expected CAPIO FS: ");

// Table header lines
server_println(
CAPIO_LOG_SERVER_CLI_LEVEL_JSON,
"|============================================================================"
"==========================================================|");

server_println(CAPIO_LOG_SERVER_CLI_LEVEL_JSON, "|" + std::string(134, ' ') + "|");

{
std::ostringstream oss;
oss << "| Parsed configuration file for workflow: \033[1;36m"
<< capio_global_configuration->workflow_name
<< std::setw(94 - capio_global_configuration->workflow_name.length())
<< "\033[0m |";
server_println(CAPIO_LOG_SERVER_CLI_LEVEL_JSON, oss.str());
}

server_println(CAPIO_LOG_SERVER_CLI_LEVEL_JSON, "|" + std::string(134, ' ') + "|");

server_println(
CAPIO_LOG_SERVER_CLI_LEVEL_JSON,
"| File color legend: \033[48;5;034m \033[0m File stored in memory" +
std::string(82, ' ') + "|");

server_println(
CAPIO_LOG_SERVER_CLI_LEVEL_JSON,
"| \033[48;5;172m \033[0m File stored on file system" +
std::string(77, ' ') + "|");

server_println(
CAPIO_LOG_SERVER_CLI_LEVEL_JSON,
"|============================================================================"
"==========================================================|");

server_println(
CAPIO_LOG_SERVER_CLI_LEVEL_JSON,
"|======|===================|===================|====================|========"
"============|============|===========|=========|==========|");

server_println(CAPIO_LOG_SERVER_CLI_LEVEL_JSON,
"| Kind | Filename | Producer step | Consumer step | "
"Commit Rule | Fire Rule | Permanent | Exclude | n_files |");

server_println(
CAPIO_LOG_SERVER_CLI_LEVEL_JSON,
"|======|===================|===================|====================|========"
"============|============|===========|=========|==========|");

// Iterate over _locations
for (auto &itm : _locations) {
std::string color_preamble =
std::get<11>(itm.second) ? "\033[38;5;034m" : "\033[38;5;172m";
std::string color_post = "\033[0m";

std::string name_trunc = truncateLastN(itm.first, 12);
auto kind = std::get<6>(itm.second) ? "F" : "D";
std::cout << "| " << color_preamble << kind << color_post << " | " << color_preamble

std::ostringstream base_line;
base_line << "| " << color_preamble << kind << color_post << " | " << color_preamble
<< name_trunc << color_post << std::setfill(' ')
<< std::setw(20 - name_trunc.length()) << "| ";

auto producers = std::get<0>(itm.second);
auto consumers = std::get<1>(itm.second);
auto rowCount =
producers.size() > consumers.size() ? producers.size() : consumers.size();
auto rowCount = std::max(producers.size(), consumers.size());

// Add logic to handle the n_files column
std::string n_files = std::to_string(std::get<8>(itm.second));
if (std::get<8>(itm.second) < 1) {
n_files = "N.A.";
}

for (std::size_t i = 0; i <= rowCount; i++) {
std::string prod, cons;
if (i > 0) {
std::cout << "| | | ";
std::ostringstream line;

if (i == 0) {
line << base_line.str();
} else {
line << "| | | ";
}

if (i < producers.size()) {
auto prod1 = truncateLastN(producers.at(i), 12);
std::cout << prod1 << std::setfill(' ') << std::setw(20 - prod1.length())
<< " | ";
line << prod1 << std::setfill(' ') << std::setw(20 - prod1.length()) << " | ";
} else {
std::cout << std::setfill(' ') << std::setw(20) << " | ";
line << std::setfill(' ') << std::setw(20) << " | ";
}

if (i < consumers.size()) {
auto cons1 = truncateLastN(consumers.at(i), 12);
std::cout << " " << cons1 << std::setfill(' ') << std::setw(20 - cons1.length())
<< " | ";
line << " " << cons1 << std::setfill(' ') << std::setw(20 - cons1.length())
<< " | ";
} else {
std::cout << std::setfill(' ') << std::setw(21) << " | ";
line << std::setfill(' ') << std::setw(21) << " | ";
}

if (i == 0) {
std::string commit_rule = std::get<2>(itm.second),
fire_rule = std::get<3>(itm.second);
bool exclude = std::get<4>(itm.second), permanent = std::get<5>(itm.second);

std::cout << " " << commit_rule << std::setfill(' ')
<< std::setw(20 - commit_rule.length()) << " | " << fire_rule
<< std::setfill(' ') << std::setw(13 - fire_rule.length()) << " | "
<< " " << (permanent ? "YES" : "NO ") << " | "
<< (exclude ? "YES" : "NO ") << " | " << n_files
<< std::setw(11 - n_files.length()) << " | " << std::endl;
line << " " << commit_rule << std::setfill(' ')
<< std::setw(20 - commit_rule.length()) << " | " << fire_rule
<< std::setfill(' ') << std::setw(13 - fire_rule.length()) << " | "
<< " " << (permanent ? "YES" : "NO ") << " | "
<< (exclude ? "YES" : "NO ") << " | " << n_files
<< std::setw(10 - n_files.length()) << " |";
} else {
std::cout << std::setfill(' ') << std::setw(20) << "|" << std::setfill(' ')
<< std::setw(13) << "|" << std::setfill(' ') << std::setw(12) << "|"
<< std::setfill(' ') << std::setw(10) << "|" << std::setw(11) << "|"
<< std::endl;
line << std::setfill(' ') << std::setw(20) << "|" << std::setfill(' ')
<< std::setw(13) << "|" << std::setfill(' ') << std::setw(12) << "|"
<< std::setfill(' ') << std::setw(10) << "|" << std::setw(10) << "|";
}

server_println(CAPIO_LOG_SERVER_CLI_LEVEL_JSON, line.str());
}
std::cout << "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
<< std::endl;

server_println(
CAPIO_LOG_SERVER_CLI_LEVEL_JSON,
"*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*");
}
std::cout << std::endl;
};

server_println(CAPIO_LOG_SERVER_CLI_LEVEL_JSON, "");
}

/**
* Check whether the file is contained inside the location, either by direct name or by glob
Expand Down Expand Up @@ -440,11 +470,11 @@ class CapioCLEngine {
START_LOG(gettid(), "call(path=%s)", path.c_str());
if (const auto location = _locations.find(path); location == _locations.end()) {
LOG("No rule for home node. Returning create home node");
return node_name;
return capio_global_configuration->node_name;
} else {
LOG("Found location entry");
}
return node_name;
return capio_global_configuration->node_name;
}

protected:
Expand Down
Loading