Search in sources :

Example 26 with Connectable

use of org.apache.nifi.connectable.Connectable in project nifi by apache.

the class StandardProcessSession method updateEventRepository.

private void updateEventRepository(final Checkpoint checkpoint) {
    int flowFilesReceived = 0;
    int flowFilesSent = 0;
    long bytesReceived = 0L;
    long bytesSent = 0L;
    for (final ProvenanceEventRecord event : checkpoint.reportedEvents) {
        if (isSpuriousForkEvent(event, checkpoint.removedFlowFiles)) {
            continue;
        }
        switch(event.getEventType()) {
            case SEND:
                flowFilesSent++;
                bytesSent += event.getFileSize();
                break;
            case RECEIVE:
            case FETCH:
                flowFilesReceived++;
                bytesReceived += event.getFileSize();
                break;
            default:
                break;
        }
    }
    try {
        // update event repository
        final Connectable connectable = context.getConnectable();
        final StandardFlowFileEvent flowFileEvent = new StandardFlowFileEvent(connectable.getIdentifier());
        flowFileEvent.setBytesRead(checkpoint.bytesRead);
        flowFileEvent.setBytesWritten(checkpoint.bytesWritten);
        flowFileEvent.setContentSizeIn(checkpoint.contentSizeIn);
        flowFileEvent.setContentSizeOut(checkpoint.contentSizeOut);
        flowFileEvent.setContentSizeRemoved(checkpoint.removedBytes);
        flowFileEvent.setFlowFilesIn(checkpoint.flowFilesIn);
        flowFileEvent.setFlowFilesOut(checkpoint.flowFilesOut);
        flowFileEvent.setFlowFilesRemoved(checkpoint.removedCount);
        flowFileEvent.setFlowFilesReceived(flowFilesReceived);
        flowFileEvent.setBytesReceived(bytesReceived);
        flowFileEvent.setFlowFilesSent(flowFilesSent);
        flowFileEvent.setBytesSent(bytesSent);
        long lineageMillis = 0L;
        for (final Map.Entry<FlowFileRecord, StandardRepositoryRecord> entry : checkpoint.records.entrySet()) {
            final FlowFile flowFile = entry.getKey();
            final long lineageDuration = System.currentTimeMillis() - flowFile.getLineageStartDate();
            lineageMillis += lineageDuration;
        }
        flowFileEvent.setAggregateLineageMillis(lineageMillis);
        final Map<String, Long> counters = combineCounters(checkpoint.countersOnCommit, checkpoint.immediateCounters);
        flowFileEvent.setCounters(counters);
        context.getFlowFileEventRepository().updateRepository(flowFileEvent);
        for (final FlowFileEvent connectionEvent : checkpoint.connectionCounts.values()) {
            context.getFlowFileEventRepository().updateRepository(connectionEvent);
        }
    } catch (final IOException ioe) {
        LOG.error("FlowFile Event Repository failed to update", ioe);
    }
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) IOException(java.io.IOException) StandardFlowFileEvent(org.apache.nifi.controller.repository.metrics.StandardFlowFileEvent) Connectable(org.apache.nifi.connectable.Connectable) StandardFlowFileEvent(org.apache.nifi.controller.repository.metrics.StandardFlowFileEvent) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 27 with Connectable

use of org.apache.nifi.connectable.Connectable in project nifi by apache.

the class RelationshipAuditor method updateConnectionAdvice.

/**
 * Audits the creation and removal of relationships via updateConnection().
 *
 * @param proceedingJoinPoint join point
 * @param connectionDTO dto
 * @param connectionDAO dao
 * @return connection
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ConnectionDAO+) && " + "execution(org.apache.nifi.connectable.Connection updateConnection(org.apache.nifi.web.api.dto.ConnectionDTO)) && " + "args(connectionDTO) && " + "target(connectionDAO)")
public Connection updateConnectionAdvice(ProceedingJoinPoint proceedingJoinPoint, ConnectionDTO connectionDTO, ConnectionDAO connectionDAO) throws Throwable {
    // get the previous configuration
    Connection connection = connectionDAO.getConnection(connectionDTO.getId());
    Connectable previousDestination = connection.getDestination();
    Collection<Relationship> previousRelationships = connection.getRelationships();
    Map<String, String> values = extractConfiguredPropertyValues(connection, connectionDTO);
    // perform the underlying operation
    connection = (Connection) proceedingJoinPoint.proceed();
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        Collection<Action> actions = new ArrayList<>();
        Map<String, String> updatedValues = extractConfiguredPropertyValues(connection, connectionDTO);
        // get the source
        Connectable source = connection.getSource();
        // get the current target
        Connectable destination = connection.getDestination();
        // determine if a new target was specified in the initial request
        if (destination != null && !previousDestination.getIdentifier().equals(destination.getIdentifier())) {
            // record the removal of all relationships from the previous target
            final ConnectDetails disconnectDetails = createConnectDetails(connection, source, previousRelationships, previousDestination);
            actions.add(generateAuditRecordForConnection(connection, Operation.Disconnect, disconnectDetails));
            // record the addition of all relationships to the new target
            final ConnectDetails connectDetails = createConnectDetails(connection, connection.getRelationships());
            actions.add(generateAuditRecordForConnection(connection, Operation.Connect, connectDetails));
        }
        // audit and relationships added/removed
        Collection<Relationship> newRelationships = connection.getRelationships();
        // identify any relationships that were added
        if (newRelationships != null) {
            List<Relationship> relationshipsToAdd = new ArrayList<>(newRelationships);
            if (previousRelationships != null) {
                relationshipsToAdd.removeAll(previousRelationships);
            }
            if (!relationshipsToAdd.isEmpty()) {
                final ConnectDetails connectDetails = createConnectDetails(connection, relationshipsToAdd);
                actions.add(generateAuditRecordForConnection(connection, Operation.Connect, connectDetails));
            }
        }
        // identify any relationships that were removed
        if (previousRelationships != null) {
            List<Relationship> relationshipsToRemove = new ArrayList<>(previousRelationships);
            if (newRelationships != null) {
                relationshipsToRemove.removeAll(newRelationships);
            }
            if (!relationshipsToRemove.isEmpty()) {
                final ConnectDetails connectDetails = createConnectDetails(connection, relationshipsToRemove);
                actions.add(generateAuditRecordForConnection(connection, Operation.Disconnect, connectDetails));
            }
        }
        // go through each updated value
        Date actionTimestamp = new Date();
        for (String property : updatedValues.keySet()) {
            String newValue = updatedValues.get(property);
            String oldValue = values.get(property);
            // ensure the value is changing
            if (oldValue == null || newValue == null || !newValue.equals(oldValue)) {
                // create the config details
                FlowChangeConfigureDetails configurationDetails = new FlowChangeConfigureDetails();
                configurationDetails.setName(property);
                configurationDetails.setValue(newValue);
                configurationDetails.setPreviousValue(oldValue);
                // create a configuration action
                FlowChangeAction configurationAction = new FlowChangeAction();
                configurationAction.setUserIdentity(user.getIdentity());
                configurationAction.setOperation(Operation.Configure);
                configurationAction.setTimestamp(actionTimestamp);
                configurationAction.setSourceId(connection.getIdentifier());
                configurationAction.setSourceName(connection.getName());
                configurationAction.setSourceType(Component.Connection);
                configurationAction.setActionDetails(configurationDetails);
                actions.add(configurationAction);
            }
        }
        // save the actions
        if (!actions.isEmpty()) {
            saveActions(actions, logger);
        }
    }
    return connection;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Connection(org.apache.nifi.connectable.Connection) ArrayList(java.util.ArrayList) Date(java.util.Date) Connectable(org.apache.nifi.connectable.Connectable) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) Relationship(org.apache.nifi.processor.Relationship) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 28 with Connectable

use of org.apache.nifi.connectable.Connectable in project nifi by apache.

the class StandardAuthorizableLookup method getLocalConnectable.

@Override
public Authorizable getLocalConnectable(String id) {
    final ProcessGroup group = processGroupDAO.getProcessGroup(controllerFacade.getRootGroupId());
    final Connectable connectable = group.findLocalConnectable(id);
    if (connectable == null) {
        throw new ResourceNotFoundException("Unable to find component with id " + id);
    }
    return connectable;
}
Also used : Connectable(org.apache.nifi.connectable.Connectable) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 29 with Connectable

use of org.apache.nifi.connectable.Connectable in project nifi by apache.

the class StandardReportingContext method createBulletin.

@Override
public Bulletin createBulletin(final String componentId, final String category, final Severity severity, final String message) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
    final Connectable connectable = rootGroup.findLocalConnectable(componentId);
    if (connectable == null) {
        throw new IllegalStateException("Cannot create Component-Level Bulletin because no component can be found with ID " + componentId);
    }
    return BulletinFactory.createBulletin(connectable, category, severity.name(), message);
}
Also used : Connectable(org.apache.nifi.connectable.Connectable) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 30 with Connectable

use of org.apache.nifi.connectable.Connectable in project nifi by apache.

the class FlowController method onFlowInitialized.

/**
 * <p>
 * Causes any processors that were added to the flow with a 'delayStart'
 * flag of true to now start
 * </p>
 *
 * @param startDelayedComponents true if start
 */
public void onFlowInitialized(final boolean startDelayedComponents) {
    writeLock.lock();
    try {
        if (startDelayedComponents) {
            LOG.info("Starting {} processors/ports/funnels", startConnectablesAfterInitialization.size() + startRemoteGroupPortsAfterInitialization.size());
            for (final Connectable connectable : startConnectablesAfterInitialization) {
                if (connectable.getScheduledState() == ScheduledState.DISABLED) {
                    continue;
                }
                try {
                    if (connectable instanceof ProcessorNode) {
                        connectable.getProcessGroup().startProcessor((ProcessorNode) connectable, true);
                    } else {
                        startConnectable(connectable);
                    }
                } catch (final Throwable t) {
                    LOG.error("Unable to start {} due to {}", new Object[] { connectable, t.toString() });
                    if (LOG.isDebugEnabled()) {
                        LOG.error("", t);
                    }
                }
            }
            startConnectablesAfterInitialization.clear();
            int startedTransmitting = 0;
            for (final RemoteGroupPort remoteGroupPort : startRemoteGroupPortsAfterInitialization) {
                try {
                    remoteGroupPort.getRemoteProcessGroup().startTransmitting(remoteGroupPort);
                    startedTransmitting++;
                } catch (final Throwable t) {
                    LOG.error("Unable to start transmitting with {} due to {}", new Object[] { remoteGroupPort, t });
                }
            }
            LOG.info("Started {} Remote Group Ports transmitting", startedTransmitting);
            startRemoteGroupPortsAfterInitialization.clear();
        } else {
            // because we don't provide users the ability to start or stop them - they are just notional.
            for (final Connectable connectable : startConnectablesAfterInitialization) {
                try {
                    if (connectable instanceof Funnel) {
                        startConnectable(connectable);
                    }
                } catch (final Throwable t) {
                    LOG.error("Unable to start {} due to {}", new Object[] { connectable, t });
                }
            }
            startConnectablesAfterInitialization.clear();
            startRemoteGroupPortsAfterInitialization.clear();
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) Connectable(org.apache.nifi.connectable.Connectable) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort)

Aggregations

Connectable (org.apache.nifi.connectable.Connectable)35 Connection (org.apache.nifi.connectable.Connection)18 ArrayList (java.util.ArrayList)12 HashSet (java.util.HashSet)12 ProcessGroup (org.apache.nifi.groups.ProcessGroup)12 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)10 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)10 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)9 VersionedConnection (org.apache.nifi.registry.flow.VersionedConnection)9 Relationship (org.apache.nifi.processor.Relationship)8 HashMap (java.util.HashMap)7 Collection (java.util.Collection)6 LinkedHashSet (java.util.LinkedHashSet)6 Funnel (org.apache.nifi.connectable.Funnel)6 Port (org.apache.nifi.connectable.Port)6 ProcessorNode (org.apache.nifi.controller.ProcessorNode)6 RootGroupPort (org.apache.nifi.remote.RootGroupPort)6 IOException (java.io.IOException)5 List (java.util.List)5 VersionedRemoteProcessGroup (org.apache.nifi.registry.flow.VersionedRemoteProcessGroup)5