]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTHOMERProxyHandler.cxx
Changes for #90436: Misuse of TClonesArray containing AliESDMuonCluster
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERProxyHandler.cxx
CommitLineData
06272c83 1//-*- Mode: C++ -*-
2// $Id: AliHLTHOMERProxyHandler.cxx $
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
8//* for The ALICE HLT Project. *
9//* *
10//* Permission to use, copy, modify and distribute this software and its *
11//* documentation strictly for non-commercial purposes is hereby granted *
12//* without fee, provided that the above copyright notice appears in all *
13//* copies and that both the copyright notice and this permission notice *
14//* appear in the supporting documentation. The authors make no claims *
15//* about the suitability of this software for any purpose. It is *
16//* provided "as is" without express or implied warranty. *
17//**************************************************************************
18
19/** @file AliHLTHOMERProxyHandler.cxx
20 @author Jochen Thaeder
21 @date
22 @brief HOMER proxy handler for HomerManger
23*/
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#if __GNUC__>= 3
32 using namespace std;
33#endif
34
35#include "TDOMParser.h"
36#include "TSocket.h"
37#include "TSystem.h"
38// -- -- -- -- -- -- --
39#include "AliHLTHOMERProxyHandler.h"
e728e5ba 40// -- -- -- -- -- -- --
06272c83 41
42ClassImp(AliHLTHOMERProxyHandler)
43
44/*
45 * ---------------------------------------------------------------------------------
46 * Constructor / Destructor
47 * ---------------------------------------------------------------------------------
48 */
49
50//##################################################################################
51AliHLTHOMERProxyHandler::AliHLTHOMERProxyHandler() :
52 fRealm(kHLT),
53 fXmlRpcResponse(""),
54 fSourceList(NULL) {
55 // see header file for class documentation
56 // or
57 // refer to README to build package
58 // or
59 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
60}
61
62//##################################################################################
63AliHLTHOMERProxyHandler::~AliHLTHOMERProxyHandler() {
64 // see header file for class documentation
65
66}
67
68//##################################################################################
69Int_t AliHLTHOMERProxyHandler::Initialize() {
70 // see header file for class documentation
06272c83 71 IdentifyRealm();
fd2adb88 72 return 0;
06272c83 73}
74
75/*
76 * ---------------------------------------------------------------------------------
77 * Source List - public
78 * ---------------------------------------------------------------------------------
79 */
80
81//##################################################################################
82Int_t AliHLTHOMERProxyHandler::FillSourceList(TList *srcList) {
83 // see header file for class documentation
84
85 Int_t iResult = 0;
86
87 fSourceList = srcList;
88
89 iResult = RequestXmlRpcResponse();
90
91 if (!iResult)
92 iResult = ProcessXmlRpcResponse();
93
ae17e63c 94 if (iResult < 0) {
64984943 95 HLTError("Filling SourceList failed.");
ae17e63c 96 }
06272c83 97
98 return iResult;
99}
100
101/*
102 * ---------------------------------------------------------------------------------
103 * Realms - private
104 * ---------------------------------------------------------------------------------
105 */
106
107//##################################################################################
108const Char_t *AliHLTHOMERProxyHandler::fgkHOMERProxyNode[] = {
109 "portal-dcs0.internal",
110 "alihlt-dcs0.cern.ch",
111 "alihlt-vobox0.cern.ch",
112 "alihlt-gw0.kip.uni-heidelberg.de",
af7671cd 113 "localhost",
06272c83 114 "portal-dcs1.internal",
115 "alihlt-dcs1.cern.ch",
116 "alihlt-vobox1.cern.ch",
cfa641b1 117 "alihlt-gw1.kip.uni-heidelberg.de",
118 "localhost"
06272c83 119};
120
121//##################################################################################
122void AliHLTHOMERProxyHandler::IdentifyRealm() {
123 // see header file for class documentation
124
125 TString hostIP(gSystem->GetHostByName(gSystem->HostName()).GetHostAddress());
9403dc2c 126
127 HLTInfo(hostIP.Data());
06272c83 128
129 if ( hostIP.Contains("10.162.") )
130 fRealm = kHLT;
131 else if ( hostIP.Contains("10.160.") || hostIP.Contains("10.161.") )
132 fRealm = kACR;
133 else if ( hostIP.Contains("129.206.") )
134 fRealm = kKIP;
af7671cd 135 else if ( hostIP.Contains("137.138")
136 || hostIP.Contains("128.141")
137 || hostIP.Contains("127.0.")
9403dc2c 138 || hostIP.Contains("192.168")
cfa641b1 139 )
06272c83 140 fRealm = kGPN;
cfa641b1 141 else {
142 fRealm = kLoc;
143 }
144
fd2adb88 145 //fRealm = kLoc;
146
06272c83 147 return;
148}
149
150/*
151 * ---------------------------------------------------------------------------------
152 * Proxy Communication - private
153 * ---------------------------------------------------------------------------------
154 */
155
156//##################################################################################
157Int_t AliHLTHOMERProxyHandler::RequestXmlRpcResponse() {
158 // see header file for class documentation
159
160 Int_t iResult = 0;
161
162 // -- open socket
163 // ----------------
164
165 Int_t proxyPort = 19999;
166
167 TSocket *socket = new TSocket(fgkHOMERProxyNode[fRealm], proxyPort);
168 if ( ! socket->IsValid() ) {
b6bb7ca3 169 HLTWarning(Form("Failed to create socket to %s:%d,",fgkHOMERProxyNode[fRealm], proxyPort));
170 HLTWarning(Form("trying %s:%d now.", fgkHOMERProxyNode[fRealm+kHOMERRealmsMax],proxyPort));
06272c83 171
172 socket = new TSocket(fgkHOMERProxyNode[fRealm+kHOMERRealmsMax], proxyPort);
173 if ( ! socket->IsValid() ) {
b6bb7ca3 174 HLTError(Form("Failed to create socket to %s:%d and %s:%d.",
e728e5ba 175 fgkHOMERProxyNode[fRealm], proxyPort,
176 fgkHOMERProxyNode[fRealm+kHOMERRealmsMax],proxyPort));
177
c4b95fdd 178 HLTWarning(Form("trying %s:%d now.",
179 fgkHOMERProxyNode[kLoc],proxyPort));
180 socket = new TSocket(fgkHOMERProxyNode[kLoc], proxyPort);
181 if ( ! socket->IsValid() ) {
182 HLTError(Form("Failed to create socket to %s:%d , %s:%d and %s:%d.",
183 fgkHOMERProxyNode[fRealm], proxyPort,
184 fgkHOMERProxyNode[fRealm+kHOMERRealmsMax],proxyPort,
185 fgkHOMERProxyNode[kLoc], proxyPort));
186 fRealm = -1;
187 return -1;
188 }
189 else {
190 fRealm = kLoc;
191 }
06272c83 192 }
193 else
194 fRealm = fRealm+kHOMERRealmsMax;
195 }
196
197 // -- send request
198 // -----------------
199
5e5d2b7e 200 Char_t reqMsg[] = "POST / HTTP/1.1\r\n\
06272c83 201User-Agent: curl/7.18.0 (x86_64-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1\r\n\
202Host: localhost:10000\r\n\
203Accept: */*\r\n\
204Content-type: text/xml\r\n\
205Content-Length: 68\r\n\
206\r\n<methodCall><methodName>getTcpDumpServices</methodName></methodCall>\r\n";
207
208 iResult = socket->SendRaw( reqMsg, strlen(reqMsg) );
209 if ( iResult < 1 ||
210 iResult != static_cast<Int_t>(strlen(reqMsg))) {
b6bb7ca3 211 HLTError(Form("Error sending! -- send length %d -- msg length %d.", iResult, static_cast<Int_t>(strlen(reqMsg)) ));
06272c83 212 socket->Close();
213 return iResult;
214 }
215
216 // -- receive answer
217 // -------------------
218
219 const Int_t bufferSize = 1024;
220 Char_t buffer[bufferSize];
221
222 Bool_t isXmlRpc = kFALSE;
223
224 fXmlRpcResponse = "";
225
226 // -- loop for getting full xmlRPC response
227 while(1) {
228
229 Int_t bufferLength = 0;
230
231 // -- loop for reading until end of line
232 while (1) {
233
234 iResult = socket->RecvRaw(&buffer[bufferLength], 1);
235 if ( iResult < 0) {
64984943 236 HLTError("Error reading form socket.");
06272c83 237 socket->Close();
238 return iResult;
239 }
240
241 // -- Checking for end of line
242 if ( buffer[bufferLength] == 10 ) {
243 buffer[bufferLength] = 0;
244 break;
245 }
246
247 ++bufferLength;
248 }
249
250 TString bufferString(buffer);
251
252 // -- Checking for start of XML response
253 if ( bufferString.BeginsWith("<?xml") )
254 isXmlRpc = kTRUE;
255
256 // -- Append the xml response
257 if (isXmlRpc) {
258 fXmlRpcResponse.Append(bufferString);
259 }
260
261 // -- Checking for end of XML response
262 if( ! bufferString.CompareTo("</methodResponse>") )
263 break;
264 }
265
266 // -- close socket
267 socket->Close();
268
269 return 0;
270}
271
272//##################################################################################
273Int_t AliHLTHOMERProxyHandler::ProcessXmlRpcResponse() {
274 // see header file for class documentation
275
276 Int_t iResult = 0;
277
278 // -- Parse XML RPC Response
279 // ---------------------------
280
281 TDOMParser xmlParser;
282 xmlParser.SetValidate(kFALSE);
283
64984943 284 //NOTE Have to use a temporary variable for printing the XML responce,
285 // because Form might overrun its internal buffer and crash for large strings.
286 TString infoMsg = Form("XMLResponse: %s",fXmlRpcResponse.Data());
287 HLTInfo(infoMsg.Data());
a82a31af 288
06272c83 289 iResult = xmlParser.ParseBuffer(fXmlRpcResponse.Data(), fXmlRpcResponse.Length());
290 if ( iResult < 0 ) {
b6bb7ca3 291 HLTError(Form("Parsing buffer with error: %s",
e728e5ba 292 xmlParser.GetParseCodeMessage(xmlParser.GetParseCode()) ));
293
294
06272c83 295 return iResult;
296 }
297
298 TXMLNode * node = xmlParser.GetXMLDocument()->GetRootNode()->
299 GetChildren()->GetChildren()->GetChildren()->GetChildren();
300
301 if ( strcmp( node->GetNodeName(), "string" ) ) {
64984943 302 HLTError("No node 'string' in XmlRpcResponse.");
06272c83 303 return -1;
304 }
305
306 // -- Parse Content
307 // ------------------
308
309 // -- Get Content
310 TString xmlContent(node->GetText() );
311
9e78371d 312 HLTDebug(Form("XMLContent: %s",xmlContent.Data()));
06272c83 313
314 iResult = xmlParser.ParseBuffer(xmlContent.Data(), xmlContent.Length());
315 if ( iResult < 0 ) {
b6bb7ca3 316 HLTError(Form("Parsing buffer with error: %s",
e728e5ba 317 xmlParser.GetParseCodeMessage(xmlParser.GetParseCode()) ));
318
06272c83 319 return iResult;
320 }
321
06272c83 322 if ( !xmlParser.GetXMLDocument()->GetRootNode()->HasChildren() ) {
64984943 323 HLTWarning("No Services active.");
ae17e63c 324 return 1;
06272c83 325 }
326
327 // -- Loop over all service nodes
328 TXMLNode* serviceNode = xmlParser.GetXMLDocument()->GetRootNode()->GetChildren();
329 TXMLNode* prevServiceNode = NULL;
330
331 do {
332 prevServiceNode = serviceNode;
333
334 // -- Add service to list
335 iResult = AddService( serviceNode->GetChildren() );
74682ab7 336 if ( iResult > 0 ) {
64984943 337 HLTWarning("Incomplete Service not added.");
74682ab7 338 iResult = 0;
339 }
06272c83 340 } while ( ( serviceNode = prevServiceNode->GetNextNode() ) && !iResult );
341
74682ab7 342
343
06272c83 344 return iResult;
345}
346
347/*
348 * ---------------------------------------------------------------------------------
349 * Source Resolving - private
350 * ---------------------------------------------------------------------------------
351 */
352
353//##################################################################################
354Int_t AliHLTHOMERProxyHandler::AddService(TXMLNode *innerNode) {
355 // see header file for class documentation
356
357 Int_t iResult = 0;
358
64984943 359 HLTInfo(">> New service");
06272c83 360
69f2a104 361 TXMLNode* serviceNode = innerNode;
362
06272c83 363 // -- Loop over all service properties and
364 // read them from the service tag
365 // -----------------------------------------
366
367 TString hostname = "";
368 Int_t port = 0;
369 TString dataType = "";
370 TString dataOrigin = "";
371 TString dataSpecification = "";
372
373 TXMLNode* prevInnerNode = NULL;
374
69f2a104 375 // -- Retrieve hostname and port
376 // -------------------------------
377
06272c83 378 do {
379 prevInnerNode = innerNode;
380
381 if ( ! strcmp(innerNode->GetNodeName(), "text" ) )
382 continue;
69f2a104 383
06272c83 384 // -- hostname
69f2a104 385 if ( ! strcmp( innerNode->GetNodeName(), "address") ) {
386 HLTInfo(Form(" > %s ++ %s", innerNode->GetNodeName(), innerNode->GetText() ));
06272c83 387 hostname = innerNode->GetText();
69f2a104 388 }
06272c83 389 else if ( ! strcmp( innerNode->GetNodeName(), "port") ) {
69f2a104 390 HLTInfo(Form(" > %s ++ %s", innerNode->GetNodeName(), innerNode->GetText() ));
06272c83 391 TString portS(innerNode->GetText());
392 if ( portS.IsDigit() )
393 port = portS.Atoi();
394 else {
b6bb7ca3 395 HLTError(Form("Port %s is not a digit.", portS.Data()));
06272c83 396 iResult = -1;
397 }
398 }
06272c83 399 } while ( ( innerNode = prevInnerNode->GetNextNode() ) && !iResult );
400
06272c83 401
402 // -- Change hostame from service with proxy, if outside HLT
b325d632 403 if ( fRealm != kHLT && fRealm != kHLT+kHOMERRealmsMax )
06272c83 404 hostname = fgkHOMERProxyNode[fRealm];
405
e728e5ba 406
69f2a104 407 // -- Get Data Specifications from blocks
408 // ----------------------------------------
409
410 do {
411 prevInnerNode = serviceNode;
412
413 if ( strcmp( serviceNode->GetNodeName(), "blocks") )
414 continue;
415
416 TXMLNode* blocks = serviceNode->GetChildren();
417
418 if ( ! blocks ) {
64984943 419 HLTError("No blocks present");
69f2a104 420 return 1;
421 }
422
423 TXMLNode* blockNode = blocks->GetNextNode();
424 TXMLNode* prevBlockNode = NULL;
425
426 if ( ! blockNode ) {
64984943 427 HLTError("No block present in the blocks tag");
69f2a104 428 return 1;
429 }
430
431 // -- blocks loop
432
433 do {
434 prevBlockNode = blockNode;
435
436 if ( strcmp( blockNode->GetNodeName(), "block") )
437 continue;
438
439 TXMLNode *dataNode = blockNode->GetChildren();
440 TXMLNode *prevDataNode = NULL;
441
442 if ( ! dataNode ) {
64984943 443 HLTError("No data specification tags present in block tag.");
69f2a104 444 return 1;
445 }
446 // -- data spec loop
447
448 do {
449 prevDataNode = dataNode;
450
451 if ( ! strcmp(dataNode->GetNodeName(), "text" ) )
452 continue;
453
454 HLTInfo(Form(" %s ++ %s", dataNode->GetNodeName(), dataNode->GetText() ));
455
456 if ( ! strcmp( dataNode->GetNodeName(), "dataorigin") ) {
457 dataOrigin = dataNode->GetText();
458 }
459 else if ( ! strcmp( dataNode->GetNodeName(), "datatype") ) {
460 dataType = dataNode->GetText();
461 }
462 else if ( ! strcmp( dataNode->GetNodeName(), "dataspecification") ) {
463 dataSpecification = dataNode->GetText();
464 }
465 } while ( ( dataNode = prevDataNode->GetNextNode() ) && !iResult );
466
467 // -- data spec loop
468
469 // -- Check the service properties
470 // ---------------------------------
471
472 // -- Check for completeness of the source properties
473 if ( hostname.IsNull() || !port || dataOrigin.IsNull() ||
474 dataType.IsNull() || dataSpecification.IsNull() ) {
475 HLTWarning(Form("Service provides not all values:\n\thostname\t\t %s\n\tport\t\t\t %d\n\tdataorigin\t\t %s\n\tdatatype\t\t %s\n\tdataspecification\t 0x%08X",
476 hostname.Data(), port, dataOrigin.Data(), dataType.Data(), dataSpecification.Atoi()));
477
478 return 1;
479 }
06272c83 480
69f2a104 481 // -- Create new source
482 // ----------------------
483
484 AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc();
485 source->SetService( hostname, port, dataOrigin, dataType, dataSpecification );
486
487 fSourceList->Add( source );
488
489 HLTInfo(Form( "New Source added : %s", source->GetSourceName().Data()));
06272c83 490
69f2a104 491 } while ( ( blockNode = prevBlockNode->GetNextNode() ) && !iResult );
06272c83 492
06272c83 493
69f2a104 494 // -- blocks loop
495
496 } while ( ( serviceNode = prevInnerNode->GetNextNode() ) && !iResult );
06272c83 497
498 return iResult;
499}
500
501