use of com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup in project kylo by Teradata.
the class LegacyNifiRestClient method createNewTemplateInstance.
public NifiProcessGroup createNewTemplateInstance(String templateId, List<NifiProperty> templateProperties, Map<String, Object> staticConfigProperties, boolean createReusableFlow, ReusableTemplateCreationCallback creationCallback, String versionIdentifier) {
TemplateInstanceCreator creator = new TemplateInstanceCreator(this, templateId, templateProperties, staticConfigProperties, createReusableFlow, creationCallback, versionIdentifier);
NifiProcessGroup group = creator.createTemplate();
return group;
}
use of com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup in project kylo by Teradata.
the class ImportReusableTemplate method connect.
private boolean connect() {
NifiProcessGroup processGroup = this.newTemplateInstance;
UploadProgressMessage importStatusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Connecting and validating components for " + importTemplate.getTemplateName());
connectReusableFlow(importStatusMessage, processGroup);
recreateOutputPortConnections(importStatusMessage, processGroup);
boolean valid = validateOutputPortConnections(processGroup);
importStatusMessage.update("Connected and validated components for " + importTemplate.getTemplateName(), valid);
// create any remote process group ports and connect them on the main NiFi canvas
if (isClustered()) {
ImportComponentOption remoteProcessGroupOption = importTemplateOptions.findImportComponentOption(ImportComponent.REMOTE_INPUT_PORT);
if (remoteProcessGroupOption.isUserAcknowledged() && remoteProcessGroupOption.isShouldImport()) {
if (remoteProcessGroupOption.getRemoteProcessGroupInputPortsForTemplate(importTemplate.getTemplateName()).stream().anyMatch(inputPort -> inputPort.isSelected())) {
UploadProgressMessage remoteInputPortsMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Creating remote input port connections for " + remoteProcessGroupOption.getRemoteProcessGroupInputPortsForTemplate(importTemplate.getTemplateName()).stream().filter(inputPort -> inputPort.isSelected()).map(inputPort -> inputPort.getInputPortName()).collect(Collectors.joining(",")));
valid &= createRemoteInputPorts(remoteInputPortsMessage);
}
}
if (remoteProcessGroupOption.isShouldImport() && remoteProcessGroupOption.isUserAcknowledged()) {
// identify if the user wished to remove any input ports.
valid = removeConnectionsAndInputs();
}
}
return valid && newTemplateInstance.isSuccess();
}
use of com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup 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 com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup in project kylo by Teradata.
the class ImportReusableTemplate method create.
@Override
public NifiProcessGroup create(NiFiTemplateImport niFiTemplateImport, UploadProgressMessage importStatusMessage) {
TemplateDTO dto = niFiTemplateImport.getDto();
String templateName = importTemplate.getTemplateName();
String fileName = importTemplate.getFileName();
importStatusMessage.update("Creating reusable flow instance for " + templateName);
log.info("Creating a Reusable flow template instance in Nifi. Template: {} for file {}", templateName, fileName);
Map<String, Object> configProperties = propertyExpressionResolver.getStaticConfigProperties();
NifiFlowCacheReusableTemplateCreationCallback reusableTemplateCreationCallback = new NifiFlowCacheReusableTemplateCreationCallback();
List<NifiProperty> templateProperties = importTemplate.getTemplateToImport() != null ? importTemplate.getTemplateToImport().getProperties() : Collections.emptyList();
NifiProcessGroup newTemplateInstance = nifiRestClient.createNewTemplateInstance(dto.getId(), templateProperties, configProperties, true, reusableTemplateCreationCallback, importTemplate.getVersionIdentifier());
if (newTemplateInstance.getVersionedProcessGroup() != null && StringUtils.isNotBlank(newTemplateInstance.getVersionedProcessGroup().getVersionedProcessGroupName())) {
uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Versioned off previous flow with the name: " + newTemplateInstance.getVersionedProcessGroup().getVersionedProcessGroupName(), true, true);
}
importTemplate.setTemplateResults(newTemplateInstance);
return newTemplateInstance;
}
use of com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup in project kylo by Teradata.
the class ImportUtil method applyImportPropertiesToTemplate.
public static boolean applyImportPropertiesToTemplate(RegisteredTemplate template, ImportTemplate importTemplate, ImportComponent component) {
ImportComponentOption option = importTemplate.getImportOptions().findImportComponentOption(component);
if (!option.getProperties().isEmpty() && option.getProperties().stream().anyMatch(importProperty -> StringUtils.isBlank(importProperty.getPropertyValue()))) {
importTemplate.setSuccess(false);
importTemplate.setTemplateResults(new NifiProcessGroup());
String msg = "Unable to import Template. Additional properties to be supplied before importing.";
importTemplate.getTemplateResults().addError(NifiError.SEVERITY.WARN, msg, "");
option.getErrorMessages().add(msg);
return false;
} else {
template.getSensitiveProperties().forEach(nifiProperty -> {
ImportProperty userSuppliedValue = option.getProperties().stream().filter(importFeedProperty -> nifiProperty.getProcessorId().equalsIgnoreCase(importFeedProperty.getProcessorId()) && nifiProperty.getKey().equalsIgnoreCase(importFeedProperty.getPropertyKey())).findFirst().orElse(null);
// deal with nulls?
if (userSuppliedValue == null) {
// attempt to find it via the name
userSuppliedValue = option.getProperties().stream().filter(importFeedProperty -> nifiProperty.getProcessorName().equalsIgnoreCase(importFeedProperty.getProcessorName()) && nifiProperty.getKey().equalsIgnoreCase(importFeedProperty.getPropertyKey())).findFirst().orElse(null);
}
if (userSuppliedValue != null) {
nifiProperty.setValue(userSuppliedValue.getPropertyValue());
}
});
return true;
}
}
Aggregations