Skip to content

Commit

Permalink
tape REST api: additional fix tohandling of prefixed paths
Browse files Browse the repository at this point in the history
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: dCache#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]>
  • Loading branch information
DmitryLitvintsev committed Nov 6, 2024
1 parent 499959a commit ff308e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public Response release(
JSONArray paths;
List<String> targetPaths;

FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);

try {
JSONObject reqPayload = new JSONObject(requestPayload);
paths = reqPayload.getJSONArray("paths");
Expand All @@ -170,16 +173,16 @@ public Response release(
int len = paths.length();
targetPaths = new ArrayList<>();
for (int i = 0; i < len; ++i) {
targetPaths.add(paths.getString(i));
String requestPath = paths.getString(i);
String path = rootPath.chroot(requestPath).toString();
targetPaths.add(path);
}
} catch (JSONException e) {
throw newBadRequestException(requestPayload, e);
}

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

/*
* For WLCG, this is a fire-and-forget request, so it does not need to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public StageRequestInfo getStageInfo(@ApiParam("The unique id of the request.")
@PathParam("id") String id) {
Subject subject = getSubject();
Restriction restriction = getRestriction();
FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);

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

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

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

JSONObject reqPayload;
FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);
JSONObject reqPayload;
JSONArray paths;
try {
reqPayload = new JSONObject(requestPayload);
Expand All @@ -233,7 +238,9 @@ public Response cancel(
List<String> targetPaths = new ArrayList<>();
int len = paths.length();
for (int i = 0; i < len; ++i) {
targetPaths.add(paths.getString(i));
String requestPath = paths.getString(i);
String path = rootPath.chroot(requestPath).toString();
targetPaths.add(path);
}

Subject subject = getSubject();
Expand Down Expand Up @@ -390,7 +397,8 @@ private BulkRequest toBulkRequest(String requestPayload, FsPath rootPath) {
if (!file.has("path")) {
throw new BadRequestException("file object " + i + " has no path.");
}
String path = file.getString("path");
String requestPath = file.getString("path");
String path = rootPath.chroot(requestPath).toString();
paths.add(path);
if (file.has("diskLifetime")) {
jsonLifetimes.put(path,
Expand Down

0 comments on commit ff308e5

Please sign in to comment.