use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class LegacyNifiRestClient method connectFeedToGlobalTemplate.
/**
* Connect a Feed to a reusable Template
*/
public void connectFeedToGlobalTemplate(final String feedProcessGroupId, final String feedOutputName, final String categoryProcessGroupId, String reusableTemplateCategoryGroupId, String inputPortName) throws NifiComponentNotFoundException {
ProcessGroupDTO categoryProcessGroup = getProcessGroup(categoryProcessGroupId, false, false);
ProcessGroupDTO feedProcessGroup = getProcessGroup(feedProcessGroupId, false, false);
ProcessGroupDTO categoryParent = getProcessGroup(categoryProcessGroup.getParentGroupId(), false, false);
ProcessGroupDTO reusableTemplateCategoryGroup = getProcessGroup(reusableTemplateCategoryGroupId, false, false);
// Go into the Feed and find the output port that is to be associated with the global template
Set<PortDTO> outputPortsEntity = getOutputPorts(feedProcessGroupId);
PortDTO feedOutputPort = null;
if (outputPortsEntity != null) {
feedOutputPort = NifiConnectionUtil.findPortMatchingName(outputPortsEntity, feedOutputName);
}
if (feedOutputPort == null) {
// ERROR This feed needs to have an output port assigned on it to make the connection
}
Set<PortDTO> inputPortsEntity = getInputPorts(reusableTemplateCategoryGroupId);
PortDTO inputPort = NifiConnectionUtil.findPortMatchingName(inputPortsEntity, inputPortName);
String inputPortId = inputPort.getId();
final String categoryOutputPortName = categoryProcessGroup.getName() + " to " + inputPort.getName();
// Find or create the output port that will join to the globabl template at the Category Level
Set<PortDTO> categoryOutputPortsEntity = getOutputPorts(categoryProcessGroupId);
PortDTO categoryOutputPort = null;
if (categoryOutputPortsEntity != null) {
categoryOutputPort = NifiConnectionUtil.findPortMatchingName(categoryOutputPortsEntity, categoryOutputPortName);
}
if (categoryOutputPort == null) {
// create it
PortDTO portDTO = new PortDTO();
portDTO.setParentGroupId(categoryProcessGroupId);
portDTO.setName(categoryOutputPortName);
categoryOutputPort = client.processGroups().createOutputPort(categoryProcessGroupId, portDTO);
}
// Now create a connection from the Feed PRocessGroup to this outputPortEntity
ConnectionDTO feedOutputToCategoryOutputConnection = NifiConnectionUtil.findConnection(findConnectionsForParent(categoryProcessGroupId), feedOutputPort.getId(), categoryOutputPort.getId());
if (feedOutputToCategoryOutputConnection == null) {
// CONNECT FEED OUTPUT PORT TO THE Category output port
ConnectableDTO source = new ConnectableDTO();
source.setGroupId(feedProcessGroupId);
source.setId(feedOutputPort.getId());
source.setName(feedProcessGroup.getName());
source.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name());
ConnectableDTO dest = new ConnectableDTO();
dest.setGroupId(categoryProcessGroupId);
dest.setName(categoryOutputPort.getName());
dest.setId(categoryOutputPort.getId());
dest.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name());
createConnection(categoryProcessGroup.getId(), source, dest);
}
ConnectionDTO categoryToReusableTemplateConnection = NifiConnectionUtil.findConnection(findConnectionsForParent(categoryParent.getId()), categoryOutputPort.getId(), inputPortId);
// Now connect the category PRocessGroup to the global template
if (categoryToReusableTemplateConnection == null) {
ConnectableDTO categorySource = new ConnectableDTO();
categorySource.setGroupId(categoryProcessGroupId);
categorySource.setId(categoryOutputPort.getId());
categorySource.setName(categoryOutputPortName);
categorySource.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name());
ConnectableDTO categoryToGlobalTemplate = new ConnectableDTO();
categoryToGlobalTemplate.setGroupId(reusableTemplateCategoryGroupId);
categoryToGlobalTemplate.setId(inputPortId);
categoryToGlobalTemplate.setName(inputPortName);
categoryToGlobalTemplate.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name());
createConnection(categoryParent.getId(), categorySource, categoryToGlobalTemplate);
}
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class LegacyNifiRestClient method getPortsForProcessGroup.
public Set<PortDTO> getPortsForProcessGroup(String processGroupId) throws NifiComponentNotFoundException {
Set<PortDTO> ports = new HashSet<>();
ProcessGroupDTO processGroupEntity = getProcessGroup(processGroupId, false, true);
Set<PortDTO> inputPorts = processGroupEntity.getContents().getInputPorts();
if (inputPorts != null) {
ports.addAll(inputPorts);
}
Set<PortDTO> outputPorts = processGroupEntity.getContents().getOutputPorts();
if (outputPorts != null) {
ports.addAll(outputPorts);
}
return ports;
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class LegacyNifiRestClient method deleteChildProcessGroups.
public List<ProcessGroupDTO> deleteChildProcessGroups(String processGroupId) throws NifiClientRuntimeException {
List<ProcessGroupDTO> deletedEntities = new ArrayList<>();
ProcessGroupDTO entity = getProcessGroup(processGroupId, true, true);
if (entity != null && entity.getContents().getProcessGroups() != null) {
for (ProcessGroupDTO groupDTO : entity.getContents().getProcessGroups()) {
deletedEntities.add(deleteProcessGroup(groupDTO));
}
}
return deletedEntities;
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class LegacyNifiRestClient method getPropertiesForTemplate.
/**
* @param parentProcessGroup the parent group for which this template will reside
* @param dto the template to parse
* @param includePropertyDescriptors true to include propertyDescriptor details on each property, false to just include the property key
* @return all the properties included in this template
*/
public List<NifiProperty> getPropertiesForTemplate(ProcessGroupDTO parentProcessGroup, TemplateDTO dto, boolean includePropertyDescriptors) {
if (includePropertyDescriptors) {
TemplateCreationHelper helper = new TemplateCreationHelper(this, niFiObjectCache);
ProcessGroupDTO groupDTO = helper.createTemporaryTemplateFlow(dto.getId());
dto.setSnippet(groupDTO.getContents());
}
return NifiPropertyUtil.getPropertiesForTemplate(parentProcessGroup, dto, propertyDescriptorTransform);
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class AlignNiFiComponents method autoLayout.
/**
* layout the NiFi components
*/
public void autoLayout() {
AlignProcessGroupComponents alignProcessGroupComponents = new AlignProcessGroupComponents(niFiRestClient, "root", new AlignComponentsConfig());
ProcessGroupDTO root = alignProcessGroupComponents.autoLayout();
// align all of roots children
aligned = alignProcessGroupComponents.isAligned();
root.getContents().getProcessGroups().stream().forEach(processGroupDTO -> {
AlignProcessGroupComponents categoryAlign = new AlignProcessGroupComponents(niFiRestClient, processGroupDTO.getId(), new AlignComponentsConfig());
ProcessGroupDTO groupDTO = categoryAlign.autoLayout();
if (categoryAlign.isAligned() && groupDTO != null && groupDTO.getContents() != null && groupDTO.getContents().getProcessGroups() != null) {
alignedProcessGroups += groupDTO.getContents().getProcessGroups().size();
}
aligned &= categoryAlign.isAligned();
});
}
Aggregations