use of org.apache.nifi.web.api.entity.FunnelEntity in project nifi by apache.
the class FlowMerger method mergeResponses.
@Override
protected void mergeResponses(final ProcessGroupFlowDTO clientDto, final Map<NodeIdentifier, ProcessGroupFlowDTO> dtoMap, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses) {
final FlowDTO flowDto = clientDto.getFlow();
final Set<ConnectionEntity> clientConnections = flowDto.getConnections();
final Set<ProcessorEntity> clientProcessors = flowDto.getProcessors();
final Set<PortEntity> clientInputPorts = flowDto.getInputPorts();
final Set<PortEntity> clientOutputPorts = flowDto.getOutputPorts();
final Set<RemoteProcessGroupEntity> clientRemoteProcessGroups = flowDto.getRemoteProcessGroups();
final Set<ProcessGroupEntity> clientProcessGroups = flowDto.getProcessGroups();
final Set<LabelEntity> clientLabels = flowDto.getLabels();
final Set<FunnelEntity> clientFunnels = flowDto.getFunnels();
final Map<String, Map<NodeIdentifier, ConnectionEntity>> connections = new HashMap<>();
final Map<String, Map<NodeIdentifier, FunnelEntity>> funnels = new HashMap<>();
final Map<String, Map<NodeIdentifier, PortEntity>> inputPorts = new HashMap<>();
final Map<String, Map<NodeIdentifier, LabelEntity>> labels = new HashMap<>();
final Map<String, Map<NodeIdentifier, PortEntity>> outputPorts = new HashMap<>();
final Map<String, Map<NodeIdentifier, ProcessorEntity>> processors = new HashMap<>();
final Map<String, Map<NodeIdentifier, RemoteProcessGroupEntity>> rpgs = new HashMap<>();
final Map<String, Map<NodeIdentifier, ProcessGroupEntity>> processGroups = new HashMap<>();
// Create mapping of ComponentID -> [nodeId, entity on that node]
for (final Map.Entry<NodeIdentifier, ProcessGroupFlowDTO> nodeGroupFlowEntry : dtoMap.entrySet()) {
final NodeIdentifier nodeIdentifier = nodeGroupFlowEntry.getKey();
final ProcessGroupFlowDTO nodeGroupFlowDto = nodeGroupFlowEntry.getValue();
final FlowDTO nodeFlowDto = nodeGroupFlowDto.getFlow();
// Merge connection statuses
for (final ConnectionEntity entity : nodeFlowDto.getConnections()) {
connections.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final FunnelEntity entity : nodeFlowDto.getFunnels()) {
funnels.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final PortEntity entity : nodeFlowDto.getInputPorts()) {
inputPorts.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final PortEntity entity : nodeFlowDto.getOutputPorts()) {
outputPorts.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final LabelEntity entity : nodeFlowDto.getLabels()) {
labels.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final ProcessorEntity entity : nodeFlowDto.getProcessors()) {
processors.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final RemoteProcessGroupEntity entity : nodeFlowDto.getRemoteProcessGroups()) {
rpgs.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final ProcessGroupEntity entity : nodeFlowDto.getProcessGroups()) {
processGroups.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
}
//
// Merge the components that are grouped together by ID
//
// Merge connections
ConnectionsEntityMerger.mergeConnections(clientConnections, connections);
// Merge funnel statuses
FunnelsEntityMerger.mergeFunnels(clientFunnels, funnels);
// Merge input ports
PortsEntityMerger.mergePorts(clientInputPorts, inputPorts);
// Merge output ports
PortsEntityMerger.mergePorts(clientOutputPorts, outputPorts);
// Merge labels
LabelsEntityMerger.mergeLabels(clientLabels, labels);
// Merge processors
ProcessorsEntityMerger.mergeProcessors(clientProcessors, processors);
// Merge Remote Process Groups
RemoteProcessGroupsEntityMerger.mergeRemoteProcessGroups(clientRemoteProcessGroups, rpgs);
// Merge Process Groups
ProcessGroupsEntityMerger.mergeProcessGroups(clientProcessGroups, processGroups);
}
use of org.apache.nifi.web.api.entity.FunnelEntity in project nifi by apache.
the class FunnelsEndpointMerger method merge.
@Override
public NodeResponse merge(URI uri, String method, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses, 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 FunnelsEntity responseEntity = clientResponse.getClientResponse().readEntity(FunnelsEntity.class);
final Set<FunnelEntity> funnelEntities = responseEntity.getFunnels();
final Map<String, Map<NodeIdentifier, FunnelEntity>> entityMap = new HashMap<>();
for (final NodeResponse nodeResponse : successfulResponses) {
final FunnelsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(FunnelsEntity.class);
final Set<FunnelEntity> nodeFunnelEntities = nodeResponseEntity.getFunnels();
for (final FunnelEntity nodeFunnelEntity : nodeFunnelEntities) {
final String nodeFunnelEntityId = nodeFunnelEntity.getId();
Map<NodeIdentifier, FunnelEntity> innerMap = entityMap.get(nodeFunnelEntityId);
if (innerMap == null) {
innerMap = new HashMap<>();
entityMap.put(nodeFunnelEntityId, innerMap);
}
innerMap.put(nodeResponse.getNodeId(), nodeFunnelEntity);
}
}
FunnelsEntityMerger.mergeFunnels(funnelEntities, entityMap);
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
use of org.apache.nifi.web.api.entity.FunnelEntity in project nifi by apache.
the class FunnelResource method updateFunnel.
/**
* Creates a new Funnel.
*
* @param httpServletRequest request
* @param id The id of the funnel to update.
* @param requestFunnelEntity A funnelEntity.
* @return A funnelEntity.
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Updates a funnel", response = FunnelEntity.class, authorizations = { @Authorization(value = "Write - /funnels/{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 updateFunnel(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The funnel id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The funnel configuration details.", required = true) final FunnelEntity requestFunnelEntity) {
if (requestFunnelEntity == null || requestFunnelEntity.getComponent() == null) {
throw new IllegalArgumentException("Funnel details must be specified.");
}
if (requestFunnelEntity.getRevision() == null) {
throw new IllegalArgumentException("Revision must be specified.");
}
// ensure the ids are the same
final FunnelDTO requestFunnelDTO = requestFunnelEntity.getComponent();
if (!id.equals(requestFunnelDTO.getId())) {
throw new IllegalArgumentException(String.format("The funnel id (%s) in the request body does not equal the " + "funnel id of the requested resource (%s).", requestFunnelDTO.getId(), id));
}
final PositionDTO proposedPosition = requestFunnelDTO.getPosition();
if (proposedPosition != null) {
if (proposedPosition.getX() == null || proposedPosition.getY() == null) {
throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified.");
}
}
if (isReplicateRequest()) {
return replicate(HttpMethod.PUT, requestFunnelEntity);
}
// Extract the revision
final Revision requestRevision = getRevision(requestFunnelEntity, id);
return withWriteLock(serviceFacade, requestFunnelEntity, requestRevision, lookup -> {
Authorizable authorizable = lookup.getFunnel(id);
authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
}, null, (revision, funnelEntity) -> {
// update the funnel
final FunnelEntity entity = serviceFacade.updateFunnel(revision, funnelEntity.getComponent());
populateRemainingFunnelEntityContent(entity);
return generateOkResponse(entity).build();
});
}
use of org.apache.nifi.web.api.entity.FunnelEntity in project nifi by apache.
the class FunnelResource method getFunnel.
/**
* Retrieves the specified funnel.
*
* @param id The id of the funnel to retrieve
* @return A funnelEntity.
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Gets a funnel", response = FunnelEntity.class, authorizations = { @Authorization(value = "Read - /funnels/{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 getFunnel(@ApiParam(value = "The funnel id.", required = true) @PathParam("id") final String id) {
if (isReplicateRequest()) {
return replicate(HttpMethod.GET);
}
// authorize access
serviceFacade.authorizeAccess(lookup -> {
final Authorizable funnel = lookup.getFunnel(id);
funnel.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
});
// get the funnel
final FunnelEntity entity = serviceFacade.getFunnel(id);
populateRemainingFunnelEntityContent(entity);
return generateOkResponse(entity).build();
}
use of org.apache.nifi.web.api.entity.FunnelEntity in project nifi by apache.
the class FunnelResource method removeFunnel.
/**
* Removes the specified funnel.
*
* @param httpServletRequest request
* @param version The revision is used to verify the client is working with
* the latest version of the flow.
* @param clientId Optional client id. If the client id is not specified, a
* new one will be generated. This value (whether specified or generated) is
* included in the response.
* @param id The id of the funnel to remove.
* @return A entity containing the client id and an updated revision.
*/
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Deletes a funnel", response = FunnelEntity.class, authorizations = { @Authorization(value = "Write - /funnels/{uuid}"), @Authorization(value = "Write - Parent Process Group - /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 removeFunnel(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The revision is used to verify the client is working with the latest version of the flow.", required = false) @QueryParam(VERSION) final LongParameter version, @ApiParam(value = "If the client id is not specified, new one will be generated. This value (whether specified or generated) is included in the response.", required = false) @QueryParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) final ClientIdParameter clientId, @ApiParam(value = "The funnel id.", required = true) @PathParam("id") final String id) {
if (isReplicateRequest()) {
return replicate(HttpMethod.DELETE);
}
final FunnelEntity requestFunnelEntity = new FunnelEntity();
requestFunnelEntity.setId(id);
// handle expects request (usually from the cluster manager)
final Revision requestRevision = new Revision(version == null ? null : version.getLong(), clientId.getClientId(), id);
return withWriteLock(serviceFacade, requestFunnelEntity, requestRevision, lookup -> {
final Authorizable funnel = lookup.getFunnel(id);
// ensure write permission to the funnel
funnel.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
// ensure write permission to the parent process group
funnel.getParentAuthorizable().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
}, () -> serviceFacade.verifyDeleteFunnel(id), (revision, funnelEntity) -> {
// delete the specified funnel
final FunnelEntity entity = serviceFacade.deleteFunnel(revision, funnelEntity.getId());
return generateOkResponse(entity).build();
});
}
Aggregations