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",
117 "portal-dcs1.internal",
118 "alihlt-dcs1.cern.ch",
119 "alihlt-vobox1.cern.ch",
120 "alihlt-gw1.kip.uni-heidelberg.de"
123 //##################################################################################
124 void AliHLTHOMERProxyHandler::IdentifyRealm() {
125 // see header file for class documentation
127 TString hostIP(gSystem->GetHostByName(gSystem->HostName()).GetHostAddress());
129 if ( hostIP.Contains("10.162.") )
131 else if ( hostIP.Contains("10.160.") || hostIP.Contains("10.161.") )
133 else if ( hostIP.Contains("129.206.") )
142 * ---------------------------------------------------------------------------------
143 * Proxy Communication - private
144 * ---------------------------------------------------------------------------------
147 //##################################################################################
148 Int_t AliHLTHOMERProxyHandler::RequestXmlRpcResponse() {
149 // see header file for class documentation
156 Int_t proxyPort = 19999;
158 TSocket *socket = new TSocket(fgkHOMERProxyNode[fRealm], proxyPort);
159 if ( ! socket->IsValid() ) {
160 HLTWarning(Form("Failed to create socket to %s:%d,",fgkHOMERProxyNode[fRealm], proxyPort));
161 HLTWarning(Form("trying %s:%d now.", fgkHOMERProxyNode[fRealm+kHOMERRealmsMax],proxyPort));
163 socket = new TSocket(fgkHOMERProxyNode[fRealm+kHOMERRealmsMax], proxyPort);
164 if ( ! socket->IsValid() ) {
165 HLTError(Form("Failed to create socket to %s:%d and %s:%d.",
166 fgkHOMERProxyNode[fRealm], proxyPort,
167 fgkHOMERProxyNode[fRealm+kHOMERRealmsMax],proxyPort));
173 fRealm = fRealm+kHOMERRealmsMax;
179 Char_t reqMsg[] = "PUT / HTTP/1.1\r\n\
180 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\
181 Host: localhost:10000\r\n\
183 Content-type: text/xml\r\n\
184 Content-Length: 68\r\n\
185 \r\n<methodCall><methodName>getTcpDumpServices</methodName></methodCall>\r\n";
187 iResult = socket->SendRaw( reqMsg, strlen(reqMsg) );
189 iResult != static_cast<Int_t>(strlen(reqMsg))) {
190 HLTError(Form("Error sending! -- send length %d -- msg length %d.", iResult, static_cast<Int_t>(strlen(reqMsg)) ));
196 // -------------------
198 const Int_t bufferSize = 1024;
199 Char_t buffer[bufferSize];
201 Bool_t isXmlRpc = kFALSE;
203 fXmlRpcResponse = "";
205 // -- loop for getting full xmlRPC response
208 Int_t bufferLength = 0;
210 // -- loop for reading until end of line
213 iResult = socket->RecvRaw(&buffer[bufferLength], 1);
215 HLTError(Form("Error reading form socket."));
220 // -- Checking for end of line
221 if ( buffer[bufferLength] == 10 ) {
222 buffer[bufferLength] = 0;
229 TString bufferString(buffer);
231 // -- Checking for start of XML response
232 if ( bufferString.BeginsWith("<?xml") )
235 // -- Append the xml response
237 fXmlRpcResponse.Append(bufferString);
240 // -- Checking for end of XML response
241 if( ! bufferString.CompareTo("</methodResponse>") )
251 //##################################################################################
252 Int_t AliHLTHOMERProxyHandler::ProcessXmlRpcResponse() {
253 // see header file for class documentation
257 // -- Parse XML RPC Response
258 // ---------------------------
260 TDOMParser xmlParser;
261 xmlParser.SetValidate(kFALSE);
263 HLTDebug(Form("XMLResponse: %s",fXmlRpcResponse.Data()));
265 iResult = xmlParser.ParseBuffer(fXmlRpcResponse.Data(), fXmlRpcResponse.Length());
267 HLTError(Form("Parsing buffer with error: %s",
268 xmlParser.GetParseCodeMessage(xmlParser.GetParseCode()) ));
274 TXMLNode * node = xmlParser.GetXMLDocument()->GetRootNode()->
275 GetChildren()->GetChildren()->GetChildren()->GetChildren();
277 if ( strcmp( node->GetNodeName(), "string" ) ) {
278 HLTError(Form("No node 'string' in XmlRpcResponse."));
283 // ------------------
286 TString xmlContent(node->GetText() );
288 HLTDebug(Form("XMLContent: %s",xmlContent.Data()));
290 iResult = xmlParser.ParseBuffer(xmlContent.Data(), xmlContent.Length());
292 HLTError(Form("Parsing buffer with error: %s",
293 xmlParser.GetParseCodeMessage(xmlParser.GetParseCode()) ));
298 if ( !xmlParser.GetXMLDocument()->GetRootNode()->HasChildren() ) {
299 HLTWarning(Form("No Services active."));
303 // -- Loop over all service nodes
304 TXMLNode* serviceNode = xmlParser.GetXMLDocument()->GetRootNode()->GetChildren();
305 TXMLNode* prevServiceNode = NULL;
308 prevServiceNode = serviceNode;
310 // -- Add service to list
311 iResult = AddService( serviceNode->GetChildren() );
313 HLTWarning(Form("Incomplete Service not added."));
316 } while ( ( serviceNode = prevServiceNode->GetNextNode() ) && !iResult );
324 * ---------------------------------------------------------------------------------
325 * Source Resolving - private
326 * ---------------------------------------------------------------------------------
329 //##################################################################################
330 Int_t AliHLTHOMERProxyHandler::AddService(TXMLNode *innerNode) {
331 // see header file for class documentation
335 HLTInfo(Form(">> New service"));
337 TXMLNode* serviceNode = innerNode;
339 // -- Loop over all service properties and
340 // read them from the service tag
341 // -----------------------------------------
343 TString hostname = "";
345 TString dataType = "";
346 TString dataOrigin = "";
347 TString dataSpecification = "";
349 TXMLNode* prevInnerNode = NULL;
351 // -- Retrieve hostname and port
352 // -------------------------------
355 prevInnerNode = innerNode;
357 if ( ! strcmp(innerNode->GetNodeName(), "text" ) )
361 if ( ! strcmp( innerNode->GetNodeName(), "address") ) {
362 HLTInfo(Form(" > %s ++ %s", innerNode->GetNodeName(), innerNode->GetText() ));
363 hostname = innerNode->GetText();
365 else if ( ! strcmp( innerNode->GetNodeName(), "port") ) {
366 HLTInfo(Form(" > %s ++ %s", innerNode->GetNodeName(), innerNode->GetText() ));
367 TString portS(innerNode->GetText());
368 if ( portS.IsDigit() )
371 HLTError(Form("Port %s is not a digit.", portS.Data()));
375 } while ( ( innerNode = prevInnerNode->GetNextNode() ) && !iResult );
378 // -- Change hostame from service with proxy, if outside HLT
379 if ( fRealm != kHLT || fRealm != kHLT+kHOMERRealmsMax )
380 hostname = fgkHOMERProxyNode[fRealm];
383 // -- Get Data Specifications from blocks
384 // ----------------------------------------
387 prevInnerNode = serviceNode;
389 if ( strcmp( serviceNode->GetNodeName(), "blocks") )
392 TXMLNode* blocks = serviceNode->GetChildren();
395 HLTError(Form("No blocks present"));
399 TXMLNode* blockNode = blocks->GetNextNode();
400 TXMLNode* prevBlockNode = NULL;
403 HLTError(Form("No block present in the blocks tag"));
410 prevBlockNode = blockNode;
412 if ( strcmp( blockNode->GetNodeName(), "block") )
415 TXMLNode *dataNode = blockNode->GetChildren();
416 TXMLNode *prevDataNode = NULL;
419 HLTError(Form("No data specification tags present in block tag."));
425 prevDataNode = dataNode;
427 if ( ! strcmp(dataNode->GetNodeName(), "text" ) )
430 HLTInfo(Form(" %s ++ %s", dataNode->GetNodeName(), dataNode->GetText() ));
432 if ( ! strcmp( dataNode->GetNodeName(), "dataorigin") ) {
433 dataOrigin = dataNode->GetText();
435 else if ( ! strcmp( dataNode->GetNodeName(), "datatype") ) {
436 dataType = dataNode->GetText();
438 else if ( ! strcmp( dataNode->GetNodeName(), "dataspecification") ) {
439 dataSpecification = dataNode->GetText();
441 } while ( ( dataNode = prevDataNode->GetNextNode() ) && !iResult );
445 // -- Check the service properties
446 // ---------------------------------
448 // -- Check for completeness of the source properties
449 if ( hostname.IsNull() || !port || dataOrigin.IsNull() ||
450 dataType.IsNull() || dataSpecification.IsNull() ) {
451 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",
452 hostname.Data(), port, dataOrigin.Data(), dataType.Data(), dataSpecification.Atoi()));
457 // -- Create new source
458 // ----------------------
460 AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc();
461 source->SetService( hostname, port, dataOrigin, dataType, dataSpecification );
463 fSourceList->Add( source );
465 HLTInfo(Form( "New Source added : %s", source->GetSourceName().Data()));
467 } while ( ( blockNode = prevBlockNode->GetNextNode() ) && !iResult );
472 } while ( ( serviceNode = prevInnerNode->GetNextNode() ) && !iResult );