use of org.apache.nifi.web.api.dto.ConnectionDTO in project kylo by Teradata.
the class TemplateConnectionUtil method getRemoteInputPortsForReusableTemplate.
public Optional<TemplateRemoteInputPortConnections> getRemoteInputPortsForReusableTemplate(ProcessGroupDTO reusableTemplateProcessGroup, String templateName) {
if (reusableTemplateProcessGroup == null || reusableTemplateProcessGroup.getContents() == null) {
reusableTemplateProcessGroup = getReusableTemplateCategoryProcessGroup(true);
}
String templateGroupId = reusableTemplateProcessGroup.getContents().getProcessGroups().stream().filter(g -> g.getName().equalsIgnoreCase(templateName)).map(g -> g.getId()).findFirst().orElse(null);
if (templateGroupId != null) {
String reusableTemplateProcessGroupId = reusableTemplateProcessGroup.getId();
String rootProcessGroupId = this.getRootProcessGroup().getId();
List<String> reusableTemplateInputPortIds = reusableTemplateProcessGroup.getContents().getConnections().stream().filter(conn -> conn.getDestination().getGroupId().equalsIgnoreCase(templateGroupId)).map(connectionDTO -> connectionDTO.getSource().getId()).collect(Collectors.toList());
List<ConnectionDTO> remoteConnectionsToTemplate = getRootProcessGroupConnections().stream().filter(conn -> conn.getDestination().getType().equalsIgnoreCase(NifiConstants.INPUT_PORT) && conn.getDestination().getGroupId().equalsIgnoreCase(reusableTemplateProcessGroupId) && conn.getSource().getGroupId().equalsIgnoreCase(rootProcessGroupId) && conn.getSource().getType().equalsIgnoreCase(NifiConstants.INPUT_PORT) && reusableTemplateInputPortIds.contains(conn.getDestination().getId())).collect(Collectors.toList());
Set<String> remoteInputPorts = remoteConnectionsToTemplate.stream().map(conn -> conn.getSource().getName()).collect(Collectors.toSet());
return Optional.of(new TemplateRemoteInputPortConnections(remoteConnectionsToTemplate, remoteInputPorts));
}
return Optional.empty();
}
use of org.apache.nifi.web.api.dto.ConnectionDTO in project kylo by Teradata.
the class TemplateConnectionUtil method getRemoteInputPortsForReusableTemplate.
public Optional<TemplateRemoteInputPortConnections> getRemoteInputPortsForReusableTemplate(ProcessGroupFlowDTO reusableTemplateProcessGroup, String templateName) {
String templateGroupId = reusableTemplateProcessGroup.getFlow().getProcessGroups().stream().filter(g -> g.getComponent().getName().equalsIgnoreCase(templateName)).map(g -> g.getId()).findFirst().orElse(null);
if (templateGroupId != null) {
String reusableTemplateProcessGroupId = reusableTemplateProcessGroup.getId();
String rootProcessGroupId = this.getRootProcessGroup().getId();
List<String> reusableTemplateInputPortIds = reusableTemplateProcessGroup.getFlow().getConnections().stream().filter(conn -> conn.getComponent().getDestination().getGroupId().equalsIgnoreCase(templateGroupId)).map(conn -> conn.getComponent().getSource().getId()).collect(Collectors.toList());
List<ConnectionDTO> remoteConnectionsToTemplate = getRootProcessGroupConnections().stream().filter(conn -> conn.getDestination().getType().equalsIgnoreCase(NifiConstants.INPUT_PORT) && conn.getDestination().getGroupId().equalsIgnoreCase(reusableTemplateProcessGroupId) && conn.getSource().getGroupId().equalsIgnoreCase(rootProcessGroupId) && conn.getSource().getType().equalsIgnoreCase(NifiConstants.INPUT_PORT) && reusableTemplateInputPortIds.contains(conn.getDestination().getId())).collect(Collectors.toList());
Set<String> remoteInputPorts = remoteConnectionsToTemplate.stream().map(conn -> conn.getSource().getName()).collect(Collectors.toSet());
return Optional.of(new TemplateRemoteInputPortConnections(remoteConnectionsToTemplate, remoteInputPorts));
}
return Optional.empty();
}
use of org.apache.nifi.web.api.dto.ConnectionDTO in project kylo by Teradata.
the class TemplateConnectionUtil method getAllReusableTemplateRemoteInputPorts.
public Optional<TemplateRemoteInputPortConnections> getAllReusableTemplateRemoteInputPorts() {
ProcessGroupDTO reusableTemplateProcessGroup = getReusableTemplateCategoryProcessGroup(true);
String reusableTemplateProcessGroupId = reusableTemplateProcessGroup.getId();
String rootProcessGroupId = this.getRootProcessGroup().getId();
List<String> reusableTemplateGroupIds = reusableTemplateProcessGroup.getContents().getProcessGroups().stream().map(groupDTO -> groupDTO.getId()).collect(Collectors.toList());
if (reusableTemplateGroupIds != null && !reusableTemplateGroupIds.isEmpty()) {
List<String> reusableTemplateInputPortIds = reusableTemplateProcessGroup.getContents().getConnections().stream().filter(conn -> reusableTemplateGroupIds.contains(conn.getDestination().getGroupId())).map(connectionDTO -> connectionDTO.getSource().getId()).collect(Collectors.toList());
List<ConnectionDTO> remoteConnectionsToTemplate = getRootProcessGroupConnections().stream().filter(conn -> conn.getDestination().getType().equalsIgnoreCase(NifiConstants.INPUT_PORT) && conn.getDestination().getGroupId().equalsIgnoreCase(reusableTemplateProcessGroupId) && conn.getSource().getGroupId().equalsIgnoreCase(rootProcessGroupId) && conn.getSource().getType().equalsIgnoreCase(NifiConstants.INPUT_PORT) && reusableTemplateInputPortIds.contains(conn.getDestination().getId())).collect(Collectors.toList());
Set<String> remoteInputPorts = remoteConnectionsToTemplate.stream().map(conn -> conn.getSource().getName()).collect(Collectors.toSet());
return Optional.of(new TemplateRemoteInputPortConnections(remoteConnectionsToTemplate, remoteInputPorts));
}
return Optional.empty();
}
use of org.apache.nifi.web.api.dto.ConnectionDTO in project kylo by Teradata.
the class ImportReusableTemplate method createRemoteInputPorts.
private boolean createRemoteInputPorts(UploadProgressMessage remoteInputPortsMessage) {
ImportComponentOption remoteProcessGroupOption = importTemplateOptions.findImportComponentOption(ImportComponent.REMOTE_INPUT_PORT);
String rootProcessGroupId = templateConnectionUtil.getRootProcessGroup().getId();
String reusableTemplateProcessGroupId = templateConnectionUtil.getReusableTemplateProcessGroupId();
Map<String, PortDTO> reusableTemplateCategoryPorts = getReusableTemplateCategoryProcessGroup().getContents().getInputPorts().stream().collect(Collectors.toMap(p -> p.getName(), p -> p));
StringBuffer connectedStr = new StringBuffer("");
remoteProcessGroupOption.getRemoteProcessGroupInputPortsForTemplate(importTemplate.getTemplateName()).stream().filter(r -> r.isSelected() && !r.isExisting()).forEach(r -> {
// check/create the port at the parent canvas
PortDTO portDTO = new PortDTO();
portDTO.setName(r.getInputPortName());
portDTO.setType(NifiConstants.INPUT_PORT);
portDTO.setState(NifiProcessUtil.PROCESS_STATE.STOPPED.name());
PortDTO newInputPort = nifiRestClient.getNiFiRestClient().processGroups().createInputPort(rootProcessGroupId, portDTO);
getItemsCreated().addCreatedRemoteInputPort(newInputPort);
PortDTO reusableTemplatePort = reusableTemplateCategoryPorts.get(r.getInputPortName());
// connect this to the Reusable Template input port with the same name
ConnectableDTO source = new ConnectableDTO();
source.setGroupId(rootProcessGroupId);
source.setId(newInputPort.getId());
source.setName(newInputPort.getName());
source.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name());
ConnectableDTO dest = new ConnectableDTO();
dest.setGroupId(reusableTemplateProcessGroupId);
dest.setName(r.getInputPortName());
dest.setId(reusableTemplatePort.getId());
dest.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name());
ConnectionDTO connectionDTO = nifiRestClient.getNiFiRestClient().processGroups().createConnection(rootProcessGroupId, source, dest);
getItemsCreated().addCreatedRemoteInputPortConnection(connectionDTO);
if (connectedStr.length() != 0) {
connectedStr.append(",");
} else {
connectedStr.append("Created ");
}
// enable the input port
try {
newInputPort.setState(NifiProcessUtil.PROCESS_STATE.RUNNING.name());
nifiRestClient.getNiFiRestClient().ports().updateInputPort(newInputPort.getParentGroupId(), newInputPort);
} catch (Exception e) {
}
connectedStr.append(r.getInputPortName());
remoteInputPortsMessage.update(connectedStr.toString());
});
if (connectedStr.length() != 0) {
connectedStr.append(" as remote input ports");
}
if (connectedStr.length() > 0) {
remoteInputPortsMessage.update(connectedStr.toString(), true);
} else {
remoteInputPortsMessage.complete(true);
}
return true;
}
use of org.apache.nifi.web.api.dto.ConnectionDTO in project kylo by Teradata.
the class ImportReusableTemplate method rollbackCreatedItems.
/**
* Rollback and delete any created items
* restore any items that were deleted
*/
private void rollbackCreatedItems() {
getItemsCreated().getCreatedRemoteInputPortConnections().stream().forEach(connection -> nifiRestClient.deleteConnection(connection, false));
getItemsCreated().getCreatedRemoteInputPorts().stream().forEach(portDTO -> nifiRestClient.getNiFiRestClient().ports().deleteInputPort(portDTO.getId()));
Map<String, String> oldToNewPortIdMap = new HashMap<>();
getItemsCreated().getDeletedRemoteInputPorts().stream().forEach(portDTO -> {
PortDTO createdPort = nifiRestClient.getNiFiRestClient().processGroups().createInputPort(portDTO.getParentGroupId(), portDTO);
oldToNewPortIdMap.put(portDTO.getId(), createdPort.getId());
});
// find matching connection
Map<String, String> newReusableTemplatePortNameToId = new HashMap<>();
String reusableTemplateProcessGroupId = templateConnectionUtil.getReusableTemplateProcessGroupId();
if (reusableTemplateProcessGroupId != null) {
ProcessGroupFlowDTO reusableTemplateFlow = nifiRestClient.getNiFiRestClient().processGroups().flow(reusableTemplateProcessGroupId);
String templateProcessGroupId = reusableTemplateFlow.getFlow().getProcessGroups().stream().filter(e -> e.getComponent().getName().equalsIgnoreCase(this.importTemplate.getTemplateName())).map(e -> e.getComponent().getId()).findFirst().orElse(null);
if (templateProcessGroupId != null) {
reusableTemplateFlow.getFlow().getConnections().stream().filter(connectionEntity -> connectionEntity.getComponent().getDestination().getGroupId().equalsIgnoreCase(templateProcessGroupId) && connectionEntity.getComponent().getSource().getType().equalsIgnoreCase(NifiConstants.INPUT_PORT)).forEach(connectionEntity -> {
newReusableTemplatePortNameToId.put(connectionEntity.getComponent().getSource().getName(), connectionEntity.getComponent().getSource().getId());
});
}
}
String rootProcessGroupId = templateConnectionUtil.getRootProcessGroup().getId();
getItemsCreated().getDeletedRemoteInputPortConnections().stream().forEach(connectionDTO -> {
String newId = oldToNewPortIdMap.get(connectionDTO.getSource().getId());
connectionDTO.getSource().setId(newId);
String newDestId = newReusableTemplatePortNameToId.get(connectionDTO.getSource().getName());
connectionDTO.getDestination().setId(newDestId);
ConnectionDTO restoredConnection = nifiRestClient.getNiFiRestClient().processGroups().createConnection(rootProcessGroupId, connectionDTO.getSource(), connectionDTO.getDestination());
});
}
Aggregations