use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class CurrentUserEndpointMerger method mergeResponses.
@Override
protected void mergeResponses(final CurrentUserEntity clientEntity, final Map<NodeIdentifier, CurrentUserEntity> entityMap, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses) {
for (final Map.Entry<NodeIdentifier, CurrentUserEntity> entry : entityMap.entrySet()) {
final CurrentUserEntity entity = entry.getValue();
if (entity != clientEntity) {
mergePermissions(clientEntity.getControllerPermissions(), entity.getControllerPermissions());
mergePermissions(clientEntity.getCountersPermissions(), entity.getCountersPermissions());
mergePermissions(clientEntity.getPoliciesPermissions(), entity.getPoliciesPermissions());
mergePermissions(clientEntity.getProvenancePermissions(), entity.getProvenancePermissions());
mergePermissions(clientEntity.getTenantsPermissions(), entity.getTenantsPermissions());
mergePermissions(clientEntity.getSystemPermissions(), entity.getSystemPermissions());
mergePermissions(clientEntity.getTenantsPermissions(), entity.getTenantsPermissions());
final Set<ComponentRestrictionPermissionDTO> clientEntityComponentRestrictionsPermissions = clientEntity.getComponentRestrictionPermissions();
final Set<ComponentRestrictionPermissionDTO> entityComponentRestrictionsPermissions = entity.getComponentRestrictionPermissions();
// only retain the component restriction permissions in common
clientEntityComponentRestrictionsPermissions.retainAll(entityComponentRestrictionsPermissions);
// merge the component restriction permissions
clientEntityComponentRestrictionsPermissions.forEach(clientEntityPermission -> {
final ComponentRestrictionPermissionDTO entityPermission = entityComponentRestrictionsPermissions.stream().filter(entityComponentRestrictionsPermission -> {
return entityComponentRestrictionsPermission.getRequiredPermission().getId().equals(clientEntityPermission.getRequiredPermission().getId());
}).findFirst().orElse(null);
mergePermissions(clientEntityPermission.getPermissions(), entityPermission.getPermissions());
});
}
}
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class DropRequestEndpointMerger method mergeResponses.
@Override
protected void mergeResponses(DropRequestDTO clientDto, Map<NodeIdentifier, DropRequestDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
boolean nodeWaiting = false;
int originalCount = 0;
long originalSize = 0;
int currentCount = 0;
long currentSize = 0;
int droppedCount = 0;
long droppedSize = 0;
DropFlowFileState state = null;
boolean allFinished = true;
String failureReason = null;
for (final Map.Entry<NodeIdentifier, DropRequestDTO> nodeEntry : dtoMap.entrySet()) {
final DropRequestDTO nodeDropRequest = nodeEntry.getValue();
if (!nodeDropRequest.isFinished()) {
allFinished = false;
}
if (nodeDropRequest.getFailureReason() != null) {
failureReason = nodeDropRequest.getFailureReason();
}
currentCount += nodeDropRequest.getCurrentCount();
currentSize += nodeDropRequest.getCurrentSize();
droppedCount += nodeDropRequest.getDroppedCount();
droppedSize += nodeDropRequest.getDroppedSize();
if (nodeDropRequest.getOriginalCount() == null) {
nodeWaiting = true;
} else {
originalCount += nodeDropRequest.getOriginalCount();
originalSize += nodeDropRequest.getOriginalSize();
}
final DropFlowFileState nodeState = DropFlowFileState.valueOfDescription(nodeDropRequest.getState());
if (state == null || state.ordinal() > nodeState.ordinal()) {
state = nodeState;
}
}
clientDto.setCurrentCount(currentCount);
clientDto.setCurrentSize(currentSize);
clientDto.setCurrent(FormatUtils.formatCount(currentCount) + " / " + FormatUtils.formatDataSize(currentSize));
clientDto.setDroppedCount(droppedCount);
clientDto.setDroppedSize(droppedSize);
clientDto.setDropped(FormatUtils.formatCount(droppedCount) + " / " + FormatUtils.formatDataSize(droppedSize));
clientDto.setFinished(allFinished);
clientDto.setFailureReason(failureReason);
if (originalCount == 0) {
clientDto.setPercentCompleted(allFinished ? 100 : 0);
} else {
clientDto.setPercentCompleted((int) ((double) droppedCount / (double) originalCount * 100D));
}
if (!nodeWaiting) {
clientDto.setOriginalCount(originalCount);
clientDto.setOriginalSize(originalSize);
clientDto.setOriginal(FormatUtils.formatCount(originalCount) + " / " + FormatUtils.formatDataSize(originalSize));
}
if (state != null) {
clientDto.setState(state.toString());
}
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class FlowMerger method mergeResponses.
@Override
protected void mergeResponses(final ProcessGroupFlowDTO clientDto, final Map<NodeIdentifier, ProcessGroupFlowDTO> dtoMap, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses) {
final FlowDTO flowDto = clientDto.getFlow();
final Set<ConnectionEntity> clientConnections = flowDto.getConnections();
final Set<ProcessorEntity> clientProcessors = flowDto.getProcessors();
final Set<PortEntity> clientInputPorts = flowDto.getInputPorts();
final Set<PortEntity> clientOutputPorts = flowDto.getOutputPorts();
final Set<RemoteProcessGroupEntity> clientRemoteProcessGroups = flowDto.getRemoteProcessGroups();
final Set<ProcessGroupEntity> clientProcessGroups = flowDto.getProcessGroups();
final Set<LabelEntity> clientLabels = flowDto.getLabels();
final Set<FunnelEntity> clientFunnels = flowDto.getFunnels();
final Map<String, Map<NodeIdentifier, ConnectionEntity>> connections = new HashMap<>();
final Map<String, Map<NodeIdentifier, FunnelEntity>> funnels = new HashMap<>();
final Map<String, Map<NodeIdentifier, PortEntity>> inputPorts = new HashMap<>();
final Map<String, Map<NodeIdentifier, LabelEntity>> labels = new HashMap<>();
final Map<String, Map<NodeIdentifier, PortEntity>> outputPorts = new HashMap<>();
final Map<String, Map<NodeIdentifier, ProcessorEntity>> processors = new HashMap<>();
final Map<String, Map<NodeIdentifier, RemoteProcessGroupEntity>> rpgs = new HashMap<>();
final Map<String, Map<NodeIdentifier, ProcessGroupEntity>> processGroups = new HashMap<>();
// Create mapping of ComponentID -> [nodeId, entity on that node]
for (final Map.Entry<NodeIdentifier, ProcessGroupFlowDTO> nodeGroupFlowEntry : dtoMap.entrySet()) {
final NodeIdentifier nodeIdentifier = nodeGroupFlowEntry.getKey();
final ProcessGroupFlowDTO nodeGroupFlowDto = nodeGroupFlowEntry.getValue();
final FlowDTO nodeFlowDto = nodeGroupFlowDto.getFlow();
// Merge connection statuses
for (final ConnectionEntity entity : nodeFlowDto.getConnections()) {
connections.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final FunnelEntity entity : nodeFlowDto.getFunnels()) {
funnels.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final PortEntity entity : nodeFlowDto.getInputPorts()) {
inputPorts.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final PortEntity entity : nodeFlowDto.getOutputPorts()) {
outputPorts.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final LabelEntity entity : nodeFlowDto.getLabels()) {
labels.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final ProcessorEntity entity : nodeFlowDto.getProcessors()) {
processors.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final RemoteProcessGroupEntity entity : nodeFlowDto.getRemoteProcessGroups()) {
rpgs.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final ProcessGroupEntity entity : nodeFlowDto.getProcessGroups()) {
processGroups.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
}
//
// Merge the components that are grouped together by ID
//
// Merge connections
ConnectionsEntityMerger.mergeConnections(clientConnections, connections);
// Merge funnel statuses
FunnelsEntityMerger.mergeFunnels(clientFunnels, funnels);
// Merge input ports
PortsEntityMerger.mergePorts(clientInputPorts, inputPorts);
// Merge output ports
PortsEntityMerger.mergePorts(clientOutputPorts, outputPorts);
// Merge labels
LabelsEntityMerger.mergeLabels(clientLabels, labels);
// Merge processors
ProcessorsEntityMerger.mergeProcessors(clientProcessors, processors);
// Merge Remote Process Groups
RemoteProcessGroupsEntityMerger.mergeRemoteProcessGroups(clientRemoteProcessGroups, rpgs);
// Merge Process Groups
ProcessGroupsEntityMerger.mergeProcessGroups(clientProcessGroups, processGroups);
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class FlowSnippetEndpointMerger method merge.
@Override
public NodeResponse merge(final URI uri, final String method, Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final NodeResponse clientResponse) {
final FlowEntity responseEntity = clientResponse.getClientResponse().readEntity(FlowEntity.class);
final FlowDTO flowDto = responseEntity.getFlow();
if (flowDto == null) {
return clientResponse;
} else {
final Map<String, Map<NodeIdentifier, ProcessorEntity>> processorMap = new HashMap<>();
final Map<String, Map<NodeIdentifier, RemoteProcessGroupEntity>> remoteProcessGroupMap = new HashMap<>();
for (final NodeResponse nodeResponse : successfulResponses) {
final FlowEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(FlowEntity.class);
final FlowDTO nodeContents = nodeResponseEntity.getFlow();
for (final ProcessorEntity nodeProcessor : nodeContents.getProcessors()) {
Map<NodeIdentifier, ProcessorEntity> innerMap = processorMap.computeIfAbsent(nodeProcessor.getId(), id -> new HashMap<>());
innerMap.put(nodeResponse.getNodeId(), nodeProcessor);
}
for (final RemoteProcessGroupEntity nodeRemoteProcessGroup : nodeContents.getRemoteProcessGroups()) {
Map<NodeIdentifier, RemoteProcessGroupEntity> innerMap = remoteProcessGroupMap.computeIfAbsent(nodeRemoteProcessGroup.getId(), id -> new HashMap<>());
innerMap.put(nodeResponse.getNodeId(), nodeRemoteProcessGroup);
}
}
final ProcessorEndpointMerger procMerger = new ProcessorEndpointMerger();
for (final ProcessorEntity processor : flowDto.getProcessors()) {
final String procId = processor.getId();
final Map<NodeIdentifier, ProcessorEntity> mergeMap = processorMap.get(procId);
procMerger.mergeResponses(processor, mergeMap, successfulResponses, problematicResponses);
}
final RemoteProcessGroupEndpointMerger rpgMerger = new RemoteProcessGroupEndpointMerger();
for (final RemoteProcessGroupEntity remoteProcessGroup : flowDto.getRemoteProcessGroups()) {
final String remoteProcessGroupId = remoteProcessGroup.getId();
final Map<NodeIdentifier, RemoteProcessGroupEntity> mergeMap = remoteProcessGroupMap.get(remoteProcessGroupId);
rpgMerger.mergeResponses(remoteProcessGroup, mergeMap, successfulResponses, problematicResponses);
}
}
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class FunnelsEndpointMerger method merge.
@Override
public NodeResponse merge(URI uri, String method, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses, NodeResponse clientResponse) {
if (!canHandle(uri, method)) {
throw new IllegalArgumentException("Cannot use Endpoint Mapper of type " + getClass().getSimpleName() + " to map responses for URI " + uri + ", HTTP Method " + method);
}
final FunnelsEntity responseEntity = clientResponse.getClientResponse().readEntity(FunnelsEntity.class);
final Set<FunnelEntity> funnelEntities = responseEntity.getFunnels();
final Map<String, Map<NodeIdentifier, FunnelEntity>> entityMap = new HashMap<>();
for (final NodeResponse nodeResponse : successfulResponses) {
final FunnelsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(FunnelsEntity.class);
final Set<FunnelEntity> nodeFunnelEntities = nodeResponseEntity.getFunnels();
for (final FunnelEntity nodeFunnelEntity : nodeFunnelEntities) {
final String nodeFunnelEntityId = nodeFunnelEntity.getId();
Map<NodeIdentifier, FunnelEntity> innerMap = entityMap.get(nodeFunnelEntityId);
if (innerMap == null) {
innerMap = new HashMap<>();
entityMap.put(nodeFunnelEntityId, innerMap);
}
innerMap.put(nodeResponse.getNodeId(), nodeFunnelEntity);
}
}
FunnelsEntityMerger.mergeFunnels(funnelEntities, entityMap);
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
Aggregations