use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.
the class AbstractValidateImportTemplate method validateNiFiTemplateImport.
/**
* Validate the NiFi template is valid. This method will validate the template can be created/overwritten based upon the user supplied properties
*/
public void validateNiFiTemplateImport() {
// ImportOptions options = template.getImportOptions();
ImportComponentOption nifiTemplateOption = this.importTemplateOptions.findImportComponentOption(ImportComponent.NIFI_TEMPLATE);
// if the options of the TEMPLATE_DATA are marked to import and overwrite this should be as well
ImportComponentOption templateData = this.importTemplateOptions.findImportComponentOption(ImportComponent.TEMPLATE_DATA);
if (templateData.isUserAcknowledged()) {
nifiTemplateOption.setUserAcknowledged(true);
}
if (templateData.isShouldImport()) {
nifiTemplateOption.setShouldImport(true);
}
if (templateData.isOverwrite()) {
nifiTemplateOption.setOverwrite(true);
}
if (nifiTemplateOption.isShouldImport()) {
UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Validating the NiFi template");
String templateName = null;
TemplateDTO dto = null;
try {
templateName = NifiTemplateParser.getTemplateName(this.importTemplate.getNifiTemplateXml());
this.importTemplate.setTemplateName(templateName);
dto = nifiRestClient.getNiFiRestClient().templates().findByName(templateName).orElse(null);
if (dto != null) {
this.importTemplate.setNifiTemplateId(dto.getId());
// if the template incoming is an XML template and it already exists, or if its a zip file and it exists and the user has not acknowledge to overwrite then error out
if ((!this.importTemplateOptions.isUserAcknowledged(ImportComponent.NIFI_TEMPLATE) || this.importTemplateOptions.isUserAcknowledged(ImportComponent.NIFI_TEMPLATE) && !this.importTemplate.isZipFile()) && !this.importTemplateOptions.isImportAndOverwrite(ImportComponent.NIFI_TEMPLATE) && !this.importTemplateOptions.isContinueIfExists(ImportComponent.NIFI_TEMPLATE)) {
this.importTemplate.setValid(false);
String msg = "Unable to import Template " + templateName + ". It already exists in NiFi.";
this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.NIFI_TEMPLATE, msg);
statusMessage.update("Validation Error: Unable to import Template " + templateName + ". It already exists in NiFi.");
statusMessage.complete(false);
} else {
statusMessage.update("Validated the NiFi template. ");
statusMessage.complete(true);
}
} else {
statusMessage.update("Validated the NiFi template. The template " + templateName + " will be created in NiFi");
statusMessage.complete(true);
}
} catch (ParserConfigurationException | XPathExpressionException | IOException | SAXException e) {
getLogger().error("Error validating the file {} for import ", fileName, e);
this.importTemplate.setValid(false);
this.importTemplate.getTemplateResults().addError(NifiError.SEVERITY.WARN, "The xml file you are trying to import is not a valid NiFi template. Please try again. " + e.getMessage(), "");
statusMessage.complete(false);
}
nifiTemplateOption.setValidForImport(!nifiTemplateOption.hasErrorMessages());
}
uploadProgressService.completeSection(importTemplateOptions, ImportSection.Section.VALIDATE_NIFI_TEMPLATE);
}
use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.
the class ImportUtil method inspectZipComponents.
public static Set<ImportComponentOption> inspectZipComponents(InputStream inputStream, ImportType importType) throws IOException {
Set<ImportComponentOption> options = new HashSet<>();
ZipInputStream zis = new ZipInputStream(inputStream);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (entry.getName().startsWith(ImportTemplate.NIFI_TEMPLATE_XML_FILE)) {
options.add(new ImportComponentOption(ImportComponent.NIFI_TEMPLATE, importType.equals(ImportType.TEMPLATE) ? true : false));
} else if (entry.getName().startsWith(ImportTemplate.TEMPLATE_JSON_FILE)) {
options.add(new ImportComponentOption(ImportComponent.TEMPLATE_DATA, importType.equals(ImportType.TEMPLATE) ? true : false));
} else if (entry.getName().startsWith(ImportTemplate.NIFI_CONNECTING_REUSABLE_TEMPLATE_XML_FILE)) {
options.add(new ImportComponentOption(ImportComponent.REUSABLE_TEMPLATE, false));
} else if (entry.getName().startsWith(ImportTemplate.REUSABLE_TEMPLATE_REMOTE_INPUT_PORT_JSON_FILE)) {
options.add(new ImportComponentOption(ImportComponent.REMOTE_INPUT_PORT, false));
} else if (entry.getName().startsWith(ImportTemplate.REUSABLE_TEMPLATE_OUTPUT_CONNECTION_FILE)) {
options.add(new ImportComponentOption(ImportComponent.TEMPLATE_CONNECTION_INFORMATION, true));
} else if (importType.equals(ImportType.FEED) && entry.getName().startsWith(ImportFeed.FEED_JSON_FILE)) {
options.add(new ImportComponentOption(ImportComponent.FEED_DATA, true));
options.add(new ImportComponentOption(ImportComponent.USER_DATASOURCES, true));
}
}
zis.closeEntry();
zis.close();
return options;
}
use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.
the class ImportUtil method applyImportPropertiesToFeed.
public static boolean applyImportPropertiesToFeed(FeedMetadata metadata, ImportFeed importFeed, ImportComponent component) {
ImportComponentOption option = importFeed.getImportOptions().findImportComponentOption(component);
if (!option.getProperties().isEmpty() && option.getProperties().stream().anyMatch(importProperty -> StringUtils.isBlank(importProperty.getPropertyValue()))) {
importFeed.setSuccess(false);
if (importFeed.getTemplate() == null) {
ImportTemplate importTemplate = new ImportTemplate(importFeed.getFileName());
importFeed.setTemplate(importTemplate);
}
String feedCategory = importFeed.getImportOptions().getCategorySystemName() != null ? importFeed.getImportOptions().getCategorySystemName() : metadata.getSystemCategoryName();
String msg = "The feed " + FeedNameUtil.fullName(feedCategory, metadata.getSystemFeedName()) + " needs additional properties to be supplied before importing.";
importFeed.addErrorMessage(metadata, msg);
option.getErrorMessages().add(msg);
return false;
} else {
metadata.getSensitiveProperties().forEach(nifiProperty -> {
ImportProperty userSuppliedValue = importFeed.getImportOptions().getProperties(ImportComponent.FEED_DATA).stream().filter(importFeedProperty -> {
return nifiProperty.getProcessorId().equalsIgnoreCase(importFeedProperty.getProcessorId()) && nifiProperty.getKey().equalsIgnoreCase(importFeedProperty.getPropertyKey());
}).findFirst().orElse(null);
// deal with nulls?
if (userSuppliedValue != null) {
nifiProperty.setValue(userSuppliedValue.getPropertyValue());
}
});
return true;
}
}
use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.
the class IntegrationTestBase method importReusableFlowXmlTemplate.
protected ImportTemplate importReusableFlowXmlTemplate(String templatePath, ReusableTemplateConnectionInfo connectionInfo) {
LOG.info("Importing template {}", templatePath);
List<ImportComponentOption> importComponentOptions = new ArrayList<>();
importComponentOptions.add(new ImportComponentOptionBuilder(ImportComponent.TEMPLATE_DATA).alwaysImport().build());
importComponentOptions.add(new ImportComponentOptionBuilder(ImportComponent.NIFI_TEMPLATE).alwaysImport().build());
importComponentOptions.add(new ImportComponentOptionBuilder(ImportComponent.REUSABLE_TEMPLATE).alwaysImport().build());
if (connectionInfo != null) {
importComponentOptions.add(new ImportComponentOptionBuilder(ImportComponent.TEMPLATE_CONNECTION_INFORMATION).alwaysImport().connectionInfo(connectionInfo).build());
}
String importOptions = ObjectMapperSerializer.serialize(importComponentOptions);
String uploadKey = UUID.randomUUID().toString();
Response post = given(AdminControllerV2.BASE).contentType("multipart/form-data").multiPart(new File(templatePath)).multiPart("uploadKey", uploadKey).multiPart("importComponents", importOptions).when().post(AdminControllerV2.IMPORT_TEMPLATE);
post.then().statusCode(HTTP_OK);
return post.as(ImportTemplate.class);
}
Aggregations