Skip to content

Commit b83bc85

Browse files
DmitryLitvintsevmksahakyan
authored andcommitted
tape REST api: additional fix tohandling of prefixed paths
Motivation: ----------- Users reported 2 day pin lifetime on staged files (which is a default) despite specifying different values. This is due to failure to match target key on truncated vs prefixed path in target argument map keyed on un-prefixed paths. Modification: ------------- Use full target paths throughout the system. Make sure to strip prefix when exposing paths to users. Result: ------- Observe correct user specified pin lifetime. Ticket: #7687 Patch: https://rb.dcache.org/r/14339/ Target: trunk Request: 10.2, 10.1, 10.0, 9.2 Require-book: no Require-notes: yes Signed-off-by: Dmitry Litvintsev <[email protected]>
1 parent 96a1e89 commit b83bc85

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

modules/dcache-frontend/src/main/java/org/dcache/restful/resources/tape/ReleaseResources.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public Response release(
159159
JSONArray paths;
160160
List<String> targetPaths;
161161

162+
FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
163+
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);
164+
162165
try {
163166
JSONObject reqPayload = new JSONObject(requestPayload);
164167
paths = reqPayload.getJSONArray("paths");
@@ -170,16 +173,16 @@ public Response release(
170173
int len = paths.length();
171174
targetPaths = new ArrayList<>();
172175
for (int i = 0; i < len; ++i) {
173-
targetPaths.add(paths.getString(i));
176+
String requestPath = paths.getString(i);
177+
String path = rootPath.chroot(requestPath).toString();
178+
targetPaths.add(path);
174179
}
175180
} catch (JSONException e) {
176181
throw newBadRequestException(requestPayload, e);
177182
}
178183

179184
Subject subject = getSubject();
180185
Restriction restriction = getRestriction();
181-
FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
182-
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);
183186

184187
/*
185188
* For WLCG, this is a fire-and-forget request, so it does not need to

modules/dcache-frontend/src/main/java/org/dcache/restful/resources/tape/StageResources.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public StageRequestInfo getStageInfo(@ApiParam("The unique id of the request.")
167167
@PathParam("id") String id) {
168168
Subject subject = getSubject();
169169
Restriction restriction = getRestriction();
170+
FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
171+
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);
170172

171173
BulkRequestInfo lastInfo = null;
172174
List<BulkRequestTargetInfo> targetInfos = new ArrayList<>();
@@ -187,6 +189,7 @@ public StageRequestInfo getStageInfo(@ApiParam("The unique id of the request.")
187189
offset = lastInfo.getNextId();
188190
}
189191

192+
targetInfos.forEach(ti -> ti.setTarget(FsPath.create(ti.getTarget()).stripPrefix(rootPath)));
190193
lastInfo.setTargets(targetInfos);
191194

192195
return new StageRequestInfo(lastInfo);
@@ -218,7 +221,9 @@ public Response cancel(
218221
+ "does not belong to that stage request, this request will fail.", required = true)
219222
String requestPayload) {
220223

221-
JSONObject reqPayload;
224+
FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
225+
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);
226+
JSONObject reqPayload;
222227
JSONArray paths;
223228
try {
224229
reqPayload = new JSONObject(requestPayload);
@@ -233,7 +238,9 @@ public Response cancel(
233238
List<String> targetPaths = new ArrayList<>();
234239
int len = paths.length();
235240
for (int i = 0; i < len; ++i) {
236-
targetPaths.add(paths.getString(i));
241+
String requestPath = paths.getString(i);
242+
String path = rootPath.chroot(requestPath).toString();
243+
targetPaths.add(path);
237244
}
238245

239246
Subject subject = getSubject();
@@ -390,7 +397,8 @@ private BulkRequest toBulkRequest(String requestPayload, FsPath rootPath) {
390397
if (!file.has("path")) {
391398
throw new BadRequestException("file object " + i + " has no path.");
392399
}
393-
String path = file.getString("path");
400+
String requestPath = file.getString("path");
401+
String path = rootPath.chroot(requestPath).toString();
394402
paths.add(path);
395403
if (file.has("diskLifetime")) {
396404
jsonLifetimes.put(path,

0 commit comments

Comments
 (0)