use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class RegisteredTemplateService method getRegisteredTemplateForUpdate.
/**
* Return a registered template object that is populated for use with updating in Kylo
*
* @param registeredTemplateRequest the request to get a registered template
* @return a RegisteredTemplate object mapping either one already defined in Kylo, or a new template that maps to one in NiFi
*/
public RegisteredTemplate getRegisteredTemplateForUpdate(RegisteredTemplateRequest registeredTemplateRequest) {
if (registeredTemplateRequest.isTemplateEdit()) {
this.accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_TEMPLATES);
}
RegisteredTemplate registeredTemplate = null;
// attempt to find the template as a Service
RegisteredTemplateRequest serviceLevelRequest = new RegisteredTemplateRequest(registeredTemplateRequest);
// editing a feed will run as a service account
serviceLevelRequest.setFeedEdit(true);
RegisteredTemplate template = findRegisteredTemplate(serviceLevelRequest);
boolean canEdit = true;
if (template != null && StringUtils.isNotBlank(template.getId()) && registeredTemplateRequest.isTemplateEdit()) {
canEdit = checkTemplatePermission(template.getId(), TemplateAccessControl.EDIT_TEMPLATE);
}
if (canEdit) {
registeredTemplate = template;
if (registeredTemplate == null) {
registeredTemplate = nifiTemplateToRegisteredTemplate(registeredTemplateRequest.getNifiTemplateId());
}
if (registeredTemplate == null) {
// throw exception
} else {
if (StringUtils.isBlank(registeredTemplate.getId()) && template != null && StringUtils.isNotBlank(template.getId())) {
registeredTemplate.setId(template.getId());
}
Set<PortDTO> ports = null;
// fetch ports for this template
try {
if (registeredTemplate.getNifiTemplate() != null) {
ports = nifiRestClient.getPortsForTemplate(registeredTemplate.getNifiTemplate());
} else {
ports = nifiRestClient.getPortsForTemplate(registeredTemplate.getNifiTemplateId());
}
} catch (NifiComponentNotFoundException notFoundException) {
syncNiFiTemplateId(registeredTemplate);
ports = nifiRestClient.getPortsForTemplate(registeredTemplate.getNifiTemplateId());
}
if (ports == null) {
ports = new HashSet<>();
}
List<PortDTO> outputPorts = ports.stream().filter(portDTO -> portDTO != null && NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name().equalsIgnoreCase(portDTO.getType())).collect(Collectors.toList());
List<PortDTO> inputPorts = ports.stream().filter(portDTO -> portDTO != null && NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name().equalsIgnoreCase(portDTO.getType())).collect(Collectors.toList());
registeredTemplate.setReusableTemplate(inputPorts != null && !inputPorts.isEmpty());
List<ReusableTemplateConnectionInfo> reusableTemplateConnectionInfos = registeredTemplate.getReusableTemplateConnections();
List<ReusableTemplateConnectionInfo> updatedConnectionInfo = new ArrayList<>();
for (final PortDTO port : outputPorts) {
ReusableTemplateConnectionInfo reusableTemplateConnectionInfo = null;
if (reusableTemplateConnectionInfos != null && !reusableTemplateConnectionInfos.isEmpty()) {
reusableTemplateConnectionInfo = Iterables.tryFind(reusableTemplateConnectionInfos, reusableTemplateConnectionInfo1 -> reusableTemplateConnectionInfo1.getFeedOutputPortName().equalsIgnoreCase(port.getName())).orNull();
}
if (reusableTemplateConnectionInfo == null) {
reusableTemplateConnectionInfo = new ReusableTemplateConnectionInfo();
reusableTemplateConnectionInfo.setFeedOutputPortName(port.getName());
}
updatedConnectionInfo.add(reusableTemplateConnectionInfo);
}
registeredTemplate.setReusableTemplateConnections(updatedConnectionInfo);
registeredTemplate.initializeProcessors();
ensureRegisteredTemplateInputProcessors(registeredTemplate);
}
}
return registeredTemplate;
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class ImportReusableTemplate method connectReusableFlow.
private ProcessGroupDTO connectReusableFlow(UploadProgressMessage importStatusMessage, NifiProcessGroup newTemplateInstance) {
String templateName = this.importTemplate.getTemplateName();
ImportComponentOption componentOption = importTemplateOptions.findImportComponentOption(ImportComponent.TEMPLATE_CONNECTION_INFORMATION);
ProcessGroupDTO processGroupDTO = newTemplateInstance.getProcessGroupEntity();
Set<PortDTO> inputPorts = getReusableTemplateInputPorts();
Set<ConnectionDTO> reusableTemplateConnections = getReusableTemplateConnections();
if (componentOption != null && !componentOption.getConnectionInfo().isEmpty()) {
// connect the output port to the input port
// we are connecting a reusable template back to another reusable template
// follow the input port destination connection to its internal process group port
Set<ConnectionDTO> newConnections = new HashSet<>();
String reusableTemplateProcessGroupId = getReusableTemplatesProcessGroupId();
if (reusableTemplateProcessGroupId != null) {
for (ReusableTemplateConnectionInfo connectionInfo : componentOption.getConnectionInfo()) {
String reusableTemplateInputPortName = connectionInfo.getReusableTemplateInputPortName();
// find the portdto matching this name in the reusable template group
/**
* The connection coming from the 'reusableTemplateInputPortName' to the next input port
*/
Optional<ConnectionDTO> connectionToUse = Optional.empty();
/**
* The port that matches the 'reusableTemplateInputPortName connection destination
*/
Optional<PortDTO> sourcePort = Optional.empty();
connectionToUse = inputPorts.stream().filter(portDTO -> portDTO.getName().equalsIgnoreCase(reusableTemplateInputPortName)).findFirst().flatMap(portToInspect -> reusableTemplateConnections.stream().filter(connectionDTO -> connectionDTO.getDestination().getType().equalsIgnoreCase(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name()) && connectionDTO.getSource().getId().equalsIgnoreCase(portToInspect.getId())).findFirst());
if (connectionToUse.isPresent()) {
sourcePort = newTemplateInstance.getProcessGroupEntity().getContents().getOutputPorts().stream().filter(portDTO -> portDTO.getName().equalsIgnoreCase(connectionInfo.getFeedOutputPortName())).findFirst();
}
if (sourcePort.isPresent()) {
// make the connection now from the output port to the 'connectionToUse' destination
ConnectableDTO source = NifiConnectionUtil.asConnectable(sourcePort.get());
ConnectableDTO dest = NifiConnectionUtil.asNewConnectable(connectionToUse.get().getDestination());
ConnectionDTO newConnection = nifiRestClient.getNiFiRestClient().processGroups().createConnection(reusableTemplateProcessGroupId, source, dest);
newConnections.add(newConnection);
connections.add(newConnection);
log.info("Connected the output port {} ({}) to another reusable template input port: {} {{}). The public reusable template port name is: {} ", source.getName(), source.getId(), dest.getName(), dest.getId(), reusableTemplateInputPortName);
uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Connected this template '" + templateName + "' with '" + reusableTemplateInputPortName + "' connected to '" + sourcePort.get().getName() + "'", true, true);
} else {
// log.error("Unable to find a connection to connect the reusable template together. Please verify the Input Port named '{}' under the 'reusable_templates' group has a connection going to another input port",reusableTemplateInputPortName);
// importTemplate.getTemplateResults().addError(NifiError.SEVERITY.FATAL, "Unable to connect the reusable template to the designated input port: '" + reusableTemplateInputPortName + "'. Please verify the Input Port named '" + reusableTemplateInputPortName + "' under the 'reusable_templates' group has a connection going to another input port. You may need to re-import the template with this input port. ", "");
// importStatusMessage.update("Unable to connect the reusable template to the designated input port: "+reusableTemplateInputPortName, false);
// uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Unable to connect this template '"+templateName+"' with '"+reusableTemplateInputPortName,true,false);
// break;
}
}
}
if (!newConnections.isEmpty()) {
// requery for the ports to check validity again
processGroupDTO = nifiRestClient.getNiFiRestClient().processGroups().findById(newTemplateInstance.getProcessGroupEntity().getId(), false, true).orElse(processGroupDTO);
// reset it back to the newTemplateInstance
newTemplateInstance.updateProcessGroupContent(processGroupDTO);
}
}
return processGroupDTO;
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class ImportReusableTemplate method markExistingRemoteInputPorts.
private boolean markExistingRemoteInputPorts(ImportComponentOption remoteProcessGroupOption, Map<String, RemoteProcessGroupInputPort> remoteProcessGroupInputPortMap, Map<String, PortDTO> thisTemplatePorts, boolean isNew) {
String rootProcessGroupId = templateConnectionUtil.getRootProcessGroup().getId();
// This will get or create the reusable_template process group
String reusableTemplateProcessGroupId = templateConnectionUtil.getReusableTemplateProcessGroupId();
// Select the userSupplied ports from the whole list
Map<String, RemoteProcessGroupInputPort> userSuppliedRemoteInputPorts = remoteProcessGroupOption.getRemoteProcessGroupInputPortsForTemplate(importTemplate.getTemplateName()).stream().collect(Collectors.toMap(inputPort -> inputPort.getInputPortName(), inputPort -> inputPort));
Optional<TemplateRemoteInputPortConnections> existingRemoteProcessInputPortInformation = getExistingRemoteProcessInputPortInformation();
if (existingRemoteProcessInputPortInformation.isPresent()) {
// mark the items in the this.remoteProcessGroupInputPortMap as 'existing' if they are already in NiFi, and 'selected' if the user has selected them
existingRemoteProcessInputPortInformation.get().getExistingRemoteConnectionsToTemplate().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) && thisTemplatePorts.containsKey(conn.getDestination().getName())).map(conn -> thisTemplatePorts.get(conn.getDestination().getName())).filter(p -> remoteProcessGroupInputPortMap.containsKey(p.getName())).map(port -> remoteProcessGroupInputPortMap.get(port.getName())).forEach(remoteProcessGroupInputPort -> {
remoteProcessGroupInputPort.setSelected(isNew || (userSuppliedRemoteInputPorts.containsKey(remoteProcessGroupInputPort.getInputPortName()) && userSuppliedRemoteInputPorts.get(remoteProcessGroupInputPort.getInputPortName()).isSelected()));
remoteProcessGroupInputPort.setExisting(true);
RemoteProcessGroupInputPort userSuppliedPort = userSuppliedRemoteInputPorts.get(remoteProcessGroupInputPort.getInputPortName());
if (userSuppliedPort != null) {
userSuppliedPort.setExisting(true);
}
});
}
remoteProcessGroupInputPortMap.values().stream().filter(inputPort -> userSuppliedRemoteInputPorts.containsKey(inputPort.getInputPortName())).forEach(inputPort -> inputPort.setSelected(true));
// warn if not existing, but has the same name as an already existing input port in the root process group
Set<String> rootInputPorts = nifiRestClient.getNiFiRestClient().processGroups().getInputPorts(rootProcessGroupId).stream().map(inputPort -> inputPort.getName()).collect(Collectors.toSet());
Set<String> portAlreadyExists = remoteProcessGroupInputPortMap.values().stream().filter(remoteProcessGroupInputPort -> !remoteProcessGroupInputPort.isExisting() && rootInputPorts.contains(remoteProcessGroupInputPort.getInputPortName())).map(remoteProcessGroupInputPort -> remoteProcessGroupInputPort.getInputPortName()).collect(Collectors.toSet());
if (!portAlreadyExists.isEmpty()) {
importTemplate.getTemplateResults().addError(NifiError.SEVERITY.FATAL, " The input port names " + portAlreadyExists.stream().collect(Collectors.joining(",")) + " already exists as a remote port for another template.", "");
remoteProcessGroupOption.getErrorMessages().add("The input port names " + portAlreadyExists.stream().collect(Collectors.joining(",")) + " already exists as a remote port for another template.");
importTemplate.setSuccess(false);
importTemplate.setValid(false);
importTemplate.setRemoteProcessGroupInputPortsNeeded(true);
return false;
}
return true;
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class IntegrationTestBase method deleteExistingReusableVersionedFlows.
protected void deleteExistingReusableVersionedFlows() {
LOG.info("Deleting existing reusable versioned flows");
// otherwise if we don't delete each time we import a new template
// exiting templates are versioned off and keep piling up
PortDTO[] ports = getReusableInputPorts();
for (PortDTO port : ports) {
deleteVersionedNifiFlow(port.getParentGroupId());
}
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class IntegrationTestBase method getReusableInputPorts.
protected PortDTO[] getReusableInputPorts() {
Response response = given(NifiIntegrationRestController.BASE).when().get(NifiIntegrationRestController.REUSABLE_INPUT_PORTS);
response.then().statusCode(HTTP_OK);
return response.as(PortDTO[].class);
}
Aggregations