Search in sources :

Example 1 with RemoteProcessGroupStatusEntity

use of org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity in project nifi by apache.

the class EntityFactory method createRemoteProcessGroupStatusEntity.

public RemoteProcessGroupStatusEntity createRemoteProcessGroupStatusEntity(final RemoteProcessGroupStatusDTO status, final PermissionsDTO permissions) {
    final RemoteProcessGroupStatusEntity entity = new RemoteProcessGroupStatusEntity();
    entity.setCanRead(permissions.getCanRead());
    // always set the status, as it's always allowed... just need to provide permission context for merging responses
    entity.setRemoteProcessGroupStatus(status);
    return entity;
}
Also used : RemoteProcessGroupStatusEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity)

Example 2 with RemoteProcessGroupStatusEntity

use of org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity in project nifi by apache.

the class RemoteProcessGroupStatusEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(RemoteProcessGroupStatusEntity clientEntity, Map<NodeIdentifier, RemoteProcessGroupStatusEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final RemoteProcessGroupStatusDTO mergedRemoteProcessGroupStatus = clientEntity.getRemoteProcessGroupStatus();
    mergedRemoteProcessGroupStatus.setNodeSnapshots(new ArrayList<>());
    final NodeIdentifier selectedNodeId = entityMap.entrySet().stream().filter(e -> e.getValue() == clientEntity).map(e -> e.getKey()).findFirst().orElse(null);
    final NodeRemoteProcessGroupStatusSnapshotDTO selectedNodeSnapshot = new NodeRemoteProcessGroupStatusSnapshotDTO();
    selectedNodeSnapshot.setStatusSnapshot(mergedRemoteProcessGroupStatus.getAggregateSnapshot().clone());
    selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress());
    selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort());
    selectedNodeSnapshot.setNodeId(selectedNodeId.getId());
    mergedRemoteProcessGroupStatus.getNodeSnapshots().add(selectedNodeSnapshot);
    // merge the other nodes
    for (final Map.Entry<NodeIdentifier, RemoteProcessGroupStatusEntity> entry : entityMap.entrySet()) {
        final NodeIdentifier nodeId = entry.getKey();
        final RemoteProcessGroupStatusEntity nodeRemoteProcessGroupStatusEntity = entry.getValue();
        final RemoteProcessGroupStatusDTO nodeRemoteProcessGroupStatus = nodeRemoteProcessGroupStatusEntity.getRemoteProcessGroupStatus();
        if (nodeRemoteProcessGroupStatus == mergedRemoteProcessGroupStatus) {
            continue;
        }
        mergeStatus(mergedRemoteProcessGroupStatus, clientEntity.getCanRead(), nodeRemoteProcessGroupStatus, nodeRemoteProcessGroupStatusEntity.getCanRead(), nodeId);
    }
}
Also used : NodeRemoteProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeRemoteProcessGroupStatusSnapshotDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) RemoteProcessGroupStatusEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity) Map(java.util.Map) Set(java.util.Set) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) URI(java.net.URI) Pattern(java.util.regex.Pattern) ComponentEntityStatusMerger(org.apache.nifi.cluster.manager.ComponentEntityStatusMerger) RemoteProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ArrayList(java.util.ArrayList) NodeRemoteProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeRemoteProcessGroupStatusSnapshotDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) RemoteProcessGroupStatusEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity) RemoteProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO) Map(java.util.Map)

Example 3 with RemoteProcessGroupStatusEntity

use of org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity in project nifi by apache.

the class FlowResource method getRemoteProcessGroupStatus.

/**
 * Retrieves the specified remote process group status.
 *
 * @param id The id of the processor history to retrieve.
 * @return A remoteProcessGroupStatusEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("remote-process-groups/{id}/status")
@ApiOperation(value = "Gets status for a remote process group", response = RemoteProcessGroupStatusEntity.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 getRemoteProcessGroupStatus(@ApiParam(value = "Whether or not to include the breakdown per node. Optional, defaults to false", required = false) @QueryParam("nodewise") @DefaultValue(NODEWISE) Boolean nodewise, @ApiParam(value = "The id of the node where to get the status.", required = false) @QueryParam("clusterNodeId") String clusterNodeId, @ApiParam(value = "The remote process group id.", required = true) @PathParam("id") String id) throws InterruptedException {
    authorizeFlow();
    // ensure a valid request
    if (Boolean.TRUE.equals(nodewise) && clusterNodeId != null) {
        throw new IllegalArgumentException("Nodewise requests cannot be directed at a specific node.");
    }
    if (isReplicateRequest()) {
        // determine where this request should be sent
        if (clusterNodeId == null) {
            final NodeResponse nodeResponse = replicateNodeResponse(HttpMethod.GET);
            final RemoteProcessGroupStatusEntity entity = (RemoteProcessGroupStatusEntity) nodeResponse.getUpdatedEntity();
            // ensure there is an updated entity (result of merging) and prune the response as necessary
            if (entity != null && !nodewise) {
                entity.getRemoteProcessGroupStatus().setNodeSnapshots(null);
            }
            return nodeResponse.getResponse();
        } else {
            return replicate(HttpMethod.GET, clusterNodeId);
        }
    }
    // get the specified remote process group status
    final RemoteProcessGroupStatusEntity entity = serviceFacade.getRemoteProcessGroupStatus(id);
    return generateOkResponse(entity).build();
}
Also used : NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) RemoteProcessGroupStatusEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity) 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

RemoteProcessGroupStatusEntity (org.apache.nifi.web.api.entity.RemoteProcessGroupStatusEntity)3 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ComponentEntityStatusMerger (org.apache.nifi.cluster.manager.ComponentEntityStatusMerger)1 StatusMerger (org.apache.nifi.cluster.manager.StatusMerger)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 NodeRemoteProcessGroupStatusSnapshotDTO (org.apache.nifi.web.api.dto.status.NodeRemoteProcessGroupStatusSnapshotDTO)1 RemoteProcessGroupStatusDTO (org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO)1