Search in sources :

Example 1 with NifiFlowProcessGroup

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

the class NifiIntegrationRestController method getFlow.

@GET
@Path(FLOW + "/{processGroupId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the flow of the specified process group.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the flow.", response = NifiFlowProcessGroup.class), @ApiResponse(code = 500, message = "The process group is unavailable.", response = RestResponseStatus.class) })
public Response getFlow(@PathParam("processGroupId") String processGroupId) {
    accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ADMIN_FEEDS);
    NifiFlowProcessGroup flow = legacyNifiRestClient.getFeedFlow(processGroupId);
    NifiFlowDeserializer.prepareForSerialization(flow);
    return Response.ok(flow).build();
}
Also used : NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with NifiFlowProcessGroup

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

the class DefaultNiFiFlowVisitorClient method getTemplateFeedFlow.

public NifiFlowProcessGroup getTemplateFeedFlow(TemplateDTO template) {
    ProcessGroupDTO parentProcessGroup = new ProcessGroupDTO();
    parentProcessGroup.setId(UUID.randomUUID().toString());
    parentProcessGroup.setParentGroupId(UUID.randomUUID().toString());
    parentProcessGroup.setName(template.getName());
    parentProcessGroup.setContents(template.getSnippet());
    NifiConnectionOrderVisitorCache cache = new NifiConnectionOrderVisitorCache();
    Collection<ProcessGroupDTO> groups = NifiProcessUtil.getProcessGroups(parentProcessGroup);
    cache.add(parentProcessGroup);
    // add the snippet as its own process group
    if (template.getSnippet().getProcessors() != null) {
        // find the first processor and get its parent group id
        Optional<ProcessorDTO> firstProcessor = template.getSnippet().getProcessors().stream().findFirst();
        if (firstProcessor.isPresent()) {
            String groupId = firstProcessor.get().getParentGroupId();
            ProcessGroupDTO snippetGroup = new ProcessGroupDTO();
            snippetGroup.setId(groupId);
            snippetGroup.setParentGroupId(template.getGroupId());
            snippetGroup.setContents(template.getSnippet());
            cache.add(snippetGroup);
        }
    }
    if (groups != null) {
        groups.stream().forEach(group -> cache.add(group));
    }
    // add any remote ProcessGroups
    if (template.getSnippet().getRemoteProcessGroups() != null) {
        template.getSnippet().getRemoteProcessGroups().stream().forEach(remoteProcessGroupDTO -> cache.add(remoteProcessGroupDTO));
    }
    NifiVisitableProcessGroup visitableGroup = getFlowOrder(parentProcessGroup, cache, false);
    NifiFlowProcessGroup flow = new NifiFlowBuilder().build(visitableGroup);
    return flow;
}
Also used : NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) NifiFlowBuilder(com.thinkbiganalytics.nifi.rest.model.visitor.NifiFlowBuilder) NifiConnectionOrderVisitorCache(com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitorCache) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Example 3 with NifiFlowProcessGroup

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

the class DefaultFeedManagerTemplateService method getNiFiTemplateFlowProcessors.

/**
 * For a given Template and its related connection info to the reusable templates, walk the graph to return the Processors.
 * The system will first walk the incoming templateid.  If the {@code connectionInfo} parameter is set it will make the connections to the incoming template and continue walking those processors
 *
 * @param nifiTemplateId the NiFi templateId required to start walking the flow
 * @param connectionInfo the connections required to connect
 * @return a list of all the processors for a template and possible connections
 */
public List<RegisteredTemplate.FlowProcessor> getNiFiTemplateFlowProcessors(String nifiTemplateId, List<ReusableTemplateConnectionInfo> connectionInfo) {
    TemplateDTO templateDTO = nifiRestClient.getTemplateById(nifiTemplateId);
    // make the connection
    if (connectionInfo != null && !connectionInfo.isEmpty()) {
        Set<PortDTO> templatePorts = templateDTO.getSnippet().getOutputPorts();
        Map<String, PortDTO> outputPorts = templateDTO.getSnippet().getOutputPorts().stream().collect(Collectors.toMap(portDTO -> portDTO.getName(), Function.identity()));
        Map<String, PortDTO> inputPorts = getReusableFeedInputPorts().stream().collect(Collectors.toMap(portDTO -> portDTO.getName(), Function.identity()));
        connectionInfo.stream().forEach(reusableTemplateConnectionInfo -> {
            PortDTO outputPort = outputPorts.get(reusableTemplateConnectionInfo.getFeedOutputPortName());
            PortDTO inputPort = inputPorts.get(reusableTemplateConnectionInfo.getReusableTemplateInputPortName());
            ConnectionDTO connectionDTO = new ConnectionDTO();
            ConnectableDTO source = new ConnectableDTO();
            source.setName(reusableTemplateConnectionInfo.getFeedOutputPortName());
            source.setType(outputPort.getType());
            source.setId(outputPort.getId());
            source.setGroupId(outputPort.getParentGroupId());
            ConnectableDTO dest = new ConnectableDTO();
            dest.setName(inputPort.getName());
            dest.setType(inputPort.getType());
            dest.setId(inputPort.getId());
            dest.setGroupId(inputPort.getParentGroupId());
            connectionDTO.setSource(source);
            connectionDTO.setDestination(dest);
            connectionDTO.setId(UUID.randomUUID().toString());
            templateDTO.getSnippet().getConnections().add(connectionDTO);
        });
    }
    NifiFlowProcessGroup template = nifiRestClient.getTemplateFeedFlow(templateDTO);
    return template.getProcessorMap().values().stream().map(flowProcessor -> {
        RegisteredTemplate.FlowProcessor p = new RegisteredTemplate.FlowProcessor(flowProcessor.getId());
        p.setGroupId(flowProcessor.getParentGroupId());
        p.setType(flowProcessor.getType());
        p.setName(flowProcessor.getName());
        p.setFlowId(flowProcessor.getFlowId());
        p.setIsLeaf(flowProcessor.isLeaf());
        return p;
    }).collect(Collectors.toList());
}
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) NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) RegisteredTemplate(com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Example 4 with NifiFlowProcessGroup

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

the class ImportConnectedReusableTemplateIT method registerConnectedReusableTemplate.

public ConnectedTemplate registerConnectedReusableTemplate() {
    URL resource = IntegrationTestBase.class.getResource("connecting_reusable_flow.xml");
    ImportTemplate template1 = importReusableFlowXmlTemplate(resource.getPath(), null);
    String template1ProcessGroupId = template1.getTemplateResults().getProcessGroupEntity().getId();
    // Now import a reusable flow that has additional output ports in it.
    // Kylo will prompt to connect this to another reusable flow
    URL resource2 = IntegrationTestBase.class.getResource("reusable-flow1.xml");
    ImportTemplate template2 = importReusableFlowXmlTemplate(resource2.getPath(), null);
    // verify it failed
    Assert.assertFalse(template2.isSuccess());
    Assert.assertTrue(template2.isReusableFlowOutputPortConnectionsNeeded());
    // reassign the connections to connect to template1
    ReusableTemplateConnectionInfo connectionInfo = template2.getReusableTemplateConnections().stream().filter(conn -> "to another flow".equalsIgnoreCase(conn.getFeedOutputPortName())).findFirst().orElse(null);
    // Obtain the reusable connection input ports
    // get v1/feedmgr/nifi/reusable-input-ports
    PortDTO[] reusableInputPorts = getReusableInputPorts();
    // the 'connecting_reusable_flow.xml' has an input port named 'from reusable port'.
    // find it and try to connect it to this one
    PortDTO connectingPort = Arrays.stream(reusableInputPorts).filter(portDTO -> portDTO.getName().equalsIgnoreCase("from reusable port")).findFirst().orElse(null);
    if (connectingPort != null) {
        connectionInfo.setInputPortDisplayName(connectingPort.getName());
        connectionInfo.setReusableTemplateInputPortName(connectingPort.getName());
        connectionInfo.setReusableTemplateProcessGroupName(template1.getTemplateResults().getProcessGroupEntity().getName());
    }
    template2 = importReusableFlowXmlTemplate(resource2.getPath(), connectionInfo);
    Assert.assertTrue(template2.isSuccess());
    Assert.assertFalse(template2.isReusableFlowOutputPortConnectionsNeeded());
    // get the flow for the parent processor and verify it is connected to the other reusable flow
    NifiFlowProcessGroup flow = getFlow(template2.getTemplateResults().getProcessGroupEntity().getId());
    Assert.assertNotNull(flow);
    boolean testUpdate2ProcessorExists = flow.getProcessorMap().values().stream().anyMatch(p -> "test-update2".equalsIgnoreCase(p.getName()));
    Assert.assertTrue(testUpdate2ProcessorExists);
    return new ConnectedTemplate(template1, template2);
}
Also used : NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) PortDTO(org.apache.nifi.web.api.dto.PortDTO) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) URL(java.net.URL)

Example 5 with NifiFlowProcessGroup

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

the class TestFlowBuilder method testFlowBuilder.

@Test
public void testFlowBuilder() {
    // build a graph of processors
    NifiVisitableProcessGroup parent = new NifiVisitableProcessGroup(processGroupDTO());
    NifiVisitableProcessor processor1 = processor();
    NifiVisitableProcessor processor2 = processor();
    NifiVisitableProcessor processor3 = processor();
    NifiVisitableProcessor processor4 = processor();
    NifiVisitableProcessor processor5 = processor();
    NifiVisitableProcessor processor6 = processor();
    NifiVisitableProcessor processor7 = processor();
    // connect processors
    connect(processor1, processor2);
    connect(processor2, processor3);
    connect(processor2, processor4);
    connect(processor4, processor5);
    connect(processor5, processor6);
    connect(processor5, processor7);
    parent.getStartingProcessors().add(processor1);
    NifiFlowBuilder builder = new NifiFlowBuilder();
    NifiFlowProcessGroup group = builder.build(parent);
    Assert.assertTrue(group.getStartingProcessors().size() == 1);
    // assert processors 3,6,7 are ending/leaf processors
    Assert.assertTrue(group.getEndingProcessors().size() == 3);
}
Also used : NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) Test(org.junit.Test)

Aggregations

NifiFlowProcessGroup (com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup)11 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)5 NifiFlowBuilder (com.thinkbiganalytics.nifi.rest.model.visitor.NifiFlowBuilder)3 NifiVisitableProcessGroup (com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup)3 ReusableTemplateConnectionInfo (com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 ArrayList (java.util.ArrayList)2 PortDTO (org.apache.nifi.web.api.dto.PortDTO)2 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)2 TemplateConnectionUtil (com.thinkbiganalytics.feedmgr.nifi.TemplateConnectionUtil)1 NifiFlowCache (com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCache)1 PortDTOWithGroupInfo (com.thinkbiganalytics.feedmgr.rest.model.PortDTOWithGroupInfo)1 RegisteredTemplate (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplate)1 RegisteredTemplateRequest (com.thinkbiganalytics.feedmgr.rest.model.RegisteredTemplateRequest)1 FeedServicesAccessControl (com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl)1 StreamingFeedJmsNotificationService (com.thinkbiganalytics.feedmgr.service.feed.StreamingFeedJmsNotificationService)1 SecurityService (com.thinkbiganalytics.feedmgr.service.security.SecurityService)1 ImportTemplate (com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate)1 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)1