use of org.apache.nifi.web.api.entity.RemoteProcessGroupEntity 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.web.api.entity.RemoteProcessGroupEntity 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.web.api.entity.RemoteProcessGroupEntity in project nifi by apache.
the class StandardNiFiServiceFacade method createRemoteProcessGroup.
@Override
public RemoteProcessGroupEntity createRemoteProcessGroup(final Revision revision, final String groupId, final RemoteProcessGroupDTO remoteProcessGroupDTO) {
final RevisionUpdate<RemoteProcessGroupDTO> snapshot = createComponent(revision, remoteProcessGroupDTO, () -> remoteProcessGroupDAO.createRemoteProcessGroup(groupId, remoteProcessGroupDTO), remoteProcessGroup -> dtoFactory.createRemoteProcessGroupDto(remoteProcessGroup));
final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupDTO.getId());
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(remoteProcessGroup);
final RemoteProcessGroupStatusDTO status = dtoFactory.createRemoteProcessGroupStatusDto(controllerFacade.getRemoteProcessGroupStatus(remoteProcessGroup.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(remoteProcessGroup.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
return entityFactory.createRemoteProcessGroupEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
}
use of org.apache.nifi.web.api.entity.RemoteProcessGroupEntity in project nifi by apache.
the class RemoteProcessGroupEntityMerger method mergeComponents.
/**
* Merges the RemoteProcessGroupEntity responses.
*
* @param clientEntity the entity being returned to the client
* @param entityMap all node responses
*/
@Override
public void mergeComponents(final RemoteProcessGroupEntity clientEntity, final Map<NodeIdentifier, RemoteProcessGroupEntity> entityMap) {
final RemoteProcessGroupDTO clientDto = clientEntity.getComponent();
final Map<NodeIdentifier, RemoteProcessGroupDTO> dtoMap = new HashMap<>();
for (final Map.Entry<NodeIdentifier, RemoteProcessGroupEntity> entry : entityMap.entrySet()) {
final RemoteProcessGroupEntity nodeProcEntity = entry.getValue();
final RemoteProcessGroupDTO nodeProcDto = nodeProcEntity.getComponent();
dtoMap.put(entry.getKey(), nodeProcDto);
}
mergeDtos(clientDto, dtoMap);
}
use of org.apache.nifi.web.api.entity.RemoteProcessGroupEntity in project nifi by apache.
the class RemoteProcessGroupEntityMergerTest method testMergeRemoteProcessGroups.
@Test
public void testMergeRemoteProcessGroups() throws Exception {
final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1", 8080, "host-1", 19998, null, null, null, false);
final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2", 8081, "host-2", 19999, null, null, null, false);
final PermissionsDTO permissed = new PermissionsDTO();
permissed.setCanRead(true);
permissed.setCanWrite(true);
final RemoteProcessGroupStatusDTO status = new RemoteProcessGroupStatusDTO();
status.setAggregateSnapshot(new RemoteProcessGroupStatusSnapshotDTO());
final RemoteProcessGroupPortDTO in1_1 = new RemoteProcessGroupPortDTO();
in1_1.setName("in1");
final RemoteProcessGroupPortDTO in1_2 = new RemoteProcessGroupPortDTO();
in1_2.setName("in2");
final Set<RemoteProcessGroupPortDTO> inputs1 = new HashSet<>();
inputs1.add(in1_1);
inputs1.add(in1_2);
final RemoteProcessGroupPortDTO out1_1 = new RemoteProcessGroupPortDTO();
out1_1.setName("out1");
final Set<RemoteProcessGroupPortDTO> outputs1 = new HashSet<>();
outputs1.add(out1_1);
final RemoteProcessGroupContentsDTO contents1 = new RemoteProcessGroupContentsDTO();
contents1.setInputPorts(inputs1);
contents1.setOutputPorts(outputs1);
final RemoteProcessGroupDTO rpg1 = new RemoteProcessGroupDTO();
rpg1.setContents(contents1);
final RemoteProcessGroupEntity entity1 = new RemoteProcessGroupEntity();
entity1.setPermissions(permissed);
entity1.setStatus(status);
entity1.setComponent(rpg1);
final RemoteProcessGroupPortDTO in2_1 = new RemoteProcessGroupPortDTO();
in2_1.setName("in1");
final Set<RemoteProcessGroupPortDTO> inputs2 = new HashSet<>();
inputs2.add(in2_1);
final RemoteProcessGroupPortDTO out2_1 = new RemoteProcessGroupPortDTO();
out2_1.setName("out1");
final RemoteProcessGroupPortDTO out2_2 = new RemoteProcessGroupPortDTO();
out2_2.setName("out2");
final Set<RemoteProcessGroupPortDTO> outputs2 = new HashSet<>();
outputs2.add(out2_1);
outputs2.add(out2_2);
final RemoteProcessGroupContentsDTO contents2 = new RemoteProcessGroupContentsDTO();
contents2.setInputPorts(inputs2);
contents2.setOutputPorts(outputs2);
final RemoteProcessGroupDTO rpg2 = new RemoteProcessGroupDTO();
rpg2.setContents(contents2);
final RemoteProcessGroupEntity entity2 = new RemoteProcessGroupEntity();
entity2.setPermissions(permissed);
entity2.setStatus(status);
entity2.setComponent(rpg2);
final Map<NodeIdentifier, RemoteProcessGroupEntity> nodeMap = new HashMap<>();
nodeMap.put(node1, entity1);
nodeMap.put(node2, entity2);
final RemoteProcessGroupEntityMerger merger = new RemoteProcessGroupEntityMerger();
merger.merge(entity1, nodeMap);
// should only include ports in common to all rpg's
assertEquals(1, entity1.getComponent().getContents().getInputPorts().size());
assertEquals("in1", entity1.getComponent().getContents().getInputPorts().iterator().next().getName());
assertEquals(1, entity1.getComponent().getContents().getOutputPorts().size());
assertEquals("out1", entity1.getComponent().getContents().getOutputPorts().iterator().next().getName());
}
Aggregations