Java Code Examples for org.apache.nifi.web.api.dto.ProcessorDTO#getConfig()

The following examples show how to use org.apache.nifi.web.api.dto.ProcessorDTO#getConfig() . 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: ProcessorResource.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Populate the uri's for the specified processor and its relationships.
 */
public ProcessorDTO populateRemainingProcessorContent(ProcessorDTO processor) {
    // get the config details and see if there is a custom ui for this processor type
    ProcessorConfigDTO config = processor.getConfig();
    if (config != null) {
        // consider legacy custom ui fist
        String customUiUrl = servletContext.getInitParameter(processor.getType());
        if (StringUtils.isNotBlank(customUiUrl)) {
            config.setCustomUiUrl(customUiUrl);
        } else {
            // see if this processor has any ui extensions
            final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions");
            if (uiExtensionMapping.hasUiExtension(processor.getType())) {
                final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(processor.getType());
                for (final UiExtension uiExtension : uiExtensions) {
                    if (UiExtensionType.ProcessorConfiguration.equals(uiExtension.getExtensionType())) {
                        config.setCustomUiUrl(uiExtension.getContextPath() + "/configure");
                    }
                }
            }
        }
    }

    return processor;
}
 
Example 2
Source File: TemplateUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static void escapeParameterReferences(final ProcessorDTO processorDto) {
    final ProcessorConfigDTO config = processorDto.getConfig();
    if (config == null) {
        return;
    }

    final ParameterParser parameterParser = new ExpressionLanguageAwareParameterParser();

    final Map<String, String> escapedPropertyValues = new HashMap<>();
    for (final Map.Entry<String, String> entry : config.getProperties().entrySet()) {
        final ParameterTokenList references = parameterParser.parseTokens(entry.getValue());
        final String escaped = references.escape();
        escapedPropertyValues.put(entry.getKey(), escaped);
    }

    config.setProperties(escapedPropertyValues);
}
 
Example 3
Source File: AuthorizeParameterReference.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static void authorizeParameterReferences(final FlowSnippetDTO flowSnippet, final Authorizer authorizer, final Authorizable parameterContextAuthorizable, final NiFiUser user) {
    for (final ProcessorDTO processorDto : flowSnippet.getProcessors()) {
        final ProcessorConfigDTO configDto = processorDto.getConfig();
        if (configDto == null) {
            continue;
        }

        authorizeParameterReferences(configDto.getProperties(), authorizer, parameterContextAuthorizable, user);
    }

    for (final ControllerServiceDTO serviceDto : flowSnippet.getControllerServices()) {
        authorizeParameterReferences(serviceDto.getProperties(), authorizer, parameterContextAuthorizable, user);
    }

    // Note: there is no need to recurse here because when a template/snippet is instantiated, if there are any components in child Process Groups, a new Process Group will be created
    // without any Parameter Context, so there is no need to perform any authorization beyond the top-level group where the instantiation is occurring.
}
 
Example 4
Source File: StandardSnippetDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void lookupSensitiveProcessorProperties(final Set<ProcessorDTO> processors) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());

    // 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 && processorConfig.getProperties() != null) {
            final Map<String, String> processorProperties = processorConfig.getProperties();

            // find the corresponding processor
            final ProcessorNode processorNode = rootGroup.findProcessor(processorDTO.getId());
            if (processorNode == null) {
                throw new IllegalArgumentException(String.format("Unable to create snippet because Processor '%s' could not be found", processorDTO.getId()));
            }

            // look for sensitive properties get the actual value
            for (Entry<PropertyDescriptor, String> entry : processorNode.getProperties().entrySet()) {
                final PropertyDescriptor descriptor = entry.getKey();

                if (descriptor.isSensitive()) {
                    processorProperties.put(descriptor.getName(), entry.getValue());
                }
            }
        }
    }
}
 
Example 5
Source File: StandardNiFiWebConfigurationContext.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private ComponentDetails getComponentConfiguration(final ProcessorDTO processor) {
    final ProcessorConfigDTO processorConfig = processor.getConfig();
    return new ComponentDetails.Builder()
            .id(processor.getId())
            .name(processor.getName())
            .type(processor.getType())
            .state(processor.getState())
            .annotationData(processorConfig.getAnnotationData())
            .properties(processorConfig.getProperties())
            .descriptors(buildComponentDescriptorMap(processorConfig))
            .validateErrors(processor.getValidationErrors()).build();
}
 
Example 6
Source File: ProcessorSchemaFunction.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessorSchema apply(ProcessorDTO processorDTO) {
    ProcessorConfigDTO processorDTOConfig = processorDTO.getConfig();

    Map<String, Object> map = new HashMap<>();
    map.put(NAME_KEY, processorDTO.getName());
    map.put(ID_KEY, processorDTO.getId());
    map.put(CLASS_KEY, processorDTO.getType());
    map.put(SCHEDULING_STRATEGY_KEY, processorDTOConfig.getSchedulingStrategy());
    map.put(SCHEDULING_PERIOD_KEY, processorDTOConfig.getSchedulingPeriod());

    map.put(CommonPropertyKeys.MAX_CONCURRENT_TASKS_KEY, processorDTOConfig.getConcurrentlySchedulableTaskCount());
    map.put(ProcessorSchema.PENALIZATION_PERIOD_KEY, processorDTOConfig.getPenaltyDuration());
    map.put(CommonPropertyKeys.YIELD_PERIOD_KEY, processorDTOConfig.getYieldDuration());
    Long runDurationMillis = processorDTOConfig.getRunDurationMillis();
    if (runDurationMillis != null) {
        map.put(ProcessorSchema.RUN_DURATION_NANOS_KEY, runDurationMillis * 1000);
    }
    map.put(ProcessorSchema.AUTO_TERMINATED_RELATIONSHIPS_LIST_KEY, nullToEmpty(processorDTO.getRelationships()).stream()
            .filter(RelationshipDTO::isAutoTerminate)
            .map(RelationshipDTO::getName)
            .collect(Collectors.toList()));
    map.put(PROPERTIES_KEY, new HashMap<>(nullToEmpty(processorDTOConfig.getProperties())));

    String annotationData = processorDTOConfig.getAnnotationData();
    if(annotationData != null && !annotationData.isEmpty()) {
        map.put(ANNOTATION_DATA_KEY, annotationData);
    }

    return new ProcessorSchema(map);
}
 
Example 7
Source File: ProcessorResource.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Populate the uri's for the specified processor and its relationships.
 */
public ProcessorDTO populateRemainingProcessorContent(ProcessorDTO processor) {
    // get the config details and see if there is a custom ui for this processor type
    ProcessorConfigDTO config = processor.getConfig();
    if (config != null) {
        // consider legacy custom ui fist
        String customUiUrl = servletContext.getInitParameter(processor.getType());
        if (StringUtils.isNotBlank(customUiUrl)) {
            config.setCustomUiUrl(customUiUrl);
        } else {
            final BundleDTO bundle = processor.getBundle();

            // see if this processor has any ui extensions
            final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions");
            if (uiExtensionMapping.hasUiExtension(processor.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) {
                final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(processor.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion());
                for (final UiExtension uiExtension : uiExtensions) {
                    if (UiExtensionType.ProcessorConfiguration.equals(uiExtension.getExtensionType())) {
                        config.setCustomUiUrl(uiExtension.getContextPath() + "/configure");
                    }
                }
            }
        }
    }

    return processor;
}
 
Example 8
Source File: StandardSnippetDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void lookupSensitiveProcessorProperties(final Set<ProcessorDTO> processors) {
    final ProcessGroup rootGroup = flowController.getFlowManager().getRootGroup();

    // 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 && processorConfig.getProperties() != null) {
            final Map<String, String> processorProperties = processorConfig.getProperties();

            // find the corresponding processor
            final ProcessorNode processorNode = rootGroup.findProcessor(processorDTO.getId());
            if (processorNode == null) {
                throw new IllegalArgumentException(String.format("Unable to create snippet because Processor '%s' could not be found", processorDTO.getId()));
            }

            // look for sensitive properties get the actual value
            for (Entry<PropertyDescriptor, String> entry : processorNode.getRawPropertyValues().entrySet()) {
                final PropertyDescriptor descriptor = entry.getKey();

                if (descriptor.isSensitive()) {
                    processorProperties.put(descriptor.getName(), entry.getValue());
                }
            }
        }
    }
}
 
Example 9
Source File: StandardNiFiWebConfigurationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
private ComponentDetails getComponentConfiguration(final ProcessorDTO processor) {
    final ProcessorConfigDTO processorConfig = processor.getConfig();
    return new ComponentDetails.Builder()
            .id(processor.getId())
            .name(processor.getName())
            .type(processor.getType())
            .state(processor.getState())
            .annotationData(processorConfig.getAnnotationData())
            .properties(processorConfig.getProperties())
            .descriptors(buildComponentDescriptorMap(processorConfig))
            .validateErrors(processor.getValidationErrors()).build();
}
 
Example 10
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 11
Source File: StandardFlowSynchronizer.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void updateProcessor(final ProcessorNode procNode, final ProcessorDTO processorDTO, final ProcessGroup processGroup, final FlowController controller) {

        procNode.pauseValidationTrigger();
        try {
            final ProcessorConfigDTO config = processorDTO.getConfig();
            procNode.setProcessGroup(processGroup);
            procNode.setLossTolerant(config.isLossTolerant());
            procNode.setPenalizationPeriod(config.getPenaltyDuration());
            procNode.setYieldPeriod(config.getYieldDuration());
            procNode.setBulletinLevel(LogLevel.valueOf(config.getBulletinLevel()));
            updateNonFingerprintedProcessorSettings(procNode, processorDTO);

            if (config.getSchedulingStrategy() != null) {
                procNode.setSchedulingStrategy(SchedulingStrategy.valueOf(config.getSchedulingStrategy()));
            }

            if (config.getExecutionNode() != null) {
                procNode.setExecutionNode(ExecutionNode.valueOf(config.getExecutionNode()));
            }

            // must set scheduling strategy before these two
            procNode.setMaxConcurrentTasks(config.getConcurrentlySchedulableTaskCount());
            procNode.setScheduldingPeriod(config.getSchedulingPeriod());
            if (config.getRunDurationMillis() != null) {
                procNode.setRunDuration(config.getRunDurationMillis(), TimeUnit.MILLISECONDS);
            }

            procNode.setAnnotationData(config.getAnnotationData());

            if (config.getAutoTerminatedRelationships() != null) {
                final Set<Relationship> relationships = new HashSet<>();
                for (final String rel : config.getAutoTerminatedRelationships()) {
                    relationships.add(procNode.getRelationship(rel));
                }
                procNode.setAutoTerminatedRelationships(relationships);
            }

            procNode.setProperties(config.getProperties());

            final ScheduledState scheduledState = ScheduledState.valueOf(processorDTO.getState());
            if (ScheduledState.RUNNING.equals(scheduledState)) {
                procNode.performValidation(); // ensure that processor has been validated
                controller.startProcessor(processGroup.getIdentifier(), procNode.getIdentifier());
            } else if (ScheduledState.DISABLED.equals(scheduledState)) {
                processGroup.disableProcessor(procNode);
            } else if (ScheduledState.STOPPED.equals(scheduledState)) {
                controller.stopProcessor(processGroup.getIdentifier(), procNode.getIdentifier());
            }
        } finally {
            procNode.resumeValidationTrigger();
        }
    }
 
Example 12
Source File: ProcessorAuditor.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts the values for the configured properties from the specified Processor.
 */
private Map<String, String> extractConfiguredPropertyValues(ProcessorNode processor, ProcessorDTO processorDTO) {
    Map<String, String> values = new HashMap<>();

    if (processorDTO.getName() != null) {
        values.put(NAME, processor.getName());
    }
    if (processorDTO.getBundle() != null) {
        final BundleCoordinate bundle = processor.getBundleCoordinate();
        values.put(EXTENSION_VERSION, formatExtensionVersion(processor.getComponentType(), bundle));
    }
    if (processorDTO.getConfig() != null) {
        ProcessorConfigDTO newConfig = processorDTO.getConfig();
        if (newConfig.getConcurrentlySchedulableTaskCount() != null) {
            values.put(CONCURRENTLY_SCHEDULABLE_TASKS, String.valueOf(processor.getMaxConcurrentTasks()));
        }
        if (newConfig.getPenaltyDuration() != null) {
            values.put(PENALTY_DURATION, processor.getPenalizationPeriod());
        }
        if (newConfig.getYieldDuration() != null) {
            values.put(YIELD_DURATION, processor.getYieldPeriod());
        }
        if (newConfig.getBulletinLevel() != null) {
            values.put(BULLETIN_LEVEL, processor.getBulletinLevel().name());
        }
        if (newConfig.getAnnotationData() != null) {
            values.put(ANNOTATION_DATA, processor.getAnnotationData());
        }
        if (newConfig.getSchedulingPeriod() != null) {
            values.put(SCHEDULING_PERIOD, String.valueOf(processor.getSchedulingPeriod()));
        }
        if (newConfig.getAutoTerminatedRelationships() != null) {
            // get each of the auto terminated relationship names
            final Set<Relationship> autoTerminatedRelationships = processor.getAutoTerminatedRelationships();
            final List<String> autoTerminatedRelationshipNames = new ArrayList<>(autoTerminatedRelationships.size());
            for (final Relationship relationship : autoTerminatedRelationships) {
                autoTerminatedRelationshipNames.add(relationship.getName());
            }

            // sort them and include in the configuration
            Collections.sort(autoTerminatedRelationshipNames, Collator.getInstance(Locale.US));
            values.put(AUTO_TERMINATED_RELATIONSHIPS, StringUtils.join(autoTerminatedRelationshipNames, ", "));
        }
        if (newConfig.getProperties() != null) {
            // for each property specified, extract its configured value
            Map<String, String> properties = newConfig.getProperties();
            Map<PropertyDescriptor, String> configuredProperties = processor.getRawPropertyValues();
            for (String propertyName : properties.keySet()) {
                // build a descriptor for getting the configured value
                PropertyDescriptor propertyDescriptor = new PropertyDescriptor.Builder().name(propertyName).build();
                String configuredPropertyValue = configuredProperties.get(propertyDescriptor);

                // if the configured value couldn't be found, use the default value from the actual descriptor
                if (configuredPropertyValue == null) {
                    propertyDescriptor = locatePropertyDescriptor(configuredProperties.keySet(), propertyDescriptor);
                    configuredPropertyValue = propertyDescriptor.getDefaultValue();
                }
                values.put(propertyName, configuredPropertyValue);
            }
        }
        if (newConfig.getComments() != null) {
            values.put(COMMENTS, processor.getComments());
        }
        if (newConfig.getSchedulingStrategy() != null) {
            values.put(SCHEDULING_STRATEGY, processor.getSchedulingStrategy().name());
        }
        if (newConfig.getExecutionNode() != null) {
            values.put(EXECUTION_NODE, processor.getExecutionNode().name());
        }
    }

    return values;
}
 
Example 13
Source File: StandardProcessorDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void verifyUpdate(ProcessorNode processor, ProcessorDTO processorDTO) {
    // ensure the state, if specified, is valid
    if (isNotNull(processorDTO.getState())) {
        try {
            final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());

            // only attempt an action if it is changing
            if (!purposedScheduledState.equals(processor.getScheduledState())) {
                // perform the appropriate action
                switch (purposedScheduledState) {
                    case RUNNING:
                        processor.verifyCanStart();
                        break;
                    case STOPPED:
                        switch (processor.getScheduledState()) {
                            case RUNNING:
                                processor.verifyCanStop();
                                break;
                            case DISABLED:
                                processor.verifyCanEnable();
                                break;
                        }
                        break;
                    case DISABLED:
                        processor.verifyCanDisable();
                        break;
                }
            }
        } catch (IllegalArgumentException iae) {
            throw new IllegalArgumentException(String.format(
                    "The specified processor state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.",
                    processorDTO.getState()));
        }
    }

    boolean modificationRequest = false;
    if (isAnyNotNull(processorDTO.getName(), processorDTO.getBundle())) {
        modificationRequest = true;
    }

    final BundleDTO bundleDTO = processorDTO.getBundle();
    if (bundleDTO != null) {
        // ensures all nodes in a cluster have the bundle, throws exception if bundle not found for the given type
        final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(flowController.getExtensionManager(), processor.getCanonicalClassName(), bundleDTO);
        // ensure we are only changing to a bundle with the same group and id, but different version
        processor.verifyCanUpdateBundle(bundleCoordinate);
    }

    final ProcessorConfigDTO configDTO = processorDTO.getConfig();
    if (configDTO != null) {
        if (isAnyNotNull(configDTO.getAnnotationData(),
                configDTO.getAutoTerminatedRelationships(),
                configDTO.getBulletinLevel(),
                configDTO.getComments(),
                configDTO.getConcurrentlySchedulableTaskCount(),
                configDTO.getPenaltyDuration(),
                configDTO.getProperties(),
                configDTO.getSchedulingPeriod(),
                configDTO.getSchedulingStrategy(),
                configDTO.getExecutionNode(),
                configDTO.getYieldDuration())) {

            modificationRequest = true;
        }

        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(processor, configDTO);

        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }
    }

    if (modificationRequest) {
        processor.verifyCanUpdate();
    }
}
 
Example 14
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 15
Source File: StandardFlowSynchronizer.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private void updateProcessor(final ProcessorNode procNode, final ProcessorDTO processorDTO, final ProcessGroup processGroup, final FlowController controller)
        throws ProcessorInstantiationException {
    final ProcessorConfigDTO config = processorDTO.getConfig();
    procNode.setPosition(toPosition(processorDTO.getPosition()));
    procNode.setName(processorDTO.getName());
    procNode.setStyle(processorDTO.getStyle());
    procNode.setProcessGroup(processGroup);
    procNode.setComments(config.getComments());
    procNode.setLossTolerant(config.isLossTolerant());
    procNode.setPenalizationPeriod(config.getPenaltyDuration());
    procNode.setYieldPeriod(config.getYieldDuration());
    procNode.setBulletinLevel(LogLevel.valueOf(config.getBulletinLevel()));

    if (config.getSchedulingStrategy() != null) {
        procNode.setSchedulingStrategy(SchedulingStrategy.valueOf(config.getSchedulingStrategy()));
    }

    if (config.getExecutionNode() != null) {
        procNode.setExecutionNode(ExecutionNode.valueOf(config.getExecutionNode()));
    }

    // must set scheduling strategy before these two
    procNode.setMaxConcurrentTasks(config.getConcurrentlySchedulableTaskCount());
    procNode.setScheduldingPeriod(config.getSchedulingPeriod());
    if (config.getRunDurationMillis() != null) {
        procNode.setRunDuration(config.getRunDurationMillis(), TimeUnit.MILLISECONDS);
    }

    procNode.setAnnotationData(config.getAnnotationData());

    if (config.getAutoTerminatedRelationships() != null) {
        final Set<Relationship> relationships = new HashSet<>();
        for (final String rel : config.getAutoTerminatedRelationships()) {
            relationships.add(procNode.getRelationship(rel));
        }
        procNode.setAutoTerminatedRelationships(relationships);
    }

    procNode.setProperties(config.getProperties());

    final ScheduledState scheduledState = ScheduledState.valueOf(processorDTO.getState());
    if (ScheduledState.RUNNING.equals(scheduledState)) {
        controller.startProcessor(processGroup.getIdentifier(), procNode.getIdentifier());
    } else if (ScheduledState.DISABLED.equals(scheduledState)) {
        processGroup.disableProcessor(procNode);
    }
}
 
Example 16
Source File: ProcessorAuditor.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts the values for the configured properties from the specified Processor.
 */
private Map<String, String> extractConfiguredPropertyValues(ProcessorNode processor, ProcessorDTO processorDTO) {
    Map<String, String> values = new HashMap<>();

    if (processorDTO.getName() != null) {
        values.put(NAME, processor.getName());
    }
    if (processorDTO.getConfig() != null) {
        ProcessorConfigDTO newConfig = processorDTO.getConfig();
        if (newConfig.getConcurrentlySchedulableTaskCount() != null) {
            values.put(CONCURRENTLY_SCHEDULABLE_TASKS, String.valueOf(processor.getMaxConcurrentTasks()));
        }
        if (newConfig.getPenaltyDuration() != null) {
            values.put(PENALTY_DURATION, processor.getPenalizationPeriod());
        }
        if (newConfig.getYieldDuration() != null) {
            values.put(YIELD_DURATION, processor.getYieldPeriod());
        }
        if (newConfig.getBulletinLevel() != null) {
            values.put(BULLETIN_LEVEL, processor.getBulletinLevel().name());
        }
        if (newConfig.getAnnotationData() != null) {
            values.put(ANNOTATION_DATA, processor.getAnnotationData());
        }
        if (newConfig.getSchedulingPeriod() != null) {
            values.put(SCHEDULING_PERIOD, String.valueOf(processor.getSchedulingPeriod()));
        }
        if (newConfig.getAutoTerminatedRelationships() != null) {
            // get each of the auto terminated relationship names
            final Set<Relationship> autoTerminatedRelationships = processor.getAutoTerminatedRelationships();
            final List<String> autoTerminatedRelationshipNames = new ArrayList<>(autoTerminatedRelationships.size());
            for (final Relationship relationship : autoTerminatedRelationships) {
                autoTerminatedRelationshipNames.add(relationship.getName());
            }

            // sort them and include in the configuration
            Collections.sort(autoTerminatedRelationshipNames, Collator.getInstance(Locale.US));
            values.put(AUTO_TERMINATED_RELATIONSHIPS, StringUtils.join(autoTerminatedRelationshipNames, ", "));
        }
        if (newConfig.getProperties() != null) {
            // for each property specified, extract its configured value
            Map<String, String> properties = newConfig.getProperties();
            Map<PropertyDescriptor, String> configuredProperties = processor.getProperties();
            for (String propertyName : properties.keySet()) {
                // build a descriptor for getting the configured value
                PropertyDescriptor propertyDescriptor = new PropertyDescriptor.Builder().name(propertyName).build();
                String configuredPropertyValue = configuredProperties.get(propertyDescriptor);

                // if the configured value couldn't be found, use the default value from the actual descriptor
                if (configuredPropertyValue == null) {
                    propertyDescriptor = locatePropertyDescriptor(configuredProperties.keySet(), propertyDescriptor);
                    configuredPropertyValue = propertyDescriptor.getDefaultValue();
                }
                values.put(propertyName, configuredPropertyValue);
            }
        }
        if (newConfig.getComments() != null) {
            values.put(COMMENTS, processor.getComments());
        }
        if (newConfig.getSchedulingStrategy() != null) {
            values.put(SCHEDULING_STRATEGY, processor.getSchedulingStrategy().name());
        }
        if (newConfig.getExecutionNode() != null) {
            values.put(EXECUTION_NODE, processor.getExecutionNode().name());
        }
    }

    return values;
}
 
Example 17
Source File: StandardProcessorDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private void verifyUpdate(ProcessorNode processor, ProcessorDTO processorDTO) {
    // ensure the state, if specified, is valid
    if (isNotNull(processorDTO.getState())) {
        try {
            final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());

            // only attempt an action if it is changing
            if (!purposedScheduledState.equals(processor.getScheduledState())) {
                // perform the appropriate action
                switch (purposedScheduledState) {
                    case RUNNING:
                        processor.verifyCanStart();
                        break;
                    case STOPPED:
                        switch (processor.getScheduledState()) {
                            case RUNNING:
                                processor.verifyCanStop();
                                break;
                            case DISABLED:
                                processor.verifyCanEnable();
                                break;
                        }
                        break;
                    case DISABLED:
                        processor.verifyCanDisable();
                        break;
                }
            }
        } catch (IllegalArgumentException iae) {
            throw new IllegalArgumentException(String.format(
                    "The specified processor state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.",
                    processorDTO.getState()));
        }
    }

    boolean modificationRequest = false;
    if (isAnyNotNull(processorDTO.getName())) {
        modificationRequest = true;
    }

    final ProcessorConfigDTO configDTO = processorDTO.getConfig();
    if (configDTO != null) {
        if (isAnyNotNull(configDTO.getAnnotationData(),
                configDTO.getAutoTerminatedRelationships(),
                configDTO.getBulletinLevel(),
                configDTO.getComments(),
                configDTO.getConcurrentlySchedulableTaskCount(),
                configDTO.getPenaltyDuration(),
                configDTO.getProperties(),
                configDTO.getSchedulingPeriod(),
                configDTO.getSchedulingStrategy(),
                configDTO.getExecutionNode(),
                configDTO.getYieldDuration())) {

            modificationRequest = true;
        }

        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(processor, configDTO);

        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }
    }

    if (modificationRequest) {
        processor.verifyCanUpdate();
    }
}