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"
41 ClassImp(AliHLTHOMERProxyHandler)
44 * ---------------------------------------------------------------------------------
45 * Constructor / Destructor
46 * ---------------------------------------------------------------------------------
49 //##################################################################################
50 AliHLTHOMERProxyHandler::AliHLTHOMERProxyHandler() :
54 // see header file for class documentation
56 // refer to README to build package
58 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
61 //##################################################################################
62 AliHLTHOMERProxyHandler::~AliHLTHOMERProxyHandler() {
63 // see header file for class documentation
67 //##################################################################################
68 Int_t AliHLTHOMERProxyHandler::Initialize() {
69 // see header file for class documentation
79 * ---------------------------------------------------------------------------------
80 * Source List - public
81 * ---------------------------------------------------------------------------------
84 //##################################################################################
85 Int_t AliHLTHOMERProxyHandler::FillSourceList(TList *srcList) {
86 // see header file for class documentation
90 fSourceList = srcList;
92 iResult = RequestXmlRpcResponse();
95 iResult = ProcessXmlRpcResponse();
98 HLTError("Filling SourceList failed.");
104 * ---------------------------------------------------------------------------------
106 * ---------------------------------------------------------------------------------
109 //##################################################################################
110 const Char_t *AliHLTHOMERProxyHandler::fgkHOMERProxyNode[] = {
111 "portal-dcs0.internal",
112 "alihlt-dcs0.cern.ch",
113 "alihlt-vobox0.cern.ch",
114 "alihlt-gw0.kip.uni-heidelberg.de",
115 "portal-dcs1.internal",
116 "alihlt-dcs1.cern.ch",
117 "alihlt-vobox1.cern.ch",
118 "alihlt-gw1.kip.uni-heidelberg.de"
121 //##################################################################################
122 void AliHLTHOMERProxyHandler::IdentifyRealm() {
123 // see header file for class documentation
125 TString hostIP(gSystem->GetHostByName(gSystem->HostName()).GetHostAddress());
127 if ( hostIP.Contains("10.162.") )
129 else if ( hostIP.Contains("10.160.") || hostIP.Contains("10.161.") )
131 else if ( hostIP.Contains("129.206.") )
140 * ---------------------------------------------------------------------------------
141 * Proxy Communication - private
142 * ---------------------------------------------------------------------------------
145 //##################################################################################
146 Int_t AliHLTHOMERProxyHandler::RequestXmlRpcResponse() {
147 // see header file for class documentation
154 Int_t proxyPort = 19999;
156 TSocket *socket = new TSocket(fgkHOMERProxyNode[fRealm], proxyPort);
157 if ( ! socket->IsValid() ) {
158 HLTWarning("Failed to create socket to %s:%d,",fgkHOMERProxyNode[fRealm], proxyPort);
159 HLTWarning("trying %s:%d now.", fgkHOMERProxyNode[fRealm+kHOMERRealmsMax],proxyPort);
161 socket = new TSocket(fgkHOMERProxyNode[fRealm+kHOMERRealmsMax], proxyPort);
162 if ( ! socket->IsValid() ) {
163 HLTError("Failed to create socket to %s:%d and %s:%d.",
164 fgkHOMERProxyNode[fRealm], proxyPort,
165 fgkHOMERProxyNode[fRealm+kHOMERRealmsMax],proxyPort);
170 fRealm = fRealm+kHOMERRealmsMax;
176 Char_t reqMsg[] = "PUT / HTTP/1.1\r\n\
177 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\
178 Host: localhost:10000\r\n\
180 Content-type: text/xml\r\n\
181 Content-Length: 68\r\n\
182 \r\n<methodCall><methodName>getTcpDumpServices</methodName></methodCall>\r\n";
184 iResult = socket->SendRaw( reqMsg, strlen(reqMsg) );
186 iResult != static_cast<Int_t>(strlen(reqMsg))) {
187 HLTError("Error sending! -- send length %d -- msg length %d.", iResult, strlen(reqMsg) );
193 // -------------------
195 const Int_t bufferSize = 1024;
196 Char_t buffer[bufferSize];
198 Bool_t isXmlRpc = kFALSE;
200 fXmlRpcResponse = "";
202 // -- loop for getting full xmlRPC response
205 Int_t bufferLength = 0;
207 // -- loop for reading until end of line
210 iResult = socket->RecvRaw(&buffer[bufferLength], 1);
212 HLTError("Error reading form socket.");
217 // -- Checking for end of line
218 if ( buffer[bufferLength] == 10 ) {
219 buffer[bufferLength] = 0;
226 TString bufferString(buffer);
228 // -- Checking for start of XML response
229 if ( bufferString.BeginsWith("<?xml") )
232 // -- Append the xml response
234 fXmlRpcResponse.Append(bufferString);
237 // -- Checking for end of XML response
238 if( ! bufferString.CompareTo("</methodResponse>") )
248 //##################################################################################
249 Int_t AliHLTHOMERProxyHandler::ProcessXmlRpcResponse() {
250 // see header file for class documentation
254 // -- Parse XML RPC Response
255 // ---------------------------
257 TDOMParser xmlParser;
258 xmlParser.SetValidate(kFALSE);
260 HLTInfo("XMLResponse:\n %s",fXmlRpcResponse.Data());
262 iResult = xmlParser.ParseBuffer(fXmlRpcResponse.Data(), fXmlRpcResponse.Length());
264 HLTError("Parsing buffer with error: %s",
265 xmlParser.GetParseCodeMessage(xmlParser.GetParseCode()) );
269 TXMLNode * node = xmlParser.GetXMLDocument()->GetRootNode()->
270 GetChildren()->GetChildren()->GetChildren()->GetChildren();
272 if ( strcmp( node->GetNodeName(), "string" ) ) {
273 HLTError("No node 'string' in XmlRpcResponse.");
278 // ------------------
281 TString xmlContent(node->GetText() );
283 HLTInfo("XMLContent:\n %s",xmlContent.Data());
285 iResult = xmlParser.ParseBuffer(xmlContent.Data(), xmlContent.Length());
287 HLTError("Parsing buffer with error: %s",
288 xmlParser.GetParseCodeMessage(xmlParser.GetParseCode()) );
293 if ( !xmlParser.GetXMLDocument()->GetRootNode()->HasChildren() ) {
294 HLTInfo("No Services active.");
298 // -- Loop over all service nodes
299 TXMLNode* serviceNode = xmlParser.GetXMLDocument()->GetRootNode()->GetChildren();
300 TXMLNode* prevServiceNode = NULL;
303 prevServiceNode = serviceNode;
305 // -- Add service to list
306 iResult = AddService( serviceNode->GetChildren() );
308 } while ( ( serviceNode = prevServiceNode->GetNextNode() ) && !iResult );
314 * ---------------------------------------------------------------------------------
315 * Source Resolving - private
316 * ---------------------------------------------------------------------------------
319 //##################################################################################
320 Int_t AliHLTHOMERProxyHandler::AddService(TXMLNode *innerNode) {
321 // see header file for class documentation
325 HLTInfo(">> New service");
327 // -- Loop over all service properties and
328 // read them from the service tag
329 // -----------------------------------------
331 TString hostname = "";
333 TString dataType = "";
334 TString dataOrigin = "";
335 TString dataSpecification = "";
337 TXMLNode* prevInnerNode = NULL;
340 prevInnerNode = innerNode;
342 if ( ! strcmp(innerNode->GetNodeName(), "text" ) )
345 HLTInfo(" %s ++ %s", innerNode->GetNodeName(), innerNode->GetText() );
348 if ( ! strcmp( innerNode->GetNodeName(), "address") )
349 hostname = innerNode->GetText();
350 else if ( ! strcmp( innerNode->GetNodeName(), "port") ) {
351 TString portS(innerNode->GetText());
352 if ( portS.IsDigit() )
355 HLTError("Port %s is not a digit.", portS.Data());
359 else if ( ! strcmp( innerNode->GetNodeName(), "dataorigin") )
360 dataOrigin = innerNode->GetText();
361 else if ( ! strcmp( innerNode->GetNodeName(), "datatype") )
362 dataType = innerNode->GetText();
363 else if ( ! strcmp( innerNode->GetNodeName(), "dataspecification") )
364 dataSpecification = innerNode->GetText();
366 } while ( ( innerNode = prevInnerNode->GetNextNode() ) && !iResult );
368 // -- Check the service properties
369 // ---------------------------------
371 // -- Change hostame from service with proxy, if outside HLT
372 if ( fRealm != kHLT || fRealm != kHLT+kHOMERRealmsMax )
373 hostname = fgkHOMERProxyNode[fRealm];
375 // -- Check for completeness of the source properties
376 if ( hostname.IsNull() || !port || dataOrigin.IsNull() ||
377 dataType.IsNull() /*|| dataSpecification.IsNull()*/ ) {
378 HLTError("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", hostname.Data(),
379 port, dataOrigin.Data(), dataType.Data(), dataSpecification.Data());
383 // -- Create new source
384 // ----------------------
386 AliHLTHOMERSourceDesc * source = new AliHLTHOMERSourceDesc();
387 source->SetService( hostname, port, dataType, dataOrigin, dataSpecification );
389 fSourceList->Add( source );
391 HLTInfo( "New Source added : %s", source->GetSourceName().Data());