Search in sources :

Example 11 with NoRouteToCellException

use of dmg.cells.nucleus.NoRouteToCellException in project dcache by dCache.

the class UserAdminShell method sendObject.

private Serializable sendObject(CellPath cellPath, Serializable object) throws NoRouteToCellException, InterruptedException, CommandException, AclException {
    CellAddressCore addr = cellPath.getCurrent();
    checkCdPermission(addr.isLocalAddress() ? addr.getCellName() : addr.toString());
    try {
        return _cellStub.send(cellPath, object, Serializable.class, _timeout).get();
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if (_fullException) {
            return getStackTrace(cause);
        }
        Throwables.throwIfInstanceOf(cause, Error.class);
        Throwables.throwIfInstanceOf(cause, NoRouteToCellException.class);
        Throwables.throwIfInstanceOf(cause, CommandException.class);
        throw new CommandThrowableException(cause.toString(), cause);
    }
}
Also used : CellAddressCore(dmg.cells.nucleus.CellAddressCore) CommandThrowableException(dmg.util.CommandThrowableException) Serializable(java.io.Serializable) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandException(dmg.util.CommandException) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with NoRouteToCellException

use of dmg.cells.nucleus.NoRouteToCellException in project dcache by dCache.

the class FileResources method cmrResources.

@POST
@ApiOperation(value = "Modify a file or directory.")
@Path("{path : .*}")
@ApiResponses({ @ApiResponse(code = 400, message = "Transition for directories not supported"), @ApiResponse(code = 400, message = "Unsupported QoS transition"), @ApiResponse(code = 400, message = "Unknown target QoS"), @ApiResponse(code = 400, message = "Unknown action"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 409, message = "Attribute already exists"), @ApiResponse(code = 409, message = "No such attribute"), @ApiResponse(code = 500, message = "Internal Server Error") })
@Consumes({ MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public Response cmrResources(@ApiParam(value = "Path of file or directory to be modified.", required = true) @PathParam("path") String requestPath, @ApiParam(value = "A JSON object that has an 'action' " + "item with a String value.\n" + "\n" + "If the 'action' value is 'mkdir' " + "then a new directory is created " + "with the name taken from the " + "value of the JSON object 'name' " + "item.  This directory is created " + "within the supplied path parameter, " + "which must be an existing directory.\n" + "\n" + "If action is 'mv' then the file " + "or directory specified by the path " + "parameter is moved and/or " + "renamed with the value of the JSON " + "object 'destination' item describing " + "the final location.  If the " + "'destination' value is a relative " + "path then it is resolved against " + "the path parameter value.\n" + "\n" + "If action is 'qos' then the value " + "of the JSON object 'target' item " + "describes the desired QoS." + "\n" + "If action is 'pin' then the default " + "value of lifetime is 0 and liftime-unit " + "SECONDS." + "\n" + "If action is 'rm-xattr' then " + "extended attributes of a file " + "or directory are removed as " + "given by the 'names' item.  The " + "'names' value is either a " + "string or an array of strings." + "\n" + "If action is 'set-xattr' then " + "extended attributes are created " + "or modified.  The optional " + "'mode' item controls whether to " + "create a new attribute (CREATE), " + "to modify an existing attribute " + "(MODIFY), or to assign the value " + "by either creating a new " + "attribute or modifying an " + "existing attribute (EITHER).  " + "EITHER is the default mode.  The " + "'attributes' item value is a JSON " + "Object with the new attributes," + "where the JSON Object's key is " + "the attribute name and the " + "corresponding JSON Object's " + "value is this attribute's value." + "\n" + "If action is 'set-label' then " + "a label is added to the" + "given file object." + "'label' item value is a String." + "\n" + "If action is 'rm-label' then the corresponding" + "label of a file is removed." + "The  'label' value is either a string." + "\n" + "If action is 'chgrp' then the " + "command requests the change of " + "group-owner of the target file " + "or directory.  The value of the " + "JSON object 'gid' item is the " + "numerical value of the desired " + "new group-owner." + "\n" + "If action is 'chmod' then the " + "command reqests the change of " + "the target file's or directory's " + "permissions.  The value of the " + "JSON object 'mode' item is the " + "numerical value of the desired " + "mode.", required = true, examples = @Example({ @ExampleProperty(mediaType = "MV", value = "{\n" + "    \"action\" : \"mv\",\n" + "    \"destination\" : \"../foo\"\n" + "}"), @ExampleProperty(mediaType = "MKDIR", value = "{\n" + "    \"action\" : \"mkdir\",\n" + "    \"name\" : \"new-subdir\"\n" + "}"), @ExampleProperty(mediaType = "QOS", value = "{\n" + "    \"action\" : \"qos\",\n" + "    \"target\" : \"DISK+TAPE\"\n" + "}"), @ExampleProperty(mediaType = "PIN", value = "{\n" + "    \"action\" : \"pin\",\n" + "    \"lifetime\" : \"number\"\n" + "    \"lifetime-unit\" : \"SECONDS|MINUTES|HOURS|DAYS\"\n" + "}"), @ExampleProperty(mediaType = "UNPIN", value = "{\n" + "    \"action\" : \"unpin\",\n" + "}"), @ExampleProperty(mediaType = "SET-XATTR", value = "{\n" + "    \"action\" : \"set-xattr\",\n" + "    \"mode\" : \"CREATE\",\n" + "    \"attributes\" : {\n" + "        \"attr-1\": \"First attribute\",\n" + "        \"attr-2\": \"Second attribute\"\n" + "    }\n" + "}"), @ExampleProperty(mediaType = "RM-XATTR", value = "{\n" + "    \"action\" : \"rm-xattr\",\n" + "    \"names\" : [\n" + "        \"attr-1\",\n" + "        \"attr-2\"\n" + "    ]\n" + "}"), @ExampleProperty(mediaType = "SET-LABEL", value = "{\n" + "    \"action\" : \"set-label\",\n" + "    \"label\" : : \"label\",\n" + "}"), @ExampleProperty(mediaType = "RM-LABEL", value = "{\n" + "    \"action\" : \"rm-label\",\n" + "    \"label\" :  \"label\",\n" + "}"), @ExampleProperty(mediaType = "CHGRP", value = "{\n" + "    \"action\" : \"chgrp\",\n" + "    \"gid\" : 1000\n" + "}"), @ExampleProperty(mediaType = "CHMOD", value = "{\n" + "    \"action\" : \"chmod\",\n" + "    \"mode\" : 493\n" + "}") })) String requestPayload) {
    try {
        JSONObject reqPayload = new JSONObject(requestPayload);
        String action = (String) reqPayload.get("action");
        PnfsHandler pnfsHandler = HandlerBuilders.roleAwarePnfsHandler(pnfsmanager);
        FsPath path = pathMapper.asDcachePath(request, requestPath, ForbiddenException::new);
        PnfsId pnfsId;
        Long uid;
        switch(action) {
            case "mkdir":
                String name = (String) reqPayload.get("name");
                FsPath.checkChildName(name, BadRequestException::new);
                pnfsHandler = HandlerBuilders.pnfsHandler(// FIXME: non-role identity to ensure correct ownership
                pnfsmanager);
                pnfsHandler.createPnfsDirectory(path.child(name).toString());
                break;
            case "mv":
                String dest = (String) reqPayload.get("destination");
                FsPath target = pathMapper.resolve(request, path, dest);
                pnfsHandler.renameEntry(path.toString(), target.toString(), true);
                break;
            case "qos":
                String targetQos = reqPayload.getString("target");
                new QoSTransitionEngine(poolmanager, poolMonitor, pnfsHandler, pinmanager).adjustQoS(path, targetQos, request.getRemoteHost());
                break;
            case "pin":
                Integer lifetime = reqPayload.optInt("lifetime");
                if (lifetime == null) {
                    lifetime = 0;
                }
                String lifetimeUnitVal = reqPayload.optString("lifetime-unit");
                TimeUnit lifetimeUnit = lifetimeUnitVal == null ? TimeUnit.SECONDS : TimeUnit.valueOf(lifetimeUnitVal);
                pnfsId = pnfsHandler.getPnfsIdByPath(path.toString());
                /*
                     *  Fire-and-forget, as it was in 5.2
                     */
                pinmanager.notify(new PinManagerPinMessage(FileAttributes.ofPnfsId(pnfsId), getProtocolInfo(), getRequestId(), lifetimeUnit.toMillis(lifetime)));
                break;
            case "unpin":
                pnfsId = pnfsHandler.getPnfsIdByPath(path.toString());
                PinManagerUnpinMessage message = new PinManagerUnpinMessage(pnfsId);
                message.setRequestId(getRequestId());
                pinmanager.notify(message);
                break;
            case "rm-xattr":
                Object namesArgument = reqPayload.get("names");
                if (namesArgument instanceof String) {
                    pnfsHandler.removeExtendedAttribute(path, (String) namesArgument);
                } else if (namesArgument instanceof JSONArray) {
                    JSONArray namesArray = (JSONArray) namesArgument;
                    List<String> names = new ArrayList<>(namesArray.length());
                    for (int i = 0; i < namesArray.length(); i++) {
                        names.add(namesArray.getString(i));
                    }
                    pnfsHandler.removeExtendedAttribute(path, names);
                } else {
                    throw new JSONException("\"names\" is not a String or an array");
                }
                break;
            case "set-xattr":
                String modeString = reqPayload.optString("mode", "EITHER");
                Mode xattrSetMode = modeOf(modeString);
                JSONObject attributeOject = reqPayload.getJSONObject("attributes");
                Map<String, byte[]> attributes = new HashMap<>(attributeOject.length());
                for (String key : attributeOject.keySet()) {
                    String value = attributeOject.getString(key);
                    attributes.put(key, value.getBytes(StandardCharsets.UTF_8));
                }
                pnfsHandler.writeExtendedAttribute(path, attributes, xattrSetMode);
                break;
            case "set-label":
                String label = reqPayload.getString("label");
                pnfsHandler.setFileAttributes(path, FileAttributes.ofLabel(label));
                break;
            case "rm-label":
                String labelsArgument = reqPayload.getString("label");
                pnfsHandler.removeLabel(path, labelsArgument);
                break;
            case "chgrp":
                int gid = reqPayload.getInt("gid");
                pnfsHandler.setFileAttributes(path, FileAttributes.ofGid(gid));
                break;
            case "chmod":
                int mode = reqPayload.getInt("mode");
                pnfsHandler.setFileAttributes(path, FileAttributes.ofMode(mode));
                break;
            default:
                throw new UnsupportedOperationException("No such action " + action);
        }
    } catch (FileNotFoundCacheException e) {
        throw new NotFoundException(e);
    } catch (PermissionDeniedCacheException e) {
        if (RequestUser.isAnonymous()) {
            throw new NotAuthorizedException(e);
        } else {
            throw new ForbiddenException(e);
        }
    } catch (AttributeExistsCacheException e) {
        throw new WebApplicationException(Response.status(409, "Attribute already exist").build());
    } catch (NoAttributeCacheException e) {
        throw new WebApplicationException(Response.status(409, "No such attribute").build());
    } catch (UnsupportedOperationException | URISyntaxException | JSONException | CacheException | InterruptedException | NoRouteToCellException e) {
        throw new BadRequestException(e.getMessage(), e);
    }
    return successfulResponse(Response.Status.CREATED);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) QoSTransitionEngine(org.dcache.qos.QoSTransitionEngine) NotFoundException(javax.ws.rs.NotFoundException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) URISyntaxException(java.net.URISyntaxException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ArrayList(java.util.ArrayList) FsPath(diskCacheV111.util.FsPath) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) ForbiddenException(javax.ws.rs.ForbiddenException) PnfsId(diskCacheV111.util.PnfsId) Mode(diskCacheV111.vehicles.PnfsWriteExtendedAttributesMessage.Mode) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) PnfsHandler(diskCacheV111.util.PnfsHandler) PinManagerPinMessage(org.dcache.pinmanager.PinManagerPinMessage) PinManagerUnpinMessage(org.dcache.pinmanager.PinManagerUnpinMessage) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) JSONObject(org.json.JSONObject) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) BadRequestException(javax.ws.rs.BadRequestException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) JSONObject(org.json.JSONObject) Path(javax.ws.rs.Path) FsPath(diskCacheV111.util.FsPath) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with NoRouteToCellException

use of dmg.cells.nucleus.NoRouteToCellException in project dcache by dCache.

the class FileResources method getFileAttributes.

@GET
@ApiOperation(value = "Find metadata and optionally directory contents.", notes = "The method offers the possibility to list the content of a " + "directory in addition to providing metadata of a " + "specified file or directory.")
@ApiResponses({ @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Internal Server Error") })
@Path("{path : .*}")
@Produces(MediaType.APPLICATION_JSON)
public JsonFileAttributes getFileAttributes(@ApiParam("Path of file or directory.") @PathParam("path") String requestPath, @ApiParam("Whether to include directory listing.") @DefaultValue("false") @QueryParam("children") boolean isList, @ApiParam("Whether to include file locality information.") @DefaultValue("false") @QueryParam("locality") boolean isLocality, @ApiParam(value = "Whether to include replica locations.") @QueryParam("locations") boolean isLocations, @ApiParam(value = "Whether to include quality of service.") @DefaultValue("false") @QueryParam("qos") boolean isQos, @ApiParam("Whether to include extended attributes.") @QueryParam("xattr") boolean isXattr, @ApiParam("Whether to include labels.") @QueryParam("labels") boolean isLabels, @ApiParam("Whether or not to list checksum values.") @QueryParam("checksum") boolean isChecksum, @ApiParam("Limit number of replies in directory listing.") @QueryParam("limit") String limit, @ApiParam("Number of entries to skip in directory listing.") @QueryParam("offset") String offset) throws CacheException {
    JsonFileAttributes fileAttributes = new JsonFileAttributes();
    Set<FileAttribute> attributes = NamespaceUtils.getRequestedAttributes(isLocality, isLocations, isQos, isChecksum, false);
    PnfsHandler handler = HandlerBuilders.roleAwarePnfsHandler(pnfsmanager);
    FsPath path = pathMapper.asDcachePath(request, requestPath, ForbiddenException::new);
    try {
        FileAttributes namespaceAttributes = handler.getFileAttributes(path, attributes);
        NamespaceUtils.chimeraToJsonAttributes(path.name(), fileAttributes, namespaceAttributes, isLocality, isLocations, isLabels, false, isXattr, isChecksum, request, poolMonitor);
        if (isQos) {
            NamespaceUtils.addQoSAttributes(fileAttributes, namespaceAttributes, request, poolMonitor, pinmanager);
        }
        // fill children list id it's a directory and listing is requested
        if (namespaceAttributes.getFileType() == FileType.DIR && isList) {
            Range<Integer> range;
            try {
                int lower = (offset == null) ? 0 : Integer.parseInt(offset);
                int ceiling = (limit == null) ? Integer.MAX_VALUE : Integer.parseInt(limit);
                if (ceiling < 0 || lower < 0) {
                    throw new BadRequestException("limit and offset can not be less than zero.");
                }
                range = (Integer.MAX_VALUE - lower < ceiling) ? Range.atLeast(lower) : Range.closedOpen(lower, lower + ceiling);
            } catch (NumberFormatException e) {
                throw new BadRequestException("limit and offset must be an integer value.");
            }
            List<JsonFileAttributes> children = new ArrayList<>();
            DirectoryStream stream = listDirectoryHandler.list(HttpServletRequests.roleAwareSubject(request), HttpServletRequests.roleAwareRestriction(request), path, null, range, attributes);
            for (DirectoryEntry entry : stream) {
                String fName = entry.getName();
                JsonFileAttributes childrenAttributes = new JsonFileAttributes();
                NamespaceUtils.chimeraToJsonAttributes(fName, childrenAttributes, entry.getFileAttributes(), isLocality, isLocations, isLabels, false, isXattr, isChecksum, request, poolMonitor);
                childrenAttributes.setFileName(fName);
                if (isQos) {
                    NamespaceUtils.addQoSAttributes(childrenAttributes, entry.getFileAttributes(), request, poolMonitor, pinmanager);
                }
                children.add(childrenAttributes);
            }
            fileAttributes.setChildren(children);
        }
    } catch (FileNotFoundCacheException e) {
        throw new NotFoundException(e);
    } catch (PermissionDeniedCacheException e) {
        if (RequestUser.isAnonymous()) {
            throw new NotAuthorizedException(e);
        } else {
            throw new ForbiddenException(e);
        }
    } catch (CacheException | InterruptedException | NoRouteToCellException ex) {
        LOG.warn(Exceptions.meaningfulMessage(ex));
        throw new InternalServerErrorException(ex);
    }
    return fileAttributes;
}
Also used : AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) ArrayList(java.util.ArrayList) DirectoryStream(org.dcache.util.list.DirectoryStream) NotFoundException(javax.ws.rs.NotFoundException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) JsonFileAttributes(org.dcache.restful.providers.JsonFileAttributes) JsonFileAttributes(org.dcache.restful.providers.JsonFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) FsPath(diskCacheV111.util.FsPath) ForbiddenException(javax.ws.rs.ForbiddenException) PnfsHandler(diskCacheV111.util.PnfsHandler) DirectoryEntry(org.dcache.util.list.DirectoryEntry) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) BadRequestException(javax.ws.rs.BadRequestException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) FileAttribute(org.dcache.namespace.FileAttribute) Path(javax.ws.rs.Path) FsPath(diskCacheV111.util.FsPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with NoRouteToCellException

use of dmg.cells.nucleus.NoRouteToCellException in project dcache by dCache.

the class IdResources method getAttributes.

@GET
@ApiOperation(value = "Discover information about a file from the PNFS-ID.", notes = "Retrieve all file attributes plus the file's path from the " + "given PNFS-ID.")
@ApiResponses({ @ApiResponse(code = 400, message = "Bad pnsfid"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Internal Server Error") })
@Path("{pnfsid}")
@Produces(MediaType.APPLICATION_JSON)
public JsonFileAttributes getAttributes(@ApiParam("The PNFS-ID of a file or directory.") @PathParam("pnfsid") String value) {
    Set<FileAttribute> attributeSet = NamespaceUtils.getRequestedAttributes(true, true, true, true, true);
    JsonFileAttributes result = new JsonFileAttributes();
    PnfsHandler handler = HandlerBuilders.roleAwarePnfsHandler(pnfsmanager);
    try {
        PnfsId id = new PnfsId(value);
        FileAttributes attributes = handler.getFileAttributes(id, attributeSet);
        /*
             * Caveat: Because there is a possibility that a given file could have
             * a number of hard-linked paths, and that the current path finder
             * code selects only the most recently created path/link, there
             * is a possibility of getting a path which may not correspond
             * to the expected one.
             */
        FsPath path = FsPath.create(attributes.getStorageInfo().getKey("path"));
        /*
             * Since FileResources maps according to the effective root,
             * we should return the path in the same form here.
             */
        result.setPath(pathMapper.asRequestPath(request, path));
        String name = path.name();
        result.setFileName(name);
        NamespaceUtils.chimeraToJsonAttributes(name, result, attributes, true, true, true, true, false, true, request, poolMonitor);
        NamespaceUtils.addQoSAttributes(result, attributes, request, poolMonitor, pinmanager);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Bad pnsfid " + value, e);
    } catch (FileNotFoundCacheException e) {
        throw new NotFoundException(e);
    } catch (PermissionDeniedCacheException e) {
        if (RequestUser.isAnonymous()) {
            throw new NotAuthorizedException(e);
        } else {
            throw new ForbiddenException(e);
        }
    } catch (CacheException | InterruptedException | NoRouteToCellException e) {
        LOGGER.warn(Exceptions.meaningfulMessage(e));
        throw new InternalServerErrorException(e);
    }
    return result;
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) PnfsId(diskCacheV111.util.PnfsId) NotFoundException(javax.ws.rs.NotFoundException) PnfsHandler(diskCacheV111.util.PnfsHandler) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) JsonFileAttributes(org.dcache.restful.providers.JsonFileAttributes) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) BadRequestException(javax.ws.rs.BadRequestException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) JsonFileAttributes(org.dcache.restful.providers.JsonFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) FileAttribute(org.dcache.namespace.FileAttribute) FsPath(diskCacheV111.util.FsPath) FsPath(diskCacheV111.util.FsPath) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 15 with NoRouteToCellException

use of dmg.cells.nucleus.NoRouteToCellException in project dcache by dCache.

the class BillingResources method getP2ps.

@GET
@ApiOperation("Provides a list of pool-to-pool transfers for a specific " + "PNFS-ID.")
@ApiResponses({ @ApiResponse(code = 400, message = "Bad request"), @ApiResponse(code = 403, message = "p2p records are only available to admin users."), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Internal Server Error") })
@Produces(MediaType.APPLICATION_JSON)
@Path("p2ps/{pnfsid}")
public List<P2PTransferRecord> getP2ps(@ApiParam("The file to list.") @PathParam("pnfsid") PnfsId pnfsid, @ApiParam("Return no transfers after this datestamp.") @QueryParam("before") String before, @ApiParam("Return no transfers before this datestamp.") @QueryParam("after") String after, @ApiParam("Maximum number of transfers to return.") @QueryParam("limit") Integer limit, @ApiParam("Number of transfers to skip.") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam("Only select transfers from the specified pool.") @QueryParam("serverPool") String serverPool, @ApiParam("Only select transfers to the specified pool.") @QueryParam("clientPool") String clientPool, @ApiParam("Only select transfers triggered by the specified client.") @QueryParam("client") String client, @ApiParam("How to sort responses.") @DefaultValue("date") @QueryParam("sort") String sort) {
    if (!RequestUser.canViewFileOperations(unlimitedOperationVisibility)) {
        throw new ForbiddenException("P2p records are only available to admin users.");
    }
    try {
        limit = limit == null ? Integer.MAX_VALUE : limit;
        PagedList<P2PTransferRecord> result = service.getP2ps(pnfsid, before, after, limit, offset, serverPool, clientPool, client, sort);
        response.addIntHeader(TOTAL_COUNT_HEADER, result.total);
        return result.contents;
    } catch (FileNotFoundCacheException e) {
        throw new NotFoundException(e);
    } catch (NoRouteToCellException | InterruptedException | CacheException e) {
        LOGGER.warn(Exceptions.meaningfulMessage(e));
        throw new InternalServerErrorException(e);
    } catch (IllegalArgumentException | ParseException e) {
        throw new BadRequestException(e.getMessage(), e);
    }
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFoundException(javax.ws.rs.NotFoundException) P2PTransferRecord(org.dcache.restful.providers.billing.P2PTransferRecord) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) BadRequestException(javax.ws.rs.BadRequestException) ParseException(java.text.ParseException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)67 CacheException (diskCacheV111.util.CacheException)55 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)25 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)22 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)19 ArrayList (java.util.ArrayList)15 ApiOperation (io.swagger.annotations.ApiOperation)14 ApiResponses (io.swagger.annotations.ApiResponses)14 Produces (javax.ws.rs.Produces)14 BadRequestException (javax.ws.rs.BadRequestException)13 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)13 Path (javax.ws.rs.Path)13 CellPath (dmg.cells.nucleus.CellPath)11 ExecutionException (java.util.concurrent.ExecutionException)11 ForbiddenException (javax.ws.rs.ForbiddenException)11 GET (javax.ws.rs.GET)11 FsPath (diskCacheV111.util.FsPath)10 PnfsId (diskCacheV111.util.PnfsId)10 SRMException (org.dcache.srm.SRMException)10 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)10