use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class AlignProcessGroupComponents method createLayoutGroups.
/**
* Group the items together to create the various LayoutGroups needed for different Rendering
*/
private void createLayoutGroups() {
Map<String, Set<ProcessGroupDTO>> outputPortIdToGroup = new HashMap<String, Set<ProcessGroupDTO>>();
groupIdToOutputPorts = new HashMap<>();
Map<String, Set<ProcessGroupDTO>> inputPortIdToGroup = new HashMap<String, Set<ProcessGroupDTO>>();
groupIdToInputPorts = new HashMap<>();
Map<String, Set<String>> groupIdToGroup = new HashMap<>();
List<ProcessGroupDTO> connectedGroups = new LinkedList<>();
parentProcessGroup.getContents().getConnections().stream().filter(connectionDTO -> (isOutputPortToGroupConnection(connectionDTO) || isGroupToGroupConnection(connectionDTO) || isInputPortToGroupConnection(connectionDTO))).forEach(connectionDTO -> {
PortDTO outputPort = outputPortMap.get(connectionDTO.getDestination().getId()) == null ? outputPortMap.get(connectionDTO.getSource().getId()) : outputPortMap.get(connectionDTO.getDestination().getId());
PortDTO inputPort = inputPortMap.get(connectionDTO.getSource().getId()) == null ? inputPortMap.get(connectionDTO.getDestination().getId()) : inputPortMap.get(connectionDTO.getSource().getId());
ProcessGroupDTO destinationGroup = processGroupDTOMap.get(connectionDTO.getDestination().getGroupId());
ProcessGroupDTO sourceGroup = processGroupDTOMap.get(connectionDTO.getSource().getGroupId());
if (outputPort != null) {
ProcessGroupDTO processGroup = destinationGroup == null ? sourceGroup : destinationGroup;
outputPortIdToGroup.computeIfAbsent(outputPort.getId(), (key) -> new HashSet<ProcessGroupDTO>()).add(processGroup);
groupIdToOutputPorts.computeIfAbsent(processGroup.getId(), (key) -> new HashSet<PortDTO>()).add(outputPort);
if (processGroupWithConnectionsMap.containsKey(processGroup.getId())) {
processGroupWithConnectionsMap.get(processGroup.getId()).addConnection(connectionDTO).addPort(outputPort);
}
}
if (inputPort != null) {
ProcessGroupDTO processGroup = destinationGroup == null ? sourceGroup : destinationGroup;
inputPortIdToGroup.computeIfAbsent(inputPort.getId(), (key) -> new HashSet<ProcessGroupDTO>()).add(processGroup);
groupIdToInputPorts.computeIfAbsent(processGroup.getId(), (key) -> new HashSet<PortDTO>()).add(inputPort);
if (processGroupWithConnectionsMap.containsKey(processGroup.getId())) {
processGroupWithConnectionsMap.get(processGroup.getId()).addConnection(connectionDTO).addPort(outputPort);
}
} else if (destinationGroup != null && sourceGroup != null) {
groupIdToGroup.computeIfAbsent(sourceGroup.getId(), (key) -> new HashSet<String>()).add(destinationGroup.getId());
}
});
// group port connections together
groupIdToOutputPorts.entrySet().stream().forEach(entry -> {
String processGroupId = entry.getKey();
String portKey = entry.getValue().stream().map(portDTO -> portDTO.getId()).sorted().collect(Collectors.joining(","));
portKey = "AAA" + portKey;
layoutGroups.computeIfAbsent(portKey, (key) -> new ProcessGroupToOutputPort(entry.getValue())).add(processGroupDTOMap.get(processGroupId));
});
// group port connections together
groupIdToInputPorts.entrySet().stream().forEach(entry -> {
String processGroupId = entry.getKey();
String portKey = entry.getValue().stream().map(portDTO -> portDTO.getId()).sorted().collect(Collectors.joining(","));
portKey = "BBB" + portKey;
layoutGroups.computeIfAbsent(portKey, (key) -> new InputPortToProcessGroup(entry.getValue())).add(processGroupDTOMap.get(processGroupId));
});
groupIdToGroup.entrySet().stream().forEach(entry -> {
String sourceGroupId = entry.getKey();
String processGroupKey = entry.getValue().stream().sorted().collect(Collectors.joining(","));
processGroupKey = "CCC" + processGroupKey;
layoutGroups.computeIfAbsent(processGroupKey, (key) -> new ProcessGroupToProcessGroup(entry.getValue())).add(processGroupDTOMap.get(entry.getKey()));
});
// add in any groups that dont have connections to ports
processGroupDTOMap.values().stream().filter(processGroupDTO -> !groupIdToGroup.values().stream().flatMap(set -> set.stream()).collect(Collectors.toSet()).contains(processGroupDTO.getId()) && !groupIdToInputPorts.containsKey(processGroupDTO.getId()) && !groupIdToOutputPorts.containsKey(processGroupDTO.getId()) && !groupIdToGroup.containsKey(processGroupDTO.getId())).forEach(group -> {
layoutGroups.computeIfAbsent("NO_PORTS", (key) -> new ProcessGroupWithoutConnections()).add(group);
});
// identify the sequence of processgroups if they are connected to each other
List<String> startingProcessorIds = groupIdToGroup.keySet().stream().filter(id -> !groupIdToGroup.values().stream().anyMatch(ids -> ids.contains(id))).collect(Collectors.toList());
connectedProcessGroups = new ArrayList<>();
// start with these and attempt to create flows
startingProcessorIds.forEach(id -> {
LayoutOrder layoutOrder = new LayoutOrder(0, 0, processGroupDTOMap.get(id), new LinkedList<>());
addPorts(layoutOrder, id);
connectedProcessGroups.add(layoutOrder);
buildLayoutOrder(layoutOrder, processGroupDTOMap.get(id), groupIdToGroup);
ConnectedProcessGroup connectedProcessGroup = new ConnectedProcessGroup(layoutOrder);
connectedProcessGroupsLayouts.add(connectedProcessGroup);
});
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class AlignProcessGroupComponents method buildLayoutOrder.
private void buildLayoutOrder(LayoutOrder layoutOrder, ProcessGroupDTO group, Map<String, Set<String>> groupIdToGroup) {
Set<String> next = groupIdToGroup.get(group.getId());
if (next != null) {
int nextLevel = layoutOrder.getLevel() + 1;
List<ProcessGroupDTO> levelGroups = new LinkedList<>();
next.forEach(dest -> {
if (!processedProcessGroups.contains(dest)) {
processedProcessGroups.add(dest);
int order = 0;
ProcessGroupDTO groupDTO = processGroupDTOMap.get(dest);
levelGroups.add(groupDTO);
LayoutOrder nextOrder = new LayoutOrder(nextLevel, order, groupDTO, levelGroups);
addPorts(nextOrder, dest);
layoutOrder.addNext(nextOrder);
order++;
buildLayoutOrder(nextOrder, groupDTO, groupIdToGroup);
}
});
}
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NifiConnectionOrderVisitor method searchConnectionMatchingSource.
private ConnectionDTO searchConnectionMatchingSource(String parentGroupId, String destinationId) {
// search up to find the connection that matches this dest id
try {
ProcessGroupDTO parent = null;
try {
log.debug("fetch ProcessGroup for searchConnectionMatchingSource {} ", parentGroupId);
parent = getGroup(parentGroupId);
} catch (NifiComponentNotFoundException e) {
log.debug("Exception searching Connection matching the source. Parent Group ID: " + parentGroupId + ", and destinationId of " + destinationId);
}
if (parent != null) {
// processGroup.getDto().setParent(parentParent.getProcessGroup());
// get Contents of this parent
NifiVisitableProcessGroup visitableProcessGroup = new NifiVisitableProcessGroup(parent);
ConnectionDTO conn = visitableProcessGroup.getConnectionMatchingSourceId(destinationId);
if (conn != null) {
return conn;
}
if (conn == null && parent.getParentGroupId() != null) {
return searchConnectionMatchingSource(parent.getParentGroupId(), destinationId);
}
}
} catch (Exception e) {
log.error("Exception searching Connection matching the source. Parent Group ID: " + parentGroupId + ", and destinationId of " + destinationId);
}
return null;
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NifiConnectionOrderVisitor method fetchProcessGroupForNameAndIdentifier.
private ProcessGroupDTO fetchProcessGroupForNameAndIdentifier(String groupId) {
// fetch it
ProcessGroupDTO processGroupEntity = null;
try {
try {
log.debug("fetchProcessGroup {} ", groupId);
processGroupEntity = getGroup(groupId);
} catch (NifiComponentNotFoundException e) {
log.debug("Unable to find the process group " + groupId);
}
} catch (Exception e) {
log.error("Exception fetching the process group " + groupId);
}
return processGroupEntity;
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NifiVisitableProcessGroup method accept.
/**
* Visit this process group using the supplied visitor
*
* @param nifiVisitor the visitor
*/
@Override
public void accept(NifiFlowVisitor nifiVisitor) {
if (dto.getContents() != null) {
if (dto.getContents().getProcessors() != null) {
for (ProcessorDTO processorDTO : dto.getContents().getProcessors()) {
NifiVisitableProcessor processor = getOrCreateProcessor(nifiVisitor, processorDTO);
nifiVisitor.visitProcessor(processor);
}
}
if (dto.getContents().getProcessGroups() != null) {
for (ProcessGroupDTO processGroupDTO : dto.getContents().getProcessGroups()) {
if (processGroupDTO != null) {
nifiVisitor.visitProcessGroup(getOrCreateProcessGroup(nifiVisitor, processGroupDTO));
}
}
}
if (dto.getContents().getConnections() != null) {
for (ConnectionDTO connectionDTO : dto.getContents().getConnections()) {
nifiVisitor.visitConnection(new NifiVisitableConnection(this, connectionDTO));
}
}
populateStartingAndEndingProcessors();
}
}
Aggregations