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

« back to all changes in this revision

Viewing changes to src/api/reservation_info.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:
 
1
/*****************************************************************************\
 
2
 *  reseration_info.c - get/print the reservation state information of slurm
 
3
 *****************************************************************************
 
4
 *  Copyright (C) 2009 Lawrence Livermore National Security.
 
5
 *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
 
6
 *  Written by Morris Jette <jette1@llnl.gov> et. al.
 
7
 *  CODE-OCEC-09-009. All rights reserved.
 
8
 *   
 
9
 *  This file is part of SLURM, a resource management program.
 
10
 *  For details, see <https://computing.llnl.gov/linux/slurm/>.
 
11
 *  Please also read the included file: DISCLAIMER.
 
12
 *  
 
13
 *  SLURM is free software; you can redistribute it and/or modify it under
 
14
 *  the terms of the GNU General Public License as published by the Free
 
15
 *  Software Foundation; either version 2 of the License, or (at your option)
 
16
 *  any later version.
 
17
 *
 
18
 *  In addition, as a special exception, the copyright holders give permission 
 
19
 *  to link the code of portions of this program with the OpenSSL library under 
 
20
 *  certain conditions as described in each individual source file, and 
 
21
 *  distribute linked combinations including the two. You must obey the GNU 
 
22
 *  General Public License in all respects for all of the code used other than 
 
23
 *  OpenSSL. If you modify file(s) with this exception, you may extend this 
 
24
 *  exception to your version of the file(s), but you are not obligated to do 
 
25
 *  so. If you do not wish to do so, delete this exception statement from your
 
26
 *  version.  If you delete this exception statement from all source files in 
 
27
 *  the program, then also delete it here.
 
28
 *  
 
29
 *  SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
 
30
 *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
31
 *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
32
 *  details.
 
33
 *  
 
34
 *  You should have received a copy of the GNU General Public License along
 
35
 *  with SLURM; if not, write to the Free Software Foundation, Inc.,
 
36
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
 
37
\*****************************************************************************/
 
38
 
 
39
#ifdef HAVE_CONFIG_H
 
40
#  include "config.h"
 
41
#endif
 
42
 
 
43
#include <errno.h>
 
44
#include <stdio.h>
 
45
#include <stdlib.h>
 
46
 
 
47
#include <slurm/slurm.h>
 
48
 
 
49
#include "src/api/job_info.h"
 
50
#include "src/common/parse_time.h"
 
51
#include "src/common/slurm_protocol_api.h"
 
52
#include "src/common/xmalloc.h"
 
53
#include "src/common/xstring.h"
 
54
 
 
55
/*
 
56
 * slurm_print_reservation_info_msg - output information about all Slurm 
 
57
 *      reservations based upon message as loaded using slurm_load_reservation
 
58
 * IN out - file to write to
 
59
 * IN resv_info_ptr - reservation information message pointer
 
60
 * IN one_liner - print as a single line if true
 
61
 */
 
62
void slurm_print_reservation_info_msg ( FILE* out, 
 
63
                reserve_info_msg_t * resv_info_ptr, int one_liner )
 
64
{
 
65
        int i ;
 
66
        reserve_info_t * resv_ptr = resv_info_ptr->reservation_array ;
 
67
        char time_str[32];
 
68
 
 
69
        slurm_make_time_str( (time_t *)&resv_info_ptr->last_update, time_str, 
 
70
                             sizeof(time_str));
 
71
        fprintf( out, "Reservation data as of %s, record count %d\n",
 
72
                time_str, resv_info_ptr->record_count);
 
73
 
 
74
        for (i = 0; i < resv_info_ptr->record_count; i++) {
 
75
                slurm_print_reservation_info ( out, & resv_ptr[i], one_liner );
 
76
        }
 
77
 
 
78
}
 
79
 
 
80
/*
 
81
 * slurm_print_reservation_info - output information about a specific Slurm 
 
82
 *      reservation based upon message as loaded using slurm_load_reservation
 
83
 * IN out - file to write to
 
84
 * IN resv_ptr - an individual reservation information record pointer
 
85
 * IN one_liner - print as a single line if true
 
86
 */
 
87
void slurm_print_reservation_info ( FILE* out, reserve_info_t * resv_ptr, 
 
88
                                    int one_liner )
 
89
{
 
90
        char *print_this = slurm_sprint_reservation_info(resv_ptr, one_liner);
 
91
        fprintf ( out, "%s", print_this);
 
92
        xfree(print_this);
 
93
}
 
94
 
 
95
 
 
96
/*
 
97
 * slurm_sprint_reservation_info - output information about a specific Slurm 
 
98
 *      reservation based upon message as loaded using slurm_load_reservations
 
99
 * IN resv_ptr - an individual reservation information record pointer
 
100
 * IN one_liner - print as a single line if true
 
101
 * RET out - char * containing formatted output (must be freed after call)
 
102
 *           NULL is returned on failure.
 
103
 */
 
104
char *slurm_sprint_reservation_info ( reserve_info_t * resv_ptr, 
 
105
                                      int one_liner )
 
106
{
 
107
        char tmp1[32], tmp2[32], *flag_str = NULL;
 
108
        char tmp_line[MAXHOSTRANGELEN];
 
109
        char *out = NULL;
 
110
 
 
111
        /****** Line 1 ******/
 
112
        slurm_make_time_str(&resv_ptr->start_time, tmp1, sizeof(tmp1));
 
113
        slurm_make_time_str(&resv_ptr->end_time,   tmp2, sizeof(tmp2));
 
114
        snprintf(tmp_line, sizeof(tmp_line),
 
115
                 "ReservationName=%s StartTime=%s EndTime=%s Duration=%u",
 
116
                 resv_ptr->name, tmp1, tmp2, 
 
117
                 (uint32_t) (difftime(resv_ptr->end_time, 
 
118
                                      resv_ptr->start_time) / 60));
 
119
        xstrcat(out, tmp_line);
 
120
 
 
121
        if (one_liner)
 
122
                xstrcat(out, " ");
 
123
        else
 
124
                xstrcat(out, "\n   ");
 
125
        
 
126
        /****** Line 2 ******/
 
127
        flag_str = reservation_flags_string(resv_ptr->flags);
 
128
 
 
129
        snprintf(tmp_line, sizeof(tmp_line), 
 
130
                 "Nodes=%s NodeCnt=%u Features=%s PartitionName=%s Flags=%s",
 
131
                 resv_ptr->node_list, resv_ptr->node_cnt,
 
132
                 resv_ptr->features,  resv_ptr->partition, flag_str);
 
133
        xfree(flag_str);
 
134
        xstrcat(out, tmp_line);
 
135
        if (one_liner)
 
136
                xstrcat(out, " ");
 
137
        else
 
138
                xstrcat(out, "\n   ");
 
139
        
 
140
        /****** Line 3 ******/
 
141
        snprintf(tmp_line, sizeof(tmp_line), 
 
142
                 "Users=%s Accounts=%s", 
 
143
                 resv_ptr->users, resv_ptr->accounts);
 
144
        xstrcat(out, tmp_line);
 
145
        if (one_liner)
 
146
                xstrcat(out, "\n");
 
147
        else
 
148
                xstrcat(out, "\n\n");
 
149
        
 
150
        return out;
 
151
}
 
152
 
 
153
 
 
154
 
 
155
/*
 
156
 * slurm_load_reservations - issue RPC to get all slurm reservation 
 
157
 *      configuration information if changed since update_time 
 
158
 * IN update_time - time of current configuration data
 
159
 * IN reserve_info_msg_pptr - place to store a reservation configuration 
 
160
 *      pointer
 
161
 * RET 0 or a slurm error code
 
162
 * NOTE: free the response using slurm_free_reservation_info_msg
 
163
 */
 
164
extern int slurm_load_reservations (time_t update_time, 
 
165
                reserve_info_msg_t **resp)
 
166
{
 
167
        int rc;
 
168
        slurm_msg_t req_msg;
 
169
        slurm_msg_t resp_msg;
 
170
        resv_info_request_msg_t req;
 
171
 
 
172
        slurm_msg_t_init(&req_msg);
 
173
        slurm_msg_t_init(&resp_msg);
 
174
 
 
175
        req.last_update  = update_time;
 
176
        req_msg.msg_type = REQUEST_RESERVATION_INFO;
 
177
        req_msg.data     = &req;
 
178
        
 
179
        if (slurm_send_recv_controller_msg(&req_msg, &resp_msg) < 0)
 
180
                return SLURM_ERROR;
 
181
        
 
182
        switch (resp_msg.msg_type) {
 
183
        case RESPONSE_RESERVATION_INFO:
 
184
                *resp = (reserve_info_msg_t *) resp_msg.data;
 
185
                break;
 
186
        case RESPONSE_SLURM_RC:
 
187
                rc = ((return_code_msg_t *) resp_msg.data)->return_code;
 
188
                slurm_free_return_code_msg(resp_msg.data);      
 
189
                if (rc) 
 
190
                        slurm_seterrno_ret(rc);
 
191
                *resp = NULL;
 
192
                break;
 
193
        default:
 
194
                slurm_seterrno_ret(SLURM_UNEXPECTED_MSG_ERROR);
 
195
                break;
 
196
        }
 
197
 
 
198
        return SLURM_PROTOCOL_SUCCESS;
 
199
}