Search in sources :

Example 1 with PortDTOWithGroupInfo

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

the class TemplateConnectionUtil method getReusableFeedInputPorts.

/**
 * @return all input ports under the {@link TemplateCreationHelper#REUSABLE_TEMPLATES_PROCESS_GROUP_NAME} process group
 */
public Set<PortDTOWithGroupInfo> getReusableFeedInputPorts() {
    Set<PortDTOWithGroupInfo> ports = new HashSet<>();
    String reusableProcessGroupId = this.getReusableTemplateProcessGroupId();
    if (reusableProcessGroupId != null) {
        try {
            ProcessGroupFlowDTO processGroup = restClient.getNiFiRestClient().processGroups().flow(reusableProcessGroupId);
            if (processGroup != null) {
                ports.addAll(getReusableFeedInputPorts(processGroup));
            }
        } catch (final NifiComponentNotFoundException e) {
            log.debug("Reusable template process group not found: {}", reusableProcessGroupId, e);
        }
    }
    return ports;
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) PortDTOWithGroupInfo(com.thinkbiganalytics.feedmgr.rest.model.PortDTOWithGroupInfo) HashSet(java.util.HashSet)

Example 2 with PortDTOWithGroupInfo

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

the class DefaultFeedManagerTemplateService method getReusableTemplateProcessorsForInputPorts.

/**
 * Return all the processors that are connected to a given NiFi input port
 *
 * @param inputPortIds the ports to inspect
 * @return all the processors that are connected to a given NiFi input port
 */
public List<RegisteredTemplate.Processor> getReusableTemplateProcessorsForInputPorts(List<String> inputPortIds) {
    Set<ProcessorDTO> processorDTOs = new HashSet<>();
    if (inputPortIds != null && !inputPortIds.isEmpty()) {
        ProcessGroupDTO processGroup = nifiRestClient.getProcessGroupByName("root", TemplateCreationHelper.REUSABLE_TEMPLATES_PROCESS_GROUP_NAME);
        if (processGroup != null) {
            // fetch the Content
            ProcessGroupDTO content = nifiRestClient.getProcessGroup(processGroup.getId(), true, true);
            processGroup.setContents(content.getContents());
            Set<PortDTOWithGroupInfo> ports = getReusableFeedInputPorts();
            ports.stream().filter(portDTO -> inputPortIds.contains(portDTO.getId())).forEach(port -> {
                List<ConnectionDTO> connectionDTOs = NifiConnectionUtil.findConnectionsMatchingSourceId(processGroup.getContents().getConnections(), port.getId());
                if (connectionDTOs != null) {
                    connectionDTOs.stream().forEach(connectionDTO -> {
                        String processGroupId = connectionDTO.getDestination().getGroupId();
                        Set<ProcessorDTO> processors = nifiRestClient.getProcessorsForFlow(processGroupId);
                        if (processors != null) {
                            processorDTOs.addAll(processors);
                        }
                    });
                }
            });
        }
    }
    List<RegisteredTemplate.Processor> processorProperties = processorDTOs.stream().map(processorDTO -> registeredTemplateUtil.toRegisteredTemplateProcessor(processorDTO, true)).collect(Collectors.toList());
    return processorProperties;
}
Also used : PortDTOWithGroupInfo(com.thinkbiganalytics.feedmgr.rest.model.PortDTOWithGroupInfo) LoggerFactory(org.slf4j.LoggerFactory) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) StringUtils(org.apache.commons.lang3.StringUtils) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) TemplateChangeEvent(com.thinkbiganalytics.metadata.api.event.template.TemplateChangeEvent) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) TemplateAccessControl(com.thinkbiganalytics.metadata.api.template.security.TemplateAccessControl) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) FeedManagerTemplateProvider(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplateProvider) OpsManagerFeedProvider(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeedProvider) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Set(java.util.Set) UUID(java.util.UUID) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Collectors(java.util.stream.Collectors) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) Principal(java.security.Principal) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) Optional(java.util.Optional) TemplateChange(com.thinkbiganalytics.metadata.api.event.template.TemplateChange) HashMap(java.util.HashMap) Function(java.util.function.Function) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) MetadataChange(com.thinkbiganalytics.metadata.api.event.MetadataChange) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) StreamingFeedJmsNotificationService(com.thinkbiganalytics.feedmgr.service.feed.StreamingFeedJmsNotificationService) Logger(org.slf4j.Logger) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) DateTime(org.joda.time.DateTime) TemplateCreationHelper(com.thinkbiganalytics.nifi.feedmgr.TemplateCreationHelper) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) PortDTOWithGroupInfo(com.thinkbiganalytics.feedmgr.rest.model.PortDTOWithGroupInfo) HashSet(java.util.HashSet)

Example 3 with PortDTOWithGroupInfo

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

the class DefaultFeedManagerTemplateService method getRegisteredTemplateProcessors.

@Override
public List<RegisteredTemplate.Processor> getRegisteredTemplateProcessors(String templateId, boolean includeReusableProcessors) {
    List<RegisteredTemplate.Processor> processorProperties = new ArrayList<>();
    RegisteredTemplate template = registeredTemplateService.findRegisteredTemplate(new RegisteredTemplateRequest.Builder().templateId(templateId).nifiTemplateId(templateId).includeAllProperties(true).build());
    if (template != null) {
        template.initializeProcessors();
        processorProperties.addAll(template.getInputProcessors());
        processorProperties.addAll(template.getNonInputProcessors());
        if (includeReusableProcessors && template.getReusableTemplateConnections() != null && !template.getReusableTemplateConnections().isEmpty()) {
            // 1 fetch ports in reusable templates
            Map<String, PortDTO> reusableTemplateInputPorts = new HashMap<>();
            Set<PortDTOWithGroupInfo> ports = getReusableFeedInputPorts();
            if (ports != null) {
                ports.stream().forEach(portDTO -> reusableTemplateInputPorts.put(portDTO.getName(), portDTO));
            }
            // match to the name
            List<String> matchingPortIds = template.getReusableTemplateConnections().stream().filter(conn -> reusableTemplateInputPorts.containsKey(conn.getReusableTemplateInputPortName())).map(reusableTemplateConnectionInfo -> reusableTemplateInputPorts.get(reusableTemplateConnectionInfo.getReusableTemplateInputPortName()).getId()).collect(Collectors.toList());
            List<RegisteredTemplate.Processor> reusableProcessors = getReusableTemplateProcessorsForInputPorts(matchingPortIds);
            processorProperties.addAll(reusableProcessors);
        }
    }
    return processorProperties;
}
Also used : PortDTOWithGroupInfo(com.thinkbiganalytics.feedmgr.rest.model.PortDTOWithGroupInfo) LoggerFactory(org.slf4j.LoggerFactory) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) StringUtils(org.apache.commons.lang3.StringUtils) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) TemplateChangeEvent(com.thinkbiganalytics.metadata.api.event.template.TemplateChangeEvent) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) TemplateAccessControl(com.thinkbiganalytics.metadata.api.template.security.TemplateAccessControl) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) FeedManagerTemplateProvider(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplateProvider) OpsManagerFeedProvider(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeedProvider) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Set(java.util.Set) UUID(java.util.UUID) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Collectors(java.util.stream.Collectors) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) Principal(java.security.Principal) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) Optional(java.util.Optional) TemplateChange(com.thinkbiganalytics.metadata.api.event.template.TemplateChange) HashMap(java.util.HashMap) Function(java.util.function.Function) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) MetadataChange(com.thinkbiganalytics.metadata.api.event.MetadataChange) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) StreamingFeedJmsNotificationService(com.thinkbiganalytics.feedmgr.service.feed.StreamingFeedJmsNotificationService) Logger(org.slf4j.Logger) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) DateTime(org.joda.time.DateTime) TemplateCreationHelper(com.thinkbiganalytics.nifi.feedmgr.TemplateCreationHelper) FeedManagerTemplate(com.thinkbiganalytics.metadata.api.template.FeedManagerTemplate) NifiFlowCache(com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) HashMap(java.util.HashMap) PortDTO(org.apache.nifi.web.api.dto.PortDTO) ArrayList(java.util.ArrayList) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) PortDTOWithGroupInfo(com.thinkbiganalytics.feedmgr.rest.model.PortDTOWithGroupInfo)

Example 4 with PortDTOWithGroupInfo

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

the class DefaultTemplateExporter method export.

private ExportTemplate export(String templateId) {
    RegisteredTemplate template = registeredTemplateService.findRegisteredTemplate(new RegisteredTemplateRequest.Builder().templateId(templateId).nifiTemplateId(templateId).includeSensitiveProperties(true).build());
    if (template != null) {
        List<String> connectingReusableTemplates = new ArrayList<>();
        Set<String> connectedTemplateIds = new HashSet<>();
        Set<ReusableTemplateConnectionInfo> outputPortConnectionMetadata = new HashSet<>();
        Set<RemoteProcessGroupInputPort> templateRemoteInputPorts = new HashSet<>();
        List<ReusableTemplateConnectionInfo> reusableTemplateConnectionInfos = null;
        if (template.usesReusableTemplate()) {
            reusableTemplateConnectionInfos = template.getReusableTemplateConnections();
        }
        List<ReusableTemplateConnectionInfo> remoteProcessGroupConnectionInfo = getRemoteProcessGroupConnectionInfo(template.getNifiTemplate());
        if (reusableTemplateConnectionInfos != null) {
            reusableTemplateConnectionInfos.addAll(remoteProcessGroupConnectionInfo);
        } else {
            reusableTemplateConnectionInfos = remoteProcessGroupConnectionInfo;
        }
        if (reusableTemplateConnectionInfos != null && !reusableTemplateConnectionInfos.isEmpty()) {
            ProcessGroupFlowDTO reusableTemplateFlow = templateConnectionUtil.getReusableTemplateCategoryProcessGroupFlow();
            Map<String, PortDTOWithGroupInfo> reusableTemplatePorts = templateConnectionUtil.getReusableFeedInputPorts(reusableTemplateFlow).stream().collect(Collectors.toMap(port -> port.getName(), port -> port));
            reusableTemplateConnectionInfos.stream().filter(connectionInfo -> StringUtils.isBlank(connectionInfo.getReusableTemplateProcessGroupName())).forEach(connectionInfo -> {
                PortDTOWithGroupInfo port = reusableTemplatePorts.get(connectionInfo.getReusableTemplateInputPortName());
                if (port != null) {
                    connectionInfo.setReusableTemplateProcessGroupName(port.getDestinationProcessGroupName());
                }
            });
            // Get flow information for the 'reusable_templates' process group in NiFi
            if (reusableTemplateFlow != null) {
                gatherConnectedReusableTemplates(connectingReusableTemplates, connectedTemplateIds, outputPortConnectionMetadata, reusableTemplateConnectionInfos, reusableTemplateFlow);
            }
            // Only gather remote input ports on the reusable templates if enabled
            if (isRemoteProcessGroupsEnabled()) {
                // for all the reusable templates used gather any that have remote input ports
                reusableTemplateConnectionInfos.stream().forEach(connectionInfo -> {
                    Set<RemoteProcessGroupInputPort> remoteProcessGroupInputPorts = findReusableTemplateRemoteInputPorts(reusableTemplateFlow, connectionInfo.getReusableTemplateProcessGroupName());
                    templateRemoteInputPorts.addAll(remoteProcessGroupInputPorts);
                });
            }
        }
        String templateXml = null;
        try {
            if (template != null) {
                try {
                    templateXml = nifiRestClient.getTemplateXml(template.getNifiTemplateId());
                } catch (NifiClientRuntimeException e) {
                    TemplateDTO templateDTO = nifiRestClient.getTemplateByName(template.getTemplateName());
                    if (templateDTO != null) {
                        templateXml = nifiRestClient.getTemplateXml(templateDTO.getId());
                    }
                }
            }
        } catch (NifiConnectionException e) {
            throw e;
        } catch (Exception e) {
            throw new TemplateExportException("Unable to find Nifi Template for " + templateId);
        }
        // create a zip file with the template and xml
        byte[] zipFile = zip(template, templateXml, connectingReusableTemplates, outputPortConnectionMetadata, templateRemoteInputPorts);
        return new ExportTemplate(SystemNamingService.generateSystemName(template.getTemplateName()) + ".template.zip", template.getTemplateName(), template.getDescription(), template.isStream(), zipFile);
    } else {
        throw new TemplateExportException("Unable to find Template for " + templateId);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) RegisteredTemplateService(com.thinkbiganalytics.feedmgr.service.template.RegisteredTemplateService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PortDTOWithGroupInfo(com.thinkbiganalytics.feedmgr.rest.model.PortDTOWithGroupInfo) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) StringUtils(org.apache.commons.lang3.StringUtils) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) NifiRemoteProcessGroupUtil(com.thinkbiganalytics.nifi.rest.support.NifiRemoteProcessGroupUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ObjectMapperSerializer(com.thinkbiganalytics.json.ObjectMapperSerializer) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) TemplateExportException(com.thinkbiganalytics.nifi.feedmgr.TemplateExportException) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) TemplateAccessControl(com.thinkbiganalytics.metadata.api.template.security.TemplateAccessControl) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) ZipEntry(java.util.zip.ZipEntry) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) NifiConnectionException(com.thinkbiganalytics.nifi.rest.client.NifiConnectionException) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) TemplateExporter(com.thinkbiganalytics.metadata.api.template.export.TemplateExporter) Set(java.util.Set) IOException(java.io.IOException) SystemNamingService(com.thinkbiganalytics.feedmgr.rest.support.SystemNamingService) Collectors(java.util.stream.Collectors) ExportTemplate(com.thinkbiganalytics.metadata.api.template.export.ExportTemplate) List(java.util.List) Optional(java.util.Optional) TemplateConnectionUtil(com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil) TemplateRemoteInputPortConnections(com.thinkbiganalytics.feedmgr.rest.model.TemplateRemoteInputPortConnections) Collections(java.util.Collections) LegacyNifiRestClient(com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ArrayList(java.util.ArrayList) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) NifiConnectionException(com.thinkbiganalytics.nifi.rest.client.NifiConnectionException) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) TemplateExportException(com.thinkbiganalytics.nifi.feedmgr.TemplateExportException) NifiConnectionException(com.thinkbiganalytics.nifi.rest.client.NifiConnectionException) IOException(java.io.IOException) ExportTemplate(com.thinkbiganalytics.metadata.api.template.export.ExportTemplate) RemoteProcessGroupInputPort(com.thinkbiganalytics.feedmgr.rest.model.RemoteProcessGroupInputPort) TemplateExportException(com.thinkbiganalytics.nifi.feedmgr.TemplateExportException) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) RegisteredTemplateRequest(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) PortDTOWithGroupInfo(com.thinkbiganalytics.feedmgr.rest.model.PortDTOWithGroupInfo) HashSet(java.util.HashSet)

Aggregations

PortDTOWithGroupInfo (com.thinkbiganalytics.feedmgr.rest.model.PortDTOWithGroupInfo)4 HashSet (java.util.HashSet)4 ProcessGroupFlowDTO (org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO)4 TemplateConnectionUtil (com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil)3 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)3 RegisteredTemplateRequest (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest)3 ReusableTemplateConnectionInfo (com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)3 FeedServicesAccessControl (com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl)3 TemplateAccessControl (com.thinkbiganalytics.metadata.api.template.security.TemplateAccessControl)3 LegacyNifiRestClient (com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient)3 AccessController (com.thinkbiganalytics.security.AccessController)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 StringUtils (org.apache.commons.lang3.StringUtils)3 NifiFlowCache (com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache)2