Search in sources :

Example 16 with FlowSnippetDTO

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

the class TemplateCreationHelper method createTemporaryTemplateFlow.

/**
 * Creates an instance of the supplied template under the temporary inspection group inside its own process group
 *
 * @param templateId the template to instantiate
 * @return the process group holding this template
 */
public ProcessGroupDTO createTemporaryTemplateFlow(@Nonnull final String templateId) {
    ProcessGroupDTO temporaryTemplateInspectionGroup = nifiObjectCache.getOrCreateTemporaryTemplateInspectionGroup();
    // next create the temp group
    snapshotControllerServiceReferences();
    ProcessGroupDTO tempGroup = null;
    try {
        tempGroup = nifiRestClient.processGroups().create(temporaryTemplateInspectionGroup.getId(), "template_" + System.currentTimeMillis());
    } catch (NifiComponentNotFoundException e) {
        nifiObjectCache.resetTemporaryTemplateInspectionGroup();
        tempGroup = nifiRestClient.processGroups().create(temporaryTemplateInspectionGroup.getId(), "template_" + System.currentTimeMillis());
    }
    TemplateInstance instance = instantiateFlowFromTemplate(tempGroup.getId(), templateId);
    FlowSnippetDTO snippet = instance.getFlowSnippetDTO();
    identifyNewlyCreatedControllerServiceReferences(instance);
    tempGroup.setContents(snippet);
    // now delete it
    nifiRestClient.processGroups().delete(tempGroup);
    cleanupControllerServices();
    return tempGroup;
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Example 17 with FlowSnippetDTO

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

the class TemplateInstanceCreator method createTemplate.

public NifiProcessGroup createTemplate() throws TemplateCreationException {
    try {
        NifiProcessGroup newProcessGroup = null;
        TemplateDTO template = restClient.getTemplateById(templateId);
        VersionedProcessGroup versionedProcessGroup = null;
        if (template != null) {
            TemplateCreationHelper templateCreationHelper = new TemplateCreationHelper(this.restClient);
            templateCreationHelper.setTemplateProperties(templateProperties);
            String processGroupId = null;
            ProcessGroupDTO group = null;
            if (isCreateReusableFlow()) {
                log.info("Creating a new Reusable flow instance for template: {} ", template.getName());
                // 1 get/create the parent "reusable_templates" processgroup
                ProcessGroupDTO reusableParentGroup = restClient.getProcessGroupByName("root", TemplateCreationHelper.REUSABLE_TEMPLATES_PROCESS_GROUP_NAME);
                if (reusableParentGroup == null) {
                    reusableParentGroup = restClient.createProcessGroup("root", TemplateCreationHelper.REUSABLE_TEMPLATES_PROCESS_GROUP_NAME);
                }
                ProcessGroupDTO thisGroup = restClient.getProcessGroupByName(reusableParentGroup.getId(), template.getName());
                if (thisGroup != null) {
                    // version the group
                    log.info("A previous Process group of with this name {} was found.  Versioning it before continuing", thisGroup.getName());
                    versionedProcessGroup = templateCreationHelper.versionProcessGroup(thisGroup, this.getVersionIdentifier());
                }
                group = restClient.createProcessGroup(reusableParentGroup.getId(), template.getName());
            } else {
                String tmpName = template.getName() + "_" + System.currentTimeMillis();
                group = restClient.createProcessGroup(tmpName);
                log.info("Creating a temporary process group with name {} for template {} ", tmpName, template.getName());
            }
            processGroupId = group.getId();
            if (StringUtils.isNotBlank(processGroupId)) {
                // snapshot the existing controller services
                templateCreationHelper.snapshotControllerServiceReferences();
                log.info("Successfully Snapshot of controller services");
                // create the flow from the template
                TemplateInstance instance = templateCreationHelper.instantiateFlowFromTemplate(processGroupId, templateId);
                FlowSnippetDTO flowSnippetDTO = instance.getFlowSnippetDTO();
                log.info("Successfully created the temp flow");
                if (this.createReusableFlow) {
                    ensureInputPortsForReuseableTemplate(processGroupId);
                    log.info("Reusable flow, input ports created successfully.");
                }
                // mark the new services that were created as a result of creating the new flow from the template
                templateCreationHelper.identifyNewlyCreatedControllerServiceReferences(instance);
                ProcessGroupDTO entity = restClient.getProcessGroup(processGroupId, true, true);
                // replace static properties and inject values into the flow
                List<NifiProperty> processorProperties = NifiPropertyUtil.getProperties(entity, restClient.getPropertyDescriptorTransform());
                if (processorProperties != null) {
                    boolean didReplace = false;
                    for (NifiProperty property : processorProperties) {
                        boolean replaced = ConfigurationPropertyReplacer.resolveStaticConfigurationProperty(property, staticConfigPropertyMap);
                        if (replaced) {
                            // update the properties that are replaced
                            if (property.getPropertyDescriptor() != null && StringUtils.isNotBlank(property.getPropertyDescriptor().getIdentifiesControllerService())) {
                                // verify the property is a valid cs property
                                String value = property.getValue();
                                if (templateCreationHelper.getEnabledServiceNameMap().containsKey(value)) {
                                    property.setValue(templateCreationHelper.getEnabledServiceNameMap().get(value).get(0).getId());
                                }
                            }
                            restClient.updateProcessorProperty(property.getProcessGroupId(), property.getProcessorId(), property);
                            didReplace = true;
                        }
                    }
                    // if we replaced any properties, refetch to get the latest data
                    if (didReplace) {
                        entity = restClient.getProcessGroup(processGroupId, true, true);
                    }
                }
                // identify the various processors (first level initial processors)
                List<ProcessorDTO> inputProcessors = NifiProcessUtil.getInputProcessors(entity);
                ProcessorDTO input = null;
                List<ProcessorDTO> nonInputProcessors = NifiProcessUtil.getNonInputProcessors(entity);
                // if the input is null attempt to get the first input available on the template
                if (input == null && inputProcessors != null && !inputProcessors.isEmpty()) {
                    input = inputProcessors.get(0);
                }
                log.info("Attempt to update/validate controller services for template.");
                // update any references to the controller services and try to assign the value to an enabled service if it is not already
                boolean updatedControllerServices = false;
                if (input != null) {
                    log.info("attempt to update controllerservices on {} input processor ", input.getName());
                    List<NifiProperty> updatedProperties = templateCreationHelper.updateControllerServiceReferences(Lists.newArrayList(inputProcessors), staticConfigPropertyStringMap, instance);
                    updatedControllerServices = !updatedProperties.isEmpty();
                }
                log.info("attempt to update controllerservices on {} processors ", (nonInputProcessors != null ? nonInputProcessors.size() : 0));
                List<NifiProperty> updatedProperties = templateCreationHelper.updateControllerServiceReferences(nonInputProcessors, staticConfigPropertyStringMap, instance);
                if (!updatedControllerServices) {
                    updatedControllerServices = !updatedProperties.isEmpty();
                }
                log.info("Controller service validation complete");
                // refetch processors for updated errors
                entity = restClient.getProcessGroup(processGroupId, true, true);
                nonInputProcessors = NifiProcessUtil.getNonInputProcessors(entity);
                inputProcessors = NifiProcessUtil.getInputProcessors(entity);
                if (inputProcessors != null && !inputProcessors.isEmpty()) {
                    input = inputProcessors.get(0);
                }
                // /make the input/output ports in the category group as running
                if (isCreateReusableFlow()) {
                    log.info("Reusable flow, attempt to mark the connection ports as running.");
                    templateCreationHelper.startProcessGroupAndParentInputPorts(entity);
                    // templateCreationHelper.markConnectionPortsAsRunning(entity);
                    log.info("Reusable flow.  Successfully marked the ports as running.");
                }
                newProcessGroup = new NifiProcessGroup(entity, input, nonInputProcessors);
                newProcessGroup.setVersionedProcessGroup(versionedProcessGroup);
                newProcessGroup.setReusableFlowInstance(isCreateReusableFlow());
                if (isCreateReusableFlow()) {
                    // call listeners notify of before mark as running  processing
                    if (creationCallback != null) {
                        try {
                            creationCallback.beforeMarkAsRunning(template.getName(), entity);
                        } catch (Exception e) {
                            log.error("Error calling callback beforeMarkAsRunning ", e);
                        }
                    }
                    log.info("Reusable flow, attempt to mark the Processors as running.");
                    templateCreationHelper.markProcessorsAsRunning(newProcessGroup);
                    log.info("Reusable flow.  Successfully marked the Processors as running.");
                    // align items
                    AlignProcessGroupComponents alignProcessGroupComponents = new AlignProcessGroupComponents(restClient.getNiFiRestClient(), entity.getParentGroupId());
                    alignProcessGroupComponents.autoLayout();
                }
                templateCreationHelper.cleanupControllerServices();
                log.info("Controller service cleanup complete");
                List<NifiError> errors = templateCreationHelper.getErrors();
                // add any global errors to the object
                if (errors != null && !errors.isEmpty()) {
                    for (NifiError error : errors) {
                        newProcessGroup.addError(error);
                    }
                }
                newProcessGroup.setSuccess(!newProcessGroup.hasFatalErrors());
                if (!newProcessGroup.isSuccess()) {
                    log.info("Errors while importing the template. {} errors found. {}", (errors != null ? errors.size() : 0), (errors != null ? " - " + StringUtils.join(errors, ",") : ""));
                } else {
                    log.info("Success.  Finished importing template ");
                }
                return newProcessGroup;
            }
        }
    } catch (final Exception e) {
        if (log.isDebugEnabled() && e instanceof WebApplicationException) {
            final Response response = ((WebApplicationException) e).getResponse();
            log.debug("NiFi server returned error: {}", response.readEntity(String.class), e);
        }
        throw new TemplateCreationException("Unable to create the template for the Id of [" + templateId + "]. " + e.getMessage(), e);
    }
    return null;
}
Also used : FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) WebApplicationException(javax.ws.rs.WebApplicationException) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) VersionedProcessGroup(com.thinkbiganalytics.nifi.rest.model.VersionedProcessGroup) WebApplicationException(javax.ws.rs.WebApplicationException) Response(javax.ws.rs.core.Response) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) AlignProcessGroupComponents(com.thinkbiganalytics.nifi.rest.client.layout.AlignProcessGroupComponents) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)

Example 18 with FlowSnippetDTO

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

the class CreateFeedBuilder method build.

/**
 * Build the NiFi flow instance
 *
 * @return an object indicating if the feed flow was successfully built or not
 */
public NifiProcessGroup build() throws FeedCreationException {
    try {
        log.info("Creating the feed {}.{} ", category, feedName);
        newProcessGroup = null;
        Stopwatch totalTime = Stopwatch.createStarted();
        Stopwatch eventTime = Stopwatch.createStarted();
        TemplateDTO template = getTemplate();
        if (template != null) {
            log.debug("Time to get Template {}.  ElapsedTime: {} ms", template.getName(), eventTime(eventTime));
            // create the encompassing process group
            eventTime.start();
            ProcessGroupDTO feedProcessGroup = createProcessGroupForFeed();
            log.debug("Time to create process group.  ElapsedTime: {} ms", eventTime(eventTime));
            if (feedProcessGroup != null) {
                String processGroupId = feedProcessGroup.getId();
                // snapshot the existing controller services
                eventTime.start();
                templateCreationHelper.snapshotControllerServiceReferences();
                log.debug("Time to snapshotControllerServices.  ElapsedTime: {} ms", eventTime(eventTime));
                // create the flow from the template
                eventTime.start();
                TemplateInstance instance = templateCreationHelper.instantiateFlowFromTemplate(processGroupId, templateId);
                FlowSnippetDTO feedInstance = instance.getFlowSnippetDTO();
                feedProcessGroup.setContents(feedInstance);
                log.debug("Time to instantiateFlowFromTemplate.  ElapsedTime: {} ms", eventTime(eventTime));
                eventTime.start();
                String feedCategoryId = feedProcessGroup.getParentGroupId();
                ProcessGroupDTO categoryGroup = this.categoryGroup;
                if (categoryGroup == null) {
                    categoryGroup = this.categoryGroup = restClient.getProcessGroup(feedCategoryId, false, false);
                }
                // update the group with this template?
                updatePortConnectionsForProcessGroup(feedProcessGroup, categoryGroup);
                log.debug("Time to updatePortConnectionsForProcessGroup.  ElapsedTime: {} ms", eventTime(eventTime));
                eventTime.start();
                // mark the new services that were created as a result of creating the new flow from the template
                templateCreationHelper.identifyNewlyCreatedControllerServiceReferences(instance);
                log.debug("Time to identifyNewlyCreatedControllerServiceReferences.  ElapsedTime: {} ms", eventTime(eventTime));
                eventTime.start();
                // match the properties incoming to the defined properties
                updateProcessGroupProperties(processGroupId, feedProcessGroup.getName());
                log.debug("Time to updateProcessGroupProperties.  ElapsedTime: {} ms", eventTime(eventTime));
                eventTime.start();
                // Fetch the Feed Group now that it has the flow in it
                ProcessGroupDTO entity = restClient.getProcessGroup(processGroupId, true, true);
                log.debug("Time to getProcessGroup.  ElapsedTime: {} ms", eventTime(eventTime));
                eventTime.start();
                ProcessorDTO input = fetchInputProcessorForProcessGroup(entity);
                ProcessorDTO cleanupProcessor = NifiProcessUtil.findFirstProcessorsByType(NifiProcessUtil.getInputProcessors(entity), "com.thinkbiganalytics.nifi.v2.metadata.TriggerCleanup");
                List<ProcessorDTO> nonInputProcessors = NifiProcessUtil.getNonInputProcessors(entity);
                log.debug("Time to fetchInputProcessorForProcessGroup.  ElapsedTime: {} ms", eventTime(eventTime));
                eventTime.start();
                List<NifiProperty> updatedControllerServiceProperties = new ArrayList<>();
                // update any references to the controller services and try to assign the value to an enabled service if it is not already
                if (input != null) {
                    updatedControllerServiceProperties.addAll(templateCreationHelper.updateControllerServiceReferences(Lists.newArrayList(input), instance));
                }
                if (cleanupProcessor != null) {
                    updatedControllerServiceProperties.addAll(templateCreationHelper.updateControllerServiceReferences(Collections.singletonList(cleanupProcessor), instance));
                }
                updatedControllerServiceProperties.addAll(templateCreationHelper.updateControllerServiceReferences(nonInputProcessors, instance));
                log.debug("Time to updatedControllerServiceProperties.  ElapsedTime: {} ms", eventTime(eventTime));
                eventTime.start();
                // refetch processors for updated errors
                entity = restClient.getProcessGroup(processGroupId, true, true);
                input = fetchInputProcessorForProcessGroup(entity);
                nonInputProcessors = NifiProcessUtil.getNonInputProcessors(entity);
                newProcessGroup = new NifiProcessGroup(entity, input, nonInputProcessors);
                log.debug("Time to re-fetchInputProcessorForProcessGroup.  ElapsedTime: {} ms", eventTime(eventTime));
                // Validate and if invalid Delete the process group
                if (newProcessGroup.hasFatalErrors()) {
                    eventTime.start();
                    removeProcessGroup(entity);
                    // cleanupControllerServices();
                    newProcessGroup.setSuccess(false);
                    log.debug("Time to removeProcessGroup. Errors found.  ElapsedTime: {} ms", eventTime(eventTime));
                } else {
                    eventTime.start();
                    // update the input schedule
                    updateFeedSchedule(newProcessGroup, input);
                    log.debug("Time to update feed schedule.  ElapsedTime: {} ms", eventTime(eventTime));
                    eventTime.start();
                    // just need to update for this processgroup
                    Collection<ProcessorDTO> processors = NifiProcessUtil.getProcessors(entity);
                    Collection<ConnectionDTO> connections = NifiConnectionUtil.getAllConnections(entity);
                    nifiFlowCache.updateFlowForFeed(feedMetadata, entity.getId(), processors, connections);
                    log.debug("Time to build flow graph with {} processors and {} connections.  ElapsedTime: {} ms", processors.size(), connections.size(), eventTime(eventTime));
                    /*

                        //Cache the processorIds to the respective flowIds for availability in the ProvenanceReportingTask
                        NifiVisitableProcessGroup group = nifiFlowCache.getFlowOrder(newProcessGroup.getProcessGroupEntity(), true);
                       log.debug("Time to get the flow order.  ElapsedTime: {} ms", eventTime(eventTime));

                        eventTime.start();
                        NifiFlowProcessGroup
                            flow =
                            new NifiFlowBuilder().build(
                                group);
                       log.debug("Time to build flow graph with {} processors.  ElapsedTime: {} ms", flow.getProcessorMap().size(), eventTime(eventTime));

                        eventTime.start();
                        nifiFlowCache.updateFlow(feedMetadata, flow);
                       log.debug("Time to update NiFiFlowCache with {} processors.  ElapsedTime: {} ms", flow.getProcessorMap().size(), eventTime(eventTime));
                        */
                    eventTime.start();
                    // disable all inputs
                    restClient.disableInputProcessors(newProcessGroup.getProcessGroupEntity().getId());
                    log.debug("Time to disableInputProcessors.  ElapsedTime: {} ms", eventTime(eventTime));
                    eventTime.start();
                    // mark everything else as running
                    templateCreationHelper.markProcessorsAsRunning(newProcessGroup);
                    log.debug("Time to markNonInputsAsRunning.  ElapsedTime: {} ms", eventTime(eventTime));
                    // if desired start the input processor
                    if (input != null) {
                        eventTime.start();
                        if (enabled) {
                            markInputAsRunning(newProcessGroup, input);
                            // /make the input/output ports in the category group as running
                            if (hasConnectionPorts()) {
                                templateCreationHelper.markConnectionPortsAsRunning(entity);
                            }
                        } else {
                            // /make the input/output ports in the category group as running
                            if (hasConnectionPorts()) {
                                templateCreationHelper.markConnectionPortsAsRunning(entity);
                            }
                            markInputAsStopped(newProcessGroup, input);
                        }
                        log.debug("Time to mark input as {}.  ElapsedTime: {} ms", (enabled ? "Running" : "Stopped"), eventTime(eventTime));
                    }
                    if (newProcessGroup.hasFatalErrors()) {
                        eventTime.start();
                        rollback();
                        newProcessGroup.setRolledBack(true);
                        // cleanupControllerServices();
                        newProcessGroup.setSuccess(false);
                        log.debug("Time to rollback on Fatal Errors.  ElapsedTime: {} ms", eventTime(eventTime));
                    }
                    List<NifiError> templateCreationErrors = templateCreationHelper.getErrors();
                    if (templateCreationErrors != null) {
                        errors.addAll(templateCreationErrors);
                    }
                    // add any global errors to the object
                    if (errors != null && !errors.isEmpty()) {
                        for (NifiError error : errors) {
                            newProcessGroup.addError(error);
                            if (error.isFatal()) {
                                newProcessGroup.setSuccess(false);
                                if (!newProcessGroup.isRolledBack()) {
                                    rollback();
                                    newProcessGroup.setRolledBack(true);
                                }
                            }
                        }
                    }
                }
                eventTime.start();
                templateCreationHelper.cleanupControllerServices();
                // fix the feed metadata controller service references
                updateFeedMetadataControllerServiceReferences(updatedControllerServiceProperties);
                log.debug("Time cleanup controller services.  ElapsedTime: {} ms", eventTime(eventTime));
                // align items
                if (this.autoAlign) {
                    eventTime.start();
                    log.info("Aligning Feed flows in NiFi ");
                    AlignProcessGroupComponents alignProcessGroupComponents = new AlignProcessGroupComponents(restClient.getNiFiRestClient(), entity.getParentGroupId());
                    alignProcessGroupComponents.autoLayout();
                    // fetch the parent to get that id to align
                    if (newCategory) {
                        log.info("This is the first feed created in the category {}.  Aligning the categories. ", feedMetadata.getCategory().getSystemName());
                        new AlignProcessGroupComponents(restClient.getNiFiRestClient(), this.categoryGroup.getParentGroupId()).autoLayout();
                    }
                    log.info("Time align feed process groups.  ElapsedTime: {} ms", eventTime(eventTime));
                } else {
                    log.info("Skipping auto alignment in NiFi. You can always manually align this category and all of its feeds by using the rest api: /v1/feedmgr/nifi/auto-align/{}", entity.getParentGroupId());
                    if (newCategory) {
                        log.info("To re align the categories: /v1/feedmgr/nifi/auto-align/{}", this.categoryGroup.getParentGroupId());
                    }
                }
            }
        } else {
            log.error("Unable to create/save the feed {}.  Unable to find a template for id {}", feedName, templateId);
            throw new FeedCreationException("Unable to create the feed [" + feedName + "]. Unable to find a template with id " + templateId);
        }
        log.info("Time save Feed flow in NiFi.  ElapsedTime: {} ms", eventTime(totalTime));
        return newProcessGroup;
    } catch (NifiClientRuntimeException e) {
        throw new FeedCreationException("Unable to create the feed [" + feedName + "]. " + e.getMessage(), e);
    }
}
Also used : FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) FeedCreationException(com.thinkbiganalytics.nifi.feedmgr.FeedCreationException) NifiClientRuntimeException(com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException) TemplateInstance(com.thinkbiganalytics.nifi.feedmgr.TemplateInstance) NifiError(com.thinkbiganalytics.nifi.rest.model.NifiError) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) AlignProcessGroupComponents(com.thinkbiganalytics.nifi.rest.client.layout.AlignProcessGroupComponents) NifiProcessGroup(com.thinkbiganalytics.nifi.rest.model.NifiProcessGroup)

Example 19 with FlowSnippetDTO

use of org.apache.nifi.web.api.dto.FlowSnippetDTO in project nifi by apache.

the class StandardNiFiServiceFacade method createTemplateInstance.

@Override
public FlowEntity createTemplateInstance(final String groupId, final Double originX, final Double originY, final String templateEncodingVersion, final FlowSnippetDTO requestSnippet, final String idGenerationSeed) {
    // instantiate the template - there is no need to make another copy of the flow snippet since the actual template
    // was copied and this dto is only used to instantiate it's components (which as already completed)
    final FlowSnippetDTO snippet = templateDAO.instantiateTemplate(groupId, originX, originY, templateEncodingVersion, requestSnippet, idGenerationSeed);
    // save the flow
    controllerFacade.save();
    // post process the new flow snippet
    final FlowDTO flowDto = postProcessNewFlowSnippet(groupId, snippet);
    final FlowEntity flowEntity = new FlowEntity();
    flowEntity.setFlow(flowDto);
    return flowEntity;
}
Also used : FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) VersionedFlowDTO(org.apache.nifi.web.api.dto.VersionedFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) FlowEntity(org.apache.nifi.web.api.entity.FlowEntity) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) VersionedFlowEntity(org.apache.nifi.web.api.entity.VersionedFlowEntity)

Example 20 with FlowSnippetDTO

use of org.apache.nifi.web.api.dto.FlowSnippetDTO in project nifi by apache.

the class TestFlowController method testInstantiateSnippetWithProcessor.

@Test
public void testInstantiateSnippetWithProcessor() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ProcessorNode processorNode = controller.createProcessor(DummyProcessor.class.getName(), id, coordinate);
    // create a processor dto
    final ProcessorDTO processorDTO = new ProcessorDTO();
    // use a different id here
    processorDTO.setId(UUID.randomUUID().toString());
    processorDTO.setPosition(new PositionDTO(new Double(0), new Double(0)));
    processorDTO.setStyle(processorNode.getStyle());
    processorDTO.setParentGroupId("1234");
    processorDTO.setInputRequirement(processorNode.getInputRequirement().name());
    processorDTO.setPersistsState(processorNode.getProcessor().getClass().isAnnotationPresent(Stateful.class));
    processorDTO.setRestricted(processorNode.isRestricted());
    processorDTO.setExtensionMissing(processorNode.isExtensionMissing());
    processorDTO.setType(processorNode.getCanonicalClassName());
    processorDTO.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion()));
    processorDTO.setName(processorNode.getName());
    processorDTO.setState(processorNode.getScheduledState().toString());
    processorDTO.setRelationships(new ArrayList<>());
    processorDTO.setDescription("description");
    processorDTO.setSupportsParallelProcessing(!processorNode.isTriggeredSerially());
    processorDTO.setSupportsEventDriven(processorNode.isEventDrivenSupported());
    processorDTO.setSupportsBatching(processorNode.isSessionBatchingSupported());
    ProcessorConfigDTO configDTO = new ProcessorConfigDTO();
    configDTO.setSchedulingPeriod(processorNode.getSchedulingPeriod());
    configDTO.setPenaltyDuration(processorNode.getPenalizationPeriod());
    configDTO.setYieldDuration(processorNode.getYieldPeriod());
    configDTO.setRunDurationMillis(processorNode.getRunDuration(TimeUnit.MILLISECONDS));
    configDTO.setConcurrentlySchedulableTaskCount(processorNode.getMaxConcurrentTasks());
    configDTO.setLossTolerant(processorNode.isLossTolerant());
    configDTO.setComments(processorNode.getComments());
    configDTO.setBulletinLevel(processorNode.getBulletinLevel().name());
    configDTO.setSchedulingStrategy(processorNode.getSchedulingStrategy().name());
    configDTO.setExecutionNode(processorNode.getExecutionNode().name());
    configDTO.setAnnotationData(processorNode.getAnnotationData());
    processorDTO.setConfig(configDTO);
    // create the snippet with the processor
    final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO();
    flowSnippetDTO.setProcessors(Collections.singleton(processorDTO));
    // instantiate the snippet
    assertEquals(0, controller.getRootGroup().getProcessors().size());
    controller.instantiateSnippet(controller.getRootGroup(), flowSnippetDTO);
    assertEquals(1, controller.getRootGroup().getProcessors().size());
}
Also used : Stateful(org.apache.nifi.annotation.behavior.Stateful) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) DummyProcessor(org.apache.nifi.controller.service.mock.DummyProcessor) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Test(org.junit.Test)

Aggregations

FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)30 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)15 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)15 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)10 HashMap (java.util.HashMap)9 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)9 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)9 HashSet (java.util.HashSet)8 PortDTO (org.apache.nifi.web.api.dto.PortDTO)8 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)7 PositionDTO (org.apache.nifi.web.api.dto.PositionDTO)7 Test (org.junit.Test)7 Map (java.util.Map)6 ProcessGroup (org.apache.nifi.groups.ProcessGroup)6 RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)6