Search in sources :

Example 1 with NifiProcessGroup

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

the class LegacyNifiRestClient method createNewTemplateInstance.

public NifiProcessGroup createNewTemplateInstance(String templateId, List<NifiProperty> templateProperties, Map<String, Object> staticConfigProperties, boolean createReusableFlow, ReusableTemplateCreationCallback creationCallback, String versionIdentifier) {
    TemplateInstanceCreator creator = new TemplateInstanceCreator(this, templateId, templateProperties, staticConfigProperties, createReusableFlow, creationCallback, versionIdentifier);
    NifiProcessGroup group = creator.createTemplate();
    return group;
}
Also used : TemplateInstanceCreator(com.thinkbiganalytics.nifi.feedmgr.TemplateInstanceCreator) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)

Example 2 with NifiProcessGroup

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

the class ImportReusableTemplate method connect.

private boolean connect() {
    NifiProcessGroup processGroup = this.newTemplateInstance;
    UploadProgressMessage importStatusMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Connecting and validating components for " + importTemplate.getTemplateName());
    connectReusableFlow(importStatusMessage, processGroup);
    recreateOutputPortConnections(importStatusMessage, processGroup);
    boolean valid = validateOutputPortConnections(processGroup);
    importStatusMessage.update("Connected and validated components for " + importTemplate.getTemplateName(), valid);
    // create any remote process group ports and connect them on the main NiFi canvas
    if (isClustered()) {
        ImportComponentOption remoteProcessGroupOption = importTemplateOptions.findImportComponentOption(ImportComponent.REMOTE_INPUT_PORT);
        if (remoteProcessGroupOption.isUserAcknowledged() && remoteProcessGroupOption.isShouldImport()) {
            if (remoteProcessGroupOption.getRemoteProcessGroupInputPortsForTemplate(importTemplate.getTemplateName()).stream().anyMatch(inputPort -> inputPort.isSelected())) {
                UploadProgressMessage remoteInputPortsMessage = uploadProgressService.addUploadStatus(importTemplateOptions.getUploadKey(), "Creating remote input port connections for " + remoteProcessGroupOption.getRemoteProcessGroupInputPortsForTemplate(importTemplate.getTemplateName()).stream().filter(inputPort -> inputPort.isSelected()).map(inputPort -> inputPort.getInputPortName()).collect(Collectors.joining(",")));
                valid &= createRemoteInputPorts(remoteInputPortsMessage);
            }
        }
        if (remoteProcessGroupOption.isShouldImport() && remoteProcessGroupOption.isUserAcknowledged()) {
            // identify if the user wished to remove any input ports.
            valid = removeConnectionsAndInputs();
        }
    }
    return valid && newTemplateInstance.isSuccess();
}
Also used : UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) UploadProgressService(com.thinkbiganalytics.feedmgr.service.UploadProgressService) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) LoggerFactory(org.slf4j.LoggerFactory) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) StringUtils(org.apache.commons.lang3.StringUtils) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) NifiFlowUtil(com.thinkbiganalytics.nifi.rest.support.NifiFlowUtil) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) ReusableTemplateCreationCallback(com.thinkbiganalytics.nifi.feedmgr.ReusableTemplateCreationCallback) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) RegisteredTemplateCache(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateCache) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ImportTemplateOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportTemplateOptions) Optional(java.util.Optional) NiFiTemplateImport(com.thinkbiganalytics.feedmgr.service.template.importing.model.NiFiTemplateImport) ImportComponent(com.thinkbiganalytics.feedmgr.rest.ImportComponent) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) HashMap(java.util.HashMap) ImportSection(com.thinkbiganalytics.feedmgr.rest.ImportSection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Nullable(javax.annotation.Nullable) NiFiClusterSummary(com.thinkbiganalytics.nifi.rest.model.NiFiClusterSummary) Logger(org.slf4j.Logger) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) TemplateRemoteInputPortConnections(com.thinkbiganalytics.feedmgr.rest.model.TemplateRemoteInputPortConnections) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)

Example 3 with NifiProcessGroup

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

the class ImportReusableTemplate method validateOutputPortConnections.

private boolean validateOutputPortConnections(NifiProcessGroup newTemplateInstance) {
    // Validate port connections
    newTemplateInstance.getProcessGroupEntity().getContents().getOutputPorts().stream().forEach(portDTO -> {
        if (portDTO.getValidationErrors() != null && !portDTO.getValidationErrors().isEmpty()) {
            importTemplate.setReusableFlowOutputPortConnectionsNeeded(true);
        }
        ReusableTemplateConnectionInfo connectionInfo = new ReusableTemplateConnectionInfo();
        connectionInfo.setFeedOutputPortName(portDTO.getName());
        // attempt to prefill it with the previous connection if it existed
        ConnectionDTO reusableTemplateInputPortConnection = findReusableTemplateInputPortConnectionForOutputPort(portDTO);
        if (reusableTemplateInputPortConnection != null) {
            connectionInfo.setInputPortDisplayName(reusableTemplateInputPortConnection.getSource().getName());
            connectionInfo.setReusableTemplateInputPortName(reusableTemplateInputPortConnection.getSource().getName());
            String processGroupName = findReusableTemplateProcessGroup(reusableTemplateInputPortConnection.getDestination().getGroupId()).map(processGroupDTO -> processGroupDTO.getName()).orElse(null);
            connectionInfo.setReusableTemplateProcessGroupName(processGroupName);
        }
        importTemplate.addReusableTemplateConnection(connectionInfo);
    });
    return importTemplate.isSuccess() && importTemplate.isValid() && !importTemplate.isReusableFlowOutputPortConnectionsNeeded();
}
Also used : UploadProgressService(com.thinkbiganalytics.feedmgr.service.UploadProgressService) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) LoggerFactory(org.slf4j.LoggerFactory) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) StringUtils(org.apache.commons.lang3.StringUtils) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ConnectionStatusEntity(org.apache.nifi.web.api.entity.ConnectionStatusEntity) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) NifiFlowUtil(com.thinkbiganalytics.nifi.rest.support.NifiFlowUtil) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) ReusableTemplateCreationCallback(com.thinkbiganalytics.nifi.feedmgr.ReusableTemplateCreationCallback) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) UploadProgressMessage(com.thinkbiganalytics.feedmgr.rest.model.UploadProgressMessage) RegisteredTemplateCache(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateCache) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ImportTemplateOptions(com.thinkbiganalytics.feedmgr.rest.model.ImportTemplateOptions) Optional(java.util.Optional) NiFiTemplateImport(com.thinkbiganalytics.feedmgr.service.template.importing.model.NiFiTemplateImport) ImportComponent(com.thinkbiganalytics.feedmgr.rest.ImportComponent) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) HashMap(java.util.HashMap) ImportSection(com.thinkbiganalytics.feedmgr.rest.ImportSection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PropertyExpressionResolver(com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Nullable(javax.annotation.Nullable) NiFiClusterSummary(com.thinkbiganalytics.nifi.rest.model.NiFiClusterSummary) Logger(org.slf4j.Logger) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) TemplateRemoteInputPortConnections(com.thinkbiganalytics.feedmgr.rest.model.TemplateRemoteInputPortConnections) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ImportComponentOption(com.thinkbiganalytics.feedmgr.rest.model.ImportComponentOption) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)

Example 4 with NifiProcessGroup

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

the class ImportReusableTemplate method create.

@Override
public NifiProcessGroup create(NiFiTemplateImport niFiTemplateImport, UploadProgressMessage importStatusMessage) {
    TemplateDTO dto = niFiTemplateImport.getDto();
    String templateName = importTemplate.getTemplateName();
    String fileName = importTemplate.getFileName();
    importStatusMessage.update("Creating reusable flow instance for " + templateName);
    log.info("Creating a Reusable flow template instance in Nifi. Template: {} for file {}", templateName, fileName);
    Map<String, Object> configProperties = propertyExpressionResolver.getStaticConfigProperties();
    NifiFlowCacheReusableTemplateCreationCallback reusableTemplateCreationCallback = new NifiFlowCacheReusableTemplateCreationCallback();
    List<NifiProperty> templateProperties = importTemplate.getTemplateToImport() != null ? importTemplate.getTemplateToImport().getProperties() : Collections.emptyList();
    NifiProcessGroup newTemplateInstance = nifiRestClient.createNewTemplateInstance(dto.getId(), templateProperties, configProperties, true, reusableTemplateCreationCallback, importTemplate.getVersionIdentifier());
    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);
    }
    importTemplate.setTemplateResults(newTemplateInstance);
    return newTemplateInstance;
}
Also used : TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)

Example 5 with NifiProcessGroup

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

NifiProcessGroup (com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)11 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)9 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)7 NifiError (com.thinkbiganalytics.nifi.rest.model.NifiError)6 ReusableTemplateConnectionInfo (com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 Optional (java.util.Optional)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 StringUtils (org.apache.commons.lang3.StringUtils)5 PropertyExpressionResolver (com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver)4 TemplateConnectionUtil (com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil)4 NifiFlowCache (com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache)4 ImportComponent (com.thinkbiganalytics.feedmgr.rest.ImportComponent)4 RegisteredTemplateService (com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService)4 LegacyNifiRestClient (com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient)4 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)4