Skip to content

Commit

Permalink
KYLIN-3355 Improve the HTTP return code
Browse files Browse the repository at this point in the history
  • Loading branch information
shaofengshi committed Aug 2, 2018
1 parent bccfb7f commit 9fec0c4
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 102 deletions.
20 changes: 0 additions & 20 deletions core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ CubeSegment appendSegment(CubeInstance cube, TSRange tsRange, SegmentRange segRa
CubeInstance cubeCopy = cube.latestCopyForWrite(); // get a latest copy

checkInputRanges(tsRange, segRange);
checkBuildingSegment(cubeCopy);

// fix start/end a bit
if (cubeCopy.getModel().getPartitionDesc().isPartitioned()) {
Expand Down Expand Up @@ -673,7 +672,6 @@ public CubeSegment refreshSegment(CubeInstance cube, TSRange tsRange, SegmentRan
CubeInstance cubeCopy = cube.latestCopyForWrite(); // get a latest copy

checkInputRanges(tsRange, segRange);
checkBuildingSegment(cubeCopy);

if (cubeCopy.getModel().getPartitionDesc().isPartitioned() == false) {
// full build
Expand Down Expand Up @@ -716,8 +714,6 @@ public CubeSegment refreshSegment(CubeInstance cube, TSRange tsRange, SegmentRan
public CubeSegment[] optimizeSegments(CubeInstance cube, Set<Long> cuboidsRecommend) throws IOException {
CubeInstance cubeCopy = cube.latestCopyForWrite(); // get a latest copy

checkReadyForOptimize(cubeCopy);

List<CubeSegment> readySegments = cubeCopy.getSegments(SegmentStatusEnum.READY);
CubeSegment[] optimizeSegments = new CubeSegment[readySegments.size()];
int i = 0;
Expand All @@ -744,7 +740,6 @@ public CubeSegment mergeSegments(CubeInstance cube, TSRange tsRange, SegmentRang
throw new IllegalArgumentException("Cube " + cubeCopy + " has no segments");

checkInputRanges(tsRange, segRange);
checkBuildingSegment(cubeCopy);
checkCubeIsPartitioned(cubeCopy);

if (cubeCopy.getSegments().getFirstSegment().isOffsetCube()) {
Expand Down Expand Up @@ -829,21 +824,6 @@ private void checkInputRanges(TSRange tsRange, SegmentRange segRange) {
}
}

private void checkBuildingSegment(CubeInstance cube) {
checkBuildingSegment(cube, cube.getConfig().getMaxBuildingSegments());
}

private void checkReadyForOptimize(CubeInstance cube) {
checkBuildingSegment(cube, 1);
}

private void checkBuildingSegment(CubeInstance cube, int maxBuildingSeg) {
if (cube.getBuildingSegments().size() >= maxBuildingSeg) {
throw new IllegalStateException(
"There is already " + cube.getBuildingSegments().size() + " building segment; ");
}
}

private void checkCubeIsPartitioned(CubeInstance cube) {
if (cube.getDescriptor().getModel().getPartitionDesc().isPartitioned() == false) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.kylin.rest.exception.ForbiddenException;
import org.apache.kylin.rest.exception.InternalErrorException;
import org.apache.kylin.rest.exception.NotFoundException;
import org.apache.kylin.rest.exception.TooManyRequestException;
import org.apache.kylin.rest.exception.UnauthorizedException;
import org.apache.kylin.rest.msg.Message;
import org.apache.kylin.rest.msg.MsgPicker;
Expand Down Expand Up @@ -101,6 +102,13 @@ ErrorResponse handleUnauthorized(HttpServletRequest req, Exception ex) {
return new ErrorResponse(req.getRequestURL().toString(), ex);
}

@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
@ExceptionHandler(TooManyRequestException.class)
@ResponseBody
ErrorResponse handleTooManyRequest(HttpServletRequest req, Exception ex) {
return new ErrorResponse(req.getRequestURL().toString(), ex);
}

protected void checkRequiredArg(String fieldName, Object fieldValue) {
if (fieldValue == null || StringUtils.isEmpty(String.valueOf(fieldValue))) {
throw new BadRequestException(fieldName + " is required");
Expand Down
Loading

0 comments on commit 9fec0c4

Please sign in to comment.