New jobid module megaupdate (replaced strmd5 by str2md5, work on ++ magic, ...).
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 21 Sep 2006 17:56:35 +0000 (17:56 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 21 Sep 2006 17:56:35 +0000 (17:56 +0000)
org.glite.lb-utils.jobid/Makefile
org.glite.lb-utils.jobid/interface/Exception.h [new file with mode: 0644]
org.glite.lb-utils.jobid/interface/JobId.h [new file with mode: 0644]
org.glite.lb-utils.jobid/interface/JobIdExceptions.h [new file with mode: 0644]

index e05e3e7..986b5e0 100644 (file)
@@ -30,7 +30,7 @@ INSTALL:=libtool --mode=install install
 OBJS:=cjobid.o strmd5.o
 LOBJS:=${OBJS:.o=.lo}
 
-HDRS:=cjobid.h strmd5.h
+HDRS:=cjobid.h strmd5.h Exception.h JobId.h JobIdExceptions.h
 
 STATICLIB:=libglite_lbu_jobid.a
 LTLIB:=libglite_lbu_jobid.la
diff --git a/org.glite.lb-utils.jobid/interface/Exception.h b/org.glite.lb-utils.jobid/interface/Exception.h
new file mode 100644 (file)
index 0000000..21a9064
--- /dev/null
@@ -0,0 +1,138 @@
+#ifndef  GLITE_WMS_UTILS_EXCEPTION_EXCEPTION_H
+#define GLITE_WMS_UTILS_EXCEPTION_EXCEPTION_H
+
+/*
+ * Exception.h
+ * Copyright (c) 2001 The European Datagrid Project - IST programme, all rights reserved.
+ * Contributors are mentioned in the code where appropriate.
+ */
+
+#include <fstream>
+#include <cstdlib>
+//#include <list>
+#include <syslog.h>  // For logging exceptions to log file
+#include <errno.h> // list the exception codes
+#include <string>
+#include <vector>
+#include <exception> // base ancestor stl::exception
+
+
+namespace glite {
+       namespace lb_utils {
+               namespace exception {
+
+extern pthread_mutex_t METHOD_MUTEX; //  used in order to store info into a file (rather then syslog)
+#define GLITE_STACK_TRY(method_name) std::string METHOD = method_name ;  int LINE = __LINE__ ; try {
+#define GLITE_STACK_CATCH() } catch (glite::lb_utils::exception::Exception &exc){ exc.push_back ( __FILE__ , LINE,  METHOD ); throw exc ;  } catch (std::exception &ex){ glite::lb_utils::exception::Exception exc( __FILE__ , LINE,  METHOD, 0, "Standard exception: " + std::string(ex.what()) ); throw exc; }
+
+/**
+ * The Exception base classe contains attributes into which are placed exception information and provides
+ * constructor that beyond the error code take parameters specifying the source file and line number
+ * (e.g. through __FILE__ and __LINE__) where the error has been generated and string messages,
+ * allowing an easy way of storing the origin of the exception.
+ * Moreover it provides methods for getting all the exception information and for logging them either
+ * in a log file or to the syslog daemon.
+ * Each of the derived types may contain its private attributes describing the actual error instance in detail.
+ * Moreover each exception has an attribute representing the exception identifier that is set by the
+ * class constructor and allows the identification of the original exception.
+ *
+ * @version 0.1
+ * @date 22 July 2004
+ * @author Alessandro Maraschini <alessandro.maraschini@datamat.it>
+*/
+
+class Exception : public std::exception{
+   public:
+       /**
+       *  Constructor Update all mandatory fields
+       * @param method the name of the method that raised the exception
+       * @param source The source that raised the exception (could be the file path, the class Name, etc etc)
+       * @param  exc the previous exception as in the stack trace */
+       Exception (  const std::string& source,  const std::string& method,  Exception *exc);
+       /**
+       *  Constructor Update all mandatory fields
+       * @param code the code representing the thrown exception
+       * @param exception the name of the thrown exception
+       * @param method the name of the method that raised the exception
+       * @param source The source that raised the exception (could be the file path, the class Name, etc etc) */
+       Exception ( const std::string& source, const std::string& method,  int code,  const std::string& exception);
+
+       /**
+       *  Constructor Update all mandatory fields
+       * @param source the path of the file that raised the exception
+       * @param line_number the number of the line in the file that raised the exception
+       * @param method the name of the method that raised the exception
+       * @param code the code representing the thrown exception
+       * @param exception the name of the thrown exception */
+       Exception (const std::string& source,  int line_number,   const std::string& method,  int code,  const std::string& exception);
+       /**
+       * Default Destructor
+       */
+       virtual ~Exception() throw ();
+       /**
+       *  Return a string debug message containing information about Exception thrown
+       * Debug message contains all the attributes stored in an exception instance such as the method, the file and the line
+       * that threw the exception.
+       *@return the debug message string representation
+       */
+       virtual std::string dbgMessage();
+       /**
+       *  Return the error code
+       * @return The integer representing the code of the error that generated the exception
+       */
+       virtual int getCode();
+
+       /**
+       * return the Error Message associated to the Exception
+       * @return The Exception string message representation
+       */
+       virtual const char* what() const  throw ();
+
+       /**
+       *  Print Exception error information into a log file
+       * @param logfile the file where to log exception information
+       */
+       virtual void log(const std::string& logfile = "");
+       /**
+       *   Retrieve the Exception name
+       * @return the name of the Exception thrown
+       */
+       virtual std::string getExceptionName();
+
+       /**
+       *   Retrieve the Stack of the exception as a list of previous generated exceptions
+       *@return the string representation of the stack trace: each line correspond to an exception message
+       */
+       virtual std::string printStackTrace() ;
+       /**
+       *   Return the list of methods that caused the Exception
+       */
+       virtual std::vector<std::string> getStackTrace() ;
+       /**
+       * Update stack information
+       */
+       virtual void push_back (  const std::string& source, int line_number,  const std::string& method   ) ;
+  protected:
+               /** Empty constructor*/
+               Exception();
+               /**  integer error code representing the cause of the error */
+               int                   error_code;
+               /**  string exception message representation*/
+               std::string          error_message ;
+               /**  line number where the exception was raised */
+               int                   line;
+               /** The name of the file where the exception was raised */
+               std::string          source_file;
+               /** the name of the exception */
+               std::string          exception_name;
+               /** the name of the method where the expceiton was raised */
+               std::string          method_name ;
+               /** a string representation of the stacktrace */
+               std::string          stack;
+               /** the actual internal stacktrace representation */
+               std::vector< std::string> stack_strings ;
+               /** the name of the ancestor exception */
+               std::string          ancestor ;
+}; //End  Exception Class
+}}}  // Closing namespace
+#endif
diff --git a/org.glite.lb-utils.jobid/interface/JobId.h b/org.glite.lb-utils.jobid/interface/JobId.h
new file mode 100644 (file)
index 0000000..b99992d
--- /dev/null
@@ -0,0 +1,126 @@
+#ifndef GLITE_WMSUTILS_JOBID_JOBID_H
+#define GLITE_WMSUTILS_JOBID_JOBID_H
+
+/*
+ * JobId.h
+ * Copyright (c) 2001 The European Datagrid Project - IST programme, all rights reserved.
+ *
+ */
+
+#include <string>
+#include <iosfwd>
+
+#include "glite/lb-utils/cjobid.h"
+
+typedef struct _glite_lbu_jobid_s* glite_lbu_jobid_t;
+
+namespace glite { 
+namespace lb_utils {
+namespace jobid {
+
+/**
+ * Managing Identification, checking, retreiving info from a job
+ * File name: JobId.h
+ * The JobId class provides a representation of the Datagrid job identifier
+ * (dg_jobId) and the methods for manipulating it.
+ * We remind that the format of the dg_jobId is as follows:
+ * <LB address>:<LB port>/<Unique String>
+ *
+ * @ingroup common
+ * @version 0.1
+ * @date 15 April 2002
+ * @author Alessandro Maraschini <alessandro.maraschini@datamat.it>  */ 
+
+class JobId {
+public:
+    /**@name Constructors/Destructor */
+    //@{
+    /** Instantiates an empty  JobId object */
+    JobId() ;
+    /**
+     * Instantiates a JobId object from the passed dg_jobId in string format.
+     * @param  job_id_string a string representig a classAd expression
+     * @throws  WrongIdException When a string is passed in a wrong format
+     */
+    JobId(const std::string& job_id_string);
+    JobId(const JobId&);
+    JobId(const glite_lbu_JobId&);
+    /**
+     * Destructor
+     * Destroy the Job Id instance
+     */
+    ~JobId() ;
+  //@}
+
+    /**@name Miscellaneous  */
+    //@{
+    /** Unsets the JobId instance. Clear all it's memebers */
+    void clear() ;
+    /**
+     * Check wheater the jobId has been already created (true) or not (false)
+     *@return  true (jobId created) or false (jobId not yet created)
+     */
+    bool isSet() { return ( m_JobId != 0 ) ; }
+    /**
+     * Set the JobId instance according to the LB and RB server addresses and the unique string passed as input parameters.
+     * @param lb_server  Loggin and Bookkeeping server  address
+     * @param port Loggin and Bookkeeping port ( dafault value is 9000 )
+     * @param  unique A Unique identification ( automatically generatad by md5 protocol )
+     * @throws  WrongIdException  When one parameter has been passed in a wrong format  */
+    void setJobId(const std::string& lb_server, int port = 0, const std::string& unique = "");
+  //@}
+    /**@name Get Methods */
+  //@{
+    /** @return the LB address  into its string format
+    * @throws  EmptyIdException  If the jobId has not been initialised yet */
+    std::string getServer() const;
+    /** @return the Unique string into its string format
+    * @throws  EmptyIdException  If the jobId has not been initialised yet */
+    std::string getUnique() const;
+  //@}
+    /** This method sets the JobId instance from the JobId in string format given
+    * as input.
+    * @param dg_JobId the string representing the job
+    * @throws  WrongIdException  When a string is passed in a wrong format */
+    void fromString ( const std::string& dg_JobId );
+    /** Converts the jobId into a string
+    @return the string representation of a JobId*/
+    std::string toString() const;
+    /** casting operator */
+    operator const glite_lbu_JobId() const { return m_JobId; }
+    /** Operator "=" create a deep copy of the JobId instance*/
+    JobId & operator=(JobId const &);
+    /** Operator "=" create a deep copy of the JobId instance*/
+    JobId & operator=(const glite_lbu_JobId &);
+    /** Retrieve the internal id reference 
+    *@return the JobId internal reference used by some LB methods */
+    glite_lbu_JobId  getId() const ;
+private:
+    // This Variable stores the Job unique identification String
+    glite_lbu_JobId m_JobId;
+    mutable char* m_pStr;
+    mutable char* m_pBkserver;
+    mutable char* m_pUnique;
+    /** Operator "<"*/
+    friend bool operator<(JobId const& lhs, JobId const& rhs);
+    /** Operator "=="*/
+    friend bool operator==(JobId const& lhs, JobId const& rhs);
+};
+
+inline bool operator<(JobId const& lhs, JobId const& rhs)
+{
+  return    strcmp ( lhs.m_pStr , rhs.m_pStr )  <0 ;
+}
+
+inline bool operator==(JobId const& lhs, JobId const& rhs)
+{
+return     strcmp ( lhs.m_pStr , rhs.m_pStr ) ==0 ;
+}
+
+std::ostream& operator<<(std::ostream& os, JobId const& id);
+
+} // namespace jobid
+} // namespace lb_utils
+} // namespace glite
+
+#endif // GLITE_WMSUTILS_JOBID_JOBID_H
diff --git a/org.glite.lb-utils.jobid/interface/JobIdExceptions.h b/org.glite.lb-utils.jobid/interface/JobIdExceptions.h
new file mode 100644 (file)
index 0000000..d154adf
--- /dev/null
@@ -0,0 +1,80 @@
+#ifndef GLITE_WMSUTILS_JOBID_EXCEPTIONS_H
+#define GLITE_WMSUTILS_JOBID_EXCEPTIONS_H
+
+/*
+ * JobIdExceptions.h
+ * Copyright (c) 2001 The European Datagrid Project - IST programme, all rights reserved.
+ */
+
+#include "glite/lb-utils/Exception.h"
+
+namespace glite { 
+namespace lb_utils { 
+namespace jobid {
+
+/**
+ * JobIdException - Exception thrown by JobId Class
+ * @ingroup Common
+ * @version 0.1
+ * @date 15 April 2002
+ * @author Alessandro Maraschini <alessandro.maraschini@datamat.it>
+*/
+
+class JobIdException : public glite::lb_utils::exception::Exception {
+public:
+    /**
+     * Update all mandatory Exception Information
+     */
+  JobIdException (const std::string& file,
+                                   int line,
+                                   const std::string& method,
+                                   int code,
+                                   const std::string& exception_name) ;
+};//End CLass  JobIdException
+
+/**
+* WrongIdFieldException
+* This Exception is thrown when a Job Id syntax error is found
+* A valid Job Identification string should be made as follows:
+* <LB address>:<LB port>/ <Unique string> */
+class  WrongIdException  : public JobIdException {
+public:
+  /**
+  * Constructor
+  * @param file - The source file which has generated the Exception
+  * @param line - The line number in the source file where the Exception has been thrown
+  * @param method - The Name of the method which has thrown the Exception
+  * @param code - The Code of the Error raised
+  * @param field - The wrong expression catched */
+    WrongIdException(const std::string& file,
+                                      int line,
+                                      const std::string& method,
+                                      int code );
+}; //End CLass WrongIdException
+/**
+*  EmptyIdException
+* This Exception is thrown when the user tries to get information from a JobId
+* which has not been initialized yet, i.e tries to use the get<field name> Methods
+*/
+class EmptyIdException : public JobIdException {
+public:
+  /**
+  * Constructor
+  * @param file - The source file which has generated the Exception
+  * @param line - The line number in the source file where the Exception has been thrown
+  * @param method - The Name of the method which has thrown the Exception
+  * @param code - The Code of the Error raised
+  * @param field - The Empty filed requested for */
+    EmptyIdException::EmptyIdException(const std::string& file,
+                                      int line,
+                                      const std::string& method,
+                                      int code ,
+                                      const std::string& field );
+}; //End CLass EmptyIdException
+
+} // namespace jobid
+} // namespace lb_utils
+} // namespace glite
+
+#endif // GLITE_WMSUTILS_JOBID_EXCEPTIONS_H
+