Search in sources :

Example 11 with ImportComponentOption

use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.

the class ImportTemplateArchive method importFeedTemplate.

@Nullable
private RegisteredTemplate importFeedTemplate(RegisteredTemplate existingTemplate) {
    RegisteredTemplate template = null;
    niFiTemplateImport = importIntoNiFi(this.importTemplate, this.importTemplateOptions);
    ImportComponentOption registeredTemplateImport = this.importTemplateOptions.findImportComponentOption(ImportComponent.TEMPLATE_DATA);
    if (existingTemplate != null) {
        importTemplate.setTemplateId(existingTemplate.getId());
    }
    if (registeredTemplateImport.isShouldImport() && registeredTemplateImport.isValidForImport()) {
        UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Importing feed template");
        this.newTemplateInstance = create(niFiTemplateImport, statusMessage);
        if (newTemplateInstance.isSuccess()) {
            importTemplate.setSuccess(true);
            RegisteredTemplate savedTemplate = registerTemplate(importTemplate, importTemplateOptions);
            if (savedTemplate != null) {
                template = savedTemplate;
            }
        } else {
            importTemplate.setSuccess(false);
        }
        statusMessage.complete(importTemplate.isSuccess());
    } else {
        importTemplate.setSuccess(true);
    }
    return template;
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) Nullable(javax.annotation.Nullable)

Example 12 with ImportComponentOption

use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.

the class ValidateImportTemplatesArchive method validateRegisteredTemplate.

/**
 * Validate the Registered Template is valid for importing
 */
private void validateRegisteredTemplate() {
    ImportComponentOption registeredTemplateOption = this.importTemplateOptions.findImportComponentOption(ImportComponent.TEMPLATE_DATA);
    // validate template
    boolean validForImport = true;
    if (!registeredTemplateOption.isUserAcknowledged()) {
        this.importTemplate.setValid(false);
        this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.TEMPLATE_DATA, "A template exists.  Do you want to import it?");
    }
    if (registeredTemplateOption.isUserAcknowledged() && registeredTemplateOption.isShouldImport()) {
        UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(this.importTemplateOptions.getUploadKey(), "Validating feed template for import");
        RegisteredTemplate registeredTemplate = this.importTemplate.getTemplateToImport();
        // validate unique
        // 1 find if the template exists in the system running as a service account
        RegisteredTemplate existingTemplate = registeredTemplateService.findRegisteredTemplate(new RegisteredTemplateRequest.Builder().templateName(registeredTemplate.getTemplateName()).isFeedEdit(true).build());
        if (existingTemplate != null) {
            if (this.importTemplateOptions.stopProcessingAlreadyExists(ImportComponent.TEMPLATE_DATA)) {
                this.importTemplate.setValid(false);
                String msg = "Unable to import the template " + registeredTemplate.getTemplateName() + " It is already registered.";
                this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.TEMPLATE_DATA, msg);
                statusMessage.update("Validation error: The template " + registeredTemplate.getTemplateName() + " is already registered", false);
            } else {
                // skip importing if user doesnt want it.
                if (!registeredTemplateOption.isOverwrite()) {
                    validForImport = false;
                }
                statusMessage.complete(true);
            }
            registeredTemplate.setId(existingTemplate.getId());
            // validate entity access
            if (accessController.isEntityAccessControlled() && registeredTemplateOption.isOverwrite()) {
                // requery as the currently logged in user
                statusMessage = uploadProgressService.addUploadStatus(this.importTemplateOptions.getUploadKey(), "Validating template entity access");
                existingTemplate = registeredTemplateService.findRegisteredTemplate(RegisteredTemplateRequest.requestByTemplateName(registeredTemplate.getTemplateName()));
                // ensure the user can Edit this template
                boolean valid = existingTemplate != null && existingTemplate.getAllowedActions().hasAction(TemplateAccessControl.EDIT_TEMPLATE.getSystemName());
                if (!valid) {
                    this.importTemplate.setValid(false);
                    validForImport = false;
                    statusMessage.update("Access Denied: You do not have edit access for the template " + registeredTemplate.getTemplateName(), false);
                    this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.TEMPLATE_DATA, "Access Denied: You do not have edit access for the template ");
                } else {
                    statusMessage.complete(valid);
                }
            }
        } else {
            // template doesnt exist.. it is new ensure the user is allowed to create templates
            boolean editAccess = accessController.hasPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_TEMPLATES);
            if (!editAccess) {
                statusMessage.update("Access Denied: You are not allowed to create the template " + registeredTemplate.getTemplateName(), false);
                this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.TEMPLATE_DATA, "Access Denied: You are not allowed to create the template ");
            }
            registeredTemplate.setId(null);
            statusMessage.complete(editAccess);
        }
        validForImport &= !registeredTemplateOption.hasErrorMessages();
        if (validForImport) {
            boolean isValid = validateTemplateProperties();
            if (this.importTemplate.isValid()) {
                this.importTemplate.setValid(isValid);
            }
            validForImport &= isValid;
        }
        registeredTemplateOption.setValidForImport(validForImport);
    }
    this.uploadProgressService.completeSection(this.importTemplateOptions, ImportSection.Section.VALIDATE_REGISTERED_TEMPLATE);
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)

Example 13 with ImportComponentOption

use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.

the class ValidateImportTemplatesArchive method validateReusableTemplate.

/**
 * Validate any reusable templates as part of a zip file upload are valid for importing
 */
private void validateReusableTemplate() {
    // validate the reusable template
    if (this.importTemplate.hasConnectingReusableTemplate()) {
        ImportComponentOption reusableTemplateOption = this.importTemplateOptions.findImportComponentOption(ImportComponent.REUSABLE_TEMPLATE);
        UploadProgressMessage reusableTemplateStatusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Validating Reusable Template. ");
        if (reusableTemplateOption.isShouldImport()) {
            boolean validForImport = true;
            // for each of the connecting template
            for (String reusableTemplateXml : this.importTemplate.getNifiConnectingReusableTemplateXmls()) {
                try {
                    String templateName = NifiTemplateParser.getTemplateName(reusableTemplateXml);
                    UploadProgressMessage statusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Validating Reusable Template. " + templateName);
                    TemplateDTO dto = nifiRestClient.getTemplateByName(templateName);
                    // if there is a match and it has not been acknowledged by the user to overwrite or not, error out
                    if (dto != null && !reusableTemplateOption.isUserAcknowledged()) {
                        // error out it exists
                        this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.REUSABLE_TEMPLATE, "A reusable template with the same name " + templateName + " exists.");
                        this.importTemplate.setValid(false);
                        statusMessage.update("Reusable template, " + templateName + ", already exists.", false);
                        validForImport = false;
                    } else if (dto != null && reusableTemplateOption.isUserAcknowledged() && !reusableTemplateOption.isOverwrite()) {
                        validForImport = false;
                        // user has asked to not import the template.
                        uploadProgressService.removeMessage(importTemplateOptions.getUploadKey(), statusMessage);
                    } else {
                        uploadProgressService.removeMessage(importTemplateOptions.getUploadKey(), statusMessage);
                        // statusMessage.update("Validated Reusable Template", true);
                        validForImport &= true;
                    }
                } catch (Exception e) {
                    log.error("Error parsing template name from file {} ", fileName, e);
                    validForImport = false;
                }
            }
            reusableTemplateOption.setValidForImport(validForImport);
            reusableTemplateStatusMessage.update("Validated Reusable Templates ", !reusableTemplateOption.hasErrorMessages());
        } else if (!reusableTemplateOption.isUserAcknowledged()) {
            this.importTemplate.getImportOptions().addErrorMessage(ImportComponent.REUSABLE_TEMPLATE, "The file " + this.importTemplate.getFileName() + " has a reusable template to import.");
            this.importTemplate.setValid(false);
            reusableTemplateStatusMessage.update("A reusable template was found. Additional input needed.", false);
        } else {
            reusableTemplateStatusMessage.update("Reusable template found in import, but it is not marked for importing", true);
        }
    }
    this.uploadProgressService.completeSection(this.importTemplateOptions, ImportSection.Section.VALIDATE_REUSABLE_TEMPLATE);
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption)

Example 14 with ImportComponentOption

use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption in project kylo by Teradata.

the class ImportUtil method addToImportOptionsSensitiveProperties.

public static void addToImportOptionsSensitiveProperties(ImportOptions importOptions, List<NifiProperty> sensitiveProperties, ImportComponent component) {
    ImportComponentOption option = importOptions.findImportComponentOption(component);
    if (option.getProperties().isEmpty()) {
        option.setProperties(sensitiveProperties.stream().map(p -> new ImportProperty(p.getProcessorName(), p.getProcessorId(), p.getKey(), "", p.getProcessorType())).collect(Collectors.toList()));
    } else {
        // only add in those that are unique
        Map<String, ImportProperty> propertyMap = option.getProperties().stream().collect(Collectors.toMap(p -> p.getProcessorNameTypeKey(), p -> p));
        sensitiveProperties.stream().filter(nifiProperty -> !propertyMap.containsKey(nifiProperty.getProcessorNameTypeKey())).forEach(p -> {
            option.getProperties().add(new ImportProperty(p.getProcessorName(), p.getProcessorId(), p.getKey(), "", p.getProcessorType()));
        });
    }
}
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)

Example 15 with ImportComponentOption

use of com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption 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;
    }
}
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) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)

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