Search in sources :

Example 1 with NearlineData

use of org.dcache.pool.nearline.json.NearlineData in project dcache by dCache.

the class PoolInfoResources method getNearlineQueues.

@GET
@ApiOperation("Get nearline activity information for a specific pool.")
@ApiResponses({ @ApiResponse(code = 400, message = "unrecognized queue type"), @ApiResponse(code = 403, message = "Pool command only accessible to admin users."), @ApiResponse(code = 500, message = "Internal Server Error") })
@Path("/{pool}/nearline/queues")
@Produces(MediaType.APPLICATION_JSON)
public List<NearlineData> getNearlineQueues(@ApiParam("The pool to be described.") @PathParam("pool") String pool, @ApiParam("Select transfers of a specific type " + "(flush, stage, remove).") @QueryParam("type") String typeList, @ApiParam("The number of items to skip.") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam("The maximum number of items to return.") @QueryParam("limit") Integer limit, @ApiParam("Select only operations affecting this PNFS-ID.") @QueryParam("pnfsid") String pnfsid, @ApiParam("Select only operations in this state.") @QueryParam("state") String state, @ApiParam("Select only operations of this storage class.") @QueryParam("storageClass") String storageClass, @ApiParam("How the returned values should be sorted.") @DefaultValue("class,created") @QueryParam("sort") String sort) {
    if (!RequestUser.canViewFileOperations(unlimitedOperationVisibility)) {
        throw new ForbiddenException("Pool command only accessible to admin users.");
    }
    limit = limit == null ? Integer.MAX_VALUE : limit;
    List<NearlineData> list = new ArrayList<>();
    PagedList<NearlineData> pagedList;
    int count = 0;
    try {
        String[] types = typeList == null ? new String[0] : typeList.split(",");
        for (String type : types) {
            switch(type) {
                case "flush":
                    pagedList = service.getFlush(pool, offset, limit, pnfsid, state, storageClass, sort);
                    list.addAll(pagedList.contents);
                    count += pagedList.total;
                    break;
                case "stage":
                    pagedList = service.getStage(pool, offset, limit, pnfsid, state, storageClass, sort);
                    list.addAll(pagedList.contents);
                    count += pagedList.total;
                    break;
                case "remove":
                    pagedList = service.getRemove(pool, offset, limit, pnfsid, state, storageClass, sort);
                    list.addAll(pagedList.contents);
                    count += pagedList.total;
                    break;
                default:
                    throw new BadRequestException("unrecognized queue type: " + type);
            }
        }
        response.addIntHeader(TOTAL_COUNT_HEADER, count);
        return list;
    } catch (InterruptedException | NoRouteToCellException | CacheException e) {
        LOGGER.warn(Exceptions.meaningfulMessage(e));
        throw new InternalServerErrorException(e);
    }
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) CacheException(diskCacheV111.util.CacheException) ArrayList(java.util.ArrayList) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NearlineData(org.dcache.pool.nearline.json.NearlineData) Path(javax.ws.rs.Path) CellPath(dmg.cells.nucleus.CellPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

CacheException (diskCacheV111.util.CacheException)1 CellPath (dmg.cells.nucleus.CellPath)1 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 BadRequestException (javax.ws.rs.BadRequestException)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 GET (javax.ws.rs.GET)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 NearlineData (org.dcache.pool.nearline.json.NearlineData)1