Skip to content

Commit

Permalink
tape api: fix handling 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: #7687
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 4, 2024
1 parent e98ab94 commit 6a6836b
Show file tree
Hide file tree
Showing 2 changed files with 21 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 @@ -115,6 +115,8 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Component;

Expand All @@ -127,6 +129,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
@Api(value = "tape", authorizations = {@Authorization("basicAuth")})
@Path("tape/stage")
public final class StageResources {
private static final Logger LOGGER = LoggerFactory.getLogger(StageResources.class);
private static final String STAGE = "STAGE";

@Context
Expand Down Expand Up @@ -167,6 +170,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 +192,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 +224,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 +241,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,11 +400,13 @@ 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,
TimeUtils.validateDuration(file.getString("diskLifetime")));
LOGGER.error("Path {}, diskLifetime {}, {}", path, file.getString("diskLifetime"), TimeUtils.validateDuration(file.getString("diskLifetime")));
}
if (file.has("targetedMetadata")) {
getTargetedMetadataForPath(file).ifPresent(mdata ->
Expand Down

0 comments on commit 6a6836b

Please sign in to comment.