use of org.apache.nifi.web.api.entity.PortEntity in project kylo by Teradata.
the class NiFiProcessGroupsRestClientV1 method createOutputPort.
@Nonnull
@Override
public PortDTO createOutputPort(@Nonnull final String processGroupId, @Nonnull final PortDTO outputPort) {
final PortEntity entity = new PortEntity();
entity.setComponent(outputPort);
final RevisionDTO revision = new RevisionDTO();
revision.setVersion(0L);
entity.setRevision(revision);
try {
return client.post(BASE_PATH + processGroupId + "/output-ports", entity, PortEntity.class).getComponent();
} catch (final NotFoundException e) {
throw new NifiComponentNotFoundException(processGroupId, NifiConstants.NIFI_COMPONENT_TYPE.PROCESS_GROUP, e);
}
}
use of org.apache.nifi.web.api.entity.PortEntity in project nifi by apache.
the class StandardNiFiServiceFacade method updateInputPort.
@Override
public PortEntity updateInputPort(final Revision revision, final PortDTO inputPortDTO) {
final Port inputPortNode = inputPortDAO.getPort(inputPortDTO.getId());
final RevisionUpdate<PortDTO> snapshot = updateComponent(revision, inputPortNode, () -> inputPortDAO.updatePort(inputPortDTO), port -> dtoFactory.createPortDto(port));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(inputPortNode);
final PortStatusDTO status = dtoFactory.createPortStatusDto(controllerFacade.getInputPortStatus(inputPortNode.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(inputPortNode.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
return entityFactory.createPortEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
}
use of org.apache.nifi.web.api.entity.PortEntity in project nifi by apache.
the class PortEntityMerger method mergeComponents.
/**
* Merges the PortEntity responses.
*
* @param clientEntity the entity being returned to the client
* @param entityMap all node responses
*/
@Override
public void mergeComponents(PortEntity clientEntity, Map<NodeIdentifier, PortEntity> entityMap) {
final PortDTO clientDto = clientEntity.getComponent();
final Map<NodeIdentifier, PortDTO> dtoMap = new HashMap<>();
for (final Map.Entry<NodeIdentifier, PortEntity> entry : entityMap.entrySet()) {
final PortEntity nodePortEntity = entry.getValue();
final PortDTO nodePortDto = nodePortEntity.getComponent();
dtoMap.put(entry.getKey(), nodePortDto);
}
mergeDtos(clientDto, dtoMap);
}
use of org.apache.nifi.web.api.entity.PortEntity in project nifi by apache.
the class InputPortsEndpointMerger 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 InputPortsEntity responseEntity = clientResponse.getClientResponse().readEntity(InputPortsEntity.class);
final Set<PortEntity> portEntities = responseEntity.getInputPorts();
final Map<String, Map<NodeIdentifier, PortEntity>> entityMap = new HashMap<>();
for (final NodeResponse nodeResponse : successfulResponses) {
final InputPortsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(InputPortsEntity.class);
final Set<PortEntity> nodePortEntities = nodeResponseEntity.getInputPorts();
for (final PortEntity nodePortEntity : nodePortEntities) {
final NodeIdentifier nodeId = nodeResponse.getNodeId();
Map<NodeIdentifier, PortEntity> innerMap = entityMap.get(nodeId);
if (innerMap == null) {
innerMap = new HashMap<>();
entityMap.put(nodePortEntity.getId(), innerMap);
}
innerMap.put(nodeResponse.getNodeId(), nodePortEntity);
}
}
PortsEntityMerger.mergePorts(portEntities, entityMap);
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
use of org.apache.nifi.web.api.entity.PortEntity in project nifi by apache.
the class InputPortResource method removeInputPort.
/**
* Removes the specified input port.
*
* @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 input port to remove.
* @return A inputPortEntity.
*/
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Deletes an input port", response = PortEntity.class, authorizations = { @Authorization(value = "Write - /input-ports/{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 removeInputPort(@Context 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 input port id.", required = true) @PathParam("id") final String id) {
if (isReplicateRequest()) {
return replicate(HttpMethod.DELETE);
}
final PortEntity requestPortEntity = new PortEntity();
requestPortEntity.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, requestPortEntity, requestRevision, lookup -> {
final Authorizable inputPort = lookup.getInputPort(id);
// ensure write permission to the input port
inputPort.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
// ensure write permission to the parent process group
inputPort.getParentAuthorizable().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
}, () -> serviceFacade.verifyDeleteInputPort(id), (revision, portEntity) -> {
// delete the specified input port
final PortEntity entity = serviceFacade.deleteInputPort(revision, portEntity.getId());
return generateOkResponse(entity).build();
});
}
Aggregations