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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 * 
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 * 
 *  Sun Microsystems Inc., March, 2001
 * 
 * 
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 * 
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 * 
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 * 
 *   Copyright: 2001 by Sun Microsystems, Inc.
 * 
 *   All Rights Reserved.
 * 
 ************************************************************************/
/*___INFO__MARK_END__*/

#include <string.h>

#include "basis_types.h"
#include "sge.h"
#include "sgermon.h"
#include "sge_strL.h"
#include "sge_ulongL.h"

#include "sgeobj/sge_answer.h"
#include "sgeobj/sge_advance_reservation.h"
#include "sgeobj/sge_centry.h"
#include "sgeobj/sge_job.h"
#include "sgeobj/sge_range.h"
#include "sgeobj/sge_mailrec.h"
#include "sgeobj/sge_userset.h"
#include "sgeobj/sge_qinstance.h"
#include "sgeobj/sge_qref.h"
#include "sgeobj/sge_mesobj.h"
#include "sgeobj/cull_parse_util.h"

#include "qrstat_report_handler.h"

#include "msg_common.h"

bool
qrstat_print(lList **answer_list, qrstat_report_handler_t *handler, qrstat_env_t *qrstat_env) {
   bool ret = true;

   DENTER(TOP_LAYER, "qrstat_print");

   {
      lListElem *ar = NULL;

      handler->report_start(handler, answer_list);
      if (qrstat_env->is_summary == false &&
          lGetNumberOfElem(qrstat_env->ar_list) == 0) {

          ret = false;

          for_each(ar, qrstat_env->ar_id_list) {
            handler->report_start_unknown_ar(handler, qrstat_env, answer_list);
            handler->report_ar_node_ulong_unknown(handler, qrstat_env, answer_list, "id", lGetUlong(ar, ULNG));
            handler->report_finish_unknown_ar(handler, answer_list);
          }
          handler->report_newline(handler, answer_list);
      } else {
         for_each(ar, qrstat_env->ar_list) {

            handler->report_start_ar(handler, qrstat_env, answer_list);
            handler->report_ar_node_ulong(handler, qrstat_env, answer_list, "id", lGetUlong(ar, AR_id));
            handler->report_ar_node_string(handler, answer_list, "name", lGetString(ar, AR_name));
            handler->report_ar_node_string(handler, answer_list, "owner", lGetString(ar, AR_owner));
            handler->report_ar_node_state(handler, answer_list, "state", lGetUlong(ar, AR_state));         
            handler->report_ar_node_time(handler, answer_list, "start_time",
                                         ((time_t)lGetUlong(ar, AR_start_time)));
            handler->report_ar_node_time(handler, answer_list, "end_time",
                                         ((time_t)lGetUlong(ar, AR_end_time)));
            handler->report_ar_node_duration(handler, answer_list, "duration", lGetUlong(ar, AR_duration));

            if (qrstat_env->is_explain || handler->show_summary == false) {
               lListElem *qinstance;
               for_each(qinstance, lGetList(ar, AR_reserved_queues)) {
                  lListElem *qim = NULL;
                  for_each(qim, lGetList(qinstance, QU_message_list)) {
                     const char *message = lGetString(qim, QIM_message);
                     handler->report_ar_node_string(handler, answer_list, "message", message);
                  }
               }
            }
            if (handler->show_summary == false) {
               handler->report_ar_node_time(handler, answer_list, "submission_time",
                                         ((time_t)lGetUlong(ar, AR_submission_time)));
               handler->report_ar_node_string(handler, answer_list, "group", lGetString(ar, AR_group));
               handler->report_ar_node_string(handler, answer_list, "account", lGetString(ar, AR_account));

               if (lGetList(ar, AR_resource_list) != NULL) {
                  lListElem *resource = NULL;

                  handler->report_start_resource_list(handler, answer_list);            
                  for_each(resource, lGetList(ar, AR_resource_list)) {
                     dstring string_value = DSTRING_INIT;

                     if (lGetString(resource, CE_stringval)) {
                        sge_dstring_append(&string_value, lGetString(resource, CE_stringval));
                     } else {
                        sge_dstring_sprintf(&string_value, "%f", lGetDouble(resource, CE_doubleval));
                     }

                     handler->report_resource_list_node(handler, answer_list,
                                                        lGetString(resource, CE_name),
                                                        sge_dstring_get_string(&string_value));
                     sge_dstring_free(&string_value);
                  }
                  handler->report_finish_resource_list(handler, answer_list);
               }
               
               if (lGetUlong(ar, AR_error_handling) != 0) {
                  handler->report_ar_node_boolean(handler, answer_list, "error_handling", true);
               }
               
               if (lGetList(ar, AR_granted_slots) != NULL) {
                  lListElem *resource = NULL;

                  handler->report_start_granted_slots_list(handler, answer_list);
                  for_each(resource, lGetList(ar, AR_granted_slots)) {
                     handler->report_granted_slots_list_node(handler, answer_list,
                                                             lGetString(resource, JG_qname),
                                                             lGetUlong(resource, JG_slots));
                  }
                  handler->report_finish_granted_slots_list(handler, answer_list);
               }
               if (lGetString(ar, AR_pe) != NULL) {
                  dstring pe_range_string = DSTRING_INIT;

                  range_list_print_to_string(lGetList(ar, AR_pe_range), &pe_range_string, true, false, false);
                  handler->report_start_granted_parallel_environment(handler, answer_list);
                  handler->report_granted_parallel_environment_node(handler, answer_list,
                                                                    lGetString(ar, AR_pe),
                                                                    sge_dstring_get_string(&pe_range_string));
                  handler->report_finish_granted_parallel_environment(handler, answer_list);
                  sge_dstring_free(&pe_range_string);
               }
               if (lGetList(ar, AR_master_queue_list) != NULL) {
                  char tmp_buffer[MAX_STRING_SIZE];
                  int fields[] = {QR_name, 0 };
                  const char *delis[] = {" ", ",", ""};
                  uni_print_list(NULL, tmp_buffer, sizeof(tmp_buffer), lGetList(ar, AR_master_queue_list), 
                                 fields, delis, FLG_NO_DELIS_STRINGS);
                  handler->report_ar_node_string(handler, answer_list, "master hard queue_list", tmp_buffer);
               }

               if (lGetString(ar, AR_checkpoint_name) != NULL) {
                  handler->report_ar_node_string(handler, answer_list, "checkpoint_name",
                                                 lGetString(ar, AR_checkpoint_name));
               }

               if (lGetUlong(ar, AR_mail_options) != 0) {
                  dstring mailopt = DSTRING_INIT;

                  sge_dstring_append_mailopt(&mailopt, lGetUlong(ar, AR_mail_options));
                  handler->report_ar_node_string(handler, answer_list, "mail_options",
                                                 sge_dstring_get_string(&mailopt));

                  sge_dstring_free(&mailopt);
               }

               if (lGetList(ar, AR_mail_list) != NULL) {
                  lListElem *mail = NULL;

                  handler->report_start_mail_list(handler, answer_list);
                  for_each(mail, lGetList(ar, AR_mail_list)) {
                     const char *host=NULL;
                     host=lGetHost(mail, MR_host);
                     handler->report_mail_list_node(handler, answer_list,
                                                    lGetString(mail, MR_user),
                                                    host?host:"NONE");
                  }
                  handler->report_finish_mail_list(handler, answer_list);
               }
               if (lGetList(ar, AR_acl_list) != NULL) {
                  lListElem *acl = NULL;

                  handler->report_start_acl_list(handler, answer_list);
                  for_each(acl, lGetList(ar, AR_acl_list)) {
                     handler->report_acl_list_node(handler, answer_list,
                                                    lGetString(acl, ARA_name));
                  }
                  handler->report_finish_acl_list(handler, answer_list);
               }
               if (lGetList(ar, AR_xacl_list) != NULL) {
                  lListElem *xacl = NULL;

                  handler->report_start_xacl_list(handler, answer_list);
                  for_each(xacl, lGetList(ar, AR_xacl_list)) {
                     handler->report_xacl_list_node(handler, answer_list,
                                                    lGetString(xacl, ARA_name));
                  }
                  handler->report_finish_xacl_list(handler, answer_list);
               }
            }
            handler->report_finish_ar(handler, answer_list);
         }
      }

      handler->report_finish(handler, answer_list);
   }
   DRETURN(ret);
}