forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TXProofMgr.cxx
1811 lines (1588 loc) · 55.3 KB
/
TXProofMgr.cxx
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
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/proofx:$Id$
// Author: Gerardo Ganis 12/12/2005
/*************************************************************************
* Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
/**
\defgroup proofx XProofD client Library
\ingroup proof
The XProofD client library, libProofx, contain the classes providing
the client to interact with the XRootD-based xproofd daemon.
*/
/** \class TXProofMgr
\ingroup proofx
Implementation of the functionality provided by TProofMgr in the case of a xproofd-based session.
*/
#include <errno.h>
#include <memory>
#ifdef WIN32
#include <io.h>
#endif
#include "Getline.h"
#include "TList.h"
#include "TObjArray.h"
#include "TObjString.h"
#include "TProof.h"
#include "TProofLog.h"
#include "TXProofMgr.h"
#include "TXSocket.h"
#include "TXSocketHandler.h"
#include "TROOT.h"
#include "TStopwatch.h"
#include "TSysEvtHandler.h"
#include "XProofProtocol.h"
#include "XrdProofConn.h"
ClassImp(TXProofMgr);
//
//----- ProofMgr Interrupt signal handler
//
class TProofMgrInterruptHandler : public TSignalHandler {
private:
TProofMgr *fMgr;
TProofMgrInterruptHandler(const TProofMgrInterruptHandler&); // Not implemented
TProofMgrInterruptHandler& operator=(const TProofMgrInterruptHandler&); // Not implemented
public:
TProofMgrInterruptHandler(TProofMgr *mgr)
: TSignalHandler(kSigInterrupt, kFALSE), fMgr(mgr) { }
Bool_t Notify();
};
////////////////////////////////////////////////////////////////////////////////
/// TProofMgr interrupt handler.
Bool_t TProofMgrInterruptHandler::Notify()
{
// Only on clients
if (isatty(0) != 0 && isatty(1) != 0) {
TString u = fMgr->GetUrl();
Printf("Opening new connection to %s", u.Data());
TXSocket *s = new TXSocket(u, 'C', kPROOF_Protocol,
kXPROOF_Protocol, 0, -1, (TXHandler *)fMgr);
if (s && s->IsValid()) {
// Set the interrupt flag on the server
s->CtrlC();
}
}
return kTRUE;
}
// Autoloading hooks.
// These are needed to avoid using the plugin manager which may create
// problems in multi-threaded environments.
TProofMgr *GetTXProofMgr(const char *url, Int_t l, const char *al)
{ return ((TProofMgr *) new TXProofMgr(url, l, al)); }
class TXProofMgrInit {
public:
TXProofMgrInit() {
TProofMgr::SetTXProofMgrHook(&GetTXProofMgr);
}};
static TXProofMgrInit gxproofmgr_init;
////////////////////////////////////////////////////////////////////////////////
/// Create a PROOF manager for the standard (old) environment.
TXProofMgr::TXProofMgr(const char *url, Int_t dbg, const char *alias)
: TProofMgr(url, dbg, alias)
{
// Set the correct servert type
fServType = kXProofd;
// Initialize
if (Init(dbg) != 0) {
// Failure: make sure the socket is deleted so that its lack of
// validity is correctly transmitted
SafeDelete(fSocket);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Do real initialization: open the connection and set the relevant
/// variables.
/// Login and authentication are dealt with at this level, if required.
/// Return 0 in case of success, 1 if the remote server is a 'proofd',
/// -1 in case of error.
Int_t TXProofMgr::Init(Int_t)
{
// Here we make sure that the port is explicitly specified in the URL,
// even when it matches the default value
TString u = fUrl.GetUrl(kTRUE);
fSocket = 0;
if (!(fSocket = new TXSocket(u, 'C', kPROOF_Protocol,
kXPROOF_Protocol, 0, -1, this)) ||
!(fSocket->IsValid())) {
if (!fSocket || !(fSocket->IsServProofd()))
if (gDebug > 0)
Error("Init", "while opening the connection to %s - exit (error: %d)",
u.Data(), (fSocket ? fSocket->GetOpenError() : -1));
if (fSocket && fSocket->IsServProofd())
fServType = TProofMgr::kProofd;
return -1;
}
// Protocol run by remote PROOF server
fRemoteProtocol = fSocket->GetRemoteProtocol();
// We add the manager itself for correct destruction
{ R__LOCKGUARD(gROOTMutex);
gROOT->GetListOfSockets()->Remove(fSocket);
}
// Set interrupt PROOF handler from now on
fIntHandler = new TProofMgrInterruptHandler(this);
// We are done
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor: close the connection
TXProofMgr::~TXProofMgr()
{
SetInvalid();
}
////////////////////////////////////////////////////////////////////////////////
/// Invalidate this manager by closing the connection
void TXProofMgr::SetInvalid()
{
if (fSocket)
fSocket->Close("P");
SafeDelete(fSocket);
// Avoid destroying twice
{ R__LOCKGUARD(gROOTMutex);
gROOT->GetListOfSockets()->Remove(this);
}
}
////////////////////////////////////////////////////////////////////////////////
/// Dummy version provided for completeness. Just returns a pointer to
/// existing session 'id' (as shown by TProof::QuerySessions) or 0 if 'id' is
/// not valid. The boolena 'gui' should be kTRUE when invoked from the GUI.
TProof *TXProofMgr::AttachSession(TProofDesc *d, Bool_t gui)
{
if (!IsValid()) {
Warning("AttachSession","invalid TXProofMgr - do nothing");
return 0;
}
if (!d) {
Warning("AttachSession","invalid description object - do nothing");
return 0;
}
if (d->GetProof())
// Nothing to do if already in contact with proofserv
return d->GetProof();
// Re-compose url
TString u(Form("%s/?%d", fUrl.GetUrl(kTRUE), d->GetRemoteId()));
// We need this to set correctly the kUsingSessionGui bit before the first
// feedback messages arrive
if (gui)
u += "GUI";
// Attach
TProof *p = new TProof(u, 0, 0, gDebug, 0, this);
if (p && p->IsValid()) {
// Set reference manager
p->SetManager(this);
// Save record about this session
Int_t st = (p->IsIdle()) ? TProofDesc::kIdle
: TProofDesc::kRunning;
d->SetStatus(st);
d->SetProof(p);
// Set session tag
p->SetName(d->GetName());
} else {
// Session creation failed
Error("AttachSession", "attaching to PROOF session");
}
return p;
}
////////////////////////////////////////////////////////////////////////////////
/// Detach session with 'id' from its proofserv. The 'id' is the number
/// shown by QuerySessions. The correspondent TProof object is deleted.
/// If id == 0 all the known sessions are detached.
/// Option opt="S" or "s" forces session shutdown.
void TXProofMgr::DetachSession(Int_t id, Option_t *opt)
{
if (!IsValid()) {
Warning("DetachSession","invalid TXProofMgr - do nothing");
return;
}
if (id > 0) {
// Single session request
TProofDesc *d = GetProofDesc(id);
if (d) {
if (fSocket)
fSocket->DisconnectSession(d->GetRemoteId(), opt);
TProof *p = d->GetProof();
fSessions->Remove(d);
SafeDelete(p);
delete d;
}
} else if (id == 0) {
// Requesto to destroy all sessions
if (fSocket) {
TString o = Form("%sA",opt);
fSocket->DisconnectSession(-1, o);
}
if (fSessions) {
// Delete PROOF sessions
TIter nxd(fSessions);
TProofDesc *d = 0;
while ((d = (TProofDesc *)nxd())) {
TProof *p = d->GetProof();
SafeDelete(p);
}
fSessions->Delete();
}
}
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Detach session 'p' from its proofserv. The instance 'p' is invalidated
/// and should be deleted by the caller
void TXProofMgr::DetachSession(TProof *p, Option_t *opt)
{
if (!IsValid()) {
Warning("DetachSession","invalid TXProofMgr - do nothing");
return;
}
if (p) {
// Single session request
TProofDesc *d = GetProofDesc(p);
if (d) {
if (fSocket)
fSocket->DisconnectSession(d->GetRemoteId(), opt);
fSessions->Remove(d);
p->Close(opt);
delete d;
}
}
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Checks if 'url' refers to the same 'user@host:port' entity as the URL
/// in memory. TProofMgr::MatchUrl cannot be used here because of the
/// 'double' default port, implying an additional check on the port effectively
/// open.
Bool_t TXProofMgr::MatchUrl(const char *url)
{
if (!IsValid()) {
Warning("MatchUrl","invalid TXProofMgr - do nothing");
return 0;
}
TUrl u(url);
// Correct URL protocol
if (!strcmp(u.GetProtocol(), TUrl("a").GetProtocol()))
u.SetProtocol("proof");
if (u.GetPort() == TUrl("a").GetPort()) {
// Set default port
Int_t port = gSystem->GetServiceByName("proofd");
if (port < 0)
port = 1093;
u.SetPort(port);
}
// Now we can check
if (!strcmp(u.GetHostFQDN(), fUrl.GetHost()))
if (u.GetPort() == fUrl.GetPort() ||
u.GetPort() == fSocket->GetPort())
if (strlen(u.GetUser()) <= 0 || !strcmp(u.GetUser(),fUrl.GetUser()))
return kTRUE;
// Match failed
return kFALSE;
}
////////////////////////////////////////////////////////////////////////////////
/// Show available workers
void TXProofMgr::ShowWorkers()
{
if (!IsValid()) {
Warning("ShowWorkers","invalid TXProofMgr - do nothing");
return;
}
// Send the request
TObjString *os = fSocket->SendCoordinator(kQueryWorkers);
if (os) {
TObjArray *oa = TString(os->GetName()).Tokenize(TString("&"));
if (oa) {
TIter nxos(oa);
TObjString *to = 0;
while ((to = (TObjString *) nxos()))
// Now parse them ...
Printf("+ %s", to->GetName());
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// Gets the URL to be prepended to paths when accessing the MSS associated
/// with the connected cluster, if any. The information is retrieved from
/// the cluster the first time or if retrieve is true.
const char *TXProofMgr::GetMssUrl(Bool_t retrieve)
{
if (fMssUrl.IsNull() || retrieve) {
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Error("GetMssUrl", "invalid TXProofMgr - do nothing");
return 0;
}
// Server may not support it
if (fSocket->GetXrdProofdVersion() < 1007) {
Error("GetMssUrl", "functionality not supported by server");
return 0;
}
TObjString *os = fSocket->SendCoordinator(kQueryMssUrl);
if (os) {
Printf("os: '%s'", os->GetName());
fMssUrl = os->GetName();
SafeDelete(os);
} else {
Error("GetMssUrl", "problems retrieving the required information");
return 0;
}
} else if (!IsValid()) {
Warning("GetMssUrl", "TXProofMgr is now invalid: information may not be valid");
return 0;
}
// Done
return fMssUrl.Data();
}
////////////////////////////////////////////////////////////////////////////////
/// Get list of sessions accessible to this manager
TList *TXProofMgr::QuerySessions(Option_t *opt)
{
if (opt && !strncasecmp(opt,"L",1))
// Just return the existing list
return fSessions;
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Warning("QuerySessions","invalid TXProofMgr - do nothing");
return 0;
}
// Create list if not existing
if (!fSessions) {
fSessions = new TList();
fSessions->SetOwner();
}
// Send the request
TList *ocl = new TList;
TObjString *os = fSocket->SendCoordinator(kQuerySessions);
if (os) {
TObjArray *oa = TString(os->GetName()).Tokenize(TString("|"));
if (oa) {
TProofDesc *d = 0;
TIter nxos(oa);
TObjString *to = (TObjString *) nxos();
if (to && to->GetString().IsDigit() && !strncasecmp(opt,"S",1))
Printf("// +++ %s session(s) currently active +++", to->GetName());
while ((to = (TObjString *) nxos())) {
// Now parse them ...
Int_t id = -1, st = -1;
TString al, tg, tk;
Ssiz_t from = 0;
while (to->GetString()[from] == ' ') { from++; }
if (!to->GetString().Tokenize(tk, from, " ") || !tk.IsDigit()) continue;
id = tk.Atoi();
if (!to->GetString().Tokenize(tg, from, " ")) continue;
if (!to->GetString().Tokenize(al, from, " ")) continue;
if (!to->GetString().Tokenize(tk, from, " ") || !tk.IsDigit()) continue;
st = tk.Atoi();
// Add to the list, if not already there
if (!(d = (TProofDesc *) fSessions->FindObject(tg))) {
Int_t locid = fSessions->GetSize() + 1;
d = new TProofDesc(tg, al, GetUrl(), locid, id, st, 0);
fSessions->Add(d);
} else {
// Set missing / update info
d->SetStatus(st);
d->SetRemoteId(id);
d->SetTitle(al);
}
// Add to the list for final garbage collection
ocl->Add(new TObjString(tg));
}
SafeDelete(oa);
}
SafeDelete(os);
}
// Printout and Garbage collection
if (fSessions->GetSize() > 0) {
TIter nxd(fSessions);
TProofDesc *d = 0;
while ((d = (TProofDesc *)nxd())) {
if (ocl->FindObject(d->GetName())) {
if (opt && !strncasecmp(opt,"S",1))
d->Print("");
} else {
fSessions->Remove(d);
SafeDelete(d);
}
}
}
// We are done
return fSessions;
}
////////////////////////////////////////////////////////////////////////////////
/// Handle asynchronous input on the socket
Bool_t TXProofMgr::HandleInput(const void *)
{
if (fSocket && fSocket->IsValid()) {
TMessage *mess;
if (fSocket->Recv(mess) >= 0) {
Int_t what = mess->What();
if (gDebug > 0)
Info("HandleInput", "%p: got message type: %d", this, what);
switch (what) {
case kPROOF_TOUCH:
fSocket->RemoteTouch();
break;
default:
Warning("HandleInput", "%p: got unknown message type: %d", this, what);
break;
}
}
} else {
Warning("HandleInput", "%p: got message but socket is invalid!", this);
}
// We are done
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Handle error on the input socket
Bool_t TXProofMgr::HandleError(const void *in)
{
XHandleErr_t *herr = in ? (XHandleErr_t *)in : 0;
// Try reconnection
if (fSocket && herr && (herr->fOpt == 1)) {
fSocket->Reconnect();
if (fSocket && fSocket->IsValid()) {
if (gDebug > 0)
Printf("ProofMgr: connection to coordinator at %s re-established",
fUrl.GetUrl());
return kFALSE;
}
}
Printf("TXProofMgr::HandleError: %p: got called ...", this);
// Interrupt any PROOF session in Collect
if (fSessions && fSessions->GetSize() > 0) {
TIter nxd(fSessions);
TProofDesc *d = 0;
while ((d = (TProofDesc *)nxd())) {
TProof *p = (TProof *) d->GetProof();
if (p)
p->InterruptCurrentMonitor();
}
}
if (gDebug > 0)
Printf("TXProofMgr::HandleError: %p: DONE ... ", this);
// We are done
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Send a cleanup request for the sessions associated with the current user.
/// If 'hard' is true sessions are signalled for termination and moved to
/// terminate at all stages (top master, sub-master, workers). Otherwise
/// (default) only top-master sessions are asked to terminate, triggering
/// a gentle session termination. In all cases all sessions should be gone
/// after a few (2 or 3) session checking cycles.
/// A user with superuser privileges can also asks cleaning for an different
/// user, specified by 'usr', or for all users (usr = *)
/// Return 0 on success, -1 in case of error.
Int_t TXProofMgr::Reset(Bool_t hard, const char *usr)
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Warning("Reset","invalid TXProofMgr - do nothing");
return -1;
}
Int_t h = (hard) ? 1 : 0;
fSocket->SendCoordinator(kCleanupSessions, usr, h);
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Get logs or log tails from last session associated with this manager
/// instance.
/// The arguments allow to specify a session different from the last one:
/// isess specifies a position relative to the last one, i.e. 1
/// for the next to last session; the absolute value is taken
/// so -1 and 1 are equivalent.
/// stag specifies the unique tag of the wanted session
/// The special value stag = "NR" allows to just initialize the TProofLog
/// object w/o retrieving the files; this may be useful when the number
/// of workers is large and only a subset of logs is required.
/// If 'stag' is specified 'isess' is ignored (unless stag = "NR").
/// If 'pattern' is specified only the lines containing it are retrieved
/// (remote grep functionality); to filter out a pattern 'pat' use
/// pattern = "-v pat".
/// If 'rescan' is TRUE, masters will rescan the worker sandboxes for the exact
/// paths, instead of using the save information; may be useful when the
/// ssave information looks wrong or incomplete.
/// Returns a TProofLog object (to be deleted by the caller) on success,
/// 0 if something wrong happened.
TProofLog *TXProofMgr::GetSessionLogs(Int_t isess, const char *stag,
const char *pattern, Bool_t rescan)
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Warning("GetSessionLogs","invalid TXProofMgr - do nothing");
return 0;
}
TProofLog *pl = 0;
// The absolute value of isess counts
isess = (isess > 0) ? -isess : isess;
// Special option in stag
bool retrieve = 1;
TString sesstag(stag);
if (sesstag == "NR") {
retrieve = 0;
sesstag = "";
}
// Get the list of paths
Int_t xrs = (rescan) ? 1 : 0;
TObjString *os = fSocket->SendCoordinator(kQueryLogPaths, sesstag.Data(), isess, -1, xrs);
// Analyse it now
Int_t ii = 0;
if (os) {
TString rs(os->GetName());
Ssiz_t from = 0;
// The session tag
TString tag;
if (!rs.Tokenize(tag, from, "|")) {
Warning("GetSessionLogs", "Session tag undefined: corruption?\n"
" (received string: %s)", os->GetName());
return (TProofLog *)0;
}
// The pool url
TString purl;
if (!rs.Tokenize(purl, from, "|")) {
Warning("GetSessionLogs", "Pool URL undefined: corruption?\n"
" (received string: %s)", os->GetName());
return (TProofLog *)0;
}
// Create the instance now
if (!pl)
pl = new TProofLog(tag, GetUrl(), this);
// Per-node info
TString to;
while (rs.Tokenize(to, from, "|")) {
if (!to.IsNull()) {
TString ord(to);
ord.Strip(TString::kLeading, ' ');
TString url(ord);
if ((ii = ord.Index(" ")) != kNPOS)
ord.Remove(ii);
if ((ii = url.Index(" ")) != kNPOS)
url.Remove(0, ii + 1);
// Add to the list (special tag for valgrind outputs)
if (url.Contains(".valgrind")) ord += "-valgrind";
pl->Add(ord, url);
// Notify
if (gDebug > 1)
Info("GetSessionLogs", "ord: %s, url: %s", ord.Data(), url.Data());
}
}
// Cleanup
SafeDelete(os);
// Retrieve the default part if required
if (pl && retrieve) {
const char *pat = pattern ? pattern : "-v \"| SvcMsg\"";
if (pat && strlen(pat) > 0)
pl->Retrieve("*", TProofLog::kGrep, 0, pat);
else
pl->Retrieve();
}
}
// Done
return pl;
}
////////////////////////////////////////////////////////////////////////////////
/// Read, via the coordinator, 'len' bytes from offset 'ofs' of 'file'.
/// Returns a TObjString with the content or 0, in case of failure
TObjString *TXProofMgr::ReadBuffer(const char *fin, Long64_t ofs, Int_t len)
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Warning("ReadBuffer","invalid TXProofMgr - do nothing");
return (TObjString *)0;
}
// Send the request
return fSocket->SendCoordinator(kReadBuffer, fin, len, ofs, 0);
}
////////////////////////////////////////////////////////////////////////////////
/// Read, via the coordinator, 'fin' filtered. If 'pattern' starts with '|',
/// it represents a command filtering the output. Elsewhere, it is a grep
/// pattern. Returns a TObjString with the content or 0 in case of failure
TObjString *TXProofMgr::ReadBuffer(const char *fin, const char *pattern)
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Warning("ReadBuffer", "invalid TXProofMgr - do nothing");
return (TObjString *)0;
}
const char *ptr;
Int_t type; // 1 = grep, 2 = grep -v, 3 = pipe through cmd
if (*pattern == '|') {
ptr = &pattern[1]; // strip first char if it is a command
type = 3;
}
else {
ptr = pattern;
type = 1;
}
// Prepare the buffer
Int_t plen = strlen(ptr);
Int_t lfi = strlen(fin);
char *buf = new char[lfi + plen + 1];
memcpy(buf, fin, lfi);
memcpy(buf+lfi, ptr, plen);
buf[lfi+plen] = 0;
// Send the request
return fSocket->SendCoordinator(kReadBuffer, buf, plen, 0, type);
}
////////////////////////////////////////////////////////////////////////////////
/// Display what ROOT versions are available on the cluster
void TXProofMgr::ShowROOTVersions()
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Warning("ShowROOTVersions","invalid TXProofMgr - do nothing");
return;
}
// Send the request
TObjString *os = fSocket->SendCoordinator(kQueryROOTVersions);
if (os) {
// Display it
Printf("----------------------------------------------------------\n");
Printf("Available versions (tag ROOT-vers remote-path PROOF-version):\n");
Printf("%s", os->GetName());
Printf("----------------------------------------------------------");
SafeDelete(os);
}
// We are done
return;
}
////////////////////////////////////////////////////////////////////////////////
/// Set the default ROOT version to be used
Int_t TXProofMgr::SetROOTVersion(const char *tag)
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Warning("SetROOTVersion","invalid TXProofMgr - do nothing");
return -1;
}
// Send the request
fSocket->SendCoordinator(kROOTVersion, tag);
// We are done
return (fSocket->GetOpenError() != kXR_noErrorYet) ? -1 : 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Send a message to connected users. Only superusers can do this.
/// The first argument specifies the message or the file from where to take
/// the message.
/// The second argument specifies the user to which to send the message: if
/// empty or null the message is send to all the connected users.
/// return 0 in case of success, -1 in case of error
Int_t TXProofMgr::SendMsgToUsers(const char *msg, const char *usr)
{
Int_t rc = 0;
// Check input
if (!msg || strlen(msg) <= 0) {
Error("SendMsgToUsers","no message to send - do nothing");
return -1;
}
// Buffer (max 32K)
const Int_t kMAXBUF = 32768;
char buf[kMAXBUF] = {0};
char *p = &buf[0];
size_t space = kMAXBUF - 1;
Int_t lusr = 0;
// A specific user?
if (usr && strlen(usr) > 0 && (strlen(usr) != 1 || usr[0] != '*')) {
lusr = (strlen(usr) + 3);
snprintf(buf, kMAXBUF, "u:%s ", usr);
p += lusr;
space -= lusr;
}
ssize_t len = 0;
// Is it from file ?
if (!gSystem->AccessPathName(msg, kFileExists)) {
// From file: can we read it ?
if (gSystem->AccessPathName(msg, kReadPermission)) {
Error("SendMsgToUsers","request to read message from unreadable file '%s'", msg);
return -1;
}
// Open the file
FILE *f = 0;
if (!(f = fopen(msg, "r"))) {
Error("SendMsgToUsers", "file '%s' cannot be open", msg);
return -1;
}
// Determine the number of bytes to be read from the file.
size_t left = 0;
off_t rcsk = lseek(fileno(f), (off_t) 0, SEEK_END);
if ((rcsk != (off_t)(-1))) {
left = (size_t) rcsk;
if ((lseek(fileno(f), (off_t) 0, SEEK_SET) == (off_t)(-1))) {
Error("SendMsgToUsers", "cannot rewind open file (seek to 0)");
fclose(f);
return -1;
}
} else {
Error("SendMsgToUsers", "cannot get size of open file (seek to END)");
fclose(f);
return -1;
}
// Now readout from file
size_t wanted = left;
if (wanted > space) {
wanted = space;
Warning("SendMsgToUsers",
"requested to send %lld bytes: max size is %lld bytes: truncating",
(Long64_t)left, (Long64_t)space);
}
do {
while ((len = read(fileno(f), p, wanted)) < 0 &&
TSystem::GetErrno() == EINTR)
TSystem::ResetErrno();
if (len < 0) {
SysError("SendMsgToUsers", "error reading file");
break;
}
// Update counters
left = (len >= (ssize_t)left) ? 0 : left - len;
p += len;
wanted = (left > kMAXBUF-1) ? kMAXBUF-1 : left;
} while (len > 0 && left > 0);
// Close file
fclose(f);
} else {
// Add the message to the buffer
len = strlen(msg);
if (len > (ssize_t)space) {
Warning("SendMsgToUsers",
"requested to send %lld bytes: max size is %lld bytes: truncating",
(Long64_t)len, (Long64_t)space);
len = space;
}
memcpy(p, msg, len);
}
// Null-terminate
buf[len + lusr] = 0;
// Send the request
fSocket->SendCoordinator(kSendMsgToUser, buf);
return rc;
}
////////////////////////////////////////////////////////////////////////////////
/// Run 'grep' on the nodes
void TXProofMgr::Grep(const char *what, const char *how, const char *where)
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Error("Grep","invalid TXProofMgr - do nothing");
return;
}
// Server may not support it
if (fSocket->GetXrdProofdVersion() < 1006) {
Error("Grep", "functionality not supported by server");
return;
}
// Send the request
TObjString *os = Exec(kGrep, what, how, where);
// Show the result, if any
if (os) Printf("%s", os->GetName());
// Cleanup
SafeDelete(os);
}
////////////////////////////////////////////////////////////////////////////////
/// Run 'find' on the nodes
void TXProofMgr::Find(const char *what, const char *how, const char *where)
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Error("Find","invalid TXProofMgr - do nothing");
return;
}
// Server may not support it
if (fSocket->GetXrdProofdVersion() < 1006) {
Error("Find", "functionality not supported by server (XrdProofd version: %d)",
fSocket->GetXrdProofdVersion());
return;
}
// Send the request
TObjString *os = Exec(kFind, what, how, where);
// Show the result, if any
if (os) Printf("%s", os->GetName());
// Cleanup
SafeDelete(os);
}
////////////////////////////////////////////////////////////////////////////////
/// Run 'ls' on the nodes
void TXProofMgr::Ls(const char *what, const char *how, const char *where)
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Error("Ls","invalid TXProofMgr - do nothing");
return;
}
// Server may not support it
if (fSocket->GetXrdProofdVersion() < 1006) {
Error("Ls", "functionality not supported by server");
return;
}
// Send the request
TObjString *os = Exec(kLs, what, how, where);
// Show the result, if any
if (os) Printf("%s", os->GetName());
// Cleanup
SafeDelete(os);
}
////////////////////////////////////////////////////////////////////////////////
/// Run 'more' on the nodes
void TXProofMgr::More(const char *what, const char *how, const char *where)
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Error("More","invalid TXProofMgr - do nothing");
return;
}
// Server may not support it
if (fSocket->GetXrdProofdVersion() < 1006) {
Error("More", "functionality not supported by server");
return;
}
// Send the request
TObjString *os = Exec(kMore, what, how, where);
// Show the result, if any
if (os) Printf("%s", os->GetName());
// Cleanup
SafeDelete(os);
}
////////////////////////////////////////////////////////////////////////////////
/// Run 'rm' on the nodes. The user is prompted before removal, unless 'how'
/// contains "--force" or a combination of single letter options including 'f',
/// e.g. "-fv".
Int_t TXProofMgr::Rm(const char *what, const char *how, const char *where)
{
// Nothing to do if not in contact with proofserv
if (!IsValid()) {
Error("Rm","invalid TXProofMgr - do nothing");
return -1;
}
// Server may not support it
if (fSocket->GetXrdProofdVersion() < 1006) {
Error("Rm", "functionality not supported by server");
return -1;