Search in sources :

Example 21 with ImportComponentOption

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);
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 22 with ImportComponentOption

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;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) HashSet(java.util.HashSet)

Example 23 with ImportComponentOption

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;
    }
}
Also used : FeedDataTransformation(com.thinkbiganalytics.feedmgr.rest.model.FeedDataTransformation) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) StringUtils(org.apache.commons.lang3.StringUtils) ImportOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportOptions) HashSet(java.util.HashSet) ObjectMapperSerializer(com.thinkbiganalytics.json.ObjectMapperSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) ImportProperty(com.thinkbiganalytics.feedmgr.rest.model.ImportProperty) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ImportType(com.thinkbiganalytics.feedmgr.rest.ImportType) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) ZipEntry(java.util.zip.ZipEntry) Nonnull(javax.annotation.Nonnull) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) StringWriter(java.io.StringWriter) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ZipFileUtil(com.thinkbiganalytics.feedmgr.support.ZipFileUtil) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) ImportFeed(com.thinkbiganalytics.feedmgr.service.feed.importing.model.ImportFeed) Optional(java.util.Optional) ImportComponent(com.thinkbiganalytics.feedmgr.rest.ImportComponent) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) InputStream(java.io.InputStream) ImportProperty(com.thinkbiganalytics.feedmgr.rest.model.ImportProperty) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate)

Example 24 with ImportComponentOption

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);
}
Also used : Response(com.jayway.restassured.response.Response) ImportComponentOptionBuilder(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOptionBuilder) ArrayList(java.util.ArrayList) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) File(java.io.File)

Aggregations

ImportComponentOption (com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)24 UploadProgressMessage (com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage)14 ImportTemplate (com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate)11 ImportComponent (com.thinkbiganalytics.feedmgr.rest.ImportComponent)9 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)9 HashSet (java.util.HashSet)9 List (java.util.List)9 Optional (java.util.Optional)9 Set (java.util.Set)9 Collectors (java.util.stream.Collectors)9 StringUtils (org.apache.commons.lang3.StringUtils)9 RemoteProcessGroupInputPort (com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort)8 ReusableTemplateConnectionInfo (com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)8 NifiError (com.thinkbiganalytics.nifi.rest.model.NifiError)8 NifiProcessGroup (com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)8 IOException (java.io.IOException)8 Map (java.util.Map)8 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)8 ImportTemplateOptions (com.thinkbiganalytics.feedmgr.rest.model.ImportTemplateOptions)7 ImportSection (com.thinkbiganalytics.feedmgr.rest.ImportSection)6