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

« back to all changes in this revision

Viewing changes to source/libs/sgeobj/sge_pe_task.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 <string.h>
 
34
 
 
35
#include "sge_string.h"
 
36
#include "sgermon.h"
 
37
#include "sge_log.h"
 
38
#include "cull_list.h"
 
39
 
 
40
#include "sgeobj/sge_object.h"
 
41
#include "sgeobj/sge_answer.h"
 
42
 
 
43
#include "sgeobj/sge_job.h"
 
44
#include "sgeobj/sge_ja_task.h"
 
45
#include "sgeobj/sge_path_alias.h"
 
46
#include "sgeobj/sge_pe_task.h"
 
47
#include "sgeobj/sge_var.h"
 
48
#include "sgeobj/sge_utility.h"
 
49
#include "sgeobj/sge_usage.h"
 
50
 
 
51
#include "msg_common.h"
 
52
#include "sgeobj/msg_sgeobjlib.h"
 
53
 
 
54
/****** sgeobj/pe_task/pe_task_sum_past_usage() *******************************
 
55
*  NAME
 
56
*     pe_task_sum_past_usage() -- sum up pe tasks past usage
 
57
*
 
58
*  SYNOPSIS
 
59
*     lListElem* pe_task_sum_past_usage(lListElem *container, 
 
60
*                                       const lListElem *pe_task) 
 
61
*
 
62
*  FUNCTION
 
63
*     The pe task list of a ja task can contain one container 
 
64
*     element to hold the usage of finished pe tasks no longer 
 
65
*     stored in the task list.
 
66
*
 
67
*     This function adds the usage of pe_task to the usage of container.
 
68
*
 
69
*  INPUTS
 
70
*     lListElem *container     - container object to hold past usage
 
71
*     const lListElem *pe_task - the pe task from which to copy usage
 
72
*
 
73
*  RESULT
 
74
*     lListElem* - the container object
 
75
*
 
76
*  SEE ALSO
 
77
*     sgeobj/pe_task/pe_task_sum_past_usage_all()
 
78
*     sgeobj/pe_task/pe_task_sum_past_usage_list()
 
79
*******************************************************************************/
 
80
lListElem *
 
81
pe_task_sum_past_usage(lListElem *container, const lListElem *pe_task)
 
82
{
 
83
   lList *container_usage;
 
84
   const lList *pe_task_usage;
 
85
   lList *container_reported_usage;
 
86
   const lList *pe_task_reported_usage;
 
87
   
 
88
   DENTER(TOP_LAYER, "pe_task_sum_past_usage");
 
89
 
 
90
   /* invalid input - nothing to do */
 
91
   if (container == NULL || pe_task == NULL) {
 
92
      DRETURN(NULL);
 
93
   }
 
94
 
 
95
   if (container == pe_task) {
 
96
      /* container and pe_task are the same element - nothing to do */
 
97
      DRETURN(container);
 
98
   }
 
99
 
 
100
   /* we sum up the scaled_usage */
 
101
   container_usage = lGetOrCreateList(container, PET_scaled_usage, "reported_usage", UA_Type);
 
102
   pe_task_usage = lGetList(pe_task, PET_scaled_usage);
 
103
   if (pe_task_usage != NULL) {
 
104
      usage_list_sum(container_usage, pe_task_usage);
 
105
   }
 
106
 
 
107
   /* 
 
108
    * and we sum up the already reported usage
 
109
    * (for long running jobs having intermediate usage records) 
 
110
    */
 
111
   container_reported_usage = lGetOrCreateList(container, PET_reported_usage, "reported_usage", UA_Type);
 
112
   pe_task_reported_usage = lGetList(pe_task, PET_reported_usage);
 
113
   if (pe_task_reported_usage != NULL) {
 
114
      usage_list_sum(container_reported_usage, pe_task_reported_usage);
 
115
   }
 
116
 
 
117
   DRETURN(container);
 
118
}
 
119
 
 
120
/****** sgeobj/pe_task/pe_task_sum_past_usage_all() ***************************
 
121
*  NAME
 
122
*     pe_task_sum_past_usage_all() -- sum up all pe tasks past usage
 
123
*
 
124
*  SYNOPSIS
 
125
*     lListElem* pe_task_sum_past_usage_all(lList *pe_task_list)
 
126
*
 
127
*  FUNCTION
 
128
*     Similar to pe_task_sum_past_usage, but will sum up the usage of 
 
129
*     all pe tasks in a task list to the container object in this list.
 
130
*
 
131
*     If the container object does not yet exist, it will be created.
 
132
*
 
133
*  INPUTS
 
134
*     lList *pe_task_list - the pe task list to process
 
135
*
 
136
*  RESULT
 
137
*     lListElem* - the container object
 
138
*
 
139
*  SEE ALSO
 
140
*     sgeobj/pe_task/pe_task_sum_past_usage()
 
141
*     sgeobj/pe_task/pe_task_sum_past_usage_list()
 
142
*******************************************************************************/
 
143
lListElem *pe_task_sum_past_usage_all(lList *pe_task_list)
 
144
{
 
145
   lListElem *container = NULL;
 
146
   const lListElem *pe_task;
 
147
 
 
148
   DENTER(TOP_LAYER, "pe_task_sum_past_usage_all");
 
149
 
 
150
   /* no pe task list - nothing to do */
 
151
   if (pe_task_list == NULL) {
 
152
      DRETURN(NULL);
 
153
   }
 
154
 
 
155
   /* loop over all pe tasks and sum up usage */
 
156
   for_each(pe_task, pe_task_list) {
 
157
      if (container == NULL) {
 
158
         container = pe_task_sum_past_usage_list(pe_task_list, pe_task);
 
159
      } else {
 
160
         pe_task_sum_past_usage(container, pe_task);
 
161
      }
 
162
   }
 
163
 
 
164
   DRETURN(container);
 
165
}
 
166
 
 
167
/****** sgeobj/pe_task/pe_task_sum_past_usage_list() **************************
 
168
*  NAME
 
169
*     pe_task_sum_past_usage_list() -- sum up pe tasks past usage
 
170
*
 
171
*  SYNOPSIS
 
172
*     lListElem* 
 
173
*     pe_task_sum_past_usage_list(lList *pe_task_list, 
 
174
*                                 const lListElem *pe_task) 
 
175
*
 
176
*  FUNCTION
 
177
*     Similar to pe_task_sum_past_usage.
 
178
*     The container is retrieved from pe_task_list, if it does not 
 
179
*     yet exist it is created and inserted into pe_task_list as 
 
180
*     first element.
 
181
*
 
182
*  INPUTS
 
183
*     lList *pe_task_list      - list containing the container object
 
184
*     const lListElem *pe_task - the pe task from which to copy usage
 
185
*
 
186
*  RESULT
 
187
*     lListElem* - the container object
 
188
*
 
189
*  SEE ALSO
 
190
*     sgeobj/pe_task/pe_task_sum_past_usage()
 
191
*     sgeobj/pe_task/pe_task_sum_past_usage_all()
 
192
******************************************************************************/
 
193
lListElem *
 
194
pe_task_sum_past_usage_list(lList *pe_task_list, const lListElem *pe_task)
 
195
{
 
196
   lListElem *container;
 
197
 
 
198
   DENTER(TOP_LAYER, "pe_task_sum_past_usage_list");
 
199
 
 
200
   /* no pe task list - nothing to do */
 
201
   if (pe_task_list == NULL) {
 
202
      DRETURN(NULL);
 
203
   }
 
204
 
 
205
   /* get container - if it does not yet exist, create it as first element in pe task list */
 
206
   container = lGetElemStr(pe_task_list, PET_id, PE_TASK_PAST_USAGE_CONTAINER);
 
207
   if (container == NULL) {
 
208
      container = lCreateElem(PET_Type);
 
209
      lSetString(container, PET_id, PE_TASK_PAST_USAGE_CONTAINER);
 
210
      lInsertElem(pe_task_list, NULL, container);
 
211
   }
 
212
 
 
213
   /* sum up usage */
 
214
   pe_task_sum_past_usage(container, pe_task);
 
215
 
 
216
   DRETURN(container);
 
217
}
 
218
 
 
219
/****** sge_pe_task/pe_task_verify_request() ***********************************
 
220
*  NAME
 
221
*     pe_task_verify_request() -- verify a pe task request object
 
222
*
 
223
*  SYNOPSIS
 
224
*     bool 
 
225
*     pe_task_verify_request(const lListElem *petr, lList **answer_list) 
 
226
*
 
227
*  FUNCTION
 
228
*     Verifies structure and contents of a pe task request.
 
229
*     A pe task request is sent to sge_execd by qrsh -inherit.
 
230
*
 
231
*  INPUTS
 
232
*     const lListElem *petr - the object to verify
 
233
*     lList **answer_list   - answer list to pass back error messages
 
234
*
 
235
*  RESULT
 
236
*     bool - true on success,
 
237
*            false on error with error message in answer_list
 
238
*
 
239
*  NOTES
 
240
*     MT-NOTE: pe_task_verify_request() is MT safe 
 
241
*
 
242
*  BUGS
 
243
*     The function is far from being complete.
 
244
*     Currently, only the CULL structure is verified, not the contents.
 
245
*
 
246
*  SEE ALSO
 
247
*     sge_object/object_verify_cull()
 
248
*******************************************************************************/
 
249
bool 
 
250
pe_task_verify_request(const lListElem *petr, lList **answer_list) {
 
251
   bool ret = true;
 
252
 
 
253
   DENTER(TOP_LAYER, "pe_task_verify_request");
 
254
 
 
255
   if (petr == NULL) {
 
256
      answer_list_add_sprintf(answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
 
257
                              MSG_NULLELEMENTPASSEDTO_S, SGE_FUNC);
 
258
      ret = false;
 
259
   }
 
260
 
 
261
   if (ret) {
 
262
      if (!object_verify_cull(petr, PETR_Type)) {
 
263
         answer_list_add_sprintf(answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, 
 
264
                                 MSG_OBJECT_STRUCTURE_ERROR);
 
265
         ret = false;
 
266
      }
 
267
   }
 
268
 
 
269
   /* 
 
270
    * A pe task request entering execd must have some additional properties: 
 
271
    *    - PETR_jobid > 0
 
272
    *    - PETR_jataskid > 0
 
273
    *    - PETR_owner != NULL
 
274
    *    - verify PETR_queuename, if != NULL
 
275
    *    - verify PETR_cwd, if it is != NULL
 
276
    *    - verify PETR_path_aliases, if they are != NULL
 
277
    *    - verify PETR_environment, if it is != NULL
 
278
    *    - PETR_submission_time (currently unused)
 
279
    */
 
280
 
 
281
   if (ret) {
 
282
      ret = object_verify_ulong_not_null(petr, answer_list, PETR_jobid);
 
283
   }
 
284
 
 
285
   if (ret) {
 
286
      ret = object_verify_ulong_not_null(petr, answer_list, PETR_jataskid);
 
287
   }
 
288
 
 
289
   if (ret) {
 
290
      ret = object_verify_string_not_null(petr, answer_list, PETR_owner);
 
291
   }
 
292
 
 
293
   if (ret) {
 
294
      const char *queue_name = lGetString(petr, PETR_queuename);
 
295
 
 
296
      if (queue_name != NULL) {
 
297
         if (verify_str_key(
 
298
               answer_list, queue_name, MAX_VERIFY_STRING,
 
299
               lNm2Str(PETR_queuename), KEY_TABLE) != STATUS_OK) {
 
300
            ret = false;
 
301
         }
 
302
      }
 
303
   }
 
304
 
 
305
   if (ret) {
 
306
      const char *cwd = lGetString(petr, PETR_cwd);
 
307
 
 
308
      if (cwd != NULL) {
 
309
         ret = path_verify(cwd, answer_list, "cwd", true);
 
310
      }
 
311
   }
 
312
 
 
313
   if (ret) {
 
314
      const lList *path_aliases = lGetList(petr, PETR_path_aliases);
 
315
 
 
316
      if (path_aliases != NULL) {
 
317
         ret = path_alias_verify(path_aliases, answer_list);
 
318
      }
 
319
   } 
 
320
 
 
321
   if (ret) {
 
322
      const lList *env_list = lGetList(petr, PETR_environment);
 
323
 
 
324
      if (env_list != NULL) {
 
325
         ret = var_list_verify(env_list, answer_list);
 
326
      }
 
327
   } 
 
328
 
 
329
   DRETURN(ret);
 
330
}