-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdClXRootDResponses.hh
877 lines (772 loc) · 32.4 KB
/
XrdClXRootDResponses.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
//------------------------------------------------------------------------------
// Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
// Author: Lukasz Janyst <ljanyst@cern.ch>
//------------------------------------------------------------------------------
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------
#ifndef __XRD_CL_XROOTD_RESPONSES_HH__
#define __XRD_CL_XROOTD_RESPONSES_HH__
#include "XrdCl/XrdClBuffer.hh"
#include "XrdCl/XrdClStatus.hh"
#include "XrdCl/XrdClURL.hh"
#include "XrdCl/XrdClAnyObject.hh"
#include "XProtocol/XProtocol.hh"
#include <string>
#include <vector>
#include <list>
#include <ctime>
namespace XrdCl
{
//----------------------------------------------------------------------------
//! Path location info
//----------------------------------------------------------------------------
class LocationInfo
{
public:
//------------------------------------------------------------------------
//! Describes the node type and file status for a given location
//------------------------------------------------------------------------
enum LocationType
{
ManagerOnline, //!< manager node where the file is online
ManagerPending, //!< manager node where the file is pending to be online
ServerOnline, //!< server node where the file is online
ServerPending //!< server node where the file is pending to be online
};
//------------------------------------------------------------------------
//! Describes the allowed access type for the file at given location
//------------------------------------------------------------------------
enum AccessType
{
Read, //!< read access is allowed
ReadWrite //!< write access is allowed
};
//------------------------------------------------------------------------
//! Location
//------------------------------------------------------------------------
class Location
{
public:
//--------------------------------------------------------------------
//! Constructor
//--------------------------------------------------------------------
Location( const std::string &address,
LocationType type,
AccessType access ):
pAddress( address ),
pType( type ),
pAccess( access ) {}
//--------------------------------------------------------------------
//! Get address
//--------------------------------------------------------------------
const std::string &GetAddress() const
{
return pAddress;
}
//--------------------------------------------------------------------
//! Get location type
//--------------------------------------------------------------------
LocationType GetType() const
{
return pType;
}
//--------------------------------------------------------------------
//! Get access type
//--------------------------------------------------------------------
AccessType GetAccessType() const
{
return pAccess;
}
//--------------------------------------------------------------------
//! Check whether the location is a server
//--------------------------------------------------------------------
bool IsServer() const
{
return pType == ServerOnline || pType == ServerPending;
}
//--------------------------------------------------------------------
//! Check whether the location is a manager
//--------------------------------------------------------------------
bool IsManager() const
{
return pType == ManagerOnline || pType == ManagerPending;
}
private:
std::string pAddress;
LocationType pType;
AccessType pAccess;
};
//------------------------------------------------------------------------
//! List of locations
//------------------------------------------------------------------------
typedef std::vector<Location> LocationList;
//------------------------------------------------------------------------
//! Iterator over locations
//------------------------------------------------------------------------
typedef LocationList::iterator Iterator;
//------------------------------------------------------------------------
//! Iterator over locations
//------------------------------------------------------------------------
typedef LocationList::const_iterator ConstIterator;
//------------------------------------------------------------------------
//! Constructor
//------------------------------------------------------------------------
LocationInfo();
//------------------------------------------------------------------------
//! Get number of locations
//------------------------------------------------------------------------
uint32_t GetSize() const
{
return pLocations.size();
}
//------------------------------------------------------------------------
//! Get the location at index
//------------------------------------------------------------------------
Location &At( uint32_t index )
{
return pLocations[index];
}
//------------------------------------------------------------------------
//! Get the location begin iterator
//------------------------------------------------------------------------
Iterator Begin()
{
return pLocations.begin();
}
//------------------------------------------------------------------------
//! Get the location begin iterator
//------------------------------------------------------------------------
ConstIterator Begin() const
{
return pLocations.begin();
}
//------------------------------------------------------------------------
//! Get the location end iterator
//------------------------------------------------------------------------
Iterator End()
{
return pLocations.end();
}
//------------------------------------------------------------------------
//! Get the location end iterator
//------------------------------------------------------------------------
ConstIterator End() const
{
return pLocations.end();
}
//------------------------------------------------------------------------
//! Add a location
//------------------------------------------------------------------------
void Add( const Location &location )
{
pLocations.push_back( location );
}
//------------------------------------------------------------------------
//! Parse server response and fill up the object
//------------------------------------------------------------------------
bool ParseServerResponse( const char *data );
private:
bool ProcessLocation( std::string &location );
LocationList pLocations;
};
//----------------------------------------------------------------------------
//! Request status
//----------------------------------------------------------------------------
class XRootDStatus: public Status
{
public:
//------------------------------------------------------------------------
//! Constructor
//------------------------------------------------------------------------
XRootDStatus( uint16_t st = 0,
uint16_t code = 0,
uint32_t errN = 0,
const std::string &message = "" ):
Status( st, code, errN ),
pMessage( message ) {}
//------------------------------------------------------------------------
//! Constructor
//------------------------------------------------------------------------
XRootDStatus( const Status &st,
const std::string &message = "" ):
Status( st ),
pMessage( message ) {}
//------------------------------------------------------------------------
//! Get error message
//------------------------------------------------------------------------
const std::string &GetErrorMessage() const
{
return pMessage;
}
//------------------------------------------------------------------------
//! Set the error message
//------------------------------------------------------------------------
void SetErrorMessage( const std::string &message )
{
pMessage = message;
}
//------------------------------------------------------------------------
//! Convert to string
//------------------------------------------------------------------------
std::string ToStr() const
{
if( code == errErrorResponse )
{
std::ostringstream o;
o << "[ERROR] Server responded with an error: [" << errNo << "] ";
o << pMessage << std::endl;
return o.str();
}
std::string str = ToString();
if( !pMessage.empty() )
str += ": " + pMessage;
return str;
}
private:
std::string pMessage;
};
//----------------------------------------------------------------------------
//! Binary buffer
//----------------------------------------------------------------------------
typedef Buffer BinaryDataInfo;
//----------------------------------------------------------------------------
//! Protocol response
//----------------------------------------------------------------------------
class ProtocolInfo
{
public:
//------------------------------------------------------------------------
//! Types of XRootD servers
//------------------------------------------------------------------------
enum HostTypes
{
IsManager = kXR_isManager, //!< Manager
IsServer = kXR_isServer, //!< Data server
AttrMeta = kXR_attrMeta, //!< Meta attribute
AttrProxy = kXR_attrProxy, //!< Proxy attribute
AttrSuper = kXR_attrSuper //!< Supervisor attribute
};
//------------------------------------------------------------------------
//! Constructor
//------------------------------------------------------------------------
ProtocolInfo( uint32_t version, uint32_t hostInfo ):
pVersion( version ), pHostInfo( hostInfo ) {}
//------------------------------------------------------------------------
//! Get version info
//------------------------------------------------------------------------
uint32_t GetVersion() const
{
return pVersion;
}
//------------------------------------------------------------------------
//! Get host info
//------------------------------------------------------------------------
uint32_t GetHostInfo() const
{
return pHostInfo;
}
//------------------------------------------------------------------------
//! Test host info flags
//------------------------------------------------------------------------
bool TestHostInfo( uint32_t flags )
{
return pHostInfo & flags;
}
private:
uint32_t pVersion;
uint32_t pHostInfo;
};
//----------------------------------------------------------------------------
//! Object stat info
//----------------------------------------------------------------------------
class StatInfo
{
public:
//------------------------------------------------------------------------
//! Flags
//------------------------------------------------------------------------
enum Flags
{
XBitSet = kXR_xset, //!< Executable/searchable bit set
IsDir = kXR_isDir, //!< This is a directory
Other = kXR_other, //!< Neither a file nor a directory
Offline = kXR_offline, //!< File is not online (ie. on disk)
POSCPending = kXR_poscpend, //!< File opened with POST flag, not yet
//!< successfully closed
IsReadable = kXR_readable, //!< Read access is allowed
IsWritable = kXR_writable, //!< Write access is allowed
BackUpExists = kXR_bkpexist //!< Back up copy exists
};
//------------------------------------------------------------------------
//! Constructor
//------------------------------------------------------------------------
StatInfo();
//------------------------------------------------------------------------
//! Constructor
//------------------------------------------------------------------------
StatInfo( const std::string &id, uint64_t size, uint32_t flags,
uint64_t modTime);
//------------------------------------------------------------------------
//! Get id
//------------------------------------------------------------------------
const std::string GetId() const
{
return pId;
}
//------------------------------------------------------------------------
//! Get size (in bytes)
//------------------------------------------------------------------------
uint64_t GetSize() const
{
return pSize;
}
//------------------------------------------------------------------------
//! Get flags
//------------------------------------------------------------------------
uint32_t GetFlags() const
{
return pFlags;
}
//------------------------------------------------------------------------
//! Test flags
//------------------------------------------------------------------------
bool TestFlags( uint32_t flags ) const
{
return pFlags & flags;
}
//------------------------------------------------------------------------
//! Get modification time (in seconds since epoch)
//------------------------------------------------------------------------
uint64_t GetModTime() const
{
return pModTime;
}
//------------------------------------------------------------------------
//! Get modification time
//------------------------------------------------------------------------
std::string GetModTimeAsString() const
{
char ts[256];
time_t modTime = pModTime;
tm *t = gmtime( &modTime );
strftime( ts, 255, "%F %T", t );
return ts;
}
//------------------------------------------------------------------------
//! Parse server response and fill up the object
//------------------------------------------------------------------------
bool ParseServerResponse( const char *data );
private:
//------------------------------------------------------------------------
// Normal stat
//------------------------------------------------------------------------
std::string pId;
uint64_t pSize;
uint32_t pFlags;
uint64_t pModTime;
};
//----------------------------------------------------------------------------
//! VFS stat info
//----------------------------------------------------------------------------
class StatInfoVFS
{
public:
//------------------------------------------------------------------------
//! Constructor
//------------------------------------------------------------------------
StatInfoVFS();
//------------------------------------------------------------------------
//! Get number of nodes that can provide read/write space
//------------------------------------------------------------------------
uint64_t GetNodesRW() const
{
return pNodesRW;
}
//------------------------------------------------------------------------
//! Get size of the largest contiguous area of free r/w space (in MB)
//------------------------------------------------------------------------
uint64_t GetFreeRW() const
{
return pFreeRW;
}
//------------------------------------------------------------------------
//! Get percentage of the partition utilization represented by FreeRW
//------------------------------------------------------------------------
uint8_t GetUtilizationRW() const
{
return pUtilizationRW;
}
//------------------------------------------------------------------------
//! Get number of nodes that can provide staging space
//------------------------------------------------------------------------
uint64_t GetNodesStaging() const
{
return pNodesStaging;
}
//------------------------------------------------------------------------
//! Get size of the largest contiguous area of free staging space (in MB)
//------------------------------------------------------------------------
uint64_t GetFreeStaging() const
{
return pFreeStaging;
}
//------------------------------------------------------------------------
//! Get percentage of the partition utilization represented by FreeStaging
//------------------------------------------------------------------------
uint8_t GetUtilizationStaging() const
{
return pUtilizationStaging;
}
//------------------------------------------------------------------------
//! Parse server response and fill up the object
//------------------------------------------------------------------------
bool ParseServerResponse( const char *data );
private:
//------------------------------------------------------------------------
// kXR_vfs stat
//------------------------------------------------------------------------
uint64_t pNodesRW;
uint64_t pFreeRW;
uint32_t pUtilizationRW;
uint64_t pNodesStaging;
uint64_t pFreeStaging;
uint32_t pUtilizationStaging;
};
//----------------------------------------------------------------------------
//! Directory list
//----------------------------------------------------------------------------
class DirectoryList
{
public:
//------------------------------------------------------------------------
//! Directory entry
//------------------------------------------------------------------------
class ListEntry
{
public:
//--------------------------------------------------------------------
//! Constructor
//--------------------------------------------------------------------
ListEntry( const std::string &hostAddress,
const std::string &name,
StatInfo *statInfo = 0):
pHostAddress( hostAddress ),
pName( name ),
pStatInfo( statInfo )
{}
//--------------------------------------------------------------------
//! Destructor
//--------------------------------------------------------------------
~ListEntry()
{
delete pStatInfo;
}
//--------------------------------------------------------------------
//! Get host address
//--------------------------------------------------------------------
const std::string &GetHostAddress() const
{
return pHostAddress;
}
//--------------------------------------------------------------------
//! Get file name
//--------------------------------------------------------------------
const std::string &GetName() const
{
return pName;
}
//--------------------------------------------------------------------
//! Get the stat info object
//--------------------------------------------------------------------
StatInfo *GetStatInfo()
{
return pStatInfo;
}
//--------------------------------------------------------------------
//! Get the stat info object
//--------------------------------------------------------------------
const StatInfo *GetStatInfo() const
{
return pStatInfo;
}
//--------------------------------------------------------------------
//! Set the stat info object (and transfer the ownership)
//--------------------------------------------------------------------
void SetStatInfo( StatInfo *info )
{
pStatInfo = info;
}
private:
std::string pHostAddress;
std::string pName;
StatInfo *pStatInfo;
};
//------------------------------------------------------------------------
//! Constructor
//------------------------------------------------------------------------
DirectoryList();
//------------------------------------------------------------------------
//! Destructor
//------------------------------------------------------------------------
~DirectoryList();
//------------------------------------------------------------------------
//! Directory listing
//------------------------------------------------------------------------
typedef std::vector<ListEntry*> DirList;
//------------------------------------------------------------------------
//! Directory listing iterator
//------------------------------------------------------------------------
typedef DirList::iterator Iterator;
//------------------------------------------------------------------------
//! Directory listing const iterator
//------------------------------------------------------------------------
typedef DirList::const_iterator ConstIterator;
//------------------------------------------------------------------------
//! Add an entry to the list - takes ownership
//------------------------------------------------------------------------
void Add( ListEntry *entry )
{
pDirList.push_back( entry );
}
//------------------------------------------------------------------------
//! Get an entry at given index
//------------------------------------------------------------------------
ListEntry *At( uint32_t index )
{
return pDirList[index];
}
//------------------------------------------------------------------------
//! Get the begin iterator
//------------------------------------------------------------------------
Iterator Begin()
{
return pDirList.begin();
}
//------------------------------------------------------------------------
//! Get the begin iterator
//------------------------------------------------------------------------
ConstIterator Begin() const
{
return pDirList.begin();
}
//------------------------------------------------------------------------
//! Get the end iterator
//------------------------------------------------------------------------
Iterator End()
{
return pDirList.end();
}
//------------------------------------------------------------------------
//! Get the end iterator
//------------------------------------------------------------------------
ConstIterator End() const
{
return pDirList.end();
}
//------------------------------------------------------------------------
//! Get the size of the listing
//------------------------------------------------------------------------
uint32_t GetSize() const
{
return pDirList.size();
}
//------------------------------------------------------------------------
//! Get parent directory name
//------------------------------------------------------------------------
const std::string &GetParentName() const
{
return pParent;
}
//------------------------------------------------------------------------
//! Set name of the parent directory
//------------------------------------------------------------------------
void SetParentName( const std::string &parent )
{
size_t pos = parent.find( '?' );
pParent = pos == std::string::npos ? parent : parent.substr( 0, pos );
if( !pParent.empty() && pParent[pParent.length()-1] != '/' )
pParent += "/";
}
//------------------------------------------------------------------------
//! Parse server response and fill up the object
//------------------------------------------------------------------------
bool ParseServerResponse( const std::string &hostId,
const char *data );
private:
DirList pDirList;
std::string pParent;
};
//----------------------------------------------------------------------------
//! Information returned by file open operation
//----------------------------------------------------------------------------
class OpenInfo
{
public:
//------------------------------------------------------------------------
//! Constructor
//------------------------------------------------------------------------
OpenInfo( const uint8_t *fileHandle,
uint64_t sessionId,
StatInfo *statInfo = 0 ):
pSessionId(sessionId), pStatInfo( statInfo )
{
memcpy( pFileHandle, fileHandle, 4 );
}
//------------------------------------------------------------------------
//! Destructor
//------------------------------------------------------------------------
~OpenInfo()
{
delete pStatInfo;
}
//------------------------------------------------------------------------
//! Get the file handle (4bytes)
//------------------------------------------------------------------------
void GetFileHandle( uint8_t *fileHandle ) const
{
memcpy( fileHandle, pFileHandle, 4 );
}
//------------------------------------------------------------------------
//! Get the stat info
//------------------------------------------------------------------------
const StatInfo *GetStatInfo() const
{
return pStatInfo;
}
//------------------------------------------------------------------------
// Get session ID
//------------------------------------------------------------------------
uint64_t GetSessionId() const
{
return pSessionId;
}
private:
uint8_t pFileHandle[4];
uint64_t pSessionId;
StatInfo *pStatInfo;
};
//----------------------------------------------------------------------------
//! Describe a data chunk for vector read
//----------------------------------------------------------------------------
struct ChunkInfo
{
//--------------------------------------------------------------------------
//! Constructor
//--------------------------------------------------------------------------
ChunkInfo( uint64_t off = 0, uint32_t len = 0, void *buff = 0 ):
offset( off ), length( len ), buffer(buff) {}
uint64_t offset; //! offset in the file
uint32_t length; //! length of the chunk
void *buffer; //! optional buffer pointer
};
//----------------------------------------------------------------------------
//! List of chunks
//----------------------------------------------------------------------------
typedef std::vector<ChunkInfo> ChunkList;
//----------------------------------------------------------------------------
//! Vector read info
//----------------------------------------------------------------------------
class VectorReadInfo
{
public:
//------------------------------------------------------------------------
//! Constructor
//------------------------------------------------------------------------
VectorReadInfo(): pSize( 0 ) {}
//------------------------------------------------------------------------
//! Get Size
//------------------------------------------------------------------------
uint32_t GetSize() const
{
return pSize;
}
//------------------------------------------------------------------------
//! Set size
//------------------------------------------------------------------------
void SetSize( uint32_t size )
{
pSize = size;
}
//------------------------------------------------------------------------
//! Get chunks
//------------------------------------------------------------------------
ChunkList &GetChunks()
{
return pChunks;
}
//------------------------------------------------------------------------
//! Get chunks
//------------------------------------------------------------------------
const ChunkList &GetChunks() const
{
return pChunks;
}
private:
ChunkList pChunks;
uint32_t pSize;
};
//----------------------------------------------------------------------------
// List of URLs
//----------------------------------------------------------------------------
struct HostInfo
{
HostInfo():
flags(0), protocol(0), loadBalancer(false) {}
HostInfo( const URL &u, bool lb = false ):
flags(0), protocol(0), loadBalancer(lb), url(u) {}
uint32_t flags; //!< Host type
uint32_t protocol; //!< Version of the protocol the host is speaking
bool loadBalancer; //!< Was the host used as a load balancer
URL url; //!< URL of the host
};
typedef std::vector<HostInfo> HostList;
//----------------------------------------------------------------------------
//! Handle an async response
//----------------------------------------------------------------------------
class ResponseHandler
{
public:
virtual ~ResponseHandler() {}
//------------------------------------------------------------------------
//! Called when a response to associated request arrives or an error
//! occurs
//!
//! @param status status of the request
//! @param response an object associated with the response
//! (request dependent)
//! @param hostList list of hosts the request was redirected to
//------------------------------------------------------------------------
virtual void HandleResponseWithHosts( XRootDStatus *status,
AnyObject *response,
HostList *hostList )
{
delete hostList;
HandleResponse( status, response );
}
//------------------------------------------------------------------------
//! Called when a response to associated request arrives or an error
//! occurs
//!
//! @param status status of the request
//! @param response an object associated with the response
//! (request dependent)
//------------------------------------------------------------------------
virtual void HandleResponse( XRootDStatus *status,
AnyObject *response )
{
(void)status; (void)response;
}
};
}
#endif // __XRD_CL_XROOTD_RESPONSES_HH__