Java Code Examples for org.apache.nifi.web.api.dto.ProcessorConfigDTO#setAutoTerminatedRelationships()

The following examples show how to use org.apache.nifi.web.api.dto.ProcessorConfigDTO#setAutoTerminatedRelationships() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlowFromDOMFactory.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public static ProcessorDTO getProcessor(final Element element, final StringEncryptor encryptor) {
    final ProcessorDTO dto = new ProcessorDTO();

    dto.setId(getString(element, "id"));
    dto.setName(getString(element, "name"));
    dto.setType(getString(element, "class"));
    dto.setPosition(getPosition(DomUtils.getChild(element, "position")));
    dto.setStyle(getStyle(DomUtils.getChild(element, "styles")));

    final ProcessorConfigDTO configDto = new ProcessorConfigDTO();
    dto.setConfig(configDto);
    configDto.setComments(getString(element, "comment"));
    configDto.setConcurrentlySchedulableTaskCount(getInt(element, "maxConcurrentTasks"));
    final String schedulingPeriod = getString(element, "schedulingPeriod");
    configDto.setSchedulingPeriod(schedulingPeriod);
    configDto.setPenaltyDuration(getString(element, "penalizationPeriod"));
    configDto.setYieldDuration(getString(element, "yieldPeriod"));
    configDto.setBulletinLevel(getString(element, "bulletinLevel"));
    configDto.setLossTolerant(getBoolean(element, "lossTolerant"));
    final ScheduledState scheduledState = getScheduledState(element);
    dto.setState(scheduledState.toString());

    // handle scheduling strategy
    final String schedulingStrategyName = getString(element, "schedulingStrategy");
    if (schedulingStrategyName == null || schedulingStrategyName.trim().isEmpty()) {
        configDto.setSchedulingStrategy(SchedulingStrategy.TIMER_DRIVEN.name());
    } else {
        configDto.setSchedulingStrategy(schedulingStrategyName.trim());
    }

    // handle execution node
    final String executionNode = getString(element, "executionNode");
    if (executionNode == null || executionNode.trim().isEmpty()) {
        configDto.setExecutionNode(ExecutionNode.ALL.name());
    } else {
        configDto.setExecutionNode(executionNode.trim());
    }

    final Long runDurationNanos = getOptionalLong(element, "runDurationNanos");
    if (runDurationNanos != null) {
        configDto.setRunDurationMillis(TimeUnit.NANOSECONDS.toMillis(runDurationNanos));
    }

    configDto.setProperties(getProperties(element, encryptor));
    configDto.setAnnotationData(getString(element, "annotationData"));

    final Set<String> autoTerminatedRelationships = new HashSet<>();
    final List<Element> autoTerminateList = getChildrenByTagName(element, "autoTerminatedRelationship");
    for (final Element autoTerminateElement : autoTerminateList) {
        autoTerminatedRelationships.add(autoTerminateElement.getTextContent());
    }
    configDto.setAutoTerminatedRelationships(autoTerminatedRelationships);

    return dto;
}
 
Example 2
Source File: TemplateUtils.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Scrubs processors prior to saving. This includes removing sensitive properties, validation errors, property descriptors, etc.
 *
 * @param processors procs
 */
private static void scrubProcessors(final Set<ProcessorDTO> processors) {
    // go through each processor
    for (final ProcessorDTO processorDTO : processors) {
        final ProcessorConfigDTO processorConfig = processorDTO.getConfig();

        // ensure that some property configuration have been specified
        if (processorConfig != null) {
            // if properties have been specified, remove sensitive ones
            if (processorConfig.getProperties() != null) {
                Map<String, String> processorProperties = processorConfig.getProperties();

                // look for sensitive properties and remove them
                if (processorConfig.getDescriptors() != null) {
                    final Collection<PropertyDescriptorDTO> descriptors = processorConfig.getDescriptors().values();
                    for (PropertyDescriptorDTO descriptor : descriptors) {
                        if (Boolean.TRUE.equals(descriptor.isSensitive())) {
                            processorProperties.put(descriptor.getName(), null);
                        }

                        scrubPropertyDescriptor(descriptor);
                    }
                }
            }

            processorConfig.setCustomUiUrl(null);
            processorConfig.setDefaultConcurrentTasks(null);
            processorConfig.setDefaultSchedulingPeriod(null);
            processorConfig.setAutoTerminatedRelationships(null);
        }

        if (processorDTO.getRelationships() != null) {
            for (final RelationshipDTO relationship : processorDTO.getRelationships()) {
                relationship.setDescription(null);
            }
        }

        processorDTO.setValidationErrors(null);
        processorDTO.setInputRequirement(null);
        processorDTO.setDescription(null);
        processorDTO.setInputRequirement(null);
        processorDTO.setPersistsState(null);
        processorDTO.setState(null);
        processorDTO.setSupportsBatching(null);
        processorDTO.setSupportsEventDriven(null);
        processorDTO.setSupportsParallelProcessing(null);
    }
}
 
Example 3
Source File: FlowFromDOMFactory.java    From nifi with Apache License 2.0 4 votes vote down vote up
public static ProcessorDTO getProcessor(final Element element, final StringEncryptor encryptor, final FlowEncodingVersion flowEncodingVersion) {
    final ProcessorDTO dto = new ProcessorDTO();

    dto.setId(getString(element, "id"));
    dto.setVersionedComponentId(getString(element, "versionedComponentId"));
    dto.setName(getString(element, "name"));
    dto.setType(getString(element, "class"));
    dto.setBundle(getBundle(DomUtils.getChild(element, "bundle")));
    dto.setPosition(getPosition(DomUtils.getChild(element, "position")));
    dto.setStyle(getStyle(DomUtils.getChild(element, "styles")));

    final ProcessorConfigDTO configDto = new ProcessorConfigDTO();
    dto.setConfig(configDto);
    configDto.setComments(getString(element, "comment"));
    configDto.setConcurrentlySchedulableTaskCount(getInt(element, "maxConcurrentTasks"));
    final String schedulingPeriod = getString(element, "schedulingPeriod");
    configDto.setSchedulingPeriod(schedulingPeriod);
    configDto.setPenaltyDuration(getString(element, "penalizationPeriod"));
    configDto.setYieldDuration(getString(element, "yieldPeriod"));
    configDto.setBulletinLevel(getString(element, "bulletinLevel"));
    configDto.setLossTolerant(getBoolean(element, "lossTolerant"));
    final ScheduledState scheduledState = getScheduledState(element);
    dto.setState(scheduledState.toString());

    // handle scheduling strategy
    final String schedulingStrategyName = getString(element, "schedulingStrategy");
    if (schedulingStrategyName == null || schedulingStrategyName.trim().isEmpty()) {
        configDto.setSchedulingStrategy(SchedulingStrategy.TIMER_DRIVEN.name());
    } else {
        configDto.setSchedulingStrategy(schedulingStrategyName.trim());
    }

    // handle execution node
    final String executionNode = getString(element, "executionNode");
    if (executionNode == null || executionNode.trim().isEmpty()) {
        configDto.setExecutionNode(ExecutionNode.ALL.name());
    } else {
        configDto.setExecutionNode(executionNode.trim());
    }

    final Long runDurationNanos = getOptionalLong(element, "runDurationNanos");
    if (runDurationNanos != null) {
        configDto.setRunDurationMillis(TimeUnit.NANOSECONDS.toMillis(runDurationNanos));
    }

    configDto.setProperties(getProperties(element, encryptor, flowEncodingVersion));
    configDto.setAnnotationData(getString(element, "annotationData"));

    final Set<String> autoTerminatedRelationships = new HashSet<>();
    final List<Element> autoTerminateList = getChildrenByTagName(element, "autoTerminatedRelationship");
    for (final Element autoTerminateElement : autoTerminateList) {
        autoTerminatedRelationships.add(autoTerminateElement.getTextContent());
    }
    configDto.setAutoTerminatedRelationships(autoTerminatedRelationships);

    return dto;
}
 
Example 4
Source File: TemplateUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Scrubs processors prior to saving. This includes removing sensitive properties, validation errors, property descriptors, etc.
 *
 * @param processors procs
 */
private static void scrubProcessors(final Set<ProcessorDTO> processors) {
    // go through each processor
    for (final ProcessorDTO processorDTO : processors) {
        final ProcessorConfigDTO processorConfig = processorDTO.getConfig();

        // ensure that some property configuration have been specified
        if (processorConfig != null) {
            // if properties have been specified, remove sensitive ones
            if (processorConfig.getProperties() != null) {
                Map<String, String> processorProperties = processorConfig.getProperties();

                // look for sensitive properties and remove them
                if (processorConfig.getDescriptors() != null) {
                    final Collection<PropertyDescriptorDTO> descriptors = processorConfig.getDescriptors().values();
                    for (PropertyDescriptorDTO descriptor : descriptors) {
                        if (Boolean.TRUE.equals(descriptor.isSensitive())) {
                            processorProperties.put(descriptor.getName(), null);
                        }

                        scrubPropertyDescriptor(descriptor);
                    }
                }
            }

            processorConfig.setCustomUiUrl(null);
            processorConfig.setDefaultConcurrentTasks(null);
            processorConfig.setDefaultSchedulingPeriod(null);
            processorConfig.setAutoTerminatedRelationships(null);
        }

        if (processorDTO.getRelationships() != null) {
            for (final RelationshipDTO relationship : processorDTO.getRelationships()) {
                relationship.setDescription(null);
            }
        }

        processorDTO.setExtensionMissing(null);
        processorDTO.setMultipleVersionsAvailable(null);
        processorDTO.setValidationErrors(null);
        processorDTO.setValidationStatus(null);
        processorDTO.setInputRequirement(null);
        processorDTO.setDescription(null);
        processorDTO.setInputRequirement(null);
        processorDTO.setPersistsState(null);
        processorDTO.setSupportsBatching(null);
        processorDTO.setSupportsEventDriven(null);
        processorDTO.setSupportsParallelProcessing(null);
    }
}
 
Example 5
Source File: ParameterContextIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testProcessorStartedAfterLongValidationPeriod() throws NiFiClientException, IOException, InterruptedException {
    final ParameterContextEntity createdContextEntity = createParameterContext("sleep", "6 secs");

    // Set the Parameter Context on the root Process Group
    setParameterContext("root", createdContextEntity);

    // Create a Processor and update it to reference Parameter "name"
    ProcessorEntity processorEntity = createProcessor(TEST_PROCESSORS_PACKAGE + ".Sleep", NIFI_GROUP_ID, TEST_EXTENSIONS_ARTIFACT_ID, getNiFiVersion());
    final String processorId = processorEntity.getId();

    // Update processor to reference Parameter "name"
    final ProcessorConfigDTO config = processorEntity.getComponent().getConfig();
    config.setProperties(Collections.singletonMap("Validate Sleep Time", "#{sleep}"));
    config.setAutoTerminatedRelationships(Collections.singleton("success"));
    getNifiClient().getProcessorClient().updateProcessor(processorEntity);

    waitForValidProcessor(processorId);

    // Start Processors
    getNifiClient().getProcessorClient().startProcessor(processorId, processorEntity.getRevision().getClientId(), 1);

    try {
        // Update Parameter Context to a long validation time.
        final ParameterContextUpdateRequestEntity updateRequestEntity = updateParameterContext(createdContextEntity, "sleep", "6 sec");

        final Set<AffectedComponentEntity> affectedComponents = updateRequestEntity.getRequest().getReferencingComponents();
        assertEquals(1, affectedComponents.size());
        final String affectedComponentId = affectedComponents.iterator().next().getId();
        assertEquals(processorId, affectedComponentId);

        getClientUtil().waitForParameterContextRequestToComplete(createdContextEntity.getId(), updateRequestEntity.getRequest().getRequestId());

        waitForRunningProcessor(processorId);
    } finally {
        // Ensure that we stop the processor so that other tests are allowed to change the Parameter Context, etc.
        getNifiClient().getProcessorClient().stopProcessor(processorId, processorEntity.getRevision().getClientId(), 2);
        waitForStoppedProcessor(processorId);

        getNifiClient().getProcessorClient().deleteProcessor(processorId, processorEntity.getRevision().getClientId(), 3);
    }
}
 
Example 6
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 4 votes vote down vote up
public ProcessorEntity setAutoTerminatedRelationships(final ProcessorEntity currentEntity, final Set<String> autoTerminatedRelationships) throws NiFiClientException, IOException {
    final ProcessorConfigDTO config = new ProcessorConfigDTO();
    config.setAutoTerminatedRelationships(autoTerminatedRelationships);
    return updateProcessorConfig(currentEntity, config);
}