From 35c53b42079d36f7598fa526d3168876a060dc53 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Filipovi=C4=8D?= Date: Fri, 5 Jun 2009 13:08:02 +0000 Subject: [PATCH] Modified HTML and text interface at branch_2_0. --- org.glite.lb.server/Makefile | 13 ++++-- .../interface/pretty_print_wrapper.h | 10 ++++ org.glite.lb.server/src/lb_html.c | 46 +++++++++++++------ org.glite.lb.server/src/lb_text.c | 53 ++++++++++++---------- org.glite.lb.server/src/pretty_print_wrapper.cpp | 24 ++++++++++ 5 files changed, 104 insertions(+), 42 deletions(-) create mode 100644 org.glite.lb.server/interface/pretty_print_wrapper.h create mode 100644 org.glite.lb.server/src/pretty_print_wrapper.cpp diff --git a/org.glite.lb.server/Makefile b/org.glite.lb.server/Makefile index 8e63577..4081506 100644 --- a/org.glite.lb.server/Makefile +++ b/org.glite.lb.server/Makefile @@ -51,6 +51,7 @@ GSOAP_FILES_PREFIX:= bk_ws_ YACC=bison -y CC=gcc +CXX=g++ ifeq ($(gsoap_version),2.7.0) VPATH=${top_srcdir}/interface:${top_srcdir}/src:${top_srcdir}/test:${top_srcdir}/doc:${top_srcdir}/examples:${top_srcdir}/project:${gsoap_prefix} @@ -83,6 +84,8 @@ CFLAGS:= \ -D_GNU_SOURCE ${LB_STANDALONE_FLAGS} ${LB_PERF_FLAGS} -DLB_EVENTS_BLOB \ -I${globus_prefix}/include/${nothrflavour} #gridsite needs this +CXXFLAGS:=${CFLAGS} + ifdef LB_PROF SRVBONES_LIB:= ${stagedir}/lib/libglite_lbu_server_bones.la LB_COMMON_LIB:=${stagedir}/lib/libglite_lb_common_${nothrflavour}.la @@ -107,6 +110,7 @@ TEST_LIBS:=-L${cppunit_prefix}/lib -lcppunit TEST_INC:=-I${cppunit_prefix}/include COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} +CXXCOMPILE:=libtool --mode=compile ${CXX} ${CXXFLAGS} LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/lib ${LDFLAGS} SOLINK:=libtool --mode=link ${CC} -module ${LDFLAGS} -rpath ${stagedir}/lib # XXX: not used? LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS} @@ -168,7 +172,7 @@ BKSERVER_BASE_OBJS:= \ lb_xml_parse_V21.o lb_text.o \ openserver.o query.o userjobs.o db_store.o request.o store.o \ stored_master.o srv_purge.o server_state.o dump.o lb_authz.o load.o \ - notification.o il_notification.o notif_match.o stats.o db_calls.o db_supp.o lb_rss.o + notification.o il_notification.o notif_match.o stats.o db_calls.o db_supp.o lb_rss.o pretty_print_wrapper.o gsoap_version ?= ${gsoap_default_version} @@ -210,7 +214,7 @@ endif INDEX_OBJS:= index.o index_parse.o jobstat_supp.o openserver.o \ jobstat.o query.o get_events.o write2rgma.o index_lex.o \ lb_authz.o store.o bkindex.o stats.o\ - request.o db_store.o srv_purge.o notif_match.o il_lbproxy.o dump.o lb_xml_parse.o il_notification.o lb_proto.o lb_text.o server_state.o lb_xml_parse_V21.o lb_html.o cond_dump.o notification.o seqcode.o userjobs.o load.o db_calls.o db_supp.o lb_rss.o + request.o db_store.o srv_purge.o notif_match.o il_lbproxy.o dump.o lb_xml_parse.o il_notification.o lb_proto.o lb_text.o server_state.o lb_xml_parse_V21.o lb_html.o cond_dump.o notification.o seqcode.o userjobs.o load.o db_calls.o db_supp.o lb_rss.o pretty_print_wrapper.o INDEX_LIBS:= ${SRVBONES_LIB} ${COMMON_LIBS} ${LB_MACHINE_LIB} ${EXT_LIBS} ${LB_UTILS_DB_LIB} @@ -238,7 +242,7 @@ LIB_OBJS_BK:= \ openserver.o query.o userjobs.o db_store.o request.o store.o \ stored_master.o srv_purge.o server_state.o dump.o lb_authz.o load.o \ notification.o il_notification.o notif_match.o stats.o write2rgma.o \ - db_calls.o db_supp.o lb_rss.o + db_calls.o db_supp.o lb_rss.o pretty_print_wrapper.o MONDB_OBJS:=mon-db.o ${LIB_OBJS_BK} MONDB_LIBS:=${COMMON_LIBS} ${LB_MACHINE_LIB} ${LB_UTILS_DB_LIB} ${EXT_LIBS} @@ -393,6 +397,9 @@ clean: %.o %.lo: %.c ${COMPILE} -c $< +%.o %.lo: %.cpp + ${CXXCOMPILE} -c $< + test_query_events.o: %.o: %.cpp ${CXX} -c ${CFLAGS} ${TEST_INC} $< diff --git a/org.glite.lb.server/interface/pretty_print_wrapper.h b/org.glite.lb.server/interface/pretty_print_wrapper.h new file mode 100644 index 0000000..e99a2af --- /dev/null +++ b/org.glite.lb.server/interface/pretty_print_wrapper.h @@ -0,0 +1,10 @@ +#ifdef __cplusplus +extern "C" { +#endif + +int pretty_print(char *jdl, char **formated_print); + +#ifdef __cplusplus +} +#endif + diff --git a/org.glite.lb.server/src/lb_html.c b/org.glite.lb.server/src/lb_html.c index 5cc88ce..30f3cad 100644 --- a/org.glite.lb.server/src/lb_html.c +++ b/org.glite.lb.server/src/lb_html.c @@ -3,6 +3,7 @@ #include "lb_html.h" #include "lb_proto.h" #include "cond_dump.h" +#include "pretty_print_wrapper.h" #include "glite/lb/context-int.h" @@ -127,14 +128,21 @@ int edg_wll_UserNotifsToHTML(edg_wll_Context ctx UNUSED_VAR, char **notifids, ch } #define TR(name,type,field) \ +{ \ + int l; \ if (field){ \ - int l = asprintf(&pomA,"" name ":" \ - "" type "", (field)); \ - pomB = realloc(pomB, sizeof(*pomB)*(pomL+l+1)); \ - strcpy(pomB+pomL, pomA); \ - pomL += l; \ - free(pomA); pomA=NULL; \ - } + l = asprintf(&pomA,"" name ":" \ + "" type "", (field)); \ + } \ + else{ \ + l = asprintf(&pomA,"" name \ + ""); \ + } \ + pomB = realloc(pomB, sizeof(*pomB)*(pomL+l+1)); \ + strcpy(pomB+pomL, pomA); \ + pomL += l; \ + free(pomA); pomA=NULL; \ +} int edg_wll_NotificationToHTML(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, char **message){ char *pomA = NULL, *pomB = NULL, *flags, *cond; @@ -145,6 +153,8 @@ int edg_wll_NotificationToHTML(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, ch TR("Destination", "%s", ni->destination); TR("Valid until", "%s", ni->valid); + TR("Flags", "%s", flags); + free(flags); if (! edg_wll_Condition_Dump(ni, &cond, 0)){ asprintf(&pomA, "%s

Conditions

\r\n
%s
\r\n", @@ -156,9 +166,6 @@ int edg_wll_NotificationToHTML(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, ch } free(cond); - TR("Flags", "%s", flags); - free(flags); - asprintf(&pomA, "\r\n\t\r\n" "

Notification %s

\r\n" "%s
" @@ -194,26 +201,35 @@ int edg_wll_JobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat time_t time = stat.stateEnterTime.tv_sec; TR("State entered","%s",ctime(&time)); } + else + TR("State entered", "%s", NULL); if ( (stat.lastUpdateTime.tv_sec) || (stat.lastUpdateTime.tv_usec) ) { time_t time = stat.lastUpdateTime.tv_sec; TR("Last update","%s",ctime(&time)); } + else + TR("Last update", "%s", NULL); TR("Expect update","%s",stat.expectUpdate ? "YES" : "NO"); TR("Expect update from","%s",stat.expectFrom); TR("Location","%s",stat.location); TR("Destination","%s",stat.destination); TR("Cancelling","%s",stat.cancelling>0 ? "YES" : "NO"); - if (stat.cancelReason != NULL) { - TR("Cancel reason","%s",stat.cancelReason); - } + TR("Cancel reason","%s",stat.cancelReason); TR("CPU time","%d",stat.cpuTime); TR("Done code","%d",stat.done_code); TR("Exit code","%d",stat.exit_code); - if (stat.jdl) asprintf(&jdl,"

Job description

\r\n" - "
%s
\r\n",stat.jdl); + if (stat.jdl){ + char *jdl_unp; + if (pretty_print(stat.jdl, &jdl_unp) == 0) + asprintf(&jdl,"

Job description

\r\n" + "
%s
\r\n",jdl_unp); + else + asprintf(&jdl,"

Job description (not a ClassAd)" + "

\r\n
%s
\r\n",stat.jdl); + } if (stat.rsl) asprintf(&rsl,"

RSL

\r\n" "
%s
\r\n",stat.rsl); diff --git a/org.glite.lb.server/src/lb_text.c b/org.glite.lb.server/src/lb_text.c index 7bd1e49..510441c 100644 --- a/org.glite.lb.server/src/lb_text.c +++ b/org.glite.lb.server/src/lb_text.c @@ -56,23 +56,19 @@ int edg_wll_QueryToText(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *eventsOut return -1; } -/*#define TR(name,type,field) \ - if (field) { \ - asprintf(&a,"%s%s=" type "\n", \ - b, name, field); \ - free(b); \ - b = a; \ - }*/ #define TR(name,type,field) \ - if (field){ \ - int l = asprintf(&a,"%s=" type "\n", \ +{ \ + int l; \ + if (field) \ + l = asprintf(&a,"%s=" type "\n", \ name, field); \ - printf("a = %s l = %i\n", a, l); \ - b = realloc(b, sizeof(*b)*(pomL+l+1)); \ - strcpy(b+pomL, a); \ - pomL += l; \ - free(a); a=NULL; \ - } + else \ + l = asprintf(&a,"%s=\n", name); \ + b = realloc(b, sizeof(*b)*(pomL+l+1)); \ + strcpy(b+pomL, a); \ + pomL += l; \ + free(a); a=NULL; \ +} int edg_wll_UserInfoToText(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message) { @@ -137,16 +133,15 @@ int edg_wll_NotificationToText(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, ch TR("Notif_id", "%s", ni->notifid); TR("Destination", "%s", ni->destination); TR("Valid_until", "%s", ni->valid); + flags = edg_wll_stat_flags_to_string(ni->flags); + TR("Flags", "%s", flags); + free(flags); if (! edg_wll_Condition_Dump(ni, &cond, 1)){ TR("Conditions", "%s", cond); } free(cond); - flags = edg_wll_stat_flags_to_string(ni->flags); - TR("Flags", "%s", flags); - free(flags); *message = b; - printf("Returning message: %s\n", a); return 0; } @@ -178,22 +173,27 @@ int edg_wll_JobStatusToText(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat asprintf(&a, "%sstateEnterTime=%s", b, ctime(&time)); free(b); b = a; } + else{ + asprintf(&a, "%sstateEnterTime=", b); + free(b); b = a; + } if ( (stat.lastUpdateTime.tv_sec) || (stat.lastUpdateTime.tv_usec) ) { time_t time = stat.lastUpdateTime.tv_sec; //TR("Last_update","%s",ctime(&time)); asprintf(&a, "%slastUpdateTime=%s", b, ctime(&time)); free(b); b = a; } + else{ + asprintf(&a, "%slastUpdateTime=", b); + free(b); b = a; + } TR("expectUpdate","%s",stat.expectUpdate ? "YES" : "NO"); TR("expectFrom","%s",stat.expectFrom); TR("location","%s",stat.location); TR("destination","%s",stat.destination); TR("cancelling","%s",stat.cancelling>0 ? "YES" : "NO"); - if (stat.cancelReason != NULL) { - TR("cancelReason","%s",stat.cancelReason); - } + TR("cancelReason","%s",stat.cancelReason); TR("cpuTime","%d",stat.cpuTime); - TR("done_code","%d",stat.done_code); TR("exit_code","%d",stat.exit_code); @@ -203,7 +203,12 @@ int edg_wll_JobStatusToText(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat asprintf(&jdl,"jdl=%s\n", my_jdl); free(my_jdl); } - if (stat.rsl) asprintf(&rsl,"rsl=%s\n", stat.rsl); + else + asprintf(&jdl,"jdl=\n"); + if (stat.rsl) + asprintf(&rsl,"rsl=%s\n", stat.rsl); + else + asprintf(&rsl,"rsl=\n"); asprintf(&a, "Job=%s\n" "%s" diff --git a/org.glite.lb.server/src/pretty_print_wrapper.cpp b/org.glite.lb.server/src/pretty_print_wrapper.cpp new file mode 100644 index 0000000..df7c806 --- /dev/null +++ b/org.glite.lb.server/src/pretty_print_wrapper.cpp @@ -0,0 +1,24 @@ +#include "pretty_print_wrapper.h" + +#include +#include +#include + +int pretty_print(char *jdl, char **formated_print){ + ClassAd *classad; + ClassAdParser parser; + + classad = parser.ParseClassAd(std::string(jdl), true); + if (! classad){ + *formated_print = NULL; + return -1; // not ClassAd data + } + + PrettyPrint pp; + std::string buf; + pp.Unparse(buf, classad); + *formated_print = strdup(buf.c_str()); + + return 0; +} + -- 1.8.2.3