Search in sources :

Example 1 with IllegalClusterResourceRequestException

use of org.apache.nifi.web.IllegalClusterResourceRequestException in project nifi by apache.

the class ControllerResource method getCluster.

// -------
// cluster
// -------
/**
 * Gets the contents of this NiFi cluster. This includes all nodes and their status.
 *
 * @return A clusterEntity
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("cluster")
@ApiOperation(value = "Gets the contents of the cluster", notes = "Returns the contents of the cluster including all nodes and their status.", response = ClusterEntity.class, authorizations = { @Authorization(value = "Read - /controller") })
@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 = 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 getCluster() {
    authorizeController(RequestAction.READ);
    // ensure connected to the cluster
    if (!isConnectedToCluster()) {
        throw new IllegalClusterResourceRequestException("Only a node connected to a cluster can process the request.");
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET, getClusterCoordinatorNode());
    }
    final ClusterDTO dto = serviceFacade.getCluster();
    // create entity
    final ClusterEntity entity = new ClusterEntity();
    entity.setCluster(dto);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : IllegalClusterResourceRequestException(org.apache.nifi.web.IllegalClusterResourceRequestException) ClusterDTO(org.apache.nifi.web.api.dto.ClusterDTO) ClusterEntity(org.apache.nifi.web.api.entity.ClusterEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with IllegalClusterResourceRequestException

use of org.apache.nifi.web.IllegalClusterResourceRequestException in project nifi by apache.

the class ControllerResource method getNode.

/**
 * Gets the contents of the specified node in this NiFi cluster.
 *
 * @param id The node id.
 * @return A nodeEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("cluster/nodes/{id}")
@ApiOperation(value = "Gets a node in the cluster", response = NodeEntity.class, authorizations = { @Authorization(value = "Read - /controller") })
@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 getNode(@ApiParam(value = "The node id.", required = true) @PathParam("id") String id) {
    authorizeController(RequestAction.READ);
    // ensure connected to the cluster
    if (!isConnectedToCluster()) {
        throw new IllegalClusterResourceRequestException("Only a node connected to a cluster can process the request.");
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET, getClusterCoordinatorNode());
    }
    // get the specified relationship
    final NodeDTO dto = serviceFacade.getNode(id);
    // create the response entity
    final NodeEntity entity = new NodeEntity();
    entity.setNode(dto);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : IllegalClusterResourceRequestException(org.apache.nifi.web.IllegalClusterResourceRequestException) NodeDTO(org.apache.nifi.web.api.dto.NodeDTO) NodeEntity(org.apache.nifi.web.api.entity.NodeEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with IllegalClusterResourceRequestException

use of org.apache.nifi.web.IllegalClusterResourceRequestException in project nifi by apache.

the class ControllerResource method updateNode.

/**
 * Updates the contents of the specified node in this NiFi cluster.
 *
 * @param id         The id of the node
 * @param nodeEntity A nodeEntity
 * @return A nodeEntity
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("cluster/nodes/{id}")
@ApiOperation(value = "Updates a node in the cluster", response = NodeEntity.class, authorizations = { @Authorization(value = "Write - /controller") })
@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 updateNode(@ApiParam(value = "The node id.", required = true) @PathParam("id") String id, @ApiParam(value = "The node configuration. The only configuration that will be honored at this endpoint is the status.", required = true) NodeEntity nodeEntity) {
    authorizeController(RequestAction.WRITE);
    // ensure connected to the cluster
    if (!isConnectedToCluster()) {
        throw new IllegalClusterResourceRequestException("Only a node connected to a cluster can process the request.");
    }
    if (nodeEntity == null || nodeEntity.getNode() == null) {
        throw new IllegalArgumentException("Node details must be specified.");
    }
    // get the request node
    final NodeDTO requestNodeDTO = nodeEntity.getNode();
    if (!id.equals(requestNodeDTO.getNodeId())) {
        throw new IllegalArgumentException(String.format("The node id (%s) in the request body does " + "not equal the node id of the requested resource (%s).", requestNodeDTO.getNodeId(), id));
    }
    if (isReplicateRequest()) {
        return replicateToCoordinator(HttpMethod.PUT, nodeEntity);
    }
    // update the node
    final NodeDTO node = serviceFacade.updateNode(requestNodeDTO);
    // create the response entity
    NodeEntity entity = new NodeEntity();
    entity.setNode(node);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : IllegalClusterResourceRequestException(org.apache.nifi.web.IllegalClusterResourceRequestException) NodeDTO(org.apache.nifi.web.api.dto.NodeDTO) NodeEntity(org.apache.nifi.web.api.entity.NodeEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with IllegalClusterResourceRequestException

use of org.apache.nifi.web.IllegalClusterResourceRequestException in project nifi by apache.

the class ControllerResource method deleteNode.

/**
 * Removes the specified from this NiFi cluster.
 *
 * @param id The id of the node
 * @return A nodeEntity
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("cluster/nodes/{id}")
@ApiOperation(value = "Removes a node from the cluster", response = NodeEntity.class, authorizations = { @Authorization(value = "Write - /controller") })
@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 deleteNode(@ApiParam(value = "The node id.", required = true) @PathParam("id") String id) {
    authorizeController(RequestAction.WRITE);
    // ensure connected to the cluster
    if (!isConnectedToCluster()) {
        throw new IllegalClusterResourceRequestException("Only a node connected to a cluster can process the request.");
    }
    if (isReplicateRequest()) {
        return replicateToCoordinator(HttpMethod.DELETE, getRequestParameters());
    }
    serviceFacade.deleteNode(id);
    // create the response entity
    final NodeEntity entity = new NodeEntity();
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : IllegalClusterResourceRequestException(org.apache.nifi.web.IllegalClusterResourceRequestException) NodeEntity(org.apache.nifi.web.api.entity.NodeEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with IllegalClusterResourceRequestException

use of org.apache.nifi.web.IllegalClusterResourceRequestException 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();
}
Also used : ClusterSearchResultsEntity(org.apache.nifi.web.api.entity.ClusterSearchResultsEntity) IllegalClusterResourceRequestException(org.apache.nifi.web.IllegalClusterResourceRequestException) NodeSearchResultDTO(org.apache.nifi.web.api.dto.search.NodeSearchResultDTO) ClusterDTO(org.apache.nifi.web.api.dto.ClusterDTO) ArrayList(java.util.ArrayList) NodeDTO(org.apache.nifi.web.api.dto.NodeDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 IllegalClusterResourceRequestException (org.apache.nifi.web.IllegalClusterResourceRequestException)5 GET (javax.ws.rs.GET)3 NodeDTO (org.apache.nifi.web.api.dto.NodeDTO)3 NodeEntity (org.apache.nifi.web.api.entity.NodeEntity)3 ClusterDTO (org.apache.nifi.web.api.dto.ClusterDTO)2 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1 PUT (javax.ws.rs.PUT)1 NodeSearchResultDTO (org.apache.nifi.web.api.dto.search.NodeSearchResultDTO)1 ClusterEntity (org.apache.nifi.web.api.entity.ClusterEntity)1 ClusterSearchResultsEntity (org.apache.nifi.web.api.entity.ClusterSearchResultsEntity)1