use of org.apache.nifi.web.api.entity.ConnectionStatusEntity in project nifi by apache.
the class ConnectionStatusEndpointMerger method mergeResponses.
@Override
protected void mergeResponses(ConnectionStatusEntity clientEntity, Map<NodeIdentifier, ConnectionStatusEntity> entityMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
final ConnectionStatusDTO mergedConnectionStatus = clientEntity.getConnectionStatus();
mergedConnectionStatus.setNodeSnapshots(new ArrayList<>());
final NodeIdentifier selectedNodeId = entityMap.entrySet().stream().filter(e -> e.getValue() == clientEntity).map(e -> e.getKey()).findFirst().orElse(null);
final NodeConnectionStatusSnapshotDTO selectedNodeSnapshot = new NodeConnectionStatusSnapshotDTO();
selectedNodeSnapshot.setStatusSnapshot(mergedConnectionStatus.getAggregateSnapshot().clone());
selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress());
selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort());
selectedNodeSnapshot.setNodeId(selectedNodeId.getId());
mergedConnectionStatus.getNodeSnapshots().add(selectedNodeSnapshot);
// merge the other nodes
for (final Map.Entry<NodeIdentifier, ConnectionStatusEntity> entry : entityMap.entrySet()) {
final NodeIdentifier nodeId = entry.getKey();
final ConnectionStatusEntity nodeConnectionStatusEntity = entry.getValue();
final ConnectionStatusDTO nodeConnectionStatus = nodeConnectionStatusEntity.getConnectionStatus();
if (nodeConnectionStatus == mergedConnectionStatus) {
continue;
}
mergeStatus(mergedConnectionStatus, clientEntity.getCanRead(), nodeConnectionStatus, nodeConnectionStatusEntity.getCanRead(), nodeId);
}
}
use of org.apache.nifi.web.api.entity.ConnectionStatusEntity in project kylo by Teradata.
the class ImportReusableTemplate method removeConnectionsAndInputs.
private boolean removeConnectionsAndInputs() {
Optional<TemplateRemoteInputPortConnections> existingRemoteProcessInputPortInformation = getExistingRemoteProcessInputPortInformation();
if (existingRemoteProcessInputPortInformation.isPresent()) {
// find the input ports that are 'existing' but not 'selected' . These should be deleted
Set<String> inputPortNamesToRemove = remoteProcessGroupInputPortMap.values().stream().filter((remoteInputPort -> !remoteInputPort.isSelected() && existingRemoteProcessInputPortInformation.get().getExistingRemoteInputPortNames().contains(remoteInputPort.getInputPortName()))).map(remoteInputPort -> remoteInputPort.getInputPortName()).collect(Collectors.toSet());
// Find the connections that match the input ports that are to be removed
Set<ConnectionDTO> connectionsToRemove = existingRemoteProcessInputPortInformation.get().getExistingRemoteConnectionsToTemplate().stream().filter(connectionDTO -> inputPortNamesToRemove.contains(connectionDTO.getSource().getName())).collect(Collectors.toSet());
log.info("Removing input ports {}", inputPortNamesToRemove);
Set<ConnectionDTO> connectionsWithQueue = new HashSet<>();
// first validate the queues are empty ... if not warn user the following ports cant be deleted and rollback
connectionsToRemove.stream().forEach(connection -> {
Optional<ConnectionStatusEntity> connectionStatus = nifiRestClient.getNiFiRestClient().connections().getConnectionStatus(connection.getId());
if (connectionStatus.isPresent() && connectionStatus.get().getConnectionStatus().getAggregateSnapshot().getFlowFilesQueued() > 0) {
connectionsWithQueue.add(connection);
}
});
if (!connectionsWithQueue.isEmpty()) {
UploadProgressMessage importStatusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Unable to remove inputPort and connection for :" + connectionsWithQueue.stream().map(c -> c.getSource().getName()).collect(Collectors.joining(",")) + ". The Queues are not empty. Failed to import template: " + importTemplate.getTemplateName(), true, false);
importTemplate.setValid(false);
importTemplate.setSuccess(false);
return false;
} else {
connectionsToRemove.stream().forEach(connection -> {
nifiRestClient.deleteConnection(connection, false);
getItemsCreated().addDeletedRemoteInputPortConnection(connection);
try {
PortDTO deletedPort = nifiRestClient.getNiFiRestClient().ports().deleteInputPort(connection.getSource().getId());
if (deletedPort != null) {
getItemsCreated().addDeletedRemoteInputPort(deletedPort);
}
} catch (NifiComponentNotFoundException e) {
// this is ok to catch as its deleted already
}
});
UploadProgressMessage importStatusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Removed inputPort and connection for :" + connectionsToRemove.stream().map(c -> c.getSource().getName()).collect(Collectors.joining(",")) + " for template: " + importTemplate.getTemplateName(), true, true);
}
return true;
}
return true;
}
use of org.apache.nifi.web.api.entity.ConnectionStatusEntity in project nifi by apache.
the class FlowResource method getConnectionStatus.
/**
* Retrieves the specified connection status.
*
* @param id The id of the connection history to retrieve.
* @return A connectionStatusEntity.
* @throws InterruptedException if interrupted
*/
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("connections/{id}/status")
@ApiOperation(value = "Gets status for a connection", response = ConnectionStatusEntity.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 getConnectionStatus(@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 connection 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 ConnectionStatusEntity entity = (ConnectionStatusEntity) nodeResponse.getUpdatedEntity();
// ensure there is an updated entity (result of merging) and prune the response as necessary
if (entity != null && !nodewise) {
entity.getConnectionStatus().setNodeSnapshots(null);
}
return nodeResponse.getResponse();
} else {
return replicate(HttpMethod.GET, clusterNodeId);
}
}
// get the specified connection status
final ConnectionStatusEntity entity = serviceFacade.getConnectionStatus(id);
return generateOkResponse(entity).build();
}
use of org.apache.nifi.web.api.entity.ConnectionStatusEntity in project nifi by apache.
the class EntityFactory method createConnectionStatusEntity.
public ConnectionStatusEntity createConnectionStatusEntity(final ConnectionStatusDTO status, final PermissionsDTO permissions) {
final ConnectionStatusEntity entity = new ConnectionStatusEntity();
entity.setCanRead(permissions.getCanRead());
// always set the status, as it's always allowed... just need to provide permission context for merging responses
entity.setConnectionStatus(status);
return entity;
}
Aggregations