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

« back to all changes in this revision

Viewing changes to source/libs/gdi/sge_gdi_ctx.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
 
 
33
#include <netdb.h>
 
34
#include <stdlib.h>
 
35
#include <stdio.h>
 
36
#include <string.h>
 
37
#include <pwd.h>
 
38
#include <grp.h>
 
39
#include <errno.h>
 
40
#include <pthread.h>
 
41
#include <sys/types.h>
 
42
#include <sys/socket.h>  
 
43
 
 
44
#include "lck/sge_lock.h"
 
45
 
 
46
#include "comm/commlib.h"
 
47
#include "comm/lists/cl_util.h"
 
48
 
 
49
#include "rmon/sgermon.h"
 
50
 
 
51
#include "uti/sge_hostname.h"
 
52
#include "uti/sge_log.h"
 
53
#include "uti/sge_stdlib.h"
 
54
#include "uti/sge_string.h"
 
55
#include "uti/sge_unistd.h"
 
56
#include "uti/sge_env.h"
 
57
#include "uti/sge_prog.h"
 
58
#include "uti/setup_path.h"
 
59
#include "uti/sge_bootstrap.h"
 
60
#include "uti/sge_uidgid.h"
 
61
#include "uti/sge_profiling.h"
 
62
#include "uti/msg_utilib.h"
 
63
#include "uti/sge_language.h"
 
64
#include "uti/sge_spool.h"
 
65
 
 
66
#include "sgeobj/sge_answer.h"
 
67
 
 
68
#include "gdi/qm_name.h"
 
69
 
 
70
#include "sgeobj/sge_feature.h"
 
71
#include "sgeobj/sge_conf.h"
 
72
#include "sgeobj/sge_object.h"
 
73
 
 
74
#include "sge.h"
 
75
#include "sge_csp_path.h"
 
76
#include "msg_gdilib.h"
 
77
 
 
78
/*
 
79
** need this for lInit(nmv)
 
80
*/
 
81
extern lNameSpace nmv[];
 
82
 
 
83
#if  1
 
84
/* TODO: throw this out asap */
 
85
#include "gdi/sge_gdi.h"
 
86
 
 
87
void gdi_once_init(void);
 
88
void feature_mt_init(void);
 
89
void sc_mt_init(void);
 
90
#endif
 
91
 
 
92
#include "gdi/sge_gdi_ctx.h"
 
93
#include "gdi/sge_gdi2.h"
 
94
#include "gdi/sge_gdi_packet_internal.h"
 
95
 
 
96
typedef struct {
 
97
   sge_env_state_class_t* sge_env_state_obj;
 
98
   sge_prog_state_class_t* sge_prog_state_obj;
 
99
   sge_path_state_class_t* sge_path_state_obj;
 
100
   sge_bootstrap_state_class_t* sge_bootstrap_state_obj;
 
101
   sge_csp_path_class_t* sge_csp_path_obj;
 
102
   
 
103
   char* component_name;
 
104
   char* thread_name;
 
105
   char* master;
 
106
   char* component_username;
 
107
   char* username;
 
108
   char* groupname;
 
109
   uid_t uid;
 
110
   gid_t gid;
 
111
 
 
112
   char *ssl_private_key;
 
113
   char *ssl_certificate;
 
114
 
 
115
   lList *alp;
 
116
   int last_commlib_error;
 
117
   sge_error_class_t *eh;
 
118
 
 
119
   bool is_qmaster_internal_client;
 
120
   bool is_setup;
 
121
} sge_gdi_ctx_t;
 
122
 
 
123
static pthread_key_t  gdi_state_key;
 
124
static pthread_once_t gdi_once_control = PTHREAD_ONCE_INIT;
 
125
 
 
126
typedef struct {
 
127
   /* gdi request base */
 
128
   u_long32 request_id;     /* incremented with each GDI request to have a unique request ID
 
129
                               it is ensured that the request ID is also contained in answer */
 
130
} gdi_state_t;
 
131
 
 
132
static void gdi_state_destroy(void* state) {
 
133
   free(state);
 
134
}
 
135
 
 
136
void gdi_once_init(void) {
 
137
   pthread_key_create(&gdi_state_key, &gdi_state_destroy);
 
138
 
139
 
 
140
static void gdi_state_init(gdi_state_t* state) {
 
141
   state->request_id = 0;
 
142
}
 
143
 
 
144
/****** gid/gdi_setup/gdi_mt_init() ************************************************
 
145
*  NAME
 
146
*     gdi_mt_init() -- Initialize GDI state for multi threading use.
 
147
*
 
148
*  SYNOPSIS
 
149
*     void gdi_mt_init(void) 
 
150
*
 
151
*  FUNCTION
 
152
*     Set up GDI. This function must be called at least once before any of the
 
153
*     GDI functions is used. This function is idempotent, i.e. it is safe to
 
154
*     call it multiple times.
 
155
*
 
156
*     Thread local storage for the GDI state information is reserved. 
 
157
*
 
158
*  INPUTS
 
159
*     void - NONE 
 
160
*
 
161
*  RESULT
 
162
*     void - NONE
 
163
*
 
164
*  NOTES
 
165
*     MT-NOTE: gdi_mt_init() is MT safe 
 
166
*
 
167
*******************************************************************************/
 
168
void gdi_mt_init(void)
 
169
{
 
170
   pthread_once(&gdi_once_control, gdi_once_init);
 
171
}
 
172
 
 
173
/****** libs/gdi/gdi_state_get_????() ************************************
 
174
*  NAME
 
175
*     gdi_state_get_????() - read access to gdilib global variables
 
176
*
 
177
*  FUNCTION
 
178
*     Provides access to either global variable or per thread global
 
179
*     variable.
 
180
*
 
181
******************************************************************************/
 
182
u_long32 gdi_state_get_next_request_id(void)
 
183
{
 
184
   GET_SPECIFIC(gdi_state_t, gdi_state, 
 
185
                gdi_state_init, gdi_state_key, "gdi_state_get_next_request_id");
 
186
   gdi_state->request_id++;
 
187
   return gdi_state->request_id;
 
188
}
 
189
 
 
190
typedef struct {
 
191
   sge_gdi_ctx_class_t* ctx;   
 
192
} sge_gdi_ctx_thread_local_t;
 
193
 
 
194
static pthread_once_t sge_gdi_ctx_once = PTHREAD_ONCE_INIT;
 
195
static pthread_key_t  sge_gdi_ctx_key;
 
196
static void sge_gdi_thread_local_ctx_once_init(void);
 
197
static void sge_gdi_thread_local_ctx_destroy(void* theState);
 
198
static void sge_gdi_thread_local_ctx_init(sge_gdi_ctx_thread_local_t* theState);
 
199
 
 
200
static void sge_gdi_thread_local_ctx_once_init(void)
 
201
{
 
202
   pthread_key_create(&sge_gdi_ctx_key, sge_gdi_thread_local_ctx_destroy);
 
203
}
 
204
 
 
205
static void sge_gdi_thread_local_ctx_destroy(void* theState) {
 
206
   sge_gdi_ctx_thread_local_t *tl = (sge_gdi_ctx_thread_local_t*)theState;
 
207
   tl->ctx = NULL;
 
208
   free(theState);
 
209
}
 
210
 
 
211
static void sge_gdi_thread_local_ctx_init(sge_gdi_ctx_thread_local_t* theState)
 
212
{
 
213
   memset(theState, 0, sizeof(sge_gdi_ctx_thread_local_t));
 
214
}
 
215
 
 
216
 
 
217
sge_gdi_ctx_class_t* sge_gdi_get_thread_local_ctx() {
 
218
 
 
219
   pthread_once(&sge_gdi_ctx_once, sge_gdi_thread_local_ctx_once_init);
 
220
   {
 
221
      GET_SPECIFIC(sge_gdi_ctx_thread_local_t, tl, sge_gdi_thread_local_ctx_init, sge_gdi_ctx_key,
 
222
                "sge_gdi_get_thread_local_ctx");
 
223
      return tl->ctx;
 
224
   }   
 
225
}
 
226
 
 
227
void sge_gdi_set_thread_local_ctx(sge_gdi_ctx_class_t* ctx) {
 
228
 
 
229
   DENTER(TOP_LAYER, "sge_gdi_set_thread_local_ctx");
 
230
   
 
231
   pthread_once(&sge_gdi_ctx_once, sge_gdi_thread_local_ctx_once_init);
 
232
   { 
 
233
      GET_SPECIFIC(sge_gdi_ctx_thread_local_t, tl, sge_gdi_thread_local_ctx_init, sge_gdi_ctx_key,
 
234
                "set_thread_local_ctx");
 
235
      tl->ctx = ctx;
 
236
 
 
237
      if (ctx != NULL) {
 
238
         sge_bootstrap_state_set_thread_local(ctx->get_sge_bootstrap_state(ctx));
 
239
         log_state_set_log_context(ctx);
 
240
      } else {
 
241
         sge_bootstrap_state_set_thread_local(NULL);
 
242
         log_state_set_log_context(NULL);
 
243
      }
 
244
   }   
 
245
   DRETURN_VOID;
 
246
}
 
247
 
 
248
static bool 
 
249
sge_gdi_ctx_setup(sge_gdi_ctx_class_t *thiz, int prog_number, const char* component_name,
 
250
                  int thread_number, const char *thread_name, const char* username, 
 
251
                  const char *groupname, const char *sge_root, const char *sge_cell, 
 
252
                  int sge_qmaster_port, int sge_execd_port, bool from_services,
 
253
                  bool is_qmaster_internal_client);
 
254
 
 
255
static void sge_gdi_ctx_destroy(void *theState);
 
256
 
 
257
static void sge_gdi_ctx_set_is_setup(sge_gdi_ctx_class_t *thiz, bool is_setup);
 
258
static bool sge_gdi_ctx_is_setup(sge_gdi_ctx_class_t *thiz);
 
259
static void sge_gdi_ctx_class_get_errors(sge_gdi_ctx_class_t *thiz, lList **alpp, bool clear_errors);
 
260
static void sge_gdi_ctx_class_error(sge_gdi_ctx_class_t *thiz, int error_type, int error_quality, const char* fmt, ...);
 
261
static sge_env_state_class_t* get_sge_env_state(sge_gdi_ctx_class_t *thiz);
 
262
static sge_prog_state_class_t* get_sge_prog_state(sge_gdi_ctx_class_t *thiz);
 
263
static sge_path_state_class_t* get_sge_path_state(sge_gdi_ctx_class_t *thiz);
 
264
static sge_csp_path_class_t* get_sge_csp_path(sge_gdi_ctx_class_t *thiz);
 
265
static sge_bootstrap_state_class_t* get_sge_bootstrap_state(sge_gdi_ctx_class_t *thiz);
 
266
static int reresolve_qualified_hostname(sge_gdi_ctx_class_t *thiz);
 
267
static cl_com_handle_t* get_com_handle(sge_gdi_ctx_class_t *thiz);
 
268
static const char* get_component_name(sge_gdi_ctx_class_t *thiz);
 
269
static const char* get_thread_name(sge_gdi_ctx_class_t *thiz);
 
270
static const char* get_progname(sge_gdi_ctx_class_t *thiz);
 
271
static const char* get_ca_local_root(sge_gdi_ctx_class_t *thiz);
 
272
static const char* get_ca_root(sge_gdi_ctx_class_t *thiz);
 
273
static u_long32 get_who(sge_gdi_ctx_class_t *thiz);
 
274
static bool is_daemonized(sge_gdi_ctx_class_t *thiz);
 
275
static void set_daemonized(sge_gdi_ctx_class_t *thiz, bool daemonized);
 
276
static bool get_job_spooling(sge_gdi_ctx_class_t *thiz);
 
277
static void set_job_spooling(sge_gdi_ctx_class_t *thiz, bool job_spooling);
 
278
static u_long32 get_listener_thread_count(sge_gdi_ctx_class_t *thiz);
 
279
static u_long32 get_worker_thread_count(sge_gdi_ctx_class_t *thiz);
 
280
static u_long32 get_scheduler_thread_count(sge_gdi_ctx_class_t *thiz);
 
281
static u_long32 get_jvm_thread_count(sge_gdi_ctx_class_t *thiz);
 
282
static const char* get_master(sge_gdi_ctx_class_t *thiz, bool reread);
 
283
static u_long32 get_sge_qmaster_port(sge_gdi_ctx_class_t *thiz);
 
284
static u_long32 get_sge_execd_port(sge_gdi_ctx_class_t *thiz);
 
285
static const char* get_spooling_method(sge_gdi_ctx_class_t *thiz);
 
286
static const char* get_spooling_lib(sge_gdi_ctx_class_t *thiz);
 
287
static const char* get_spooling_params(sge_gdi_ctx_class_t *thiz);
 
288
static const char* get_username(sge_gdi_ctx_class_t *thiz);
 
289
static const char* get_cell_root(sge_gdi_ctx_class_t *thiz);
 
290
static const char* get_sge_root(sge_gdi_ctx_class_t *thiz);
 
291
static const char* get_groupname(sge_gdi_ctx_class_t *thiz);
 
292
static uid_t ctx_get_uid(sge_gdi_ctx_class_t *thiz);
 
293
static gid_t ctx_get_gid(sge_gdi_ctx_class_t *thiz);
 
294
static const char* get_qualified_hostname(sge_gdi_ctx_class_t *thiz);
 
295
static const char* get_unqualified_hostname(sge_gdi_ctx_class_t *thiz);
 
296
static const char* get_default_cell(sge_gdi_ctx_class_t *thiz);
 
297
static const char* get_admin_user(sge_gdi_ctx_class_t *thiz);
 
298
static const char* get_binary_path(sge_gdi_ctx_class_t *thiz);
 
299
static const char* get_qmaster_spool_dir(sge_gdi_ctx_class_t *thiz);
 
300
static const char* get_bootstrap_file(sge_gdi_ctx_class_t *thiz);
 
301
static const char* get_act_qmaster_file(sge_gdi_ctx_class_t *thiz);
 
302
static const char* get_acct_file(sge_gdi_ctx_class_t *thiz);
 
303
static const char* get_reporting_file(sge_gdi_ctx_class_t *thiz);
 
304
static const char* get_shadow_master_file(sge_gdi_ctx_class_t *thiz);
 
305
static sge_exit_func_t get_exit_func(sge_gdi_ctx_class_t *thiz);
 
306
static void set_exit_func(sge_gdi_ctx_class_t *thiz, sge_exit_func_t exfunc);
 
307
static void set_private_key(sge_gdi_ctx_class_t *thiz, const char *pkey);
 
308
static void set_certificate(sge_gdi_ctx_class_t *thiz, const char *cert);
 
309
static const char* get_private_key(sge_gdi_ctx_class_t *thiz);
 
310
static const char* get_certificate(sge_gdi_ctx_class_t *thiz);
 
311
static int ctx_get_last_commlib_error(sge_gdi_ctx_class_t *thiz);
 
312
static void ctx_set_last_commlib_error(sge_gdi_ctx_class_t *thiz, int cl_error);
 
313
static bool ctx_is_qmaster_internal_client(sge_gdi_ctx_class_t *thiz);
 
314
 
 
315
static int sge_gdi_ctx_class_prepare_enroll(sge_gdi_ctx_class_t *thiz);
 
316
static int sge_gdi_ctx_class_connect(sge_gdi_ctx_class_t *thiz);
 
317
static int sge_gdi_ctx_class_is_alive(sge_gdi_ctx_class_t *thiz);
 
318
                  
 
319
static lList* sge_gdi_ctx_class_gdi_tsm(sge_gdi_ctx_class_t *thiz, const char *schedd_name, const char *cell);
 
320
static lList* sge_gdi_ctx_class_gdi_kill(sge_gdi_ctx_class_t *thiz, lList *id_list, const char *cell, 
 
321
                                          u_long32 option_flags, u_long32 action_flag);
 
322
static bool sge_gdi_ctx_class_gdi_get_mapping_name(sge_gdi_ctx_class_t *thiz, const char *requestedHost, char *buf, int buflen);
 
323
static bool sge_gdi_ctx_class_gdi_check_permission(sge_gdi_ctx_class_t *thiz, lList **alpp, int option);
 
324
 
 
325
static int sge_gdi_ctx_log_flush_func(cl_raw_list_t* list_p);
 
326
 
 
327
static void sge_gdi_ctx_class_dprintf(sge_gdi_ctx_class_t *ctx);
 
328
 
 
329
sge_gdi_ctx_class_t *
 
330
sge_gdi_ctx_class_create(int prog_number, const char *component_name, 
 
331
                         int thread_number, const char *thread_name,
 
332
                         const char *username, const char *groupname,
 
333
                         const char *sge_root, const char *sge_cell, 
 
334
                         int sge_qmaster_port, int sge_execd_port, 
 
335
                         bool from_services, bool is_qmaster_internal_client, 
 
336
                         lList **alpp)
 
337
{
 
338
   sge_gdi_ctx_class_t *ret = (sge_gdi_ctx_class_t *)sge_malloc(sizeof(sge_gdi_ctx_class_t));
 
339
   sge_gdi_ctx_t *gdi_ctx = NULL;
 
340
 
 
341
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_create");
 
342
 
 
343
   if (!ret) {
 
344
      answer_list_add_sprintf(alpp, STATUS_EMALLOC, 
 
345
                              ANSWER_QUALITY_ERROR, MSG_MEMORY_MALLOCFAILED);
 
346
      DRETURN(NULL);
 
347
   }
 
348
 
 
349
   if (is_qmaster_internal_client) {
 
350
      ret->sge_gdi_packet_execute = sge_gdi_packet_execute_internal; 
 
351
      ret->sge_gdi_packet_wait_for_result = sge_gdi_packet_wait_for_result_internal;
 
352
   } else {
 
353
      ret->sge_gdi_packet_execute = sge_gdi_packet_execute_external; 
 
354
      ret->sge_gdi_packet_wait_for_result = sge_gdi_packet_wait_for_result_external;
 
355
   }
 
356
   ret->gdi = sge_gdi2;
 
357
   ret->gdi_multi = sge_gdi2_multi;
 
358
   ret->gdi_wait = sge_gdi2_wait;
 
359
 
 
360
   ret->get_errors = sge_gdi_ctx_class_get_errors;
 
361
   ret->prepare_enroll = sge_gdi_ctx_class_prepare_enroll;
 
362
   ret->connect = sge_gdi_ctx_class_connect;
 
363
   ret->is_alive = sge_gdi_ctx_class_is_alive;
 
364
   ret->tsm = sge_gdi_ctx_class_gdi_tsm;
 
365
   ret->kill = sge_gdi_ctx_class_gdi_kill;
 
366
   ret->gdi_check_permission = sge_gdi_ctx_class_gdi_check_permission;
 
367
   ret->gdi_get_mapping_name = sge_gdi_ctx_class_gdi_get_mapping_name;
 
368
 
 
369
   ret->get_sge_env_state = get_sge_env_state;
 
370
   ret->get_sge_prog_state = get_sge_prog_state;
 
371
   ret->get_sge_path_state = get_sge_path_state;
 
372
   ret->get_sge_bootstrap_state = get_sge_bootstrap_state;
 
373
   ret->reresolve_qualified_hostname = reresolve_qualified_hostname;
 
374
   ret->get_component_name = get_component_name;
 
375
   ret->get_thread_name = get_thread_name;
 
376
   ret->get_progname = get_progname;
 
377
   ret->get_who = get_who;
 
378
   ret->is_daemonized = is_daemonized;
 
379
   ret->set_daemonized = set_daemonized;
 
380
   ret->get_job_spooling = get_job_spooling;
 
381
   ret->set_job_spooling = set_job_spooling;
 
382
   ret->get_listener_thread_count = get_listener_thread_count;
 
383
   ret->get_worker_thread_count = get_worker_thread_count;
 
384
   ret->get_scheduler_thread_count = get_scheduler_thread_count;
 
385
   ret->get_jvm_thread_count = get_jvm_thread_count;
 
386
   ret->get_qualified_hostname = get_qualified_hostname;
 
387
   ret->get_unqualified_hostname = get_unqualified_hostname;
 
388
   ret->get_master = get_master;
 
389
   ret->get_sge_qmaster_port = get_sge_qmaster_port;
 
390
   ret->get_sge_execd_port = get_sge_execd_port;
 
391
   ret->get_username = get_username;
 
392
   ret->get_spooling_method = get_spooling_method;
 
393
   ret->get_spooling_lib = get_spooling_lib;
 
394
   ret->get_spooling_params = get_spooling_params;
 
395
   ret->get_admin_user = get_admin_user;
 
396
   ret->get_binary_path = get_binary_path;
 
397
   ret->get_qmaster_spool_dir = get_qmaster_spool_dir;
 
398
   ret->get_bootstrap_file = get_bootstrap_file;
 
399
   ret->get_act_qmaster_file = get_act_qmaster_file;
 
400
   ret->get_acct_file = get_acct_file;
 
401
   ret->get_reporting_file = get_reporting_file;
 
402
   ret->get_shadow_master_file = get_shadow_master_file;
 
403
   ret->get_default_cell = get_default_cell;
 
404
   ret->get_cell_root = get_cell_root;
 
405
   ret->get_sge_root = get_sge_root;
 
406
   ret->get_groupname = get_groupname;
 
407
   ret->get_uid = ctx_get_uid;
 
408
   ret->get_gid = ctx_get_gid;   
 
409
   ret->get_com_handle = get_com_handle;   
 
410
 
 
411
   ret->set_exit_func = set_exit_func;
 
412
   ret->get_exit_func = get_exit_func;
 
413
 
 
414
   ret->set_private_key = set_private_key;
 
415
   ret->set_certificate = set_certificate;
 
416
   ret->get_private_key = get_private_key;
 
417
   ret->get_certificate = get_certificate;
 
418
   ret->get_ca_root = get_ca_root;
 
419
   ret->get_ca_local_root = get_ca_local_root;
 
420
   ret->is_qmaster_internal_client = ctx_is_qmaster_internal_client;
 
421
 
 
422
   ret->dprintf = sge_gdi_ctx_class_dprintf;
 
423
 
 
424
   ret->sge_gdi_ctx_handle = (sge_gdi_ctx_t*)sge_malloc(sizeof(sge_gdi_ctx_t));
 
425
   memset(ret->sge_gdi_ctx_handle, 0, sizeof(sge_gdi_ctx_t));
 
426
 
 
427
   if (!ret->sge_gdi_ctx_handle) {
 
428
      answer_list_add_sprintf(alpp, STATUS_EMALLOC, 
 
429
                              ANSWER_QUALITY_ERROR, MSG_MEMORY_MALLOCFAILED);
 
430
      sge_gdi_ctx_class_destroy(&ret);
 
431
      DRETURN(NULL);
 
432
   }
 
433
 
 
434
   /*
 
435
   ** create error handler of context
 
436
   */
 
437
   gdi_ctx = (sge_gdi_ctx_t*)ret->sge_gdi_ctx_handle;
 
438
   gdi_ctx->eh = sge_error_class_create();
 
439
   if (!gdi_ctx->eh) {
 
440
      answer_list_add_sprintf(alpp, STATUS_EMALLOC, 
 
441
                              ANSWER_QUALITY_ERROR, MSG_MEMORY_MALLOCFAILED);
 
442
      DRETURN(NULL);
 
443
   }
 
444
 
 
445
 
 
446
   if (!sge_gdi_ctx_setup(ret, prog_number, component_name, thread_number, thread_name, 
 
447
                          username, groupname, sge_root, sge_cell, sge_qmaster_port, 
 
448
                          sge_execd_port, from_services, is_qmaster_internal_client)) {
 
449
      sge_gdi_ctx_class_get_errors(ret, alpp, true);
 
450
      sge_gdi_ctx_class_destroy(&ret);
 
451
      DRETURN(NULL);
 
452
   }
 
453
 
 
454
   /*
 
455
   ** set default exit func, maybe overwritten
 
456
   */
 
457
   ret->set_exit_func(ret, gdi2_default_exit_func);
 
458
 
 
459
   DRETURN(ret);
 
460
}
 
461
 
 
462
void sge_gdi_ctx_class_destroy(sge_gdi_ctx_class_t **pst)
 
463
{
 
464
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_destroy");
 
465
 
 
466
   if (!pst || !*pst) {
 
467
      DRETURN_VOID;
 
468
   }   
 
469
      
 
470
   /* free internal context structure */   
 
471
   sge_gdi_ctx_destroy((*pst)->sge_gdi_ctx_handle);
 
472
   FREE(*pst);
 
473
   *pst = NULL;
 
474
 
 
475
   DRETURN_VOID;
 
476
}
 
477
 
 
478
static void sge_gdi_ctx_class_get_errors(sge_gdi_ctx_class_t *thiz, lList **alpp, bool clear_errors)
 
479
{
 
480
   sge_gdi_ctx_t *gdi_ctx = NULL;
 
481
 
 
482
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_get_errors");
 
483
 
 
484
   if (!thiz || !thiz->sge_gdi_ctx_handle) {
 
485
      DRETURN_VOID;
 
486
   }   
 
487
   
 
488
   gdi_ctx = (sge_gdi_ctx_t*)thiz->sge_gdi_ctx_handle;
 
489
      
 
490
   sge_error_to_answer_list(gdi_ctx->eh, alpp, clear_errors);
 
491
 
 
492
   DRETURN_VOID;
 
493
}
 
494
 
 
495
static void sge_gdi_ctx_class_error(sge_gdi_ctx_class_t *thiz, int error_type, int error_quality, const char* fmt, ...)
 
496
{
 
497
   sge_gdi_ctx_t *gdi_ctx = NULL;
 
498
 
 
499
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_error");
 
500
 
 
501
   if (!thiz || !thiz->sge_gdi_ctx_handle) {
 
502
      DRETURN_VOID;
 
503
   }   
 
504
   
 
505
   gdi_ctx = (sge_gdi_ctx_t*)thiz->sge_gdi_ctx_handle;
 
506
      
 
507
   if (gdi_ctx->eh) {
 
508
      if (fmt != NULL) {
 
509
         va_list arg_list;
 
510
         va_start(arg_list, fmt);
 
511
         gdi_ctx->eh->verror(gdi_ctx->eh, error_type, error_quality, fmt, arg_list);
 
512
      }
 
513
   }   
 
514
 
 
515
   DRETURN_VOID;
 
516
}
 
517
 
 
518
static void sge_gdi_ctx_set_is_setup(sge_gdi_ctx_class_t *thiz, bool is_setup)
 
519
{
 
520
   sge_gdi_ctx_t *gdi_ctx = NULL;
 
521
 
 
522
   DENTER(TOP_LAYER, "sge_gdi_ctx_set_is_setup");
 
523
 
 
524
   if (!thiz || !thiz->sge_gdi_ctx_handle) {
 
525
      DRETURN_VOID;
 
526
   }   
 
527
   
 
528
   gdi_ctx = (sge_gdi_ctx_t*)thiz->sge_gdi_ctx_handle;
 
529
      
 
530
   gdi_ctx->is_setup = is_setup;
 
531
 
 
532
   DRETURN_VOID;
 
533
}
 
534
 
 
535
 
 
536
static bool sge_gdi_ctx_is_setup(sge_gdi_ctx_class_t *thiz)
 
537
{
 
538
   sge_gdi_ctx_t *gdi_ctx = NULL;
 
539
 
 
540
   DENTER(TOP_LAYER, "sge_gdi_ctx_is_setup");
 
541
 
 
542
   if (!thiz || !thiz->sge_gdi_ctx_handle) {
 
543
      DRETURN(false);
 
544
   }   
 
545
   
 
546
   gdi_ctx = (sge_gdi_ctx_t*)thiz->sge_gdi_ctx_handle;
 
547
 
 
548
   DRETURN(gdi_ctx->is_setup);
 
549
}
 
550
 
 
551
 
 
552
static bool 
 
553
sge_gdi_ctx_setup(sge_gdi_ctx_class_t *thiz, int prog_number, const char* component_name,
 
554
                  int thread_number, const char *thread_name, const char* username, 
 
555
                  const char *groupname, const char *sge_root, const char *sge_cell, 
 
556
                  int sge_qmaster_port, int sge_execd_port, bool from_services,
 
557
                  bool qmaster_internal_client)
 
558
{
 
559
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *)thiz->sge_gdi_ctx_handle;
 
560
   sge_error_class_t *eh = es->eh;
 
561
 
 
562
   DENTER(TOP_LAYER, "sge_gdi_ctx_setup");
 
563
 
 
564
   /*
 
565
    * Call all functions which have to be called once for each process.
 
566
    * Those functions will then be called when the first thread of a process
 
567
    * creates its context. 
 
568
    */
 
569
   prof_mt_init();
 
570
   feature_mt_init();
 
571
   gdi_mt_init();
 
572
   sc_mt_init();
 
573
   obj_mt_init();
 
574
   bootstrap_mt_init();
 
575
   sc_mt_init();
 
576
   uidgid_mt_init();
 
577
   path_mt_init();
 
578
   
 
579
 
 
580
   /* TODO: shall we do that here ? */
 
581
   lInit(nmv);
 
582
 
 
583
   es->is_qmaster_internal_client = qmaster_internal_client;
 
584
 
 
585
   es->sge_env_state_obj = sge_env_state_class_create(sge_root, sge_cell, sge_qmaster_port, sge_execd_port, from_services, qmaster_internal_client, eh);
 
586
   if (!es->sge_env_state_obj) {
 
587
      DRETURN(false);
 
588
   }   
 
589
 
 
590
   es->sge_prog_state_obj = sge_prog_state_class_create(es->sge_env_state_obj, prog_number, eh);
 
591
   if (!es->sge_prog_state_obj) {
 
592
      DRETURN(false);
 
593
   }   
 
594
 
 
595
   es->sge_path_state_obj = sge_path_state_class_create(es->sge_env_state_obj, eh);
 
596
   if (!es->sge_path_state_obj) {
 
597
      DRETURN(false);
 
598
   }
 
599
 
 
600
   es->sge_bootstrap_state_obj = sge_bootstrap_state_class_create(es->sge_path_state_obj, eh);
 
601
   if (!es->sge_bootstrap_state_obj) {
 
602
      DRETURN(false);
 
603
   }
 
604
   
 
605
   if (feature_initialize_from_string(es->sge_bootstrap_state_obj->get_security_mode(es->sge_bootstrap_state_obj))) {
 
606
      DRETURN(false);
 
607
   }   
 
608
   
 
609
   es->sge_csp_path_obj = sge_csp_path_class_create(es->sge_env_state_obj, es->sge_prog_state_obj, eh);
 
610
   if (!es->sge_csp_path_obj) {
 
611
      DRETURN(false);
 
612
   }   
 
613
 
 
614
   if (component_name == NULL) {
 
615
      es->component_name = strdup(prognames[prog_number]);
 
616
   } else {
 
617
      es->component_name = strdup(component_name);
 
618
   }
 
619
 
 
620
   if (thread_name == NULL) {
 
621
      es->thread_name = strdup(prognames[prog_number]);
 
622
   } else {
 
623
      es->thread_name = strdup(thread_name);
 
624
   }
 
625
   
 
626
   /* set uid and gid */
 
627
   {      
 
628
      struct passwd *pwd;
 
629
      struct passwd pw_struct;
 
630
      char *buffer;
 
631
      int size;
 
632
 
 
633
      size = get_pw_buffer_size();
 
634
      buffer = sge_malloc(size);
 
635
      pwd = sge_getpwnam_r(username, &pw_struct, buffer, size);
 
636
 
 
637
      if (!pwd) {
 
638
         eh->error(eh, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, "sge_getpwnam_r failed for username %s", username);
 
639
         FREE(buffer);
 
640
         DRETURN(false);
 
641
      }
 
642
      es->uid = pwd->pw_uid;
 
643
      if (groupname != NULL) {
 
644
         gid_t gid;
 
645
         if (sge_group2gid(groupname, &gid, MAX_NIS_RETRIES) == 1) {
 
646
            eh->error(eh, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, "sge_group2gid failed for groupname %s", groupname);
 
647
            FREE(buffer);
 
648
            DRETURN(false);
 
649
         }
 
650
         es->gid = gid;
 
651
      } else {
 
652
         es->gid = pwd->pw_gid;
 
653
      }
 
654
 
 
655
      FREE(buffer);
 
656
   }
 
657
   
 
658
   es->username = strdup(username);
 
659
 
 
660
#if defined( INTERIX )
 
661
   /* Strip Windows domain name from user name */
 
662
   {
 
663
      char *plus_sign;
 
664
 
 
665
      plus_sign = strstr(es->username, "+");
 
666
      if (plus_sign!=NULL) {
 
667
         plus_sign++;
 
668
         strcpy(es->username, plus_sign);
 
669
      }
 
670
   }
 
671
#endif
 
672
   
 
673
   /*
 
674
   ** groupname
 
675
   */
 
676
   if (groupname != NULL) {
 
677
      es->groupname = strdup(groupname);
 
678
   } else {   
 
679
      if (_sge_gid2group(es->gid, &(es->gid), &(es->groupname), MAX_NIS_RETRIES)) {
 
680
         eh->error(eh, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, MSG_GDI_GETGRGIDXFAILEDERRORX_U, sge_u32c(es->gid));
 
681
         DRETURN(false);
 
682
      }
 
683
   }
 
684
 
 
685
   /*
 
686
   ** set the component_username and check if login is needed
 
687
   */
 
688
   {
 
689
      struct passwd *pwd = NULL;
 
690
      char *buffer;
 
691
      int size;
 
692
      struct passwd pwentry;
 
693
 
 
694
      size = get_pw_buffer_size();
 
695
      buffer = sge_malloc(size);
 
696
      if (getpwuid_r((uid_t)getuid(), &pwentry, buffer, size, &pwd) == 0) {
 
697
         es->component_username = sge_strdup(es->component_username, pwd->pw_name);
 
698
         FREE(buffer);
 
699
      } else {
 
700
         eh->error(eh, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, "getpwuid_r failed");
 
701
         FREE(buffer);
 
702
         DRETURN(false);
 
703
      }
 
704
#if 0
 
705
      /*
 
706
      ** TODO: Login to system somehow and send something like a token with request
 
707
      **       similar like the secret key in CSP mode
 
708
      */
 
709
      DPRINTF(("es->username: '%s', es->component_username: '%s'\n", es->username, es->component_username));      
 
710
      if (strcmp(es->username, es->component_username) != 0) {
 
711
#if 1      
 
712
         eh->error(eh, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, "!!!! Alert login needed !!!!!");
 
713
         DRETURN(false);
 
714
#else
 
715
         eh->error(eh, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, "!!!! First time login !!!!!");
 
716
/*          sge_authenticate(es->username, callback_handler); */
 
717
         
 
718
#endif
 
719
      }
 
720
#endif
 
721
   }    
 
722
 
 
723
   DRETURN(true);
 
724
}
 
725
 
 
726
sge_gdi_ctx_class_t *
 
727
sge_gdi_ctx_class_create_from_bootstrap(int prog_number, const char* component_name,
 
728
                                        int thread_number, const char *thread_name,
 
729
                                        const char* url, const char* username, lList **alpp)
 
730
{
 
731
   char sge_root[BUFSIZ];
 
732
   char sge_cell[BUFSIZ];
 
733
   char sge_qmaster_port[BUFSIZ];
 
734
   char *token = NULL;
 
735
   char sge_url[BUFSIZ];
 
736
   
 
737
   struct  saved_vars_s *url_ctx = NULL;
 
738
   int sge_qmaster_p = 0;
 
739
   int sge_execd_p = 0;
 
740
   bool is_qmaster_internal_client = false;
 
741
 
 
742
   sge_gdi_ctx_class_t * ret = NULL;
 
743
   
 
744
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_create_from_bootstrap");
 
745
 
 
746
   /* determine the connection type: local/remote */
 
747
   if (!strncmp(url, "internal://", (sizeof("internal://")-1))) {
 
748
      DPRINTF(("**** Using internal context for %s ****\n", component_name));   
 
749
      is_qmaster_internal_client = true;
 
750
   }
 
751
   
 
752
   /* parse the url */
 
753
   DPRINTF(("url = %s\n", url));
 
754
   if (is_qmaster_internal_client) {
 
755
      sscanf(url, "internal://%s", sge_url);
 
756
   } else {
 
757
      sscanf(url, "bootstrap://%s", sge_url);
 
758
   }
 
759
   DPRINTF(("sge_url = %s\n", sge_url));
 
760
   
 
761
   /* search for sge_root */
 
762
   token = sge_strtok_r(sge_url, "@", &url_ctx);   
 
763
   if (token == NULL ) {
 
764
      answer_list_add_sprintf(alpp, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, "invalid url, sge_root not found");
 
765
      sge_free_saved_vars(url_ctx);
 
766
      DRETURN(NULL);
 
767
   }   
 
768
   strcpy(sge_root, token);
 
769
   
 
770
   /* search for sge_cell */
 
771
   token = sge_strtok_r(NULL, ":", &url_ctx);
 
772
   
 
773
   if (token == NULL ) {
 
774
      answer_list_add_sprintf(alpp, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, "invalid url, sge_cell not found");
 
775
      sge_free_saved_vars(url_ctx);
 
776
      DRETURN(NULL);
 
777
   }
 
778
   strcpy(sge_cell, token);
 
779
   
 
780
   /* get the qmaster port */
 
781
   token = sge_strtok_r(NULL, NULL, &url_ctx);
 
782
 
 
783
   if (token == NULL ) {
 
784
      answer_list_add_sprintf(alpp, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, "invalid url, qmaster_port not found");
 
785
      sge_free_saved_vars(url_ctx);
 
786
      DRETURN(NULL);
 
787
   }
 
788
   strcpy(sge_qmaster_port, token);
 
789
   
 
790
   sge_qmaster_p = atoi(sge_qmaster_port);
 
791
   
 
792
   if (sge_qmaster_p <= 0 ) {
 
793
      answer_list_add_sprintf(alpp, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, "invalid url, invalid sge_qmaster_port port %s", sge_qmaster_port);
 
794
      sge_free_saved_vars(url_ctx);
 
795
      DRETURN(NULL);
 
796
   }
 
797
 
 
798
   sge_free_saved_vars(url_ctx);
 
799
   
 
800
   /* TODO we need a way to define the execd port, from_services is always false (certs from keystore) */
 
801
   
 
802
   ret = sge_gdi_ctx_class_create(prog_number, component_name, thread_number, thread_name,
 
803
                                  username, NULL, sge_root, sge_cell, sge_qmaster_p, sge_execd_p, 
 
804
                                  false, is_qmaster_internal_client, alpp);
 
805
   
 
806
   DRETURN(ret); 
 
807
}
 
808
 
 
809
 
 
810
static void sge_gdi_ctx_destroy(void *theState)
 
811
{
 
812
   sge_gdi_ctx_t *s = (sge_gdi_ctx_t *)theState;
 
813
 
 
814
   DENTER(TOP_LAYER, "sge_gdi_ctx_destroy");
 
815
 
 
816
   sge_env_state_class_destroy(&(s->sge_env_state_obj));
 
817
   sge_prog_state_class_destroy(&(s->sge_prog_state_obj));
 
818
   sge_path_state_class_destroy(&(s->sge_path_state_obj));
 
819
   sge_bootstrap_state_class_destroy(&(s->sge_bootstrap_state_obj));
 
820
   sge_csp_path_class_destroy(&(s->sge_csp_path_obj));
 
821
   sge_free(s->master);
 
822
   sge_free(s->username);
 
823
   sge_free(s->groupname);
 
824
   sge_free(s->component_name);
 
825
   sge_free(s->thread_name);
 
826
   sge_free(s->component_username);
 
827
   sge_free(s->ssl_certificate);
 
828
   sge_free(s->ssl_private_key);
 
829
   sge_error_class_destroy(&(s->eh));
 
830
   sge_free((char*)s);
 
831
 
 
832
   DRETURN_VOID;
 
833
}
 
834
 
 
835
static int sge_gdi_ctx_class_connect(sge_gdi_ctx_class_t *thiz) 
 
836
{
 
837
   
 
838
   int ret = 0;
 
839
   bool is_alive_check = true;
 
840
   
 
841
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_connect");
 
842
   
 
843
   /*
 
844
   ** TODO: must contain similar functionality as sge_gdi_setup
 
845
   */
 
846
 
 
847
   ret = sge_gdi_ctx_class_prepare_enroll(thiz);
 
848
 
 
849
   /* check if master is alive */
 
850
   if (ret == CL_RETVAL_OK && is_alive_check) {
 
851
      const char *master = thiz->get_master(thiz, true);
 
852
      DPRINTF(("thiz->get_master(thiz) = %s\n", master)); 
 
853
      ret = thiz->is_alive(thiz);
 
854
   }
 
855
 
 
856
   DRETURN(ret);
 
857
}
 
858
 
 
859
static int sge_gdi_ctx_class_prepare_enroll(sge_gdi_ctx_class_t *thiz) {
 
860
   
 
861
   sge_path_state_class_t* path_state = thiz->get_sge_path_state(thiz);
 
862
   sge_bootstrap_state_class_t * bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
863
   cl_host_resolve_method_t resolve_method = CL_SHORT;
 
864
   cl_framework_t  communication_framework = CL_CT_TCP;
 
865
   cl_com_handle_t* handle = NULL;
 
866
   const char *help = NULL;
 
867
   const char *default_domain = NULL;
 
868
   int cl_ret = CL_RETVAL_OK;
 
869
   
 
870
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_prepare_enroll");
 
871
 
 
872
   /* context setup is complete => setup the commlib
 
873
   ** TODO:
 
874
   ** there is a problem in qsub if it is used with CL_RW_THREAD, the signaling in qsub -sync
 
875
   ** makes qsub hang
 
876
   */
 
877
   
 
878
   if (cl_com_setup_commlib_complete() == CL_FALSE) {
 
879
      switch (thiz->get_who(thiz)) {
 
880
         case QMASTER:
 
881
         case QMON:
 
882
         case DRMAA:
 
883
         case JGDI:
 
884
         case SCHEDD:
 
885
         case EXECD:
 
886
            INFO((SGE_EVENT,MSG_GDI_MULTI_THREADED_STARTUP));
 
887
            cl_ret = cl_com_setup_commlib(CL_RW_THREAD, CL_LOG_OFF, sge_gdi_ctx_log_flush_func);
 
888
            break;
 
889
         default:
 
890
            INFO((SGE_EVENT,MSG_GDI_SINGLE_THREADED_STARTUP));
 
891
            cl_ret = cl_com_setup_commlib(CL_NO_THREAD, CL_LOG_OFF, sge_gdi_ctx_log_flush_func);
 
892
            /*
 
893
            ** verbose logging is switched on by default
 
894
            */
 
895
            log_state_set_log_verbose(1);
 
896
      }
 
897
      if (cl_ret != CL_RETVAL_OK) {
 
898
         sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, 
 
899
                            "cl_com_setup_commlib failed: %s", cl_get_error_text(cl_ret));
 
900
         DRETURN(cl_ret);
 
901
      }
 
902
   }
 
903
 
 
904
   /* set the alias file */
 
905
   cl_ret = cl_com_set_alias_file((char*)path_state->get_alias_file(path_state));
 
906
   if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) {
 
907
      sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, 
 
908
                         "cl_com_set_alias_file failed: %s", cl_get_error_text(cl_ret));
 
909
      DRETURN(cl_ret);
 
910
   }
 
911
 
 
912
   /* setup the resolve method */
 
913
      
 
914
   if( bootstrap_state->get_ignore_fqdn(bootstrap_state) == false ) {
 
915
      resolve_method = CL_LONG;
 
916
   }
 
917
   if ((help = bootstrap_state->get_default_domain(bootstrap_state)) != NULL) {
 
918
      if (SGE_STRCASECMP(help, NONE_STR) != 0) {
 
919
         default_domain = help;
 
920
      }
 
921
   }
 
922
   
 
923
   cl_ret = cl_com_set_resolve_method(resolve_method, (char*)default_domain);
 
924
   if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) {
 
925
      sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, 
 
926
                         "cl_com_set_resolve_method failed: %s", cl_get_error_text(cl_ret));
 
927
      DRETURN(cl_ret);
 
928
   }
 
929
 
 
930
   /*
 
931
   ** reresolve qualified hostname with use of host aliases 
 
932
   ** (corresponds to reresolve_me_qualified_hostname)
 
933
   */
 
934
   cl_ret = thiz->reresolve_qualified_hostname(thiz);
 
935
   if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) { 
 
936
      sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_WARNING, 
 
937
                         "reresolve hostname failed: %s", cl_get_error_text(cl_ret));
 
938
      DRETURN(cl_ret);
 
939
   } 
 
940
   
 
941
   
 
942
   /* 
 
943
   ** TODO set a general_communication_error  
 
944
   */
 
945
   cl_ret = cl_com_set_error_func(general_communication_error);
 
946
   if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) {
 
947
      sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, 
 
948
                         "cl_com_set_error_func failed: %s", cl_get_error_text(cl_ret));
 
949
      DRETURN(cl_ret);
 
950
   }
 
951
   
 
952
   /* TODO set tag name function */
 
953
   cl_ret = cl_com_set_tag_name_func(sge_dump_message_tag);
 
954
   if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) {
 
955
      sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, 
 
956
                         "cl_com_set_tag_name_func failed: %s", cl_get_error_text(cl_ret));
 
957
      DRETURN(cl_ret);
 
958
   }
 
959
   
 
960
#ifdef DEBUG_CLIENT_SUPPORT
 
961
   /* set debug client callback function to rmon's debug client callback */
 
962
   cl_ret = cl_com_set_application_debug_client_callback_func(rmon_debug_client_callback);
 
963
   if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) {
 
964
      sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, 
 
965
                         "cl_com_set_application_debug_client_callback_func failed: %s", cl_get_error_text(cl_ret));
 
966
      DRETURN(cl_ret);
 
967
   }
 
968
#endif
 
969
 
 
970
   handle = thiz->get_com_handle(thiz);
 
971
   if (handle == NULL) {
 
972
      /* handle does not exist, create one */
 
973
      
 
974
      int me_who = thiz->get_who(thiz);
 
975
      const char *progname = thiz->get_progname(thiz);
 
976
      const char *master = thiz->get_master(thiz, true);
 
977
      const char *qualified_hostname = thiz->get_qualified_hostname(thiz);
 
978
      u_long32 sge_qmaster_port = thiz->get_sge_qmaster_port(thiz); /* TODO: reresolving of port from /etc/services etc. */
 
979
      u_long32 sge_execd_port = thiz->get_sge_execd_port(thiz);
 
980
      int my_component_id = 0; /* 1 for daemons, 0=automatical for clients */
 
981
      
 
982
      if (master == NULL && !(me_who == QMASTER)) { 
 
983
         DRETURN(CL_RETVAL_UNKNOWN);
 
984
      }    
 
985
 
 
986
      /*
 
987
      ** CSP initialize
 
988
      */
 
989
      if (strcasecmp(bootstrap_state->get_security_mode(bootstrap_state), "csp") == 0) {
 
990
         cl_ssl_setup_t *sec_ssl_setup_config = NULL;
 
991
         cl_ssl_cert_mode_t ssl_cert_mode = CL_SSL_PEM_FILE;
 
992
         sge_csp_path_class_t *sge_csp = get_sge_csp_path(thiz);
 
993
 
 
994
         if (thiz->get_certificate(thiz) != NULL) {
 
995
            ssl_cert_mode = CL_SSL_PEM_BYTE;
 
996
            sge_csp->set_cert_file(sge_csp, thiz->get_certificate(thiz));
 
997
            sge_csp->set_key_file(sge_csp, thiz->get_private_key(thiz));
 
998
         }   
 
999
         sge_csp->dprintf(sge_csp);
 
1000
 
 
1001
         communication_framework = CL_CT_SSL;
 
1002
         cl_ret = cl_com_create_ssl_setup(&sec_ssl_setup_config,
 
1003
                                       ssl_cert_mode,
 
1004
                                       CL_SSL_v23,                                   /* ssl_method           */
 
1005
                                       (char*)sge_csp->get_CA_cert_file(sge_csp),    /* ssl_CA_cert_pem_file */
 
1006
                                       (char*)sge_csp->get_CA_key_file(sge_csp),     /* ssl_CA_key_pem_file  */
 
1007
                                       (char*)sge_csp->get_cert_file(sge_csp),       /* ssl_cert_pem_file    */
 
1008
                                       (char*)sge_csp->get_key_file(sge_csp),        /* ssl_key_pem_file     */
 
1009
                                       (char*)sge_csp->get_rand_file(sge_csp),       /* ssl_rand_file        */
 
1010
                                       (char*)sge_csp->get_reconnect_file(sge_csp),  /* ssl_reconnect_file   */
 
1011
                                       (char*)sge_csp->get_crl_file(sge_csp),        /* ssl_crl_file         */
 
1012
                                       sge_csp->get_refresh_time(sge_csp),           /* ssl_refresh_time     */
 
1013
                                       (char*)sge_csp->get_password(sge_csp),        /* ssl_password         */
 
1014
                                       sge_csp->get_verify_func(sge_csp));           /* ssl_verify_func (cl_ssl_verify_func_t)  */
 
1015
         if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) {
 
1016
            DPRINTF(("return value of cl_com_create_ssl_setup(): %s\n", cl_get_error_text(cl_ret)));
 
1017
            sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, MSG_GDI_CANT_CONNECT_HANDLE_SSUUS, 
 
1018
                               qualified_hostname,
 
1019
                               progname, 0, 
 
1020
                               sge_qmaster_port,
 
1021
                               cl_get_error_text(cl_ret));
 
1022
            DRETURN(cl_ret);
 
1023
         }
 
1024
 
 
1025
         /*
 
1026
         ** set the CSP credential info into commlib
 
1027
         */
 
1028
         cl_ret = cl_com_specify_ssl_configuration(sec_ssl_setup_config);
 
1029
         if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) {
 
1030
            DPRINTF(("return value of cl_com_specify_ssl_configuration(): %s\n", cl_get_error_text(cl_ret)));
 
1031
            sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, MSG_GDI_CANT_CONNECT_HANDLE_SSUUS, 
 
1032
                               (char*)thiz->get_component_name(thiz), 0,
 
1033
                               sge_qmaster_port,
 
1034
                               cl_get_error_text(cl_ret));
 
1035
            cl_com_free_ssl_setup(&sec_ssl_setup_config);
 
1036
            DRETURN(cl_ret);
 
1037
         }
 
1038
         cl_com_free_ssl_setup(&sec_ssl_setup_config);
 
1039
      }
 
1040
 
 
1041
      if ( me_who == QMASTER ||
 
1042
           me_who == EXECD   ||
 
1043
           me_who == SCHEDD  || 
 
1044
           me_who == SHADOWD ) {
 
1045
         my_component_id = 1;   
 
1046
      }
 
1047
 
 
1048
      switch (me_who) {
 
1049
 
 
1050
         case EXECD:
 
1051
            /* add qmaster as known endpoint */
 
1052
            DPRINTF(("re-read actual qmaster file (prepare_enroll)\n"));
 
1053
            cl_com_append_known_endpoint_from_name((char*)master, 
 
1054
                                                   (char*)prognames[QMASTER],
 
1055
                                                   1 ,
 
1056
                                                   sge_qmaster_port,
 
1057
                                                   CL_CM_AC_DISABLED ,
 
1058
                                                   CL_TRUE);
 
1059
            handle = cl_com_create_handle(&cl_ret, 
 
1060
                                          communication_framework, 
 
1061
                                          CL_CM_CT_MESSAGE, 
 
1062
                                          CL_TRUE,
 
1063
                                          sge_execd_port, 
 
1064
                                          CL_TCP_DEFAULT,
 
1065
                                          (char*)thiz->get_component_name(thiz),
 
1066
                                          my_component_id, 
 
1067
                                          1, 
 
1068
                                          0);
 
1069
            cl_com_set_auto_close_mode(handle, CL_CM_AC_ENABLED);
 
1070
            if (handle == NULL) {
 
1071
               if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) {
 
1072
                  /*
 
1073
                  ** TODO: eh error handler does no logging
 
1074
                  */
 
1075
                  ERROR((SGE_EVENT, MSG_GDI_CANT_GET_COM_HANDLE_SSUUS, 
 
1076
                                    qualified_hostname,
 
1077
                                    (char*)thiz->get_component_name(thiz),
 
1078
                                    sge_u32c(my_component_id), 
 
1079
                                    sge_u32c(sge_execd_port),
 
1080
                                    cl_get_error_text(cl_ret)));
 
1081
               }
 
1082
            }
 
1083
            break;
 
1084
 
 
1085
         case QMASTER:
 
1086
            DPRINTF(("creating QMASTER handle\n"));
 
1087
            cl_com_append_known_endpoint_from_name((char*)master, 
 
1088
                                                   (char*) prognames[QMASTER],
 
1089
                                                   1,
 
1090
                                                   sge_qmaster_port,
 
1091
                                                   CL_CM_AC_DISABLED ,
 
1092
                                                   CL_TRUE);
 
1093
 
 
1094
            /* do a later qmaster commlib listen before creating qmaster handle */
 
1095
            /* TODO: CL_COMMLIB_DELAYED_LISTEN is set to CL_FALSE, because
 
1096
                     enabling it might cause problems with current shadowd and
 
1097
                     startup qmaster implementation */
 
1098
            cl_commlib_set_global_param(CL_COMMLIB_DELAYED_LISTEN, CL_FALSE);
 
1099
 
 
1100
            handle = cl_com_create_handle(&cl_ret, 
 
1101
                                          communication_framework, 
 
1102
                                          CL_CM_CT_MESSAGE, /* message based tcp communication */
 
1103
                                          CL_TRUE, 
 
1104
                                          sge_qmaster_port, /* create service on qmaster port */
 
1105
                                          CL_TCP_DEFAULT,   /* use standard connect mode */
 
1106
                                          (char*)thiz->get_component_name(thiz), 
 
1107
                                          my_component_id,  /* this endpoint is called "qmaster" 
 
1108
                                                               and has id 1 */
 
1109
                                          1, 
 
1110
                                          0); /* select timeout is set to 1 second 0 usec */
 
1111
            if (handle == NULL) {
 
1112
               if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) {   
 
1113
                  /*
 
1114
                  ** TODO: eh error handler does no logging
 
1115
                  */
 
1116
                  ERROR((SGE_EVENT, MSG_GDI_CANT_GET_COM_HANDLE_SSUUS, 
 
1117
                                       qualified_hostname,
 
1118
                                       (char*)thiz->get_component_name(thiz),
 
1119
                                       sge_u32c(my_component_id), 
 
1120
                                       sge_u32c(sge_qmaster_port),
 
1121
                                       cl_get_error_text(cl_ret)));
 
1122
               }
 
1123
            } else {
 
1124
               /* TODO: remove reresolving here */
 
1125
               int alive_back = 0;
 
1126
               char act_resolved_qmaster_name[CL_MAXHOSTLEN]; 
 
1127
               cl_com_set_synchron_receive_timeout(handle, 5);
 
1128
               /* TODO: reresolve master */
 
1129
               master = thiz->get_master(thiz, true);
 
1130
               
 
1131
               if (master != NULL) {
 
1132
                  /* TODO: sge_hostcmp uses implicitly bootstrap state info */
 
1133
                  /* check a running qmaster on different host */
 
1134
                  if (getuniquehostname(master, act_resolved_qmaster_name, 0) == CL_RETVAL_OK &&
 
1135
                        sge_hostcmp(act_resolved_qmaster_name, qualified_hostname) != 0) {
 
1136
                     DPRINTF(("act_qmaster file contains host "SFQ" which doesn't match local host name "SFQ"\n",
 
1137
                              master, qualified_hostname));
 
1138
 
 
1139
                     cl_com_set_error_func(NULL);
 
1140
 
 
1141
                     alive_back = thiz->is_alive(thiz);
 
1142
                     cl_ret = cl_com_set_error_func(general_communication_error);
 
1143
                     if (cl_ret != CL_RETVAL_OK) {
 
1144
                        ERROR((SGE_EVENT, cl_get_error_text(cl_ret)) );
 
1145
                     }
 
1146
 
 
1147
                     if (alive_back == CL_RETVAL_OK && getenv("SGE_TEST_HEARTBEAT_TIMEOUT") == NULL ) {
 
1148
                        CRITICAL((SGE_EVENT, MSG_GDI_MASTER_ON_HOST_X_RUNINNG_TERMINATE_S, master));
 
1149
                        /* TODO: remove !!! */
 
1150
                        SGE_EXIT(NULL, 1);
 
1151
                     } else {
 
1152
                        DPRINTF(("qmaster on host "SFQ" is down\n", master));
 
1153
                     }
 
1154
                  } else {
 
1155
                     DPRINTF(("act_qmaster file contains local host name\n"));
 
1156
                  }
 
1157
               } else {
 
1158
                  DPRINTF(("skipping qmaster alive check because act_qmaster is not availabe\n"));
 
1159
               }
 
1160
            }
 
1161
            break;
 
1162
 
 
1163
         case QMON:
 
1164
            DPRINTF(("creating QMON GDI handle\n"));
 
1165
            handle = cl_com_create_handle(&cl_ret, 
 
1166
                                          communication_framework, 
 
1167
                                          CL_CM_CT_MESSAGE, 
 
1168
                                          CL_FALSE, 
 
1169
                                          sge_qmaster_port, 
 
1170
                                          CL_TCP_DEFAULT,
 
1171
                                          (char*)thiz->get_component_name(thiz), 
 
1172
                                          my_component_id, 
 
1173
                                          1, 
 
1174
                                          0);
 
1175
            cl_com_set_auto_close_mode(handle, CL_CM_AC_ENABLED);
 
1176
            if (handle == NULL) {
 
1177
               if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) {
 
1178
                  ERROR((SGE_EVENT, MSG_GDI_CANT_CONNECT_HANDLE_SSUUS, 
 
1179
                                       qualified_hostname,
 
1180
                                       (char*)thiz->get_component_name(thiz),
 
1181
                                       sge_u32c(my_component_id), 
 
1182
                                       sge_u32c(sge_qmaster_port),
 
1183
                                       cl_get_error_text(cl_ret)));
 
1184
               }
 
1185
            }
 
1186
            break;
 
1187
 
 
1188
         default:
 
1189
            /* this is for "normal" gdi clients of qmaster */
 
1190
            DPRINTF(("creating %s GDI handle\n", thiz->get_component_name(thiz)));
 
1191
            handle = cl_com_create_handle(&cl_ret, 
 
1192
                                          communication_framework, 
 
1193
                                          CL_CM_CT_MESSAGE, 
 
1194
                                          CL_FALSE, 
 
1195
                                          sge_qmaster_port, 
 
1196
                                          CL_TCP_DEFAULT,
 
1197
                                          (char*)thiz->get_component_name(thiz), 
 
1198
                                          my_component_id, 
 
1199
                                          1, 
 
1200
                                          0);
 
1201
            if (handle == NULL) {
 
1202
/*             if (cl_ret != CL_RETVAL_OK && cl_ret != ctx_get_last_commlib_error(thiz)) { */
 
1203
                  sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, 
 
1204
                                     MSG_GDI_CANT_CONNECT_HANDLE_SSUUS, 
 
1205
                                     thiz->get_qualified_hostname(thiz), 
 
1206
                                     thiz->get_component_name(thiz), 
 
1207
                                     sge_u32c(my_component_id),
 
1208
                                     sge_u32c(sge_qmaster_port),
 
1209
                                     cl_get_error_text(cl_ret));
 
1210
/*             }        */
 
1211
            }
 
1212
            break;
 
1213
      }
 
1214
      ctx_set_last_commlib_error(thiz, cl_ret);
 
1215
   }
 
1216
 
 
1217
#ifdef DEBUG_CLIENT_SUPPORT
 
1218
   /* set rmon callback for message printing (after handle creation) */
 
1219
   rmon_set_print_callback(gdi_rmon_print_callback_function);
 
1220
#endif
 
1221
 
 
1222
   if ((thiz->get_who(thiz) == QMASTER) && (getenv("SGE_TEST_SOCKET_BIND") != NULL)) {
 
1223
      /* this is for testsuite socket bind test (issue 1096 ) */
 
1224
         struct timeval now;
 
1225
         gettimeofday(&now,NULL);
 
1226
     
 
1227
         /* if this environment variable is set, we wait 15 seconds after 
 
1228
            communication lib setup */
 
1229
         DPRINTF(("waiting for 60 seconds, because environment SGE_TEST_SOCKET_BIND is set\n"));
 
1230
         while ( handle != NULL && now.tv_sec - handle->start_time.tv_sec  <= 60 ) {
 
1231
            DPRINTF(("timeout: "sge_U32CFormat"\n",sge_u32c(now.tv_sec - handle->start_time.tv_sec)));
 
1232
            cl_commlib_trigger(handle, 1);
 
1233
            gettimeofday(&now,NULL);
 
1234
         }
 
1235
         DPRINTF(("continue with setup\n"));
 
1236
   }
 
1237
   DRETURN(cl_ret);   
 
1238
}
 
1239
 
 
1240
static int sge_gdi_ctx_class_is_alive(sge_gdi_ctx_class_t *thiz) 
 
1241
{
 
1242
   cl_com_SIRM_t* status = NULL;
 
1243
   int cl_ret = CL_RETVAL_OK;
 
1244
   cl_com_handle_t *handle = thiz->get_com_handle(thiz);
 
1245
 
 
1246
   /* TODO */
 
1247
   const char* comp_name = prognames[QMASTER];
 
1248
   const char* comp_host = thiz->get_master(thiz, false);
 
1249
   int         comp_id   = 1;
 
1250
 
 
1251
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_is_alive");
 
1252
   
 
1253
   if (handle == NULL) {
 
1254
      sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR,
 
1255
                "handle not found %s:0", thiz->get_component_name(thiz));
 
1256
      DRETURN(CL_RETVAL_PARAMS);
 
1257
   }
 
1258
 
 
1259
   DPRINTF(("to->comp_host, to->comp_name, to->comp_id: %s/%s/%d\n", comp_host?comp_host:"", comp_name?comp_name:"", comp_id));
 
1260
   cl_ret = cl_commlib_get_endpoint_status(handle, (char*)comp_host, (char*)comp_name, comp_id, &status);
 
1261
   if (cl_ret != CL_RETVAL_OK) {
 
1262
      sge_gdi_ctx_class_error(thiz, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR,
 
1263
                "cl_commlib_get_endpoint_status failed: "SFQ, cl_get_error_text(cl_ret));
 
1264
   } else {
 
1265
      DEBUG((SGE_EVENT,MSG_GDI_QMASTER_STILL_RUNNING));   
 
1266
   }
 
1267
 
 
1268
   if (status != NULL) {
 
1269
      DEBUG((SGE_EVENT,MSG_GDI_ENDPOINT_UPTIME_UU, sge_u32c(status->runtime) , 
 
1270
             sge_u32c(status->application_status)));
 
1271
      cl_com_free_sirm_message(&status);
 
1272
   }
 
1273
 
 
1274
   DRETURN(cl_ret);
 
1275
}
 
1276
 
 
1277
static lList* sge_gdi_ctx_class_gdi_tsm(sge_gdi_ctx_class_t *thiz, const char *schedd_name, const char *cell)
 
1278
{
 
1279
   lList *alp = NULL;
 
1280
   
 
1281
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_gdi_tsm");
 
1282
 
 
1283
   alp = gdi2_tsm(thiz, schedd_name, cell);
 
1284
 
 
1285
   DRETURN(alp);
 
1286
 
 
1287
}
 
1288
 
 
1289
static lList* sge_gdi_ctx_class_gdi_kill(sge_gdi_ctx_class_t *thiz, lList *id_list, const char *cell, 
 
1290
                                          u_long32 option_flags, u_long32 action_flag)
 
1291
{
 
1292
   lList *alp = NULL;
 
1293
   
 
1294
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_gdi_kill");
 
1295
 
 
1296
   alp = gdi2_kill(thiz, id_list, cell, option_flags, action_flag);
 
1297
 
 
1298
   DRETURN(alp);
 
1299
 
 
1300
}
 
1301
 
 
1302
static bool sge_gdi_ctx_class_gdi_check_permission(sge_gdi_ctx_class_t *thiz, lList **alpp, int option)
 
1303
{
 
1304
   bool ret = false;
 
1305
   
 
1306
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_gdi_check_permission");
 
1307
 
 
1308
   ret = sge_gdi2_check_permission(thiz, alpp, option);
 
1309
 
 
1310
   DRETURN(ret);
 
1311
 
 
1312
}
 
1313
 
 
1314
static bool sge_gdi_ctx_class_gdi_get_mapping_name(sge_gdi_ctx_class_t *thiz, const char *requestedHost, char *buf, int buflen)
 
1315
{
 
1316
   bool ret = false;
 
1317
   
 
1318
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_gdi_get_mapping_name");
 
1319
 
 
1320
   ret = sge_gdi2_get_mapping_name(thiz, requestedHost, buf, buflen);
 
1321
 
 
1322
   DRETURN(ret);
 
1323
 
 
1324
}
 
1325
 
 
1326
static void sge_gdi_ctx_class_dprintf(sge_gdi_ctx_class_t *ctx)
 
1327
{
 
1328
   DENTER(TOP_LAYER, "sge_gdi_ctx_class_dprintf");
 
1329
 
 
1330
   if (ctx == NULL) {
 
1331
      DRETURN_VOID;
 
1332
   }   
 
1333
   DPRINTF(("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n"));   
 
1334
      
 
1335
   (ctx->get_sge_env_state(ctx))->dprintf(ctx->get_sge_env_state(ctx)); 
 
1336
   (ctx->get_sge_prog_state(ctx))->dprintf(ctx->get_sge_prog_state(ctx)); 
 
1337
   (ctx->get_sge_path_state(ctx))->dprintf(ctx->get_sge_path_state(ctx)); 
 
1338
   (ctx->get_sge_bootstrap_state(ctx))->dprintf(ctx->get_sge_bootstrap_state(ctx)); 
 
1339
 
 
1340
   DPRINTF(("master: %s\n", ctx->get_master(ctx, false)));
 
1341
   DPRINTF(("uid/username: %d/%s\n", (int) ctx->get_uid(ctx), ctx->get_username(ctx)));
 
1342
   DPRINTF(("gid/groupname: %d/%s\n", (int) ctx->get_gid(ctx), ctx->get_groupname(ctx)));
 
1343
 
 
1344
   DPRINTF(("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"));   
 
1345
 
 
1346
   DRETURN_VOID;
 
1347
}
 
1348
 
 
1349
 
 
1350
/** --------- getter/setter ------------------------------------------------- */
 
1351
static cl_com_handle_t* get_com_handle(sge_gdi_ctx_class_t *thiz) 
 
1352
{
 
1353
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1354
   return cl_com_get_handle(es->component_name, 0);
 
1355
}
 
1356
   
 
1357
static sge_env_state_class_t* get_sge_env_state(sge_gdi_ctx_class_t *thiz) 
 
1358
{
 
1359
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1360
   return es->sge_env_state_obj;
 
1361
}
 
1362
 
 
1363
static sge_prog_state_class_t* get_sge_prog_state(sge_gdi_ctx_class_t *thiz) 
 
1364
{
 
1365
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1366
   return es->sge_prog_state_obj;
 
1367
}
 
1368
 
 
1369
static sge_path_state_class_t* get_sge_path_state(sge_gdi_ctx_class_t *thiz) 
 
1370
{
 
1371
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1372
   return es->sge_path_state_obj;
 
1373
}
 
1374
 
 
1375
static sge_csp_path_class_t* get_sge_csp_path(sge_gdi_ctx_class_t *thiz) 
 
1376
{
 
1377
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1378
   return es->sge_csp_path_obj;
 
1379
}
 
1380
 
 
1381
static sge_bootstrap_state_class_t* get_sge_bootstrap_state(sge_gdi_ctx_class_t *thiz)
 
1382
{
 
1383
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1384
   return es->sge_bootstrap_state_obj;
 
1385
}
 
1386
 
 
1387
static const char* get_master(sge_gdi_ctx_class_t *thiz, bool reread) {
 
1388
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1389
   sge_path_state_class_t* path_state = thiz->get_sge_path_state(thiz);
 
1390
   sge_error_class_t *eh = es ? es->eh : NULL;
 
1391
   
 
1392
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_master");
 
1393
   
 
1394
   if (es->master == NULL || reread) {
 
1395
      char err_str[SGE_PATH_MAX+128];
 
1396
      char master_name[CL_MAXHOSTLEN];
 
1397
 
 
1398
      if (get_qm_name(master_name, path_state->get_act_qmaster_file(path_state), err_str) == -1) {         
 
1399
         if (eh != NULL) {
 
1400
            eh->error(eh, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, MSG_GDI_READMASTERNAMEFAILED_S, err_str);
 
1401
         }
 
1402
         DRETURN(NULL);
 
1403
      } 
 
1404
      DPRINTF(("(re-)reading act_qmaster file. Got master host \"%s\"\n", master_name));
 
1405
      /*
 
1406
      ** TODO: thread locking needed here ?
 
1407
      */ 
 
1408
      es->master = sge_strdup(es->master,master_name);
 
1409
   }   
 
1410
   DRETURN(es->master);
 
1411
}
 
1412
 
 
1413
static const char* get_qualified_hostname(sge_gdi_ctx_class_t *thiz) {
 
1414
   sge_prog_state_class_t* prog_state = thiz->get_sge_prog_state(thiz);
 
1415
   const char *qualified_hostname = NULL;
 
1416
   
 
1417
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_progname");
 
1418
   qualified_hostname = prog_state->get_qualified_hostname(prog_state); 
 
1419
   DRETURN(qualified_hostname);
 
1420
}
 
1421
 
 
1422
static const char* get_unqualified_hostname(sge_gdi_ctx_class_t *thiz) {
 
1423
   sge_prog_state_class_t* prog_state = thiz->get_sge_prog_state(thiz);
 
1424
   const char *unqualified_hostname = NULL;
 
1425
   
 
1426
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_unqualified_hostname");
 
1427
   unqualified_hostname = prog_state->get_unqualified_hostname(prog_state); 
 
1428
   DRETURN(unqualified_hostname);
 
1429
}
 
1430
 
 
1431
static const char* get_component_name(sge_gdi_ctx_class_t *thiz) {
 
1432
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1433
   const char* ret = NULL;
 
1434
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_component_name");
 
1435
   ret = es->component_name;
 
1436
   DRETURN(ret);
 
1437
}  
 
1438
 
 
1439
static const char* get_thread_name(sge_gdi_ctx_class_t *thiz) {
 
1440
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1441
   const char* ret = NULL;
 
1442
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_thread_name");
 
1443
   ret = es->thread_name;
 
1444
   DRETURN(ret);
 
1445
}  
 
1446
 
 
1447
static const char* get_progname(sge_gdi_ctx_class_t *thiz) {
 
1448
   sge_prog_state_class_t* prog_state = thiz->get_sge_prog_state(thiz);
 
1449
   const char *progname = NULL;
 
1450
   
 
1451
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_progname");
 
1452
   progname = prog_state->get_sge_formal_prog_name(prog_state); 
 
1453
   DRETURN(progname);
 
1454
}
 
1455
 
 
1456
static u_long32 get_who(sge_gdi_ctx_class_t *thiz) {
 
1457
   sge_prog_state_class_t* prog_state = thiz->get_sge_prog_state(thiz);
 
1458
   u_long32 prognumber = 0;
 
1459
   
 
1460
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_who");
 
1461
   prognumber = prog_state->get_who(prog_state); 
 
1462
   DRETURN(prognumber);
 
1463
}
 
1464
 
 
1465
static bool is_daemonized(sge_gdi_ctx_class_t *thiz) {
 
1466
   sge_prog_state_class_t* prog_state = thiz->get_sge_prog_state(thiz);
 
1467
   bool is_daemonized = false;
 
1468
   
 
1469
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->is_daemonized");
 
1470
   is_daemonized = (prog_state->get_daemonized(prog_state)) ? true : false;
 
1471
   DRETURN(is_daemonized);
 
1472
}
 
1473
 
 
1474
static void set_daemonized(sge_gdi_ctx_class_t *thiz, bool daemonized) {
 
1475
   sge_prog_state_class_t* prog_state = thiz->get_sge_prog_state(thiz);
 
1476
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->set_daemonized");
 
1477
   prog_state->set_daemonized(prog_state, daemonized);
 
1478
   DRETURN_VOID;
 
1479
}
 
1480
 
 
1481
static bool get_job_spooling(sge_gdi_ctx_class_t *thiz) {
 
1482
   sge_bootstrap_state_class_t* bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1483
   bool job_spooling = true;
 
1484
   
 
1485
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_job_spooling");
 
1486
   job_spooling = bootstrap_state->get_job_spooling(bootstrap_state);
 
1487
   DRETURN(job_spooling);
 
1488
}
 
1489
 
 
1490
static void set_job_spooling(sge_gdi_ctx_class_t *thiz, bool job_spooling) {
 
1491
   sge_bootstrap_state_class_t* bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1492
 
 
1493
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->set_job_spooling");
 
1494
   bootstrap_state->set_job_spooling(bootstrap_state, job_spooling);
 
1495
   DRETURN_VOID;
 
1496
}
 
1497
 
 
1498
static const char* get_spooling_method(sge_gdi_ctx_class_t *thiz) {
 
1499
   sge_bootstrap_state_class_t* bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1500
   const char *spooling_method = NULL;
 
1501
   
 
1502
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_spooling_method");
 
1503
   spooling_method = bootstrap_state->get_spooling_method(bootstrap_state);
 
1504
   DRETURN(spooling_method);
 
1505
}
 
1506
 
 
1507
static const char* get_spooling_lib(sge_gdi_ctx_class_t *thiz) {
 
1508
   sge_bootstrap_state_class_t* bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1509
   const char *spooling_lib = NULL;
 
1510
   
 
1511
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_spooling_lib");
 
1512
   spooling_lib = bootstrap_state->get_spooling_lib(bootstrap_state);
 
1513
   DRETURN(spooling_lib);
 
1514
}
 
1515
 
 
1516
static const char* get_spooling_params(sge_gdi_ctx_class_t *thiz) {
 
1517
   sge_bootstrap_state_class_t* bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1518
   const char *spooling_params = NULL;
 
1519
   
 
1520
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_spooling_params");
 
1521
   spooling_params = bootstrap_state->get_spooling_params(bootstrap_state);
 
1522
   DRETURN(spooling_params);
 
1523
}
 
1524
 
 
1525
static u_long32 get_listener_thread_count(sge_gdi_ctx_class_t *thiz) {
 
1526
   sge_bootstrap_state_class_t* bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1527
   u_long32 thread_count = 0;
 
1528
   
 
1529
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_listenr_thread_count");
 
1530
   thread_count = bootstrap_state->get_listener_thread_count(bootstrap_state);
 
1531
   DRETURN(thread_count);
 
1532
}
 
1533
 
 
1534
static u_long32 get_worker_thread_count(sge_gdi_ctx_class_t *thiz) {
 
1535
   sge_bootstrap_state_class_t* bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1536
   u_long32 thread_count = 0;
 
1537
   
 
1538
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_worker_thread_count");
 
1539
   thread_count = bootstrap_state->get_worker_thread_count(bootstrap_state);
 
1540
   DRETURN(thread_count);
 
1541
}
 
1542
 
 
1543
static u_long32 get_scheduler_thread_count(sge_gdi_ctx_class_t *thiz) {
 
1544
   sge_bootstrap_state_class_t* bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1545
   u_long32 thread_count = 0;
 
1546
   
 
1547
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_scheduler_thread_count");
 
1548
   thread_count = bootstrap_state->get_scheduler_thread_count(bootstrap_state);
 
1549
   DRETURN(thread_count);
 
1550
}
 
1551
 
 
1552
static u_long32 get_jvm_thread_count(sge_gdi_ctx_class_t *thiz) {
 
1553
   sge_bootstrap_state_class_t* bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1554
   u_long32 thread_count = 0;
 
1555
   
 
1556
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_jvm_thread_count");
 
1557
   thread_count = bootstrap_state->get_jvm_thread_count(bootstrap_state);
 
1558
   DRETURN(thread_count);
 
1559
}
 
1560
 
 
1561
static sge_exit_func_t get_exit_func(sge_gdi_ctx_class_t *thiz) {
 
1562
   sge_prog_state_class_t* prog_state = thiz->get_sge_prog_state(thiz);
 
1563
   sge_exit_func_t exit_func = NULL;
 
1564
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_exit_func");
 
1565
   exit_func = prog_state->get_exit_func(prog_state);
 
1566
   DRETURN(exit_func);
 
1567
}
 
1568
 
 
1569
static void set_exit_func(sge_gdi_ctx_class_t *thiz, sge_exit_func_t exit_func) {
 
1570
   sge_prog_state_class_t* prog_state = thiz->get_sge_prog_state(thiz);
 
1571
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->set_exit_func");
 
1572
   prog_state->set_exit_func(prog_state, exit_func);
 
1573
   DRETURN_VOID;
 
1574
}
 
1575
 
 
1576
static void set_private_key(sge_gdi_ctx_class_t *thiz, const char *pkey) {
 
1577
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1578
   
 
1579
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->set_private_key");
 
1580
 
 
1581
   if ( es->ssl_private_key != NULL ) {
 
1582
      FREE(es->ssl_private_key);
 
1583
   }
 
1584
   es->ssl_private_key = pkey ? strdup(pkey): NULL;
 
1585
 
 
1586
   DRETURN_VOID;
 
1587
}
 
1588
 
 
1589
static const char* get_private_key(sge_gdi_ctx_class_t *thiz) {
 
1590
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1591
   const char *pkey = NULL;
 
1592
   
 
1593
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_private_key");
 
1594
   pkey = es->ssl_private_key;
 
1595
   DRETURN(pkey);
 
1596
}
 
1597
 
 
1598
 
 
1599
static void set_certificate(sge_gdi_ctx_class_t *thiz, const char *cert) {
 
1600
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1601
 
 
1602
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->set_certificate");
 
1603
 
 
1604
   if (es->ssl_certificate != NULL) {
 
1605
      FREE(es->ssl_certificate);
 
1606
   }
 
1607
   es->ssl_certificate = cert ? strdup(cert) : NULL;
 
1608
 
 
1609
   DRETURN_VOID;
 
1610
}
 
1611
 
 
1612
static const char* get_certificate(sge_gdi_ctx_class_t *thiz) {
 
1613
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1614
   const char *cert = NULL;
 
1615
   
 
1616
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_certificate");
 
1617
   cert = es->ssl_certificate;
 
1618
   DRETURN(cert);
 
1619
}
 
1620
 
 
1621
static const char* get_ca_local_root(sge_gdi_ctx_class_t *thiz) {
 
1622
   sge_csp_path_class_t *sge_csp = get_sge_csp_path(thiz);
 
1623
   const char *ca_local_root = NULL;
 
1624
   
 
1625
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_ca_local_root");
 
1626
   if (sge_csp != NULL) {
 
1627
      ca_local_root = sge_csp->get_ca_local_root(sge_csp);
 
1628
   }   
 
1629
   DRETURN(ca_local_root);
 
1630
}
 
1631
 
 
1632
static const char* get_ca_root(sge_gdi_ctx_class_t *thiz) {
 
1633
   sge_csp_path_class_t *sge_csp = get_sge_csp_path(thiz);
 
1634
   const char *ca_root = NULL;
 
1635
   
 
1636
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_ca_root");
 
1637
   if (sge_csp != NULL) {
 
1638
      ca_root = sge_csp->get_ca_root(sge_csp);
 
1639
   }
 
1640
   DRETURN(ca_root);
 
1641
}
 
1642
 
 
1643
static const char* get_default_cell(sge_gdi_ctx_class_t *thiz) {
 
1644
   sge_prog_state_class_t* prog_state = thiz->get_sge_prog_state(thiz);
 
1645
   const char *default_cell = NULL;
 
1646
   
 
1647
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_default_cell");
 
1648
   default_cell = prog_state->get_default_cell(prog_state); 
 
1649
   DRETURN(default_cell);
 
1650
}
 
1651
 
 
1652
 
 
1653
static const char* get_cell_root(sge_gdi_ctx_class_t *thiz) {
 
1654
   sge_path_state_class_t* path_state = thiz->get_sge_path_state(thiz);
 
1655
   const char *cell_root = NULL;
 
1656
   
 
1657
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_cell_root");
 
1658
   cell_root = path_state->get_cell_root(path_state); 
 
1659
   DRETURN(cell_root);
 
1660
}
 
1661
 
 
1662
static const char* get_sge_root(sge_gdi_ctx_class_t *thiz) {
 
1663
   sge_path_state_class_t* path_state = thiz->get_sge_path_state(thiz);
 
1664
   const char *sge_root = NULL;
 
1665
   
 
1666
   DENTER(BASIS_LAYER, "sge_gdi_ctx_class->get_sge_root");
 
1667
   sge_root = path_state->get_sge_root(path_state); 
 
1668
   DRETURN(sge_root);
 
1669
}
 
1670
 
 
1671
 
 
1672
static const char* get_admin_user(sge_gdi_ctx_class_t *thiz) {
 
1673
   sge_bootstrap_state_class_t * bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1674
   return bootstrap_state->get_admin_user(bootstrap_state);
 
1675
}
 
1676
 
 
1677
static const char* get_binary_path(sge_gdi_ctx_class_t *thiz) {
 
1678
   sge_bootstrap_state_class_t * bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1679
   return bootstrap_state->get_binary_path(bootstrap_state);
 
1680
}
 
1681
 
 
1682
static const char* get_qmaster_spool_dir(sge_gdi_ctx_class_t *thiz) {
 
1683
   sge_bootstrap_state_class_t * bootstrap_state = thiz->get_sge_bootstrap_state(thiz);
 
1684
   return bootstrap_state->get_qmaster_spool_dir(bootstrap_state);
 
1685
}
 
1686
 
 
1687
static const char* get_bootstrap_file(sge_gdi_ctx_class_t *thiz) {
 
1688
   sge_path_state_class_t *path_state = thiz->get_sge_path_state(thiz);
 
1689
   return path_state->get_bootstrap_file(path_state);
 
1690
}
 
1691
 
 
1692
static const char* get_act_qmaster_file(sge_gdi_ctx_class_t *thiz) {
 
1693
   sge_path_state_class_t *path_state = thiz->get_sge_path_state(thiz);
 
1694
   return path_state->get_act_qmaster_file(path_state);
 
1695
}
 
1696
 
 
1697
static const char* get_acct_file(sge_gdi_ctx_class_t *thiz) {
 
1698
   sge_path_state_class_t *path_state = thiz->get_sge_path_state(thiz);
 
1699
   return path_state->get_acct_file(path_state);
 
1700
}
 
1701
 
 
1702
static const char* get_reporting_file(sge_gdi_ctx_class_t *thiz) {
 
1703
   sge_path_state_class_t *path_state = thiz->get_sge_path_state(thiz);
 
1704
   return path_state->get_reporting_file(path_state);
 
1705
}
 
1706
 
 
1707
 
 
1708
static const char* get_shadow_master_file(sge_gdi_ctx_class_t *thiz) {
 
1709
   sge_path_state_class_t *path_state = thiz->get_sge_path_state(thiz);
 
1710
   return path_state->get_shadow_masters_file(path_state);
 
1711
}
 
1712
 
 
1713
 
 
1714
static const char* get_username(sge_gdi_ctx_class_t *thiz) {
 
1715
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1716
   return es->username;
 
1717
}
 
1718
 
 
1719
static const char* get_groupname(sge_gdi_ctx_class_t *thiz) {
 
1720
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1721
   return es->groupname;
 
1722
}
 
1723
 
 
1724
 
 
1725
static u_long32 get_sge_qmaster_port(sge_gdi_ctx_class_t *thiz) {
 
1726
   sge_env_state_class_t *es = thiz->get_sge_env_state(thiz);
 
1727
   return es->get_sge_qmaster_port(es);
 
1728
}
 
1729
 
 
1730
static u_long32 get_sge_execd_port(sge_gdi_ctx_class_t *thiz) {
 
1731
   sge_env_state_class_t *es = thiz->get_sge_env_state(thiz);
 
1732
   return es->get_sge_execd_port(es);
 
1733
}
 
1734
 
 
1735
static int ctx_get_last_commlib_error(sge_gdi_ctx_class_t *thiz) {
 
1736
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1737
   return es->last_commlib_error;
 
1738
}
 
1739
 
 
1740
static void ctx_set_last_commlib_error(sge_gdi_ctx_class_t *thiz, int cl_error) {
 
1741
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1742
   es->last_commlib_error = cl_error;
 
1743
}
 
1744
 
 
1745
 
 
1746
static uid_t ctx_get_uid(sge_gdi_ctx_class_t *thiz) {
 
1747
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1748
   return es->uid;
 
1749
}
 
1750
 
 
1751
static gid_t ctx_get_gid(sge_gdi_ctx_class_t *thiz) {
 
1752
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1753
   return es->gid;
 
1754
}
 
1755
 
 
1756
static bool ctx_is_qmaster_internal_client(sge_gdi_ctx_class_t *thiz) {
 
1757
   sge_gdi_ctx_t *es = (sge_gdi_ctx_t *) thiz->sge_gdi_ctx_handle;
 
1758
   return es->is_qmaster_internal_client;
 
1759
}
 
1760
 
 
1761
 
 
1762
static int sge_gdi_ctx_log_flush_func(cl_raw_list_t* list_p) 
 
1763
{
 
1764
   int ret_val;
 
1765
   cl_log_list_elem_t* elem = NULL;
 
1766
 
 
1767
   DENTER(COMMD_LAYER, "sge_gdi_ctx_log_flush_func");
 
1768
 
 
1769
   if (list_p == NULL) {
 
1770
      DRETURN(CL_RETVAL_LOG_NO_LOGLIST);
 
1771
   }
 
1772
 
 
1773
   if ((ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
 
1774
      DRETURN(ret_val);
 
1775
   }
 
1776
 
 
1777
   while ((elem = cl_log_list_get_first_elem(list_p) ) != NULL) {
 
1778
      char* param;
 
1779
      if (elem->log_parameter == NULL) {
 
1780
         param = "";
 
1781
      } else {
 
1782
         param = elem->log_parameter;
 
1783
      }
 
1784
 
 
1785
      switch(elem->log_type) {
 
1786
         case CL_LOG_ERROR: 
 
1787
            if (log_state_get_log_level() >= LOG_ERR) {
 
1788
               ERROR((SGE_EVENT,  "%s %-20s=> %s %s\n", elem->log_module_name, elem->log_thread_name, elem->log_message, param ));
 
1789
            } else {
 
1790
               printf("%s %-20s=> %s %s\n", elem->log_module_name, elem->log_thread_name, elem->log_message, param);
 
1791
            }
 
1792
            break;
 
1793
         case CL_LOG_WARNING:
 
1794
            if (log_state_get_log_level() >= LOG_WARNING) {
 
1795
               WARNING((SGE_EVENT,"%s %-20s=> %s %s\n", elem->log_module_name, elem->log_thread_name, elem->log_message, param ));
 
1796
            } else {
 
1797
               printf("%s %-20s=> %s %s\n", elem->log_module_name, elem->log_thread_name, elem->log_message, param);
 
1798
            }
 
1799
            break;
 
1800
         case CL_LOG_INFO:
 
1801
            if (log_state_get_log_level() >= LOG_INFO) {
 
1802
               INFO((SGE_EVENT,   "%s %-20s=> %s %s\n", elem->log_module_name, elem->log_thread_name, elem->log_message, param ));
 
1803
            } else {
 
1804
               printf("%s %-20s=> %s %s\n", elem->log_module_name, elem->log_thread_name, elem->log_message, param);
 
1805
            }
 
1806
            break;
 
1807
         case CL_LOG_DEBUG:
 
1808
            if (log_state_get_log_level() >= LOG_DEBUG) { 
 
1809
               DEBUG((SGE_EVENT,  "%s %-20s=> %s %s\n", elem->log_module_name, elem->log_thread_name, elem->log_message, param ));
 
1810
            } else {
 
1811
               printf("%s %-20s=> %s %s\n", elem->log_module_name, elem->log_thread_name, elem->log_message, param);
 
1812
            }
 
1813
            break;
 
1814
         case CL_LOG_OFF:
 
1815
            break;
 
1816
      }
 
1817
      cl_log_list_del_log(list_p);
 
1818
   }
 
1819
   
 
1820
   if ((ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
 
1821
      DRETURN(ret_val);
 
1822
   } 
 
1823
   DRETURN(CL_RETVAL_OK);
 
1824
}
 
1825
 
 
1826
/*
 
1827
** TODO: 
 
1828
** only helper function to do the setup for clients similar to sge_setup()
 
1829
*/
 
1830
int 
 
1831
sge_setup2(sge_gdi_ctx_class_t **context, u_long32 progid, u_long32 thread_id,
 
1832
           lList **alpp, bool is_qmaster_intern_client)
 
1833
{
 
1834
   char  user[128] = "";
 
1835
   char  group[128] = "";
 
1836
   const char *sge_root = NULL;
 
1837
   const char *sge_cell = NULL;
 
1838
   u_long32 sge_qmaster_port = 0;
 
1839
   u_long32 sge_execd_port = 0;
 
1840
   bool from_services = false;
 
1841
 
 
1842
   DENTER(TOP_LAYER, "sge_setup2");
 
1843
 
 
1844
   if (context == NULL) {
 
1845
      answer_list_add_sprintf(alpp, STATUS_ESEMANTIC, ANSWER_QUALITY_CRITICAL, MSG_GDI_CONTEXT_NULL);
 
1846
      DRETURN(AE_ERROR);
 
1847
   }
 
1848
 
 
1849
   /*
 
1850
   ** TODO:
 
1851
   ** get the environment for now here  -> sge_env_class_t should be enhanced and used instead as input param
 
1852
   */
 
1853
   sge_root = getenv("SGE_ROOT");
 
1854
   if (sge_root == NULL) {
 
1855
      answer_list_add_sprintf(alpp, STATUS_ESEMANTIC, 
 
1856
                              ANSWER_QUALITY_CRITICAL, MSG_SGEROOTNOTSET);
 
1857
      DRETURN(AE_ERROR);
 
1858
   }
 
1859
   sge_cell = getenv("SGE_CELL")?getenv("SGE_CELL"):DEFAULT_CELL;
 
1860
   sge_qmaster_port = sge_get_qmaster_port(&from_services);
 
1861
   sge_execd_port = sge_get_execd_port();
 
1862
 
 
1863
   /*
 
1864
    * uidgid_mt_init() needs to be called here already so that sge_uid2user()
 
1865
    * sge_gid2group() works correctly. Other *_mt_init() functions are called
 
1866
    * in sge_gdi_ctx_class_create();
 
1867
    */
 
1868
   uidgid_mt_init();
 
1869
 
 
1870
   if (sge_uid2user(geteuid(), user, sizeof(user), MAX_NIS_RETRIES)) {
 
1871
      answer_list_add_sprintf(alpp, STATUS_ESEMANTIC, ANSWER_QUALITY_CRITICAL, MSG_SYSTEM_RESOLVEUSER);
 
1872
      DRETURN(AE_ERROR);
 
1873
   }
 
1874
 
 
1875
   if (sge_gid2group(getegid(), group, sizeof(group), MAX_NIS_RETRIES)) {
 
1876
      answer_list_add_sprintf(alpp, STATUS_ESEMANTIC, ANSWER_QUALITY_CRITICAL, MSG_SYSTEM_RESOLVEGROUP);
 
1877
      DRETURN(AE_ERROR);
 
1878
   }
 
1879
 
 
1880
   /* a dynamic eh handler is created */
 
1881
   *context = sge_gdi_ctx_class_create(progid, prognames[progid], thread_id, 
 
1882
                                       threadnames[thread_id], user, group,
 
1883
                                       sge_root, sge_cell, sge_qmaster_port, 
 
1884
                                       sge_execd_port, from_services, 
 
1885
                                       is_qmaster_intern_client, alpp);
 
1886
 
 
1887
   if (*context == NULL) {
 
1888
      DRETURN(AE_ERROR);
 
1889
   }
 
1890
 
 
1891
   /* 
 
1892
   ** TODO: we set the log state context here 
 
1893
   **       this should be done more explicitily !!!
 
1894
   */
 
1895
   log_state_set_log_context(*context);
 
1896
 
 
1897
   /* 
 
1898
   ** TODO: bootstrap info is used in cull functions sge_hostcpy
 
1899
   **       ignore_fqdn, domain_name
 
1900
   **       Therefore we have to set it into the thread ctx
 
1901
   */
 
1902
   sge_gdi_set_thread_local_ctx(*context);
 
1903
 
 
1904
   DRETURN(AE_OK);
 
1905
}
 
1906
 
 
1907
/*
 
1908
** TODO: 
 
1909
** only helper function to do the setup for clients similar to sge_gdi_setup()
 
1910
*/
 
1911
int sge_gdi2_setup(sge_gdi_ctx_class_t **context_ref, u_long32 progid, u_long32 thread_id, lList **alpp)
 
1912
{
 
1913
   int ret = AE_OK;
 
1914
   bool alpp_was_null = true;
 
1915
 
 
1916
   DENTER(TOP_LAYER, "sge_gdi2_setup");
 
1917
 
 
1918
   if (context_ref && sge_gdi_ctx_is_setup(*context_ref)) {
 
1919
      if (alpp_was_null) {
 
1920
         SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_GDI_GDI_ALREADY_SETUP));
 
1921
      } else {
 
1922
         answer_list_add_sprintf(alpp, STATUS_EEXIST, ANSWER_QUALITY_WARNING,
 
1923
                                 MSG_GDI_GDI_ALREADY_SETUP);
 
1924
      }
 
1925
      DRETURN(AE_ALREADY_SETUP);
 
1926
   }
 
1927
   ret = sge_setup2(context_ref, progid, thread_id, alpp, false); 
 
1928
   if (ret != AE_OK) {
 
1929
      DRETURN(ret);
 
1930
   }
 
1931
 
 
1932
   if ((*context_ref)->prepare_enroll(*context_ref) != CL_RETVAL_OK) {
 
1933
      sge_gdi_ctx_class_get_errors(*context_ref, alpp, true);
 
1934
      DRETURN(AE_QMASTER_DOWN);
 
1935
   }
 
1936
 
 
1937
   sge_gdi_ctx_set_is_setup(*context_ref, true);
 
1938
 
 
1939
   DRETURN(AE_OK);
 
1940
}
 
1941
 
 
1942
static int reresolve_qualified_hostname(sge_gdi_ctx_class_t *thiz) {
 
1943
   char unique_hostname[CL_MAXHOSTLEN];
 
1944
   sge_prog_state_class_t* prog_state = thiz->get_sge_prog_state(thiz);
 
1945
   int ret = CL_RETVAL_OK;
 
1946
 
 
1947
   DENTER(TOP_LAYER, "gdi2_reresolve_qualified_hostname");
 
1948
 
 
1949
   ret=getuniquehostname(prog_state->get_qualified_hostname(prog_state), unique_hostname, 0);
 
1950
   if( ret != CL_RETVAL_OK ) {
 
1951
      DRETURN(ret);
 
1952
   }
 
1953
   prog_state->set_qualified_hostname(prog_state, unique_hostname);
 
1954
 
 
1955
   DRETURN(ret);
 
1956
}