Skip to content

Commit abcd4b2

Browse files
authored
Merge pull request #8091 from dCache/fix/11.2/7997
bulk: report 413 Entity Too Large is limits on bulk requests are exce…
2 parents b5ad359 + cdc2a07 commit abcd4b2

4 files changed

Lines changed: 87 additions & 8 deletions

File tree

modules/dcache-bulk/src/main/java/org/dcache/services/bulk/BulkService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,15 +497,15 @@ private <M extends Message> void relayToLeader(M message, MessageReply<M> reply)
497497
}
498498

499499
private synchronized void checkDepthConstraints(BulkRequest request)
500-
throws BulkPermissionDeniedException {
500+
throws BulkContentTooLargeException {
501501
switch (request.getExpandDirectories()) {
502502
case ALL:
503503
switch (allowedDepth) {
504504
case ALL:
505505
checkTargetCount(request);
506506
return;
507507
default:
508-
throw new BulkPermissionDeniedException(
508+
throw new BulkContentTooLargeException(
509509
"full directory recursion not permitted.");
510510
}
511511
case TARGETS:
@@ -515,7 +515,7 @@ private synchronized void checkDepthConstraints(BulkRequest request)
515515
checkTargetCount(request);
516516
return;
517517
default:
518-
throw new BulkPermissionDeniedException(
518+
throw new BulkContentTooLargeException(
519519
"processing children of a directory not permitted.");
520520
}
521521
default:
@@ -548,27 +548,27 @@ private void checkRestrictions(Restriction restriction, String uuid)
548548
}
549549

550550
private synchronized void checkTargetCount(BulkRequest request)
551-
throws BulkPermissionDeniedException {
551+
throws BulkContentTooLargeException {
552552
List<String> targets = request.getTarget();
553553
int listSize = targets == null ? 0 : targets.size();
554554
switch (request.getExpandDirectories()) {
555555
case NONE:
556556
if (listSize > maxFlatTargets) {
557-
throw new BulkPermissionDeniedException(
557+
throw new BulkContentTooLargeException(
558558
String.format(TARGET_COUNT_ERROR_FORMAT, listSize, maxFlatTargets,
559559
Depth.NONE.name()));
560560
}
561561
break;
562562
case TARGETS:
563563
if (listSize > maxShallowTargets) {
564-
throw new BulkPermissionDeniedException(
564+
throw new BulkContentTooLargeException(
565565
String.format(TARGET_COUNT_ERROR_FORMAT, listSize, maxShallowTargets,
566566
Depth.TARGETS.name()));
567567
}
568568
break;
569569
case ALL:
570570
if (listSize > maxRecursiveTargets) {
571-
throw new BulkPermissionDeniedException(
571+
throw new BulkContentTooLargeException(
572572
String.format(TARGET_COUNT_ERROR_FORMAT, listSize, maxRecursiveTargets,
573573
Depth.ALL.name()));
574574
}
@@ -700,4 +700,4 @@ private void validateTargets(String uuid, Subject subject, List<String> paths)
700700
}
701701
}
702702
}
703-
}
703+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ public StageRequestInfo getStageInfo(@ApiParam("The unique id of the request.")
210210
@ApiResponse(code = 401, message = "Unauthorized"),
211211
@ApiResponse(code = 403, message = "Forbidden"),
212212
@ApiResponse(code = 404, message = "Not Found"),
213+
@ApiResponse(code = 413, message = "Content Too Large"),
213214
@ApiResponse(code = 429, message = "Too many requests"),
214215
@ApiResponse(code = 500, message = "Internal Server Error")
215216
})
@@ -275,6 +276,7 @@ public Response cancel(
275276
@ApiResponse(code = 400, message = "Bad request"),
276277
@ApiResponse(code = 401, message = "Unauthorized"),
277278
@ApiResponse(code = 403, message = "Forbidden"),
279+
@ApiResponse(code = 413, message = "Content Too Large"),
278280
@ApiResponse(code = 429, message = "Too many requests"),
279281
@ApiResponse(code = 500, message = "Internal Server Error")
280282
})

modules/dcache-frontend/src/main/java/org/dcache/restful/util/bulk/BulkServiceCommunicator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
6060
package org.dcache.restful.util.bulk;
6161

6262
import static javax.ws.rs.core.Response.Status.TOO_MANY_REQUESTS;
63+
import static javax.ws.rs.core.Response.Status.REQUEST_ENTITY_TOO_LARGE;
6364

6465
import com.google.common.base.Throwables;
6566
import dmg.util.Exceptions;
@@ -71,6 +72,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
7172
import javax.ws.rs.InternalServerErrorException;
7273
import javax.ws.rs.NotFoundException;
7374
import org.dcache.cells.CellStub;
75+
import org.dcache.services.bulk.BulkContentTooLargeException;
7476
import org.dcache.services.bulk.BulkPermissionDeniedException;
7577
import org.dcache.services.bulk.BulkQuotaExceededException;
7678
import org.dcache.services.bulk.BulkRequestNotFoundException;
@@ -124,6 +126,8 @@ private void checkError(BulkServiceMessage message) {
124126

125127
if (error instanceof BulkPermissionDeniedException) {
126128
throw new ForbiddenException(error);
129+
} else if (error instanceof BulkContentTooLargeException) {
130+
throw new ClientErrorException(REQUEST_ENTITY_TOO_LARGE, error);
127131
} else if (error instanceof BulkQuotaExceededException) {
128132
throw new ClientErrorException(TOO_MANY_REQUESTS, error);
129133
} else if (error instanceof BulkRequestNotFoundException) {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
COPYRIGHT STATUS:
3+
Dec 1st 2001, Fermi National Accelerator Laboratory (FNAL) documents and
4+
software are sponsored by the U.S. Department of Energy under Contract No.
5+
DE-AC02-76CH03000. Therefore, the U.S. Government retains a world-wide
6+
non-exclusive, royalty-free license to publish or reproduce these documents
7+
and software for U.S. Government purposes. All documents and software
8+
available from this server are protected under the U.S. and Foreign
9+
Copyright Laws, and FNAL reserves all rights.
10+
11+
Distribution of the software available from this server is free of
12+
charge subject to the user following the terms of the Fermitools
13+
Software Legal Information.
14+
15+
Redistribution and/or modification of the software shall be accompanied
16+
by the Fermitools Software Legal Information (including the copyright
17+
notice).
18+
19+
The user is asked to feed back problems, benefits, and/or suggestions
20+
about the software to the Fermilab Software Providers.
21+
22+
Neither the name of Fermilab, the URA, nor the names of the contributors
23+
may be used to endorse or promote products derived from this software
24+
without specific prior written permission.
25+
26+
DISCLAIMER OF LIABILITY (BSD):
27+
28+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FERMILAB,
32+
OR THE URA, OR THE U.S. DEPARTMENT of ENERGY, OR CONTRIBUTORS BE LIABLE
33+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
35+
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
36+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40+
41+
Liabilities of the Government:
42+
43+
This software is provided by URA, independent from its Prime Contract
44+
with the U.S. Department of Energy. URA is acting independently from
45+
the Government and in its own private capacity and is not acting on
46+
behalf of the U.S. Government, nor as its contractor nor its agent.
47+
Correspondingly, it is understood and agreed that the U.S. Government
48+
has no connection to this software and in no manner whatsoever shall
49+
be liable for nor assume any responsibility or obligation for any claim,
50+
cost, or damages arising out of or resulting from the use of the software
51+
available from this server.
52+
53+
Export Control:
54+
55+
All documents and software available from this server are subject to U.S.
56+
export control laws. Anyone downloading information from this server is
57+
obligated to secure any necessary Government licenses before exporting
58+
documents or software obtained from this server.
59+
*/
60+
package org.dcache.services.bulk;
61+
62+
public class BulkContentTooLargeException extends BulkServiceException {
63+
64+
private static final long serialVersionUID = 1L;
65+
66+
public BulkContentTooLargeException(String message) {
67+
super(message);
68+
}
69+
70+
public BulkContentTooLargeException(String message, Throwable cause) {
71+
super(message, cause);
72+
}
73+
}

0 commit comments

Comments
 (0)