Search in sources :

Example 21 with ProcessorConfigDTO

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

the class TestFlowController method testInstantiateSnippetWhenProcessorMissingBundle.

@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.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());
    // missing bundle
    processorDTO.setBundle(null);
    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);
}
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) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Test(org.junit.Test)

Example 22 with ProcessorConfigDTO

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

the class ProcessorAuditor method extractConfiguredPropertyValues.

/**
 * 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.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;
}
Also used : ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) Relationship(org.apache.nifi.processor.Relationship) ArrayList(java.util.ArrayList) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate)

Example 23 with ProcessorConfigDTO

use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project nifi-minifi by apache.

the class ProcessorSchemaFunction method apply.

@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);
}
Also used : ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) HashMap(java.util.HashMap) RelationshipDTO(org.apache.nifi.web.api.dto.RelationshipDTO) ProcessorSchema(org.apache.nifi.minifi.commons.schema.ProcessorSchema)

Aggregations

ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)23 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)15 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)6 PositionDTO (org.apache.nifi.web.api.dto.PositionDTO)6 HashSet (java.util.HashSet)5 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)4 LegacyNifiRestClient (com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient)3 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)3 Stateful (org.apache.nifi.annotation.behavior.Stateful)3 Relationship (org.apache.nifi.processor.Relationship)3 BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)3 RelationshipDTO (org.apache.nifi.web.api.dto.RelationshipDTO)3 NiFiRestClient (com.thinkbiganalytics.nifi.rest.client.NiFiRestClient)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2