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);
}
}
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;
}
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;
}
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);
}
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();
}
}
Aggregations