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()) ));
299 if ( !xmlParser.GetXMLDocument()->GetRootNode()->HasChildren() ) {
300 HLTWarning(Form("No Services active."));
304 // -- Loop over all service nodes
305 TXMLNode* serviceNode = xmlParser.GetXMLDocument()->GetRootNode()->GetChildren();
306 TXMLNode* prevServiceNode = NULL;
309 prevServiceNode = serviceNode;
311 // -- Add service to list
312 iResult = AddService( serviceNode->GetChildren() );
314 HLTWarning(Form("Incomplete Service not added."));
317 } while ( ( serviceNode = prevServiceNode->GetNextNode() ) && !iResult );
325 * ---------------------------------------------------------------------------------
326 * Source Resolving - private
327 * ---------------------------------------------------------------------------------
330 //##################################################################################
331 Int_t AliHLTHOMERProxyHandler::AddService(TXMLNode *innerNode) {
332 // see header file for class documentation
336 HLTInfo(Form(">> New service"));
338 // -- Loop over all service properties and
339 // read them from the service tag
340 // -----------------------------------------
342 TString hostname = "";
344 TString dataType = "";
345 TString dataOrigin = "";
346 TString dataSpecification = "";
348 TXMLNode* prevInnerNode = NULL;
351 prevInnerNode = innerNode;
353 if ( ! strcmp(innerNode->GetNodeName(), "text" ) )
356 HLTInfo(Form(" %s ++ %s", innerNode->GetNodeName(), innerNode->GetText() ));
359 if ( ! strcmp( innerNode->GetNodeName(), "address") )
360 hostname = innerNode->GetText();
361 else if ( ! strcmp( innerNode->GetNodeName(), "port") ) {
362 TString portS(innerNode->GetText());
363 if ( portS.IsDigit() )
366 HLTError(Form("Port %s is not a digit.", portS.Data()));
370 else if ( ! strcmp( innerNode->GetNodeName(), "dataorigin") )
371 dataOrigin = innerNode->GetText();
372 else if ( ! strcmp( innerNode->GetNodeName(), "datatype") )
373 dataType = innerNode->GetText();
374 else if ( ! strcmp( innerNode->GetNodeName(), "dataspecification") )
375 dataSpecification = innerNode->GetText();
377 } while ( ( innerNode = prevInnerNode->GetNextNode() ) && !iResult );
379 // -- Check the service properties
380 // ---------------------------------
382 // -- Change hostame from service with proxy, if outside HLT
383 if ( fRealm != kHLT || fRealm != kHLT+kHOMERRealmsMax )
384 hostname = fgkHOMERProxyNode[fRealm];
386 // -- Check for completeness of the source properties
387 if ( hostname.IsNull() || !port || dataOrigin.IsNull() ||
388 dataType.IsNull() || dataSpecification.IsNull() ) {
389 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 %s",
390 hostname.Data(), port, dataOrigin.Data(), dataType.Data(), dataSpecification.Data()));
395 // -- Create new source
396 // ----------------------
398 AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc();
399 source->SetService( hostname, port, dataOrigin, dataType, dataSpecification );
401 fSourceList->Add( source );
403 HLTInfo(Form( "New Source added : %s", source->GetSourceName().Data()));