job submit and support run in worker

This commit is contained in:
Rongsong Shen 2025-11-28 17:24:31 +08:00
parent 3630e38a07
commit e497dd1b69
18 changed files with 502 additions and 236 deletions

View file

@ -16,32 +16,61 @@ static int mark_job_update(cluster_t*, job_t*, int);
uint64_t jobid = 100;
static job_t* create_job(cluster_t* c, uint64_t jobid, char* queue, char* user,
char* exechome, char* execcwd, char* execuser,
char* cmdline, char* exdata, uint32_t mintasks,
uint32_t maxtasks)
static job_t* create_job(cluster_t* c, xce_job_t* j)
{
job_t* job = NULL;
job_t* job = NULL;
static int typeid = -1;
if (typeid < 0) {
typeid = typeid_of_name(&(c->objmgr), "xjob");
TRACE("%s type %s id %d", __func__, "xjob", typeid);
}
if (typeid < 0) {
SET_ERROR(-typeid);
return NULL;
}
job = create_obj_by_typeid(&(c->objmgr), typeid, j);
return job;
}
uint64_t job_submit(void* c, char* user, char* queue, char* resreq,
char* cmdline, char* exdata, uint32_t mintasks,
uint32_t maxtasks)
uint64_t job_submit(void* c, xce_job_submit_t* submit)
{
job_t* job = NULL;
job_t* job = NULL;
uint64_t base_id = submit->jobid;
xce_job_t j = { .submit = submit->submit };
time_t now = time(NULL);
int i;
job = create_job(c, jobid++, queue, user, "/tmp", "/tmp", user, cmdline,
exdata, mintasks, maxtasks);
if (job == NULL) {
return -errno;
j.sub_time = now;
j.queue_time = now;
j.start_time = 0;
j.finish_time = 0;
j.pidinfo = NULL;
j.state = JOB_STAT_PEND;
j.allocs = NULL;
j.run_time = 0;
j.run_usage = NULL;
j.exit_info = NULL;
j.ckptinfo = NULL;
j.pending_ctrl = 0;
for (i = 0; i < submit->array_size; i++) {
j.jobid = base_id + i;
job = create_job(c, &j);
if (job == NULL) {
return -errno;
}
}
return job->job.jobid;
return base_id;
}
int load_jobs(void* c)
{
#if 0
job_t* job;
int i;
char cmdline[1024];
@ -62,6 +91,7 @@ int load_jobs(void* c)
return -errno;
}
}
#endif
return 0;
}
@ -181,27 +211,27 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
char* q_pre_exec;
char* q_post_exec;
rc = get_queue_exec(c, j->job.queue, &q_pre_exec, &q_post_exec);
rc = get_queue_exec(c, j->job.submit->queue, &q_pre_exec, &q_post_exec);
if (rc < 0) {
obj_deref(j);
obj_deref(w);
return rc;
}
if (j->job.start_info->q_pre_exec != NULL) {
obj_deref(j->job.start_info->q_pre_exec);
if (j->job.submit->start_info->q_pre_exec != NULL) {
obj_deref(j->job.submit->start_info->q_pre_exec);
}
if (j->job.start_info->q_post_exec != NULL) {
obj_deref(j->job.start_info->q_post_exec);
if (j->job.submit->start_info->q_post_exec != NULL) {
obj_deref(j->job.submit->start_info->q_post_exec);
}
j->job.start_info->q_pre_exec = q_pre_exec;
j->job.start_info->q_post_exec = q_post_exec;
j->job.submit->start_info->q_pre_exec = q_pre_exec;
j->job.submit->start_info->q_post_exec = q_post_exec;
}
einfo.jobid = alloc->jobid;
einfo.start_info = j->job.start_info;
einfo.start_info = j->job.submit->start_info;
einfo.launchinfo = &launchinfo;
rc = xce_startjob_req(w->ep, &einfo);
@ -398,18 +428,16 @@ int handle_jobsubmit(cluster_t* c, endpoint_t* ep, xce_request_t* request)
init_reply_by_req(&reply, request);
if (NULLSTR(submit->user) || NULLSTR(submit->queue)
|| NULLSTR(submit->cmdline)) {
if (NULLSTR(submit->submit->user) || NULLSTR(submit->submit->queue)
|| (submit->submit->start_info == NULL)
|| NULLSTR(submit->submit->start_info->cmdline)) {
jobid = 0;
errno = EINVAL;
} else {
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
HOOK_DETAIL_JOB_NEW, c, submit);
jobid = job_submit(c, (char*)submit->user, (char*)submit->queue,
(char*)submit->resreq, (char*)submit->cmdline,
(char*)submit->exdata, submit->mintasks,
submit->maxtasks);
jobid = job_submit(c, submit);
}
if (jobid == 0) {
reply.status = -errno;