Search in sources :

Example 16 with NifiProperty

use of com.thinkbiganalytics.nifi.rest.model.NifiProperty in project kylo by Teradata.

the class ImportTemplateArchive method create.

@Override
public NifiProcessGroup create(NiFiTemplateImport niFiTemplateImport, UploadProgressMessage importStatusMessage) {
    log.info("Importing Zip file template {}, overwrite: {}, reusableFlow: {}", importTemplate.getFileName(), this.importTemplateOptions.isImportAndOverwrite(ImportComponent.TEMPLATE_DATA), importTemplateOptions.isImport(ImportComponent.REUSABLE_TEMPLATE));
    if (importTemplate.isValid()) {
    }
    TemplateDTO dto = niFiTemplateImport.getDto();
    String templateName = importTemplate.getTemplateName();
    String fileName = importTemplate.getFileName();
    importStatusMessage.update("Importing the NiFi flow, " + templateName);
    log.info("Creating a template instance in Nifi. Template: {} for file {}", templateName, fileName);
    Map<String, Object> configProperties = propertyExpressionResolver.getStaticConfigProperties();
    List<NifiProperty> templateProperties = importTemplate.getTemplateToImport() != null ? importTemplate.getTemplateToImport().getProperties() : Collections.emptyList();
    this.newTemplateInstance = nifiRestClient.createNewTemplateInstance(dto.getId(), templateProperties, configProperties, false, null, importTemplate.getVersionIdentifier());
    importTemplate.setTemplateResults(newTemplateInstance);
    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);
    }
    return newTemplateInstance;
}
Also used : TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty)

Example 17 with NifiProperty

use of com.thinkbiganalytics.nifi.rest.model.NifiProperty in project kylo by Teradata.

the class ValidateImportTemplatesArchive method validateTemplateProperties.

/**
 * Validate the Template doesnt have any sensitive properties needing additional user input before importing
 *
 * @return true if valid, false if not
 */
private boolean validateTemplateProperties() {
    RegisteredTemplate template = importTemplate.getTemplateToImport();
    // detect any sensitive properties and prompt for input before proceeding
    List<NifiProperty> sensitiveProperties = template.getSensitiveProperties();
    ImportUtil.addToImportOptionsSensitiveProperties(importTemplateOptions, sensitiveProperties, ImportComponent.TEMPLATE_DATA);
    boolean valid = ImportUtil.applyImportPropertiesToTemplate(template, importTemplate, ImportComponent.TEMPLATE_DATA);
    if (!valid) {
        importTemplate.getImportOptions().addErrorMessage(ImportComponent.TEMPLATE_DATA, "Additional properties are required for the Template");
    }
    this.importTemplateOptions.findImportComponentOption(ImportComponent.TEMPLATE_DATA).setAnalyzed(true);
    return valid;
}
Also used : NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)

Example 18 with NifiProperty

use of com.thinkbiganalytics.nifi.rest.model.NifiProperty 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 19 with NifiProperty

use of com.thinkbiganalytics.nifi.rest.model.NifiProperty 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)

Example 20 with NifiProperty

use of com.thinkbiganalytics.nifi.rest.model.NifiProperty in project kylo by Teradata.

the class PropertyExpressionResolverTest method testFeedMetadataProperties.

@Test
public void testFeedMetadataProperties() {
    FeedMetadata metadata = new FeedMetadata();
    metadata.setSystemFeedName("feedSystemName");
    metadata.setCategory(new FeedCategory());
    metadata.setTable(new TableSetup());
    metadata.getTable().setSourceTableSchema(new DefaultTableSchema());
    metadata.getTable().setTableSchema(new DefaultTableSchema());
    metadata.getTable().getSourceTableSchema().setName("sourceTableName");
    metadata.getTable().getTableSchema().setName("tableSchemaName");
    final NifiProperty prop1 = createProperty("${metadata.table.sourceTableSchema.name}");
    Assert.assertTrue(resolver.resolveExpression(metadata, prop1));
    Assert.assertEquals("sourceTableName", prop1.getValue());
}
Also used : FeedCategory(com.thinkbiganalytics.feedmgr.rest.model.FeedCategory) FeedMetadata(com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata) TableSetup(com.thinkbiganalytics.feedmgr.rest.model.schema.TableSetup) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) DefaultTableSchema(com.thinkbiganalytics.discovery.model.DefaultTableSchema) Test(org.junit.Test)

Aggregations

NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)47 ArrayList (java.util.ArrayList)22 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)19 Map (java.util.Map)15 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)13 HashMap (java.util.HashMap)13 List (java.util.List)13 HashSet (java.util.HashSet)12 Collectors (java.util.stream.Collectors)12 Nonnull (javax.annotation.Nonnull)12 StringUtils (org.apache.commons.lang3.StringUtils)12 Set (java.util.Set)11 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)11 NifiProcessGroup (com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)10 Optional (java.util.Optional)10 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)10 LegacyNifiRestClient (com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient)8 NifiError (com.thinkbiganalytics.nifi.rest.model.NifiError)8 Collections (java.util.Collections)7 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)7