]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/AliShuttleConfig.cxx
update (alberto):
[u/mrichter/AliRoot.git] / SHUTTLE / AliShuttleConfig.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.8  2006/08/15 10:50:00  jgrosseo
19 effc++ corrections (alberto)
20
21 Revision 1.7  2006/07/20 09:54:40  jgrosseo
22 introducing status management: The processing per subdetector is divided into several steps,
23 after each step the status is stored on disk. If the system crashes in any of the steps the Shuttle
24 can keep track of the number of failures and skips further processing after a certain threshold is
25 exceeded. These thresholds can be configured in LDAP.
26
27 Revision 1.6  2006/07/19 10:09:55  jgrosseo
28 new configuration, accesst to DAQ FES (Alberto)
29
30 Revision 1.5  2006/07/10 13:01:41  jgrosseo
31 enhanced storing of last sucessfully processed run (alberto)
32
33 Revision 1.4  2006/06/12 09:11:16  jgrosseo
34 coding conventions (Alberto)
35
36 Revision 1.3  2006/06/06 14:26:40  jgrosseo
37 o) removed files that were moved to STEER
38 o) shuttle updated to follow the new interface (Alberto)
39
40 Revision 1.7  2006/05/12 09:07:16  colla
41 12/05/06
42 New configuration complete
43
44 Revision 1.2  2006/03/07 07:52:34  hristov
45 New version (B.Yordanov)
46
47 Revision 1.4  2005/11/19 14:20:31  byordano
48 logbook config added to AliShuttleConfig
49
50 Revision 1.3  2005/11/17 19:24:25  byordano
51 TList changed to TObjArray in AliShuttleConfig
52
53 Revision 1.2  2005/11/17 14:43:23  byordano
54 import to local CVS
55
56 Revision 1.1.1.1  2005/10/28 07:33:58  hristov
57 Initial import as subdirectory in AliRoot
58
59 Revision 1.1.1.1  2005/09/12 22:11:40  byordano
60 SHUTTLE package
61
62 Revision 1.3  2005/08/30 09:13:02  byordano
63 some docs added
64
65 */
66
67
68 //
69 // This class keeps the AliShuttle configuration.
70 // It reads the configuration for LDAP server.
71 // For every child entry in basedn which has schema type 'shuttleConfig'
72 // it creates a detector configuration. This configuration includes:
73 // DCS server host and port and the set of aliases for which data from
74 // will be retrieved (used by AliShuttle).
75 //
76
77
78 #include "AliShuttleConfig.h"
79 #include "AliShuttleInterface.h"
80
81 #include "AliLog.h"
82
83 #include <TSystem.h>
84 #include <TObjString.h>
85 #include <TLDAPResult.h>
86 #include <TLDAPEntry.h>
87 #include <TLDAPAttribute.h>
88
89
90 AliShuttleConfig::AliShuttleConfigHolder::AliShuttleConfigHolder(const TLDAPEntry* entry):
91 fDetector(""),
92 fDCSHost(""),
93 fDCSPort(0),
94 fIsValid(kFALSE),
95 fSkipDCSQuery(kFALSE)
96 {
97 // constructor of the shuttle configuration holder
98
99         TLDAPAttribute* anAttribute;
100         fDCSAliases = new TObjArray();
101         fDCSAliases->SetOwner(1);
102
103         anAttribute = entry->GetAttribute("det"); // MUST
104         fDetector = anAttribute->GetValue();
105
106         anAttribute = entry->GetAttribute("DCSHost"); // MAY
107         if (!anAttribute) {
108                 AliWarning(
109                         Form("%s has not DCS host entry - Shuttle will skip DCS data query!",
110                                 fDetector.Data()));
111                 fIsValid = kTRUE;
112                 fSkipDCSQuery = kTRUE;
113                 return;
114         }
115
116         fDCSHost = anAttribute->GetValue();
117
118         anAttribute = entry->GetAttribute("DCSPort"); // MAY
119         if (!anAttribute) {
120                 AliError(Form("Invalid configuration! %s has DCS Host but no port number!",
121                                 fDetector.Data()));
122                 return;
123         }
124         TString portStr = anAttribute->GetValue();
125         fDCSPort = portStr.Atoi();
126
127         anAttribute = entry->GetAttribute("DCSAlias"); // MAY
128         if (!anAttribute) {
129                 AliError(Form("Invalid configuration! %s has DCS host settings but no DCSAlias entries!",
130                                 fDetector.Data()));
131                 return;
132         }
133
134         const char* anAlias;
135         while ((anAlias = anAttribute->GetValue())) {
136                 fDCSAliases->AddLast(new TObjString(anAlias));
137         }
138
139         fIsValid = kTRUE;
140
141
142 }
143
144 //______________________________________________________________________________________________
145 AliShuttleConfig::AliShuttleConfigHolder::~AliShuttleConfigHolder()
146 {
147 // destructor of the shuttle configuration holder
148
149         delete fDCSAliases;
150 }
151
152 ClassImp(AliShuttleConfig)
153
154 //______________________________________________________________________________________________
155 AliShuttleConfig::AliShuttleConfig(const char* host, Int_t port,
156         const char* binddn, const char* password, const char* basedn):
157         fIsValid(kFALSE),
158         fDAQlbHost(""), fDAQlbUser(""), fDAQlbPass(""),
159         fMaxPPRetries(0), fMaxRetries(0), fDetectorMap(), fDetectorList(),
160         fShuttleInstanceHost(""), fProcessedDetectors(), fProcessAll(kFALSE)
161 {
162         //
163         // host: ldap server host
164         // port: ldap server port
165         // binddn: binddn used for ldap binding (simple bind is used!).
166         // password: password for binddn
167         // basedn: this is basedn whose childeren entries which have
168         // (objectClass=shuttleConfig) will be used as detector configurations.
169         //
170
171         fDetectorMap.SetOwner();
172         fDetectorList.SetOwner(0); //fDetectorList and fDetectorMap share the same object!
173         fProcessedDetectors.SetOwner();
174
175         TLDAPServer aServer(host, port, binddn, password, 3);
176
177         if (!aServer.IsConnected()) {
178                 AliError(Form("Can't connect to ldap server %s:%d",
179                                 host, port));
180                 return;
181         }
182
183         // reads configuration for the shuttle running on this machine
184
185         fShuttleInstanceHost = gSystem->HostName();
186         TString queryFilter = Form("(ShuttleHost=%s)", fShuttleInstanceHost.Data());
187
188         TLDAPResult* aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, queryFilter.Data());
189
190         if (!aResult) {
191                 AliError(Form("Can't find configuration with base DN: %s",
192                                 basedn));
193                 return;
194         }
195
196         if (aResult->GetCount() == 0) {
197                 AliError(Form("No Shuttle instance for host = %s!",
198                                         fShuttleInstanceHost.Data()));
199                 AliError(Form("All detectors will be processed."));
200                 fProcessAll=kTRUE;
201         }
202
203         if (aResult->GetCount() > 1) {
204                 AliError(Form("More than one Shuttle instance for host %s!",
205                                         fShuttleInstanceHost.Data()));
206                 delete aResult;
207                 return;
208         }
209
210         TLDAPEntry* anEntry = 0;
211         TLDAPAttribute* anAttribute = 0;
212
213         if(!fProcessAll){
214                 anEntry = aResult->GetNext();
215                 anAttribute = anEntry->GetAttribute("detectors");
216                 const char *detName;
217                 while((detName = anAttribute->GetValue())){
218                         TObjString *objDet= new TObjString(detName);
219                         fProcessedDetectors.Add(objDet);
220                 }
221         }
222
223         delete anEntry; delete aResult;
224
225         // Detector configuration (DCS Archive DB settings)
226
227         aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, "(objectClass=AliShuttleDetector)");
228         if (!aResult) {
229                 AliError(Form("Can't find configuration with base DN: %s", basedn));
230                 return;
231         }
232
233
234         while ((anEntry = aResult->GetNext())) {
235                 AliShuttleConfigHolder* aHolder = new AliShuttleConfigHolder(anEntry);
236                 delete anEntry;
237
238                 if (!aHolder->IsValid()) {
239                         AliError("Detector configuration error!");
240                         delete aHolder;
241                         delete aResult;
242                         return;
243                 }
244
245                 TObjString* detStr = new TObjString(aHolder->GetDetector());
246                 fDetectorMap.Add(detStr, aHolder);
247                 fDetectorList.AddLast(detStr);
248         }
249
250         delete aResult;
251
252         // Global configuration (DAQ logbook)
253
254         aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL,
255                         "(objectClass=AliShuttleGlobalConfig)");
256         if (!aResult) {
257                 AliError(Form("Can't find configuration with base DN: %s",
258                                 basedn));
259                 return;
260         }
261
262         if (aResult->GetCount() == 0) {
263                 AliError("Can't find DAQ logbook configuration!");
264                 delete aResult;
265                 return;
266         }
267
268         if (aResult->GetCount() > 1) {
269                 AliError("More than one DAQ logbook configuration found!");
270                 delete aResult;
271                 return;
272         }
273
274         anEntry = aResult->GetNext();
275
276         anAttribute = anEntry->GetAttribute("DAQLogbookHost");
277         if (!anAttribute) {
278                 AliError("Can't find DAQLogbookHost attribute!");
279                 delete anEntry; delete aResult;
280                 return;
281         }
282         fDAQlbHost = anAttribute->GetValue();
283
284         anAttribute = anEntry->GetAttribute("DAQLogbookUser");
285         if (!anAttribute) {
286                 AliError("Can't find DAQLogbookUser attribute!");
287                 delete aResult; delete anEntry;
288                 return;
289         }
290         fDAQlbUser = anAttribute->GetValue();
291
292         anAttribute = anEntry->GetAttribute("DAQLogbookPassword");
293         if (!anAttribute) {
294                 AliError("Can't find DAQLogbookPassword attribute!");
295                 delete aResult; delete anEntry;
296                 return;
297         }
298         fDAQlbPass = anAttribute->GetValue();
299
300         anAttribute = anEntry->GetAttribute("MaxPPRetries");
301         if (!anAttribute) {
302                 AliError("Can't find MaxPPRetries attribute!");
303                 delete aResult; delete anEntry;
304                 return;
305         }
306         TString tmpStr = anAttribute->GetValue();
307         fMaxPPRetries = tmpStr.Atoi();
308
309         anAttribute = anEntry->GetAttribute("MaxRetries");
310         if (!anAttribute) {
311                 AliError("Can't find MaxRetries attribute!");
312                 delete aResult; delete anEntry;
313                 return;
314         }
315         tmpStr = anAttribute->GetValue();
316         fMaxRetries = tmpStr.Atoi();
317
318         delete aResult; delete anEntry;
319
320         // FES configuration (FES logbook and hosts)
321
322         for(int iSys=0;iSys<3;iSys++){
323                 queryFilter = Form("(system=%s)", AliShuttleInterface::fkSystemNames[iSys]);
324                 aResult = aServer.Search(basedn, LDAP_SCOPE_ONELEVEL, queryFilter.Data());
325                 if (!aResult) {
326                         AliError(Form("Can't find configuration for system: %s",
327                                         AliShuttleInterface::fkSystemNames[iSys]));
328                         return;
329                 }
330
331                 if (aResult->GetCount() != 1 ) {
332                         AliError("Error in FES configuration!");
333                         delete aResult;
334                         return;
335                 }
336
337                 anEntry = aResult->GetNext();
338
339                 anAttribute = anEntry->GetAttribute("LogbookHost");
340                 if (!anAttribute) {
341                         AliError(Form ("Can't find LogbookHost attribute for %s!!",
342                                                 AliShuttleInterface::fkSystemNames[iSys]));
343                         delete aResult; delete anEntry;
344                         return;
345                 }
346                 fFESlbHost[iSys] = anAttribute->GetValue();
347
348                 anAttribute = anEntry->GetAttribute("LogbookUser");
349                 if (!anAttribute) {
350                         AliError(Form ("Can't find LogbookUser attribute for %s!!",
351                                                 AliShuttleInterface::fkSystemNames[iSys]));
352                         delete aResult; delete anEntry;
353                         return;
354                 }
355                 fFESlbUser[iSys] = anAttribute->GetValue();
356
357                 anAttribute = anEntry->GetAttribute("LogbookPassword");
358                 if (!anAttribute) {
359                         AliError(Form ("Can't find LogbookPassword attribute for %s!!",
360                                                 AliShuttleInterface::fkSystemNames[iSys]));
361                         delete aResult; delete anEntry;
362                         return;
363                 }
364                 fFESlbPass[iSys] = anAttribute->GetValue();
365
366                 anAttribute = anEntry->GetAttribute("FSHost");
367                 if (!anAttribute) {
368                         AliError(Form ("Can't find FSHost attribute for %s!!",
369                                                 AliShuttleInterface::fkSystemNames[iSys]));
370                         delete aResult; delete anEntry;
371                         return;
372                 }
373                 fFESHost[iSys] = anAttribute->GetValue();
374
375                 anAttribute = anEntry->GetAttribute("FSUser");
376                 if (!anAttribute) {
377                         AliError(Form ("Can't find FSUser attribute for %s!!",
378                                                 AliShuttleInterface::fkSystemNames[iSys]));
379                         delete aResult; delete anEntry;
380                         return;
381                 }
382                 fFESUser[iSys] = anAttribute->GetValue();
383
384                 anAttribute = anEntry->GetAttribute("FSPassword");
385                 if (anAttribute) fFESPass[iSys] = anAttribute->GetValue();
386
387                 delete aResult; delete anEntry;
388         }
389
390         fIsValid = kTRUE;
391 }
392
393 //______________________________________________________________________________________________
394 AliShuttleConfig::~AliShuttleConfig()
395 {
396 // destructor
397
398         fDetectorMap.DeleteAll();
399         fDetectorList.Clear();
400         fProcessedDetectors.Delete();
401 }
402
403 //______________________________________________________________________________________________
404 const TObjArray* AliShuttleConfig::GetDetectors() const
405 {
406         //
407         // returns collection of TObjString which contains the name
408         // of every detector which is in the configuration.
409         //
410
411         return &fDetectorList;
412 }
413
414 //______________________________________________________________________________________________
415 Bool_t AliShuttleConfig::HasDetector(const char* detector) const
416 {
417         //
418         // checks for paricular detector in the configuration.
419         //
420         return fDetectorMap.GetValue(detector) != NULL;
421 }
422
423 //______________________________________________________________________________________________
424 const char* AliShuttleConfig::GetDCSHost(const char* detector) const
425 {
426         //
427         // returns DCS server host used by particular detector
428         //
429         
430         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
431         if (!aHolder) {
432                 AliError(Form("There isn't configuration for detector: %s",
433                         detector));
434                 return NULL;
435         }
436
437         return aHolder->GetDCSHost();
438 }
439
440 //______________________________________________________________________________________________
441 Int_t AliShuttleConfig::GetDCSPort(const char* detector) const
442 {
443         //
444         // returns DCS server port used by particular detector
445         //
446
447
448         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
449         if (!aHolder) {
450                 AliError(Form("There isn't configuration for detector: %s",
451                         detector));
452                 return 0;
453         }
454
455         return aHolder->GetDCSPort();
456 }
457
458 //______________________________________________________________________________________________
459 const TObjArray* AliShuttleConfig::GetDCSAliases(const char* detector) const
460 {
461         //
462         // returns collection of TObjString which represents the set of aliases
463         // which used for data retrieval for particular detector
464         //
465
466         AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) fDetectorMap.GetValue(detector);
467         if (!aHolder) {
468                 AliError(Form("There isn't configuration for detector: %s",
469                         detector));
470                 return NULL;
471         }
472
473         return aHolder->GetDCSAliases();
474 }
475
476 //______________________________________________________________________________________________
477 Bool_t AliShuttleConfig::HostProcessDetector(const char* detector) const
478 {
479         // return TRUE if detector is handled by host or if fProcessAll is TRUE
480
481         if(fProcessAll) return kTRUE;
482         TIter iter(&fProcessedDetectors);
483         TObjString* detName;
484         while((detName = (TObjString*) iter.Next())){
485                 if(detName->String() == detector) return kTRUE;
486         }
487         return kFALSE;
488 }
489
490 //______________________________________________________________________________________________
491 void AliShuttleConfig::Print(Option_t* /*option*/) const
492 {
493 // print configuration
494         
495         TString result;
496         result += '\n';
497
498         result += Form("\nShuttle running on %s \n\n", fShuttleInstanceHost.Data());
499
500         if(fProcessAll) {
501                 result += Form("All detectors will be processed! \n\n");
502         } else {
503                 result += "Detectors processed by this host: ";
504                 TIter it(&fProcessedDetectors);
505                 TObjString* aDet;
506                 while ((aDet = (TObjString*) it.Next())) {
507                         result += Form("%s ", aDet->String().Data());
508                 }
509                 result += "\n\n";
510         }
511
512         result += Form("Max PP retries = %d - Max total retries = %d\n\n", fMaxPPRetries, fMaxRetries);
513
514         result += Form("DAQ Logbook Configuration \n \tHost: %s - User: %s - ",
515                 fDAQlbHost.Data(), fDAQlbUser.Data());
516
517         result += "Password: ";
518         result.Append('*', fDAQlbPass.Length());
519         result += "\n\n";
520
521         for(int iSys=0;iSys<3;iSys++){
522                 result += Form("FES Configuration for %s system\n", AliShuttleInterface::fkSystemNames[iSys]);
523                 result += Form("\tLogbook host: \t%s - \tUser: %s\n",
524                                                 fFESlbHost[iSys].Data(), fFESlbUser[iSys].Data());
525                 // result += Form("Logbook Password:",fFESlbPass[iSys].Data());
526                 result += Form("\tFES host: \t%s - \tUser: %s\n\n", fFESHost[iSys].Data(), fFESUser[iSys].Data());
527                 // result += Form("FES Password:",fFESPass[iSys].Data());
528         }
529
530         TIter iter(fDetectorMap.GetTable());
531         TPair* aPair;
532         while ((aPair = (TPair*) iter.Next())) {
533                 AliShuttleConfigHolder* aHolder = (AliShuttleConfigHolder*) aPair->Value();
534                 if(aHolder->SkipDCSQuery()) continue;
535                 result += Form("DCS archive DB configuration for *** %s *** \n", aHolder->GetDetector());
536                 result += Form("\tAmanda server: %s:%d \n", aHolder->GetDCSHost(), aHolder->GetDCSPort());
537
538                 result += "\tDCS Aliases: ";
539                 const TObjArray* aliases = aHolder->GetDCSAliases();
540                 TIter it(aliases);
541                 TObjString* anAlias;
542                 while ((anAlias = (TObjString*) it.Next())) {
543                         result += Form("%s ", anAlias->String().Data());
544                 }
545
546                 result += "\n\n";
547
548         }
549
550         if(!fIsValid) result += "\n\n********** !!!!! Configuration is INVALID !!!!! **********\n";
551
552         AliInfo(result);
553 }