Search in sources :

Example 1 with DoorTransferRecord

use of org.dcache.restful.providers.billing.DoorTransferRecord in project dcache by dCache.

the class BillingResources method getReads.

@GET
@ApiOperation("Provides a list of read transfers for a specific PNFS-ID.")
@ApiResponses({ @ApiResponse(code = 400, message = "Bad request"), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Internal Server Error") })
@Produces(MediaType.APPLICATION_JSON)
@Path("reads/{pnfsid}")
public List<DoorTransferRecord> getReads(@ApiParam("The file to list.") @PathParam("pnfsid") PnfsId pnfsid, @ApiParam("Return no reads after this datestamp.") @QueryParam("before") String before, @ApiParam("Return no reads before this datestamp.") @QueryParam("after") String after, @ApiParam("Maximum number of reads to return.") @QueryParam("limit") Integer limit, @ApiParam("Number of reads to skip.") @DefaultValue("0") @QueryParam("offset") Integer offset, @ApiParam("Only select reads from the specified pool.") @QueryParam("pool") String pool, @ApiParam("Only select reads initiated by the specified door.") @QueryParam("door") String door, @ApiParam("Only select reads requested by the client.") @QueryParam("client") String client, @ApiParam("How to sort responses.") @DefaultValue("date") @QueryParam("sort") String sort) {
    try {
        limit = limit == null ? Integer.MAX_VALUE : limit;
        Long suid = RequestUser.getSubjectUidForFileOperations(unlimitedOperationVisibility);
        PagedList<DoorTransferRecord> result = service.getReads(pnfsid, before, after, limit, offset, suid, pool, door, 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 : CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFoundException(javax.ws.rs.NotFoundException) DoorTransferRecord(org.dcache.restful.providers.billing.DoorTransferRecord) 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)

Example 2 with DoorTransferRecord

use of org.dcache.restful.providers.billing.DoorTransferRecord in project dcache by dCache.

the class BillingResources method getWrites.

@GET
@ApiOperation("Provides a list of write transfers for a specific PNFS-ID.")
@ApiResponses({ @ApiResponse(code = 400, message = "Bad request"), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Internal Server Error") })
@Produces(MediaType.APPLICATION_JSON)
@Path("writes/{pnfsid}")
public List<DoorTransferRecord> getWrites(@ApiParam("The file to list.") @PathParam("pnfsid") PnfsId pnfsid, @ApiParam("Return no writes after this datestamp.") @QueryParam("before") String before, @ApiParam("Return no writes before this datestamp.") @QueryParam("after") String after, @ApiParam("Maximum number of writes to return.") @QueryParam("limit") Integer limit, @ApiParam("Number of writes to skip.") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam("Only select writes from the specified pool.") @QueryParam("pool") String pool, @ApiParam("Only select writes initiated by the specified door.") @QueryParam("door") String door, @ApiParam("Only select writes requested by the client.") @QueryParam("client") String client, @ApiParam("How to sort responses.") @DefaultValue("date") @QueryParam("sort") String sort) {
    try {
        limit = limit == null ? Integer.MAX_VALUE : limit;
        Long suid = RequestUser.getSubjectUidForFileOperations(unlimitedOperationVisibility);
        PagedList<DoorTransferRecord> result = service.getWrites(pnfsid, before, after, limit, offset, suid, pool, door, 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 : CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFoundException(javax.ws.rs.NotFoundException) DoorTransferRecord(org.dcache.restful.providers.billing.DoorTransferRecord) 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)

Example 3 with DoorTransferRecord

use of org.dcache.restful.providers.billing.DoorTransferRecord in project dcache by dCache.

the class BillingInfoServiceImpl method getDoorTransfers.

private PagedList<DoorTransferRecord> getDoorTransfers(Type type, PnfsId pnfsid, String before, String after, Integer limit, int offset, String door, String pool, String client, String sort, Long suid) throws FileNotFoundCacheException, ParseException, CacheException, NoRouteToCellException, InterruptedException {
    if (Strings.isNullOrEmpty(sort)) {
        sort = "date";
    }
    TransferRecordRequestMessage message = new TransferRecordRequestMessage(pnfsid, getDate(before), getDate(after), type, door, null, pool, client, limit == null ? Integer.MAX_VALUE : limit, offset, sort);
    message = collector.sendRecordRequest(message);
    Predicate<TransferRecord> matchesSubject = r -> suid == null || r.getMappedUid() == null || suid.intValue() == r.getMappedUid();
    List<DoorTransferRecord> list = message.getRecords().stream().filter(matchesSubject).map(DoorTransferRecord::new).collect(Collectors.toList());
    return new PagedList<>(list, list.size());
}
Also used : BillingInfoCollectionUtils(org.dcache.restful.util.billing.BillingInfoCollectionUtils) StorageRecordRequestMessage(org.dcache.vehicles.billing.StorageRecordRequestMessage) TransferRecordRequestMessage(org.dcache.vehicles.billing.TransferRecordRequestMessage) Callable(java.util.concurrent.Callable) TimeFrame(org.dcache.util.histograms.TimeFrame) ArrayList(java.util.ArrayList) Command(dmg.util.command.Command) Strings(com.google.common.base.Strings) Future(java.util.concurrent.Future) BillingDataGridEntry(org.dcache.restful.providers.billing.BillingDataGridEntry) TransferRecord(org.dcache.services.billing.db.data.TransferRecord) CacheException(diskCacheV111.util.CacheException) DoorTransferRecord(org.dcache.restful.providers.billing.DoorTransferRecord) P2PTransferRecord(org.dcache.restful.providers.billing.P2PTransferRecord) Map(java.util.Map) BillingDataGrid(org.dcache.restful.providers.billing.BillingDataGrid) Histogram(org.dcache.util.histograms.Histogram) ParseException(java.text.ParseException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PagedList(org.dcache.restful.providers.PagedList) PnfsId(diskCacheV111.util.PnfsId) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) BillingDataRequestMessage(org.dcache.vehicles.billing.BillingDataRequestMessage) RecordRequestMessage(org.dcache.vehicles.billing.RecordRequestMessage) List(java.util.List) BillingTransferRecord(org.dcache.restful.providers.billing.BillingTransferRecord) HistogramModel(org.dcache.util.histograms.HistogramModel) HSMTransferRecord(org.dcache.restful.providers.billing.HSMTransferRecord) Option(dmg.util.command.Option) CellDataCollectingService(org.dcache.services.collector.CellDataCollectingService) Type(org.dcache.vehicles.billing.RecordRequestMessage.Type) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) Entry(java.util.Map.Entry) Argument(dmg.util.command.Argument) BillingInfoCollector(org.dcache.restful.util.billing.BillingInfoCollector) TransferRecord(org.dcache.services.billing.db.data.TransferRecord) DoorTransferRecord(org.dcache.restful.providers.billing.DoorTransferRecord) P2PTransferRecord(org.dcache.restful.providers.billing.P2PTransferRecord) BillingTransferRecord(org.dcache.restful.providers.billing.BillingTransferRecord) HSMTransferRecord(org.dcache.restful.providers.billing.HSMTransferRecord) DoorTransferRecord(org.dcache.restful.providers.billing.DoorTransferRecord) PagedList(org.dcache.restful.providers.PagedList) TransferRecordRequestMessage(org.dcache.vehicles.billing.TransferRecordRequestMessage)

Aggregations

CacheException (diskCacheV111.util.CacheException)3 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)3 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)3 ParseException (java.text.ParseException)3 DoorTransferRecord (org.dcache.restful.providers.billing.DoorTransferRecord)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 BadRequestException (javax.ws.rs.BadRequestException)2 GET (javax.ws.rs.GET)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NotFoundException (javax.ws.rs.NotFoundException)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Strings (com.google.common.base.Strings)1 PnfsId (diskCacheV111.util.PnfsId)1 Argument (dmg.util.command.Argument)1 Command (dmg.util.command.Command)1 Option (dmg.util.command.Option)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1