use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NifiIntegrationRestController method autoAlign.
@GET
@Path("/auto-align/{processGroupId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Organizes the components of the specified process group.")
@ApiResponses(@ApiResponse(code = 200, message = "The result of the operation.", response = RestResponseStatus.class))
public Response autoAlign(@PathParam("processGroupId") String processGroupId) {
accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ADMIN_FEEDS);
RestResponseStatus status;
if ("all".equals(processGroupId)) {
AlignNiFiComponents alignNiFiComponents = new AlignNiFiComponents();
alignNiFiComponents.setNiFiRestClient(legacyNifiRestClient.getNiFiRestClient());
alignNiFiComponents.autoLayout();
String message = "";
if (alignNiFiComponents.isAligned()) {
message = "Aligned All of NiFi. " + alignNiFiComponents.getAlignedProcessGroups() + " process groups were aligned ";
} else {
message = "Alignment failed while attempting to align all of NiFi. " + alignNiFiComponents.getAlignedProcessGroups() + " were successfully aligned. Please look at the logs for more information";
}
status = new RestResponseStatus.ResponseStatusBuilder().message(message).buildSuccess();
} else {
AlignProcessGroupComponents alignProcessGroupComponents = new AlignProcessGroupComponents(legacyNifiRestClient.getNiFiRestClient(), processGroupId);
ProcessGroupDTO alignedGroup = alignProcessGroupComponents.autoLayout();
String message = "";
if (alignProcessGroupComponents.isAligned()) {
message = "Aligned " + alignedGroup.getContents().getProcessGroups().size() + " process groups under " + alignedGroup.getName();
} else {
message = "Alignment failed for process group " + processGroupId + ". Please look at the logs for more information";
}
status = new RestResponseStatus.ResponseStatusBuilder().message(message).buildSuccess();
}
return Response.ok(status).build();
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class DefaultTemplateExporter method gatherConnectedReusableTemplates.
private void gatherConnectedReusableTemplates(List<String> connectingReusableTemplates, Set<String> connectedTemplateIds, Set<ReusableTemplateConnectionInfo> connectingOutputPortConnectionMetadata, List<ReusableTemplateConnectionInfo> reusableTemplateConnectionInfos, ProcessGroupFlowDTO reusableTemplateFlow) {
for (ReusableTemplateConnectionInfo reusableTemplateConnectionInfo : reusableTemplateConnectionInfos) {
String inputName = reusableTemplateConnectionInfo.getReusableTemplateInputPortName();
// find the process group instance in the 'reusable_templates' group in NiFi for this input port
Optional<ProcessGroupDTO> processGroupDTO = reusableTemplateFlow.getFlow().getConnections().stream().map(connectionEntity -> connectionEntity.getComponent()).filter(connectionDTO -> connectionDTO.getSource().getName().equals(inputName) && connectionDTO.getSource().getType().equals(NifiConstants.INPUT_PORT)).flatMap(connectionDTO -> reusableTemplateFlow.getFlow().getProcessGroups().stream().map(processGroupEntity -> processGroupEntity.getComponent()).filter(groupDTO -> groupDTO.getId().equals(connectionDTO.getDestination().getGroupId()))).findFirst();
if (processGroupDTO.isPresent()) {
// walk the output ports to find any other connecting templates
List<ReusableTemplateConnectionInfo> outputPortConnectionMetadata = new ArrayList<>();
List<ConnectionDTO> outputPortConnections = reusableTemplateFlow.getFlow().getConnections().stream().map(connectionEntity -> connectionEntity.getComponent()).filter(connectionDTO -> connectionDTO.getSource().getGroupId().equals(processGroupDTO.get().getId()) && connectionDTO.getSource().getType().equals(NifiConstants.OUTPUT_PORT)).collect(Collectors.toList());
for (ConnectionDTO outputConnection : outputPortConnections) {
// walk these and get their templates
// first get the connection metadata info needed
// 1 find the reusable template input port for this connected template
Optional<ConnectionDTO> inputPortToProcessGroupConnection = reusableTemplateFlow.getFlow().getConnections().stream().map(connectionEntity -> connectionEntity.getComponent()).filter(connectionDTO -> connectionDTO.getDestination().getId().equals(outputConnection.getDestination().getId()) && connectionDTO.getSource().getType().equals(NifiConstants.INPUT_PORT)).findFirst();
if (inputPortToProcessGroupConnection.isPresent()) {
ReusableTemplateConnectionInfo connectionInfo = new ReusableTemplateConnectionInfo();
connectionInfo.setFeedOutputPortName(outputConnection.getSource().getName());
connectionInfo.setReusableTemplateInputPortName(inputPortToProcessGroupConnection.get().getSource().getName());
connectionInfo.setInputPortDisplayName(inputPortToProcessGroupConnection.get().getSource().getName());
String processGroupName = reusableTemplateFlow.getFlow().getProcessGroups().stream().filter(processGroupEntity -> processGroupEntity.getComponent().getId().equals(inputPortToProcessGroupConnection.get().getDestination().getGroupId())).map(processGroupEntity -> processGroupEntity.getComponent().getName()).findFirst().orElse(null);
connectionInfo.setReusableTemplateProcessGroupName(processGroupName);
outputPortConnectionMetadata.add(connectionInfo);
// recursively walk these flows and gather other output port connections
connectingOutputPortConnectionMetadata.add(connectionInfo);
}
// also add in the process group if it doesnt connect
}
if (!outputPortConnectionMetadata.isEmpty()) {
gatherConnectedReusableTemplates(connectingReusableTemplates, connectedTemplateIds, connectingOutputPortConnectionMetadata, outputPortConnectionMetadata, reusableTemplateFlow);
}
}
// find the template that has the input port name
Map<String, String> map = nifiRestClient.getTemplatesAsXmlMatchingInputPortName(inputName, reusableTemplateConnectionInfo.getReusableTemplateProcessGroupName());
if (map != null && !map.isEmpty()) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String portTemplateId = entry.getKey();
if (!connectedTemplateIds.contains(portTemplateId)) {
connectedTemplateIds.add(portTemplateId);
connectingReusableTemplates.add(entry.getValue());
}
}
}
}
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class ImportReusableTemplate method validateOutputPortConnections.
private boolean validateOutputPortConnections(NifiProcessGroup newTemplateInstance) {
// Validate port connections
newTemplateInstance.getProcessGroupEntity().getContents().getOutputPorts().stream().forEach(portDTO -> {
if (portDTO.getValidationErrors() != null && !portDTO.getValidationErrors().isEmpty()) {
importTemplate.setReusableFlowOutputPortConnectionsNeeded(true);
}
ReusableTemplateConnectionInfo connectionInfo = new ReusableTemplateConnectionInfo();
connectionInfo.setFeedOutputPortName(portDTO.getName());
// attempt to prefill it with the previous connection if it existed
ConnectionDTO reusableTemplateInputPortConnection = findReusableTemplateInputPortConnectionForOutputPort(portDTO);
if (reusableTemplateInputPortConnection != null) {
connectionInfo.setInputPortDisplayName(reusableTemplateInputPortConnection.getSource().getName());
connectionInfo.setReusableTemplateInputPortName(reusableTemplateInputPortConnection.getSource().getName());
String processGroupName = findReusableTemplateProcessGroup(reusableTemplateInputPortConnection.getDestination().getGroupId()).map(processGroupDTO -> processGroupDTO.getName()).orElse(null);
connectionInfo.setReusableTemplateProcessGroupName(processGroupName);
}
importTemplate.addReusableTemplateConnection(connectionInfo);
});
return importTemplate.isSuccess() && importTemplate.isValid() && !importTemplate.isReusableFlowOutputPortConnectionsNeeded();
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NifiRestTest2 method testEvent.
// @Test
public void testEvent() {
try {
ProcessGroupDTO dto = restClient.getProcessGroupByName("root", "jhim");
// ProcessGroupEntity entity= restClient.getProcessGroup("3813381f-2205-414c-bfcf-5900f45fcf601234",true,true);
int i = 0;
} catch (Exception e) {
if (e instanceof NotFoundException) {
int i = 0;
} else if (e instanceof ProcessingException) {
if (e.getCause() instanceof NoHttpResponseException) {
// connection error
} else if (e.getCause() instanceof HttpHostConnectException) {
// connection error
}
}
}
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project nifi-minifi by apache.
the class FlowSnippetDTOEnricher method enrich.
public void enrich(FlowSnippetDTO flowSnippetDTO, final String encodingVersion) {
List<FlowSnippetDTO> allFlowSnippets = getAllFlowSnippets(flowSnippetDTO);
Set<RemoteProcessGroupDTO> remoteProcessGroups = getAll(allFlowSnippets, FlowSnippetDTO::getRemoteProcessGroups).collect(Collectors.toSet());
Map<String, String> connectableNameMap = getAll(allFlowSnippets, FlowSnippetDTO::getProcessors).collect(Collectors.toMap(ComponentDTO::getId, ProcessorDTO::getName));
Map<String, String> rpgIdToTargetIdMap = new HashMap<>();
for (RemoteProcessGroupDTO remoteProcessGroupDTO : remoteProcessGroups) {
final RemoteProcessGroupContentsDTO contents = remoteProcessGroupDTO.getContents();
final Set<RemoteProcessGroupPortDTO> rpgInputPortDtos = nullToEmpty(contents.getInputPorts());
final Set<RemoteProcessGroupPortDTO> rpgOutputPortDtos = nullToEmpty(contents.getOutputPorts());
switch(encodingVersion) {
case "1.2":
// Map all port DTOs to their respective targetIds
rpgIdToTargetIdMap.putAll(Stream.concat(rpgInputPortDtos.stream(), rpgOutputPortDtos.stream()).collect(Collectors.toMap(RemoteProcessGroupPortDTO::getId, RemoteProcessGroupPortDTO::getTargetId)));
break;
default:
break;
}
addConnectables(connectableNameMap, rpgInputPortDtos, RemoteProcessGroupPortDTO::getId, RemoteProcessGroupPortDTO::getId);
addConnectables(connectableNameMap, rpgOutputPortDtos, RemoteProcessGroupPortDTO::getId, RemoteProcessGroupPortDTO::getId);
}
addConnectables(connectableNameMap, getAll(allFlowSnippets, FlowSnippetDTO::getInputPorts).collect(Collectors.toList()), PortDTO::getId, PortDTO::getName);
addConnectables(connectableNameMap, getAll(allFlowSnippets, FlowSnippetDTO::getOutputPorts).collect(Collectors.toList()), PortDTO::getId, PortDTO::getName);
final Set<ConnectionDTO> connections = getAll(allFlowSnippets, FlowSnippetDTO::getConnections).collect(Collectors.toSet());
// Enrich connection endpoints using known names and overriding with targetIds for remote ports
for (ConnectionDTO connection : connections) {
setName(connectableNameMap, connection.getSource(), rpgIdToTargetIdMap);
setName(connectableNameMap, connection.getDestination(), rpgIdToTargetIdMap);
}
// Override any ids that are for Remote Ports to use their target Ids where available
connections.stream().flatMap(connectionDTO -> Stream.of(connectionDTO.getSource(), connectionDTO.getDestination())).filter(connectable -> connectable.getType().equals(ConnectableType.REMOTE_OUTPUT_PORT.toString()) || connectable.getType().equals(ConnectableType.REMOTE_INPUT_PORT.toString())).forEach(connectable -> connectable.setId(Optional.ofNullable(rpgIdToTargetIdMap.get(connectable.getId())).orElse(connectable.getId())));
// Establish unique names for connections
for (ConnectionDTO connection : connections) {
if (StringUtil.isNullOrEmpty(connection.getName())) {
StringBuilder name = new StringBuilder();
ConnectableDTO connectionSource = connection.getSource();
name.append(determineValueForConnectable(connectionSource, rpgIdToTargetIdMap));
name.append("/");
if (connection.getSelectedRelationships() != null && connection.getSelectedRelationships().size() > 0) {
name.append(connection.getSelectedRelationships().iterator().next());
}
name.append("/");
ConnectableDTO connectionDestination = connection.getDestination();
name.append(determineValueForConnectable(connectionDestination, rpgIdToTargetIdMap));
connection.setName(name.toString());
}
}
nullToEmpty(flowSnippetDTO.getProcessGroups()).stream().map(ProcessGroupDTO::getContents).forEach(snippetDTO -> enrich(snippetDTO, encodingVersion));
}
Aggregations