Search in sources :

Example 1 with PreferenceResult

use of org.dcache.restful.providers.selection.PreferenceResult in project dcache by dCache.

the class PoolPreferenceResources method match.

@GET
@ApiOperation("Describe the pools selected by a particular request.")
@ApiResponses({ @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code = 500, message = "Internal Server Error") })
@Produces(MediaType.APPLICATION_JSON)
public List<PreferenceResult> match(@ApiParam(value = "The operation type.", allowableValues = "READ,CACHE,WRITE,P2P,ANY") @DefaultValue("READ") @QueryParam("type") String type, @ApiParam("The name of the matching store unit.") @DefaultValue("*") @QueryParam("store") String store, @ApiParam("The name of the matching dcache unit.") @DefaultValue("*") @QueryParam("dcache") String dcache, @DefaultValue("*") @ApiParam("The name of the matching net unit.") @QueryParam("net") String net, @DefaultValue("*") @ApiParam("The matching protocol unit.") @QueryParam("protocol") String protocol, @ApiParam("The linkgroup unit, or 'none' for a request outside of a linkgroup.") @DefaultValue("none") @QueryParam("linkGroup") String linkGroup) {
    try {
        String command = "psux match " + type + " " + store + " " + dcache + " " + net + " " + protocol + (linkGroup.equals("none") ? "" : " -linkGroup=" + linkGroup);
        PoolPreferenceLevel[] poolPreferenceLevels = poolManager.sendAndWait(command, PoolPreferenceLevel[].class);
        List<PreferenceResult> results = new ArrayList<>();
        for (PoolPreferenceLevel level : poolPreferenceLevels) {
            results.add(new PreferenceResult(level));
        }
        return results;
    } catch (JSONException | IllegalArgumentException e) {
        throw new BadRequestException(e);
    } catch (CacheException | InterruptedException | NoRouteToCellException e) {
        LOGGER.warn(Exceptions.meaningfulMessage(e));
        throw new InternalServerErrorException(e);
    }
}
Also used : PoolPreferenceLevel(diskCacheV111.poolManager.PoolPreferenceLevel) CacheException(diskCacheV111.util.CacheException) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) PreferenceResult(org.dcache.restful.providers.selection.PreferenceResult) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

PoolPreferenceLevel (diskCacheV111.poolManager.PoolPreferenceLevel)1 CacheException (diskCacheV111.util.CacheException)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 GET (javax.ws.rs.GET)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 Produces (javax.ws.rs.Produces)1 PreferenceResult (org.dcache.restful.providers.selection.PreferenceResult)1 JSONException (org.json.JSONException)1