From 92da5bd10ca31050c7d243739123f2773700d006 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Voc=C5=AF?= Date: Wed, 16 May 2012 08:01:34 +0000 Subject: [PATCH] merge of branch michal_Torque --- org.glite.lb.server/Makefile | 18 +- org.glite.lb.server/interface/lb_authz.h | 6 + org.glite.lb.server/src/bkserverd.c | 11 +- org.glite.lb.server/src/lb_authz.c | 17 +- org.glite.lb.server/src/lb_xml_parse.c.T | 2 +- org.glite.lb.server/src/lb_xml_parse_V21.c.T | 2 +- org.glite.lb.server/src/lcas_lb.c | 6 + org.glite.lb.server/src/ws_typeref.c.T | 33 +- org.glite.lb.state-machine/interface/intjobstat.h | 2 +- org.glite.lb.state-machine/interface/seqcode_aux.h | 3 +- org.glite.lb.state-machine/src/intjobstat_supp.c | 9 +- org.glite.lb.state-machine/src/process_event_pbs.c | 476 ++++++++++++++------- org.glite.lb.state-machine/src/seqcode_aux.c | 135 +++--- 13 files changed, 503 insertions(+), 217 deletions(-) diff --git a/org.glite.lb.server/Makefile b/org.glite.lb.server/Makefile index 3e91ad0..9a0c3ed 100644 --- a/org.glite.lb.server/Makefile +++ b/org.glite.lb.server/Makefile @@ -99,6 +99,7 @@ LIBCARES_LIBS?=${cares_libs} -lcares GSOAP_CFLAGS?=-I${gsoap_prefix}/include -I${gsoap_prefix}/ EXPAT_CFLAGS?=-I${expat_prefix}/include GLOBUS_GSSAPI_GSI_CFLAGS?=-I${globus_prefix}/include/${nothrflavour} +KERBEROS_GSSAPI_GSI_CFLAGS=-DNO_GLOBUS_GSSAPI CPPUNIT_LIBS?=-L${cppunit_prefix}/${libdir} -lcppunit CPPUNIT_CFLAGS?=-I${cppunit_prefix}/include @@ -106,8 +107,16 @@ CPPUNIT_CFLAGS?=-I${cppunit_prefix}/include VOMS_CFLAGS?=-I${voms_prefix}/include -I${voms_prefix}/include/glite/security VOMS_LIBS?=-L${voms_prefix}/${libdir} -lvomsapi${vomsflavour} +ifeq ($(gssapi_provider), kerberos) +GSSAPI_GSI_CFLAGS=${KERBEROS_GSSAPI_GSI_CFLAGS} +VOMS_LIBS= +VOMS_CFLAGS= +else +GSSAPI_GSI_CFLAGS=${GLOBUS_GSSAPI_GSI_CFLAGS} +endif + CFLAGS:= ${CFLAGS} \ - ${GLOBUS_GSSAPI_GSI_CFLAGS} \ + ${GSSAPI_GSI_CFLAGS} \ ${WS_CFLAGS} ${DEBUG} \ -DVERSION=\"${version}\" \ ${GSOAP_CFLAGS} \ @@ -157,9 +166,14 @@ EXT_LIBS:= \ -lz \ ${GRIDSITE_LIBS} \ ${CLASSADS_LIBS} \ - ${LIBCARES_LIBS} \ + ${LIBCARES_LIBS} + +ifeq ($(gssapi_provider), kerberos) +else +EXT_LIBS+= \ ${LCAS_LIBS} \ ${VOMS_LIBS} +endif COMMON_LIBS:= -L${stagedir}${prefix}/${libdir} -lglite_lb_common${default_flavour} -lglite_security_gss${default_flavour} -lglite_lbu_trio -lglite_lbu_maildir -lglite_lbu_log diff --git a/org.glite.lb.server/interface/lb_authz.h b/org.glite.lb.server/interface/lb_authz.h index 8da9f42..1a1e6eb 100644 --- a/org.glite.lb.server/interface/lb_authz.h +++ b/org.glite.lb.server/interface/lb_authz.h @@ -27,7 +27,11 @@ extern "C" { #ifndef NO_GACL #include #endif +#ifndef NO_GLOBUS_GSSAPI #include +#else +struct vomsdata { int dummy; }; +#endif typedef struct _edg_wll_Acl { #ifndef NO_GACL @@ -80,8 +84,10 @@ edg_wll_GetACL(edg_wll_Context, glite_jobid_const_t, edg_wll_Acl *); extern int edg_wll_SetVomsGroups(edg_wll_Context, edg_wll_GssConnection *, char *, char *, char *, char *); +#ifndef NO_GLOBUS_GSSAPI extern void edg_wll_FreeVomsGroups(edg_wll_VomsGroups *); +#endif extern int check_store_authz(edg_wll_Context ctx, edg_wll_Event *ev); diff --git a/org.glite.lb.server/src/bkserverd.c b/org.glite.lb.server/src/bkserverd.c index 916f0fe..b833491 100644 --- a/org.glite.lb.server/src/bkserverd.c +++ b/org.glite.lb.server/src/bkserverd.c @@ -425,6 +425,8 @@ int main(int argc, char *argv[]) purge_timeout[EDG_WLL_JOB_CLEARED] = 60*60*24*3; purge_timeout[EDG_WLL_JOB_ABORTED] = 60*60*24*7; purge_timeout[EDG_WLL_JOB_CANCELLED] = 60*60*24*7; + + if (edg_wll_InitContext(&ctx) != 0) { fprintf(stderr, "Couldn't create L&B context, exiting.\n"); exit(1); @@ -678,7 +680,7 @@ int main(int argc, char *argv[]) ret = edg_wll_gss_watch_creds(server_cert, &cert_mtime); if (ret < 0) glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN,"edg_wll_gss_watch_creds failed, unable to access credentials\n"); - if ( !edg_wll_gss_acquire_cred_gsi(server_cert, server_key, &mycred, &gss_code) ) + if ( !edg_wll_gss_acquire_cred_gsi(server_cert, server_key, &mycred, &gss_code) && mycred->name != NULL) { glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Server identity: %s", mycred->name); server_subject = strdup(mycred->name); @@ -689,7 +691,6 @@ int main(int argc, char *argv[]) glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR, "Server running unauthenticated"); server_subject = strdup("anonymous LB"); } - if ( noAuth ) glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Server in promiscuous mode"); glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, @@ -878,7 +879,6 @@ int main(int argc, char *argv[]) if (port) free(port); edg_wll_gss_release_cred(&mycred, NULL); - return 0; } @@ -1199,6 +1199,7 @@ int bk_handle_connection(int conn, struct timeval *timeout, void *data) glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_INFO, "[%d] client DN: %s",getpid(),ctx->peerName); } +#if 0 if ( edg_wll_SetVomsGroups(ctx, &ctx->connections->serverConnection->gss, server_cert, server_key, vomsdir, cadir) ) { char *errt, *errd; @@ -1208,13 +1209,15 @@ int bk_handle_connection(int conn, struct timeval *timeout, void *data) free(errt); free(errd); edg_wll_ResetError(ctx); } +#endif + if (ctx->vomsGroups.len > 0) { int i; glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_DEBUG, "[%d] client's VOMS groups:",getpid()); for ( i = 0; i < ctx->vomsGroups.len; i++ ) - glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_DEBUG, "\t%s:%s", ctx->vomsGroups.val[i].vo, ctx->vomsGroups.val[i].name); + glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_DEBUG, "\t %s:%s", ctx->vomsGroups.val[i].vo, ctx->vomsGroups.val[i].name); } if (ctx->fqans && *(ctx->fqans)) { diff --git a/org.glite.lb.server/src/lb_authz.c b/org.glite.lb.server/src/lb_authz.c index 02e3b7e..936621a 100644 --- a/org.glite.lb.server/src/lb_authz.c +++ b/org.glite.lb.server/src/lb_authz.c @@ -22,8 +22,10 @@ limitations under the License. #include #include +#ifndef NO_GLOBUS_GSSAPI #include "lcas/lcas_pem.h" #include "voms/voms_apic.h" +#endif #include "glite/lb/context-int.h" #include "lb_authz.h" #include "glite/lbu/log.h" @@ -60,6 +62,7 @@ edg_wll_get_fqans(edg_wll_Context ctx, struct vomsdata *voms_info, attrs = NULL; num = 0; +#ifndef NO_GLOBUS_GSSAPI for (voms_cert = voms_info->data; voms_cert && *voms_cert; voms_cert++) { for (f = (*voms_cert)->fqan; f && *f; f++) { tmp = realloc(attrs, (num + 1) * sizeof(*attrs)); @@ -80,11 +83,13 @@ edg_wll_get_fqans(edg_wll_Context ctx, struct vomsdata *voms_info, attrs = tmp; attrs[num++] = NULL; } +#endif *fqans = attrs; return 0; } +#ifndef NO_GLOBUS_GSSAPI static int add_groups(edg_wll_Context ctx, struct voms *voms_cert, char *vo_name, edg_wll_VomsGroups *groups) @@ -135,6 +140,7 @@ get_groups(edg_wll_Context ctx, struct vomsdata *voms_info, res_groups->val = groups.val; return 0; } +#endif int edg_wll_SetVomsGroups(edg_wll_Context ctx, edg_wll_GssConnection *gss, char *server_cert, char *server_key, char *voms_dir, char *ca_dir) @@ -150,6 +156,10 @@ edg_wll_SetVomsGroups(edg_wll_Context ctx, edg_wll_GssConnection *gss, char *ser memset (&ctx->vomsGroups, 0, sizeof(ctx->vomsGroups)); edg_wll_ResetError(ctx); +#ifdef NO_GLOBUS_GSSAPI + return 0; +#else + if (ctx->fqans) { char **f; for (f = ctx->fqans; f && *f; f++) @@ -174,7 +184,6 @@ edg_wll_SetVomsGroups(edg_wll_Context ctx, edg_wll_GssConnection *gss, char *ser ret = -1; /* XXX VOMS Error */ goto end; } - ret = VOMS_RetrieveFromCtx(gss->context, RECURSE_CHAIN, voms_info, &err); if (ret == 0) { if (err == VERR_NOEXT) @@ -202,8 +211,11 @@ end: VOMS_Destroy(voms_info); return ret; + +#endif /* NO_GLOBUS_GSSAPI */ } +#ifndef NO_GLOBUS_GSSAPI void edg_wll_FreeVomsGroups(edg_wll_VomsGroups *groups) { @@ -219,6 +231,7 @@ edg_wll_FreeVomsGroups(edg_wll_VomsGroups *groups) free(groups->val[len].name); } } +#endif static int parse_creds(edg_wll_Context ctx, edg_wll_VomsGroups *groups, char **fqans, @@ -950,6 +963,7 @@ check_store_authz(edg_wll_Context ctx, edg_wll_Event *ev) break; } +#ifndef NO_GLOBUS_GSSAPI if (enable_lcas) { /* XXX make a real RSL ? */ request = (char *) action2name(action); @@ -965,6 +979,7 @@ check_store_authz(edg_wll_Context ctx, edg_wll_Event *ev) if (ret) goto end; } +#endif /* by default the server is open to any authenticated client */ if (policy_file == NULL) diff --git a/org.glite.lb.server/src/lb_xml_parse.c.T b/org.glite.lb.server/src/lb_xml_parse.c.T index 773ee2a..afde05d 100644 --- a/org.glite.lb.server/src/lb_xml_parse.c.T +++ b/org.glite.lb.server/src/lb_xml_parse.c.T @@ -1838,7 +1838,7 @@ int edg_wll_JobStatusToXML(edg_wll_Context ctx, edg_wll_JobStat stat, char **mes if (stat.children) edg_wll_add_strlist_to_XMLBody(&pomB, stat.children, "children", "jobId", "\t\t\t", NULL); if (stat.children_hist) edg_wll_add_intlist_to_XMLBody(&pomB, stat.children_hist, "children_hist", edg_wll_StatToString, "\t\t\t", 1, stat.children_hist[0]); if (stat.children_states) edg_wll_add_stslist_to_XMLBody(ctx, &pomB, stat.children_states, "children_states", "", EDG_WLL_JOB_UNDEF); - if (stat.user_tags) edg_wll_add_taglist_to_XMLBody(&pomB, stat.user_tags, "user_tags", "tag", "name", "\t\t\t", NULL); + if (stat.user_tags) edg_wll_add_usertag_to_XMLBody(&pomB, stat.user_tags, "user_tags", "tag", "name", "\t\t\t", NULL); if (stat.stateEnterTimes) edg_wll_add_intlist_to_XMLBody(&pomB, stat.stateEnterTimes, "stateEnterTimes", edg_wll_StatToString, "\t\t\t",1, stat.stateEnterTimes[0]); pomC = edg_wll_StatToString(stat.state); diff --git a/org.glite.lb.server/src/lb_xml_parse_V21.c.T b/org.glite.lb.server/src/lb_xml_parse_V21.c.T index 540302a..111be9c 100644 --- a/org.glite.lb.server/src/lb_xml_parse_V21.c.T +++ b/org.glite.lb.server/src/lb_xml_parse_V21.c.T @@ -1184,7 +1184,7 @@ int edg_wll_JobStatusToXMLV21(edg_wll_Context ctx, edg_wll_JobStat stat, char ** if (stat.children) edg_wll_add_strlist_to_XMLBody(&pomB, stat.children, "children", "jobId", "\t\t\t", NULL); if (stat.children_hist) edg_wll_add_intlist_to_XMLBody(&pomB, stat.children_hist, "children_hist", return_string_el, "\t\t\t", 1, stat.children_hist[0]); if (stat.children_states) edg_wll_add_stslist_to_XMLBodyV21(ctx, &pomB, stat.children_states, "children_states", "", EDG_WLL_JOB_UNDEF); - if (stat.user_tags) edg_wll_add_taglist_to_XMLBody(&pomB, stat.user_tags, "user_tags", "tag", "name", "\t\t\t", NULL); + if (stat.user_tags) edg_wll_add_usertag_to_XMLBody(&pomB, stat.user_tags, "user_tags", "tag", "name", "\t\t\t", NULL); if (stat.stateEnterTimes) edg_wll_add_intlist_to_XMLBody(&pomB, stat.stateEnterTimes, "stateEnterTimes", return_string_el, "\t\t\t",1, stat.stateEnterTimes[0]); pomC = edg_wll_StatToString(stat.state); diff --git a/org.glite.lb.server/src/lcas_lb.c b/org.glite.lb.server/src/lcas_lb.c index 9101d30..15cf923 100644 --- a/org.glite.lb.server/src/lcas_lb.c +++ b/org.glite.lb.server/src/lcas_lb.c @@ -24,7 +24,9 @@ limitations under the License. #include "lcas/lcas_modules.h" #include "lcas/lcas_utils.h" +#ifndef NO_GLOBUS_GSSAPI #include "voms/voms_apic.h" +#endif #include #include "authz_policy.h" #include "lb_authz.h" @@ -88,6 +90,7 @@ plugin_confirm_authorization(lcas_request_t request, lcas_cred_id_t lcas_cred) #endif } +#ifndef NO_GLOBUS_GSSAPI if (cred) { voms_info = VOMS_Init(NULL, NULL); if (voms_info == NULL) { @@ -100,14 +103,17 @@ plugin_confirm_authorization(lcas_request_t request, lcas_cred_id_t lcas_cred) if (ret == 1) edg_wll_get_fqans(ctx, voms_info, &princ.fqans); } +#endif ret = check_authz_policy(edg_wll_get_server_policy(), &princ, action); ret = (ret == 1) ? LCAS_MOD_SUCCESS : LCAS_MOD_FAIL; end: edg_wll_FreeContext(ctx); +#ifndef NO_GLOBUS_GSSAPI if (voms_info) VOMS_Destroy(voms_info); +#endif if (cert) X509_free(cert); if (chain) diff --git a/org.glite.lb.server/src/ws_typeref.c.T b/org.glite.lb.server/src/ws_typeref.c.T index aa3a330..450900a 100644 --- a/org.glite.lb.server/src/ws_typeref.c.T +++ b/org.glite.lb.server/src/ws_typeref.c.T @@ -65,7 +65,7 @@ sub eventFieldAssign { }; $source = "$src->$native_en.$native_fn"; $dest = "VALUEEV_GET($dst, $soap_en)->$soap_fn"; -# print STDERR "$src, $dst, $soap_en, $soap_fn, $native_fn, $tn, $usuc\n"; + print STDERR "$src, $dst, $soap_en, $soap_fn, $native_fn, $tn, $usuc\n"; if ($tn eq 'int') { if ($f->{codes}) { @@ -104,6 +104,23 @@ sub eventFieldAssign { gen $indent."$dest = soap_malloc(soap, sizeof(*$dst->$soap_fn));\n"; gen $indent."$dest->tag = soap_strdup(soap, $source.tag);\n"; gen $indent."$dest->value = soap_strdup(soap, $source.value);\n"; + } elsif ($tn eq 'taglist') { + gen qq{ +! { +! struct lbt__tagValue *t; +! int i; +! +! for (i=0; $source && $source\[i].tag; i++); +! /* GLITE_SECURITY_GSOAP_LIST_CREATE(soap, $dst, $soap_en.$soap_fn, struct lbt__tagValue, i); */ +! GLITE_SECURITY_GSOAP_LIST_CREATE0(soap, $dest, VALUEEV_GET($dst,$soap_en)->__size$soap_fn, struct lbt__tagValue, i); +! for (i=0; $source && $source\[i].tag; i++) { +! t = GLITE_SECURITY_GSOAP_LIST_GET($dest, i); +! t->tag = soap_strdup(soap,$source\[i].tag); +! t->value = soap_strdup(soap,$source\[i].value); +! } +! } +}; + } else { die "Unknown type $tn"; } @@ -137,6 +154,20 @@ sub eventFieldFree { gen $indent." if ($dest->value) soap_dealloc(soap, $dest->value);\n"; gen $indent." soap_dealloc(soap, $dest);\n"; gen $indent."}\n"; + } elsif ($tn eq 'taglist') { + gen qq{ +! if($dest) { +! struct lbt__tagValue *t; +! int i; +! +! for(i=0; i < VALUEEV_GET($dst, $soap_en)->__size$soap_fn; i++) { +! t = GLITE_SECURITY_GSOAP_LIST_GET($dest, i); +! if(t->tag) soap_dealloc(soap, t->tag); +! if(t->value) soap_dealloc(soap, t->value); +! } +! GLITE_SECURITY_GSOAP_LIST_DESTROY0(soap, $dest, VALUEEV_GET($dst, $soap_en)->__size$soap_fn); +! } + }; } else { die "Unknown type $tn"; } diff --git a/org.glite.lb.state-machine/interface/intjobstat.h b/org.glite.lb.state-machine/interface/intjobstat.h index dcb1031..9596491 100644 --- a/org.glite.lb.state-machine/interface/intjobstat.h +++ b/org.glite.lb.state-machine/interface/intjobstat.h @@ -31,7 +31,7 @@ limitations under the License. /* where Z.XX is version from indent + 1 (version after commit), Y = Z+1 */ /* and DESCRIPTION is short hit why version changed */ -#define INTSTAT_VERSION "revision 2.10 - payload owner" +#define INTSTAT_VERSION "revision 2.11 - payload owner" // ".... MAX LENGTH 32 BYTES !! ...." // Internal error codes diff --git a/org.glite.lb.state-machine/interface/seqcode_aux.h b/org.glite.lb.state-machine/interface/seqcode_aux.h index daeb67c..19fbf3a 100644 --- a/org.glite.lb.state-machine/interface/seqcode_aux.h +++ b/org.glite.lb.state-machine/interface/seqcode_aux.h @@ -26,9 +26,8 @@ int before_deep_resubmission(const char *a, const char *b); int same_branch(const char *a, const char *b) ; int edg_wll_compare_pbs_seq(const char *a,const char *b); -#define edg_wll_compare_condor_seq edg_wll_compare_pbs_seq -edg_wll_PBSEventSource get_pbs_event_source(const char *pbs_seq_num) ; +int edg_wll_compare_condor_seq(const char *a,const char *b); edg_wll_CondorEventSource get_condor_event_source(const char *condor_seq_num) ; diff --git a/org.glite.lb.state-machine/src/intjobstat_supp.c b/org.glite.lb.state-machine/src/intjobstat_supp.c index a436180..ff4fe62 100644 --- a/org.glite.lb.state-machine/src/intjobstat_supp.c +++ b/org.glite.lb.state-machine/src/intjobstat_supp.c @@ -38,6 +38,9 @@ limitations under the License. /* TBD: share in whole logging or workload */ + +/* XXX - how come this is not generated from .T when the JobStat structure is? */ + #ifdef __GNUC__ #define UNUSED_VAR __attribute__((unused)) #else @@ -537,7 +540,8 @@ char *enc_JobStat(char *old, edg_wll_JobStat* stat) if (ret) ret = enc_string(ret, stat->pbs_scheduler); if (ret) ret = enc_string(ret, stat->pbs_dest_host); if (ret) ret = enc_int(ret, stat->pbs_pid); - if (ret) ret = enc_string(ret, stat->pbs_resource_usage); + if (ret) ret = enc_taglist(ret, stat->pbs_resource_requested); + if (ret) ret = enc_taglist(ret, stat->pbs_resource_usage); if (ret) ret = enc_int(ret, stat->pbs_exit_status); if (ret) ret = enc_string(ret, stat->pbs_error_desc); if (ret) ret = enc_string(ret, stat->condor_status); @@ -643,7 +647,8 @@ edg_wll_JobStat* dec_JobStat(char *in, char **rest) if (tmp_in != NULL) stat->pbs_scheduler = dec_string(tmp_in, &tmp_in); if (tmp_in != NULL) stat->pbs_dest_host = dec_string(tmp_in, &tmp_in); if (tmp_in != NULL) stat->pbs_pid = dec_int(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->pbs_resource_usage = dec_string(tmp_in, &tmp_in); + if (tmp_in != NULL) stat->pbs_resource_requested = dec_taglist(tmp_in, &tmp_in); + if (tmp_in != NULL) stat->pbs_resource_usage = dec_taglist(tmp_in, &tmp_in); if (tmp_in != NULL) stat->pbs_exit_status = dec_int(tmp_in, &tmp_in); if (tmp_in != NULL) stat->pbs_error_desc = dec_string(tmp_in, &tmp_in); if (tmp_in != NULL) stat->condor_status = dec_string(tmp_in, &tmp_in); diff --git a/org.glite.lb.state-machine/src/process_event_pbs.c b/org.glite.lb.state-machine/src/process_event_pbs.c index 89e1465..ab8a81c 100644 --- a/org.glite.lb.state-machine/src/process_event_pbs.c +++ b/org.glite.lb.state-machine/src/process_event_pbs.c @@ -56,6 +56,93 @@ static int compare_timestamps(struct timeval a, struct timeval b) #define rep(a,b) { free(a); a = (b == NULL) ? NULL : strdup(b); } #define rep_cond(a,b) { if (b) { free(a); a = strdup(b); } } +/* maps PBS/Torque substates to LB job states */ +static int _PBSsubstate2lbstate[] = { + /* TRANSIN */ EDG_WLL_JOB_SUBMITTED, + /* TRANSICM */ EDG_WLL_JOB_SUBMITTED, + /* TRNOUT */ EDG_WLL_JOB_SUBMITTED, + /* TRNOUTCM */ EDG_WLL_JOB_SUBMITTED, + /* SUBSTATE04 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE05 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE06 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE07 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE08 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE09 */ EDG_WLL_JOB_UNKNOWN, + /* QUEUED */ EDG_WLL_JOB_WAITING, + /* PRESTAGEIN */ EDG_WLL_JOB_READY, + /* SUBSTATE12 */ EDG_WLL_JOB_UNKNOWN, + /* SYNCRES */ EDG_WLL_JOB_READY, + /* STAGEIN */ EDG_WLL_JOB_READY, + /* STAGEGO */ EDG_WLL_JOB_SCHEDULED, + /* STAGECMP */ EDG_WLL_JOB_READY, + /* SUBSTATE17 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE18 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE19 */ EDG_WLL_JOB_UNKNOWN, + /* HELD */ EDG_WLL_JOB_WAITING, + /* SYNCHOLD */ EDG_WLL_JOB_WAITING, + /* DEPNHOLD */ EDG_WLL_JOB_WAITING, + /* SUBSTATE23 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE24 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE25 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE26 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE27 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE28 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE29 */ EDG_WLL_JOB_UNKNOWN, + /* WAITING */ EDG_WLL_JOB_WAITING, + /* SUBSTATE31 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE32 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE33 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE34 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE35 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE36 */ EDG_WLL_JOB_UNKNOWN, + /* STAGEFAIL */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE38 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE39 */ EDG_WLL_JOB_UNKNOWN, + /* PRERUN */ EDG_WLL_JOB_SCHEDULED, + /* STARTING */ EDG_WLL_JOB_SCHEDULED, + /* RUNNING */ EDG_WLL_JOB_RUNNING, + /* SUSPEND */ EDG_WLL_JOB_WAITING, + /* SUBSTATE44 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE45 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE46 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE47 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE48 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE49 */ EDG_WLL_JOB_UNKNOWN, + /* EXITING */ EDG_WLL_JOB_RUNNING, + /* STAGEOUT */ EDG_WLL_JOB_RUNNING, + /* STAGEDEL */ EDG_WLL_JOB_RUNNING, + /* EXITED */ EDG_WLL_JOB_RUNNING, + /* ABORT */ EDG_WLL_JOB_CANCELLED, + /* SUBSTATE55 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE56 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE57 */ EDG_WLL_JOB_UNKNOWN, + /* OBIT */ EDG_WLL_JOB_RUNNING, + /* COMPLETE */ EDG_WLL_JOB_DONE, + /* RERUN */ EDG_WLL_JOB_WAITING, + /* RERUN1 */ EDG_WLL_JOB_WAITING, + /* RERUN2 */ EDG_WLL_JOB_WAITING, + /* RERUN3 */ EDG_WLL_JOB_WAITING, + /* SUBSTATE64 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE65 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE66 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE67 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE68 */ EDG_WLL_JOB_UNKNOWN, + /* SUBSTATE69 */ EDG_WLL_JOB_UNKNOWN, + /* RETURNSTD */ EDG_WLL_JOB_RUNNING +}; + + +/* maps PBS/Torque job states to status characters for display */ +static char *_PBSstate2char[] = { + /* TRANSIT -> */ "T", + /* QUEUED -> */ "Q", + /* HELD -> */ "H", + /* WAITING -> */ "W", + /* RUNNING -> */ "R", + /* EXITING -> */ "E", + /* COMPLETE-> */ "C" +}; + int processEvent_PBS(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char **errstring) { edg_wll_JobStatCode old_state = js->pub.state; @@ -68,162 +155,263 @@ int processEvent_PBS(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, c } switch (e->any.type) { - case EDG_WLL_EVENT_REGJOB: - if (USABLE(res)) { - js->pub.state = EDG_WLL_JOB_SUBMITTED; - rep(js->pub.pbs_state, "Q"); - } - if (USABLE_DATA(res)) { - } - break; - case EDG_WLL_EVENT_PBSQUEUED: - if (USABLE(res)) { - js->pub.state = EDG_WLL_JOB_WAITING; - rep(js->pub.pbs_state, "Q"); - } - if (USABLE_DATA(res)) { - if (!js->pub.pbs_queue) - js->pub.pbs_queue = strdup(e->PBSQueued.queue); - assert(!strcmp(js->pub.pbs_queue, e->PBSQueued.queue)); - rep_cond(js->pub.pbs_owner,e->PBSQueued.owner); - rep_cond(js->pub.pbs_name,e->PBSQueued.name); - } - break; - case EDG_WLL_EVENT_PBSMATCH: - if (USABLE(res)) { - js->pub.state = EDG_WLL_JOB_READY; - rep(js->pub.pbs_state, "Q"); - } - if (USABLE_DATA(res)) { - rep_cond(js->pub.pbs_dest_host,e->PBSMatch.dest_host); - } - break; - case EDG_WLL_EVENT_PBSPENDING: - if (USABLE(res)) { - js->pub.state = EDG_WLL_JOB_WAITING; - rep(js->pub.pbs_state, "Q"); - js->pbs_reruning = 0; // reset possible reruning flag - } - if (USABLE_DATA(res)) { - rep_cond(js->pub.pbs_reason,e->PBSPending.reason); + case EDG_WLL_EVENT_PBSINTERNALSTATECHANGE: + if(USABLE(res)) { + /* TODO: should we use this? Maybe to cross check... + * js->pub.state = _PBSsubstate2lbstate[e->PBSInternalStateChange.newsubstate]; + */ + rep(js->pub.pbs_state, _PBSstate2char[e->PBSInternalStateChange.newstate]); + js->pub.pbs_substate = e->PBSInternalStateChange.newsubstate; + } + break; + + case EDG_WLL_EVENT_REGJOB: + if (USABLE(res)) { + js->pub.state = EDG_WLL_JOB_SUBMITTED; + } + if (USABLE_DATA(res)) { + /* this is going to be the first server taking care of the job */ + rep(js->pub.network_server, e->regJob.ns); + } + break; + + case EDG_WLL_EVENT_PBSTRANSFER: + if(USABLE(res)) { + switch(e->PBSTransfer.result) { + case EDG_WLL_PBSTRANSFER_START: + break; + + case EDG_WLL_PBSTRANSFER_OK: + break; + + case EDG_WLL_PBSTRANSFER_REFUSED: + case EDG_WLL_PBSTRANSFER_FAIL: + break; + + default: + break; + } - break; - case EDG_WLL_EVENT_PBSRUN: - if (USABLE(res)) { - switch (get_pbs_event_source(e->any.seqcode)) { - case EDG_WLL_PBS_EVENT_SOURCE_SERVER: - js->pub.state = EDG_WLL_JOB_SCHEDULED; - rep(js->pub.pbs_state, "Q"); - break; - case EDG_WLL_PBS_EVENT_SOURCE_MOM: - js->pub.state = EDG_WLL_JOB_RUNNING; - rep(js->pub.pbs_state, "R"); - break; - default: - assert(0); // running event from strange source - break; + } + if(USABLE_DATA(res)) { + /* job going to another server */ + switch(e->PBSTransfer.result) { + case EDG_WLL_PBSTRANSFER_OK: + /* update job location */ + switch(e->PBSTransfer.destination) { + case EDG_WLL_SOURCE_PBS_SERVER: + break; + default: + /* where is it going? */ + break; + } + break; + default: + break; } - if (USABLE_DATA(res)) { - rep_cond(js->pub.pbs_scheduler, e->PBSRun.scheduler); - rep_cond(js->pub.pbs_dest_host, e->PBSRun.dest_host); - js->pub.pbs_pid = e->PBSRun.pid; - } - break; - case EDG_WLL_EVENT_PBSRERUN: - if (USABLE(res)) { - switch (get_pbs_event_source(e->any.seqcode)) { - case EDG_WLL_PBS_EVENT_SOURCE_SERVER: - js->pub.state = EDG_WLL_JOB_WAITING; - rep(js->pub.pbs_state, "Q"); - break; - case EDG_WLL_PBS_EVENT_SOURCE_MOM: - js->pub.state = EDG_WLL_JOB_WAITING; - rep(js->pub.pbs_state, "E"); - js->pbs_reruning = 1; - break; - default: - assert(0); // running event from strande source - break; - } + } + break; + + case EDG_WLL_EVENT_PBSACCEPTED: + if(USABLE(res)) { + switch(e->any.source) { + case EDG_WLL_SOURCE_PBS_SERVER: + /* accepted by server means job is submitted */ + js->pub.state = EDG_WLL_JOB_SUBMITTED; + break; + + case EDG_WLL_SOURCE_PBS_SMOM: + case EDG_WLL_SOURCE_PBS_MOM: + /* accepted by MOM: job is going to run */ + js->pub.state = EDG_WLL_JOB_SCHEDULED; + break; + + default: + /* this would be weird */ + break; } - if (USABLE_DATA(res)) { + } + break; + + case EDG_WLL_EVENT_PBSREFUSED: + break; + + case EDG_WLL_EVENT_PBSQUEUED: + if (USABLE(res)) { + js->pub.state = EDG_WLL_JOB_WAITING; + } + if (USABLE_DATA(res)) { + if(e->any.source == EDG_WLL_SOURCE_PBS_SERVER) { + /* queue */ + rep(js->pub.pbs_queue, e->PBSQueued.queue); + + /* job owner */ + if(!js->pub.pbs_owner) + rep_cond(js->pub.pbs_owner, e->PBSQueued.owner); + /* job_name */ + if(!js->pub.pbs_name) + rep_cond(js->pub.pbs_name, e->PBSQueued.name); } - break; - case EDG_WLL_EVENT_PBSDONE: - if (USABLE(res)) { - switch (get_pbs_event_source(e->any.seqcode)) { - case EDG_WLL_PBS_EVENT_SOURCE_SERVER: - js->pub.state = EDG_WLL_JOB_DONE; - js->pub.done_code = EDG_WLL_STAT_OK; - rep(js->pub.pbs_state, "C"); - break; - case EDG_WLL_PBS_EVENT_SOURCE_MOM: - if (!js->pbs_reruning) { - js->pub.state = EDG_WLL_JOB_DONE; - js->pub.done_code = EDG_WLL_STAT_OK; - rep(js->pub.pbs_state, "C"); - } - break; - default: - assert(0); //done event from strange source - break; - } + } + break; + + case EDG_WLL_EVENT_PBSMATCH: + /* XXX - not used yet */ + if (USABLE(res)) { + js->pub.state = EDG_WLL_JOB_READY; + } + if (USABLE_DATA(res)) { + rep_cond(js->pub.pbs_dest_host,e->PBSMatch.dest_host); + } + break; + + case EDG_WLL_EVENT_PBSPENDING: + /* XXX - not used yet */ + if (USABLE(res)) { + js->pub.state = EDG_WLL_JOB_WAITING; + js->pbs_reruning = 0; // reset possible reruning flag + } + if (USABLE_DATA(res)) { + rep_cond(js->pub.pbs_reason,e->PBSPending.reason); + } + break; + + case EDG_WLL_EVENT_PBSWAITING: + break; + + case EDG_WLL_EVENT_PBSRUN: + if (USABLE(res)) { + switch (e->any.source) { + case EDG_WLL_SOURCE_PBS_SERVER: + js->pub.state = EDG_WLL_JOB_SCHEDULED; + break; + case EDG_WLL_SOURCE_PBS_SMOM: + case EDG_WLL_SOURCE_PBS_MOM: + js->pub.state = EDG_WLL_JOB_RUNNING; + break; + default: + assert(0); // running event from strange source + break; } - if (USABLE_DATA(res)) { - js->pub.pbs_exit_status = e->PBSDone.exit_status; + } + if (USABLE_DATA(res)) { + /* session id */ + rep_cond(js->pub.pbs_scheduler, e->PBSRun.scheduler); + rep_cond(js->pub.pbs_dest_host, e->PBSRun.dest_host); + js->pub.pbs_pid = e->PBSRun.pid; + } + break; + + case EDG_WLL_EVENT_PBSRERUN: + if (USABLE(res)) { + switch (e->any.source) { + case EDG_WLL_SOURCE_PBS_SERVER: + js->pub.state = EDG_WLL_JOB_WAITING; + break; + case EDG_WLL_SOURCE_PBS_SMOM: + case EDG_WLL_SOURCE_PBS_MOM: + js->pub.state = EDG_WLL_JOB_WAITING; + js->pbs_reruning = 1; + break; + default: + assert(0); // running event from strande source + break; } - break; - case EDG_WLL_EVENT_PBSRESOURCEUSAGE: - if (USABLE(res)) { - // signalize state done, done_code uknown + } + if (USABLE_DATA(res)) { + /* session id */ + } + break; + + case EDG_WLL_EVENT_PBSABORT: + break; + + case EDG_WLL_EVENT_PBSDONE: + if (USABLE(res)) { + switch (e->any.source) { + case EDG_WLL_SOURCE_PBS_SERVER: js->pub.state = EDG_WLL_JOB_DONE; - rep(js->pub.pbs_state, "C"); + js->pub.done_code = EDG_WLL_STAT_OK; + break; + case EDG_WLL_SOURCE_PBS_SMOM: + case EDG_WLL_SOURCE_PBS_MOM: + /* we are not done until server says so */ + /* + * if (!js->pbs_reruning) { + * js->pub.state = EDG_WLL_JOB_DONE; + * js->pub.done_code = EDG_WLL_STAT_OK; + *} + */ + break; + default: + assert(0); //done event from strange source + break; } - if (USABLE_DATA(res)) { - char *new_resource_usage; - - trio_asprintf(&new_resource_usage,"%s%s\t%s = %f [%s]", - (js->pub.pbs_resource_usage) ? js->pub.pbs_resource_usage : "", - (js->pub.pbs_resource_usage) ? "\n": "", - e->PBSResourceUsage.name, - e->PBSResourceUsage.quantity, - e->PBSResourceUsage.unit); + } + if (USABLE_DATA(res)) { + /* exit status */ + js->pub.pbs_exit_status = e->PBSDone.exit_status; + } + break; + case EDG_WLL_EVENT_PBSRESOURCEUSAGE: + if (USABLE(res)) { + // signalize state done, done_code uknown + /* nonsense: js->pub.state = EDG_WLL_JOB_DONE; */ + } + if (USABLE_DATA(res)) { + /*trio_asprintf(&new_resource_usage,"%s%s\t%s = %f [%s]", + (js->pub.pbs_resource_usage) ? js->pub.pbs_resource_usage : "", + (js->pub.pbs_resource_usage) ? "\n": "", + e->PBSResourceUsage.name, + e->PBSResourceUsage.quantity, + e->PBSResourceUsage.unit); + */ + if(e->PBSResourceUsage.usage == EDG_WLL_PBSRESOURCEUSAGE_REQUESTED) { + if (js->pub.pbs_resource_requested) free(js->pub.pbs_resource_requested); + js->pub.pbs_resource_requested = edg_wll_CopyTagList(e->PBSResourceUsage.resources); + } else if(e->PBSResourceUsage.usage == EDG_WLL_PBSRESOURCEUSAGE_USED) { if (js->pub.pbs_resource_usage) free(js->pub.pbs_resource_usage); - js->pub.pbs_resource_usage = new_resource_usage; - } - break; - case EDG_WLL_EVENT_PBSERROR: - if (USABLE(res)) { - js->pub.state = EDG_WLL_JOB_DONE; - js->pub.done_code = EDG_WLL_STAT_FAILED; - rep(js->pub.pbs_state, "C"); + js->pub.pbs_resource_usage = edg_wll_CopyTagList(e->PBSResourceUsage.resources); + } else { + /* fprintf(stderr, "resource usage %d not recognized\n", e->PBSResourceUsage.usage); */ } - if (USABLE_DATA(res)) { - char *new_error_desc; + } + break; - trio_asprintf(&new_error_desc,"%s%s\t%s", - (js->pub.pbs_error_desc) ? js->pub.pbs_error_desc : "", - (js->pub.pbs_error_desc) ? "\n" : "", - e->PBSError.error_desc); - - if (js->pub.pbs_error_desc) free(js->pub.pbs_error_desc); - js->pub.pbs_error_desc = new_error_desc; - } - break; - case EDG_WLL_EVENT_USERTAG: - if (USABLE_DATA(res)) { - if (e->userTag.name != NULL && e->userTag.value != NULL) { - add_taglist(e->userTag.name, e->userTag.value, e->any.seqcode, js); - } - } - break; + case EDG_WLL_EVENT_PBSERROR: + /* XXX - not used yet */ + if (USABLE(res)) { + js->pub.state = EDG_WLL_JOB_DONE; + js->pub.done_code = EDG_WLL_STAT_FAILED; + rep(js->pub.pbs_state, "C"); + } + if (USABLE_DATA(res)) { + char *new_error_desc; + + trio_asprintf(&new_error_desc,"%s%s\t%s", + (js->pub.pbs_error_desc) ? js->pub.pbs_error_desc : "", + (js->pub.pbs_error_desc) ? "\n" : "", + e->PBSError.error_desc); + + if (js->pub.pbs_error_desc) free(js->pub.pbs_error_desc); + js->pub.pbs_error_desc = new_error_desc; + } + break; - default: - break; + case EDG_WLL_EVENT_USERTAG: + if (USABLE_DATA(res)) { + if (e->userTag.name != NULL && e->userTag.value != NULL) { + add_taglist(e->userTag.name, e->userTag.value, e->any.seqcode, js); + } + } + break; + + default: + break; } - + /* XXX : just debug output - remove */ /*printf("processEvent_PBS(): %s (%s), state: %s --> %s\n ", @@ -238,7 +426,7 @@ int processEvent_PBS(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, c if (USABLE(res)) { rep(js->last_seqcode, e->any.seqcode); - + js->pub.lastUpdateTime = e->any.timestamp; if (old_state != js->pub.state) { js->pub.stateEnterTime = js->pub.lastUpdateTime; @@ -247,8 +435,8 @@ int processEvent_PBS(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, c } } if (! js->pub.location) js->pub.location = strdup("this is PBS"); - - + + return RET_OK; } diff --git a/org.glite.lb.state-machine/src/seqcode_aux.c b/org.glite.lb.state-machine/src/seqcode_aux.c index b19d2ec..4d9b67b 100644 --- a/org.glite.lb.state-machine/src/seqcode_aux.c +++ b/org.glite.lb.state-machine/src/seqcode_aux.c @@ -52,7 +52,7 @@ limitations under the License. int component_seqcode(const char *a, edg_wll_Source index) { - unsigned int c[EDG_WLL_SEQ_FORMAT_NUMBER+1]; + unsigned int c[EDG_WLL_SOURCE__LAST]; int res; char sc[EDG_WLL_SEQ_SIZE]; @@ -80,7 +80,7 @@ int component_seqcode(const char *a, edg_wll_Source index) char * set_component_seqcode(char *a,edg_wll_Source index,int val) { - unsigned int c[EDG_WLL_SEQ_FORMAT_NUMBER+1]; + unsigned int c[EDG_WLL_SOURCE__LAST]; int res; char *ret; char sc[EDG_WLL_SEQ_SIZE]; @@ -139,70 +139,31 @@ int same_branch(const char *a, const char *b) int edg_wll_compare_pbs_seq(const char *a,const char *b) { - char timestamp_a[14], pos_a[10], src_a; - char timestamp_b[14], pos_b[10], src_b; - int ev_code_a, ev_code_b; - int res; + unsigned int c[EDG_WLL_SEQ_PBS_FORMAT_NUMBER+1], d[EDG_WLL_SEQ_PBS_FORMAT_NUMBER+1]; + int i, res; - res = sscanf(a,"TIMESTAMP=%14s:POS=%10s:EV.CODE=%3d:SRC=%c", timestamp_a, pos_a, &ev_code_a, &src_a); - - if (res != 4) { -/* FIXME: syslog(LOG_ERR, "unparsable sequence code %s\n", a); */ - fprintf(stderr, "unparsable sequence code %s\n", a); + res = sscanf(a, EDG_WLL_SEQ_PBS_FORMAT_SCANF, + &c[0], &c[1], &c[2], &c[3], &c[4]); + if(res != EDG_WLL_SEQ_PBS_FORMAT_NUMBER) { + fprintf(stderr, "unparsable sequence code %s: %d\n", a, res); return -1; } - - res = sscanf(b,"TIMESTAMP=%14s:POS=%10s:EV.CODE=%3d:SRC=%c", timestamp_b, pos_b, &ev_code_b, &src_b); - - if (res != 4) { -/* FIXME: syslog(LOG_ERR, "unparsable sequence code %s\n", b); */ - fprintf(stderr, "unparsable sequence code %s\n", b); + + res = sscanf(b, EDG_WLL_SEQ_PBS_FORMAT_SCANF, + &d[0], &d[1], &d[2], &d[3], &d[4]); + if(res != EDG_WLL_SEQ_PBS_FORMAT_NUMBER) { + fprintf(stderr, "unparsable sequence code %s: %d\n", b, res); return -1; } - /* wild card for PBSJobReg - this event should always come as firt one */ - /* bacause it hold job.type, which is necessary for further event processing */ - if (ev_code_a == EDG_WLL_EVENT_REGJOB) return -1; - if (ev_code_b == EDG_WLL_EVENT_REGJOB) return 1; - - /* sort event w.t.r. to timestamps */ - if ((res = strcmp(timestamp_a,timestamp_b)) != 0) { - return res; - } - else { - /* if timestamps equal, sort if w.t.r. to file position */ - /* if you both events come from the same log file */ - if (src_a == src_b) { - /* zero mean in fact duplicate events in log */ - return strcmp(pos_a,pos_b); - } - /* if the events come from diffrent log files */ - /* it is possible to prioritize some src log file */ - else { - /* prioritize events from pbs_mom */ - if (src_a == 'm') return 1; - if (src_b == 'm') return -1; - - /* then prioritize events from pbs_server */ - if (src_a == 's') return 1; - if (src_b == 's') return -1; - - /* other priorities comes here... */ - } + for (i = 0 ; i <= EDG_WLL_SEQ_PBS_FORMAT_NUMBER; i++) { + if (c[i] < d[i]) return -1; + if (c[i] > d[i]) return 1; } return 0; } -edg_wll_PBSEventSource get_pbs_event_source(const char *pbs_seq_num) { - switch (pbs_seq_num[EDG_WLL_SEQ_PBS_SIZE - 2]) { - case 'c': return(EDG_WLL_PBS_EVENT_SOURCE_SCHEDULER); - case 's': return(EDG_WLL_PBS_EVENT_SOURCE_SERVER); - case 'm': return(EDG_WLL_PBS_EVENT_SOURCE_MOM); - case 'a': return(EDG_WLL_PBS_EVENT_SOURCE_ACCOUNTING); - default: return(EDG_WLL_PBS_EVENT_SOURCE_UNDEF); - } -} edg_wll_CondorEventSource get_condor_event_source(const char *condor_seq_num) { switch (condor_seq_num[EDG_WLL_SEQ_CONDOR_SIZE - 2]) { @@ -219,15 +180,73 @@ edg_wll_CondorEventSource get_condor_event_source(const char *condor_seq_num) { } } + +int edg_wll_compare_condor_seq(const char *a, const char *b) { + char timestamp_a[14], pos_a[10], src_a; + char timestamp_b[14], pos_b[10], src_b; + int ev_code_a, ev_code_b; + int res; + + res = sscanf(a,"TIMESTAMP=%14s:POS=%10s:EV.CODE=%3d:SRC=%c", timestamp_a, pos_a, &ev_code_a, &src_a); + + if (res != 4) { +/* FIXME: syslog(LOG_ERR, "unparsable sequence code %s\n", a); */ + fprintf(stderr, "unparsable sequence code %s\n", a); + return -1; + } + + res = sscanf(b,"TIMESTAMP=%14s:POS=%10s:EV.CODE=%3d:SRC=%c", timestamp_b, pos_b, &ev_code_b, &src_b); + + if (res != 4) { +/* FIXME: syslog(LOG_ERR, "unparsable sequence code %s\n", b); */ + fprintf(stderr, "unparsable sequence code %s\n", b); + return -1; + } + + /* wild card for JobReg - this event should always come as firt one */ + /* bacause it hold job.type, which is necessary for further event processing */ + if (ev_code_a == EDG_WLL_EVENT_REGJOB) return -1; + if (ev_code_b == EDG_WLL_EVENT_REGJOB) return 1; + + /* sort event w.t.r. to timestamps */ + if ((res = strcmp(timestamp_a,timestamp_b)) != 0) { + return res; + } + else { + /* if timestamps equal, sort if w.t.r. to file position */ + /* if you both events come from the same log file */ + if (src_a == src_b) { + /* zero mean in fact duplicate events in log */ + return strcmp(pos_a,pos_b); + } + /* if the events come from diffrent log files */ + /* it is possible to prioritize some src log file */ + else { + /* prioritize events from pbs_mom */ + if (src_a == 'm') return 1; + if (src_b == 'm') return -1; + + /* then prioritize events from pbs_server */ + if (src_a == 's') return 1; + if (src_b == 's') return -1; + + /* other priorities comes here... */ + } + } + + return 0; +} + + int edg_wll_compare_seq(const char *a, const char *b) { - unsigned int c[EDG_WLL_SEQ_FORMAT_NUMBER+1]; - unsigned int d[EDG_WLL_SEQ_FORMAT_NUMBER+1]; + unsigned int c[EDG_WLL_SOURCE__LAST]; + unsigned int d[EDG_WLL_SOURCE__LAST]; int res, i; char sca[EDG_WLL_SEQ_SIZE], scb[EDG_WLL_SEQ_SIZE]; - if ( (strstr(a,"TIMESTAMP=") == a) && (strstr(b,"TIMESTAMP=") == b) ) + if ( (strstr(a,"SMOM=") != NULL) && (strstr(b,"SMOM=") != NULL) ) return edg_wll_compare_pbs_seq(a,b); if (!strstr(a, "LBS")) snprintf(sca,EDG_WLL_SEQ_SIZE,"%s:LBS=000000",a); -- 1.8.2.3