Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vine: a manager argument to rename runtime directory #4041

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
23 changes: 13 additions & 10 deletions taskvine/src/bindings/python3/ndcctools/taskvine/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class Manager(object):
# @param port The port number to listen on. If zero, then a random port is chosen. A range of possible ports (low, hight) can be also specified instead of a single integer. Default is 9123
# @param name The project name to use.
# @param shutdown Automatically shutdown workers when manager is finished. Disabled by default.
# @param run_info_path Directory to write log (and staging if staging_path not given) files per run. If None, defaults to "vine-run-info"
# @param run_info_path Directory to archive workflow log directories, it is the upper level directory to run_info_template. If None, defaults to "vine-run-info"
# @param run_info_template Directory to write log (and staging if staging_path not given) files per run, append a time-based suffix if the path has already exists. If None, defaults by a %Y-%m-%dT%H%M%S format.
# @param staging_path Directory to write temporary files. Defaults to run_info_path if not given.
# @param ssl A tuple of filenames (ssl_key, ssl_cert) in pem format, or True.
# If not given, then TSL is not activated. If True, a self-signed temporary key and cert are generated.
Expand All @@ -78,6 +79,7 @@ def __init__(self,
name=None,
shutdown=False,
run_info_path="vine-run-info",
run_info_template=None,
staging_path=None,
ssl=None,
init_fn=None,
Expand Down Expand Up @@ -111,8 +113,17 @@ def __init__(self,
self._info_widget = JupyterDisplay(interval=status_display_interval)

try:
# Set an internal variable in the C code.
# No need to unset it explicitly as it doesn't rely on environment variables.
if run_info_path:
self.set_runtime_info_path(run_info_path)
cvine.vine_set_runtime_info_path(run_info_path)

# Set the environment variable VINE_RUNTIME_INFO_DIR on the C side.
# If run_info_template is not provided, unset the environment variable to prevent potential issues caused by leftover historical values from previous runs.
if run_info_template:
cvine.vine_set_runtime_info_template(run_info_template)
else:
cvine.vine_unset_runtime_info_template()

self._stats = cvine.vine_stats()
self._stats_hierarchy = cvine.vine_stats()
Expand Down Expand Up @@ -554,14 +565,6 @@ def set_catalog_servers(self, catalogs):
def set_property(self, name, value):
cvine.vine_set_property(self._taskvine, name, value)

##
# Specify a directory to write logs and staging files.
#
# @param self Reference to the current manager object.
# @param dirname A directory name
def set_runtime_info_path(self, dirname):
cvine.vine_set_runtime_info_path(dirname)

##
# Add a mandatory password that each worker must present.
#
Expand Down
9 changes: 9 additions & 0 deletions taskvine/src/manager/taskvine.h
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,15 @@ void vine_initialize_categories(struct vine_manager *m, struct rmsummary *max, c
*/
void vine_set_runtime_info_path(const char *path);

/** Sets the directory where a workflow-specific runtime logs are directly written into.
@param dir A directory
*/
void vine_set_runtime_info_template(const char *dir);

/** Unsets the directory where a workflow-specific runtime logs are directly written into.
*/
void vine_unset_runtime_info_template();

/** Adds a custom APPLICATION entry to the debug log.
@param m Reference to the current manager object.
@param entry A custom debug message.
Expand Down
35 changes: 35 additions & 0 deletions taskvine/src/manager/vine_runtime_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,38 @@ void vine_set_runtime_info_path(const char *path)
assert(path);
vine_runtime_info_path = xxstrdup(path);
}

void vine_set_runtime_info_template(const char *dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the template should only modify the value from "%Y-%m-%dT%H%M%S". vine_set_runtime_info_template should be called inside the other function to actually create the directories.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@btovar Though I was able to create the directories with the desired names, I assume it is because the vine_set_runtime_info_path and vine_set_runtime_info_template are called prior to vine_ssl_create in the manager's code, so the manager has the right global variables and env variables to initialize?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, we are setting the variables just before the manager creation.

{
assert(dir);

char absolute_template_path[512];
snprintf(absolute_template_path, sizeof(absolute_template_path), "%s/%s", vine_runtime_info_path, dir);

/* Check if the template path has already exists, if yes, append a suffix with the current time. */
struct stat st;
if (stat(absolute_template_path, &st) == 0 && S_ISDIR(st.st_mode)) {
char buf[20];
time_t now = time(NULL);
struct tm *tm_info = localtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%dT%H%M%S", tm_info);

size_t new_dir_len = strlen(dir) + strlen(buf) + 2;
char *new_dir = (char *)malloc(new_dir_len);
if (new_dir == NULL) {
perror("Error: cannot set runtime template path");
exit(EXIT_FAILURE);
}
snprintf(new_dir, new_dir_len, "%s-%s", dir, buf);

setenv("VINE_RUNTIME_INFO_DIR", new_dir, 1);
free(new_dir);
} else {
setenv("VINE_RUNTIME_INFO_DIR", dir, 1);
}
}

void vine_unset_runtime_info_template()
{
unsetenv("VINE_RUNTIME_INFO_DIR");
}