Skip to content

Commit

Permalink
Added calculation of absolute path to BulkRequestContainerJob
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Litvintsev <[email protected]>
  • Loading branch information
DmitryLitvintsev committed Nov 27, 2024
1 parent 1088963 commit 02a23ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,12 @@ void performSync() throws InterruptedException {
* (1) retrieval of required file attributes.
*/
private void fetchAttributes() {
LOGGER.debug("{} - fetchAttributes for path {}", ruid, target.getPath());
PnfsGetFileAttributes message = new PnfsGetFileAttributes(target.getPath().toString(),
FsPath absolutePath = findAbsolutePath(targetPrefix,
target.getPath().toString());
LOGGER.error("{} - fetchAttributes for path {}, prefix {}, absolute path {} ", ruid, target.getPath(), targetPrefix, absolutePath);


PnfsGetFileAttributes message = new PnfsGetFileAttributes(absolutePath.toString(),
MINIMALLY_REQUIRED_ATTRIBUTES);
ListenableFuture<PnfsGetFileAttributes> requestFuture = pnfsHandler.requestAsync(
message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import diskCacheV111.util.FsPath;
import diskCacheV111.util.PnfsHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand Down Expand Up @@ -126,6 +127,8 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import org.dcache.services.bulk.BulkRequestSummary;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
Expand All @@ -138,6 +141,9 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
@Path("/bulk-requests")
public final class BulkResources {

private static final Logger LOGGER =
LoggerFactory.getLogger(BulkResources.class);

@Context
private HttpServletRequest request;

Expand Down Expand Up @@ -235,11 +241,15 @@ public Response submit(
Subject subject = getSubject();
Restriction restriction = getRestriction();
PnfsHandler handler = HandlerBuilders.unrestrictedPnfsHandler(pnfsmanager);
BulkRequest request = toBulkRequest(requestPayload, this.request, handler);
FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);
BulkRequest request = toBulkRequest(requestPayload, this.request, handler, rootPath);

/*
* Frontend sets the URL. The backend service provides the UUID.
*/
LOGGER.error("setUrlPrefix {}",
this.request.getRequestURL().toString());
request.setUrlPrefix(this.request.getRequestURL().toString());

BulkRequestMessage message = new BulkRequestMessage(request, restriction);
Expand Down Expand Up @@ -498,7 +508,7 @@ public static Restriction getRestriction() {
* they are defined in the Bulk service as well.
*/
@VisibleForTesting
static BulkRequest toBulkRequest(String requestPayload, HttpServletRequest httpServletRequest, PnfsHandler handler) {
static BulkRequest toBulkRequest(String requestPayload, HttpServletRequest httpServletRequest, PnfsHandler handler, FsPath rootPath) {
if (Strings.emptyToNull(requestPayload) == null) {
throw new BadRequestException("empty request payload.");
}
Expand Down Expand Up @@ -531,8 +541,10 @@ static BulkRequest toBulkRequest(String requestPayload, HttpServletRequest httpS

string = removeEntry(map, String.class, "target_prefix", "target-prefix",
"targetPrefix");
LOGGER.error("prefix {} userrootaware {}", string, getUserRootAwareTargetPrefix(httpServletRequest, string, handler));

if (httpServletRequest != null) {
request.setTargetPrefix(getUserRootAwareTargetPrefix(httpServletRequest, string, handler));
request.setTargetPrefix(etUserRootAwareTargetPrefix(httpServletRequest, rootPath.toString(), handler));
} else {
request.setTargetPrefix(string);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
package org.dcache.restful.util;

import static org.dcache.restful.util.HttpServletRequests.getTargetPrefixFromUserRoot;
import static diskCacheV111.util.FsPath.create;
import static org.junit.Assert.assertEquals;

import diskCacheV111.util.FsPath;
Expand Down Expand Up @@ -181,6 +182,6 @@ private void givenTargetPrefix(String targetPrefix) {
}

private void assertThatFullPrefixIs(String fullPrefix) {
assertEquals(fullPrefix, getTargetPrefixFromUserRoot(userRootPath, targetPrefix));
assertEquals(fullPrefix, getTargetPrefixFromUserRoot(userRootPath, targetPrefix, create("/"));
}
}

0 comments on commit 02a23ff

Please sign in to comment.