~ubuntu-branches/ubuntu/vivid/slurm-llnl/vivid

« back to all changes in this revision

Viewing changes to src/plugins/jobcomp/pgsql/jobcomp_pgsql.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2009-09-24 23:28:15 UTC
  • mfrom: (1.1.11 upstream) (3.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090924232815-enh65jn32q1ebg07
Tags: 2.0.5-1
* New upstream release 
* Changed dependecy from lib-mysqlclient15 to lib-mysqlclient 
* Added Default-Start for runlevel 2 and 4 and $remote_fs requirement in
  init.d scripts (Closes: #541252)
* Postinst checks for wrong runlevels 2 and 4 links
* Upgraded to standard version 3.8.3
* Add lintian overrides for missing slurm-llnl-configurator.html in doc
  base registration
* modified postrm scripts to ignore pkill return value in order to avoid
  postrm failure when no slurm process is running
* Checking for slurmctld.pid before cancelling running and pending
  jobs during package removal 

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *  $Id: storage_pgsql.c 10893 2007-01-29 21:53:48Z da $
5
5
 *****************************************************************************
6
6
 *  Copyright (C) 2004-2007 The Regents of the University of California.
 
7
 *  Copyright (C) 2008-2009 Lawrence Livermore National Security.
7
8
 *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
8
9
 *  Written by Danny Auble <da@llnl.gov>
9
10
 *  
10
11
 *  This file is part of SLURM, a resource management program.
11
 
 *  For details, see <http://www.llnl.gov/linux/slurm/>.
 
12
 *  For details, see <https://computing.llnl.gov/linux/slurm/>.
 
13
 *  Please also read the included file: DISCLAIMER.
12
14
 *  
13
15
 *  SLURM is free software; you can redistribute it and/or modify it under
14
16
 *  the terms of the GNU General Public License as published by the Free
77
79
const char plugin_type[] = "jobcomp/pgsql";
78
80
const uint32_t plugin_version = 100;
79
81
 
80
 
#ifdef HAVE_PGSQL
81
 
 
82
 
#define DEFAULT_JOBCOMP_DB "slurm_jobcomp_db"
83
 
 
84
82
PGconn *jobcomp_pgsql_db = NULL;
85
83
 
86
84
char *jobcomp_table = "jobcomp_table";
133
131
        /* it turns out it is better if using defaults to let postgres
134
132
           handle them on it's own terms */
135
133
        if(!db_info->port) {
136
 
                db_info->port = 5432;
 
134
                db_info->port = DEFAULT_PGSQL_PORT;
137
135
                slurm_set_jobcomp_port(db_info->port);
138
136
        }
139
137
        db_info->host = slurm_get_jobcomp_host();
232
230
        }
233
231
        return res;
234
232
}
235
 
#endif
236
233
 
237
234
/*
238
235
 * init() is called when the plugin is loaded, before any other functions
241
238
extern int init ( void )
242
239
{
243
240
        static int first = 1;
244
 
#ifndef HAVE_PGSQL
245
 
        fatal("No Postgresql storage was found on the machine. "
246
 
              "Please check the config.log from the run of configure "
247
 
              "and run again.");        
248
 
#endif
 
241
 
249
242
        if(first) {
250
243
                /* since this can be loaded from many different places
251
244
                   only tell us once. */
260
253
 
261
254
extern int fini ( void )
262
255
{
263
 
#ifdef HAVE_PGSQL
264
256
        if (jobcomp_pgsql_db) {
265
257
                PQfinish(jobcomp_pgsql_db);
266
258
                jobcomp_pgsql_db = NULL;
267
259
        }
268
260
        return SLURM_SUCCESS;
269
 
#else
270
 
        return SLURM_ERROR;
271
 
#endif
272
261
}
273
262
 
274
263
extern int slurm_jobcomp_set_location(char *location)
275
264
{
276
 
#ifdef HAVE_PGSQL
277
265
        pgsql_db_info_t *db_info = _pgsql_jobcomp_create_db_info();
278
266
        int rc = SLURM_SUCCESS;
279
267
        char *db_name = NULL;
283
271
                return SLURM_SUCCESS;
284
272
        
285
273
        if(!location)
286
 
                db_name = DEFAULT_JOBCOMP_DB;
 
274
                db_name = DEFAULT_JOB_COMP_DB;
287
275
        else {
288
276
                while(location[i]) {
289
277
                        if(location[i] == '.' || location[i] == '/') {
290
278
                                debug("%s doesn't look like a database "
291
279
                                      "name using %s",
292
 
                                      location, DEFAULT_JOBCOMP_DB);
 
280
                                      location, DEFAULT_JOB_COMP_DB);
293
281
                                break;
294
282
                        }
295
283
                        i++;
296
284
                }
297
285
                if(location[i]) 
298
 
                        db_name = DEFAULT_JOBCOMP_DB;
 
286
                        db_name = DEFAULT_JOB_COMP_DB;
299
287
                else
300
288
                        db_name = location;
301
289
        }
313
301
        else
314
302
                debug("Jobcomp database init failed");
315
303
        return rc;
316
 
#else
317
 
        return SLURM_ERROR;
318
 
#endif
319
304
}
320
305
 
321
306
extern int slurm_jobcomp_log_record(struct job_record *job_ptr)
322
307
{
323
 
#ifdef HAVE_PGSQL
324
308
        int rc = SLURM_SUCCESS;
325
309
        char *usr_str = NULL, *grp_str = NULL, lim_str[32];
326
310
        char *connect_type = NULL, *reboot = NULL, *rotate = NULL,
363
347
                                            SELECT_PRINT_GEOMETRY);
364
348
        start = select_g_xstrdup_jobinfo(job_ptr->select_jobinfo,
365
349
                                         SELECT_PRINT_START);
 
350
#ifdef HAVE_BG
366
351
        blockid = select_g_xstrdup_jobinfo(job_ptr->select_jobinfo,
367
352
                                           SELECT_PRINT_BG_ID);
368
 
 
 
353
#else
 
354
        blockid = select_g_xstrdup_jobinfo(job_ptr->select_jobinfo,
 
355
                                           SELECT_PRINT_RESV_ID);
 
356
#endif
369
357
        query = xstrdup_printf(
370
358
                "insert into %s (jobid, uid, user_name, gid, group_name, "
371
359
                "name, state, proc_cnt, partition, timelimit, "
435
423
        xfree(usr_str);
436
424
 
437
425
        return rc;
438
 
#else
439
 
        return SLURM_ERROR;
440
 
#endif 
441
426
}
442
427
 
443
428
extern int slurm_jobcomp_get_errno()
444
429
{
445
 
#ifdef HAVE_PGSQL
446
430
        return plugin_errno;
447
 
#else
448
 
        return SLURM_ERROR;
449
 
#endif 
450
431
}
451
432
 
452
433
extern char *slurm_jobcomp_strerror(int errnum)
453
434
{
454
 
#ifdef HAVE_PGSQL
455
435
        char *res = _lookup_slurm_api_errtab(errnum);
456
436
        return (res ? res : strerror(errnum));
457
 
#else
458
 
        return NULL;
459
 
#endif 
460
437
}
461
438
 
462
439
/* 
468
445
{
469
446
        List job_list = NULL;
470
447
 
471
 
#ifdef HAVE_PGSQL
472
448
        if(!jobcomp_pgsql_db || PQstatus(jobcomp_pgsql_db) != CONNECTION_OK) {
473
449
                char *loc = slurm_get_jobcomp_loc();
474
450
                if(slurm_jobcomp_set_location(loc) == SLURM_ERROR) {
479
455
        }
480
456
 
481
457
        job_list = pgsql_jobcomp_process_get_jobs(job_cond);    
482
 
#endif 
 
458
 
483
459
        return job_list;
484
460
}
485
461
 
488
464
 */
489
465
extern int slurm_jobcomp_archive(acct_archive_cond_t *arch_cond)
490
466
{
491
 
#ifdef HAVE_PGSQL
492
467
        if(!jobcomp_pgsql_db || PQstatus(jobcomp_pgsql_db) != CONNECTION_OK) {
493
468
                char *loc = slurm_get_jobcomp_loc();
494
469
                if(slurm_jobcomp_set_location(loc) == SLURM_ERROR) {
499
474
        }
500
475
 
501
476
        return pgsql_jobcomp_process_archive(arch_cond);
502
 
#endif 
503
 
        return SLURM_ERROR;
504
477
}