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__*/
37
#include "sge_bootstrap.h"
40
#include "sge_unistd.h"
41
#include "sge_dstring.h"
42
#include "sge_spool.h"
43
#include "sge_uidgid.h"
44
#include "setup_path.h"
46
#include "sge_feature.h"
47
#include "sge_answer.h"
48
#include "sge_manop.h"
49
#include "sge_object.h"
51
#include "sge_centry.h"
52
#include "sge_userset.h"
53
#include "sge_all_listsL.h"
55
#include "sge_mt_init.h"
57
#include "spool/sge_spooling.h"
58
#include "spool/loader/sge_spooling_loader.h"
59
#include "spool/flatfile/sge_spooling_flatfile.h"
60
#include "spool/flatfile/sge_flatfile_obj.h"
61
#include "spool/flatfile/sge_flatfile.h"
62
#include "spool/sge_dirent.h"
63
#include "msg_utilbin.h"
64
#include "sge_profiling.h"
65
#include "gdi/sge_gdi_ctx.h"
66
#include "spool/msg_spoollib.h"
68
static int spool_object_list(const char *directory,
69
const spooling_field *fields,
70
const spool_flatfile_instr *instr,
72
sge_object_type obj_type);
74
static void usage(const char *argv0)
76
fprintf(stderr, "%s\n %s command\n\n", MSG_UTILBIN_USAGE, argv0);
77
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_COMMANDINTRO1);
78
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_COMMANDINTRO2);
79
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_TEST);
80
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_ADMINHOSTS);
81
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_CALENDARS);
82
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_CKPTS);
83
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_COMPLEXES);
84
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_CONFIGURATION);
85
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_CQUEUES);
86
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_EXECHOSTS);
87
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_LOCAL_CONF);
88
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_MANAGERS);
89
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_OPERATORS);
90
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_PES);
91
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_PROJECTS);
92
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_SHARETREE);
93
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_SUBMITHOSTS);
94
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_USERS);
95
fprintf(stderr, "%s\n", MSG_SPOOLDEFAULTS_USERSETS);
98
static int init_framework(sge_gdi_ctx_class_t *ctx)
100
int ret = EXIT_FAILURE;
102
lList *answer_list = NULL;
103
lListElem *spooling_context = NULL;
104
const char *spooling_method = ctx->get_spooling_method(ctx);
105
const char *spooling_lib = ctx->get_spooling_lib(ctx);
106
const char *spooling_params = ctx->get_spooling_params(ctx);
108
DENTER(TOP_LAYER, "init_framework");
111
sge_set_admin_username("none", NULL);
114
/* create spooling context */
115
spooling_context = spool_create_dynamic_context(&answer_list,
119
answer_list_output(&answer_list);
120
if (spooling_context == NULL) {
121
CRITICAL((SGE_EVENT, MSG_SPOOLDEFAULTS_CANNOTCREATECONTEXT));
123
spool_set_default_context(spooling_context);
125
/* initialize spooling context */
126
if (!spool_startup_context(&answer_list, spooling_context, true)) {
127
CRITICAL((SGE_EVENT, MSG_SPOOLDEFAULTS_CANNOTSTARTUPCONTEXT));
131
answer_list_output(&answer_list);
137
static int spool_manops(sge_object_type type, int argc, char *argv[])
139
int ret = EXIT_SUCCESS;
141
lList *answer_list = NULL;
142
lList **lpp = object_type_get_master_list(type);
143
int key = object_type_get_key_nm(type);
144
const lDescr *descr = object_type_get_descr(type);
146
DENTER(TOP_LAYER, "spool_manops");
149
*lpp = lCreateList("master list", descr);
152
for (i = 2; i < argc; i++) {
153
const char *name = argv[i];
154
lListElem *ep = lAddElemStr(lpp, key, name, descr);
156
if (!spool_write_object(&answer_list, spool_get_default_context(),
157
ep, name, type, true)) {
158
/* error output has been done in spooling function */
159
answer_list_output(&answer_list);
167
static int spool_configuration(int argc, char *argv[])
169
int ret = EXIT_SUCCESS;
170
lListElem *conf = NULL;
171
lList *answer_list = NULL;
172
spooling_field *fields = sge_build_CONF_field_list(true);
174
DENTER(TOP_LAYER, "spool_configuration");
176
conf = spool_flatfile_read_object(&answer_list, CONF_Type, NULL,
177
fields, NULL, false, &qconf_sfi,
178
SP_FORM_ASCII, NULL, argv[2]);
181
ERROR((SGE_EVENT, MSG_SPOOLDEFAULTS_CANTREADGLOBALCONF_S, argv[2]));
184
/* put config into a list - we can't spool free objects */
185
lSetHost(conf, CONF_name, SGE_GLOBAL_NAME);
186
if (!spool_write_object(&answer_list, spool_get_default_context(), conf, SGE_GLOBAL_NAME, SGE_TYPE_CONFIG, true)) {
187
/* error output has been done in spooling function */
190
answer_list_output(&answer_list);
197
static int spool_local_conf(int argc, char *argv[])
199
int ret = EXIT_SUCCESS;
201
DENTER(TOP_LAYER, "spool_local_conf");
203
/* we get an additional argument: the config name */
208
lList *answer_list = NULL;
209
spooling_field *fields = sge_build_CONF_field_list(true);
210
lListElem *conf = NULL;
212
conf = spool_flatfile_read_object(&answer_list, CONF_Type, NULL,
213
fields, NULL, false, &qconf_sfi,
214
SP_FORM_ASCII, NULL, argv[2]);
218
ERROR((SGE_EVENT, MSG_SPOOLDEFAULTS_CANTREADLOCALCONF_S, argv[2]));
221
/* check if a config is already there */
222
lListElem *le = spool_read_object(NULL, spool_get_default_context(), SGE_TYPE_CONFIG, argv[3]);
224
/* put config into a list - we can't spool free objects */
225
lSetHost(conf, CONF_name, argv[3]);
226
if (!spool_write_object(&answer_list, spool_get_default_context(),
227
conf, argv[3], SGE_TYPE_CONFIG, true)) {
228
/* error output has been done in spooling function */
232
fprintf(stderr, "config already there!\n");
234
answer_list_output(&answer_list);
237
lFreeList(&answer_list);
243
static int spool_sharetree(int argc, char *argv[])
245
const spooling_field *fields = sge_build_STN_field_list(true, false);
248
ret = spool_object_list(argv[2], fields, &qconf_sfi, STN_Type, SGE_TYPE_SHARETREE);
253
static int spool_complexes(int argc, char *argv[])
255
return spool_object_list(argv[2], CE_fields, &qconf_sfi, CE_Type, SGE_TYPE_CENTRY);
258
static int spool_adminhosts(int argc, char *argv[])
260
return spool_object_list(argv[2], AH_fields, &qconf_sfi, AH_Type, SGE_TYPE_ADMINHOST);
263
static int spool_calendars(int argc, char *argv[])
265
return spool_object_list(argv[2], CAL_fields, &qconf_sfi, CAL_Type, SGE_TYPE_CALENDAR);
268
static int spool_ckpts(int argc, char *argv[])
270
return spool_object_list(argv[2], CK_fields, &qconf_sfi, CK_Type, SGE_TYPE_CKPT);
273
static int spool_cqueues(int argc, char *argv[])
275
lList *answer_list = NULL;
276
spool_read_list(&answer_list, spool_get_default_context(),
277
object_type_get_master_list(SGE_TYPE_CENTRY),
279
spool_read_list(&answer_list, spool_get_default_context(),
280
object_type_get_master_list(SGE_TYPE_EXECHOST),
282
answer_list_output(&answer_list);
284
return spool_object_list(argv[2], CQ_fields, &qconf_sfi, CQ_Type, SGE_TYPE_CQUEUE);
287
static int spool_exechosts(int argc, char *argv[])
289
lList *answer_list = NULL;
290
const spooling_field *fields = sge_build_EH_field_list(true, false, false);
293
spool_read_list(&answer_list, spool_get_default_context(),
294
object_type_get_master_list(SGE_TYPE_CENTRY),
296
answer_list_output(&answer_list);
298
ret = spool_object_list(argv[2], fields, &qconf_sfi, EH_Type, SGE_TYPE_EXECHOST);
303
static int spool_projects(int argc, char *argv[])
305
const spooling_field *fields = sge_build_PR_field_list(true);
308
ret = spool_object_list(argv[2], fields, &qconf_sfi, PR_Type, SGE_TYPE_PROJECT);
313
static int spool_submithosts(int argc, char *argv[])
315
return spool_object_list(argv[2], SH_fields, &qconf_sfi, SH_Type, SGE_TYPE_SUBMITHOST);
318
static int spool_users(int argc, char *argv[])
320
const spooling_field *fields = sge_build_UU_field_list(true);
323
ret = spool_object_list(argv[2], fields, &qconf_sfi, UU_Type, SGE_TYPE_PROJECT);
328
static int spool_pes(int argc, char *argv[])
330
return spool_object_list(argv[2], PE_fields, &qconf_sfi, PE_Type, SGE_TYPE_PE);
333
static int spool_usersets(int argc, char *argv[])
335
return spool_object_list(argv[2], US_fields, &qconf_sfi, US_Type, SGE_TYPE_USERSET);
338
static int spool_object_list(const char *directory,
339
const spooling_field *fields,
340
const spool_flatfile_instr *instr,
342
sge_object_type obj_type)
344
int ret = EXIT_SUCCESS;
345
lList *answer_list = NULL;
350
dstring file = DSTRING_INIT;
352
DENTER(TOP_LAYER, "spool_object_list");
354
direntries = sge_get_dirents(directory);
356
for_each(direntry, direntries) {
357
name = lGetString(direntry, ST_name);
358
if (name[0] != '.') {
359
sge_dstring_sprintf(&file, "%s/%s", directory, name);
360
ep = spool_flatfile_read_object(&answer_list, descr, NULL,
361
fields, NULL, true, instr,
362
SP_FORM_ASCII, NULL, sge_dstring_get_string(&file));
364
if (ep != NULL && !spool_write_object(&answer_list, spool_get_default_context(), ep,
365
name, obj_type, true)) {
366
/* error output has been done in spooling function */
368
answer_list_output(&answer_list);
375
lFreeList(&direntries);
376
sge_dstring_free(&file);
378
lFreeList(&answer_list);
383
int main(int argc, char *argv[])
385
int ret = EXIT_SUCCESS;
386
lList *answer_list = NULL;
387
sge_gdi_ctx_class_t *ctx = NULL;
389
DENTER_MAIN(TOP_LAYER, "spooldefaults");
391
log_state_set_log_gui(0);
394
if (sge_setup2(&ctx, SPOOLDEFAULTS, MAIN_THREAD, &answer_list, false) != AE_OK) {
395
answer_list_output(&answer_list);
396
SGE_EXIT((void **)&ctx, EXIT_FAILURE);
399
/* parse commandline */
404
ret = init_framework(ctx);
406
if (ret == EXIT_SUCCESS) {
407
if (strcmp(argv[1], "test") == 0) {
408
/* nothing to do - init_framework succeeded */
410
/* all other commands have at least one parameter */
414
} else if (strcmp(argv[1], "adminhosts") == 0) {
415
ret = spool_adminhosts(argc, argv);
416
} else if (strcmp(argv[1], "calendars") == 0) {
417
ret = spool_calendars(argc, argv);
418
} else if (strcmp(argv[1], "ckpts") == 0) {
419
ret = spool_ckpts(argc, argv);
420
} else if (strcmp(argv[1], "complexes") == 0) {
421
ret = spool_complexes(argc, argv);
422
} else if (strcmp(argv[1], "configuration") == 0) {
423
ret = spool_configuration(argc, argv);
424
} else if (strcmp(argv[1], "cqueues") == 0) {
425
ret = spool_cqueues(argc, argv);
426
} else if (strcmp(argv[1], "exechosts") == 0) {
427
ret = spool_exechosts(argc, argv);
428
} else if (strcmp(argv[1], "local_conf") == 0) {
429
ret = spool_local_conf(argc, argv);
430
} else if (strcmp(argv[1], "managers") == 0) {
431
ret = spool_manops(SGE_TYPE_MANAGER, argc, argv);
432
} else if (strcmp(argv[1], "operators") == 0) {
433
ret = spool_manops(SGE_TYPE_OPERATOR, argc, argv);
434
} else if (strcmp(argv[1], "pes") == 0) {
435
ret = spool_pes(argc, argv);
436
} else if (strcmp(argv[1], "projects") == 0) {
437
ret = spool_projects(argc, argv);
438
} else if (strcmp(argv[1], "sharetree") == 0) {
439
ret = spool_sharetree(argc, argv);
440
} else if (strcmp(argv[1], "submithosts") == 0) {
441
ret = spool_submithosts(argc, argv);
442
} else if (strcmp(argv[1], "users") == 0) {
443
ret = spool_users(argc, argv);
444
} else if (strcmp(argv[1], "usersets") == 0) {
445
ret = spool_usersets(argc, argv);
454
if ((ret != EXIT_FAILURE) && (spool_get_default_context() != NULL)) {
455
time_t next_trigger = 0;
457
if (!spool_trigger_context(&answer_list, spool_get_default_context(),
461
if (!spool_shutdown_context(&answer_list, spool_get_default_context())) {
466
answer_list_output(&answer_list);
470
SGE_EXIT((void **)&ctx, ret);