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

« back to all changes in this revision

Viewing changes to source/libs/sched/schedd_monitor.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 <time.h>
 
35
#include <limits.h>
 
36
#include <errno.h>
 
37
 
 
38
#include "uti/sge_stdio.h"
 
39
#include "sge_all_listsL.h"
 
40
#include "schedd_monitor.h"
 
41
#include "sgermon.h"
 
42
#include "cull_parse_util.h"
 
43
#include "sge_time.h"
 
44
#include "sge_answer.h"
 
45
#include "uti/sge_string.h"
 
46
 
 
47
#include "msg_common.h"
 
48
 
 
49
 
 
50
static bool monitor_next_run = false;
 
51
static char log_string[2048 + 1] = "invalid log_string";
 
52
static char schedd_log_file[SGE_PATH_MAX + 1] = "";
 
53
 
 
54
/* if set we do not log into schedd log file but we fill up this answer list */
 
55
static lList **monitor_alpp = NULL;
 
56
 
 
57
void schedd_set_schedd_log_file(sge_gdi_ctx_class_t *ctx)
 
58
{
 
59
   const char *cell_root = ctx->get_cell_root(ctx);
 
60
   
 
61
   DENTER(TOP_LAYER, "schedd_set_schedd_log_file");
 
62
 
 
63
   if (!*schedd_log_file) {
 
64
      snprintf(schedd_log_file, sizeof(schedd_log_file), "%s/%s/%s", cell_root, "common", SCHED_LOG_NAME);
 
65
      DPRINTF(("schedd log file >>%s<<\n", schedd_log_file));
 
66
   }
 
67
 
 
68
   DEXIT;
 
69
}
 
70
 
 
71
bool schedd_is_monitor_next_run(void)
 
72
{
 
73
   return monitor_next_run;
 
74
}
 
75
 
 
76
void schedd_set_monitor_next_run(bool set)
 
77
{
 
78
   monitor_next_run = set;
 
79
}
 
80
 
 
81
char* schedd_get_log_string(void)
 
82
{
 
83
   return log_string;
 
84
}
 
85
 
 
86
void clean_monitor_alp()
 
87
{
 
88
   lFreeList(monitor_alpp);
 
89
}
 
90
 
 
91
void set_monitor_alpp(lList **alpp) {
 
92
   monitor_alpp = alpp;
 
93
   monitor_next_run = (alpp!=NULL)?true:false;
 
94
}
 
95
 
 
96
int schedd_log(const char *logstr) 
 
97
{
 
98
   DENTER(TOP_LAYER, "schedd_log");
 
99
 
 
100
   if (!monitor_next_run) {
 
101
      DEXIT;
 
102
      return 0;
 
103
   }
 
104
 
 
105
   if (monitor_alpp) {
 
106
      char logloglog[2048];
 
107
/*       DPRINTF(("schedd_log: %s\n", logstr)); */
 
108
      sprintf(logloglog, "%s", logstr);
 
109
      answer_list_add(monitor_alpp, logloglog, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR);
 
110
   } 
 
111
   else {
 
112
      time_t now;
 
113
      FILE *fp = NULL;
 
114
      char *time_str = NULL;
 
115
      char str[128];
 
116
   
 
117
      now = (time_t)sge_get_gmt();
 
118
      time_str =  ctime_r(&now, str);
 
119
      if (time_str[strlen(time_str) - 1] == '\n') {
 
120
         time_str[strlen(time_str) - 1] = '|';
 
121
      }
 
122
 
 
123
      fp = fopen(schedd_log_file, "a");
 
124
      if (!fp) {
 
125
         DPRINTF(("could not open schedd_log_file "SFQ"\n", schedd_log_file));
 
126
         DEXIT;
 
127
         return -1;
 
128
      }
 
129
 
 
130
      fprintf(fp, "%s", time_str);
 
131
      fprintf(fp, "%s\n", logstr);
 
132
      FCLOSE(fp);
 
133
   }
 
134
 
 
135
   DEXIT;
 
136
   return 0;
 
137
FCLOSE_ERROR:
 
138
   DPRINTF((MSG_FILE_ERRORCLOSEINGXY_SS, schedd_log_file, strerror(errno)));
 
139
   DEXIT;
 
140
   return -1;
 
141
}
 
142
 
 
143
 
 
144
#define NUM_ITEMS_ON_LINE 10
 
145
 
 
146
int schedd_log_list(const char *logstr, lList *lp, int nm) {
 
147
   int fields[] = { 0, 0 };
 
148
   const char *delis[] = {NULL, " ", NULL};
 
149
   lList *lp_part = NULL;
 
150
   lListElem *ep = NULL;
 
151
 
 
152
   DENTER(TOP_LAYER, "schedd_log_list");
 
153
 
 
154
#ifndef WIN32NATIVE
 
155
 
 
156
   if (!monitor_next_run) {
 
157
      DEXIT;
 
158
      return 0;
 
159
   }
 
160
   
 
161
   fields[0] = nm;
 
162
 
 
163
   for_each(ep, lp) {
 
164
      if (!lp_part) {
 
165
         lp_part = lCreateList("partial list", lGetListDescr(lp));
 
166
      }
 
167
      lAppendElem(lp_part, lCopyElem(ep));
 
168
      if ((lGetNumberOfElem(lp_part) == NUM_ITEMS_ON_LINE) || !lNext(ep)) {
 
169
         strcpy(log_string, logstr);
 
170
#ifndef WIN32NATIVE
 
171
         uni_print_list(NULL, 
 
172
                        log_string + strlen(log_string), 
 
173
                        sizeof(log_string) - strlen(log_string) - 1, 
 
174
                        lp_part, 
 
175
                        fields, delis, 0);
 
176
#endif
 
177
         schedd_log(log_string);
 
178
         lFreeList(&lp_part);
 
179
         lp_part = NULL;
 
180
      }
 
181
   }
 
182
#else
 
183
   DPRINTF(("schedd_log_list does nothing for QMonNT !!!\n"));
 
184
#endif
 
185
 
 
186
   DEXIT;
 
187
   return 0;
 
188
}
 
189
 
 
190
 
 
191
const char *job_descr(
 
192
u_long32 jobid 
 
193
) {
 
194
   static char descr[20];
 
195
 
 
196
   if (jobid) {
 
197
      sprintf(descr, "Job "sge_u32, jobid);
 
198
      return descr;
 
199
   } else
 
200
      return "Job";
 
201
   
 
202
}
 
203