Search in sources :

Example 56 with NoRouteToCellException

use of dmg.cells.nucleus.NoRouteToCellException 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 57 with NoRouteToCellException

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

the class PoolInfoResources method getMovers.

@GET
@ApiOperation(value = "Get mover information for a specific pool.", responseHeaders = { @ResponseHeader(name = "X-Total-Count", description = "Total " + "number of potential responses.  This may be greater " + "than the number of response if offset or limit are " + "specified") })
@ApiResponses({ @ApiResponse(code = 403, message = "Pool command only accessible to admin users."), @ApiResponse(code = 500, message = "Internal Server Error") })
@Path("/{pool}/movers")
@Produces(MediaType.APPLICATION_JSON)
public List<MoverData> getMovers(@ApiParam("The pool to be described.") @PathParam("pool") String pool, @ApiParam("A comma-seperated list of mover types. " + "Currently, either 'p2p-client,p2p-server' " + "or none (meaning all) is supported.") @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 movers operating on a specific PNFS-ID.") @QueryParam("pnfsid") String pnfsid, @ApiParam("Select movers with a specific queue.") @QueryParam("queue") String queue, @ApiParam("Select movers in a particular state.") @QueryParam("state") String state, @ApiParam("Select movers with a specific mode.") @QueryParam("mode") String mode, @ApiParam("Select movers initiated by a specific door.") @QueryParam("door") String door, @ApiParam("Select movers with a specific storage class.") @QueryParam("storageClass") String storageClass, @ApiParam("How returned items should be sorted.") @DefaultValue("door,startTime") @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;
    String[] type = typeList == null ? new String[0] : typeList.split(",");
    PagedList<MoverData> pagedList;
    try {
        if (type.length == 0) {
            pagedList = service.getMovers(pool, offset, limit, pnfsid, queue, state, mode, door, storageClass, sort);
            response.addIntHeader(TOTAL_COUNT_HEADER, pagedList.total);
            return pagedList.contents;
        } else if (type.length == 2) {
            if ((type[0].equals("p2p-client") && type[1].equals("p2p-server")) || (type[1].equals("p2p-client") && type[0].equals("p2p-server"))) {
                pagedList = service.getP2p(pool, offset, limit, pnfsid, queue, state, storageClass, sort);
                response.addIntHeader(TOTAL_COUNT_HEADER, pagedList.total);
                return pagedList.contents;
            }
        }
    } catch (InterruptedException | NoRouteToCellException | CacheException e) {
        LOGGER.warn(Exceptions.meaningfulMessage(e));
        throw new InternalServerErrorException(e);
    }
    String error = String.format(TYPE_ERROR, typeList);
    throw new InternalServerErrorException(error, NOT_IMPLEMENTED);
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) CacheException(diskCacheV111.util.CacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) MoverData(org.dcache.restful.providers.pool.MoverData) 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)

Example 58 with NoRouteToCellException

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

the class PoolInfoResources method updateMode.

@PATCH
@ApiOperation("Modify a pool's mode.  Requires admin role.")
@ApiResponses({ @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code = 403, message = "Pool command only accessible to admin users."), @ApiResponse(code = 500, message = "Internal Server Error") })
@Path("/{pool}/usage/mode")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateMode(@ApiParam(value = "The pool affected by the mode change.", required = true) @PathParam("pool") String pool, @ApiParam(value = "JSON object describing how the " + "pool should be modified. " + "(Corresponds to PoolModeUpdate.)", required = true) String requestPayload) {
    if (!RequestUser.isAdmin()) {
        throw new ForbiddenException("Pool command only accessible to admin users.");
    }
    try {
        PoolModeUpdate update = new ObjectMapper().readValue(requestPayload, PoolModeUpdate.class);
        PoolV2Mode mode = new PoolV2Mode(update.mode());
        mode.setResilienceEnabled(update.isResilience());
        Message message = new PoolModifyModeMessage(pool, mode);
        poolStub.sendAndWait(new CellPath(pool), message);
    } catch (JSONException | IllegalArgumentException | IOException e) {
        throw new BadRequestException(e);
    } catch (InterruptedException | NoRouteToCellException | CacheException e) {
        LOGGER.warn(Exceptions.meaningfulMessage(e));
        throw new InternalServerErrorException(e);
    }
    return successfulResponse(Response.Status.OK);
}
Also used : CellPath(dmg.cells.nucleus.CellPath) ForbiddenException(javax.ws.rs.ForbiddenException) PoolMoverKillMessage(diskCacheV111.vehicles.PoolMoverKillMessage) Message(diskCacheV111.vehicles.Message) PoolModifyModeMessage(diskCacheV111.vehicles.PoolModifyModeMessage) PoolModifyModeMessage(diskCacheV111.vehicles.PoolModifyModeMessage) CacheException(diskCacheV111.util.CacheException) JSONException(org.json.JSONException) IOException(java.io.IOException) PoolV2Mode(diskCacheV111.pools.PoolV2Mode) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) PoolModeUpdate(org.dcache.restful.providers.pool.PoolModeUpdate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) CellPath(dmg.cells.nucleus.CellPath) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PATCH(javax.ws.rs.PATCH) ApiResponses(io.swagger.annotations.ApiResponses)

Example 59 with NoRouteToCellException

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

the class PoolInfoResources method killMovers.

@DELETE
@ApiOperation("Kill a mover.  Requires admin role.")
@ApiResponses({ @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code = 403, message = "Pool command only accessible to admin users."), @ApiResponse(code = 500, message = "Internal Server Error") })
@Path("/{pool}/movers/{id : [0-9]+}")
@Produces(MediaType.APPLICATION_JSON)
public Response killMovers(@ApiParam(value = "The pool with the mover to be killed.", required = true) @PathParam("pool") String pool, @ApiParam(value = "The id of the mover to be killed.", required = true) @PathParam("id") int id) {
    if (!RequestUser.isAdmin()) {
        throw new ForbiddenException("Pool command only accessible to admin users.");
    }
    try {
        poolStub.sendAndWait(new CellPath(pool), new PoolMoverKillMessage(pool, id, "Killed by user."));
        transferInfoService.setCancelled(pool, id);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException(e);
    } catch (CacheException e) {
        if (e.getRc() == CacheException.MOVER_NOT_FOUND) {
            transferInfoService.setCancelled(pool, id);
        } else {
            LOGGER.warn(Exceptions.meaningfulMessage(e));
            throw new InternalServerErrorException(e);
        }
    } catch (InterruptedException | NoRouteToCellException e) {
        LOGGER.warn(Exceptions.meaningfulMessage(e));
        throw new InternalServerErrorException(e);
    }
    return successfulResponse(Response.Status.OK);
}
Also used : CellPath(dmg.cells.nucleus.CellPath) ForbiddenException(javax.ws.rs.ForbiddenException) CacheException(diskCacheV111.util.CacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) PoolMoverKillMessage(diskCacheV111.vehicles.PoolMoverKillMessage) Path(javax.ws.rs.Path) CellPath(dmg.cells.nucleus.CellPath) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 60 with NoRouteToCellException

use of dmg.cells.nucleus.NoRouteToCellException 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

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