use of com.thinkbiganalytics.feedmgr.service.template.importing.model.NiFiTemplateImport in project kylo by Teradata.
the class AbstractImportTemplateRoutine method importIntoNiFi.
/**
* Import a template string into NiFi as a template to use
*/
public NiFiTemplateImport importIntoNiFi(ImportTemplate template, ImportTemplateOptions importOptions) throws ImportException {
TemplateDTO dto = null;
String templateName = null;
String oldTemplateXml = null;
ImportComponentOption nifiTemplateImport = importOptions.findImportComponentOption(ImportComponent.NIFI_TEMPLATE);
if (nifiTemplateImport.isValidForImport()) {
try {
templateName = NifiTemplateParser.getTemplateName(template.getNifiTemplateXml());
template.setTemplateName(templateName);
dto = nifiRestClient.getTemplateByName(templateName);
if (dto != null) {
oldTemplateXml = nifiRestClient.getTemplateXml(dto.getId());
template.setNifiTemplateId(dto.getId());
if (importOptions.isImportAndOverwrite(ImportComponent.NIFI_TEMPLATE) && nifiTemplateImport.isValidForImport()) {
nifiRestClient.deleteTemplate(dto.getId());
} else if (!template.isZipFile()) {
// if its not a zip file we need to error out if the user has decided not to overwrite when it already exists
uploadProgressService.addUploadStatus(importOptions.getUploadKey(), "The template " + templateName + " already exists in NiFi. Please choose the option to replace the template and try again.", true, false);
template.setValid(false);
}
}
} catch (ParserConfigurationException | XPathExpressionException | IOException | SAXException e) {
throw new ImportException("The xml file you are trying to import is not a valid NiFi template. Please try again. " + e.getMessage());
}
boolean register = (dto == null || (importOptions.isImportAndOverwrite(ImportComponent.NIFI_TEMPLATE) && nifiTemplateImport.isValidForImport()));
// attempt to import the xml into NiFi if its new, or if the user said to overwrite
if (register) {
UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(importOptions.getUploadKey(), "Importing " + templateName + " into NiFi");
log.info("Attempting to import Nifi Template: {} for file {}", templateName, template.getFileName());
dto = nifiRestClient.importTemplate(template.getTemplateName(), template.getNifiTemplateXml());
template.setNifiTemplateId(dto.getId());
statusMessage.update("Imported " + templateName + " into NiFi", true);
}
}
uploadProgressService.completeSection(importOptions, ImportSection.Section.IMPORT_NIFI_TEMPLATE);
return new NiFiTemplateImport(oldTemplateXml, dto);
}
Aggregations