resurrected c++ example
authorAleš Křenek <ljocha@ics.muni.cz>
Tue, 24 Jul 2007 13:15:59 +0000 (13:15 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Tue, 24 Jul 2007 13:15:59 +0000 (13:15 +0000)
org.glite.lb.client/Makefile
org.glite.lb.client/examples/job_status_plus.cpp [new file with mode: 0644]

index 9f4b867..400530a 100644 (file)
@@ -96,9 +96,6 @@ TEST_LIBS:=-L${cppunit_prefix}/lib -lcppunit
 TEST_INC:=-I${cppunit_prefix}/include
 
 
-LDFLAGS:=-L${stagedir}/lib \
-       ${COVERAGE_FLAGS}
-
 COMPILE:=libtool --mode=compile ${CC} ${CFLAGS}
 CXXCOMPILE:=libtool --mode=compile ${CXX} ${CXXFLAGS}
 LINK:=libtool --mode=link ${CC} ${LDFLAGS} 
@@ -140,9 +137,24 @@ EXAMPLES_CL=user_jobs job_status
 EXAMPLES_CL_THR=user_jobs_threaded
 FAKE_EXAMPLES:=job_log_fake
 
+EXAMPLES_PLUS= job_status_plus
+# EXAMPLES_PLUS= indexed_attrs_plus.cpp  job_status_plus.cpp  query_events_plus.cpp listener.cpp         user_jobs_plus.cpp job_log_plus.cpp        notify_plus.cpp
+
+
 MAN_GZ:=glite-lb-logevent.1.gz
 MAN = $(MAN_GZ:.gz=)
 
+archlib:=lib
+LDFLAGS:=-L${stagedir}/lib
+host_cpu:=${shell uname -m}
+ifeq (${host_cpu},x86_64)
+    archlib:=lib64
+    LDFLAGS:=-L${stagedir}/lib ${COVERAGE_FLAGS}
+endif
+
+PLUS_EXTRA_LIB:=-lglite_wmsutils_jobid -lglite_wmsutils_exception
+
+
 # version_info=-version-info `echo ${version} | cut -d. -f1,2 | tr . :`
 
 # counted minor versions: 
@@ -174,10 +186,10 @@ ${FAKETHRLIB}: ${FAKELIBTHROBJS}
                        -lglite_security_gss_${thrflavour}
 
 ${PLUSLIB}: ${PLUSOBJS}
-       ${LINK} ${version_info} -o $@ ${PLUSLOBJS} -rpath ${PREFIX}/lib ${LIB}
+       ${LINKXX} ${version_info} -o $@ ${PLUSLOBJS} -rpath ${PREFIX}/lib ${LIB}
 
 ${THRPLUSLIB}: ${PLUSTHROBJS}
-       ${LINK} ${version_info} -o $@ ${PLUSTHRLOBJS} -rpath ${PREFIX}/lib ${THRLIB}
+       ${LINKXX} ${version_info} -o $@ ${PLUSTHRLOBJS} -rpath ${PREFIX}/lib ${THRLIB}
 
 logevent: logevent.o args.o
        ${LINK} -o $@ logevent.o args.o ${LIB} ${EXT_LIB} 
@@ -205,6 +217,9 @@ ${PLUSOBJS}: %.o: %.cpp
 ${PLUSTHROBJS}: %.thr.o: %.cpp
        ${CXXCOMPILE} ${GLOBUSTHRINC} -o $@ -c $<
 
+${EXAMPLES_PLUS}: %: %.o ${PLUSLIB}
+       ${LINKXX} -o $@ $< ${PLUSLIB} ${PLUS_EXTRA_LIB}
+
 ${LIBOBJS} ${FAKELIBOBJS}: %.o: %.c
        ${COMPILE} ${GLOBUSINC} -c $<
 
@@ -226,6 +241,9 @@ perftest_logjobs.o: perftest_logjobs.c
 %.o: %.c 
        ${CC} ${CFLAGS} ${GLOBUSINC} -c $<
 
+%.o: %.cpp
+       ${CXX} ${CFLAGS} ${GLOBUSINC} -c $<
+
 %.c: %.c.T
        rm -f $@
        ${AT3} $< >$@ || rm -f $@
diff --git a/org.glite.lb.client/examples/job_status_plus.cpp b/org.glite.lb.client/examples/job_status_plus.cpp
new file mode 100644 (file)
index 0000000..3218766
--- /dev/null
@@ -0,0 +1,176 @@
+#include <iostream>
+#include <utility>
+#include <vector>
+
+#include <sys/time.h>
+#include <unistd.h>
+
+#include "glite/wmsutils/jobid/JobId.h"
+#include "glite/lb/Job.h"
+#include "glite/wmsutils/exception/Exception.h"
+#include "glite/lb/LoggingExceptions.h"
+
+using namespace glite::lb;
+using namespace std;
+
+
+/* print results */
+static void printStatus(JobStatus &stat);
+
+
+int main(int argc,char *argv[])
+{
+
+       try {
+
+       JobStatus jobStatus;
+
+/* connect to server */
+       ServerConnection server;
+
+/* get status of the job */
+       if (argc < 2 ||  strcmp(argv[1],"--help") == 0) {
+               cout << "Usage : " << argv[0] << " job_id [job_id [...]]" << endl;
+               cout << "        " << argv[0] << " -all server[:port] [limit]" << endl;
+               return 1;
+       }
+       else    if (argc >= 2 && strcmp(argv[1],"-all") == 0) {
+               std::vector<JobStatus> jobStates;
+
+               std::vector<QueryRecord> q(1,QueryRecord(QueryRecord::OWNER,QueryRecord::EQUAL,""));
+
+
+               if (argc > 2) {
+                       char    *sc = strdup(argv[2]),*p;
+
+
+                       strtok(sc,":");
+                       p = strtok(NULL,":");
+
+                       server.setParam(EDG_WLL_PARAM_QUERY_SERVER,sc);
+                       if (p) server.setParam(EDG_WLL_PARAM_QUERY_SERVER_PORT,atoi(p));
+               }
+               
+
+               if (argc > 3) server.setParam(EDG_WLL_PARAM_QUERY_JOBS_LIMIT,atoi(argv[3]));
+               
+               try {
+                       server.queryJobStates(q, 0, jobStates);
+               } catch (LoggingException &e) {
+                       if (e.getCode() == E2BIG && 
+                               server.getParamInt(EDG_WLL_PARAM_QUERY_RESULTS) == EDG_WLL_QUERYRES_LIMITED)
+                       {
+                               cerr << e.dbgMessage() << endl;
+                               cout << "WARNING: Output truncated (soft limit = " <<
+                                       server.getParamInt(EDG_WLL_PARAM_QUERY_JOBS_LIMIT) << ")" << endl; 
+                       }
+                       else throw;
+               }
+
+               cout << "Number of jobs: " << jobStates.size() << endl;
+               cout << endl;
+
+               std::vector<JobStatus>::iterator i = jobStates.begin();
+               while (i != jobStates.end()) printStatus(*i++);
+       }
+       else {  
+               Job job;
+               for (int i=1; i < argc; i++) {
+                       try {
+                               glite::wmsutils::jobid::JobId jobId(argv[i]);
+               
+                               job = jobId;
+                               jobStatus = job.status(Job::STAT_CLASSADS);
+                               printStatus(jobStatus);
+                       } catch (glite::wmsutils::exception::Exception &e) {
+                               cerr << e.dbgMessage() << endl;
+                       }
+
+               }
+       }
+
+       }
+       catch (glite::wmsutils::exception::Exception &e) {
+               cerr << e.dbgMessage() << endl;
+       }
+}
+
+
+static void printStatus(JobStatus &stat) {
+       std::vector<pair<JobStatus::Attr, JobStatus::AttrType> > attrList = stat.getAttrs();            
+       cout << "status: " << stat.name() << endl;
+       for (unsigned i=0; i < attrList.size(); i++ ) {
+               cout << stat.getAttrName(attrList[i].first) << " = " ;
+       
+               switch (attrList[i].second) {
+
+               case JobStatus::INT_T: 
+                       cout << stat.getValInt(attrList[i].first) << endl; 
+                       break;
+
+               case JobStatus::STRING_T: 
+                       cout << stat.getValString(attrList[i].first) << endl; 
+                       break;
+
+               case JobStatus::TIMEVAL_T: 
+               { 
+                       timeval t = stat.getValTime(attrList[i].first);
+                       cout << t.tv_sec << "." << t.tv_usec << " s " << endl; 
+               }
+               break;
+
+               case JobStatus::JOBID_T:
+                       if(((glite::wmsutils::jobid::JobId)stat.getValJobId(attrList[i].first)).isSet())
+                               cout << stat.getValJobId(attrList[i].first).toString();
+                       cout << endl;
+                       break;
+
+               case JobStatus::INTLIST_T: 
+               {
+                       std::vector<int> v = stat.getValIntList(attrList[i].first);
+                       for(unsigned int i=0; i < v.size(); i++) 
+                               cout << v[i] << " ";
+                       cout << endl;
+               }
+               break;
+
+               case JobStatus::STRLIST_T:
+               {
+                       std::vector<std::string> v = stat.getValStringList(attrList[i].first);
+                       for(unsigned int i=0; i < v.size(); i++)
+                               cout << v[i] << " ";
+                       cout<< endl;
+               }
+               break;
+
+               case JobStatus::TAGLIST_T:
+               {
+                       std::vector<std::pair<std::string, std::string> > v = stat.getValTagList(attrList[i].first);
+                       for(unsigned int i=0; i < v.size(); i++)
+                               cout << v[i].first << "=" << v[i].second << " ";
+                       cout<< endl;
+               }
+               break;
+
+               case JobStatus::STSLIST_T:
+               {
+                       std::vector<JobStatus> v = stat.getValJobStatusList(attrList[i].first);
+                       for(unsigned int i=0; i < v.size(); i++)
+                               cout << v[i].name() << " ";
+                       cout << endl;
+               }
+               break;
+
+               case JobStatus::BOOL_T:
+                       cout << stat.getValBool(attrList[i].first) << endl;
+                       break;
+
+               default : /* something is wrong */ 
+                       cout << " ** attr type " 
+                            << attrList[i].second 
+                            << " not handled" << endl;
+                       break;
+               }
+       }
+       cout << endl;
+}