use of org.apache.nifi.controller.status.ConnectionStatus in project nifi by apache.
the class TestUnknownDataSet method testSomethingHavingIncomingConnection.
@Test
public void testSomethingHavingIncomingConnection() {
final String processorName = "SomeProcessor";
final String processorId = "processor-1234";
final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class);
when(record.getComponentType()).thenReturn(processorName);
when(record.getComponentId()).thenReturn(processorId);
when(record.getEventType()).thenReturn(ProvenanceEventType.CREATE);
final ClusterResolvers clusterResolvers = Mockito.mock(ClusterResolvers.class);
when(clusterResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("cluster1");
final List<ConnectionStatus> connections = new ArrayList<>();
// The content of connection is not important, just create an empty status.
connections.add(new ConnectionStatus());
final AnalysisContext context = Mockito.mock(AnalysisContext.class);
when(context.getClusterResolver()).thenReturn(clusterResolvers);
when(context.findConnectionTo(processorId)).thenReturn(connections);
final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(processorName, null, record.getEventType());
assertNotNull(analyzer);
final DataSetRefs refs = analyzer.analyze(context, record);
assertNull("If the processor has incoming connections, no refs should be created", refs);
}
use of org.apache.nifi.controller.status.ConnectionStatus in project nifi by apache.
the class TestUnknownDataSet method testGenerateFlowFile.
@Test
public void testGenerateFlowFile() {
final String processorName = "GenerateFlowFile";
final String processorId = "processor-1234";
final ProvenanceEventRecord record = Mockito.mock(ProvenanceEventRecord.class);
when(record.getComponentType()).thenReturn(processorName);
when(record.getComponentId()).thenReturn(processorId);
when(record.getEventType()).thenReturn(ProvenanceEventType.CREATE);
final ClusterResolvers clusterResolvers = Mockito.mock(ClusterResolvers.class);
when(clusterResolvers.fromHostNames(matches(".+\\.example\\.com"))).thenReturn("cluster1");
final List<ConnectionStatus> connections = new ArrayList<>();
final AnalysisContext context = Mockito.mock(AnalysisContext.class);
when(context.getClusterResolver()).thenReturn(clusterResolvers);
when(context.findConnectionTo(processorId)).thenReturn(connections);
when(context.getNiFiClusterName()).thenReturn("nifi-cluster");
final NiFiProvenanceEventAnalyzer analyzer = NiFiProvenanceEventAnalyzerFactory.getAnalyzer(processorName, null, record.getEventType());
assertNotNull(analyzer);
final DataSetRefs refs = analyzer.analyze(context, record);
assertEquals(1, refs.getInputs().size());
assertEquals(0, refs.getOutputs().size());
Referenceable ref = refs.getInputs().iterator().next();
assertEquals("nifi_data", ref.getTypeName());
assertEquals("GenerateFlowFile", ref.get(ATTR_NAME));
assertEquals("processor-1234@nifi-cluster", ref.get(ATTR_QUALIFIED_NAME));
}
use of org.apache.nifi.controller.status.ConnectionStatus in project nifi by apache.
the class ControllerStatusReportingTask method printConnectionStatus.
// Recursively prints the status of all connections in this group.
private void printConnectionStatus(final ProcessGroupStatus groupStatus, final StringBuilder builder, final boolean showDeltas) {
final List<ConnectionStatus> connectionStatuses = new ArrayList<>();
populateConnectionStatuses(groupStatus, connectionStatuses);
Collections.sort(connectionStatuses, new Comparator<ConnectionStatus>() {
@Override
public int compare(final ConnectionStatus o1, final ConnectionStatus o2) {
if (o1 == null && o2 == null) {
return 0;
}
if (o1 == null) {
return 1;
}
if (o2 == null) {
return -1;
}
return -Long.compare(o1.getQueuedBytes(), o2.getQueuedBytes());
}
});
for (final ConnectionStatus connectionStatus : connectionStatuses) {
final String input = connectionStatus.getInputCount() + " / " + FormatUtils.formatDataSize(connectionStatus.getInputBytes());
final String output = connectionStatus.getOutputCount() + " / " + FormatUtils.formatDataSize(connectionStatus.getOutputBytes());
final String queued = connectionStatus.getQueuedCount() + " / " + FormatUtils.formatDataSize(connectionStatus.getQueuedBytes());
final String inputDiff;
final String outputDiff;
final String queuedDiff;
final ConnectionStatus lastStatus = lastConnectionStatus.get(connectionStatus.getId());
if (showDeltas && lastStatus != null) {
inputDiff = toDiff(lastStatus.getInputCount(), lastStatus.getInputBytes(), connectionStatus.getInputCount(), connectionStatus.getInputBytes());
outputDiff = toDiff(lastStatus.getOutputCount(), lastStatus.getOutputBytes(), connectionStatus.getOutputCount(), connectionStatus.getOutputBytes());
queuedDiff = toDiff(lastStatus.getQueuedCount(), lastStatus.getQueuedBytes(), connectionStatus.getQueuedCount(), connectionStatus.getQueuedBytes());
} else {
inputDiff = toDiff(0L, 0L, connectionStatus.getInputCount(), connectionStatus.getInputBytes());
outputDiff = toDiff(0L, 0L, connectionStatus.getOutputCount(), connectionStatus.getOutputBytes());
queuedDiff = toDiff(0L, 0L, connectionStatus.getQueuedCount(), connectionStatus.getQueuedBytes());
}
if (showDeltas) {
builder.append(String.format(connectionLineFormat, connectionStatus.getId(), connectionStatus.getSourceName(), connectionStatus.getName(), connectionStatus.getDestinationName(), input + inputDiff, output + outputDiff, queued + queuedDiff));
} else {
builder.append(String.format(connectionLineFormat, connectionStatus.getId(), connectionStatus.getSourceName(), connectionStatus.getName(), connectionStatus.getDestinationName(), input, output, queued));
}
lastConnectionStatus.put(connectionStatus.getId(), connectionStatus);
}
}
use of org.apache.nifi.controller.status.ConnectionStatus in project nifi by apache.
the class DtoFactory method createProcessGroupStatusDto.
public ProcessGroupStatusDTO createProcessGroupStatusDto(final ProcessGroup processGroup, final ProcessGroupStatus processGroupStatus) {
final ProcessGroupStatusDTO processGroupStatusDto = createConciseProcessGroupStatusDto(processGroupStatus);
final ProcessGroupStatusSnapshotDTO snapshot = processGroupStatusDto.getAggregateSnapshot();
// processor status
final Collection<ProcessorStatusSnapshotEntity> processorStatusSnapshotEntities = new ArrayList<>();
snapshot.setProcessorStatusSnapshots(processorStatusSnapshotEntities);
final Collection<ProcessorStatus> processorStatusCollection = processGroupStatus.getProcessorStatus();
if (processorStatusCollection != null) {
for (final ProcessorStatus processorStatus : processorStatusCollection) {
final ProcessorStatusDTO processorStatusDto = createProcessorStatusDto(processorStatus);
final ProcessorNode processor = processGroup.findProcessor(processorStatusDto.getId());
final PermissionsDTO processorPermissions = createPermissionsDto(processor);
processorStatusSnapshotEntities.add(entityFactory.createProcessorStatusSnapshotEntity(processorStatusDto.getAggregateSnapshot(), processorPermissions));
}
}
// connection status
final Collection<ConnectionStatusSnapshotEntity> connectionStatusDtoCollection = new ArrayList<>();
snapshot.setConnectionStatusSnapshots(connectionStatusDtoCollection);
final Collection<ConnectionStatus> connectionStatusCollection = processGroupStatus.getConnectionStatus();
if (connectionStatusCollection != null) {
for (final ConnectionStatus connectionStatus : connectionStatusCollection) {
final ConnectionStatusDTO connectionStatusDto = createConnectionStatusDto(connectionStatus);
final Connection connection = processGroup.findConnection(connectionStatusDto.getId());
final PermissionsDTO connectionPermissions = createPermissionsDto(connection);
connectionStatusDtoCollection.add(entityFactory.createConnectionStatusSnapshotEntity(connectionStatusDto.getAggregateSnapshot(), connectionPermissions));
}
}
// local child process groups
final Collection<ProcessGroupStatusSnapshotEntity> childProcessGroupStatusDtoCollection = new ArrayList<>();
snapshot.setProcessGroupStatusSnapshots(childProcessGroupStatusDtoCollection);
final Collection<ProcessGroupStatus> childProcessGroupStatusCollection = processGroupStatus.getProcessGroupStatus();
if (childProcessGroupStatusCollection != null) {
for (final ProcessGroupStatus childProcessGroupStatus : childProcessGroupStatusCollection) {
final ProcessGroupStatusDTO childProcessGroupStatusDto = createProcessGroupStatusDto(processGroup, childProcessGroupStatus);
final ProcessGroup childProcessGroup = processGroup.findProcessGroup(childProcessGroupStatusDto.getId());
final PermissionsDTO childProcessGroupPermissions = createPermissionsDto(childProcessGroup);
childProcessGroupStatusDtoCollection.add(entityFactory.createProcessGroupStatusSnapshotEntity(childProcessGroupStatusDto.getAggregateSnapshot(), childProcessGroupPermissions));
}
}
// remote child process groups
final Collection<RemoteProcessGroupStatusSnapshotEntity> childRemoteProcessGroupStatusDtoCollection = new ArrayList<>();
snapshot.setRemoteProcessGroupStatusSnapshots(childRemoteProcessGroupStatusDtoCollection);
final Collection<RemoteProcessGroupStatus> childRemoteProcessGroupStatusCollection = processGroupStatus.getRemoteProcessGroupStatus();
if (childRemoteProcessGroupStatusCollection != null) {
for (final RemoteProcessGroupStatus childRemoteProcessGroupStatus : childRemoteProcessGroupStatusCollection) {
final RemoteProcessGroupStatusDTO childRemoteProcessGroupStatusDto = createRemoteProcessGroupStatusDto(childRemoteProcessGroupStatus);
final RemoteProcessGroup remoteProcessGroup = processGroup.findRemoteProcessGroup(childRemoteProcessGroupStatusDto.getId());
final PermissionsDTO remoteProcessGroupPermissions = createPermissionsDto(remoteProcessGroup);
childRemoteProcessGroupStatusDtoCollection.add(entityFactory.createRemoteProcessGroupStatusSnapshotEntity(childRemoteProcessGroupStatusDto.getAggregateSnapshot(), remoteProcessGroupPermissions));
}
}
// input ports
final Collection<PortStatusSnapshotEntity> inputPortStatusDtoCollection = new ArrayList<>();
snapshot.setInputPortStatusSnapshots(inputPortStatusDtoCollection);
final Collection<PortStatus> inputPortStatusCollection = processGroupStatus.getInputPortStatus();
if (inputPortStatusCollection != null) {
for (final PortStatus portStatus : inputPortStatusCollection) {
final PortStatusDTO portStatusDto = createPortStatusDto(portStatus);
final Port inputPort = processGroup.findInputPort(portStatus.getId());
final PermissionsDTO inputPortPermissions = createPermissionsDto(inputPort);
inputPortStatusDtoCollection.add(entityFactory.createPortStatusSnapshotEntity(portStatusDto.getAggregateSnapshot(), inputPortPermissions));
}
}
// output ports
final Collection<PortStatusSnapshotEntity> outputPortStatusDtoCollection = new ArrayList<>();
snapshot.setOutputPortStatusSnapshots(outputPortStatusDtoCollection);
final Collection<PortStatus> outputPortStatusCollection = processGroupStatus.getOutputPortStatus();
if (outputPortStatusCollection != null) {
for (final PortStatus portStatus : outputPortStatusCollection) {
final PortStatusDTO portStatusDto = createPortStatusDto(portStatus);
final Port outputPort = processGroup.findOutputPort(portStatus.getId());
final PermissionsDTO outputPortPermissions = createPermissionsDto(outputPort);
outputPortStatusDtoCollection.add(entityFactory.createPortStatusSnapshotEntity(portStatusDto.getAggregateSnapshot(), outputPortPermissions));
}
}
return processGroupStatusDto;
}
use of org.apache.nifi.controller.status.ConnectionStatus in project nifi-minifi by apache.
the class StatusConfigReporterTest method populateConnection.
private void populateConnection() {
ConnectionStatus connectionStatus = new ConnectionStatus();
connectionStatus.setQueuedBytes(100);
connectionStatus.setId("connectionId");
connectionStatus.setName("connectionId");
connectionStatus.setQueuedCount(10);
connectionStatus.setInputCount(1);
connectionStatus.setInputBytes(2);
connectionStatus.setOutputCount(3);
connectionStatus.setOutputBytes(4);
Collection<ConnectionStatus> statusCollection = new ArrayList<>();
statusCollection.add(connectionStatus);
when(rootGroupStatus.getConnectionStatus()).thenReturn(statusCollection);
}
Aggregations