Skip to content

Commit

Permalink
Allow default parameters on Aviso/Mirror constructors ECFLOW-1981
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosbento authored Oct 29, 2024
2 parents 690e64c + 2c51e84 commit 5f03673
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 13 deletions.
2 changes: 2 additions & 0 deletions docs/python_api/AvisoAttr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Usage:
t2 = Task('t2')
t2.add_aviso('name', '{...}', 'http://aviso.com', '60', '/path/to/auth')
The parameters `url`, `schema`, `polling`, and `auth` are optional


.. py:method:: AvisoAttr.auth( (AvisoAttr)arg1) -> str :
:module: ecflow
Expand Down
2 changes: 2 additions & 0 deletions docs/python_api/MirrorAttr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Usage:
t2 = Task('t2')
t2.add_aviso('name', '/remote/task', 'remote-ecflow', '3141', '60', True, '/path/to/auth')
The parameters `remote_host`, `remote_port`, `polling`, `ssl`, and `auth` are optional


.. py:method:: MirrorAttr.auth( (MirrorAttr)arg1) -> str :
:module: ecflow
Expand Down
88 changes: 77 additions & 11 deletions libs/pyext/src/ecflow/python/ExportNodeAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,25 +285,82 @@ static job_creation_ctrl_ptr makeJobCreationCtrl() {

static std::shared_ptr<AvisoAttr> aviso_init(const std::string& name,
const std::string& listener,
const std::string& url,
const std::string& schema,
const std::string& polling,
const std::string& auth) {
const std::string& url = AvisoAttr::default_url,
const std::string& schema = AvisoAttr::default_schema,
const std::string& polling = AvisoAttr::default_polling,
const std::string& auth = AvisoAttr::default_auth) {
auto attr = std::make_shared<AvisoAttr>(nullptr, name, listener, url, schema, polling, 0, auth, "");
return attr;
}

static std::shared_ptr<AvisoAttr> aviso_init_defaults_0(const std::string& name, const std::string& listener) {
return aviso_init(name, listener);
}

static std::shared_ptr<AvisoAttr>
aviso_init_defaults_1(const std::string& name, const std::string& listener, const std::string& url) {
return aviso_init(name, listener, url);
}

static std::shared_ptr<AvisoAttr> aviso_init_defaults_2(const std::string& name,
const std::string& listener,
const std::string& url,
const std::string& schema) {
return aviso_init(name, listener, url, schema);
}

static std::shared_ptr<AvisoAttr> aviso_init_defaults_3(const std::string& name,
const std::string& listener,
const std::string& url,
const std::string& schema,
const std::string& polling) {
return aviso_init(name, listener, url, schema, polling);
}

static std::shared_ptr<MirrorAttr> mirror_init(const std::string& name,
const std::string& path,
const std::string& host,
const std::string& port,
const std::string& polling,
bool ssl,
const std::string& auth) {
const std::string& host = ecf::MirrorAttr::default_remote_host,
const std::string& port = ecf::MirrorAttr::default_remote_port,
const std::string& polling = ecf::MirrorAttr::default_polling,
bool ssl = false,
const std::string& auth = ecf::MirrorAttr::default_remote_auth) {
auto attr = std::make_shared<MirrorAttr>(nullptr, name, path, host, port, polling, ssl, auth, "");
return attr;
}

static std::shared_ptr<MirrorAttr> mirror_init_defaults_0(const std::string& name, const std::string& path) {
return mirror_init(name, path);
}

static std::shared_ptr<MirrorAttr>
mirror_init_defaults_1(const std::string& name, const std::string& path, const std::string& host) {
return mirror_init(name, path, host);
}

static std::shared_ptr<MirrorAttr> mirror_init_defaults_2(const std::string& name,
const std::string& path,
const std::string& host,
const std::string& port) {
return mirror_init(name, path, host, port);
}

static std::shared_ptr<MirrorAttr> mirror_init_defaults_3(const std::string& name,
const std::string& path,
const std::string& host,
const std::string& port,
const std::string& polling) {
return mirror_init(name, path, host, port, polling);
}

static std::shared_ptr<MirrorAttr> mirror_init_defaults_4(const std::string& name,
const std::string& path,
const std::string& host,
const std::string& port,
const std::string& polling,
bool ssl) {
return mirror_init(name, path, host, port, polling, ssl);
}

void export_NodeAttr() {
// Trigger & Complete thin wrapper over Expression, allows us to call: Task("a").add(Trigger("a=1"),Complete("b=1"))
class_<Trigger, std::shared_ptr<Trigger>>("Trigger", DefsDoc::trigger(), init<std::string>())
Expand Down Expand Up @@ -945,8 +1002,8 @@ void export_NodeAttr() {
.def("step", &Repeat::step, "The increment for the repeat, as an integer")
.def("value", &Repeat::last_valid_value, "The current value of the repeat as an integer");

void (CronAttr::*add_time_series)(const TimeSeries&) = &CronAttr::addTimeSeries;
void (CronAttr::*add_time_series_2)(const TimeSlot& s, const TimeSlot& f, const TimeSlot& i) =
void (CronAttr::* add_time_series)(const TimeSeries&) = &CronAttr::addTimeSeries;
void (CronAttr::* add_time_series_2)(const TimeSlot& s, const TimeSlot& f, const TimeSlot& i) =
&CronAttr::addTimeSeries;
class_<CronAttr, std::shared_ptr<CronAttr>>("Cron", NodeAttrDoc::cron_doc())
.def("__init__", raw_function(&cron_raw_constructor, 1)) // will call -> cron_init or cron_init1
Expand Down Expand Up @@ -1018,6 +1075,10 @@ void export_NodeAttr() {

class_<ecf::AvisoAttr>("AvisoAttr", NodeAttrDoc::aviso_doc())
.def("__init__", make_constructor(&aviso_init))
.def("__init__", make_constructor(&aviso_init_defaults_0))
.def("__init__", make_constructor(&aviso_init_defaults_1))
.def("__init__", make_constructor(&aviso_init_defaults_2))
.def("__init__", make_constructor(&aviso_init_defaults_3))
.def(self == self) // __eq__
.def("__str__", &ecf::to_python_string) // __str__
.def("__copy__", copyObject<AvisoAttr>) // __copy__ uses copy constructor
Expand Down Expand Up @@ -1045,6 +1106,11 @@ void export_NodeAttr() {

class_<MirrorAttr>("MirrorAttr", NodeAttrDoc::mirror_doc())
.def("__init__", make_constructor(&mirror_init))
.def("__init__", make_constructor(&mirror_init_defaults_0))
.def("__init__", make_constructor(&mirror_init_defaults_1))
.def("__init__", make_constructor(&mirror_init_defaults_2))
.def("__init__", make_constructor(&mirror_init_defaults_3))
.def("__init__", make_constructor(&mirror_init_defaults_4))
.def(self == self) // __eq__
.def("__str__", &ecf::to_python_string) // __str__
.def("__copy__", copyObject<MirrorAttr>) // __copy__ uses copy constructor
Expand Down
8 changes: 6 additions & 2 deletions libs/pyext/src/ecflow/python/NodeAttrDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,9 @@ const char* NodeAttrDoc::aviso_doc() {
" AvisoAttr('name', '{...}', 'http://aviso.com', '60', '/path/to/auth'))\n"
"\n"
" t2 = Task('t2')\n"
" t2.add_aviso('name', '{...}', 'http://aviso.com', '60', '/path/to/auth')\n";
" t2.add_aviso('name', '{...}', 'http://aviso.com', '60', '/path/to/auth')\n"
"\n"
"The parameters `url`, `schema`, `polling`, and `auth` are optional\n";
}

const char* NodeAttrDoc::mirror_doc() {
Expand All @@ -754,5 +756,7 @@ const char* NodeAttrDoc::mirror_doc() {
" MirrorAttr('name', '/remote/task', 'remote-ecflow', '3141', '60', True, '/path/to/auth'))\n"
"\n"
" t2 = Task('t2')\n"
" t2.add_aviso('name', '/remote/task', 'remote-ecflow', '3141', '60', True, '/path/to/auth')\n";
" t2.add_aviso('name', '/remote/task', 'remote-ecflow', '3141', '60', True, '/path/to/auth')\n"
"\n"
"The parameters `remote_host`, `remote_port`, `polling`, `ssl`, and `auth` are optional\n";
}
76 changes: 76 additions & 0 deletions libs/pyext/test/py_u_TestAviso.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,78 @@ def can_create_aviso_from_parameters():
assert aviso.auth() == "auth"


def can_create_aviso_from_default_parameters_0():
suite = ecf.Suite("s1")

family = ecf.Family("f1")
suite.add_family(family)

task = ecf.Task("f1", ecf.AvisoAttr("name", "listener"))
assert len(list(task.avisos)) == 1

actual = list(task.avisos)[0]
assert actual.name() == "name"
assert actual.listener() == "listener"
assert actual.url() == "%ECF_AVISO_URL%"
assert actual.schema() == "%ECF_AVISO_SCHEMA%"
assert actual.polling() == "%ECF_AVISO_POLLING%"
assert actual.auth() == "%ECF_AVISO_AUTH%"


def can_create_aviso_from_default_parameters_1():
suite = ecf.Suite("s1")

family = ecf.Family("f1")
suite.add_family(family)

task = ecf.Task("f1", ecf.AvisoAttr("name", "listener", "url"))
assert len(list(task.avisos)) == 1

actual = list(task.avisos)[0]
assert actual.name() == "name"
assert actual.listener() == "listener"
assert actual.url() == "url"
assert actual.schema() == "%ECF_AVISO_SCHEMA%"
assert actual.polling() == "%ECF_AVISO_POLLING%"
assert actual.auth() == "%ECF_AVISO_AUTH%"


def can_create_aviso_from_default_parameters_2():
suite = ecf.Suite("s1")

family = ecf.Family("f1")
suite.add_family(family)

task = ecf.Task("f1", ecf.AvisoAttr("name", "listener", "url", "schema"))
assert len(list(task.avisos)) == 1

actual = list(task.avisos)[0]
assert actual.name() == "name"
assert actual.listener() == "listener"
assert actual.url() == "url"
assert actual.schema() == "schema"
assert actual.polling() == "%ECF_AVISO_POLLING%"
assert actual.auth() == "%ECF_AVISO_AUTH%"


def can_create_aviso_from_default_parameters_3():
suite = ecf.Suite("s1")

family = ecf.Family("f1")
suite.add_family(family)

task = ecf.Task("f1", ecf.AvisoAttr("name", "listener", "url", "schema", "polling"))
assert len(list(task.avisos)) == 1

actual = list(task.avisos)[0]
assert actual.name() == "name"
assert actual.listener() == "listener"
assert actual.url() == "url"
assert actual.schema() == "schema"
assert actual.polling() == "polling"
assert actual.auth() == "%ECF_AVISO_AUTH%"


def can_add_aviso_to_task():
suite = ecf.Suite("s1")

Expand Down Expand Up @@ -101,6 +173,10 @@ def can_check_job_creation_with_aviso():
Test.print_test_start(os.path.basename(__file__))

can_create_aviso_from_parameters()
can_create_aviso_from_default_parameters_0()
can_create_aviso_from_default_parameters_1()
can_create_aviso_from_default_parameters_2()
can_create_aviso_from_default_parameters_3()
can_add_aviso_to_task()
can_embed_aviso_into_task()
cannot_have_multiple_avisos_in_single_task()
Expand Down
59 changes: 59 additions & 0 deletions libs/pyext/test/py_u_TestMirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,61 @@ def can_create_mirror_from_parameters():
assert mirror.auth() == "auth"


def can_create_mirror_from_default_parameters_0():
mirror = ecf.MirrorAttr("name", "r_path")
assert mirror.name() == "name"
assert mirror.remote_path() == "r_path"
assert mirror.remote_host() == "%ECF_MIRROR_REMOTE_HOST%"
assert mirror.remote_port() == "%ECF_MIRROR_REMOTE_PORT%"
assert mirror.polling() == "%ECF_MIRROR_REMOTE_POLLING%"
assert mirror.ssl() == False
assert mirror.auth() == "%ECF_MIRROR_REMOTE_AUTH%"


def can_create_mirror_from_default_parameters_1():
mirror = ecf.MirrorAttr("name", "r_path", "r_host")
assert mirror.name() == "name"
assert mirror.remote_path() == "r_path"
assert mirror.remote_host() == "r_host"
assert mirror.remote_port() == "%ECF_MIRROR_REMOTE_PORT%"
assert mirror.polling() == "%ECF_MIRROR_REMOTE_POLLING%"
assert mirror.ssl() == False
assert mirror.auth() == "%ECF_MIRROR_REMOTE_AUTH%"


def can_create_mirror_from_default_parameters_2():
mirror = ecf.MirrorAttr("name", "r_path", "r_host", "r_port")
assert mirror.name() == "name"
assert mirror.remote_path() == "r_path"
assert mirror.remote_host() == "r_host"
assert mirror.remote_port() == "r_port"
assert mirror.polling() == "%ECF_MIRROR_REMOTE_POLLING%"
assert mirror.ssl() == False
assert mirror.auth() == "%ECF_MIRROR_REMOTE_AUTH%"


def can_create_mirror_from_default_parameters_3():
mirror = ecf.MirrorAttr("name", "r_path", "r_host", "r_port", "polling")
assert mirror.name() == "name"
assert mirror.remote_path() == "r_path"
assert mirror.remote_host() == "r_host"
assert mirror.remote_port() == "r_port"
assert mirror.polling() == "polling"
assert mirror.ssl() == False
assert mirror.auth() == "%ECF_MIRROR_REMOTE_AUTH%"


def can_create_mirror_from_default_parameters_4():
mirror = ecf.MirrorAttr("name", "r_path", "r_host", "r_port", "polling", True)
assert mirror.name() == "name"
assert mirror.remote_path() == "r_path"
assert mirror.remote_host() == "r_host"
assert mirror.remote_port() == "r_port"
assert mirror.polling() == "polling"
assert mirror.ssl() == True
assert mirror.auth() == "%ECF_MIRROR_AUTH%"


def can_add_mirror_to_task():
suite = ecf.Suite("s1")

Expand Down Expand Up @@ -101,6 +156,10 @@ def can_check_job_creation_with_mirror():
Test.print_test_start(os.path.basename(__file__))

can_create_mirror_from_parameters()
can_create_mirror_from_default_parameters_0()
can_create_mirror_from_default_parameters_1()
can_create_mirror_from_default_parameters_2()
can_create_mirror_from_default_parameters_3()
can_add_mirror_to_task()
can_embed_mirror_into_task()
cannot_have_multiple_mirrors_in_single_task()
Expand Down

0 comments on commit 5f03673

Please sign in to comment.