XrdProofdProofServMgr.h

Go to the documentation of this file.
00001 // @(#)root/proofd:$Id: XrdProofdProofServMgr.h 36520 2010-11-05 16:08:23Z ganis $
00002 // Author: G. Ganis Jan 2008
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_XrdProofdProofServMgr
00013 #define ROOT_XrdProofdProofServMgr
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // XrdProofdProofServMgr                                                  //
00018 //                                                                      //
00019 // Author: G. Ganis, CERN, 2008                                         //
00020 //                                                                      //
00021 // Class managing proofserv sessions manager.                           //
00022 //                                                                      //
00023 //////////////////////////////////////////////////////////////////////////
00024 
00025 #include <list>
00026 
00027 #ifdef OLDXRDOUC
00028 #  include "XrdSysToOuc.h"
00029 #  include "XrdOuc/XrdOucPthread.hh"
00030 #else
00031 #  include "XrdSys/XrdSysPthread.hh"
00032 #endif
00033 
00034 #include "XrdOuc/XrdOucHash.hh"
00035 #include "XrdOuc/XrdOucString.hh"
00036 
00037 #include "XrdProofdConfig.h"
00038 #include "XrdProofdProofServ.h"
00039 
00040 class XrdOucStream;
00041 class XrdProtocol_Config;
00042 class XrdProofdManager;
00043 class XrdROOTMgr;
00044 class XrdSysLogger;
00045 
00046 #define PSMMAXCNTS  3
00047 #define PSMCNTOK(t) (t >= 0 && t < PSMMAXCNTS)
00048 
00049 // Aux structure for session set env inputs
00050 typedef struct {
00051    XrdProofdProofServ *fPS;
00052    int          fLogLevel;
00053    XrdOucString fCfg;
00054    XrdOucString fLogFile;
00055    XrdOucString fSessionTag;
00056    XrdOucString fTopSessionTag;
00057    XrdOucString fSessionDir;
00058    XrdOucString fWrkDir;
00059 } ProofServEnv_t;
00060 
00061 class XpdClientSessions {
00062 public:
00063    XrdSysRecMutex   fMutex;
00064    XrdProofdClient *fClient;
00065    std::list<XrdProofdProofServ *> fProofServs;
00066    XpdClientSessions(XrdProofdClient *c = 0) : fClient(c) { }
00067    int operator==(const XpdClientSessions c) { return (c.fClient == fClient) ? 1 : 0; }
00068 };
00069 
00070 class XrdProofSessionInfo {
00071 public:
00072    time_t         fLastAccess;
00073    int            fPid;
00074    int            fID;
00075    int            fSrvType;
00076    int            fStatus;
00077    XrdOucString   fUser;
00078    XrdOucString   fGroup;
00079    XrdOucString   fUnixPath;
00080    XrdOucString   fTag;
00081    XrdOucString   fAlias;
00082    XrdOucString   fLogFile;
00083    XrdOucString   fOrdinal;
00084    XrdOucString   fUserEnvs;
00085    XrdOucString   fROOTTag;
00086    XrdOucString   fAdminPath;
00087    int            fSrvProtVers;
00088 
00089    XrdProofSessionInfo(XrdProofdClient *c, XrdProofdProofServ *s);
00090    XrdProofSessionInfo(const char *file) { ReadFromFile(file); }
00091 
00092    void FillProofServ(XrdProofdProofServ &s, XrdROOTMgr *rmgr);
00093    int ReadFromFile(const char *file);
00094    void Reset();
00095    int SaveToFile(const char *file);
00096 };
00097 
00098 class XpdEnv {
00099 public:
00100    XrdOucString   fName;
00101    XrdOucString   fEnv;
00102    XrdOucString   fUsers;
00103    XrdOucString   fGroups;
00104    int            fSvnMin;
00105    int            fSvnMax;
00106    int            fVerMin;
00107    int            fVerMax;
00108    XpdEnv(const char *n, const char *env, const char *usr = 0, const char *grp = 0,
00109           int smi = -1, int smx = -1, int vmi = -1, int vmx = -1) :
00110           fName(n), fEnv(env), fUsers(usr), fGroups(grp),
00111           fSvnMin(smi), fSvnMax(smx), fVerMin(vmi), fVerMax(vmx) { }
00112    void Reset(const char *n, const char *env, const char *usr = 0, const char *grp = 0,
00113               int smi = -1, int smx = -1, int vmi = -1, int vmx = -1) {
00114               fName = n; fEnv = env; fUsers = usr; fGroups = grp;
00115               fSvnMin = smi; fSvnMax = smx; fVerMin = vmi; fVerMax = vmx; }
00116    int Matches(const char *usr, const char *grp, int svn = -1, int ver = -1);
00117    void Print(const char *what);
00118    static int     ToVersCode(int ver, bool hex = 0);       
00119 };
00120 
00121 class XrdProofdProofServMgr : public XrdProofdConfig {
00122 
00123    XrdProofdManager  *fMgr;
00124    XrdSysRecMutex     fMutex;
00125    XrdSysRecMutex     fRecoverMutex;
00126    XrdSysRecMutex     fEnvsMutex;    // Protect usage of envs lists
00127    XrdSysSemWait      fForkSem;   // To serialize fork requests
00128    XrdSysSemWait      fProcessSem;   // To serialize process requests
00129    XrdSysLogger      *fLogger;    // Error logger
00130    int                fInternalWait;   // Timeout on replies from proofsrv
00131    XrdOucString       fProofPlugin;    // String identifying the plug-in to be loaded, e.g. "condor:"
00132    std::list<XpdEnv>  fProofServEnvs;  // Additional envs to be exported before proofserv
00133    std::list<XpdEnv>  fProofServRCs;   // Additional rcs to be passed to proofserv
00134 
00135    int                fShutdownOpt;    // What to do when a client disconnects
00136    int                fShutdownDelay;  // Delay shutdown by this (if enabled)
00137 
00138    XrdProofdPipe      fPipe;
00139 
00140    int                fCheckFrequency;
00141    int                fTerminationTimeOut;
00142    int                fVerifyTimeOut;
00143    int                fReconnectTime;
00144    int                fReconnectTimeOut;
00145    int                fRecoverTimeOut;
00146    int                fRecoverDeadline;
00147    bool               fCheckLost;
00148    XrdOucString       fParentExecs;   // List of possible 'proofserv' parent names
00149 
00150    int                fCounters[PSMMAXCNTS];  // Internal counters (see enum PSMCounters)
00151    int                fCurrentSessions;       // Number of sessions (top masters)
00152 
00153    int                fNextSessionsCheck; // Time of next sessions check
00154 
00155    XrdOucString       fActiAdminPath; // Active sessions admin area
00156    XrdOucString       fTermAdminPath; // Terminated sessions admin area
00157 
00158    XrdOucHash<XrdProofdProofServ> fSessions; // List of sessions
00159    std::list<XrdProofdProofServ *> fActiveSessions;     // List of active sessions (non-idle)
00160    std::list<XpdClientSessions *> *fRecoverClients; // List of client potentially recovering
00161 
00162    int                DoDirectiveProofServMgr(char *, XrdOucStream *, bool);
00163    int                DoDirectivePutEnv(char *, XrdOucStream *, bool);
00164    int                DoDirectivePutRc(char *, XrdOucStream *, bool);
00165    int                DoDirectiveShutdown(char *, XrdOucStream *, bool);
00166    void               ExtractEnv(char *, XrdOucStream *,
00167                                  XrdOucString &users, XrdOucString &groups,
00168                                  XrdOucString &rcval, XrdOucString &rcnam,
00169                                  int &smi, int &smx, int &vmi, int &vmx, bool &hex);
00170    void               FillEnvList(std::list<XpdEnv> *el, const char *nam, const char *val,
00171                                   const char *usrs = 0, const char *grps = 0,
00172                                   int smi = -1, int smx = -1, int vmi = -1, int vmx = -1, bool hex = 0);
00173 
00174    int                PrepareSessionRecovering();
00175    int                ResolveSession(const char *fpid);
00176 
00177    // Session Admin path management
00178    int                AddSession(XrdProofdProtocol *p, XrdProofdProofServ *s);
00179    bool               IsSessionSocket(const char *fpid);
00180    int                RmSession(const char *fpid);
00181    int                TouchSession(const char *fpid, const char *path = 0);
00182    int                VerifySession(const char *fpid, int to = -1, const char *path = 0);
00183 
00184    void               ResolveKeywords(XrdOucString &s, ProofServEnv_t *in);
00185    int                SetUserOwnerships(XrdProofdProtocol *p, const char *ord, const char *stag);
00186 
00187 public:
00188    XrdProofdProofServMgr(XrdProofdManager *mgr, XrdProtocol_Config *pi, XrdSysError *e);
00189    virtual ~XrdProofdProofServMgr() { }
00190 
00191    enum PSMProtocol { kSessionRemoval = 0, kClientDisconnect = 1, kCleanSessions = 2, kProcessReq = 3, kChgSessionSt = 4} ;
00192    enum PSMCounters { kCreateCnt = 0, kCleanSessionsCnt = 1, kProcessCnt = 2} ;
00193 
00194    XrdSysRecMutex   *Mutex() { return &fMutex; }
00195 
00196    int               Config(bool rcf = 0);
00197    int               DoDirective(XrdProofdDirective *d,
00198                                  char *val, XrdOucStream *cfg, bool rcf);
00199    void              RegisterDirectives();
00200 
00201    int               CheckFrequency() const { return fCheckFrequency; }
00202    int               InternalWait() const { return fInternalWait; }
00203    int               VerifyTimeOut() const { return fVerifyTimeOut; }
00204 
00205    inline int        NextSessionsCheck()
00206                         { XrdSysMutexHelper mhp(fMutex); return fNextSessionsCheck; }
00207    inline void       SetNextSessionsCheck(int t)
00208                         { XrdSysMutexHelper mhp(fMutex); fNextSessionsCheck = t; }
00209 
00210    bool              IsReconnecting();
00211    bool              IsClientRecovering(const char *usr, const char *grp, int &deadline);
00212    void              SetReconnectTime(bool on = 1);
00213 
00214    int               Process(XrdProofdProtocol *p);
00215    XrdSysSemWait    *ProcessSem() { return &fProcessSem; }
00216 
00217    int               Accept(XrdProofdProofServ *xps, int to, XrdOucString &e);
00218    int               Attach(XrdProofdProtocol *p);
00219    int               Create(XrdProofdProtocol *p);
00220    int               Destroy(XrdProofdProtocol *p);
00221    int               Detach(XrdProofdProtocol *p);
00222    int               Recover(XpdClientSessions *cl);
00223 
00224    void              UpdateCounter(int t, int n) { if (PSMCNTOK(t)) {
00225                                  XrdSysMutexHelper mhp(fMutex); fCounters[t] += n;
00226                                           if (fCounters[t] < 0) fCounters[t] = 0;} }
00227    int               CheckCounter(int t) { int cnt = -1; if (PSMCNTOK(t)) {
00228                                  XrdSysMutexHelper mhp(fMutex); cnt = fCounters[t];}
00229                                  return cnt; }
00230 
00231    void              BroadcastClusterInfo();
00232    int               BroadcastPriorities();
00233    int               CurrentSessions(bool recalculate = 0);
00234    void              DisconnectFromProofServ(int pid);
00235 
00236    std::list<XrdProofdProofServ *> *ActiveSessions() { return &fActiveSessions; }
00237    XrdProofdProofServ *GetActiveSession(int pid);
00238 
00239    int               CleanupProofServ(bool all = 0, const char *usr = 0);
00240 
00241    void              GetTagDirs(XrdProofdProtocol *p, XrdProofdProofServ *xps,
00242                                 XrdOucString &sesstag, XrdOucString &topsesstag,
00243                                 XrdOucString &sessiondir, XrdOucString &sesswrkdir);
00244 
00245    int               SetProofServEnv(XrdProofdProtocol *p, void *in);
00246    int               SetProofServEnvOld(XrdProofdProtocol *p, void *in);
00247 
00248    int               SaveAFSkey(XrdSecCredentials *c, const char *fn, XrdProofUI ui);
00249    int               SetUserEnvironment(XrdProofdProtocol *p);
00250 
00251    static int        SetProofServEnv(XrdProofdManager *m, XrdROOT *r);
00252 
00253    inline XrdProofdPipe *Pipe() { return &fPipe; }
00254 
00255    // Checks run periodically by the cron job
00256    int               DeleteFromSessions(const char *pid);
00257    int               MvSession(const char *fpid);
00258    int               CheckActiveSessions(bool verify = 1);
00259    int               CheckTerminatedSessions();
00260    int               CleanClientSessions(const char *usr, int srvtype);
00261    int               CleanupLostProofServ();
00262    int               RecoverActiveSessions();
00263 };
00264 
00265 class XpdSrvMgrCreateCnt {
00266 public:
00267    int                    fType;
00268    XrdProofdProofServMgr *fMgr;
00269    XpdSrvMgrCreateCnt(XrdProofdProofServMgr *m, int t) : fType(t), fMgr(m)
00270                                         { if (m && PSMCNTOK(t)) m->UpdateCounter(t,1); }
00271    ~XpdSrvMgrCreateCnt() { if (fMgr && PSMCNTOK(fType)) fMgr->UpdateCounter(fType,-1); }
00272 };
00273 
00274 class XpdSrvMgrCreateGuard {
00275 public:
00276    int *fCnt;
00277    XpdSrvMgrCreateGuard(int *c = 0) { Set(c); }
00278    ~XpdSrvMgrCreateGuard() { if (fCnt) (*fCnt)--; }
00279    void Set(int *c) { fCnt = c; if (fCnt) (*fCnt)++;}
00280 };
00281 
00282 #endif

Generated on Tue Jul 5 14:51:49 2011 for ROOT_528-00b_version by  doxygen 1.5.1