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. *
7 //* Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTHOMERProxyHandler.cxx
20 @author Jochen Thaeder
22 @brief HOMER proxy handler for HomerManger
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
35 #include "TDOMParser.h"
38 // -- -- -- -- -- -- --
39 #include "AliHLTHOMERProxyHandler.h"
40 // -- -- -- -- -- -- --
42 ClassImp(AliHLTHOMERProxyHandler)
45 * ---------------------------------------------------------------------------------
46 * Constructor / Destructor
47 * ---------------------------------------------------------------------------------
50 //##################################################################################
51 AliHLTHOMERProxyHandler::AliHLTHOMERProxyHandler() :
55 // see header file for class documentation
57 // refer to README to build package
59 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62 //##################################################################################
63 AliHLTHOMERProxyHandler::~AliHLTHOMERProxyHandler() {
64 // see header file for class documentation
68 //##################################################################################
69 Int_t AliHLTHOMERProxyHandler::Initialize() {
70 // see header file for class documentation
80 * ---------------------------------------------------------------------------------
81 * Source List - public
82 * ---------------------------------------------------------------------------------
85 //##################################################################################
86 Int_t AliHLTHOMERProxyHandler::FillSourceList(TList *srcList) {
87 // see header file for class documentation
91 fSourceList = srcList;
93 iResult = RequestXmlRpcResponse();
96 iResult = ProcessXmlRpcResponse();
99 HLTError(Form("Filling SourceList failed."));
106 * ---------------------------------------------------------------------------------
108 * ---------------------------------------------------------------------------------
111 //##################################################################################
112 const Char_t *AliHLTHOMERProxyHandler::fgkHOMERProxyNode[] = {
113 "portal-dcs0.internal",
114 "alihlt-dcs0.cern.ch",
115 "alihlt-vobox0.cern.ch",
116 "alihlt-gw0.kip.uni-heidelberg.de",
118 "portal-dcs1.internal",
119 "alihlt-dcs1.cern.ch",
120 "alihlt-vobox1.cern.ch",
121 "alihlt-gw1.kip.uni-heidelberg.de",
125 //##################################################################################
126 void AliHLTHOMERProxyHandler::IdentifyRealm() {
127 // see header file for class documentation
129 TString hostIP(gSystem->GetHostByName(gSystem->HostName()).GetHostAddress());
131 if ( hostIP.Contains("10.162.") )
133 else if ( hostIP.Contains("10.160.") || hostIP.Contains("10.161.") )
135 else if ( hostIP.Contains("129.206.") )
137 else if ( hostIP.Contains("137.138")
138 || hostIP.Contains("128.141")
139 || hostIP.Contains("127.0.")
150 * ---------------------------------------------------------------------------------
151 * Proxy Communication - private
152 * ---------------------------------------------------------------------------------
155 //##################################################################################
156 Int_t AliHLTHOMERProxyHandler::RequestXmlRpcResponse() {
157 // see header file for class documentation
164 Int_t proxyPort = 19999;
166 TSocket *socket = new TSocket(fgkHOMERProxyNode[fRealm], proxyPort);
167 if ( ! socket->IsValid() ) {
168 HLTWarning(Form("Failed to create socket to %s:%d,",fgkHOMERProxyNode[fRealm], proxyPort));
169 HLTWarning(Form("trying %s:%d now.", fgkHOMERProxyNode[fRealm+kHOMERRealmsMax],proxyPort));
171 socket = new TSocket(fgkHOMERProxyNode[fRealm+kHOMERRealmsMax], proxyPort);
172 if ( ! socket->IsValid() ) {
173 HLTError(Form("Failed to create socket to %s:%d and %s:%d.",
174 fgkHOMERProxyNode[fRealm], proxyPort,
175 fgkHOMERProxyNode[fRealm+kHOMERRealmsMax],proxyPort));
181 fRealm = fRealm+kHOMERRealmsMax;
187 Char_t reqMsg[] = "PUT / HTTP/1.1\r\n\
188 User-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\
189 Host: localhost:10000\r\n\
191 Content-type: text/xml\r\n\
192 Content-Length: 68\r\n\
193 \r\n<methodCall><methodName>getTcpDumpServices</methodName></methodCall>\r\n";
195 iResult = socket->SendRaw( reqMsg, strlen(reqMsg) );
197 iResult != static_cast<Int_t>(strlen(reqMsg))) {
198 HLTError(Form("Error sending! -- send length %d -- msg length %d.", iResult, static_cast<Int_t>(strlen(reqMsg)) ));
204 // -------------------
206 const Int_t bufferSize = 1024;
207 Char_t buffer[bufferSize];
209 Bool_t isXmlRpc = kFALSE;
211 fXmlRpcResponse = "";
213 // -- loop for getting full xmlRPC response
216 Int_t bufferLength = 0;
218 // -- loop for reading until end of line
221 iResult = socket->RecvRaw(&buffer[bufferLength], 1);
223 HLTError(Form("Error reading form socket."));
228 // -- Checking for end of line
229 if ( buffer[bufferLength] == 10 ) {
230 buffer[bufferLength] = 0;
237 TString bufferString(buffer);
239 // -- Checking for start of XML response
240 if ( bufferString.BeginsWith("<?xml") )
243 // -- Append the xml response
245 fXmlRpcResponse.Append(bufferString);
248 // -- Checking for end of XML response
249 if( ! bufferString.CompareTo("</methodResponse>") )
259 //##################################################################################
260 Int_t AliHLTHOMERProxyHandler::ProcessXmlRpcResponse() {
261 // see header file for class documentation
265 // -- Parse XML RPC Response
266 // ---------------------------
268 TDOMParser xmlParser;
269 xmlParser.SetValidate(kFALSE);
271 HLTDebug(Form("XMLResponse: %s",fXmlRpcResponse.Data()));
273 iResult = xmlParser.ParseBuffer(fXmlRpcResponse.Data(), fXmlRpcResponse.Length());
275 HLTError(Form("Parsing buffer with error: %s",
276 xmlParser.GetParseCodeMessage(xmlParser.GetParseCode()) ));
282 TXMLNode * node = xmlParser.GetXMLDocument()->GetRootNode()->
283 GetChildren()->GetChildren()->GetChildren()->GetChildren();
285 if ( strcmp( node->GetNodeName(), "string" ) ) {
286 HLTError(Form("No node 'string' in XmlRpcResponse."));
291 // ------------------
294 TString xmlContent(node->GetText() );
296 HLTDebug(Form("XMLContent: %s",xmlContent.Data()));
298 iResult = xmlParser.ParseBuffer(xmlContent.Data(), xmlContent.Length());
300 HLTError(Form("Parsing buffer with error: %s",
301 xmlParser.GetParseCodeMessage(xmlParser.GetParseCode()) ));
306 if ( !xmlParser.GetXMLDocument()->GetRootNode()->HasChildren() ) {
307 HLTWarning(Form("No Services active."));
311 // -- Loop over all service nodes
312 TXMLNode* serviceNode = xmlParser.GetXMLDocument()->GetRootNode()->GetChildren();
313 TXMLNode* prevServiceNode = NULL;
316 prevServiceNode = serviceNode;
318 // -- Add service to list
319 iResult = AddService( serviceNode->GetChildren() );
321 HLTWarning(Form("Incomplete Service not added."));
324 } while ( ( serviceNode = prevServiceNode->GetNextNode() ) && !iResult );
332 * ---------------------------------------------------------------------------------
333 * Source Resolving - private
334 * ---------------------------------------------------------------------------------
337 //##################################################################################
338 Int_t AliHLTHOMERProxyHandler::AddService(TXMLNode *innerNode) {
339 // see header file for class documentation
343 HLTInfo(Form(">> New service"));
345 TXMLNode* serviceNode = innerNode;
347 // -- Loop over all service properties and
348 // read them from the service tag
349 // -----------------------------------------
351 TString hostname = "";
353 TString dataType = "";
354 TString dataOrigin = "";
355 TString dataSpecification = "";
357 TXMLNode* prevInnerNode = NULL;
359 // -- Retrieve hostname and port
360 // -------------------------------
363 prevInnerNode = innerNode;
365 if ( ! strcmp(innerNode->GetNodeName(), "text" ) )
369 if ( ! strcmp( innerNode->GetNodeName(), "address") ) {
370 HLTInfo(Form(" > %s ++ %s", innerNode->GetNodeName(), innerNode->GetText() ));
371 hostname = innerNode->GetText();
373 else if ( ! strcmp( innerNode->GetNodeName(), "port") ) {
374 HLTInfo(Form(" > %s ++ %s", innerNode->GetNodeName(), innerNode->GetText() ));
375 TString portS(innerNode->GetText());
376 if ( portS.IsDigit() )
379 HLTError(Form("Port %s is not a digit.", portS.Data()));
383 } while ( ( innerNode = prevInnerNode->GetNextNode() ) && !iResult );
386 // -- Change hostame from service with proxy, if outside HLT
387 if ( fRealm != kHLT && fRealm != kHLT+kHOMERRealmsMax )
388 hostname = fgkHOMERProxyNode[fRealm];
391 // -- Get Data Specifications from blocks
392 // ----------------------------------------
395 prevInnerNode = serviceNode;
397 if ( strcmp( serviceNode->GetNodeName(), "blocks") )
400 TXMLNode* blocks = serviceNode->GetChildren();
403 HLTError(Form("No blocks present"));
407 TXMLNode* blockNode = blocks->GetNextNode();
408 TXMLNode* prevBlockNode = NULL;
411 HLTError(Form("No block present in the blocks tag"));
418 prevBlockNode = blockNode;
420 if ( strcmp( blockNode->GetNodeName(), "block") )
423 TXMLNode *dataNode = blockNode->GetChildren();
424 TXMLNode *prevDataNode = NULL;
427 HLTError(Form("No data specification tags present in block tag."));
433 prevDataNode = dataNode;
435 if ( ! strcmp(dataNode->GetNodeName(), "text" ) )
438 HLTInfo(Form(" %s ++ %s", dataNode->GetNodeName(), dataNode->GetText() ));
440 if ( ! strcmp( dataNode->GetNodeName(), "dataorigin") ) {
441 dataOrigin = dataNode->GetText();
443 else if ( ! strcmp( dataNode->GetNodeName(), "datatype") ) {
444 dataType = dataNode->GetText();
446 else if ( ! strcmp( dataNode->GetNodeName(), "dataspecification") ) {
447 dataSpecification = dataNode->GetText();
449 } while ( ( dataNode = prevDataNode->GetNextNode() ) && !iResult );
453 // -- Check the service properties
454 // ---------------------------------
456 // -- Check for completeness of the source properties
457 if ( hostname.IsNull() || !port || dataOrigin.IsNull() ||
458 dataType.IsNull() || dataSpecification.IsNull() ) {
459 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",
460 hostname.Data(), port, dataOrigin.Data(), dataType.Data(), dataSpecification.Atoi()));
465 // -- Create new source
466 // ----------------------
468 AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc();
469 source->SetService( hostname, port, dataOrigin, dataType, dataSpecification );
471 fSourceList->Add( source );
473 HLTInfo(Form( "New Source added : %s", source->GetSourceName().Data()));
475 } while ( ( blockNode = prevBlockNode->GetNextNode() ) && !iResult );
480 } while ( ( serviceNode = prevInnerNode->GetNextNode() ) && !iResult );