use of org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity in project nifi by apache.
the class EntityFactory method createConnectionStatusSnapshotEntity.
public ConnectionStatusSnapshotEntity createConnectionStatusSnapshotEntity(final ConnectionStatusSnapshotDTO status, final PermissionsDTO permissions) {
final ConnectionStatusSnapshotEntity entity = new ConnectionStatusSnapshotEntity();
entity.setId(status.getId());
entity.setCanRead(permissions.getCanRead());
// always set the status, as it's always allowed... just need to provide permission context for merging responses
entity.setConnectionStatusSnapshot(status);
return entity;
}
use of org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity in project nifi by apache.
the class StatusMerger method merge.
public static void merge(final ProcessGroupStatusSnapshotDTO target, final boolean targetReadablePermission, final ProcessGroupStatusSnapshotDTO toMerge, final boolean toMergeReadablePermission) {
if (target == null || toMerge == null) {
return;
}
if (targetReadablePermission && !toMergeReadablePermission) {
target.setId(toMerge.getId());
target.setName(toMerge.getName());
}
// if the versioned flow state to merge is sync failure allow it to take precedence
if (VersionedFlowState.SYNC_FAILURE.name().equals(toMerge.getVersionedFlowState())) {
target.setVersionedFlowState(VersionedFlowState.SYNC_FAILURE.name());
}
target.setBytesIn(target.getBytesIn() + toMerge.getBytesIn());
target.setFlowFilesIn(target.getFlowFilesIn() + toMerge.getFlowFilesIn());
target.setBytesQueued(target.getBytesQueued() + toMerge.getBytesQueued());
target.setFlowFilesQueued(target.getFlowFilesQueued() + toMerge.getFlowFilesQueued());
target.setBytesRead(target.getBytesRead() + toMerge.getBytesRead());
target.setBytesWritten(target.getBytesWritten() + toMerge.getBytesWritten());
target.setBytesOut(target.getBytesOut() + toMerge.getBytesOut());
target.setFlowFilesOut(target.getFlowFilesOut() + toMerge.getFlowFilesOut());
target.setBytesTransferred(target.getBytesTransferred() + toMerge.getBytesTransferred());
target.setFlowFilesTransferred(target.getFlowFilesTransferred() + toMerge.getFlowFilesTransferred());
target.setBytesReceived(target.getBytesReceived() + toMerge.getBytesReceived());
target.setFlowFilesReceived(target.getFlowFilesReceived() + toMerge.getFlowFilesReceived());
target.setBytesSent(target.getBytesSent() + toMerge.getBytesSent());
target.setFlowFilesSent(target.getFlowFilesSent() + toMerge.getFlowFilesSent());
target.setActiveThreadCount(target.getActiveThreadCount() + toMerge.getActiveThreadCount());
updatePrettyPrintedFields(target);
// connection status
// sort by id
final Map<String, ConnectionStatusSnapshotEntity> mergedConnectionMap = new HashMap<>();
for (final ConnectionStatusSnapshotEntity status : replaceNull(target.getConnectionStatusSnapshots())) {
mergedConnectionMap.put(status.getId(), status);
}
for (final ConnectionStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getConnectionStatusSnapshots())) {
ConnectionStatusSnapshotEntity merged = mergedConnectionMap.get(statusToMerge.getId());
if (merged == null) {
mergedConnectionMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merge(merged, statusToMerge);
}
target.setConnectionStatusSnapshots(mergedConnectionMap.values());
// processor status
final Map<String, ProcessorStatusSnapshotEntity> mergedProcessorMap = new HashMap<>();
for (final ProcessorStatusSnapshotEntity status : replaceNull(target.getProcessorStatusSnapshots())) {
mergedProcessorMap.put(status.getId(), status);
}
for (final ProcessorStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getProcessorStatusSnapshots())) {
ProcessorStatusSnapshotEntity merged = mergedProcessorMap.get(statusToMerge.getId());
if (merged == null) {
mergedProcessorMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merge(merged, statusToMerge);
}
target.setProcessorStatusSnapshots(mergedProcessorMap.values());
// input ports
final Map<String, PortStatusSnapshotEntity> mergedInputPortMap = new HashMap<>();
for (final PortStatusSnapshotEntity status : replaceNull(target.getInputPortStatusSnapshots())) {
mergedInputPortMap.put(status.getId(), status);
}
for (final PortStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getInputPortStatusSnapshots())) {
PortStatusSnapshotEntity merged = mergedInputPortMap.get(statusToMerge.getId());
if (merged == null) {
mergedInputPortMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merge(merged, statusToMerge);
}
target.setInputPortStatusSnapshots(mergedInputPortMap.values());
// output ports
final Map<String, PortStatusSnapshotEntity> mergedOutputPortMap = new HashMap<>();
for (final PortStatusSnapshotEntity status : replaceNull(target.getOutputPortStatusSnapshots())) {
mergedOutputPortMap.put(status.getId(), status);
}
for (final PortStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getOutputPortStatusSnapshots())) {
PortStatusSnapshotEntity merged = mergedOutputPortMap.get(statusToMerge.getId());
if (merged == null) {
mergedOutputPortMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merge(merged, statusToMerge);
}
target.setOutputPortStatusSnapshots(mergedOutputPortMap.values());
// child groups
final Map<String, ProcessGroupStatusSnapshotEntity> mergedGroupMap = new HashMap<>();
for (final ProcessGroupStatusSnapshotEntity status : replaceNull(target.getProcessGroupStatusSnapshots())) {
mergedGroupMap.put(status.getId(), status);
}
for (final ProcessGroupStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getProcessGroupStatusSnapshots())) {
ProcessGroupStatusSnapshotEntity merged = mergedGroupMap.get(statusToMerge.getId());
if (merged == null) {
mergedGroupMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merge(merged, statusToMerge);
}
target.setOutputPortStatusSnapshots(mergedOutputPortMap.values());
// remote groups
final Map<String, RemoteProcessGroupStatusSnapshotEntity> mergedRemoteGroupMap = new HashMap<>();
for (final RemoteProcessGroupStatusSnapshotEntity status : replaceNull(target.getRemoteProcessGroupStatusSnapshots())) {
mergedRemoteGroupMap.put(status.getId(), status);
}
for (final RemoteProcessGroupStatusSnapshotEntity statusToMerge : replaceNull(toMerge.getRemoteProcessGroupStatusSnapshots())) {
RemoteProcessGroupStatusSnapshotEntity merged = mergedRemoteGroupMap.get(statusToMerge.getId());
if (merged == null) {
mergedRemoteGroupMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merge(merged, statusToMerge);
}
target.setRemoteProcessGroupStatusSnapshots(mergedRemoteGroupMap.values());
}
use of org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity 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;
}
Aggregations