use of org.apache.nifi.web.api.dto.flow.FlowDTO in project nifi by apache.
the class FlowSnippetEndpointMerger method merge.
@Override
public NodeResponse merge(final URI uri, final String method, Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final NodeResponse clientResponse) {
final FlowEntity responseEntity = clientResponse.getClientResponse().readEntity(FlowEntity.class);
final FlowDTO flowDto = responseEntity.getFlow();
if (flowDto == null) {
return clientResponse;
} else {
final Map<String, Map<NodeIdentifier, ProcessorEntity>> processorMap = new HashMap<>();
final Map<String, Map<NodeIdentifier, RemoteProcessGroupEntity>> remoteProcessGroupMap = new HashMap<>();
for (final NodeResponse nodeResponse : successfulResponses) {
final FlowEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(FlowEntity.class);
final FlowDTO nodeContents = nodeResponseEntity.getFlow();
for (final ProcessorEntity nodeProcessor : nodeContents.getProcessors()) {
Map<NodeIdentifier, ProcessorEntity> innerMap = processorMap.computeIfAbsent(nodeProcessor.getId(), id -> new HashMap<>());
innerMap.put(nodeResponse.getNodeId(), nodeProcessor);
}
for (final RemoteProcessGroupEntity nodeRemoteProcessGroup : nodeContents.getRemoteProcessGroups()) {
Map<NodeIdentifier, RemoteProcessGroupEntity> innerMap = remoteProcessGroupMap.computeIfAbsent(nodeRemoteProcessGroup.getId(), id -> new HashMap<>());
innerMap.put(nodeResponse.getNodeId(), nodeRemoteProcessGroup);
}
}
final ProcessorEndpointMerger procMerger = new ProcessorEndpointMerger();
for (final ProcessorEntity processor : flowDto.getProcessors()) {
final String procId = processor.getId();
final Map<NodeIdentifier, ProcessorEntity> mergeMap = processorMap.get(procId);
procMerger.mergeResponses(processor, mergeMap, successfulResponses, problematicResponses);
}
final RemoteProcessGroupEndpointMerger rpgMerger = new RemoteProcessGroupEndpointMerger();
for (final RemoteProcessGroupEntity remoteProcessGroup : flowDto.getRemoteProcessGroups()) {
final String remoteProcessGroupId = remoteProcessGroup.getId();
final Map<NodeIdentifier, RemoteProcessGroupEntity> mergeMap = remoteProcessGroupMap.get(remoteProcessGroupId);
rpgMerger.mergeResponses(remoteProcessGroup, mergeMap, successfulResponses, problematicResponses);
}
}
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
use of org.apache.nifi.web.api.dto.flow.FlowDTO in project kylo by Teradata.
the class ImportReusableTemplate method cleanup.
public void cleanup() {
if (newTemplateInstance != null) {
String templateName = importTemplate.getTemplateName();
VersionedProcessGroup versionedProcessGroup = newTemplateInstance.getVersionedProcessGroup();
if (versionedProcessGroup != null) {
// ensure we have contents in the versionedProcess group
if (versionedProcessGroup.getVersionedProcessGroup().getContents() == null) {
FlowDTO flowDTO = nifiRestClient.getNiFiRestClient().processGroups().flow(versionedProcessGroup.getVersionedProcessGroup().getId()).getFlow();
if (flowDTO != null) {
versionedProcessGroup.getVersionedProcessGroup().setContents(NifiFlowUtil.flowToFlowSnippet(flowDTO));
}
}
// importTemplate.getTemplateResults().getVersionedProcessGroup().getVersionedProcessGroup()
uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "The Reusable template " + templateName + " is valid. Attempting to clean up and remove the previous instance ", true, true);
// if the versioned group doesnt have anything in queue delete it
Optional<ProcessGroupStatusDTO> status = nifiRestClient.getNiFiRestClient().processGroups().getStatus(versionedProcessGroup.getVersionedProcessGroup().getId());
if (!status.isPresent() || (status.isPresent() && status.get().getAggregateSnapshot().getFlowFilesQueued() > 0)) {
uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Warning! The previous version of this template '" + templateName + "', now located in NiFi under the process group '" + versionedProcessGroup.getVersionedProcessGroupName() + "' still has items in queue. Unable to delete it. ", true, true);
// if the versioned group still had items in queue then wire it back up to the newly created group
// ?? are they still wired up to the output ports
log.info("Unable to delete versioned group '{}' Items are still in queue", versionedProcessGroup.getVersionedProcessGroupName());
// stop the inputs and mark the rest as running
versionedProcessGroup.getVersionedProcessGroup().getContents().getInputPorts().stream().forEach(portDTO -> {
nifiRestClient.stopInputPort(versionedProcessGroup.getVersionedProcessGroup().getId(), portDTO.getId());
});
// start the output ports
versionedProcessGroup.getVersionedProcessGroup().getContents().getOutputPorts().stream().forEach(portDTO -> {
nifiRestClient.startOutputPort(versionedProcessGroup.getVersionedProcessGroup().getId(), portDTO.getId());
});
} else {
// delete the versioned group
try {
nifiRestClient.removeProcessGroup(importTemplate.getTemplateResults().getVersionedProcessGroup().getVersionedProcessGroup().getId(), importTemplate.getTemplateResults().getVersionedProcessGroup().getVersionedProcessGroup().getParentGroupId());
} catch (NifiClientRuntimeException e) {
log.error("Template has sucessfully imported, but Kylo is unable to remove versioned process group '{}' with id '{}'. You will need to go into NiFi and manually remove it.", versionedProcessGroup.getVersionedProcessGroupName(), versionedProcessGroup.getVersionedProcessGroup().getId());
uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Warning! Unable to remove the previous version of this template, process group: '" + versionedProcessGroup.getVersionedProcessGroupName() + "' with id of " + versionedProcessGroup.getVersionedProcessGroup().getId() + ". You will need to manually delete it from NiFi. ", true, false);
}
}
}
}
}
use of org.apache.nifi.web.api.dto.flow.FlowDTO in project nifi by apache.
the class StandardNiFiServiceFacade method createTemplateInstance.
@Override
public FlowEntity createTemplateInstance(final String groupId, final Double originX, final Double originY, final String templateEncodingVersion, final FlowSnippetDTO requestSnippet, final String idGenerationSeed) {
// instantiate the template - there is no need to make another copy of the flow snippet since the actual template
// was copied and this dto is only used to instantiate it's components (which as already completed)
final FlowSnippetDTO snippet = templateDAO.instantiateTemplate(groupId, originX, originY, templateEncodingVersion, requestSnippet, idGenerationSeed);
// save the flow
controllerFacade.save();
// post process the new flow snippet
final FlowDTO flowDto = postProcessNewFlowSnippet(groupId, snippet);
final FlowEntity flowEntity = new FlowEntity();
flowEntity.setFlow(flowDto);
return flowEntity;
}
use of org.apache.nifi.web.api.dto.flow.FlowDTO in project nifi by apache.
the class JerseyFlowClient method getSuggestedProcessGroupCoordinates.
@Override
public ProcessGroupBox getSuggestedProcessGroupCoordinates(final String parentId) throws NiFiClientException, IOException {
if (StringUtils.isBlank(parentId)) {
throw new IllegalArgumentException("Process group id cannot be null");
}
final ProcessGroupFlowEntity processGroup = getProcessGroup(parentId);
final ProcessGroupFlowDTO processGroupFlowDTO = processGroup.getProcessGroupFlow();
final FlowDTO flowDTO = processGroupFlowDTO.getFlow();
final List<ComponentEntity> pgComponents = new ArrayList<>();
pgComponents.addAll(flowDTO.getProcessGroups());
pgComponents.addAll(flowDTO.getProcessors());
pgComponents.addAll(flowDTO.getRemoteProcessGroups());
pgComponents.addAll(flowDTO.getConnections());
pgComponents.addAll(flowDTO.getFunnels());
pgComponents.addAll(flowDTO.getInputPorts());
pgComponents.addAll(flowDTO.getOutputPorts());
pgComponents.addAll(flowDTO.getLabels());
final Set<PositionDTO> positions = pgComponents.stream().map(ComponentEntity::getPosition).collect(Collectors.toSet());
if (positions.isEmpty()) {
return ProcessGroupBox.CANVAS_CENTER;
}
final List<ProcessGroupBox> coords = positions.stream().filter(Objects::nonNull).map(p -> new ProcessGroupBox(p.getX().intValue(), p.getY().intValue())).collect(Collectors.toList());
final ProcessGroupBox freeSpot = coords.get(0).findFreeSpace(coords);
return freeSpot;
}
use of org.apache.nifi.web.api.dto.flow.FlowDTO in project nifi by apache.
the class StandardNiFiServiceFacade method postProcessNewFlowSnippet.
/**
* Post processes a new flow snippet including validation, removing the snippet, and DTO conversion.
*
* @param groupId group id
* @param snippet snippet
* @return flow dto
*/
private FlowDTO postProcessNewFlowSnippet(final String groupId, final FlowSnippetDTO snippet) {
// validate the new snippet
validateSnippetContents(snippet);
// identify all components added
final Set<String> identifiers = new HashSet<>();
snippet.getProcessors().stream().map(proc -> proc.getId()).forEach(id -> identifiers.add(id));
snippet.getConnections().stream().map(conn -> conn.getId()).forEach(id -> identifiers.add(id));
snippet.getInputPorts().stream().map(port -> port.getId()).forEach(id -> identifiers.add(id));
snippet.getOutputPorts().stream().map(port -> port.getId()).forEach(id -> identifiers.add(id));
snippet.getProcessGroups().stream().map(group -> group.getId()).forEach(id -> identifiers.add(id));
snippet.getRemoteProcessGroups().stream().map(remoteGroup -> remoteGroup.getId()).forEach(id -> identifiers.add(id));
snippet.getRemoteProcessGroups().stream().filter(remoteGroup -> remoteGroup.getContents() != null && remoteGroup.getContents().getInputPorts() != null).flatMap(remoteGroup -> remoteGroup.getContents().getInputPorts().stream()).map(remoteInputPort -> remoteInputPort.getId()).forEach(id -> identifiers.add(id));
snippet.getRemoteProcessGroups().stream().filter(remoteGroup -> remoteGroup.getContents() != null && remoteGroup.getContents().getOutputPorts() != null).flatMap(remoteGroup -> remoteGroup.getContents().getOutputPorts().stream()).map(remoteOutputPort -> remoteOutputPort.getId()).forEach(id -> identifiers.add(id));
snippet.getLabels().stream().map(label -> label.getId()).forEach(id -> identifiers.add(id));
final ProcessGroup group = processGroupDAO.getProcessGroup(groupId);
final ProcessGroupStatus groupStatus = controllerFacade.getProcessGroupStatus(groupId);
return dtoFactory.createFlowDto(group, groupStatus, snippet, revisionManager, this::getProcessGroupBulletins);
}
Aggregations