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 TemplateCreationHelper method updateControllerServiceReferences.
/**
* Fix references to the controller services on the processor properties
*
* @param processors processors to inspect
* @param controllerServiceProperties property overrides for controller services
* @return the list of properties that were modified
*/
public List<NifiProperty> updateControllerServiceReferences(List<ProcessorDTO> processors, Map<String, String> controllerServiceProperties, TemplateInstance instance) {
try {
processors = reassignControllerServiceIds(processors, instance);
// merge the snapshotted services with the newly created ones and update respective processors in the newly created flow
final Map<String, ControllerServiceDTO> enabledServices = new HashMap<>();
Map<String, ControllerServiceDTO> allServices = mergedControllerServices;
for (ControllerServiceDTO dto : allServices.values()) {
if (NifiProcessUtil.SERVICE_STATE.ENABLED.name().equals(dto.getState())) {
enabledServices.put(dto.getId(), dto);
enabledServices.put(dto.getName(), dto);
}
}
List<NifiProperty> properties = new ArrayList<>();
Map<String, ProcessGroupDTO> processGroupDTOMap = new HashMap<>();
for (ProcessorDTO dto : processors) {
ProcessGroupDTO groupDTO = processGroupDTOMap.get(dto.getParentGroupId());
if (groupDTO == null) {
// we can create a tmp group dto here as all we need is the id
groupDTO = new ProcessGroupDTO();
groupDTO.setId(dto.getParentGroupId());
groupDTO.setName(dto.getParentGroupId());
processGroupDTOMap.put(dto.getParentGroupId(), groupDTO);
}
properties.addAll(NifiPropertyUtil.getPropertiesForProcessor(groupDTO, dto, restClient.getPropertyDescriptorTransform()));
}
List<NifiProperty> updatedProperties = fixControllerServiceReferences(controllerServiceProperties, enabledServices, allServices, properties);
updatedProperties.forEach(property -> restClient.updateProcessorProperty(property.getProcessGroupId(), property.getProcessorId(), property));
return updatedProperties;
} catch (NifiClientRuntimeException e) {
errors.add(new NifiError(NifiError.SEVERITY.FATAL, "Error trying to identify Controller Services. " + e.getMessage(), NifiProcessGroup.CONTROLLER_SERVICE_CATEGORY));
}
return Collections.emptyList();
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NiFiObjectCache method ensureReusableTemplateProcessGroup.
public void ensureReusableTemplateProcessGroup() {
ProcessGroupDTO processGroupToCheck = null;
if (reusableTemplateCategory != null) {
processGroupToCheck = restClient.getNiFiRestClient().processGroups().findById(reusableTemplateCategory.getId(), false, false).orElse(null);
}
if (processGroupToCheck == null) {
processGroupToCheck = restClient.getProcessGroupByName("root", reusableTemplateCategoryName);
}
if (processGroupToCheck == null) {
// create it
processGroupToCheck = restClient.createProcessGroup("root", reusableTemplateCategoryName);
}
if (processGroupToCheck != null && (reusableTemplateCategory == null || processGroupToCheck.getId().equalsIgnoreCase(reusableTemplateCategory.getId()))) {
reusableTemplateCategory = processGroupToCheck;
reusableTemplateProcessGroupId = processGroupToCheck.getId();
}
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NiFiObjectCache method getReusableTemplateInputPort.
/**
* return the matching inputport in the 'reusable_templates' process group
*/
public PortDTO getReusableTemplateInputPort(String inputPortName) {
if (reusableTemplateCategoryInputPortsByName.containsKey(inputPortName)) {
return reusableTemplateCategoryInputPortsByName.get(inputPortName);
} else {
ProcessGroupDTO reusableTemplateCategoryGroupId = getReusableTemplateCategoryProcessGroup();
Set<PortDTO> inputPortsEntity = restClient.getNiFiRestClient().processGroups().getInputPorts(reusableTemplateCategoryGroupId.getId());
if (inputPortsEntity != null) {
inputPortsEntity.stream().forEach(inputPort -> reusableTemplateCategoryInputPortsByName.put(inputPort.getName(), inputPort));
PortDTO inputPort = NifiConnectionUtil.findPortMatchingName(inputPortsEntity, inputPortName);
return inputPort;
}
}
return null;
}
use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.
the class NiFiProcessGroupsRestClientV1 method create.
public ProcessGroupDTO create(@Nonnull String parentProcessGroupId, @Nonnull String name, @Nullable Double x, @Nullable Double y) {
final ProcessGroupEntity entity = new ProcessGroupEntity();
final ProcessGroupDTO processGroup = new ProcessGroupDTO();
processGroup.setName(name);
if (x != null && y != null) {
processGroup.setPosition(new PositionDTO(x, y));
}
entity.setComponent(processGroup);
final RevisionDTO revision = new RevisionDTO();
revision.setVersion(0L);
entity.setRevision(revision);
try {
return getClient().post(BASE_PATH + parentProcessGroupId + "/process-groups", entity, ProcessGroupEntity.class).getComponent();
} catch (final NotFoundException e) {
throw new NifiComponentNotFoundException(parentProcessGroupId, NifiConstants.NIFI_COMPONENT_TYPE.PROCESS_GROUP, e);
}
}
Aggregations