use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class LegacyNifiRestClient method stopInputPort.
public PortDTO stopInputPort(String groupId, String portId) throws NifiClientRuntimeException {
PortDTO portDTO = new PortDTO();
portDTO.setId(portId);
portDTO.setState(NifiProcessUtil.PROCESS_STATE.STOPPED.name());
return client.ports().updateInputPort(groupId, portDTO);
}
use of org.apache.nifi.web.api.dto.PortDTO 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.PortDTO in project kylo by Teradata.
the class AlignProcessGroupComponents method alignPorts.
private void alignPorts(Collection<PortDTO> ports, AbstractRenderer renderer) {
ports.stream().forEach(port -> {
PortDTO positionPort = new PortDTO();
positionPort.setId(port.getId());
PositionDTO lastPosition = renderer.getLastPosition();
PositionDTO newPosition = renderer.getNextPosition(lastPosition);
positionPort.setPosition(newPosition);
niFiRestClient.ports().updateInputPort(parentProcessGroupId, positionPort);
log.debug("Aligned Port {} at {},{}", port.getName(), positionPort.getPosition().getX(), positionPort.getPosition().getY());
});
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class AbstractNiFiTemplatesRestClientTest method findByInputPortName.
/**
* Verifies finding templates by an input port name
*/
@Test
public void findByInputPortName() {
// Mock templates with only basic info
final TemplateDTO basicTemplate1 = new TemplateDTO();
basicTemplate1.setId("cf54ca27-ccb0-49a1-94f2-2834c4379b70");
final TemplateDTO basicTemplate2 = new TemplateDTO();
basicTemplate2.setId("43ce4a07-10ac-40c0-b195-598bc753988b");
final TemplateDTO basicTemplate3 = new TemplateDTO();
basicTemplate3.setId("7f57c685-f9dd-497e-8e97-7d1e6d43b59c");
// Mock templates with port info
final PortDTO port1 = new PortDTO();
port1.setId("ee77fc99-2f19-43d3-ae26-091f9caa1401");
port1.setName("to-other-template");
final PortDTO port2 = new PortDTO();
port2.setId("1b2a3c92-1964-4f87-9835-b8a19f024249");
port2.setName("to-standard-ingest");
final FlowSnippetDTO flow1 = new FlowSnippetDTO();
flow1.setInputPorts(ImmutableSet.of(port1));
final FlowSnippetDTO flow2 = new FlowSnippetDTO();
flow2.setInputPorts(ImmutableSet.of(port2));
final TemplateDTO fullTemplate1 = new TemplateDTO();
fullTemplate1.setId("cf54ca27-ccb0-49a1-94f2-2834c4379b70");
fullTemplate1.setSnippet(flow1);
final TemplateDTO fullTemplate2 = new TemplateDTO();
fullTemplate2.setId("43ce4a07-10ac-40c0-b195-598bc753988b");
fullTemplate2.setSnippet(flow2);
// Mock the NiFi Templates REST client
final NiFiTemplatesRestClient client = Mockito.mock(AbstractNiFiTemplatesRestClient.class, Mockito.CALLS_REAL_METHODS);
Mockito.when(client.findAll()).thenReturn(ImmutableSet.of(basicTemplate1, basicTemplate2, basicTemplate3));
Mockito.when(client.findById("cf54ca27-ccb0-49a1-94f2-2834c4379b70")).thenReturn(Optional.of(fullTemplate1));
Mockito.when(client.findById("43ce4a07-10ac-40c0-b195-598bc753988b")).thenReturn(Optional.of(fullTemplate2));
Mockito.when(client.findById("7f57c685-f9dd-497e-8e97-7d1e6d43b59c")).thenReturn(Optional.empty());
// Test finding matching templates
final Set<TemplateDTO> matches = client.findByInputPortName("to-standard-ingest");
Assert.assertEquals(fullTemplate2, matches.stream().findFirst().get());
Assert.assertEquals(0, client.findByInputPortName("invalid").size());
}
use of org.apache.nifi.web.api.dto.PortDTO in project nifi by apache.
the class StandardNiFiServiceFacade method getSiteToSiteDetails.
@Override
public ControllerDTO getSiteToSiteDetails() {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
if (user == null) {
throw new WebApplicationException(new Throwable("Unable to access details for current user."));
}
// serialize the input ports this NiFi has access to
final Set<PortDTO> inputPortDtos = new LinkedHashSet<>();
final Set<RootGroupPort> inputPorts = controllerFacade.getInputPorts();
for (final RootGroupPort inputPort : inputPorts) {
if (isUserAuthorized(user, inputPort)) {
final PortDTO dto = new PortDTO();
dto.setId(inputPort.getIdentifier());
dto.setName(inputPort.getName());
dto.setComments(inputPort.getComments());
dto.setState(inputPort.getScheduledState().toString());
inputPortDtos.add(dto);
}
}
// serialize the output ports this NiFi has access to
final Set<PortDTO> outputPortDtos = new LinkedHashSet<>();
for (final RootGroupPort outputPort : controllerFacade.getOutputPorts()) {
if (isUserAuthorized(user, outputPort)) {
final PortDTO dto = new PortDTO();
dto.setId(outputPort.getIdentifier());
dto.setName(outputPort.getName());
dto.setComments(outputPort.getComments());
dto.setState(outputPort.getScheduledState().toString());
outputPortDtos.add(dto);
}
}
// get the root group
final ProcessGroup rootGroup = processGroupDAO.getProcessGroup(controllerFacade.getRootGroupId());
final ProcessGroupCounts counts = rootGroup.getCounts();
// create the controller dto
final ControllerDTO controllerDTO = new ControllerDTO();
controllerDTO.setId(controllerFacade.getRootGroupId());
controllerDTO.setInstanceId(controllerFacade.getInstanceId());
controllerDTO.setName(controllerFacade.getName());
controllerDTO.setComments(controllerFacade.getComments());
controllerDTO.setInputPorts(inputPortDtos);
controllerDTO.setOutputPorts(outputPortDtos);
controllerDTO.setInputPortCount(inputPortDtos.size());
controllerDTO.setOutputPortCount(outputPortDtos.size());
controllerDTO.setRunningCount(counts.getRunningCount());
controllerDTO.setStoppedCount(counts.getStoppedCount());
controllerDTO.setInvalidCount(counts.getInvalidCount());
controllerDTO.setDisabledCount(counts.getDisabledCount());
// determine the site to site configuration
controllerDTO.setRemoteSiteListeningPort(controllerFacade.getRemoteSiteListeningPort());
controllerDTO.setRemoteSiteHttpListeningPort(controllerFacade.getRemoteSiteListeningHttpPort());
controllerDTO.setSiteToSiteSecure(controllerFacade.isRemoteSiteCommsSecure());
return controllerDTO;
}
Aggregations