~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/utilbin/spooldefaults.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
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
 
16
 * 
 
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.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
 
 
33
#include <stdio.h>
 
34
#include <stdlib.h>
 
35
#include <string.h>
 
36
 
 
37
#include "sge_bootstrap.h"
 
38
#include "sgermon.h"
 
39
#include "sge_log.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"
 
45
#include "sge_prog.h"
 
46
#include "sge_feature.h"
 
47
#include "sge_answer.h"
 
48
#include "sge_manop.h"
 
49
#include "sge_object.h"
 
50
#include "sge_pe.h"
 
51
#include "sge_centry.h"
 
52
#include "sge_userset.h"
 
53
#include "sge_all_listsL.h"
 
54
#include "sge_conf.h"
 
55
#include "sge_mt_init.h"
 
56
#include "sge.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"
 
67
 
 
68
static int spool_object_list(const char *directory,
 
69
                             const spooling_field *fields, 
 
70
                             const spool_flatfile_instr *instr,
 
71
                             const lDescr *descr,
 
72
                             sge_object_type obj_type); 
 
73
 
 
74
static void usage(const char *argv0)
 
75
{
 
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);
 
96
}
 
97
 
 
98
static int init_framework(sge_gdi_ctx_class_t *ctx)
 
99
{
 
100
   int ret = EXIT_FAILURE;
 
101
 
 
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);
 
107
 
 
108
   DENTER(TOP_LAYER, "init_framework");
 
109
 
 
110
#ifdef HP1164   
 
111
   sge_set_admin_username("none", NULL);
 
112
#endif
 
113
 
 
114
   /* create spooling context */
 
115
   spooling_context = spool_create_dynamic_context(&answer_list, 
 
116
                                                   spooling_method,
 
117
                                                   spooling_lib, 
 
118
                                                   spooling_params);
 
119
   answer_list_output(&answer_list);
 
120
   if (spooling_context == NULL) {
 
121
      CRITICAL((SGE_EVENT, MSG_SPOOLDEFAULTS_CANNOTCREATECONTEXT));
 
122
   } else {
 
123
      spool_set_default_context(spooling_context);
 
124
 
 
125
      /* initialize spooling context */
 
126
      if (!spool_startup_context(&answer_list, spooling_context, true)) {
 
127
         CRITICAL((SGE_EVENT, MSG_SPOOLDEFAULTS_CANNOTSTARTUPCONTEXT));
 
128
      } else {
 
129
         ret = EXIT_SUCCESS;
 
130
      }
 
131
      answer_list_output(&answer_list);
 
132
   }
 
133
 
 
134
   DRETURN(ret);
 
135
}
 
136
 
 
137
static int spool_manops(sge_object_type type, int argc, char *argv[])
 
138
{
 
139
   int ret = EXIT_SUCCESS;
 
140
   int i;
 
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);
 
145
 
 
146
   DENTER(TOP_LAYER, "spool_manops");
 
147
 
 
148
   if (*lpp == NULL) {
 
149
      *lpp = lCreateList("master list", descr);
 
150
   }
 
151
 
 
152
   for (i = 2; i < argc; i++) {
 
153
      const char *name = argv[i];
 
154
      lListElem *ep = lAddElemStr(lpp, key, name, descr);
 
155
 
 
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);
 
160
         ret = EXIT_FAILURE;
 
161
      }
 
162
   }
 
163
 
 
164
   DRETURN(ret);
 
165
}
 
166
 
 
167
static int spool_configuration(int argc, char *argv[])
 
168
{
 
169
   int ret = EXIT_SUCCESS;
 
170
   lListElem *conf = NULL;
 
171
   lList *answer_list = NULL;
 
172
   spooling_field *fields = sge_build_CONF_field_list(true);
 
173
 
 
174
   DENTER(TOP_LAYER, "spool_configuration");
 
175
 
 
176
   conf = spool_flatfile_read_object(&answer_list, CONF_Type, NULL,
 
177
                                   fields, NULL, false, &qconf_sfi,
 
178
                                   SP_FORM_ASCII, NULL, argv[2]);
 
179
   FREE(fields);
 
180
   if (conf == NULL) {
 
181
      ERROR((SGE_EVENT, MSG_SPOOLDEFAULTS_CANTREADGLOBALCONF_S, argv[2]));
 
182
      ret = EXIT_FAILURE;
 
183
   } else {
 
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 */
 
188
         ret = EXIT_FAILURE;
 
189
      }
 
190
      answer_list_output(&answer_list);
 
191
   }
 
192
   lFreeElem(&conf);
 
193
 
 
194
   DRETURN(ret);
 
195
}
 
196
 
 
197
static int spool_local_conf(int argc, char *argv[])
 
198
{
 
199
   int ret = EXIT_SUCCESS;
 
200
 
 
201
   DENTER(TOP_LAYER, "spool_local_conf");
 
202
 
 
203
   /* we get an additional argument: the config name */
 
204
   if (argc < 4) {
 
205
      usage(argv[0]);
 
206
      ret = EXIT_FAILURE;
 
207
   } else {
 
208
      lList *answer_list = NULL;
 
209
      spooling_field *fields = sge_build_CONF_field_list(true);
 
210
      lListElem *conf = NULL;
 
211
 
 
212
      conf = spool_flatfile_read_object(&answer_list, CONF_Type, NULL,
 
213
                                   fields, NULL, false, &qconf_sfi,
 
214
                                   SP_FORM_ASCII, NULL, argv[2]);
 
215
      FREE(fields);
 
216
 
 
217
      if (conf == NULL) {
 
218
         ERROR((SGE_EVENT, MSG_SPOOLDEFAULTS_CANTREADLOCALCONF_S, argv[2]));
 
219
         ret = EXIT_FAILURE;
 
220
      } else {
 
221
         /* check if a config is already there */
 
222
         lListElem *le = spool_read_object(NULL, spool_get_default_context(), SGE_TYPE_CONFIG, argv[3]); 
 
223
         if (le == NULL) { 
 
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 */
 
229
               ret = EXIT_FAILURE;
 
230
            } 
 
231
         } else {
 
232
            fprintf(stderr, "config already there!\n");
 
233
         }
 
234
         answer_list_output(&answer_list);
 
235
         lFreeElem(&conf);
 
236
      }
 
237
      lFreeList(&answer_list);
 
238
   }
 
239
 
 
240
   DRETURN(ret);
 
241
}
 
242
 
 
243
static int spool_sharetree(int argc, char *argv[])
 
244
{
 
245
   const spooling_field *fields = sge_build_STN_field_list(true, false);
 
246
   int ret; 
 
247
 
 
248
   ret = spool_object_list(argv[2], fields, &qconf_sfi, STN_Type, SGE_TYPE_SHARETREE);
 
249
   FREE(fields);
 
250
   return ret;
 
251
   }
 
252
 
 
253
static int spool_complexes(int argc, char *argv[])
 
254
{
 
255
   return spool_object_list(argv[2], CE_fields, &qconf_sfi, CE_Type, SGE_TYPE_CENTRY);
 
256
}
 
257
 
 
258
static int spool_adminhosts(int argc, char *argv[])
 
259
{
 
260
   return spool_object_list(argv[2], AH_fields, &qconf_sfi, AH_Type, SGE_TYPE_ADMINHOST);
 
261
}
 
262
 
 
263
static int spool_calendars(int argc, char *argv[])
 
264
{
 
265
   return spool_object_list(argv[2], CAL_fields, &qconf_sfi, CAL_Type, SGE_TYPE_CALENDAR);
 
266
}
 
267
 
 
268
static int spool_ckpts(int argc, char *argv[])
 
269
{
 
270
   return spool_object_list(argv[2], CK_fields, &qconf_sfi, CK_Type, SGE_TYPE_CKPT);
 
271
}
 
272
 
 
273
static int spool_cqueues(int argc, char *argv[])
 
274
{
 
275
   lList *answer_list = NULL;
 
276
   spool_read_list(&answer_list, spool_get_default_context(), 
 
277
                   object_type_get_master_list(SGE_TYPE_CENTRY), 
 
278
                   SGE_TYPE_CENTRY);
 
279
   spool_read_list(&answer_list, spool_get_default_context(), 
 
280
                   object_type_get_master_list(SGE_TYPE_EXECHOST), 
 
281
                   SGE_TYPE_EXECHOST);
 
282
   answer_list_output(&answer_list);
 
283
 
 
284
   return spool_object_list(argv[2], CQ_fields, &qconf_sfi, CQ_Type, SGE_TYPE_CQUEUE);
 
285
}
 
286
 
 
287
static int spool_exechosts(int argc, char *argv[])
 
288
{
 
289
   lList *answer_list = NULL;
 
290
   const spooling_field *fields = sge_build_EH_field_list(true, false, false);
 
291
   int ret; 
 
292
 
 
293
   spool_read_list(&answer_list, spool_get_default_context(), 
 
294
                   object_type_get_master_list(SGE_TYPE_CENTRY), 
 
295
                   SGE_TYPE_CENTRY);
 
296
   answer_list_output(&answer_list);
 
297
 
 
298
   ret = spool_object_list(argv[2], fields, &qconf_sfi, EH_Type, SGE_TYPE_EXECHOST);
 
299
   FREE(fields);
 
300
   return ret;
 
301
}
 
302
 
 
303
static int spool_projects(int argc, char *argv[])
 
304
{
 
305
   const spooling_field *fields = sge_build_PR_field_list(true);
 
306
   int ret; 
 
307
 
 
308
   ret = spool_object_list(argv[2], fields, &qconf_sfi, PR_Type, SGE_TYPE_PROJECT);
 
309
   FREE(fields);
 
310
   return ret;
 
311
}
 
312
 
 
313
static int spool_submithosts(int argc, char *argv[])
 
314
{
 
315
   return spool_object_list(argv[2], SH_fields, &qconf_sfi, SH_Type, SGE_TYPE_SUBMITHOST);
 
316
}
 
317
 
 
318
static int spool_users(int argc, char *argv[])
 
319
{
 
320
   const spooling_field *fields = sge_build_UU_field_list(true);
 
321
   int ret; 
 
322
 
 
323
   ret = spool_object_list(argv[2], fields, &qconf_sfi, UU_Type, SGE_TYPE_PROJECT);
 
324
   FREE(fields);
 
325
   return ret;
 
326
}
 
327
 
 
328
static int spool_pes(int argc, char *argv[])
 
329
{
 
330
   return spool_object_list(argv[2], PE_fields, &qconf_sfi, PE_Type, SGE_TYPE_PE);
 
331
}
 
332
 
 
333
static int spool_usersets(int argc, char *argv[])
 
334
{
 
335
   return spool_object_list(argv[2], US_fields, &qconf_sfi, US_Type, SGE_TYPE_USERSET);
 
336
}
 
337
 
 
338
static int spool_object_list(const char *directory,
 
339
                             const spooling_field *fields, 
 
340
                             const spool_flatfile_instr *instr,
 
341
                             const lDescr *descr,
 
342
                             sge_object_type obj_type)
 
343
{
 
344
   int ret = EXIT_SUCCESS;
 
345
   lList *answer_list = NULL;
 
346
   lListElem *ep;
 
347
   lList *direntries;
 
348
   lListElem *direntry;
 
349
   const char *name;
 
350
   dstring file = DSTRING_INIT;
 
351
 
 
352
   DENTER(TOP_LAYER, "spool_object_list");
 
353
 
 
354
   direntries = sge_get_dirents(directory);
 
355
   if (direntries) {
 
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));
 
363
            
 
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 */
 
367
               ret = EXIT_FAILURE;
 
368
               answer_list_output(&answer_list);
 
369
               break;
 
370
            }
 
371
            lFreeElem(&ep);
 
372
         }
 
373
      }
 
374
   }
 
375
   lFreeList(&direntries);
 
376
   sge_dstring_free(&file);
 
377
 
 
378
   lFreeList(&answer_list);
 
379
 
 
380
   DRETURN(ret);
 
381
}
 
382
 
 
383
int main(int argc, char *argv[])
 
384
{
 
385
   int ret = EXIT_SUCCESS;
 
386
   lList *answer_list = NULL;
 
387
   sge_gdi_ctx_class_t *ctx = NULL;
 
388
 
 
389
   DENTER_MAIN(TOP_LAYER, "spooldefaults");
 
390
 
 
391
   log_state_set_log_gui(0);
 
392
   prof_mt_init();
 
393
 
 
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);
 
397
   }
 
398
 
 
399
   /* parse commandline */
 
400
   if (argc < 2) {
 
401
      usage(argv[0]);
 
402
      ret = EXIT_FAILURE;
 
403
   } else {
 
404
      ret = init_framework(ctx);
 
405
 
 
406
      if (ret == EXIT_SUCCESS) {
 
407
         if (strcmp(argv[1], "test") == 0) {
 
408
            /* nothing to do - init_framework succeeded */
 
409
         } else {
 
410
            /* all other commands have at least one parameter */
 
411
            if (argc < 3) {
 
412
               usage(argv[0]);
 
413
               ret = EXIT_FAILURE;
 
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);
 
446
            } else {
 
447
               usage(argv[0]);
 
448
               ret = EXIT_FAILURE;
 
449
            }
 
450
         }
 
451
      }
 
452
   }
 
453
 
 
454
   if ((ret != EXIT_FAILURE) && (spool_get_default_context() != NULL)) {
 
455
      time_t next_trigger = 0;
 
456
 
 
457
      if (!spool_trigger_context(&answer_list, spool_get_default_context(), 
 
458
                                 0, &next_trigger)) {
 
459
         ret = EXIT_FAILURE;
 
460
      }
 
461
      if (!spool_shutdown_context(&answer_list, spool_get_default_context())) {
 
462
         ret = EXIT_FAILURE;
 
463
      }
 
464
   }
 
465
 
 
466
   answer_list_output(&answer_list);
 
467
 
 
468
   sge_prof_cleanup();
 
469
 
 
470
   SGE_EXIT((void **)&ctx, ret);
 
471
 
 
472
   DRETURN(ret);
 
473
}