Search in sources :

Example 1 with ConnectionStatusEntity

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);
    }
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Map(java.util.Map) Set(java.util.Set) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) ConnectionStatusDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusDTO) URI(java.net.URI) Pattern(java.util.regex.Pattern) NodeConnectionStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeConnectionStatusSnapshotDTO) ComponentEntityStatusMerger(org.apache.nifi.cluster.manager.ComponentEntityStatusMerger) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ArrayList(java.util.ArrayList) NodeConnectionStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.NodeConnectionStatusSnapshotDTO) ConnectionStatusDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Map(java.util.Map)

Example 2 with ConnectionStatusEntity

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;
}
Also used : UploadProgressService(com.thinkbiganalytics.feedmgr.service.UploadProgressService) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) LoggerFactory(org.slf4j.LoggerFactory) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) StringUtils(org.apache.commons.lang3.StringUtils) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) NifiFlowUtil(com.thinkbiganalytics.nifi.rest.support.NifiFlowUtil) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) ReusableTemplateCreationCallback(com.thinkbiganalytics.nifi.feedmgr.ReusableTemplateCreationCallback) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) RegisteredTemplateCache(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateCache) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ImportTemplateOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportTemplateOptions) Optional(java.util.Optional) NiFiTemplateImport(com.thinkbiganalytics.feedmgr.service.template.importing.model.NiFiTemplateImport) ImportComponent(com.thinkbiganalytics.feedmgr.rest.ImportComponent) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) HashMap(java.util.HashMap) ImportSection(com.thinkbiganalytics.feedmgr.rest.ImportSection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Nullable(javax.annotation.Nullable) NiFiClusterSummary(com.thinkbiganalytics.nifi.rest.model.NiFiClusterSummary) Logger(org.slf4j.Logger) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) TemplateRemoteInputPortConnections(com.thinkbiganalytics.feedmgr.rest.model.TemplateRemoteInputPortConnections) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) TemplateRemoteInputPortConnections(com.thinkbiganalytics.feedmgr.rest.model.TemplateRemoteInputPortConnections) HashSet(java.util.HashSet)

Example 3 with ConnectionStatusEntity

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();
}
Also used : NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with ConnectionStatusEntity

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;
}
Also used : ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity)

Aggregations

ConnectionStatusEntity (org.apache.nifi.web.api.entity.ConnectionStatusEntity)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Set (java.util.Set)2 PropertyExpressionResolver (com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver)1 TemplateConnectionUtil (com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil)1 NifiFlowCache (com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache)1 ImportComponent (com.thinkbiganalytics.feedmgr.rest.ImportComponent)1 ImportSection (com.thinkbiganalytics.feedmgr.rest.ImportSection)1 ImportComponentOption (com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)1 ImportTemplateOptions (com.thinkbiganalytics.feedmgr.rest.model.ImportTemplateOptions)1 RemoteProcessGroupInputPort (com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort)1 ReusableTemplateConnectionInfo (com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)1 TemplateRemoteInputPortConnections (com.thinkbiganalytics.feedmgr.rest.model.TemplateRemoteInputPortConnections)1 UploadProgressMessage (com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage)1 UploadProgressService (com.thinkbiganalytics.feedmgr.service.UploadProgressService)1 RegisteredTemplateCache (com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateCache)1 RegisteredTemplateService (com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService)1 ImportTemplate (com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate)1 NiFiTemplateImport (com.thinkbiganalytics.feedmgr.service.template.importing.model.NiFiTemplateImport)1