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

« back to all changes in this revision

Viewing changes to source/clients/common/sge_cqueue_qstat.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
 
 
32
#include <string.h>
 
33
 
 
34
#include "sge.h"
 
35
#include "sgermon.h"
 
36
#include "sge_hostL.h"
 
37
#include "sge_peL.h"
 
38
#include "sge_qrefL.h"
 
39
#include "sge_strL.h"
 
40
#include "sge_userprjL.h"
 
41
#include "sge_userprj.h"
 
42
#include "sge_cqueueL.h"
 
43
#include "sge_qinstance.h"
 
44
#include "sge_qinstance_state.h"
 
45
#include "sge_qinstance_type.h"
 
46
#include "sge_select_queue.h"
 
47
#include "sge_cqueue_qstat.h"
 
48
#include "qstat_printing.h"
 
49
#include "sge_pe.h"
 
50
#include "sge_host.h"
 
51
#include "sge_conf.h"
 
52
#include "sge_qref.h"
 
53
#include "sge_centry.h"
 
54
#include "valid_queue_user.h"
 
55
#include "sge_cqueue.h"
 
56
#include "sge_complex_schedd.h"
 
57
#include "sge_schedd_conf.h"
 
58
#include "sge_parse_num_par.h"
 
59
#include "sched/sge_resource_utilization.h"
 
60
#include "uti/sge_time.h"
 
61
 
 
62
#include "msg_clients_common.h"
 
63
 
 
64
 
 
65
bool cqueue_calculate_summary(const lListElem *cqueue, 
 
66
                                     const lList *exechost_list,
 
67
                                     const lList *centry_list,
 
68
                                     double *load, 
 
69
                                     bool *is_load_available, 
 
70
                                     u_long32 *used,
 
71
                                     u_long32 *resv,
 
72
                                     u_long32 *total,
 
73
                                     u_long32 *suspend_manual, 
 
74
                                     u_long32 *suspend_threshold,
 
75
                                     u_long32 *suspend_on_subordinate,
 
76
                                     u_long32 *suspend_calendar,
 
77
                                     u_long32 *unknown,
 
78
                                     u_long32 *load_alarm, 
 
79
                                     u_long32 *disabled_manual,
 
80
                                     u_long32 *disabled_calendar,
 
81
                                     u_long32 *ambiguous,
 
82
                                     u_long32 *orphaned,
 
83
                                     u_long32 *error,
 
84
                                     u_long32 *available,
 
85
                                     u_long32 *temp_disabled,
 
86
                                     u_long32 *manual_intervention)
 
87
 
 
88
{
 
89
   bool ret = true;
 
90
   
 
91
   DENTER(TOP_LAYER, "cqueue_calculate_summary");
 
92
   if (cqueue != NULL) {
 
93
      lList *qinstance_list = lGetList(cqueue, CQ_qinstances);
 
94
      lListElem *qinstance = NULL;
 
95
      double host_load_avg = 0.0;
 
96
      u_long32 load_slots = 0;
 
97
      u_long32 used_available = 0;
 
98
      u_long32 used_slots = 0;
 
99
      u_long32 resv_slots = 0;
 
100
 
 
101
      *load = 0.0;
 
102
      *is_load_available = false;
 
103
      *used = *total = *resv = 0;
 
104
      *available = *temp_disabled = *manual_intervention = 0;
 
105
      *suspend_manual = *suspend_threshold = *suspend_on_subordinate = 0;
 
106
      *suspend_calendar = *unknown = *load_alarm = 0;
 
107
      *disabled_manual = *disabled_calendar = *ambiguous = 0;
 
108
      *orphaned = *error = 0; 
 
109
      for_each(qinstance, qinstance_list) {
 
110
         u_long32 slots = lGetUlong(qinstance, QU_job_slots);
 
111
         bool has_value_from_object;
 
112
 
 
113
         used_slots = qinstance_slots_used(qinstance);
 
114
         resv_slots = qinstance_slots_reserved_now(qinstance);
 
115
         (*used) += used_slots;
 
116
         (*resv) += resv_slots;
 
117
         (*total) += slots;
 
118
 
 
119
         if (!sge_get_double_qattr(&host_load_avg, LOAD_ATTR_NP_LOAD_AVG, 
 
120
                                   qinstance, exechost_list, centry_list, 
 
121
                                   &has_value_from_object)) {
 
122
            if (has_value_from_object) {
 
123
               *is_load_available = true;
 
124
               load_slots += slots;
 
125
               *load += host_load_avg * slots;
 
126
            } 
 
127
         } 
 
128
 
 
129
         /*
 
130
          * manual_intervention: cdsuE
 
131
          * temp_disabled: aoACDS
 
132
          */
 
133
         if (qinstance_state_is_manual_suspended(qinstance) ||
 
134
             qinstance_state_is_unknown(qinstance) ||
 
135
             qinstance_state_is_manual_disabled(qinstance) ||
 
136
             qinstance_state_is_ambiguous(qinstance) ||
 
137
             qinstance_state_is_error(qinstance)) {
 
138
            *manual_intervention += slots;
 
139
         } else if (qinstance_state_is_alarm(qinstance) ||
 
140
                    qinstance_state_is_cal_disabled(qinstance) ||
 
141
                    qinstance_state_is_orphaned(qinstance) ||
 
142
                    qinstance_state_is_susp_on_sub(qinstance) ||
 
143
                    qinstance_state_is_cal_suspended(qinstance) ||
 
144
                    qinstance_state_is_suspend_alarm(qinstance)) {
 
145
            *temp_disabled += slots;
 
146
         } else {
 
147
            *available += slots;
 
148
            used_available += used_slots;
 
149
         }
 
150
         if (qinstance_state_is_unknown(qinstance)) {
 
151
            *unknown += slots;
 
152
         }
 
153
         if (qinstance_state_is_alarm(qinstance)) {
 
154
            *load_alarm += slots;
 
155
         }
 
156
         if (qinstance_state_is_manual_disabled(qinstance)) {
 
157
            *disabled_manual += slots;
 
158
         }
 
159
         if (qinstance_state_is_cal_disabled(qinstance)) {
 
160
            *disabled_calendar += slots;
 
161
         }
 
162
         if (qinstance_state_is_ambiguous(qinstance)) {
 
163
            *ambiguous += slots;
 
164
         }
 
165
         if (qinstance_state_is_orphaned(qinstance)) {
 
166
            *orphaned += slots;
 
167
         }
 
168
         if (qinstance_state_is_manual_suspended(qinstance)) {
 
169
            *suspend_manual += slots;
 
170
         }
 
171
         if (qinstance_state_is_susp_on_sub(qinstance)) {
 
172
            *suspend_on_subordinate += slots;
 
173
         }
 
174
         if (qinstance_state_is_cal_suspended(qinstance)) {
 
175
            *suspend_calendar += slots;
 
176
         }
 
177
         if (qinstance_state_is_suspend_alarm(qinstance)) {
 
178
            *suspend_threshold += slots;
 
179
         }
 
180
         if (qinstance_state_is_error(qinstance)) {
 
181
            *error += slots;
 
182
         }
 
183
      }  
 
184
      *load /= load_slots;
 
185
      *available -= used_available;
 
186
   }
 
187
   DEXIT;
 
188
   return ret;
 
189
}
 
190
 
 
191
int 
 
192
select_by_qref_list(lList *cqueue_list, const lList *hgrp_list, const lList *qref_list)
 
193
{
 
194
   int ret = 0;
 
195
   lList *queueref_list = NULL;
 
196
 
 
197
   DENTER(TOP_LAYER, "select_by_qref_list");
 
198
 
 
199
   /* 
 
200
    * Resolve queue pattern
 
201
    */
 
202
   {
 
203
      lList *tmp_list = NULL;
 
204
      bool found_something = true;
 
205
      queueref_list = lCopyList("", qref_list);
 
206
 
 
207
      qref_list_resolve(queueref_list, NULL, &tmp_list, 
 
208
                        &found_something, cqueue_list, hgrp_list, true, true);
 
209
      if (!found_something) {
 
210
         lFreeList(&queueref_list);
 
211
         DEXIT;
 
212
         return -1;
 
213
      }
 
214
      lFreeList(&queueref_list);
 
215
      queueref_list = tmp_list;
 
216
      tmp_list = NULL;
 
217
   }
 
218
 
 
219
   
 
220
   if (cqueue_list != NULL && queueref_list != NULL) {
 
221
      lListElem *cqueue = NULL;
 
222
      lListElem *qref = NULL;
 
223
 
 
224
      for_each(qref, queueref_list) {
 
225
         dstring cqueue_buffer = DSTRING_INIT;
 
226
         dstring hostname_buffer = DSTRING_INIT;
 
227
         const char *full_name = NULL;
 
228
         const char *cqueue_name = NULL;
 
229
         const char *hostname = NULL;
 
230
         bool has_hostname = false;
 
231
         bool has_domain = false;
 
232
         lListElem *cqueue = NULL;
 
233
         lListElem *qinstance = NULL;
 
234
         lList *qinstance_list = NULL;
 
235
         u_long32 tag = 0;
 
236
 
 
237
         full_name = lGetString(qref, QR_name); 
 
238
         cqueue_name_split(full_name, &cqueue_buffer, &hostname_buffer,
 
239
                           &has_hostname, &has_domain);
 
240
         cqueue_name = sge_dstring_get_string(&cqueue_buffer);
 
241
         hostname = sge_dstring_get_string(&hostname_buffer);
 
242
         cqueue = lGetElemStr(cqueue_list, CQ_name, cqueue_name);
 
243
         qinstance_list = lGetList(cqueue, CQ_qinstances);
 
244
         qinstance = lGetElemHost(qinstance_list, QU_qhostname, hostname);
 
245
 
 
246
         tag = lGetUlong(qinstance, QU_tag);
 
247
         lSetUlong(qinstance, QU_tag, tag | TAG_SELECT_IT);
 
248
 
 
249
         sge_dstring_free(&cqueue_buffer);
 
250
         sge_dstring_free(&hostname_buffer);
 
251
      } 
 
252
 
 
253
      for_each(cqueue, cqueue_list) {
 
254
         lListElem *qinstance = NULL;
 
255
         lList *qinstance_list = NULL;
 
256
 
 
257
         qinstance_list = lGetList(cqueue, CQ_qinstances);
 
258
         for_each(qinstance, qinstance_list) {
 
259
            u_long32 tag = lGetUlong(qinstance, QU_tag);
 
260
            bool selected = ((tag & TAG_SELECT_IT) != 0) ? true : false;
 
261
 
 
262
            if (!selected) {
 
263
               tag &= ~(TAG_SELECT_IT | TAG_SHOW_IT);
 
264
               lSetUlong(qinstance, QU_tag, tag);
 
265
            } else {
 
266
               ret++;
 
267
            }
 
268
         }
 
269
      } 
 
270
   }
 
271
 
 
272
   lFreeList(&queueref_list);
 
273
 
 
274
   DEXIT;
 
275
   return ret;
 
276
}
 
277
 
 
278
/* 
 
279
   untag all queues not selected by a -pe
 
280
 
 
281
   returns 
 
282
      0 ok
 
283
      -1 error 
 
284
 
 
285
*/
 
286
int select_by_pe_list(
 
287
lList *queue_list,
 
288
lList *peref_list,   /* ST_Type */
 
289
lList *pe_list 
 
290
) {
 
291
   int nqueues = 0;
 
292
   lList *pe_selected = NULL;
 
293
   lListElem *pe, *qep, *cqueue;
 
294
 
 
295
   DENTER(TOP_LAYER, "select_by_pe_list");
 
296
 
 
297
  /*
 
298
   * iterate through peref_list and build up a new pe_list
 
299
   * containing only those pe's referenced in peref_list
 
300
   */
 
301
   for_each(pe, peref_list) {
 
302
      lListElem *ref_pe;   /* PE_Type */
 
303
      lListElem *copy_pe;  /* PE_Type */
 
304
 
 
305
      ref_pe = pe_list_locate(pe_list, lGetString(pe, ST_name));
 
306
      copy_pe = lCopyElem(ref_pe);
 
307
      if (pe_selected == NULL) {
 
308
         const lDescr *descriptor = lGetElemDescr(ref_pe);
 
309
 
 
310
         pe_selected = lCreateList("", descriptor);
 
311
      }
 
312
      lAppendElem(pe_selected, copy_pe);
 
313
   }
 
314
   if (lGetNumberOfElem(pe_selected)==0) {
 
315
      fprintf(stderr, "%s\n", MSG_PE_NOSUCHPARALLELENVIRONMENT);
 
316
      return -1;
 
317
   }
 
318
 
 
319
   /* 
 
320
    * untag all non-parallel queues and queues not referenced 
 
321
    * by a pe in the selected pe list entry of a queue 
 
322
    */
 
323
   for_each(cqueue, queue_list) {
 
324
      lList *qinstance_list = lGetList(cqueue, CQ_qinstances);
 
325
 
 
326
      for_each(qep, qinstance_list) { 
 
327
         lListElem* found = NULL;
 
328
 
 
329
         if (!qinstance_is_parallel_queue(qep)) {
 
330
            lSetUlong(qep, QU_tag, 0);
 
331
            continue;
 
332
         }
 
333
         for_each (pe, pe_selected) {
 
334
            const char *pe_name = lGetString(pe, PE_name);
 
335
 
 
336
            found = lGetSubStr(qep, ST_name, pe_name, QU_pe_list);
 
337
            if (found != NULL) {
 
338
               break;
 
339
            }
 
340
         }
 
341
         if (found == NULL) {
 
342
            lSetUlong(qep, QU_tag, 0);
 
343
         } else {
 
344
            nqueues++;
 
345
         }
 
346
      }
 
347
   }
 
348
 
 
349
   if (pe_selected != NULL) {
 
350
      lFreeList(&pe_selected);
 
351
   }
 
352
   DEXIT;
 
353
   return nqueues;
 
354
}
 
355
 
 
356
/* 
 
357
   untag all queues not selected by a -pe
 
358
 
 
359
   returns 
 
360
      0 ok
 
361
      -1 error 
 
362
 
 
363
*/
 
364
int select_by_queue_user_list(
 
365
lList *exechost_list,
 
366
lList *cqueue_list,
 
367
lList *queue_user_list,
 
368
lList *acl_list, 
 
369
lList *project_list
 
370
) {
 
371
   int nqueues = 0;
 
372
   lListElem *qu = NULL;
 
373
   lListElem *qep = NULL;
 
374
   lListElem *cqueue = NULL;
 
375
   lListElem *ehep = NULL;
 
376
   lList *h_acl = NULL;
 
377
   lList *h_xacl = NULL;
 
378
   lList *global_acl = NULL;
 
379
   lList *global_xacl = NULL;
 
380
   lList *config_acl = NULL;
 
381
   lList *config_xacl = NULL;
 
382
   lList *prj = NULL;
 
383
   lList *xprj = NULL;
 
384
   lList *h_prj = NULL;
 
385
   lList *h_xprj = NULL;
 
386
   lList *global_prj = NULL;
 
387
   lList *global_xprj = NULL;
 
388
 
 
389
   DENTER(TOP_LAYER, "select_by_queue_user_list");
 
390
 
 
391
   /* untag all queues where no of the users has access */
 
392
 
 
393
   ehep = host_list_locate(exechost_list, "global"); 
 
394
   global_acl  = lGetList(ehep, EH_acl);
 
395
   global_xacl = lGetList(ehep, EH_xacl);
 
396
   global_prj = lGetList(ehep, EH_prj);
 
397
   global_xprj = lGetList(ehep, EH_xprj);
 
398
 
 
399
   config_acl  = mconf_get_user_lists();
 
400
   config_xacl = mconf_get_xuser_lists();
 
401
 
 
402
   for_each(cqueue, cqueue_list) {
 
403
      lList *qinstance_list = lGetList(cqueue, CQ_qinstances);
 
404
 
 
405
      for_each(qep, qinstance_list) {
 
406
         int access = 0;
 
407
         const char *host_name = NULL;
 
408
 
 
409
         prj = lGetList(qep, QU_projects);
 
410
         xprj = lGetList(qep, QU_xprojects);
 
411
 
 
412
         /* get exec host list element for current queue 
 
413
            and its access lists */
 
414
         host_name = lGetHost(qep, QU_qhostname);
 
415
         ehep = host_list_locate(exechost_list, host_name);
 
416
         if (ehep != NULL) {
 
417
            h_acl  = lGetList(ehep, EH_acl);
 
418
            h_xacl = lGetList(ehep, EH_xacl);
 
419
            h_prj = lGetList(ehep, EH_prj);
 
420
            h_xprj = lGetList(ehep, EH_xprj);
 
421
         }
 
422
 
 
423
         for_each (qu, queue_user_list) {
 
424
            lListElem *pep = NULL;
 
425
            int q_access = 0;
 
426
            int h_access = 0;
 
427
            int gh_access = 0;
 
428
            int conf_access = 0;
 
429
 
 
430
            const char *name = lGetString(qu, ST_name);
 
431
            if (name == NULL)
 
432
               continue;
 
433
 
 
434
            DPRINTF(("-----> checking queue user: %s\n", name )); 
 
435
 
 
436
            DPRINTF(("testing queue access lists\n"));
 
437
            q_access = (name[0]=='@')?
 
438
                  sge_has_access(NULL, &name[1], qep, acl_list): 
 
439
                  sge_has_access(name, NULL, qep, acl_list); 
 
440
            if (!q_access) {
 
441
               DPRINTF(("no access\n"));
 
442
            } else {
 
443
               DPRINTF(("ok\n"));
 
444
            }
 
445
            if (project_list != NULL) {
 
446
                DPRINTF(("testing queue projects lists\n"));
 
447
                for_each(pep, prj) {
 
448
                   const char *prj_name;
 
449
                   lListElem *prj;
 
450
                   if ((prj_name = lGetString(pep, PR_name))!=NULL) {
 
451
                      if ((prj = prj_list_locate(project_list, prj_name)) != NULL) {
 
452
                         q_access &= (name[0]=='@')?
 
453
                            sge_has_access_(NULL, &name[1], lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list): 
 
454
                            sge_has_access_(name, NULL, lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list); 
 
455
                      } else {
 
456
                        DPRINTF(("no reference object for project %s\n", prj_name));
 
457
                      }   
 
458
                    } 
 
459
                }
 
460
                for_each(pep, xprj) {
 
461
                   const char *prj_name;
 
462
                   lListElem *prj;
 
463
                   if ((prj_name = lGetString(pep, PR_name))!=NULL) {
 
464
                      if ((prj = prj_list_locate(project_list, prj_name)) != NULL) {
 
465
                         q_access &= (name[0]=='@')?
 
466
                            !sge_has_access_(NULL, &name[1], lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list): 
 
467
                            !sge_has_access_(name, NULL, lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list); 
 
468
                      } else {
 
469
                        DPRINTF(("no reference object for project %s\n", prj_name));
 
470
                      }   
 
471
                    }
 
472
                }
 
473
                if (!q_access) {
 
474
                   DPRINTF(("no access\n"));
 
475
                } else {
 
476
                   DPRINTF(("ok\n"));
 
477
                }
 
478
            }
 
479
 
 
480
            DPRINTF(("testing host access lists\n"));
 
481
            h_access = (name[0]=='@')?
 
482
                  sge_has_access_(NULL, &name[1], h_acl, h_xacl , acl_list):
 
483
                  sge_has_access_(name, NULL, h_acl, h_xacl , acl_list); 
 
484
            if (!h_access) {
 
485
               DPRINTF(("no access\n"));
 
486
            }else {
 
487
               DPRINTF(("ok\n"));
 
488
            }
 
489
            if (project_list != NULL) {
 
490
                DPRINTF(("testing host projects lists\n"));
 
491
                for_each(pep, h_prj) {
 
492
                   const char *prj_name;
 
493
                   lListElem *prj;
 
494
                   if ((prj_name = lGetString(pep, PR_name))!=NULL) {
 
495
                      if ((prj = prj_list_locate(project_list, prj_name)) != NULL) {
 
496
                         q_access &= (name[0]=='@')?
 
497
                            sge_has_access_(NULL, &name[1], lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list): 
 
498
                            sge_has_access_(name, NULL, lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list); 
 
499
                      } else {
 
500
                        DPRINTF(("no reference object for project %s\n", prj_name));
 
501
                      }   
 
502
                    }
 
503
                }
 
504
                for_each(pep, h_xprj) {
 
505
                   const char *prj_name;
 
506
                   lListElem *prj;
 
507
                   if ((prj_name = lGetString(pep, PR_name))!=NULL) {
 
508
                      if ((prj = prj_list_locate(project_list, prj_name)) != NULL) {
 
509
                         q_access &= (name[0]=='@')?
 
510
                            !sge_has_access_(NULL, &name[1], lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list): 
 
511
                            !sge_has_access_(name, NULL, lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list); 
 
512
                      } else {
 
513
                        DPRINTF(("no reference object for project %s\n", prj_name));
 
514
                      }   
 
515
                    }
 
516
                }
 
517
                if (!q_access) {
 
518
                   DPRINTF(("no access\n"));
 
519
                } else {
 
520
                   DPRINTF(("ok\n"));
 
521
                }
 
522
            }
 
523
 
 
524
            DPRINTF(("testing global host access lists\n"));
 
525
            gh_access = (name[0]=='@')?
 
526
                  sge_has_access_(NULL, &name[1], global_acl , global_xacl , acl_list):
 
527
                  sge_has_access_(name, NULL,global_acl , global_xacl , acl_list);
 
528
            if (!gh_access) {
 
529
               DPRINTF(("no access\n"));
 
530
            }else {
 
531
               DPRINTF(("ok\n"));
 
532
            }
 
533
            if (project_list != NULL) {
 
534
                DPRINTF(("testing host projects lists\n"));
 
535
                for_each(pep, global_prj) {
 
536
                   const char *prj_name;
 
537
                   lListElem *prj;
 
538
                   if ((prj_name = lGetString(pep, PR_name))!=NULL) {
 
539
                      if ((prj = prj_list_locate(project_list, prj_name)) != NULL) {
 
540
                         q_access &= (name[0]=='@')?
 
541
                            sge_has_access_(NULL, &name[1], lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list): 
 
542
                            sge_has_access_(name, NULL, lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list); 
 
543
                      } else {
 
544
                        DPRINTF(("no reference object for project %s\n", prj_name));
 
545
                      }   
 
546
                    }
 
547
                }
 
548
                for_each(pep, global_xprj) {
 
549
                   const char *prj_name;
 
550
                   lListElem *prj;
 
551
                   if ((prj_name = lGetString(pep, PR_name))!=NULL) {
 
552
                      if ((prj = prj_list_locate(project_list, prj_name)) != NULL) {
 
553
                         q_access &= (name[0]=='@')?
 
554
                            !sge_has_access_(NULL, &name[1], lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list): 
 
555
                            !sge_has_access_(name, NULL, lGetList(prj, PR_acl), lGetList(prj, PR_xacl), acl_list); 
 
556
                      } else {
 
557
                        DPRINTF(("no reference object for project %s\n", prj_name));
 
558
                      }   
 
559
                    }
 
560
                }
 
561
                if (!q_access) {
 
562
                   DPRINTF(("no access\n"));
 
563
                } else {
 
564
                   DPRINTF(("ok\n"));
 
565
                }
 
566
            }
 
567
 
 
568
            DPRINTF(("testing cluster config access lists\n"));
 
569
            conf_access = (name[0]=='@')?
 
570
                  sge_has_access_(NULL, &name[1],config_acl , config_xacl , acl_list): 
 
571
                  sge_has_access_(name, NULL, config_acl , config_xacl  , acl_list); 
 
572
            if (!conf_access) {
 
573
               DPRINTF(("no access\n"));
 
574
            }else {
 
575
               DPRINTF(("ok\n"));
 
576
            }
 
577
 
 
578
            access = q_access && h_access && gh_access && conf_access;
 
579
            if (!access) {
 
580
               break;
 
581
            }
 
582
         }
 
583
         if (!access) {
 
584
            DPRINTF(("no access for queue %s\n", lGetString(qep,QU_qname) ));
 
585
            lSetUlong(qep, QU_tag, 0);
 
586
         }
 
587
         else {
 
588
            DPRINTF(("access for queue %s\n", lGetString(qep,QU_qname) ));
 
589
            nqueues++;
 
590
         }
 
591
      }
 
592
   }
 
593
 
 
594
   lFreeList(&config_acl);
 
595
   lFreeList(&config_xacl);
 
596
   DEXIT;
 
597
   return nqueues;
 
598
}
 
599
 
 
600
/* 
 
601
   untag all queues not in a specific state 
 
602
 
 
603
   returns 
 
604
      0 ok
 
605
      -1 error 
 
606
 
 
607
*/
 
608
int select_by_queue_state(
 
609
u_long32 queue_states,
 
610
lList *exechost_list,
 
611
lList *queue_list,
 
612
lList *centry_list 
 
613
) {
 
614
   bool has_value_from_object; 
 
615
   double load_avg;
 
616
   char *load_avg_str;
 
617
   lListElem *cqueue = NULL;
 
618
   u_long32 interval;
 
619
 
 
620
   DENTER(TOP_LAYER, "select_by_queue_state");
 
621
 
 
622
   /* only show queues in the requested state */
 
623
   /* make it possible to display any load value in qstat output */
 
624
   if (!(load_avg_str=getenv("SGE_LOAD_AVG")) || !strlen(load_avg_str))
 
625
      load_avg_str = LOAD_ATTR_LOAD_AVG;
 
626
 
 
627
   for_each(cqueue, queue_list){
 
628
      lList *qinstance_list = lGetList(cqueue, CQ_qinstances);
 
629
      lListElem *qep = NULL;
 
630
      for_each(qep, qinstance_list) { 
 
631
 
 
632
         /* compute the load and suspend alarm */
 
633
         sge_get_double_qattr(&load_avg, load_avg_str, qep, exechost_list, centry_list, &has_value_from_object);
 
634
         if (sge_load_alarm(NULL, qep, lGetList(qep, QU_load_thresholds), exechost_list, centry_list, NULL, true)) {
 
635
            qinstance_state_set_alarm(qep, true);
 
636
         }
 
637
         parse_ulong_val(NULL, &interval, TYPE_TIM,
 
638
                         lGetString(qep, QU_suspend_interval), NULL, 0);
 
639
         if (lGetUlong(qep, QU_nsuspend) != 0 &&
 
640
             interval != 0 &&
 
641
             sge_load_alarm(NULL, qep, lGetList(qep, QU_suspend_thresholds), exechost_list, centry_list, NULL, false)) {
 
642
            qinstance_state_set_suspend_alarm(qep, true);
 
643
         }
 
644
 
 
645
      
 
646
         if (!qinstance_has_state(qep, queue_states)) {
 
647
            lSetUlong(qep, QU_tag, 0);
 
648
         }   
 
649
      }
 
650
   }
 
651
   DEXIT;
 
652
   return 0;
 
653
}   
 
654
 
 
655
/* 
 
656
   untag all queues not covered by -l  
 
657
 
 
658
   returns 
 
659
      0  successfully untagged qinstances if necessary
 
660
     -1  error 
 
661
 
 
662
*/
 
663
int select_by_resource_list(
 
664
lList *resource_list,
 
665
lList *exechost_list,
 
666
lList *queue_list,
 
667
lList *centry_list,
 
668
u_long32 empty_qs
 
669
) {
 
670
   lListElem *cqueue = NULL;
 
671
 
 
672
   DENTER(TOP_LAYER, "select_by_resource_list");
 
673
 
 
674
   if (centry_list_fill_request(resource_list, NULL, centry_list, true, true, false)) {
 
675
      /* 
 
676
      ** error message gets written by centry_list_fill_request into 
 
677
      ** SGE_EVENT 
 
678
      */
 
679
      DEXIT;
 
680
      return -1;
 
681
   }
 
682
 
 
683
   /* prepare request */
 
684
   for_each(cqueue, queue_list) {
 
685
      lListElem *qep;
 
686
      bool selected;
 
687
      lList *qinstance_list = lGetList(cqueue, CQ_qinstances);
 
688
 
 
689
      for_each(qep, qinstance_list) {
 
690
         if (empty_qs)
 
691
            sconf_set_qs_state(QS_STATE_EMPTY);
 
692
 
 
693
         selected = sge_select_queue(resource_list, qep, NULL, exechost_list, centry_list, true, -1, NULL, NULL, NULL);
 
694
         if (empty_qs)
 
695
            sconf_set_qs_state(QS_STATE_FULL);
 
696
 
 
697
         if (!selected)
 
698
            lSetUlong(qep, QU_tag, 0);
 
699
      }
 
700
   }
 
701
 
 
702
   DEXIT;
 
703
   return 0;
 
704
}   
 
705
 
 
706
bool is_cqueue_selected(lList *queue_list)
 
707
{
 
708
   lListElem *cqueue;
 
709
   bool a_qinstance_is_selected = false;
 
710
   bool a_cqueue_is_selected = false;
 
711
 
 
712
   DENTER(TOP_LAYER, "is_cqueue_selected");
 
713
   
 
714
   for_each(cqueue, queue_list) {
 
715
      lListElem *qep;
 
716
      lList *qinstance_list = lGetList(cqueue, CQ_qinstances);
 
717
      bool tmp_a_qinstance_is_selected = false;
 
718
 
 
719
      for_each(qep, qinstance_list) {
 
720
         if (lGetUlong(qep, QU_tag) & TAG_SHOW_IT) {
 
721
            tmp_a_qinstance_is_selected = true;
 
722
            break;
 
723
         }
 
724
      }
 
725
      a_qinstance_is_selected |= tmp_a_qinstance_is_selected;
 
726
      if (!tmp_a_qinstance_is_selected && (lGetNumberOfElem(lGetList(cqueue,CQ_qinstances)) > 0)) {
 
727
         lSetUlong(cqueue, CQ_tag, TAG_DEFAULT);
 
728
      } else {
 
729
         a_cqueue_is_selected |= true;
 
730
      }
 
731
   }
 
732
 
 
733
   DEXIT;
 
734
   return a_cqueue_is_selected;
 
735
}
 
736
 
 
737
/****** sge_cqueue_qstat/qinstance_slots_reserved_now() ************************
 
738
*  NAME
 
739
*     qinstance_slots_reserved_now() -- get current reserved slots
 
740
*
 
741
*  SYNOPSIS
 
742
*     int qinstance_slots_reserved_now(const lListElem *this_elem) 
 
743
*
 
744
*  FUNCTION
 
745
*     rturns the current amount of reserved slots
 
746
*
 
747
*  INPUTS
 
748
*     const lListElem *this_elem - queue elem (QU_Type)
 
749
*
 
750
*  RESULT
 
751
*     int - number of currently reserved slots
 
752
*
 
753
*  NOTES
 
754
*     MT-NOTE: qinstance_slots_reserved_now() is MT safe 
 
755
*
 
756
*  SEE ALSO
 
757
*     qinstance_slots_reserved()
 
758
*******************************************************************************/
 
759
int qinstance_slots_reserved_now(const lListElem *this_elem)
 
760
{
 
761
   int ret = 0;
 
762
   lListElem *slots;
 
763
   u_long32 now = sge_get_gmt();
 
764
   
 
765
   DENTER(TOP_LAYER, "qinstance_slots_reserved_now");
 
766
 
 
767
   slots = lGetSubStr(this_elem, RUE_name, SGE_ATTR_SLOTS, QU_resource_utilization);
 
768
   if (slots != NULL) {
 
769
      ret = utilization_max(slots, now, 0);
 
770
   } 
 
771
 
 
772
   DRETURN(ret);
 
773
}