1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
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
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.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
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"
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"
55
#include "sge_qinstance_state.h"
56
#include "sge_advance_reservation_qmaster.h"
58
#include "sge_persistence_qmaster.h"
60
#include "sgeobj/sge_object.h"
62
#include "spool/sge_spooling.h"
64
#include "msg_common.h"
65
#include "msg_qmaster.h"
68
calendar_initalize_timer(sge_gdi_ctx_class_t *ctx, monitoring_t *monitor)
72
object_description *object_base = NULL;
73
lList *answer_list = NULL;
75
DENTER(TOP_LAYER, "calendar_initalize_timer");
77
object_base = object_type_get_object_description();
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);
85
calendar_update_queue_states(ctx, cep, NULL, NULL, &ppList, monitor);
88
lFreeList(&answer_list);
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)
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;
103
const char *cal_name;
105
DENTER(TOP_LAYER, "calendar_mod");
107
/* ---- CAL_name cannot get changed - we just ignore it */
109
cal_name = lGetString(cep, CAL_name);
110
if (verify_str_key(alpp, cal_name, MAX_VERIFY_STRING, "calendar", KEY_TABLE) != STATUS_OK)
112
lSetString(new_cal, CAL_name, cal_name);
114
cal_name = lGetString(new_cal, CAL_name);
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))
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))
132
for_each(cqueue, master_cqueue_list) {
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)) {
149
DRETURN(STATUS_EUNKNOWN);
153
calendar_spool(sge_gdi_ctx_class_t *ctx, lList **alpp, lListElem *cep, gdi_object_t *object)
155
lList *answer_list = NULL;
157
bool job_spooling = ctx->get_job_spooling(ctx);
159
DENTER(TOP_LAYER, "calendar_spool");
161
dbret = spool_write_object(&answer_list, spool_get_default_context(), cep,
162
lGetString(cep, CAL_name), SGE_TYPE_CALENDAR,
164
answer_list_output(&answer_list);
167
answer_list_add_sprintf(alpp, STATUS_EUNKNOWN,
168
ANSWER_QUALITY_ERROR,
169
MSG_PERSISTENCE_WRITE_FAILED_S,
170
lGetString(cep, CAL_name));
174
return dbret ? 0 : 1;
178
sge_del_calendar(sge_gdi_ctx_class_t *ctx, lListElem *cep, lList **alpp, char *ruser, char *rhost)
180
const char *cal_name;
181
lList **master_calendar_list = object_type_get_master_list(SGE_TYPE_CALENDAR);
183
DENTER(TOP_LAYER, "sge_del_calendar");
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);
189
return STATUS_EUNKNOWN;
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);
198
return STATUS_EUNKNOWN;
200
cal_name = lGetString(cep, CAL_name);
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);
207
return STATUS_EEXIST;
210
/* prevent deletion of a still referenced calendar */
212
lList *local_answer_list = NULL;
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);
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);
223
return STATUS_ESEMANTIC;
227
/* remove timer for this calendar */
228
te_delete_one_time_event(TYPE_CALENDAR_EVENT, 0, 0, cal_name);
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);
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);
243
/****** qmaster/sge_calendar_qmaster/sge_calendar_event_handler() **************
245
* sge_calendar_event_handler() -- calendar event handler
248
* void sge_calendar_event_handler(te_event_t anEvent)
251
* Handle calendar events.
254
* te_event_t anEvent - calendar event
260
* MT-NOTE: sge_calendar_event_handler() is MT safe
262
*******************************************************************************/
263
void sge_calendar_event_handler(sge_gdi_ctx_class_t *ctx, te_event_t anEvent, monitoring_t *monitor)
266
const char* cal_name = te_get_alphanumeric_key(anEvent);
267
lList *ppList = NULL;
269
DENTER(TOP_LAYER, "sge_calendar_event_handler");
271
MONITOR_WAIT_TIME(SGE_LOCK(LOCK_GLOBAL, LOCK_WRITE), monitor);
273
if (!(cep = calendar_list_locate(*object_type_get_master_list(SGE_TYPE_CALENDAR), cal_name)))
275
ERROR((SGE_EVENT, MSG_EVE_TE4CAL_S, cal_name));
276
SGE_UNLOCK(LOCK_GLOBAL, LOCK_WRITE);
280
calendar_update_queue_states(ctx, cep, 0, NULL, &ppList, monitor);
285
SGE_UNLOCK(LOCK_GLOBAL, LOCK_WRITE);
288
} /* sge_calendar_event_handler() */
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)
292
const char *cal_name = lGetString(cep, CAL_name);
293
lList *state_changes_list = NULL;
296
DENTER(TOP_LAYER, "calendar_update_queue_states");
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);
304
state = calender_state_changes(cep, &state_changes_list, &when, NULL);
306
qinstance_change_state_on_calendar_all(ctx, cal_name, state, state_changes_list, monitor);
308
lFreeList(&state_changes_list);
313
ev = te_new_event(when, TYPE_CALENDAR_EVENT, ONE_TIME_EVENT, 0, 0, cal_name);