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);
}
}
Aggregations