]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTHOMERProxyHandler.cxx
removal of unused code
[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) {
b6bb7ca3 95 HLTError(Form("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) {
b6bb7ca3 236 HLTError(Form("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
c8fc4838 284 HLTInfo(Form("XMLResponse: %s",fXmlRpcResponse.Data()));
a82a31af 285
06272c83 286 iResult = xmlParser.ParseBuffer(fXmlRpcResponse.Data(), fXmlRpcResponse.Length());
287 if ( iResult < 0 ) {
b6bb7ca3 288 HLTError(Form("Parsing buffer with error: %s",
e728e5ba 289 xmlParser.GetParseCodeMessage(xmlParser.GetParseCode()) ));
290
291
06272c83 292 return iResult;
293 }
294
295 TXMLNode * node = xmlParser.GetXMLDocument()->GetRootNode()->
296 GetChildren()->GetChildren()->GetChildren()->GetChildren();
297
298 if ( strcmp( node->GetNodeName(), "string" ) ) {
b6bb7ca3 299 HLTError(Form("No node 'string' in XmlRpcResponse."));
06272c83 300 return -1;
301 }
302
303 // -- Parse Content
304 // ------------------
305
306 // -- Get Content
307 TString xmlContent(node->GetText() );
308
9e78371d 309 HLTDebug(Form("XMLContent: %s",xmlContent.Data()));
06272c83 310
311 iResult = xmlParser.ParseBuffer(xmlContent.Data(), xmlContent.Length());
312 if ( iResult < 0 ) {
b6bb7ca3 313 HLTError(Form("Parsing buffer with error: %s",
e728e5ba 314 xmlParser.GetParseCodeMessage(xmlParser.GetParseCode()) ));
315
06272c83 316 return iResult;
317 }
318
06272c83 319 if ( !xmlParser.GetXMLDocument()->GetRootNode()->HasChildren() ) {
b6bb7ca3 320 HLTWarning(Form("No Services active."));
ae17e63c 321 return 1;
06272c83 322 }
323
324 // -- Loop over all service nodes
325 TXMLNode* serviceNode = xmlParser.GetXMLDocument()->GetRootNode()->GetChildren();
326 TXMLNode* prevServiceNode = NULL;
327
328 do {
329 prevServiceNode = serviceNode;
330
331 // -- Add service to list
332 iResult = AddService( serviceNode->GetChildren() );
74682ab7 333 if ( iResult > 0 ) {
b6bb7ca3 334 HLTWarning(Form("Incomplete Service not added."));
74682ab7 335 iResult = 0;
336 }
06272c83 337 } while ( ( serviceNode = prevServiceNode->GetNextNode() ) && !iResult );
338
74682ab7 339
340
06272c83 341 return iResult;
342}
343
344/*
345 * ---------------------------------------------------------------------------------
346 * Source Resolving - private
347 * ---------------------------------------------------------------------------------
348 */
349
350//##################################################################################
351Int_t AliHLTHOMERProxyHandler::AddService(TXMLNode *innerNode) {
352 // see header file for class documentation
353
354 Int_t iResult = 0;
355
b6bb7ca3 356 HLTInfo(Form(">> New service"));
06272c83 357
69f2a104 358 TXMLNode* serviceNode = innerNode;
359
06272c83 360 // -- Loop over all service properties and
361 // read them from the service tag
362 // -----------------------------------------
363
364 TString hostname = "";
365 Int_t port = 0;
366 TString dataType = "";
367 TString dataOrigin = "";
368 TString dataSpecification = "";
369
370 TXMLNode* prevInnerNode = NULL;
371
69f2a104 372 // -- Retrieve hostname and port
373 // -------------------------------
374
06272c83 375 do {
376 prevInnerNode = innerNode;
377
378 if ( ! strcmp(innerNode->GetNodeName(), "text" ) )
379 continue;
69f2a104 380
06272c83 381 // -- hostname
69f2a104 382 if ( ! strcmp( innerNode->GetNodeName(), "address") ) {
383 HLTInfo(Form(" > %s ++ %s", innerNode->GetNodeName(), innerNode->GetText() ));
06272c83 384 hostname = innerNode->GetText();
69f2a104 385 }
06272c83 386 else if ( ! strcmp( innerNode->GetNodeName(), "port") ) {
69f2a104 387 HLTInfo(Form(" > %s ++ %s", innerNode->GetNodeName(), innerNode->GetText() ));
06272c83 388 TString portS(innerNode->GetText());
389 if ( portS.IsDigit() )
390 port = portS.Atoi();
391 else {
b6bb7ca3 392 HLTError(Form("Port %s is not a digit.", portS.Data()));
06272c83 393 iResult = -1;
394 }
395 }
06272c83 396 } while ( ( innerNode = prevInnerNode->GetNextNode() ) && !iResult );
397
06272c83 398
399 // -- Change hostame from service with proxy, if outside HLT
b325d632 400 if ( fRealm != kHLT && fRealm != kHLT+kHOMERRealmsMax )
06272c83 401 hostname = fgkHOMERProxyNode[fRealm];
402
e728e5ba 403
69f2a104 404 // -- Get Data Specifications from blocks
405 // ----------------------------------------
406
407 do {
408 prevInnerNode = serviceNode;
409
410 if ( strcmp( serviceNode->GetNodeName(), "blocks") )
411 continue;
412
413 TXMLNode* blocks = serviceNode->GetChildren();
414
415 if ( ! blocks ) {
416 HLTError(Form("No blocks present"));
417 return 1;
418 }
419
420 TXMLNode* blockNode = blocks->GetNextNode();
421 TXMLNode* prevBlockNode = NULL;
422
423 if ( ! blockNode ) {
424 HLTError(Form("No block present in the blocks tag"));
425 return 1;
426 }
427
428 // -- blocks loop
429
430 do {
431 prevBlockNode = blockNode;
432
433 if ( strcmp( blockNode->GetNodeName(), "block") )
434 continue;
435
436 TXMLNode *dataNode = blockNode->GetChildren();
437 TXMLNode *prevDataNode = NULL;
438
439 if ( ! dataNode ) {
440 HLTError(Form("No data specification tags present in block tag."));
441 return 1;
442 }
443 // -- data spec loop
444
445 do {
446 prevDataNode = dataNode;
447
448 if ( ! strcmp(dataNode->GetNodeName(), "text" ) )
449 continue;
450
451 HLTInfo(Form(" %s ++ %s", dataNode->GetNodeName(), dataNode->GetText() ));
452
453 if ( ! strcmp( dataNode->GetNodeName(), "dataorigin") ) {
454 dataOrigin = dataNode->GetText();
455 }
456 else if ( ! strcmp( dataNode->GetNodeName(), "datatype") ) {
457 dataType = dataNode->GetText();
458 }
459 else if ( ! strcmp( dataNode->GetNodeName(), "dataspecification") ) {
460 dataSpecification = dataNode->GetText();
461 }
462 } while ( ( dataNode = prevDataNode->GetNextNode() ) && !iResult );
463
464 // -- data spec loop
465
466 // -- Check the service properties
467 // ---------------------------------
468
469 // -- Check for completeness of the source properties
470 if ( hostname.IsNull() || !port || dataOrigin.IsNull() ||
471 dataType.IsNull() || dataSpecification.IsNull() ) {
472 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",
473 hostname.Data(), port, dataOrigin.Data(), dataType.Data(), dataSpecification.Atoi()));
474
475 return 1;
476 }
06272c83 477
69f2a104 478 // -- Create new source
479 // ----------------------
480
481 AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc();
482 source->SetService( hostname, port, dataOrigin, dataType, dataSpecification );
483
484 fSourceList->Add( source );
485
486 HLTInfo(Form( "New Source added : %s", source->GetSourceName().Data()));
06272c83 487
69f2a104 488 } while ( ( blockNode = prevBlockNode->GetNextNode() ) && !iResult );
06272c83 489
06272c83 490
69f2a104 491 // -- blocks loop
492
493 } while ( ( serviceNode = prevInnerNode->GetNextNode() ) && !iResult );
06272c83 494
495 return iResult;
496}
497
498