Back to index

nordugrid-arc-nox  1.1.0~rc6
job.h
Go to the documentation of this file.
00001 #ifndef __ARC_AREX_JOB_H__
00002 #define __ARC_AREX_JOB_H__
00003 
00004 #include <string>
00005 #include <list>
00006 
00007 #include <arc/XMLNode.h>
00008 #include <arc/message/MessageAuth.h>
00009 #include "grid-manager/jobs/users.h"
00010 #include "grid-manager/files/info_types.h"
00011 #include "grid-manager/jobs/job.h"
00012 #include "grid-manager/jobs/plugins.h"
00013 
00014 namespace ARex {
00015 
00016 class ARexGMConfig {
00017  private:
00018   JobUser *user_;
00019   bool readonly_;
00020   std::list<std::string> queues_;
00021   std::string grid_name_; // temporary solution
00022   std::string service_endpoint_; // temporary solution
00023   std::list<Arc::MessageAuth*> auths_;
00024   ContinuationPlugins cont_plugins_;
00025   std::vector<std::string> session_roots_non_draining_;
00026  public:
00027   ARexGMConfig(const std::string& config_file,const std::string& uname,const std::string& grid_name,const std::string& service_endpoint);
00028   ~ARexGMConfig(void);
00029   operator bool(void) const { return (user_ != NULL); };
00030   bool operator!(void) const { return (user_ == NULL); };
00031   JobUser* User(void) { return user_; };
00032   bool ReadOnly(void) const { return readonly_; };
00033   const std::string& GridName(void) const { return grid_name_; };
00034   const std::string& Endpoint(void) const { return service_endpoint_; };
00035   const std::list<std::string>& Queues(void) const { return queues_; };
00036   static bool InitEnvironment(const std::string& configfile);
00037   void AddAuth(Arc::MessageAuth* auth) { auths_.push_back(auth); };
00038   void ClearAuths(void) { auths_.clear(); };
00039   std::list<Arc::MessageAuth*>::iterator beginAuth(void) { return auths_.begin(); };
00040   std::list<Arc::MessageAuth*>::iterator endAuth(void) { return auths_.end(); };
00041   ContinuationPlugins& Plugins(void) { return cont_plugins_; };
00042   std::vector<std::string> SessionRootsNonDraining(void) { return session_roots_non_draining_; };
00043 };
00044 
00045 
00046 typedef enum {
00047   ARexJobNoError,
00048   ARexJobInternalError, // Failed during some internal operation - like writing some file
00049   ARexJobConfigurationError, // Problem detected which can be fixed by adjusting configuration of service
00050   ARexJobDescriptionUnsupportedError, // Job asks for feature or combination not supported by service
00051   ARexJobDescriptionMissingError, // Job is missing optional but needed for this service element
00052   ARexJobDescriptionSyntaxError, // Job description is malformed - missing elements, wrong names, etc.
00053   ARexJobDescriptionLogicalError // Job request otherwise corect has some values out of scope of service
00054 } ARexJobFailure;
00055 
00059 class ARexJob {
00060  private:
00061   std::string id_;
00062   std::string failure_;
00063   ARexJobFailure failure_type_;
00064   bool allowed_to_see_;
00065   bool allowed_to_maintain_;
00066   Arc::Logger& logger_;
00070   bool is_allowed(bool fast = false);
00071   ARexGMConfig& config_;
00072   JobLocalDescription job_;
00073   bool make_job_id(void);
00074   bool delete_job_id(void);
00075   bool update_credentials(const std::string& credentials);
00076  public:
00078   ARexJob(const std::string& id,ARexGMConfig& config,Arc::Logger& logger,bool fast_auth_check = false);
00080   ARexJob(Arc::XMLNode jsdl,ARexGMConfig& config,const std::string& credentials,const std::string& clientid,Arc::Logger& logger,Arc::XMLNode migration = Arc::XMLNode());
00081   operator bool(void) { return !id_.empty(); };
00082   bool operator!(void) { return id_.empty(); };
00084   std::string Failure(void) { std::string r=failure_; failure_=""; failure_type_=ARexJobNoError; return r; };
00085   operator ARexJobFailure(void) { return failure_type_; };
00087   std::string ID(void) { return id_; };
00089   bool GetDescription(Arc::XMLNode& jsdl);
00091   bool Cancel(void);
00093   bool Clean(void);
00095   bool Resume(void);
00097   std::string State(void);
00100   std::string State(bool& job_pending);
00102   bool Failed(void);
00104   std::string SessionDir(void);
00106   std::string LogDir(void);
00109   static int TotalJobs(ARexGMConfig& config,Arc::Logger& logger);
00111   static std::list<std::string> Jobs(ARexGMConfig& config,Arc::Logger& logger);
00113   int CreateFile(const std::string& filename);
00115   int OpenFile(const std::string& filename,bool for_read,bool for_write);
00116   std::string GetFilePath(const std::string& filename);
00118   int OpenLogFile(const std::string& name);
00119   std::string GetLogFilePath(const std::string& name);
00121   Glib::Dir* OpenDir(const std::string& dirname);
00123   std::list<std::string> LogFiles(void);
00125   bool UpdateCredentials(const std::string& credentials);
00127   bool ChooseSessionDir(const std::string& jobid, std::string& sessiondir);
00128 };
00129 
00130 } // namespace ARex
00131 
00132 #endif