New formating of HTML and text interface.
authorJiří Filipovič <fila@ics.muni.cz>
Fri, 5 Jun 2009 11:42:50 +0000 (11:42 +0000)
committerJiří Filipovič <fila@ics.muni.cz>
Fri, 5 Jun 2009 11:42:50 +0000 (11:42 +0000)
org.glite.lb.server/Makefile
org.glite.lb.server/interface/pretty_print_wrapper.h [new file with mode: 0644]
org.glite.lb.server/src/lb_html.c
org.glite.lb.server/src/lb_text.c
org.glite.lb.server/src/pretty_print_wrapper.cpp [new file with mode: 0644]

index 8e63577..4081506 100644 (file)
@@ -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 (file)
index 0000000..e99a2af
--- /dev/null
@@ -0,0 +1,10 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int pretty_print(char *jdl, char **formated_print);
+
+#ifdef __cplusplus
+}
+#endif
+
index 5cc88ce..30f3cad 100644 (file)
@@ -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,"<tr><th align=\"left\">" name ":</th>" \
-               "<td>" type "</td></tr>", (field)); \
-               pomB = realloc(pomB, sizeof(*pomB)*(pomL+l+1)); \
-               strcpy(pomB+pomL, pomA); \
-               pomL += l; \
-               free(pomA); pomA=NULL; \
-       }
+               l = asprintf(&pomA,"<tr><th align=\"left\">" name ":</th>" \
+                       "<td>" type "</td></tr>", (field)); \
+       } \
+       else{ \
+               l = asprintf(&pomA,"<tr><th align=\"left\"><span style=\"color:grey\">" name \
+                       "</span></th></tr>"); \
+       } \
+       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<h3>Conditions</h3>\r\n<pre>%s</pre>\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, "<html>\r\n\t<body>\r\n"
                "<h2>Notification %s</h2>\r\n"
                "<table halign=\"left\">%s</table>"
@@ -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,"<h3>Job description</h3>\r\n"
-               "<pre>%s</pre>\r\n",stat.jdl);
+       if (stat.jdl){
+               char *jdl_unp;
+               if (pretty_print(stat.jdl, &jdl_unp) == 0)
+                       asprintf(&jdl,"<h3>Job description</h3>\r\n"
+                                "<pre>%s</pre>\r\n",jdl_unp);
+               else
+                       asprintf(&jdl,"<h3>Job description (not a ClassAd)"
+                               "</h3>\r\n<pre>%s</pre>\r\n",stat.jdl);
+       }
 
        if (stat.rsl) asprintf(&rsl,"<h3>RSL</h3>\r\n"
                "<pre>%s</pre>\r\n",stat.rsl);
index 7bd1e49..510441c 100644 (file)
@@ -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 (file)
index 0000000..df7c806
--- /dev/null
@@ -0,0 +1,24 @@
+#include "pretty_print_wrapper.h"
+
+#include <classad_distribution.h>
+#include <string>
+#include <string.h>
+
+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;
+}
+