-
Notifications
You must be signed in to change notification settings - Fork 4
/
XrdOucName2NameDCP4RUCIO.cc
188 lines (160 loc) · 5.59 KB
/
XrdOucName2NameDCP4RUCIO.cc
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
/*
* Author: Wei Yang (SLAC National Accelerator Laboratory / Stanford University, 2017)
*/
using namespace std;
#include <stdio.h>
#include <string>
#include <errno.h>
#include <openssl/md5.h>
#include "XrdVersion.hh"
XrdVERSIONINFO(XrdOucgetName2Name, "N2N-Xcache4RUCIO");
#include "rucioGetMetaLink.hh"
#include "pfn2cache.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucName2Name.hh"
#include "XrdSys/XrdSysPlatform.hh"
#include "XrdSys/XrdSysError.hh"
class XrdOucName2NameDiskCacheProxy4Rucio : public XrdOucName2Name
{
public:
virtual int lfn2pfn(const char* lfn, char* buff, int blen);
virtual int lfn2rfn(const char* lfn, char* buff, int blen);
virtual int pfn2lfn(const char* lfn, char* buff, int blen);
XrdOucName2NameDiskCacheProxy4Rucio(XrdSysError *erp, const char* confg, const char* parms);
virtual ~XrdOucName2NameDiskCacheProxy4Rucio() {};
friend XrdOucName2Name *XrdOucgetName2Name(XrdOucgetName2NameArgs);
private:
string myName, localMetaLinkRootDir, gLFNprefix, rucioServer;
XrdSysError *eDest;
bool isCmsd;
};
XrdOucName2NameDiskCacheProxy4Rucio::XrdOucName2NameDiskCacheProxy4Rucio(XrdSysError* erp,
const char* confg,
const char* parms)
{
std::string myProg;
std::string opts, message, key, value;
std::string::iterator it;
std::size_t i;
int x;
myName = "Xcache4RUCIO";
eDest = erp;
localMetaLinkRootDir = "";
gLFNprefix = "/atlas/rucio";
rucioServer = "rucio-lb-prod.cern.ch";
isCmsd = false;
if (getenv("XRDPROG"))
{
myProg = getenv("XRDPROG");
if (myProg == "cmsd") isCmsd = true;
}
setenv("XRD_METALINKPROCESSING", "1", 0);
setenv("XRD_LOCALMETALINKFILE", "1", 0);
x = 0;
key = "";
value = "";
opts = parms;
opts += " ";
for (it=opts.begin(); it!=opts.end(); ++it)
{
if (*it == '=') x = 1;
else if (*it == ' ')
{
if (key == "metalinkdir")
localMetaLinkRootDir = value;
else if (key == "glfnprefix")
gLFNprefix = value;
else if (key == "rucioserver")
rucioServer = value;
key = "";
value = "";
x = 0;
}
else
{
if (x == 0) key += *it;
if (x == 1) value += *it;
}
}
// defaults
if (localMetaLinkRootDir == "") localMetaLinkRootDir = "/dev/shm" + gLFNprefix;
message = myName + " Init: glfnprefix = " + gLFNprefix;
eDest->Say(message.c_str());
message = myName + " Init: metalinkdir = " + localMetaLinkRootDir;
eDest->Say(message.c_str());
message = myName + " Init: RUCIO metalink server = " + rucioServer;
eDest->Say(message.c_str());
rucioGetMetaLinkInit(localMetaLinkRootDir, gLFNprefix, rucioServer);
}
int XrdOucName2NameDiskCacheProxy4Rucio::lfn2pfn(const char* lfn, char* buff, int blen)
{
std::string myLfn, myPfn, rucioDID;
std::string scope, slashScope, file;
std::size_t i;
// MD5_CTX c;
// unsigned char md5digest[MD5_DIGEST_LENGTH];
// char md5string[MD5_DIGEST_LENGTH*2+1];
if (isCmsd) // cmsd shouldn't do lfn2pfn()
{
blen = strlen(lfn);
strncpy(buff, lfn, blen);
return 0;
}
myPfn = "";
myLfn = lfn;
// see comments in pfn2cache()
// Do not allow users to specify file:// or root://localfile
if (myLfn.find("/root:/localfile") == 0 || myLfn.find("/file:/") == 0)
{
myPfn = "ENOENT";
return EFAULT;
}
if (myLfn.find("/root:/") == 0 || myLfn.find("/http:/") == 0 || myLfn.find("/https:/") == 0)
myPfn = makeMetaLink(eDest, myName, lfn); // Assume the client know the data source...
else if ((i = myLfn.rfind(gLFNprefix)) != 0)
{
// client want so access a local file that is permitted by the xcache configuration
myLfn = "/file:/localhost" + myLfn;
myPfn = makeMetaLink(eDest, myName, myLfn.c_str());
}
else // gLFN
{
// with a leading "/"
rucioDID = myLfn.substr(i + gLFNprefix.length(), myLfn.length() -i - gLFNprefix.length());
if (rucioDID.rfind("/") < rucioDID.rfind(":") && rucioDID.rfind(":") != string::npos)
// check if this is /atlas/rucio/scope:file format
myPfn = getMetaLink(eDest, myName, rucioDID);
else
{
// otherwise, assume this is /atlas/rucio/scope/xx/xx/file format
rucioDID = rucioDID.replace(rucioDID.rfind("/") -6, 7, ":");
myPfn = getMetaLink(eDest, myName, rucioDID);
}
}
if (myPfn == "EFAULT")
return EFAULT;
else if (myPfn == "ENOENT")
return ENOENT;
blen = myPfn.length();
strncpy(buff, myPfn.c_str(), blen);
buff[blen] = 0;
return 0;
}
int XrdOucName2NameDiskCacheProxy4Rucio::lfn2rfn(const char* lfn, char* buff, int blen) { return -EOPNOTSUPP; }
int XrdOucName2NameDiskCacheProxy4Rucio::pfn2lfn(const char* pfn, char* buff, int blen)
{
std::string cachePath;
cachePath = pfn2cache(localMetaLinkRootDir, gLFNprefix, pfn);
blen = cachePath.length();
strncpy(buff, cachePath.c_str(), blen);
buff[blen] = '\0';
return 0;
}
XrdOucName2Name *XrdOucgetName2Name(XrdOucgetName2NameArgs)
{
static XrdOucName2NameDiskCacheProxy4Rucio *inst = NULL;
if (inst) return (XrdOucName2Name *)inst;
inst = new XrdOucName2NameDiskCacheProxy4Rucio(eDest, confg, parms);
if (!inst) return NULL;
return (XrdOucName2Name *)inst;
}