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

« back to all changes in this revision

Viewing changes to source/daemons/qmaster/sge_calendar_qmaster.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
#include <stdio.h>
 
33
#include <string.h>
 
34
#include <ctype.h>
 
35
#include <time.h>
 
36
#include <sys/time.h>
 
37
 
 
38
#include "sge.h"
 
39
#include "sge_log.h"
 
40
#include "sgermon.h"
 
41
#include "sge_event_master.h"
 
42
#include "sge_c_gdi.h"
 
43
#include "sge_calendar_qmaster.h"
 
44
#include "sge_qmod_qmaster.h"
 
45
#include "sge_qinstance_qmaster.h"
 
46
#include "sge_time.h"
 
47
#include "sge_unistd.h"
 
48
#include "sge_answer.h"
 
49
#include "sge_cqueue.h"
 
50
#include "sge_qinstance.h"
 
51
#include "sge_calendar.h"
 
52
#include "sge_utility.h"
 
53
#include "sge_utility_qmaster.h"
 
54
#include "sge_lock.h"
 
55
#include "sge_qinstance_state.h"
 
56
#include "sge_advance_reservation_qmaster.h"
 
57
 
 
58
#include "sge_persistence_qmaster.h"
 
59
 
 
60
#include "sgeobj/sge_object.h"
 
61
 
 
62
#include "spool/sge_spooling.h"
 
63
 
 
64
#include "msg_common.h"
 
65
#include "msg_qmaster.h"
 
66
 
 
67
void
 
68
calendar_initalize_timer(sge_gdi_ctx_class_t *ctx, monitoring_t *monitor)
 
69
{
 
70
   lListElem *cep;
 
71
   lList *ppList = NULL;
 
72
   object_description *object_base = NULL;
 
73
   lList *answer_list = NULL;
 
74
 
 
75
   DENTER(TOP_LAYER, "calendar_initalize_timer");
 
76
 
 
77
   object_base = object_type_get_object_description();
 
78
 
 
79
   
 
80
   for_each (cep, *object_base[SGE_TYPE_CALENDAR].list) {
 
81
      calendar_parse_year(cep, &answer_list);
 
82
      calendar_parse_week(cep, &answer_list);         
 
83
      answer_list_output(&answer_list);
 
84
 
 
85
      calendar_update_queue_states(ctx, cep, NULL, NULL, &ppList, monitor);
 
86
   }
 
87
 
 
88
   lFreeList(&answer_list);
 
89
   lFreeList(&ppList);
 
90
 
 
91
   DRETURN_VOID;
 
92
}
 
93
 
 
94
int 
 
95
calendar_mod(sge_gdi_ctx_class_t *ctx, lList **alpp, lListElem *new_cal, lListElem *cep, int add, 
 
96
             const char *ruser, const char *rhost, gdi_object_t *object, 
 
97
             int sub_command, monitoring_t *monitor) 
 
98
{
 
99
   object_description *object_base = object_type_get_object_description();
 
100
   lList *master_ar_list = *object_base[SGE_TYPE_AR].list;
 
101
   lList *master_cqueue_list = *object_base[SGE_TYPE_CQUEUE].list;
 
102
   lListElem *cqueue;
 
103
   const char *cal_name;
 
104
 
 
105
   DENTER(TOP_LAYER, "calendar_mod");
 
106
 
 
107
   /* ---- CAL_name cannot get changed - we just ignore it */
 
108
   if (add == 1) {
 
109
      cal_name = lGetString(cep, CAL_name);
 
110
      if (verify_str_key(alpp, cal_name, MAX_VERIFY_STRING, "calendar", KEY_TABLE) != STATUS_OK)
 
111
         goto ERROR;
 
112
      lSetString(new_cal, CAL_name, cal_name);
 
113
   } else {
 
114
      cal_name = lGetString(new_cal, CAL_name);
 
115
   }
 
116
 
 
117
   /* ---- CAL_year_calendar */
 
118
   attr_mod_zerostr(cep, new_cal, CAL_year_calendar, "year calendar");
 
119
   if (lGetPosViaElem(cep, CAL_year_calendar, SGE_NO_ABORT)>=0) {
 
120
      if (!calendar_parse_year(new_cal, alpp)) 
 
121
         goto ERROR;
 
122
   }
 
123
 
 
124
   /* ---- CAL_week_calendar */
 
125
   attr_mod_zerostr(cep, new_cal, CAL_week_calendar, "week calendar");
 
126
   if (lGetPosViaElem(cep, CAL_week_calendar, SGE_NO_ABORT)>=0) {
 
127
      if (!calendar_parse_week(new_cal, alpp))
 
128
         goto ERROR;
 
129
   }
 
130
 
 
131
   if (add != 1) {
 
132
      for_each(cqueue, master_cqueue_list) {
 
133
         lListElem *queue;
 
134
         for_each(queue, lGetList(cqueue, CQ_qinstances)) {
 
135
            const char *q_cal = lGetString(queue, QU_calendar);
 
136
            if ((q_cal != NULL) && (strcmp(cal_name, q_cal) == 0)) {
 
137
               if (sge_ar_list_conflicts_with_calendar(alpp,
 
138
                   lGetString(queue, QU_full_name), new_cal, master_ar_list)) {
 
139
                  goto ERROR; 
 
140
               }
 
141
            }
 
142
         }
 
143
      }
 
144
   }
 
145
 
 
146
   DRETURN(0);
 
147
 
 
148
ERROR:
 
149
   DRETURN(STATUS_EUNKNOWN);
 
150
}
 
151
 
 
152
int 
 
153
calendar_spool(sge_gdi_ctx_class_t *ctx, lList **alpp, lListElem *cep, gdi_object_t *object) 
 
154
{
 
155
   lList *answer_list = NULL;
 
156
   bool dbret;
 
157
   bool job_spooling = ctx->get_job_spooling(ctx);
 
158
 
 
159
   DENTER(TOP_LAYER, "calendar_spool");
 
160
 
 
161
   dbret = spool_write_object(&answer_list, spool_get_default_context(), cep,
 
162
                              lGetString(cep, CAL_name), SGE_TYPE_CALENDAR,
 
163
                              job_spooling);
 
164
   answer_list_output(&answer_list);
 
165
 
 
166
   if (!dbret) {
 
167
      answer_list_add_sprintf(alpp, STATUS_EUNKNOWN, 
 
168
                              ANSWER_QUALITY_ERROR, 
 
169
                              MSG_PERSISTENCE_WRITE_FAILED_S,
 
170
                              lGetString(cep, CAL_name));
 
171
   }
 
172
 
 
173
   DEXIT;
 
174
   return dbret ? 0 : 1;
 
175
}
 
176
 
 
177
int 
 
178
sge_del_calendar(sge_gdi_ctx_class_t *ctx, lListElem *cep, lList **alpp, char *ruser, char *rhost) 
 
179
{
 
180
   const char *cal_name;
 
181
   lList **master_calendar_list = object_type_get_master_list(SGE_TYPE_CALENDAR);
 
182
 
 
183
   DENTER(TOP_LAYER, "sge_del_calendar");
 
184
 
 
185
   if ( !cep || !ruser || !rhost ) {
 
186
      CRITICAL((SGE_EVENT, MSG_SGETEXT_NULLPTRPASSED_S, SGE_FUNC));
 
187
      answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
188
      DEXIT;
 
189
      return STATUS_EUNKNOWN;
 
190
   }
 
191
 
 
192
   /* ep is no calendar element, if cep has no CAL_name */
 
193
   if (lGetPosViaElem(cep, CAL_name, SGE_NO_ABORT)<0) {
 
194
      CRITICAL((SGE_EVENT, MSG_SGETEXT_MISSINGCULLFIELD_SS,
 
195
            lNm2Str(QU_qname), SGE_FUNC));
 
196
      answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
197
      DEXIT;
 
198
      return STATUS_EUNKNOWN;
 
199
   }
 
200
   cal_name = lGetString(cep, CAL_name);
 
201
 
 
202
   if (!calendar_list_locate(*master_calendar_list, cal_name)) {
 
203
      ERROR((SGE_EVENT, MSG_SGETEXT_DOESNOTEXIST_SS, 
 
204
             MSG_OBJ_CALENDAR, cal_name));
 
205
      answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR);
 
206
      DEXIT;
 
207
      return STATUS_EEXIST;
 
208
   }
 
209
 
 
210
   /* prevent deletion of a still referenced calendar */
 
211
   {
 
212
      lList *local_answer_list = NULL;
 
213
 
 
214
      if (calendar_is_referenced(cep, &local_answer_list, 
 
215
                            *(object_type_get_master_list(SGE_TYPE_CQUEUE)))) {
 
216
         lListElem *answer = lFirst(local_answer_list);
 
217
 
 
218
         ERROR((SGE_EVENT, "denied: %s", lGetString(answer, AN_text)));
 
219
         answer_list_add(alpp, SGE_EVENT, STATUS_ESEMANTIC,
 
220
                         ANSWER_QUALITY_ERROR);
 
221
         lFreeList(&local_answer_list);
 
222
         DEXIT;
 
223
         return STATUS_ESEMANTIC;
 
224
      }
 
225
   }
 
226
 
 
227
   /* remove timer for this calendar */
 
228
   te_delete_one_time_event(TYPE_CALENDAR_EVENT, 0, 0, cal_name);
 
229
 
 
230
   sge_event_spool(ctx, 
 
231
                   alpp, 0, sgeE_CALENDAR_DEL, 
 
232
                   0, 0, cal_name, NULL, NULL,
 
233
                   NULL, NULL, NULL, true, true);
 
234
   lDelElemStr(master_calendar_list, CAL_name, cal_name);
 
235
 
 
236
   INFO((SGE_EVENT, MSG_SGETEXT_REMOVEDFROMLIST_SSSS,
 
237
         ruser, rhost, cal_name, MSG_OBJ_CALENDAR));
 
238
   answer_list_add(alpp, SGE_EVENT, STATUS_OK, ANSWER_QUALITY_INFO);
 
239
   DEXIT;
 
240
   return STATUS_OK;
 
241
}
 
242
 
 
243
/****** qmaster/sge_calendar_qmaster/sge_calendar_event_handler() **************
 
244
*  NAME
 
245
*     sge_calendar_event_handler() -- calendar event handler
 
246
*
 
247
*  SYNOPSIS
 
248
*     void sge_calendar_event_handler(te_event_t anEvent) 
 
249
*
 
250
*  FUNCTION
 
251
*     Handle calendar events. 
 
252
*
 
253
*  INPUTS
 
254
*     te_event_t anEvent - calendar event
 
255
*
 
256
*  RESULT
 
257
*     void - none
 
258
*
 
259
*  NOTES
 
260
*     MT-NOTE: sge_calendar_event_handler() is MT safe 
 
261
*
 
262
*******************************************************************************/
 
263
void sge_calendar_event_handler(sge_gdi_ctx_class_t *ctx, te_event_t anEvent, monitoring_t *monitor) 
 
264
{
 
265
   lListElem *cep;
 
266
   const char* cal_name = te_get_alphanumeric_key(anEvent);
 
267
   lList *ppList = NULL;
 
268
 
 
269
   DENTER(TOP_LAYER, "sge_calendar_event_handler");
 
270
 
 
271
   MONITOR_WAIT_TIME(SGE_LOCK(LOCK_GLOBAL, LOCK_WRITE), monitor);
 
272
 
 
273
   if (!(cep = calendar_list_locate(*object_type_get_master_list(SGE_TYPE_CALENDAR), cal_name)))
 
274
   {
 
275
      ERROR((SGE_EVENT, MSG_EVE_TE4CAL_S, cal_name));   
 
276
      SGE_UNLOCK(LOCK_GLOBAL, LOCK_WRITE);      
 
277
      DRETURN_VOID;
 
278
   }
 
279
      
 
280
   calendar_update_queue_states(ctx, cep, 0, NULL, &ppList, monitor);
 
281
   lFreeList(&ppList);
 
282
 
 
283
   FREE(cal_name);
 
284
 
 
285
   SGE_UNLOCK(LOCK_GLOBAL, LOCK_WRITE);
 
286
 
 
287
   DRETURN_VOID;
 
288
} /* sge_calendar_event_handler() */
 
289
 
 
290
int calendar_update_queue_states(sge_gdi_ctx_class_t *ctx, lListElem *cep, lListElem *old_cep, gdi_object_t *object, lList **ppList, monitoring_t *monitor)
 
291
{
 
292
   const char *cal_name = lGetString(cep, CAL_name);
 
293
   lList *state_changes_list = NULL;
 
294
   u_long32 state;
 
295
   time_t when = 0; 
 
296
   DENTER(TOP_LAYER, "calendar_update_queue_states");
 
297
 
 
298
   if (lListElem_is_changed(cep)) {
 
299
      sge_add_event( 0, old_cep ? sgeE_CALENDAR_MOD : sgeE_CALENDAR_ADD, 
 
300
                    0, 0, cal_name, NULL, NULL, cep);
 
301
      lListElem_clear_changed_info(cep);
 
302
   }
 
303
 
 
304
   state = calender_state_changes(cep, &state_changes_list, &when, NULL);
 
305
   
 
306
   qinstance_change_state_on_calendar_all(ctx, cal_name, state, state_changes_list, monitor);
 
307
 
 
308
   lFreeList(&state_changes_list);
 
309
 
 
310
   if (when) {
 
311
      te_event_t ev;
 
312
 
 
313
      ev = te_new_event(when, TYPE_CALENDAR_EVENT, ONE_TIME_EVENT, 0, 0, cal_name);
 
314
      te_add_event(ev);
 
315
      te_free_event(&ev);
 
316
   }
 
317
  
 
318
   DEXIT;
 
319
   return 0;
 
320
}
 
321