use of org.apache.nifi.web.api.dto.search.NodeSearchResultDTO in project nifi by apache.
the class FlowResource method searchCluster.
// --------------------
// search cluster nodes
// --------------------
/**
* Searches the cluster for a node with a given address.
*
* @param value Search value that will be matched against a node's address
* @return Nodes that match the specified criteria
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("cluster/search-results")
@ApiOperation(value = "Searches the cluster for a node with the specified address", notes = NON_GUARANTEED_ENDPOINT, response = ClusterSearchResultsEntity.class, authorizations = { @Authorization(value = "Read - /flow") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response searchCluster(@ApiParam(value = "Node address to search for.", required = true) @QueryParam("q") @DefaultValue(StringUtils.EMPTY) String value) {
authorizeFlow();
// ensure connected to the cluster
if (!isConnectedToCluster()) {
throw new IllegalClusterResourceRequestException("Only a node connected to a cluster can process the request.");
}
final List<NodeSearchResultDTO> nodeMatches = new ArrayList<>();
// get the nodes in the cluster
final ClusterDTO cluster = serviceFacade.getCluster();
// check each to see if it matches the search term
for (NodeDTO node : cluster.getNodes()) {
// ensure the node is connected
if (!NodeConnectionState.CONNECTED.name().equals(node.getStatus())) {
continue;
}
// determine the current nodes address
final String address = node.getAddress() + ":" + node.getApiPort();
// count the node if there is no search or it matches the address
if (StringUtils.isBlank(value) || StringUtils.containsIgnoreCase(address, value)) {
final NodeSearchResultDTO nodeMatch = new NodeSearchResultDTO();
nodeMatch.setId(node.getNodeId());
nodeMatch.setAddress(address);
nodeMatches.add(nodeMatch);
}
}
// build the response
ClusterSearchResultsEntity results = new ClusterSearchResultsEntity();
results.setNodeResults(nodeMatches);
// generate an 200 - OK response
return noCache(Response.ok(results)).build();
}
Aggregations