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