use of org.apache.geode.rest.internal.web.controllers.support.RestServersResultCollector in project geode by apache.
the class CommonCrudController method servers.
@RequestMapping(method = { RequestMethod.GET }, value = "/servers", produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
@ApiOperation(value = "fetch all REST enabled servers in the DS", notes = "Find all gemfire node where developer REST service is up and running!", response = void.class)
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 401, message = "Invalid Username or Password."), @ApiResponse(code = 403, message = "Insufficient privileges for operation."), @ApiResponse(code = 500, message = "if GemFire throws an error or exception") })
@PreAuthorize("@securityService.authorize('CLUSTER', 'READ')")
public ResponseEntity<?> servers() {
logger.debug("Executing function to get REST enabled gemfire nodes in the DS!");
Execution function;
try {
function = FunctionService.onMembers(getAllMembersInDS());
} catch (FunctionException fe) {
throw new GemfireRestException("Disributed system does not contain any valid data node that can host REST service!", fe);
}
try {
final ResultCollector<?, ?> results = function.withCollector(new RestServersResultCollector()).execute(FindRestEnabledServersFunction.FIND_REST_ENABLED_SERVERS_FUNCTION_ID);
Object functionResult = results.getResult();
if (functionResult instanceof List<?>) {
final HttpHeaders headers = new HttpHeaders();
headers.setLocation(toUri("servers"));
try {
String functionResultAsJson = JSONUtils.convertCollectionToJson((ArrayList<Object>) functionResult);
return new ResponseEntity<>(functionResultAsJson, headers, HttpStatus.OK);
} catch (JSONException e) {
throw new GemfireRestException("Could not convert function results into Restful (JSON) format!", e);
}
} else {
throw new GemfireRestException("Function has returned results that could not be converted into Restful (JSON) format!");
}
} catch (ClassCastException cce) {
throw new GemfireRestException("Key is of an inappropriate type for this region!", cce);
} catch (NullPointerException npe) {
throw new GemfireRestException("Specified key is null and this region does not permit null keys!", npe);
} catch (LowMemoryException lme) {
throw new GemfireRestException("Server has encountered low memory condition!", lme);
} catch (IllegalArgumentException ie) {
throw new GemfireRestException("Input parameter is null! ", ie);
} catch (FunctionException fe) {
throw new GemfireRestException("Server has encountered error while executing the function!", fe);
}
}
Aggregations