From ef2f29c9c7089b38d128b5c61207f33a95fd65ad Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Mon, 1 Jan 2007 12:52:33 +0000 Subject: [PATCH] admin: Implement the main job commands. Organization: Straylight/Edgeware From: Mark Wooding That's SVCSUBMIT to submit new jobs, and SVCINFO, SVCOK and SVCFAIL for responding to them. --- server/admin.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/server/admin.c b/server/admin.c index 5030dc28..d0201693 100644 --- a/server/admin.c +++ b/server/admin.c @@ -1467,6 +1467,80 @@ static void acmd_svclist(admin *a, unsigned ac, char *av[]) a_ok(a); } +static void a_canceljob(admin_bgop *bg) +{ + admin_svcop *svc = (admin_svcop *)bg; + + a_write(svc->prov, "SVCCANCEL", 0, "%s", a_jobidencode(svc), A_END); + a_jobdestroy(svc); +} + +static void acmd_svcsubmit(admin *a, unsigned ac, char *av[]) +{ + const char *tag = 0; + admin_service *svc; + admin_svcop *svcop; + const char *ver = 0; + dstr d = DSTR_INIT; + + OPTIONS(ac, av, { + OPTARG("-background", arg, { tag = arg; }) + OPTARG("-version", arg, { ver = arg; }) + }); + if (!*av) goto bad_syntax; + if ((svc = a_svcfind(a, *av)) == 0) goto fail; + if (ver && versioncmp(svc->version, ver) < 0) { + a_fail(a, "service-too-old", + "%s", SYM_NAME(svc), + "%s", svc->version, + A_END); + goto fail; + } + if ((svcop = a_jobcreate(svc->prov)) == 0) { + a_fail(a, "provider-overloaded", A_END); + goto fail; + } + if (a_bgadd(a, &svcop->bg, tag, a_canceljob)) { + a_jobdestroy(svcop); + goto fail; + } + a_write(svc->prov, "SVCJOB", 0, + "%s", a_jobidencode(svcop), + "?TOKENS", av, + A_END); + goto done; + +bad_syntax: + a_fail(a, "bad-syntax", "svcsubmit", "[OPTIONS] SERVICE ARGS...", A_END); +fail: +done: + dstr_destroy(&d); + return; +} + +static void a_replycmd(admin *a, const char *status, int donep, char *av[]) +{ + admin_svcop *svc; + + if ((svc = a_jobiddecode(&a->j, av[0])) == 0) { + a_fail(a, "unknown-jobid", av[0], A_END); + return; + } + a_write(svc->bg.a, status, svc->bg.tag, "?TOKENS", av + 1, A_END); + if (donep) { + a_jobdestroy(svc); + a_bgrelease(&svc->bg); + } + a_ok(a); +} + +static void acmd_svcok(admin *a, unsigned ac, char *av[]) + { a_replycmd(a, "OK", 1, av); } +static void acmd_svcinfo(admin *a, unsigned ac, char *av[]) + { a_replycmd(a, "INFO", 0, av); } +static void acmd_svcfail(admin *a, unsigned ac, char *av[]) + { a_replycmd(a, "FAIL", 1, av); } + /*----- Administration commands -------------------------------------------*/ /* --- Miscellaneous commands --- */ @@ -1809,9 +1883,14 @@ static const acmd acmdtab[] = { { "setifname", "PEER NEW-NAME", 2, 2, acmd_setifname }, { "svcclaim", "SERVICE VERSION", 2, 2, acmd_svcclaim }, { "svcensure", "SERVICE [VERSION]", 1, 2, acmd_svcensure }, + { "svcfail", "JOBID TOKENS...", 1, 0xffff, acmd_svcfail }, + { "svcinfo", "JOBID TOKENS...", 1, 0xffff, acmd_svcinfo }, { "svclist", 0, 0, 0, acmd_svclist }, + { "svcok", "JOBID", 1, 1, acmd_svcok }, { "svcquery", "SERVICE", 1, 1, acmd_svcquery }, { "svcrelease", "SERVICE", 1, 1, acmd_svcrelease }, + { "svcsubmit", "[OPTIONS] SERVICE TOKENS...", + 2, 0xffff, acmd_svcsubmit }, { "stats", "PEER", 1, 1, acmd_stats }, #ifndef NTRACE { "trace", "[OPTIONS]", 0, 1, acmd_trace }, -- [mdw]