[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gridcpr group progress



On Mon, 4 Aug 2003, Thilo Kielmann wrote:

> Who can point to existing APIs that do (part of) the intended functionality?

Please find attached the header files for the Grid Checkpointing
service implemented in the European DataGrid (EDG) project
(start reading checkpointing.h, which includes all the other needed
files).


As we already presented, in the EDG Grid Checkpointing framework, the idea
is to provide users with a "trivial" job checkpointing service: through
the API described in these header files,  a user can save at any moment
during the execution of a job, the state of this job (and it is up to
him/her to define what is a state). The hypothesis is, of course,
that the job can be restarted from an "intermediate" (i.e. previously
saved) state.

More information can be found at:

http://edms.cern.ch/document/347730


				Cheers, Massimo

             \\\|///
            \\ ~ ~ //
            (/ @ @ /)
   -------oOOo-(_)-oOOo----------------------------------
                              Massimo Sgaravatto
                              INFN Sezione di Padova
                              Via Marzolo, 8
                              35131 Padova - Italy
                              Tel: ++39 0498277047   Fax: ++39 0498277102
          oooO                E-mail: massimo.sgaravatto@pd.infn.it
          (   )   Oooo        Home page: http://www.pd.infn.it/~sgaravat
   --------\ (----(   )----------------------------------
            \_)    ) /
                  (_/

// File: checkpointing.h
// Author: Alessio Gianelle <gianelle@pd.infn.it>
// Copyright (c) 2002 EU DataGrid.
// For license conditions see http://www.eu-datagrid.org/license.html

// $Id: checkpointing.h,v 1.15 2002/12/20 14:43:29 gianelle Exp $

/**
 * \file
 * \brief Provides an API to realize a trivial checkpointing service. 
 * 
 * With "trivial checkpoint" we mean the possibility for the user to 
 * save and to manage a well-defined State object which describes the 
 * job and what it has done until the moment in which the State object 
 * is saved. It is also possible to restart a job from an intermediate 
 * point using a previously saved State.
 * \see http://edms.cern.ch/document/347730/1 
 *
 * \version 0.2
 * \date 18 December 2002
 * \author Alessio Gianelle <gianelle@pd.infn.it>
*/

#ifndef EDG_WORKLOAD_CHECKPOINTING_CHKPT_H
#define EDG_WORKLOAD_CHECKPOINTING_CHKPT_H

#include <edg/workload/checkpointing/client/step.h>
#include <edg/workload/checkpointing/client/stepper.h>
#include <edg/workload/checkpointing/client/jobstate.h>
#include "edg/workload/checkpointing/client/ChkptException.h"

#endif // EDG_WORKLOAD_CHECKPOINTING_CHKPT_H

//  Local Variables:
//  mode: c++
//  End:










// File: step.h
// Author: Alessio Gianelle <gianelle@pd.infn.it>
// Copyright (c) 2002 EU DataGrid.
// For license conditions see http://www.eu-datagrid.org/license.html

// $Id: step.h,v 1.2 2002/12/20 14:43:29 gianelle Exp $

/**
 * \file
 * \brief Provides the Step Object. 
 *
 * \version 0.1
 * \date 18 December 2002
 * \author Alessio Gianelle <gianelle@pd.infn.it>
*/

#ifndef EDG_WORKLOAD_CHECKPOINTING_STEP_H
#define EDG_WORKLOAD_CHECKPOINTING_STEP_H

#include <edg/workload/checkpointing/client/checkpointing_namespace.h>
#include <string>

CHKPT_NAMESPACE_BEGIN { 

  /**      
   * \brief Provides the label of a single step.
   */
  class Step {
    
  public:
    /** Provides the type of the label. */
    enum step_type { 
      integer,  /**< Numeric label. */
      label     /**< String label. */
    };
    /** \name  Constructors Destructor */ 
    /// @{ 
    /** Instantiates a Step object from a numeric label.
	\param istep - An int representing the label. */	
    Step( int istep );
    /** Instantiates a Step object from a string label.
	\param sstep - A string representing the label. */
    Step( const std::string &sstep );
    /** Instantiates a Step object from a char* label.
	\param sstep - A char* representing the label. */
    Step( const char *sstep ); 
    Step( const Step &ss ); /**< The copy constructor method. */
    ~Step( void ); /**< The Destructor method. */ 
    /// @}  
    
    /** \name Check-Type Methods. */
    /// @{
    /** Check if the object represents a string label.
	\return @a true if the label is a string value; @a false otherwise. */ 
    inline bool isLabel( void ) { return( this->s_type == label ); }
    /** Check if the object represents a numeric label.
	\return @a true if the label is a numeric value; @a false otherwise. */ 
    inline bool isInteger( void ) { return( this->s_type == integer ); }
    /// @}
    
    /** \name Get Methods. */
    /// @{
    /** Extracts the value of the numeric label.
	\return an int with the value of the label. 
	\throws WTException */
    int getInteger( void );
    /** extracts the value of the string label.
	\return a string with the value of the label. 
	\throws WTException */
    const std::string &getLabel( void ); 
    /// @}    

    /** \name Operators */
    /// @{
    /** Copy operator.
     	\param that - The Step object to copy.
	\return The current object. */
    Step &operator=( const Step &that );
    /** Int cast operator. 
	\return an int with the value of the label. 
	\throws WTException */
    inline operator int( void ) { return ( getInteger() ); }
     /** String cast operator.
	\return a string with the value of the label. 
	\throws WTException */
    inline operator const std::string &( void ) { return( getLabel() ); }
    /// @}

  private:
    step_type       s_type;     /**< The type of the step label. */ 
    union {                     
      int           s_u_istep;  /**< Numeric label. */
      std::string  *s_u_sstep;  /**< String label. */
    };    
  };

} CHKPT_NAMESPACE_END;

#endif // EDG_WORKLOAD_CHECKPOINTING_STEP_H

//  Local Variables:
//  mode: c++
//  End:
// File: stepper.h
// Author: Alessio Gianelle <gianelle@pd.infn.it>
// Copyright (c) 2002 EU DataGrid.
// For license conditions see http://www.eu-datagrid.org/license.html

// $Id: stepper.h,v 1.5 2003/07/16 13:05:46 gianelle Exp $

/**
 * \file
 * \brief Provides the StepsSet object. 
 *
 * \version 0.1
 * \date 18 December 2002
 * \author Alessio Gianelle <gianelle@pd.infn.it>
*/

#ifndef EDG_WORKLOAD_CHECKPOINTING_STEPPER_H
#define EDG_WORKLOAD_CHECKPOINTING_STEPPER_H

#include <vector>
#include <string>
#include <edg/workload/checkpointing/client/checkpointing_namespace.h>

CHKPT_NAMESPACE_BEGIN { 

  /**
   *  \brief Provides the iterator.
   *  There could be two types of iterators: a numeric stepper and a string stepper.
   * 
   *  The numeric iterator is defined through a numeric range which is
   *  described through two number: the last (the biggest) number, and
   *  the current step. In this case the iterator represents all the
   *  naturals numbers between the current step and the last one.
   *  Otherwise an iterator could be described through a list of
   *  string, if this is the case every steps is identified through a
   *  string label.  */
  
  class StepsSet {
    
  public:
    /** Provides the type of the iterator. */
    enum iterator_type { 
      integer,    /**< Identify a numeric iterator. */
      label       /**< Identify a string iterator. */
    }; 
    
    /** \name Constructors Destructor */ 
    /// @{
    /** Instantiates a StepsSet object with a string type iterator.
	\param llabel - A vector of strings that define all the names of the labels.
	\param cstep - The index of the \a current step. \b Default value is 0, which
        means the first label. */
    StepsSet( const std::vector<std::string>& llabel, int cstep = 0 );   
    /** Instantiates a StepsSet object with a numeric type iterator.
	\param last  - An int with the last step. 
	\param cstep - The index of the \a current step. \b Default value is 0. */
    StepsSet( int last, int cstep = 0);
    /// @}

    /** \name Initialize methods */
    /// @{
    /** Initialize a StepsSet object from a vector of strings. 
	\param llabel - A vector of strings that define all the names of the labels.
	\param cstep - The index of the \a current step. */
    void initialize( const std::vector<std::string>& llabel, int cstep );
    /** Initialize a StepsSet object as a numeric type iterator.
	\param last - An int with the last step. 
	\param step - The index of the \a current step. */
    void initialize( int last, int step );
    /// @}

    /** \name Get Methods */
    /// @{
    /** Gets the value of the next numeric step. 
	\return An int with the value of the next step.
	\throw  EoSException - When the range is finished. */
    int getNextInt( void ); 
    /** Gets the value of the next label (string) step. 
	\return A string with the value of the next step.
	\throw  EoSException - When the range is finished. */
    const std::string getNextLabel( void );
    /** Gets the value of the current numeric step. 
	\return An int with the value of the current step. 
	\throw  EoSException - When the range is finished. */
    int  getCurrentInt( void );
    /** Gets the value of the current label (string) step. 
	\return A string with the value of the current step.
	\throw  EoSException - When the range is finished. */
    const std::string getCurrentLabel(void );
    /// @}

    /** \name Check-Type methods */
    /// @{
    /** Check if the iterator is a numeric one.
	\return @a true if the iterator is numeric; @a false otherwise. */ 
    inline bool isInt( void ) { return ( this->ss_ittype == integer ); }
    /** Check if the iterator is a list of strings labels.
	\return @a true if the iterator is a list of strings labels; @a false otherwise. */ 
    inline bool isLabel( void ) { return ( this->ss_ittype == label ); }
    /// @}

    /** \name Miscellaneous methods */
    /// @{
    /** Clean the list of labels */
    inline void clear( void ) { this->ss_steps.clear(); } 
    /** Get the <em>numeric index</em> of the current label.
	\return An int with the index of the current label. */
    inline int  getCurrentIndex( void ) { return this->ss_current; }
    /** Get the last index.
	\return An int with the last index. */
    inline int getLastIndex( void ) { return this->ss_last; }
    /** Get the vector of labels.
	\return A vector if strings with the list of labels. */
    inline std::vector<std::string> getLabelList( void ) { return this->ss_steps; }
    /** Reset the iterator setting it equal to the first index. */
    inline void reset( void ) { this->ss_current = this->ss_first; } 
    /// @}
	
  private:
    int                      ss_first;    /**< The first index of the iterator. */
    int                      ss_last;     /**< The last index of the iterator. */
    int                      ss_current;  /**< The numeric index of the current step (It is equal to the label in a numeric iterator). */
    iterator_type            ss_ittype;   /**< The type of the iterator. */
    std::vector<std::string> ss_steps;    /**< The vector with the list of the strings labels (Not used in a numeric iterator). */
    
  };
  
} CHKPT_NAMESPACE_END;

#endif // EDG_WORKLOAD_CHECKPOINTING_STEPPER_H

//  Local Variables:
//  mode: c++
//  End:
// File: jobstate.h
// Author: Alessio Gianelle <gianelle@pd.infn.it>
// Copyright (c) 2002 EU DataGrid.
// For license conditions see http://www.eu-datagrid.org/license.html

// $Id: jobstate.h,v 1.9 2003/06/04 09:41:00 gianelle Exp $

/**
 * \file
 * \brief Provides the JobState object. 
 *
 * \version 0.1
 * \date 18 December 2002
 * \author Alessio Gianelle <gianelle@pd.infn.it>
*/

#ifndef EDG_WORKLOAD_CHECKPOINTING_JOBSTATE_H
#define EDG_WORKLOAD_CHECKPOINTING_JOBSTATE_H

#include <string>
#include <vector>

#include <edg/workload/checkpointing/client/checkpointing_namespace.h>
#include <edg/workload/checkpointing/client/step.h>
#include <edg/workload/logging/client/context.h>

#include <boost/shared_ptr.hpp>

// classAd include files
#include "classad_distribution.h"


CHKPT_NAMESPACE_BEGIN {
 
class StepsSet;

  /** 
   * \brief Provides the Job State.  
   *
   * From an internal point of view a JobState is described through a
   * ClassAd.  This ClassAd is composed by some privates attributes
   * used inside the EuDataGrid architecture; and by a ClassAds (which
   * contains all the pairs <em> <var, value> </em> define by the
   * user. This is the schema with the right names:
   * 
   * JobState = <br>
   * [ <br>
   *   StateId = "a string with the stateID"; <br>
   *   JobSteps = "the last step (an int) or a list of strings representing the iterator"; <br>
   *   CurrentStep = "an integer which is the \b index of the current step"; <br>
   *   UserData = <br>
   *   [ <br>
   *     "the <var, value> pairs set by the user" <br>
   *   ] <br>
   * ] <br>
   * */
  
  class JobState {
  
  public:

    /** This is an optional argument for the JobState class constructor. */
    typedef enum state_type { 
      empty,  /**< To construct an empty state object. */
      job     /**< To construct and initialize (through an LB query) a state object. */
    };

    /** \name Constructor/Destructor */
    /// @{
    /** Default Constructor. 
	\param type - If not set it create an empty object, otherwise if it is set 
	to \a job it retrieves <b>from the LB</b> the last saved state for that job 
	and creates a new JobState object. 
	\throw SEException If the string defining the classAd is not syntactically correct.
	\throw LFException If some errors occur querying the LB to retrieve the job state.
	\warning Both the exceptions are \b fatal exceptions!  */
    JobState( state_type type = empty );
    /** Construct the object from a string.
	\param state_str a string representig the classAd
	\throw SEException. If the string defining the classAd is not syntactically correct.
        \warning The LB context is not initialized.*/
    JobState( const std::string state_str );
    /** Construct the object from a classAd.
	\param state_ad The classAd
	\throw SEException. If the classAd is not syntactically correct.
        \warning The LB context is not initialized.*/
    JobState( classad::ClassAd *state_ad );
    /** Construct the object from a file.
	\param filename - the file with the classAd
	\throw SEException. If the classAd is not syntactically correct or if the file 
	could not be opened.
        \warning The LB context is not initialized.*/
    JobState( std::istream* file );
    /** Copy Constructors */
    JobState( const JobState &js );
    /**  Copy operator.
	 \param that - The JobState object to copy.
	 \return The current object. */
    JobState &operator=( const JobState &that );
    /** Destructor */
    ~JobState();
    /// @}
  
    /** \name Save value methods. 
	\note A valid identifier for a <var, value> pair begin with an alphabetic character 
	or an underscore, and are followed with any number of alphabetic, numeric, or underscore 
	characters. Identifiers are case-insensitive, but case-preserving.
	\warning If a similarly named expression (case-insensitive) already exists in the 
	UserData set, the old expression is deleted, and the new expression takes its place. */
    /// @{
    /** Saves an int value.
	\param name - A string to identify the name of the attribute to store.
	\param value - A int with the value of the attribute to store.
	\retval CHKPT_SyntaxError if name is not a valid identifier or if value is not set.
	\throw ESException If it is called on an empty JobState object. */
    int saveValue (const std::string& name, int value);
    /** Saves a boolean value.
	\param name - A string to identify the name of the attribute to store.
	\param value - A boolean with the value of the attribute to store.
	\retval CHKPT_SyntaxError if name is not a valid identifier or if value is not set.
	\throw ESException If it is called on an empty JobState object. */
    int saveValue (const std::string& name, bool value);
    /** Saves a double value.
	\param name - A string to identify the name of the attribute to store.
	\param value - A double with the value of the attribute to store.
	\retval CHKPT_SyntaxError if name is not a valid identifier or if value is not set.
	\throw ESException If it is called on an empty JobState object. */
    int saveValue (const std::string& name, double value);
    /** Saves a string value.
	\param name - A string to identify the name of the attribute to store.
	\param value - A char* with the value of the attribute to store.
	\retval CHKPT_SyntaxError if name is not a valid identifier or if value is not set.
	\throw ESException If it is called on an empty JobState object. */
    int saveValue (const std::string& name, const char* value);
    /** Saves a string value.
	\param name - A string to identify the name of the attribute to store.
	\param value - A string with the value of the attribute to store.
	\retval CHKPT_SyntaxError if name is not a valid identifier or if value is not set.
	\throw ESException If it is called on an empty JobState object. */
    int saveValue (const std::string& name, const std::string& value);
    /// @}

    /** \name Append value methods.
	Using these methods you can create attributes with list value.
	\warning The type of all values inside the same attribute list must be the same */
    /// @{
    /** Appends an int value to an already set attribute, or creates a new one.
	\param name - A string to identify the name of the attribute.
	\param value - A int with the value of the attribute to append.
	\retval CHKPT_SyntaxError if name is not a valid identifier or if value is not set.
	\retval CHKPT_WrongType if the type mismatched with the type of the already set attribute name.
	\throw ESException If it is called on an empty JobState object. */
    int appendValue (const std::string& name, int value);
    /** Appends a boolean value to an already set attribute, or creates a new one.
	\param name - A string to identify the name of the attribute.
	\param value - A boolean with the value of the attribute to append.
	\retval CHKPT_SyntaxError if name is not a valid identifier or if value is not set.
	\retval CHKPT_WrongType if the type mismatched with the type of the already set attribute name.
	\throw ESException If it is called on an empty JobState object. */
    int appendValue (const std::string& name, bool value);
    /** Appends a double value to an already set attribute, or creates a new one.
	\param name - A string to identify the name of the attribute.
	\param value - A double with the value of the attribute to append.
	\retval CHKPT_SyntaxError if name is not a valid identifier or if value is not set.
	\retval CHKPT_WrongType if the type mismatched with the type of the already set attribute name.
	\throw ESException If it is called on an empty JobState object. */
    int appendValue (const std::string& name, double value);
    /** Appends a string value to an already set attribute, or creates a new one.
	\param name - A string to identify the name of the attribute.
	\param value - A char* with the value of the attribute to append.
	\retval CHKPT_SyntaxError if name is not a valid identifier or if value is not set.
	\retval CHKPT_WrongType if the type mismatched with the type of the already set attribute name.
	\throw ESException If it is called on an empty JobState object. */
    int appendValue (const std::string& name, const char* value); 
    /** Appends a string value to an already set attribute, or creates a new one.
	\param name - A string to identify the name of the attribute.
	\param value - A string with the value of the attribute to append.
	\retval CHKPT_SyntaxError if name is not a valid identifier or if value is not set.
	\retval CHKPT_WrongType if the type mismatched with the type of the already set attribute name.
	\throw ESException If it is called on an empty JobState object. */
    int appendValue (const std::string& name, const std::string& value); 
    /// @}


    /** \name Get value methods. 
	Returns 1-size vector if the attribute has a single value. */
    /// @{
    /** Retrieves the integer value(s) of the specified attribute.
	\param name - A string to identify the name of the attribute.
	\return A vector of int with the values of the attribute.
	\throw ULException If the attribute doesn't exist.
	\throw WTException If you call the wrong typed function.
	\throw ESException If it is called on an empty JobState object. */
    std::vector<int> getIntValue (const std::string& name);
    /** Retrieves the boolean value(s) of the specified attribute.
	\param name - A string to identify the name of the attribute.
	\return A vector of bool with the values of the attribute.
	\throw ULException If the attribute doesn't exist.
	\throw WTException If you call the wrong typed function.
	\throw ESException If it is called on an empty JobState object. */
    std::vector<bool> getBoolValue (const std::string& name);
    /** Retrieves the double value(s) of the specified attribute.
	\param name - A string to identify the name of the attribute.
	\return A vector of double with the values of the attribute.
	\throw ULException If the attribute doesn't exist.
	\throw WTException If you call the wrong typed function.
	\throw ESException If it is called on an empty JobState object. */
    std::vector<double> getDoubleValue (const std::string& name);
    /** Retrieves the string value(s) of the specified attribute.
	\param name - A string to identify the name of the attribute.
	\return A vector of string with the values of the attribute.
	\throw ULException If the attribute doesn't exist.
	\throw WTException If you call the wrong typed function.
	\throw ESException If it is called on an empty JobState object. */
    std::vector<std::string> getStringValue (const std::string& name);
    /// @}

    /** \name Check-Type methods. 
        If the attribute is a list, the method check the type of the elements of the list.*/
    /// @{
    /** Checks if the specified attribute is of int type.
	\param name - A string to identify the name of the attribute.
	\return \a true if the specified attribute is of the requested type, \a false otherwise.
	\throw ULException If the attribute doesn't exist.
	\throw ESException If it is called on an empty JobState object. */
    bool isIntValue (const std::string& name);
    /** Checks if the specified attribute is of boolean type.
	\param name - A string to identify the name of the attribute.
	\return \a true if the specified attribute is of the requested type, \a false otherwise.
	\throw ULException If the attribute doesn't exist.
	\throw ESException If it is called on an empty JobState object. */
    bool isBoolValue (const std::string& name);
    /** Checks if the specified attribute is of double type.
	\param name - A string to identify the name of the attribute.
	\return \a true if the specified attribute is of the requested type, \a false otherwise.
	\throw ULException If the attribute doesn't exist.
	\throw ESException If it is called on an empty JobState object. */
    bool isDoubleValue (const std::string& name);
    /** Checks if the specified attribute is of string type.
	\param name - A string to identify the name of the attribute.
	\return \a true if the specified attribute is of the requested type, \a false otherwise.
	\throw ULException If the attribute doesn't exist.
	\throw ESException If it is called on an empty JobState object. */
    bool isStringValue (const std::string& name);
    /** Checks if the specified attribute is a list value.
	\param name - A string to identify the name of the attribute.
	\return \a true if the specified attribute is of the requested type, \a false otherwise.
	\throw ULException If the attribute doesn't exist.
	\throw ESException If it is called on an empty JobState object. */
    bool isListValue (const std::string& name);
    /// @}


    /** \name Miscellaneous methods. */
    /// @{
    /** Resets the ClassAd with the pairs set by the user (all the pairs are deleted).
	\throw ESException If it is called on an empty JobState object. */
    void clearPairs ( void );
    /** Set the stateId
	\param stateid - the ID of the State object. */
    void setId( const std::string& stateid );
    /** check the validity of a State Object.
	\return an error code.
	\retval CHKPT_NoStateId if the StateId has not been set.
	\retval CHKPT_EmptyState if the Object is empty (the UserData has not be set).
	\retval CHKPT_NoIterator if the stepper has not been set.
	\retval CHKPT_OutOfSet if the CurrentStep is out of the range defines by the JobSteps. */
    int checkState( void );
    /** Gets the next step of the associated iterator.
	\return A State object with the label of the next step in the iterator.
	\throw EoSException If we are at the end of the iterator.
	\throw ESException If the iterator has not be set. */
    Step getNextStep ( void );
    /** Gets the current step of the associated iterator.
	\return A Step object with the label of the current step in the iterator.
	\throw EoSException If we are at the end of the iterator.
	\throw ESException If the iterator has not been set. */
    Step getCurrentStep ( void );
    /** Convert the JobState object into a ClassAd.
	\return The ClassAd created. 
	\throw ESException If it is called on an empty JobState object. */
    classad::ClassAd toClassAd( void );
    /** Convert the JobState object into a string.
	\return The string obtained. 
	\throw ESException If it is called on an empty JobState object. */
    std::string toString( void );
    /** Store the JobState object into a file.
	\param filename - The name of the file.
	\throw ESException If it is called on an empty JobState object. */
    void toFile( const std::string& filename );
    /// @}
		
    /** \name Save and Load state methods. */
    /// @{
    /** Saves persistently the JobState object in a LB service.
	\retval CHKPT_SyntaxError if some "private" attributes are not correctly setted \b FATAL.
	\retval CHKPT_SaveFailed if some problems occur logging to LB 
                (EPERM || EINVAL || EDG_WLL_ERROR_NOJOBID) \b FATAL.
	\retval CHKPT_NotAuth if you are saving a state of another job (only for partitionable).
	\retval ENOSPC if LB infrastructure failed to accept the event due to lack of disk space.
	\retval ENOMEM if LB infrastructure failed to allocate memory.
	\retval CHKPT_ConnProb if some problems occur connecting LB 
                (EAGAIN || ECONNREFUSED) (you can retry).
	\throw SEException If an environment variable has not been set 
	        (only when we need to initialize the ctx).
	\throw LFException If some errors occur querying the LB to save the JobState.
	\throw ESException If it is called on an empty JobState object. */
    int saveState ( void );
    /** Retrieves the "last - num" JobState object for a job whose identifier is the one specified as argument.
	\param stateID - A string with the identifier for the state.
	\param num - The number of the event to retrieve: default is 0 == last!
	\return A JobState object initialized with the data retrieve from the LB service.
	\throw SEException If the string defining the classAd is not syntactically correct.
	\throw LFException If something goes wrong with the LB communication. 
        \warning Both the exceptions are \b fatal exceptions! 
	\warning If no state is found in the LB an empty object is returned.*/
    JobState loadState ( const std::string& stateID, int num = 0 );
    /// @}
	 	
  private:
    /** \name Auxiliary generic methods. */
    /// @{
    /** Create an LB context, useful to query the LB database.
	\return The edg-jobId as it is set in the EDG_WL_JOBID env variable.
	\throw SEException 
	\throw LFException  */
    const char *createContext( void );
    /** Clean the JobState object. */
    void removeall( void );
    /** Check if the object is empty.
	\param line - the line number which generate the error (___LINE__).
	\param func - the name of the function calling this method 
	              (to store it in the exception).
 	\throw ESException */
    void isEmpty(int line, const char *func);
    /** Adds a value to an already set attribute.
	This method is used by all the appendValue public methods. 
        \return CHKPT_SyntaxError.*/
    int addValue( classad::ExprTree* trees, const classad::Value& val , const std::string& name);
    /** Gets the untyped generic value of the given attribute.
	This method is used by all the getTypedValue public methods. 
        \throw ULException 
	\throw ESException. */
    classad::Value getUnTypedValue(const std::string& name); 
    /** Checks the type of the generic attribute value given.
	If the value is a list value, it returns the type of the list's elements. 
	This method is used by all the isTyped public methods. 
        \return "Int" || "Boolean" || "Double" || "String" || "Undefined" */
    const std::string getType( classad::ExprTree *tree ); 
    /** Initializes a JobState object.
	The parameter is the classAd defining the job state.
 	This method is used by all the constructors and by the load_state funcion.
        \throw SEException. */ 
    void initialize ( classad::ClassAd *cstate );
    /** Query the LB to obtain the string representing the Job State.
	This function is used by the default object constructor and by the loadState. 
        \param num the number of the event to retrieve: 0 == last!
	\throw LFException. */
    std::string getStateFromLB( const char *jobidi, int num = 0);
    /// @}
    
    std::string         js_stateId;            /**< The identifier, at the moment it is the EdgJobID. */
    boost::shared_ptr<edg_wll_Context> js_ctx; /**< Context opaque object used to log to LB. */
    StepsSet           *js_stepper;            /**< The stepper. */
    classad::ClassAd   *js_pairs;              /**< The set of <var, value> pairs defined by the user. */  
  };

} CHKPT_NAMESPACE_END;

#endif // EDG_WORKLOAD_CHECKPOINTING_JOBSTATE_H

//  Local Variables:
//  mode: c++
//  End:
// File: ChkptException.h
// Author: Alessio Gianelle <gianelle@pd.infn.it>
// Copyright (c) 2002 The European Datagrid Project - IST programme, all rights reserved.
// For license conditions see http://www.eu-datagrid.org/license.html
// Contributors are mentioned in the code where appropriate.

// $Id: ChkptException.h,v 1.10 2002/12/19 10:23:49 gianelle Exp $

/**
 * \file ChkptException.h
 * \brief Provides an exception class for the checkpointing API. 
 * 
 * \version 0.1
 * \date 16 September 2002
 * \author Alessio Gianelle <gianelle@pd.infn.it>
*/

#ifndef EDG_WORKLOAD_CHECKPOINTING_EXCEPTIONS_H
#define EDG_WORKLOAD_CHECKPOINTING_EXCEPTIONS_H

#include "edg/workload/common/utilities/Exceptions.h"
#include "edg/workload/checkpointing/client/error_code.h"

CHKPT_NAMESPACE_BEGIN { 

  /**
   * \brief This ChkptException is thrown when something goes wrong in the checkpointing API.
   *
   * All the checkpointing exceptions derive from this class. 
   * \see edg::workload::common::Exception base class.
   */  

  class ChkptException : public edg::workload::common::utilities::Exception {
    
  protected: 
    /** 
     * Empty constructor
     */
    
    ChkptException() {};
    
  public:

    /** 
     * Constructor
     */

    ChkptException ( std::string file,   /**< the file name */
		     int line,           /**< the line number */
		     std::string method, /**< the name of the method */
		     int code,           /**< the code error according with the error_code.h file */
		     std::string exception_name /**< the name of the exception */ 
		     );
  };
  
  /** 
   * \brief Raised when the iterator arrives at the end of the list.
   *
   * \param file - the file name
   * \param line - the line number
   * \param method - the name of the method
   */
  class EoSException : public ChkptException {
    
  public:
    
    EoSException ( std::string file,    /**< the file name */
		   int line,            /**< the line number */
		   std::string method   /**< the name of the method */
		   );  
  };
  
  /**
   * \brief Raised when the attribute is not set.
   *
   * \param file - the file name
   * \param line - the line number
   * \param method - the name of the method
   * \param attr - the name of the "wrong" attribute
   */
  class ULException : public ChkptException {

  public:

    ULException ( std::string file,   /**< the file name */
		  int line,           /**< the line number */
		  std::string method, /**< the name of the method */
		  std::string attr    /**< the name of the "wrong" attribute */
		  );
  };

  /** 
   * \brief Raised when the type of the attribute mismatches with the type of the function.
   * 
   * \param file - the file name
   * \param line - the line number
   * \param method - the name of the method
   * \param attr - the name (or if possible the type) of the attribute
   * \param func - the type request by the function
   */
  class WTException : public ChkptException {

  public:

    WTException ( std::string file,  /**< the file name */
		  int line,          /**< the line number */
		  std::string method,/**< the name of the method */
		  std::string attr,  /**< the name (or if possible the type) of the attribute */
		  std::string func   /**< the type request by the function */
		  );
  };
    
  /** 
   * \brief Raised when a call to an external library (LB or JobID) gives an error.
   * \warning This is a \b FATAL exception. When it is raised the State could not be stored or retrieved.
   *
   * \param file - the file name
   * \param line - the line number
   * \param method - the name of the method
   * \param func - the name of the called funtion which raised the error
   * \param error_func - the error number raised by the called function
   */
  class LFException : public ChkptException {

  public:

    LFException ( std::string file,  /**< the file name */
		  int line,          /**< the line number */ 
		  std::string method,/**< the name of the method */
		  std::string func,  /**< the name of the called funtion which raised the error */
		  int error_func     /**< the error number raised by the called function */
		  );
  };

  /**
   * \brief Raised when syntax error is found during State Object initialization.
   * \warning This is a \b FATAL exception. When it is raised the State could not be stored or retrieved.
   *
   * \param file - the file name
   * \param line - the line number
   * \param method - the name of the method
   * \param attr - the name of the "wrong" attribute
   */
  class SEException : public ChkptException {
    
  public:
    
    SEException ( std::string file,  /**< the file name */
		  int line,          /**< the line number */ 
		  std::string method,/**< the name of the method */
		  std::string attr   /**< the name of the "wrong" attribute */
		  );
  };
  
  /**
   * \brief Raised when it has been required a method on an empty (not initialized) State.
   *
   * \param file - the file name
   * \param line - the line number
   * \param method - the name of the method
   * \param code - the error code 
   * \warning Check the error code inside the exception to know if it is the StateId 
   *  (-> CHKPT_NoStateId) or the UserData (-> Chkpt_EmptyState) which has not been set. 
   */
  class ESException : public ChkptException {

  public:
    
    ESException ( std::string file,  /**< the file name */
		  int line,          /**< the line number */ 
		  std::string method,/**< the name of the method */
		  int code           /**< the error code */
		  );
  };

} CHKPT_NAMESPACE_END;

#endif

// Local Variables:
// mode: c++
// End: