org.apache.nifi.web.api.dto.ProcessorConfigDTO Java Examples

The following examples show how to use org.apache.nifi.web.api.dto.ProcessorConfigDTO. 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: SnippetUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void updateControllerServiceIdentifiers(final ProcessorConfigDTO configDto, final Map<String, String> serviceIdMap) {
    if (configDto == null) {
        return;
    }

    final Map<String, String> properties = configDto.getProperties();
    final Map<String, PropertyDescriptorDTO> descriptors = configDto.getDescriptors();
    if (properties != null && descriptors != null) {
        for (final PropertyDescriptorDTO descriptor : descriptors.values()) {
            if (descriptor.getIdentifiesControllerService() != null) {
                final String currentServiceId = properties.get(descriptor.getName());
                if (currentServiceId == null) {
                    continue;
                }

                // if this is a copy/paste action, we can continue to reference the same service, in this case
                // the serviceIdMap will be empty
                if (serviceIdMap.containsKey(currentServiceId)) {
                    final String newServiceId = serviceIdMap.get(currentServiceId);
                    properties.put(descriptor.getName(), newServiceId);
                }
            }
        }
    }
}
 
Example #5
Source File: ParameterContextIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 30000)
public void testAddingMissingParameterMakesProcessorValid() throws NiFiClientException, IOException, InterruptedException {
    final ProcessorEntity createdProcessorEntity = createProcessor(TEST_PROCESSORS_PACKAGE + ".CountEvents", NIFI_GROUP_ID, TEST_EXTENSIONS_ARTIFACT_ID, getNiFiVersion());
    final String processorId = createdProcessorEntity.getId();

    final ProcessorConfigDTO config = createdProcessorEntity.getComponent().getConfig();
    config.setProperties(Collections.singletonMap("Name", "#{foo}"));
    getNifiClient().getProcessorClient().updateProcessor(createdProcessorEntity);

    waitForInvalidProcessor(processorId);

    final Set<ParameterEntity> parameters = new HashSet<>();
    parameters.add(createParameterEntity("foo", null, false, "bar"));
    final ParameterContextEntity contextEntity = createParameterContextEntity(getTestName(), null, parameters);
    final ParameterContextEntity createdContextEntity = getNifiClient().getParamContextClient().createParamContext(contextEntity);

    setParameterContext("root", createdContextEntity);
    waitForValidProcessor(processorId);
}
 
Example #6
Source File: TestJsonEntitySerializer.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializeProcessor() throws IOException {
    final ObjectMapper jsonCodec = new ObjectMapper();
    jsonCodec.registerModule(new JaxbAnnotationModule());
    jsonCodec.setSerializationInclusion(Include.NON_NULL);

    // Test that we can properly serialize a ProcessorEntity because it has many nested levels, including a Map
    final JsonEntitySerializer serializer = new JsonEntitySerializer(jsonCodec);
    try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {

        final ProcessorConfigDTO configDto = new ProcessorConfigDTO();
        configDto.setProperties(Collections.singletonMap("key", "value"));
        final ProcessorDTO processorDto = new ProcessorDTO();
        processorDto.setConfig(configDto);

        final ProcessorEntity processor = new ProcessorEntity();
        processor.setId("123");
        processor.setComponent(processorDto);

        serializer.serialize(processor, baos);

        final String serialized = new String(baos.toByteArray(), StandardCharsets.UTF_8);
        assertEquals("{\"id\":\"123\",\"component\":{\"config\":{\"properties\":{\"key\":\"value\"}}}}", serialized);
    }
}
 
Example #7
Source File: SnippetUtils.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void updateControllerServiceIdentifiers(final ProcessorConfigDTO configDto, final Map<String, String> serviceIdMap) {
    if (configDto == null) {
        return;
    }

    final Map<String, String> properties = configDto.getProperties();
    final Map<String, PropertyDescriptorDTO> descriptors = configDto.getDescriptors();
    if (properties != null && descriptors != null) {
        for (final PropertyDescriptorDTO descriptor : descriptors.values()) {
            if (descriptor.getIdentifiesControllerService() != null) {
                final String currentServiceId = properties.get(descriptor.getName());
                if (currentServiceId == null) {
                    continue;
                }

                // if this is a copy/paste action, we can continue to reference the same service, in this case
                // the serviceIdMap will be empty
                if (serviceIdMap.containsKey(currentServiceId)) {
                    final String newServiceId = serviceIdMap.get(currentServiceId);
                    properties.put(descriptor.getName(), newServiceId);
                }
            }
        }
    }
}
 
Example #8
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 #9
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 #10
Source File: StandardNiFiWebConfigurationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
private Map<String,ComponentDescriptor> buildComponentDescriptorMap(final ProcessorConfigDTO processorConfig){

            final Map<String, ComponentDescriptor> descriptors = new HashMap<>();

            for(String key : processorConfig.getDescriptors().keySet()){

                PropertyDescriptorDTO descriptor = processorConfig.getDescriptors().get(key);
                List<AllowableValueEntity> allowableValuesEntity = descriptor.getAllowableValues();
                Map<String,String> allowableValues = new HashMap<>();

                if(allowableValuesEntity != null) {
                    for (AllowableValueEntity allowableValueEntity : allowableValuesEntity) {
                        final AllowableValueDTO allowableValueDTO = allowableValueEntity.getAllowableValue();
                        allowableValues.put(allowableValueDTO.getValue(), allowableValueDTO.getDisplayName());
                    }
                }

                ComponentDescriptor componentDescriptor = new ComponentDescriptor.Builder()
                        .name(descriptor.getName())
                        .displayName(descriptor.getDisplayName())
                        .defaultValue(descriptor.getDefaultValue())
                        .allowableValues(allowableValues)
                        .build();


                descriptors.put(key,componentDescriptor);
            }

            return descriptors;
        }
 
Example #11
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 #12
Source File: StandardNiFiWebConfigurationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
private ProcessorDTO buildProcessorDto(String id, final String annotationData, Map<String, String> properties){
    ProcessorDTO processorDto = new ProcessorDTO();
    processorDto.setId(id);
    ProcessorConfigDTO configDto = new ProcessorConfigDTO();
    processorDto.setConfig(configDto);
    configDto.setAnnotationData(annotationData);
    configDto.setProperties(properties);
    return  processorDto;

}
 
Example #13
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 #14
Source File: StandardNiFiWebConfigurationContext.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private Map<String,ComponentDescriptor> buildComponentDescriptorMap(final ProcessorConfigDTO processorConfig){

            final Map<String, ComponentDescriptor> descriptors = new HashMap<>();

            for(String key : processorConfig.getDescriptors().keySet()){

                PropertyDescriptorDTO descriptor = processorConfig.getDescriptors().get(key);
                List<AllowableValueEntity> allowableValuesEntity = descriptor.getAllowableValues();
                Map<String,String> allowableValues = new HashMap<>();

                if(allowableValuesEntity != null) {
                    for (AllowableValueEntity allowableValueEntity : allowableValuesEntity) {
                        final AllowableValueDTO allowableValueDTO = allowableValueEntity.getAllowableValue();
                        allowableValues.put(allowableValueDTO.getValue(), allowableValueDTO.getDisplayName());
                    }
                }

                ComponentDescriptor componentDescriptor = new ComponentDescriptor.Builder()
                        .name(descriptor.getName())
                        .displayName(descriptor.getDisplayName())
                        .defaultValue(descriptor.getDefaultValue())
                        .allowableValues(allowableValues)
                        .build();


                descriptors.put(key,componentDescriptor);
            }

            return descriptors;
        }
 
Example #15
Source File: StandardNiFiWebConfigurationContext.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private ProcessorDTO buildProcessorDto(String id, final String annotationData, Map<String, String> properties){
    ProcessorDTO processorDto = new ProcessorDTO();
    processorDto.setId(id);
    ProcessorConfigDTO configDto = new ProcessorConfigDTO();
    processorDto.setConfig(configDto);
    configDto.setAnnotationData(annotationData);
    configDto.setProperties(properties);
    return  processorDto;

}
 
Example #16
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 #17
Source File: ProcessorSchemaTest.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    config = new ProcessorConfigDTO();

    RelationshipDTO relationshipDTO = new RelationshipDTO();
    relationshipDTO.setName(testRelationship);
    relationshipDTO.setAutoTerminate(true);

    dto = new ProcessorDTO();
    dto.setConfig(config);
    dto.setName(testName);
    dto.setId(testId);
    dto.setType(testProcessorClass);
    config.setSchedulingStrategy(testSchedulingStrategy);
    config.setSchedulingPeriod(testSchedulingPeriod);
    config.setConcurrentlySchedulableTaskCount(testMaxConcurrentTasks);
    config.setPenaltyDuration(testPenalizationPeriod);
    config.setYieldDuration(testYieldDuration);
    config.setRunDurationMillis(testRunDurationNanos / 1000);
    config.setAnnotationData(testAnnotationData);
    dto.setRelationships(Arrays.asList(relationshipDTO));
    Map<String, String> properties = new HashMap<>();
    properties.put(testKey, testValue);
    config.setProperties(properties);

    map = new HashMap<>();
    map.put(CommonPropertyKeys.NAME_KEY, testName);
    map.put(CommonPropertyKeys.ID_KEY, testId);
    map.put(CLASS_KEY, testProcessorClass);
    map.put(CommonPropertyKeys.SCHEDULING_STRATEGY_KEY, testSchedulingStrategy);
    map.put(CommonPropertyKeys.SCHEDULING_PERIOD_KEY, testSchedulingPeriod);
    map.put(CommonPropertyKeys.MAX_CONCURRENT_TASKS_KEY, testMaxConcurrentTasks);
    map.put(ProcessorSchema.PENALIZATION_PERIOD_KEY, testPenalizationPeriod);
    map.put(CommonPropertyKeys.YIELD_PERIOD_KEY, testYieldDuration);
    map.put(ProcessorSchema.RUN_DURATION_NANOS_KEY, testRunDurationNanos);
    map.put(ProcessorSchema.AUTO_TERMINATED_RELATIONSHIPS_LIST_KEY, Arrays.asList(testRelationship));
    map.put(PROPERTIES_KEY, new HashMap<>(properties));
    map.put(ANNOTATION_DATA_KEY, testAnnotationData);
}
 
Example #18
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 #19
Source File: StandardFlowServiceTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void assertEquals(ProcessorConfigDTO expected, ProcessorConfigDTO actual) {
    if (expected == null && actual == null) {
        return;
    }

    Assert.assertEquals(expected.getAnnotationData(), actual.getAnnotationData());
    Assert.assertEquals(expected.getComments(), actual.getComments());
    Assert.assertEquals(expected.getConcurrentlySchedulableTaskCount(), actual.getConcurrentlySchedulableTaskCount());
    Assert.assertEquals(expected.getCustomUiUrl(), actual.getCustomUiUrl());
    Assert.assertEquals(expected.getDescriptors(), actual.getDescriptors());
    Assert.assertEquals(expected.getProperties(), actual.getProperties());
    Assert.assertEquals(expected.getSchedulingPeriod(), actual.getSchedulingPeriod());
}
 
Example #20
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
public ProcessorEntity updateProcessorConfig(final ProcessorEntity currentEntity, final ProcessorConfigDTO config) throws NiFiClientException, IOException {
    final ProcessorDTO processorDto = new ProcessorDTO();
    processorDto.setConfig(config);
    processorDto.setId(currentEntity.getId());

    final ProcessorEntity updatedEntity = new ProcessorEntity();
    updatedEntity.setRevision(currentEntity.getRevision());
    updatedEntity.setComponent(processorDto);
    updatedEntity.setId(currentEntity.getId());

    return nifiClient.getProcessorClient().updateProcessor(updatedEntity);
}
 
Example #21
Source File: StandardFlowServiceTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void assertEquals(ProcessorConfigDTO expected, ProcessorConfigDTO actual) {
    if (expected == null && actual == null) {
        return;
    }

    Assert.assertEquals(expected.getAnnotationData(), actual.getAnnotationData());
    Assert.assertEquals(expected.getComments(), actual.getComments());
    Assert.assertEquals(expected.getConcurrentlySchedulableTaskCount(), actual.getConcurrentlySchedulableTaskCount());
    Assert.assertEquals(expected.getCustomUiUrl(), actual.getCustomUiUrl());
    Assert.assertEquals(expected.getDescriptors(), actual.getDescriptors());
    Assert.assertEquals(expected.getProperties(), actual.getProperties());
    Assert.assertEquals(expected.getSchedulingPeriod(), actual.getSchedulingPeriod());
}
 
Example #22
Source File: TestFlowController.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testInstantiateSnippetWithDisabledProcessor() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ProcessorNode processorNode = controller.getFlowManager().createProcessor(DummyProcessor.class.getName(), id, coordinate);
    processorNode.disable();

    // create a processor dto
    final ProcessorDTO processorDTO = new ProcessorDTO();
    processorDTO.setId(UUID.randomUUID().toString()); // use a different id here
    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.setExecutionNodeRestricted(processorNode.isExecutionNodeRestricted());
    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.getFlowManager().getRootGroup().getProcessors().size());
    controller.getFlowManager().instantiateSnippet(controller.getFlowManager().getRootGroup(), flowSnippetDTO);
    assertEquals(1, controller.getFlowManager().getRootGroup().getProcessors().size());
    assertTrue(controller.getFlowManager().getRootGroup().getProcessors().iterator().next().getScheduledState().equals(ScheduledState.DISABLED));
}
 
Example #23
Source File: TestFlowController.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testInstantiateSnippetWhenProcessorMissingBundle() throws Exception {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ProcessorNode processorNode = controller.getFlowManager().createProcessor(DummyProcessor.class.getName(), id, coordinate);

    // create a processor dto
    final ProcessorDTO processorDTO = new ProcessorDTO();
    processorDTO.setId(UUID.randomUUID().toString()); // use a different id here
    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.setExecutionNodeRestricted(processorNode.isExecutionNodeRestricted());
    processorDTO.setExtensionMissing(processorNode.isExtensionMissing());

    processorDTO.setType(processorNode.getCanonicalClassName());
    processorDTO.setBundle(null); // missing bundle
    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.getFlowManager().getRootGroup().getProcessors().size());
    controller.getFlowManager().instantiateSnippet(controller.getFlowManager().getRootGroup(), flowSnippetDTO);
}
 
Example #24
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);
}
 
Example #25
Source File: TestFlowController.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testInstantiateSnippetWithProcessor() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ProcessorNode processorNode = controller.getFlowManager().createProcessor(DummyProcessor.class.getName(), id, coordinate);

    // create a processor dto
    final ProcessorDTO processorDTO = new ProcessorDTO();
    processorDTO.setId(UUID.randomUUID().toString()); // use a different id here
    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.setExecutionNodeRestricted(processorNode.isExecutionNodeRestricted());
    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.getFlowManager().getRootGroup().getProcessors().size());
    controller.getFlowManager().instantiateSnippet(controller.getFlowManager().getRootGroup(), flowSnippetDTO);
    assertEquals(1, controller.getFlowManager().getRootGroup().getProcessors().size());
}
 
Example #26
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 #27
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 4 votes vote down vote up
public ProcessorEntity updateProcessorExecutionNode(final ProcessorEntity currentEntity, final ExecutionNode executionNode) throws NiFiClientException, IOException {
    final ProcessorConfigDTO config = new ProcessorConfigDTO();
    config.setExecutionNode(executionNode.name());
    return updateProcessorConfig(currentEntity, config);
}
 
Example #28
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 4 votes vote down vote up
public ProcessorEntity updateProcessorProperties(final ProcessorEntity currentEntity, final Map<String, String> properties) throws NiFiClientException, IOException {
    final ProcessorConfigDTO config = new ProcessorConfigDTO();
    config.setProperties(properties);
    return updateProcessorConfig(currentEntity, config);
}
 
Example #29
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 4 votes vote down vote up
public ProcessorEntity updateProcessorSchedulingPeriod(final ProcessorEntity currentEntity, final String schedulingPeriod) throws NiFiClientException, IOException {
    final ProcessorConfigDTO config = new ProcessorConfigDTO();
    config.setSchedulingPeriod(schedulingPeriod);
    return updateProcessorConfig(currentEntity, config);
}
 
Example #30
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);
    }
}