1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
35
#include "sge_all_listsL.h"
36
#include "sig_handlers.h"
37
#include "parse_qsub.h"
43
#include "sge_feature.h"
44
#include "sge_language.h"
45
#include "sge_unistd.h"
46
#include "sge_answer.h"
48
#include "sge_qinstance_state.h"
50
#include "msg_common.h"
51
#include "msg_clients_common.h"
54
#include "sgeobj/sge_str.h"
55
#include "sgeobj/msg_sgeobjlib.h"
56
#include "sgeobj//sge_range.h"
57
#include "sge_options.h"
58
#include "sge_profiling.h"
59
#include "gdi/sge_gdi.h"
60
#include "gdi/sge_gdi_ctx.h"
62
static lList *sge_parse_cmdline_qmod(char **argv, char **envp, lList **ppcmdline);
63
static lList *sge_parse_qmod(lList **ppcmdline, lList **ppreflist, u_long32 *pforce);
64
static int qmod_usage(FILE *fp, char *what);
66
extern char **environ;
68
int main(int argc, char *argv[]);
76
lList *ref_list = NULL;
77
lList *alp = NULL, *pcmdline = NULL;
79
sge_gdi_ctx_class_t *ctx = NULL;
81
DENTER_MAIN(TOP_LAYER, "qmod");
85
log_state_set_log_gui(1);
86
sge_setup_sig_handlers(QMOD);
88
if (sge_gdi2_setup(&ctx, QMOD, MAIN_THREAD, &alp) != AE_OK) {
89
answer_list_output(&alp);
90
SGE_EXIT((void**)&ctx, 1);
94
** static func for parsing all qmod specific switches
95
** here we get action, force, ref_list
97
alp = sge_parse_cmdline_qmod(++argv, environ, &pcmdline);
100
** high level parsing error! show answer list
103
fprintf(stderr, "%s\n", lGetString(aep, AN_text));
106
lFreeList(&pcmdline);
107
SGE_EXIT((void**)&ctx, 1);
110
alp = sge_parse_qmod(&pcmdline, &ref_list, &force);
114
** low level parsing error! show answer list
117
fprintf(stderr, "%s\n", lGetString(aep, AN_text));
120
lFreeList(&pcmdline);
121
lFreeList(&ref_list);
122
SGE_EXIT((void**)&ctx, 1);
126
lListElem *idep = NULL;
127
for_each(idep, ref_list) {
128
lSetUlong(idep, ID_force, force);
133
alp = ctx->gdi(ctx, SGE_CQUEUE_LIST, SGE_GDI_TRIGGER, &ref_list, NULL, NULL);
140
fprintf(stdout, "%s\n", lGetString(aep, AN_text));
144
lFreeList(&ref_list);
145
lFreeList(&pcmdline);
149
SGE_EXIT((void**)&ctx, 0);
157
**** sge_parse_cmdline_qmod (static)
159
**** 'stage 1' parsing of qmod-options. Parses options
160
**** with their arguments and stores them in ppcmdline.
162
static lList *sge_parse_cmdline_qmod(
172
DENTER(TOP_LAYER, "sge_parse_cmdline_qmod");
177
sge_add_noarg(ppcmdline, 0, "-help", NULL);
182
if ((rp = parse_noopt(sp, "-help", "--help", ppcmdline, &alp)) != sp)
186
if ((rp = parse_noopt(sp, "-f", "--force", ppcmdline, &alp)) != sp)
190
if ((rp = parse_until_next_opt(sp, "-c", "--clear", ppcmdline, &alp)) != sp)
194
if ((rp = parse_until_next_opt(sp, "-cj", "--clearjob", ppcmdline, &alp)) != sp)
198
if ((rp = parse_until_next_opt(sp, "-cq", "--clearqueue", ppcmdline, &alp)) != sp)
202
if ((rp = parse_until_next_opt(sp, "-s", "--suspend", ppcmdline, &alp)) != sp)
206
if ((rp = parse_until_next_opt(sp, "-sj", "--suspendjob", ppcmdline, &alp)) != sp)
210
if ((rp = parse_until_next_opt(sp, "-sq", "--suspendqueue", ppcmdline, &alp)) != sp)
214
if ((rp = parse_until_next_opt(sp, "-us", "--unsuspend", ppcmdline, &alp)) != sp)
218
if ((rp = parse_until_next_opt(sp, "-usj", "--unsuspendjob", ppcmdline, &alp)) != sp)
222
if ((rp = parse_until_next_opt(sp, "-usq", "--unsuspendqueue", ppcmdline, &alp)) != sp)
226
if ((rp = parse_until_next_opt(sp, "-d", "--disable", ppcmdline, &alp)) != sp)
230
if ((rp = parse_until_next_opt(sp, "-rj", "--reschedulejob", ppcmdline, &alp)) != sp)
234
if ((rp = parse_until_next_opt(sp, "-rq", "--reschedulequeue", ppcmdline, &alp)) != sp)
238
if ((rp = parse_until_next_opt(sp, "-r", "--reschedule", ppcmdline, &alp)) != sp)
242
if ((rp = parse_until_next_opt(sp, "-e", "--enable", ppcmdline, &alp)) != sp)
246
if (!strcmp("-t", *sp)) {
247
lList *task_id_range_list = NULL;
250
/* next field is path_name */
253
sprintf(str,MSG_PARSE_TOPTIONMUSTHAVEALISTOFTASKIDRANGES);
254
answer_list_add(&alp, str, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR);
258
DPRINTF(("\"-t %s\"\n", *sp));
260
range_list_parse_from_string(&task_id_range_list, &alp, *sp,
261
false, true, INF_NOT_ALLOWED);
262
if (!task_id_range_list) {
266
range_list_sort_uniq_compress(task_id_range_list, &alp, true);
267
if (lGetNumberOfElem(task_id_range_list) > 1) {
268
answer_list_add(&alp, MSG_QCONF_ONLYONERANGE, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR);
272
ep_opt = sge_add_arg(ppcmdline, t_OPT, lListT, *(sp - 1), *sp);
273
lSetList(ep_opt, SPA_argval_lListT, task_id_range_list);
280
#ifdef __SGE_QINSTANCE_STATE_DEBUG__
281
if ((rp = parse_until_next_opt(sp, "-_e", "--_error", ppcmdline, &alp)) != sp)
283
if ((rp = parse_until_next_opt(sp, "-_o", "--_orphaned", ppcmdline, &alp)) != sp)
285
if ((rp = parse_until_next_opt(sp, "-_do", "--_dorphaned", ppcmdline, &alp)) != sp)
287
if ((rp = parse_until_next_opt(sp, "-_u", "--_unknown", ppcmdline, &alp)) != sp)
289
if ((rp = parse_until_next_opt(sp, "-_du", "--_dunknown", ppcmdline, &alp)) != sp)
291
if ((rp = parse_until_next_opt(sp, "-_c", "--_confambiguous", ppcmdline, &alp)) != sp)
293
if ((rp = parse_until_next_opt(sp, "-_dc", "--_dconfambiguous", ppcmdline, &alp)) != sp)
298
sprintf(str, MSG_PARSE_INVALIDOPTIONARGUMENTX_S, *sp);
299
answer_list_add(&alp, str, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR);
301
qmod_usage(stderr, NULL);
310
**** sge_parse_qmod (static)
312
**** 'stage 2' parsing of qmod-options. Gets the options from
313
**** ppcmdline, sets the force and action flags and puts the
314
**** queue/job-names/numbers in ppreflist.
316
static lList *sge_parse_qmod(lList **ppcmdline, lList **ppreflist, u_long32 *pforce)
323
DENTER(TOP_LAYER, "sge_parse_qmod");
325
/* Loop over all options. Only valid options can be in the
326
ppcmdline list. Except f_OPT all options are exclusive.
328
while(lGetNumberOfElem(*ppcmdline)) {
330
static const char *options[] = {
345
#ifdef __SGE_QINSTANCE_STATE_DEBUG__
356
static const u_long32 transitions[] = {
358
QI_DO_CLEARERROR | JOB_DO_ACTION,
359
QI_DO_CLEARERROR | QUEUE_DO_ACTION,
360
QI_DO_DISABLE | QUEUE_DO_ACTION,
362
QI_DO_RESCHEDULE | JOB_DO_ACTION,
363
QI_DO_RESCHEDULE | QUEUE_DO_ACTION,
364
QI_DO_ENABLE | QUEUE_DO_ACTION,
366
QI_DO_SUSPEND | JOB_DO_ACTION,
367
QI_DO_SUSPEND | QUEUE_DO_ACTION,
369
QI_DO_UNSUSPEND | JOB_DO_ACTION,
370
QI_DO_UNSUSPEND | QUEUE_DO_ACTION,
371
#ifdef __SGE_QINSTANCE_STATE_DEBUG__
378
QI_DO_CLEARAMBIGUOUS,
384
if (parse_flag(ppcmdline, "-help", &alp, &helpflag)) {
385
usageshowed = qmod_usage(stdout, NULL);
389
if (parse_flag(ppcmdline, "-f", &alp, pforce)) {
394
while (options[i] != NULL) {
395
if ((transitions[i] & QUEUE_DO_ACTION) == 0) {
396
parse_multi_jobtaskslist(ppcmdline, options[i], &alp, ppreflist, true, transitions[i]);
398
lList *queueList = NULL;
399
if (parse_multi_stringlist( ppcmdline, options[i], &alp, &queueList, ST_Type, ST_name)){
400
id_list_build_from_str_list(ppreflist, &alp, queueList, transitions[i], *pforce);
402
lFreeList(&queueList);
407
/* we get to this point, than there are -t options without job names. We have to write an error message */
408
if ((ep = lGetElemStr(*ppcmdline, SPA_switch, "-t")) != NULL) {
409
sprintf(str, MSG_JOB_LONELY_TOPTION_S, lGetString(ep, SPA_switch_arg));
410
answer_list_add(&alp, str, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR);
417
if(lGetNumberOfElem(*ppcmdline)) {
418
sprintf(str, MSG_PARSE_TOOMANYOPTIONS);
420
qmod_usage(stderr, NULL);
421
answer_list_add(&alp, str, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR);
430
**** qmod_usage (static)
432
**** displays usage of qmod on file fp.
433
**** Is what NULL, full usage will be displayed.
435
**** Returns always 1.
437
**** If what is a pointer to an option-string,
438
**** only usage for that option will be displayed.
439
**** ** not implemented yet! **
441
static int qmod_usage(
448
sge_dstring_init(&ds, buffer, sizeof(buffer));
450
fprintf(fp, "%s\n", feature_get_product_name(FS_SHORT_VERSION, &ds));
453
/* display full usage */
454
fprintf(fp,"%s qmod [options]\n", MSG_SRC_USAGE);
455
fprintf(fp, " [-c job_wc_queue_list] %s\n", MSG_QMOD_c_OPT_USAGE);
456
fprintf(fp, " [-cj job_list] %s\n", MSG_QMOD_c_OPT_USAGE_J);
457
fprintf(fp, " [-cq wc_queue_list] %s\n", MSG_QMOD_c_OPT_USAGE_Q);
459
fprintf(fp, " [-d wc_queue_list] %s\n", MSG_QMOD_d_OPT_USAGE);
460
fprintf(fp, " [-e wc_queue_list] %s\n", MSG_QMOD_e_OPT_USAGE);
461
fprintf(fp, " [-f] %s\n", MSG_QMOD_f_OPT_USAGE);
462
fprintf(fp, " [-help] %s\n", MSG_COMMON_help_OPT_USAGE);
463
fprintf(fp, " [-r job_wc_queue_list] %s\n", MSG_QMOD_r_OPT_USAGE);
464
fprintf(fp, " [-rj job_list] %s\n", MSG_QMOD_r_OPT_USAGE_J);
465
fprintf(fp, " [-rq wc_queue_list] %s\n", MSG_QMOD_r_OPT_USAGE_Q);
467
fprintf(fp, " [-s job_wc_queue_list] %s\n", MSG_QMOD_s_OPT_USAGE);
468
fprintf(fp, " [-sj job_list] %s\n", MSG_QMOD_s_OPT_USAGE_J);
469
fprintf(fp, " [-sq wc_queue_list] %s\n", MSG_QMOD_s_OPT_USAGE_Q);
470
fprintf(fp, " [-us job_wc_queue_list] %s\n", MSG_QMOD_us_OPT_USAGE);
471
fprintf(fp, " [-usj job_list] %s\n", MSG_QMOD_us_OPT_USAGE_J);
472
fprintf(fp, " [-usq wc_queue_list] %s\n", MSG_QMOD_us_OPT_USAGE_Q);
474
#ifdef __SGE_QINSTANCE_STATE_DEBUG__
475
fprintf(fp, " [-_e queue_list] %s\n", MSG_QMOD_err_OPT_ISAGE);
476
fprintf(fp, " [-_o queue_list] %s\n", MSG_QMOD_o_OPT_ISAGE);
477
fprintf(fp, " [-_do queue_list] %s\n", MSG_QMOD_do_OPT_ISAGE);
478
fprintf(fp, " [-_u queue_list] %s\n", MSG_QMOD_u_OPT_ISAGE);
479
fprintf(fp, " [-_du queue_list] %s\n", MSG_QMOD_du_OPT_ISAGE);
480
fprintf(fp, " [-_c queue_list] %s\n", MSG_QMOD_c_OPT_ISAGE);
481
fprintf(fp, " [-_dc queue_list] %s\n", MSG_QMOD_dc_OPT_ISAGE);
484
fprintf(fp, "job_wc_queue_list {job_tasks|wc_queue}[{','|' '}{job_tasks|wc_queue}[{','|' '}...]]\n");
485
fprintf(fp, "job_list {job_tasks}[{','|' '}job_tasks[{','|' '}...]]\n");
486
fprintf(fp, "job_tasks {{job_id'.'task_id_range}|job_name|pattern}[' -t 'task_id_range]\n");
487
fprintf(fp, "task_id_range task_id['-'task_id[':'step]]\n");
488
fprintf(fp, "wc_cqueue %s\n", MSG_QSTAT_HELP_WCCQ);
489
fprintf(fp, "wc_host %s\n", MSG_QSTAT_HELP_WCHOST);
490
fprintf(fp, "wc_hostgroup %s\n", MSG_QSTAT_HELP_WCHG);
491
fprintf(fp, "wc_qinstance wc_cqueue@wc_host\n");
492
fprintf(fp, "wc_qdomain wc_cqueue@wc_hostgroup\n");
493
fprintf(fp, "wc_queue wc_cqueue|wc_qdomain|wc_qinstance\n");
494
fprintf(fp, "wc_queue_list wc_queue[','wc_queue[','...]]\n");
496
/* display option usage */
497
fprintf(fp, MSG_QDEL_not_available_OPT_USAGE_S,what);