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__*/
38
#include "rmon/sgermon.h"
39
#include "uti/sge_string.h"
40
#include "uti/sge_stdio.h"
41
#include "sge_all_listsL.h"
42
#include "sge_bootstrap.h"
45
#include "sge_unistd.h"
46
#include "sge_dstring.h"
47
#include "sge_spool.h"
48
#include "sge_uidgid.h"
49
#include "setup_path.h"
51
#include "sge_feature.h"
52
#include "sge_answer.h"
53
#include "sge_mt_init.h"
54
#include "spool/sge_spooling.h"
55
#include "spool/loader/sge_spooling_loader.h"
56
#include "spool/berkeleydb/sge_bdb.h"
57
#include "gdi/sge_gdi_ctx.h"
59
#include "msg_common.h"
60
#include "msg_utilbin.h"
65
usage(const char *argv0)
67
fprintf(stderr, "%s\n %s command\n\n", MSG_UTILBIN_USAGE, argv0);
68
fprintf(stderr, "%s\n", MSG_DBSTAT_COMMANDINTRO1);
69
fprintf(stderr, "%s\n", MSG_DBSTAT_COMMANDINTRO2);
70
fprintf(stderr, "%s\n", MSG_DBSTAT_LIST);
71
fprintf(stderr, "%s\n", MSG_DBSTAT_DUMP);
72
fprintf(stderr, "%s\n", MSG_DBSTAT_LOAD);
73
fprintf(stderr, "%s\n", MSG_DBSTAT_DELETE);
77
init_framework(sge_gdi_ctx_class_t *ctx, bdb_info *info)
79
int ret = EXIT_FAILURE;
81
lList *answer_list = NULL;
82
lListElem *spooling_context = NULL;
83
const char *spooling_method = ctx->get_spooling_method(ctx);
84
const char *spooling_lib = ctx->get_spooling_lib(ctx);
85
const char *spooling_params = ctx->get_spooling_params(ctx);
87
DENTER(TOP_LAYER, "init_framework");
90
sge_set_admin_username("none", NULL);
93
/* create spooling context */
94
spooling_context = spool_create_dynamic_context(&answer_list,
98
answer_list_output(&answer_list);
99
if (!strcmp(bootstrap_get_spooling_method(),"classic")) {
100
CRITICAL((SGE_EVENT, MSG_SPOOLDEFAULTS_CANTHANDLECLASSICSPOOLING));
101
} else if (spooling_context == NULL) {
102
CRITICAL((SGE_EVENT, MSG_SPOOLDEFAULTS_CANNOTCREATECONTEXT));
104
spool_set_default_context(spooling_context);
105
spool_set_option(&answer_list, spooling_context, "recover=false");
106
answer_list_output(&answer_list);
108
/* initialize spooling context */
109
if (!spool_startup_context(&answer_list, spooling_context, true)) {
110
CRITICAL((SGE_EVENT, MSG_SPOOLDEFAULTS_CANNOTSTARTUPCONTEXT));
112
/* search the berkeley db info - take it from any object type,
113
* berkeleydb spools all objects using the same rule.
115
lListElem *type = spool_context_search_type(spooling_context,
117
lListElem *rule = spool_type_search_default_rule(type);
118
*info = (bdb_info)lGetRef(rule, SPR_clientdata);
121
answer_list_output(&answer_list);
128
get_database_from_key(const char *key)
130
bdb_database database = BDB_CONFIG_DB;
133
if (strncmp(key, "J", 1) == 0 ||
134
strncmp(key, "PET", 3) == 0) {
135
database = BDB_JOB_DB;
142
static const lDescr *
143
get_descr_from_key(const char *key)
145
const lDescr *descr = NULL;
147
DENTER(TOP_LAYER, "get_descr_from_key");
150
struct saved_vars_s *context = NULL;
151
const char *type_name;
153
type_name = sge_strtok_r(key, ":", &context);
154
if (type_name != NULL) {
155
sge_object_type type = object_name_get_type(type_name);
156
if (type != SGE_TYPE_ALL) {
157
descr = object_type_get_descr(type);
161
sge_free_saved_vars(context);
164
ERROR((SGE_EVENT, MSG_DBSTAT_INVALIDKEY_S, key));
172
list_objects(bdb_info info, const char *key)
174
int ret = EXIT_SUCCESS;
176
lList *answer_list = NULL;
177
bdb_database database;
179
DENTER(TOP_LAYER, "list_objects");
181
database = get_database_from_key(key);
186
dbret = spool_berkeleydb_read_keys(&answer_list, info, database,
189
/* if no key was given, read the job database as well */
190
if (strlen(key) == 0) {
191
dbret = spool_berkeleydb_read_keys(&answer_list, info, BDB_JOB_DB,
197
const lListElem *elem;
198
for_each(elem, list) {
199
fprintf(stdout, "%s\n", lGetString(elem, STU_name));
202
answer_list_output(&answer_list);
213
dump_object(bdb_info info, const char *key)
215
int ret = EXIT_SUCCESS;
217
lList *answer_list = NULL;
218
bdb_database database;
220
DENTER(TOP_LAYER, "dump_object");
222
database = get_database_from_key(key);
224
/* start a transaction */
225
dbret = spool_berkeleydb_start_transaction(&answer_list, info);
227
answer_list_output(&answer_list);
230
/* job script is spooled as string, not as cull object */
231
if (strncmp(key, "JOBSCRIPT:", 10) == 0) {
232
const char *job_script;
233
job_script = spool_berkeleydb_read_string(&answer_list, info, database, key);
234
if (job_script == NULL) {
235
answer_list_output(&answer_list);
244
object = spool_berkeleydb_read_object(&answer_list, info, database, key);
245
if (object == NULL) {
246
answer_list_output(&answer_list);
249
lDumpElemFp(stdout, object, 0);
255
/* close the transaction */
256
dbret = spool_berkeleydb_end_transaction(&answer_list, info,
257
(ret == EXIT_SUCCESS) ? true : false);
259
answer_list_output(&answer_list);
267
load_object(bdb_info info, const char *key, const char *fname)
269
int ret = EXIT_SUCCESS;
271
lList *answer_list = NULL;
272
bdb_database database;
274
lListElem *object = NULL;
276
DENTER(TOP_LAYER, "load_object");
278
database = get_database_from_key(key);
279
descr = get_descr_from_key(key);
285
if (ret == EXIT_SUCCESS) {
288
if((fd = fopen(fname, "r")) == NULL) {
289
ERROR((SGE_EVENT, MSG_ERROROPENINGFILEFORREADING_SS, fname, strerror(errno)));
292
object = lUndumpElemFp(fd, descr);
294
if (object == NULL) {
295
ERROR((SGE_EVENT, MSG_DBSTAT_ERRORUNDUMPING_S, fname));
301
if (object != NULL) {
302
/* start a transaction */
303
dbret = spool_berkeleydb_start_transaction(&answer_list, info);
305
answer_list_output(&answer_list);
309
dbret = spool_berkeleydb_write_object(&answer_list, info, database, object, key);
311
answer_list_output(&answer_list);
315
/* close the transaction */
316
dbret = spool_berkeleydb_end_transaction(&answer_list, info,
317
(ret == EXIT_SUCCESS) ? true : false);
319
answer_list_output(&answer_list);
330
ERROR((SGE_EVENT, MSG_FILE_ERRORCLOSEINGXY_SS, fname, strerror(errno)));
331
DRETURN(EXIT_FAILURE);
335
delete_object( bdb_info info, const char *key)
337
int ret = EXIT_SUCCESS;
339
lList *answer_list = NULL;
340
bdb_database database;
342
DENTER(TOP_LAYER, "delete_object");
344
database = get_database_from_key(key);
346
/* start a transaction */
347
dbret = spool_berkeleydb_start_transaction(&answer_list, info);
349
answer_list_output(&answer_list);
352
/* delete object with given key */
353
dbret = spool_berkeleydb_delete_object(&answer_list, info, database,
356
answer_list_output(&answer_list);
359
fprintf(stdout, "deleted object with key "SFQ"\n", key);
363
/* close the transaction */
364
dbret = spool_berkeleydb_end_transaction(&answer_list, info,
365
(ret == EXIT_SUCCESS) ? true : false);
367
answer_list_output(&answer_list);
376
main(int argc, char *argv[])
378
int ret = EXIT_SUCCESS;
379
lList *answer_list = NULL;
380
sge_gdi_ctx_class_t *ctx = NULL;
382
DENTER_MAIN(TOP_LAYER, "spooledit");
384
if (sge_setup2(&ctx, SPOOLDEFAULTS, MAIN_THREAD, &answer_list, false) != AE_OK) {
385
answer_list_output(&answer_list);
386
SGE_EXIT((void**)&ctx, 1);
389
if (ret == EXIT_SUCCESS) {
390
/* parse commandline */
395
bdb_info info = NULL;
396
ret = init_framework(ctx, &info);
398
if (ret == EXIT_SUCCESS) {
399
if (strcmp(argv[1], "list") == 0) {
400
ret = list_objects(info, argc > 2 ? argv[2] : "");
401
} else if (strcmp(argv[1], "dump") == 0) {
406
ret = dump_object(info, argv[2]);
408
} else if (strcmp(argv[1], "load") == 0) {
413
ret = load_object(info, argv[2], argv[3]);
415
} else if (strcmp(argv[1], "delete") == 0) {
420
ret = delete_object(info, argv[2]);
430
if (spool_get_default_context() != NULL) {
432
time_t next_trigger = 0;
433
if (!spool_trigger_context(&answer_list, spool_get_default_context(),
438
if (!spool_shutdown_context(&answer_list, spool_get_default_context())) {
443
answer_list_output(&answer_list);
445
SGE_EXIT((void**)&ctx, ret);