Search in sources :

Example 26 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class NifiIntegrationRestController method autoAlign.

@GET
@Path("/auto-align/{processGroupId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Organizes the components of the specified process group.")
@ApiResponses(@ApiResponse(code = 200, message = "The result of the operation.", response = RestResponseStatus.class))
public Response autoAlign(@PathParam("processGroupId") String processGroupId) {
    accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ADMIN_FEEDS);
    RestResponseStatus status;
    if ("all".equals(processGroupId)) {
        AlignNiFiComponents alignNiFiComponents = new AlignNiFiComponents();
        alignNiFiComponents.setNiFiRestClient(legacyNifiRestClient.getNiFiRestClient());
        alignNiFiComponents.autoLayout();
        String message = "";
        if (alignNiFiComponents.isAligned()) {
            message = "Aligned All of NiFi.  " + alignNiFiComponents.getAlignedProcessGroups() + " process groups were aligned ";
        } else {
            message = "Alignment failed while attempting to align all of NiFi. " + alignNiFiComponents.getAlignedProcessGroups() + " were successfully aligned. Please look at the logs for more information";
        }
        status = new RestResponseStatus.ResponseStatusBuilder().message(message).buildSuccess();
    } else {
        AlignProcessGroupComponents alignProcessGroupComponents = new AlignProcessGroupComponents(legacyNifiRestClient.getNiFiRestClient(), processGroupId);
        ProcessGroupDTO alignedGroup = alignProcessGroupComponents.autoLayout();
        String message = "";
        if (alignProcessGroupComponents.isAligned()) {
            message = "Aligned " + alignedGroup.getContents().getProcessGroups().size() + " process groups under " + alignedGroup.getName();
        } else {
            message = "Alignment failed for process group " + processGroupId + ". Please look at the logs for more information";
        }
        status = new RestResponseStatus.ResponseStatusBuilder().message(message).buildSuccess();
    }
    return Response.ok(status).build();
}
Also used : AlignNiFiComponents(com.thinkbiganalytics.nifi.rest.client.layout.AlignNiFiComponents) AlignProcessGroupComponents(com.thinkbiganalytics.nifi.rest.client.layout.AlignProcessGroupComponents) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) 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 27 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO 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 28 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class LegacyNifiRestClient method getPropertiesForTemplateByName.

/**
 * Expose all Properties for a given Template as parameters for external use If template is not found it will return an Empty ArrayList()
 */
public List<NifiProperty> getPropertiesForTemplateByName(String templateName) {
    TemplateDTO dto = getTemplateByName(templateName);
    if (dto != null) {
        // populate the snippet
        dto = getTemplateById(dto.getId());
    }
    ProcessGroupDTO rootProcessGroup = getProcessGroup("root", false, false);
    return NifiPropertyUtil.getPropertiesForTemplate(rootProcessGroup, dto, propertyDescriptorTransform);
}
Also used : TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)

Example 29 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class LegacyNifiRestClient method startProcessGroupAndParentInputPorts.

public void startProcessGroupAndParentInputPorts(ProcessGroupDTO entity) {
    // 1 startAll
    try {
        startAll(entity.getId(), entity.getParentGroupId());
    } catch (NifiClientRuntimeException e) {
        log.error("Error trying to mark connection ports Running for {}", entity.getName());
    }
    Set<PortDTO> ports = null;
    try {
        ports = getPortsForProcessGroup(entity.getParentGroupId());
    } catch (NifiClientRuntimeException e) {
        log.error("Error getPortsForProcessGroup {}", entity.getName());
    }
    if (ports != null && !ports.isEmpty()) {
        Map<String, PortDTO> portsById = ports.stream().collect(Collectors.toMap(port -> port.getId(), port -> port));
        ProcessGroupFlowDTO flow = getNiFiRestClient().processGroups().flow(entity.getParentGroupId());
        if (flow != null) {
            Set<PortDTO> matchingPorts = new HashSet<>();
            flow.getFlow().getConnections().stream().map(connectionEntity -> connectionEntity.getComponent()).forEach(connectionDTO -> {
                // map input ports
                if (connectionDTO.getDestination().getGroupId().equalsIgnoreCase(entity.getId()) && portsById.containsKey(connectionDTO.getSource().getId())) {
                    matchingPorts.add(portsById.get(connectionDTO.getSource().getId()));
                }
                // map output ports
                if (connectionDTO.getSource().getGroupId().equalsIgnoreCase(entity.getId()) && portsById.containsKey(connectionDTO.getDestination().getId())) {
                    matchingPorts.add(portsById.get(connectionDTO.getDestination().getId()));
                }
            });
            for (PortDTO port : matchingPorts) {
                port.setState(NifiProcessUtil.PROCESS_STATE.RUNNING.name());
                if (port.getType().equalsIgnoreCase(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name())) {
                    try {
                        if (port.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name())) {
                            PortDTO stoppedPort = stopInputPort(entity.getParentGroupId(), port.getId());
                            if (stoppedPort.getValidationErrors() != null && !stoppedPort.getValidationErrors().isEmpty()) {
                                startInputPort(entity.getParentGroupId(), port.getId());
                            } else {
                                String validationErrors = stoppedPort.getValidationErrors() != null ? ("Validation Errors: " + stoppedPort.getValidationErrors().stream().collect(Collectors.joining(","))) : "";
                                log.warn("Unable to start input port [" + port.getId() + "] with name: [" + port.getName() + "] within process group: [" + port.getParentGroupId() + "]. " + validationErrors);
                            }
                        } else {
                            startInputPort(entity.getParentGroupId(), port.getId());
                        }
                    } catch (NifiClientRuntimeException e) {
                        log.error("Error starting Input Port {} for process group {}", port.getName(), entity.getName());
                    }
                } else if (port.getType().equalsIgnoreCase(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name())) {
                    try {
                        if (port.getState().equalsIgnoreCase(NifiProcessUtil.PROCESS_STATE.DISABLED.name())) {
                            PortDTO stoppedPort = stopOutputPort(entity.getParentGroupId(), port.getId());
                            if (stoppedPort.getValidationErrors() != null && !stoppedPort.getValidationErrors().isEmpty()) {
                                startOutputPort(entity.getParentGroupId(), port.getId());
                            } else {
                                String validationErrors = stoppedPort.getValidationErrors() != null ? ("Validation Errors: " + stoppedPort.getValidationErrors().stream().collect(Collectors.joining(","))) : "";
                                log.warn("Unable to start output port [" + port.getId() + "] with name: [" + port.getName() + "] within process group: [" + port.getParentGroupId() + "]. " + validationErrors);
                            }
                        } else {
                            startOutputPort(entity.getParentGroupId(), port.getId());
                        }
                    } catch (NifiClientRuntimeException e) {
                        log.error("Error starting Output Port {} for process group {}", port.getName(), entity.getName());
                    }
                }
            }
        }
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) StringUtils(org.apache.commons.lang3.StringUtils) ClientErrorException(javax.ws.rs.ClientErrorException) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) ConfigurationPropertyReplacer(com.thinkbiganalytics.nifi.feedmgr.ConfigurationPropertyReplacer) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) NifiPropertyUtil(com.thinkbiganalytics.nifi.rest.support.NifiPropertyUtil) AboutDTO(org.apache.nifi.web.api.dto.AboutDTO) Map(java.util.Map) BulletinDTO(org.apache.nifi.web.api.dto.BulletinDTO) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ReusableTemplateCreationCallback(com.thinkbiganalytics.nifi.feedmgr.ReusableTemplateCreationCallback) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Collection(java.util.Collection) Set(java.util.Set) NifiPropertyGroup(com.thinkbiganalytics.nifi.rest.model.NifiPropertyGroup) Collectors(java.util.stream.Collectors) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) Predicate(com.google.common.base.Predicate) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) Iterables(com.google.common.collect.Iterables) NifiConnectionOrderVisitorCache(com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitorCache) NiFiPropertyDescriptor(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptor) HashMap(java.util.HashMap) NifiRemoteProcessGroupUtil(com.thinkbiganalytics.nifi.rest.support.NifiRemoteProcessGroupUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) NiFiObjectCache(com.thinkbiganalytics.nifi.rest.NiFiObjectCache) NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) Nonnull(javax.annotation.Nonnull) TemplateInstanceCreator(com.thinkbiganalytics.nifi.feedmgr.TemplateInstanceCreator) NifiConstants(com.thinkbiganalytics.nifi.rest.support.NifiConstants) Nullable(javax.annotation.Nullable) DocumentedTypeDTO(org.apache.nifi.web.api.dto.DocumentedTypeDTO) Logger(org.slf4j.Logger) TemplateCreationHelper(com.thinkbiganalytics.nifi.feedmgr.TemplateCreationHelper) NifiEnvironmentProperties(com.thinkbiganalytics.nifi.feedmgr.NifiEnvironmentProperties) TimeUnit(java.util.concurrent.TimeUnit) SearchResultsDTO(org.apache.nifi.web.api.dto.search.SearchResultsDTO) Collections(java.util.Collections) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ComponentSearchResultDTO(org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) HashSet(java.util.HashSet)

Example 30 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class LegacyNifiRestClient method getInputProcessors.

/**
 * return the Source Processors for a given group
 */
public List<ProcessorDTO> getInputProcessors(String processGroupId) throws NifiComponentNotFoundException {
    // get the group
    ProcessGroupDTO processGroupEntity = getProcessGroup(processGroupId, false, true);
    // get the Source Processors
    List<String> sourceIds = getInputProcessorIds(processGroupId);
    return NifiProcessUtil.findProcessorsByIds(processGroupEntity.getContents().getProcessors(), sourceIds);
}
Also used : ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)

Aggregations

ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)102 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)43 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)34 ArrayList (java.util.ArrayList)32 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)30 PortDTO (org.apache.nifi.web.api.dto.PortDTO)29 HashSet (java.util.HashSet)28 HashMap (java.util.HashMap)21 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)20 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)19 List (java.util.List)18 Set (java.util.Set)18 Collectors (java.util.stream.Collectors)17 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)17 NifiComponentNotFoundException (com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)16 Map (java.util.Map)15 Logger (org.slf4j.Logger)15 LoggerFactory (org.slf4j.LoggerFactory)15 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)14 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)14