use of org.apache.nifi.web.api.entity.ProcessGroupsEntity in project nifi by apache.
the class ProcessGroupsEndpointMerger method merge.
@Override
public final NodeResponse merge(final URI uri, final String method, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final NodeResponse clientResponse) {
if (!canHandle(uri, method)) {
throw new IllegalArgumentException("Cannot use Endpoint Mapper of type " + getClass().getSimpleName() + " to map responses for URI " + uri + ", HTTP Method " + method);
}
final ProcessGroupsEntity responseEntity = clientResponse.getClientResponse().readEntity(ProcessGroupsEntity.class);
final Set<ProcessGroupEntity> processGroupEntities = responseEntity.getProcessGroups();
final Map<String, Map<NodeIdentifier, ProcessGroupEntity>> entityMap = new HashMap<>();
for (final NodeResponse nodeResponse : successfulResponses) {
final ProcessGroupsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(ProcessGroupsEntity.class);
final Set<ProcessGroupEntity> nodeProcessGroupEntities = nodeResponseEntity.getProcessGroups();
for (final ProcessGroupEntity nodeProcessGroupEntity : nodeProcessGroupEntities) {
final NodeIdentifier nodeId = nodeResponse.getNodeId();
Map<NodeIdentifier, ProcessGroupEntity> innerMap = entityMap.get(nodeId);
if (innerMap == null) {
innerMap = new HashMap<>();
entityMap.put(nodeProcessGroupEntity.getId(), innerMap);
}
innerMap.put(nodeResponse.getNodeId(), nodeProcessGroupEntity);
}
}
ProcessGroupsEntityMerger.mergeProcessGroups(processGroupEntities, entityMap);
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
use of org.apache.nifi.web.api.entity.ProcessGroupsEntity in project nifi by apache.
the class ProcessGroupResource method getProcessGroups.
/**
* Retrieves all the processors in this NiFi.
*
* @return A processorsEntity.
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/process-groups")
@ApiOperation(value = "Gets all process groups", response = ProcessGroupsEntity.class, authorizations = { @Authorization(value = "Read - /process-groups/{uuid}") })
@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 getProcessGroups(@ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId) {
if (isReplicateRequest()) {
return replicate(HttpMethod.GET);
}
// authorize access
serviceFacade.authorizeAccess(lookup -> {
final Authorizable processGroup = lookup.getProcessGroup(groupId).getAuthorizable();
processGroup.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
});
// get the process groups
final Set<ProcessGroupEntity> entities = serviceFacade.getProcessGroups(groupId);
// always prune the contents
for (final ProcessGroupEntity entity : entities) {
if (entity.getComponent() != null) {
entity.getComponent().setContents(null);
}
}
// create the response entity
final ProcessGroupsEntity entity = new ProcessGroupsEntity();
entity.setProcessGroups(populateRemainingProcessGroupEntitiesContent(entities));
// generate the response
return generateOkResponse(entity).build();
}
Aggregations