use of org.apache.nifi.web.api.entity.TemplatesEntity in project nifi by apache.
the class TemplatesEndpointMerger 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 TemplatesEntity responseEntity = clientResponse.getClientResponse().readEntity(getEntityClass());
// Find the templates that all nodes know about. We do this by mapping Template ID to Template and
// then for each node, removing any template whose ID is not known to that node. After iterating over
// all of the nodes, we are left with a Map whose contents are those Templates known by all nodes.
Map<String, TemplateEntity> templatesById = null;
for (final NodeResponse nodeResponse : successfulResponses) {
final TemplatesEntity entity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(TemplatesEntity.class);
final Set<TemplateEntity> templateEntities = entity.getTemplates();
final Map<String, TemplateEntity> nodeTemplatesById = templateEntities.stream().collect(Collectors.toMap(ent -> ent.getId(), ent -> ent));
if (templatesById == null) {
// Create new HashMap so that the map that we have is modifiable.
templatesById = new HashMap<>(nodeTemplatesById);
} else {
// Only keep templates that are known by this node.
templatesById.keySet().retainAll(nodeTemplatesById.keySet());
}
}
// Set the templates to the set of templates that all nodes know about
responseEntity.setTemplates(new HashSet<>(templatesById.values()));
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
use of org.apache.nifi.web.api.entity.TemplatesEntity in project nifi by apache.
the class FlowResource method getTemplates.
// ---------
// templates
// ---------
/**
* Retrieves all the of templates in this NiFi.
*
* @return A templatesEntity.
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("templates")
@ApiOperation(value = "Gets all templates", response = TemplatesEntity.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 = 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 getTemplates() {
if (isReplicateRequest()) {
return replicate(HttpMethod.GET);
}
// authorize access
authorizeFlow();
// get all the templates
final Set<TemplateEntity> templates = serviceFacade.getTemplates();
templateResource.populateRemainingTemplateEntitiesContent(templates);
// create the response entity
final TemplatesEntity entity = new TemplatesEntity();
entity.setTemplates(templates);
entity.setGenerated(new Date());
// generate the response
return generateOkResponse(entity).build();
}
Aggregations