diff --git a/src/controller/job.c b/src/controller/job.c index 829437bb..59ef0d67 100644 --- a/src/controller/job.c +++ b/src/controller/job.c @@ -715,8 +715,12 @@ int on_job_stop(cluster_t* c, uint64_t jobid) lock(job, RTTI_LOCK_WRITE); state = job->job.state; + xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT, + HOOK_DETAIL_JOB_STOP, c, job); state |= JOB_STAT_USUSP; - mark_job_update(c, job, state); + job->job.state = state; + xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT, + HOOK_DETAIL_JOB_STOP, c, job); unlock(job); dereference(job); @@ -745,8 +749,12 @@ int on_job_resume(cluster_t* c, uint64_t jobid) lock(job, RTTI_LOCK_WRITE); state = job->job.state; + xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT, + HOOK_DETAIL_JOB_RESUME, c, job); state &= ~JOB_STAT_USUSP; - mark_job_update(c, job, state); + job->job.state = state; + xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT, + HOOK_DETAIL_JOB_RESUME, c, job); unlock(job); dereference(job); @@ -1023,7 +1031,7 @@ int do_clr_preason(cluster_t* c, endpoint_t* ep, xce_request_t* request) FREEUP(job->pend_reasons); } - xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT, + xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT, HOOK_DETAIL_CLRPREASON, c, j); unlock(j); diff --git a/src/controller/join.c b/src/controller/join.c index 2fe38a78..cbea7f3a 100644 --- a/src/controller/join.c +++ b/src/controller/join.c @@ -62,10 +62,10 @@ static int handle_worker_join(cluster_t* c, endpoint_t* ep, reply.status = idx; reply.data_which = RequestReply_data_nodata; - xce_reply(ep, c->myhost, &reply); xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_AFTER_EVENT, HOOK_DETAIL_WORKER_JOIN, c, from->name, idx); + xce_reply(ep, c->myhost, &reply); unlock(c->workermgr); if (idx < 0) { ERROR("worker %s join failed, rc %d", from->name, idx); diff --git a/src/controller/meson.build b/src/controller/meson.build index 07659d11..d09abc4e 100644 --- a/src/controller/meson.build +++ b/src/controller/meson.build @@ -73,6 +73,7 @@ controller_unit_test_src = [ 'testsuite/test_persist_schema.c', 'testsuite/test_persist_checkpoint.c', 'testsuite/test_persist_recovery.c', + 'testsuite/test_hooks.c', 'persist.c', ] diff --git a/src/controller/testsuite/controller_test.c b/src/controller/testsuite/controller_test.c index 5ab71c9f..4334905c 100644 --- a/src/controller/testsuite/controller_test.c +++ b/src/controller/testsuite/controller_test.c @@ -10,6 +10,7 @@ extern void test_persist_wal(void); extern void test_persist_schema(void); extern void test_persist_checkpoint(void); extern void test_persist_recovery(void); +extern void test_hooks(void); void setUp(void) { return; } @@ -89,6 +90,7 @@ int main(int argc, char* argv[]) TEST(test_persist_schema); TEST(test_persist_checkpoint); TEST(test_persist_recovery); + TEST(test_hooks); return UNITY_END(); } diff --git a/src/controller/testsuite/test_hooks.c b/src/controller/testsuite/test_hooks.c new file mode 100644 index 00000000..c8e9fb8b --- /dev/null +++ b/src/controller/testsuite/test_hooks.c @@ -0,0 +1,40 @@ +#include + +#include + +#include "xce/cluster_def.h" + +static void test_hook_detail_job_stop_exists(void) +{ + /* HOOK_DETAIL_JOB_STOP must be defined and distinct from JOB_UPDATE */ + int stop_val = (int)HOOK_DETAIL_JOB_STOP; + int update_val = (int)HOOK_DETAIL_JOB_UPDATE; + TEST_ASSERT_TRUE(stop_val != 0); + TEST_ASSERT_TRUE(stop_val != update_val); + printf("test_hook_detail_job_stop_exists: PASS\n"); +} + +static void test_hook_detail_job_resume_exists(void) +{ + int resume_val = (int)HOOK_DETAIL_JOB_RESUME; + int update_val = (int)HOOK_DETAIL_JOB_UPDATE; + TEST_ASSERT_TRUE(resume_val != 0); + TEST_ASSERT_TRUE(resume_val != update_val); + TEST_ASSERT_TRUE(resume_val != (int)HOOK_DETAIL_JOB_STOP); + printf("test_hook_detail_job_resume_exists: PASS\n"); +} + +static void test_hook_detail_job_stop_and_resume_are_distinct(void) +{ + TEST_ASSERT_NOT_EQUAL((int)HOOK_DETAIL_JOB_STOP, (int)HOOK_DETAIL_JOB_RESUME); + printf("test_hook_detail_job_stop_and_resume_are_distinct: PASS\n"); +} + +void test_hooks(void) +{ + printf("\n>> hook detail enum tests\n\n"); + + RUN_TEST(test_hook_detail_job_stop_exists); + RUN_TEST(test_hook_detail_job_resume_exists); + RUN_TEST(test_hook_detail_job_stop_and_resume_are_distinct); +} diff --git a/src/include/xce/cluster_def.h b/src/include/xce/cluster_def.h index cd6f35be..f8dca84b 100644 --- a/src/include/xce/cluster_def.h +++ b/src/include/xce/cluster_def.h @@ -55,7 +55,9 @@ enum { HOOK_DETAIL_QUEUE_UPDATE, HOOK_DETAIL_USERGROUP_UPDATE, HOOK_DETAIL_HOSTGROUP_UPDATE, - HOOK_DETAIL_JOB_RUSAGE_UPDATE + HOOK_DETAIL_JOB_RUSAGE_UPDATE, + HOOK_DETAIL_JOB_STOP, + HOOK_DETAIL_JOB_RESUME }; #define XCE_NS_CONFIG (0) @@ -88,7 +90,7 @@ typedef struct { endpoint_t* ep; } cluster_apiserver_t; -typedef struct { +typedef struct cluster_s { myconf_t* myconf; xce_peerinfo_t* myhost; hooksys_t hooksys;