Search in sources :

Example 11 with BundleDTO

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

the class FlowFromDOMFactory method getBundle.

public static BundleDTO getBundle(final Element bundleElement) {
    if (bundleElement == null) {
        return null;
    }
    final Element groupElement = DomUtils.getChild(bundleElement, "group");
    final Element artifactElement = DomUtils.getChild(bundleElement, "artifact");
    final Element versionElement = DomUtils.getChild(bundleElement, "version");
    return new BundleDTO(groupElement.getTextContent(), artifactElement.getTextContent(), versionElement.getTextContent());
}
Also used : Element(org.w3c.dom.Element) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO)

Example 12 with BundleDTO

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

the class FingerprintFactory method addFlowFileProcessorFingerprint.

private StringBuilder addFlowFileProcessorFingerprint(final StringBuilder builder, final Element processorElem) throws FingerprintException {
    // id
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "id"));
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "versionedComponentId"));
    // class
    final NodeList childNodes = DomUtils.getChildNodesByTagName(processorElem, "class");
    final String className = childNodes.item(0).getTextContent();
    appendFirstValue(builder, childNodes);
    // annotation data
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "annotationData"));
    // get the bundle details if possible
    final BundleDTO bundle = FlowFromDOMFactory.getBundle(DomUtils.getChild(processorElem, "bundle"));
    addBundleFingerprint(builder, bundle);
    // max concurrent tasks
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "maxConcurrentTasks"));
    // scheduling period
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "schedulingPeriod"));
    // penalization period
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "penalizationPeriod"));
    // yield period
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "yieldPeriod"));
    // bulletin level
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "bulletinLevel"));
    // loss tolerant
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "lossTolerant"));
    // scheduling strategy
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "schedulingStrategy"));
    // execution node
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "executionNode"));
    // run duration nanos
    appendFirstValue(builder, DomUtils.getChildNodesByTagName(processorElem, "runDurationNanos"));
    // get the temp instance of the Processor so that we know the default property values
    final BundleCoordinate coordinate = getCoordinate(className, bundle);
    final ConfigurableComponent configurableComponent = ExtensionManager.getTempComponent(className, coordinate);
    if (configurableComponent == null) {
        logger.warn("Unable to get Processor of type {}; its default properties will be fingerprinted instead of being ignored.", className);
    }
    // properties
    final NodeList propertyElems = DomUtils.getChildNodesByTagName(processorElem, "property");
    final List<Element> sortedPropertyElems = sortElements(propertyElems, getProcessorPropertiesComparator());
    for (final Element propertyElem : sortedPropertyElems) {
        final String propName = DomUtils.getChildElementsByTagName(propertyElem, "name").get(0).getTextContent();
        String propValue = getFirstValue(DomUtils.getChildNodesByTagName(propertyElem, "value"), null);
        addPropertyFingerprint(builder, configurableComponent, propName, propValue);
    }
    final NodeList autoTerminateElems = DomUtils.getChildNodesByTagName(processorElem, "autoTerminatedRelationship");
    final List<Element> sortedAutoTerminateElems = sortElements(autoTerminateElems, getElementTextComparator());
    for (final Element autoTerminateElem : sortedAutoTerminateElems) {
        builder.append(autoTerminateElem.getTextContent());
    }
    return builder;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate)

Example 13 with BundleDTO

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

the class TestFlowController method testInstantiateSnippetWithProcessor.

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

Example 14 with BundleDTO

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

the class TestFlowController method testInstantiateSnippetWithControllerService.

@Test
public void testInstantiateSnippetWithControllerService() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ControllerServiceNode controllerServiceNode = controller.createControllerService(ServiceA.class.getName(), id, coordinate, null, true);
    // create the controller service dto
    final ControllerServiceDTO csDto = new ControllerServiceDTO();
    // use a different id
    csDto.setId(UUID.randomUUID().toString());
    csDto.setParentGroupId(controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier());
    csDto.setName(controllerServiceNode.getName());
    csDto.setType(controllerServiceNode.getCanonicalClassName());
    csDto.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion()));
    csDto.setState(controllerServiceNode.getState().name());
    csDto.setAnnotationData(controllerServiceNode.getAnnotationData());
    csDto.setComments(controllerServiceNode.getComments());
    csDto.setPersistsState(controllerServiceNode.getControllerServiceImplementation().getClass().isAnnotationPresent(Stateful.class));
    csDto.setRestricted(controllerServiceNode.isRestricted());
    csDto.setExtensionMissing(controllerServiceNode.isExtensionMissing());
    csDto.setDescriptors(new LinkedHashMap<>());
    csDto.setProperties(new LinkedHashMap<>());
    // create the snippet with the controller service
    final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO();
    flowSnippetDTO.setControllerServices(Collections.singleton(csDto));
    // instantiate the snippet
    assertEquals(0, controller.getRootGroup().getControllerServices(false).size());
    controller.instantiateSnippet(controller.getRootGroup(), flowSnippetDTO);
    assertEquals(1, controller.getRootGroup().getControllerServices(false).size());
}
Also used : Stateful(org.apache.nifi.annotation.behavior.Stateful) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Test(org.junit.Test)

Example 15 with BundleDTO

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

the class BundleUtils method createBundleDto.

public static BundleDTO createBundleDto(final org.apache.nifi.registry.flow.Bundle bundle) {
    final BundleDTO dto = new BundleDTO();
    dto.setArtifact(bundle.getArtifact());
    dto.setGroup(bundle.getGroup());
    dto.setVersion(bundle.getVersion());
    return dto;
}
Also used : BundleDTO(org.apache.nifi.web.api.dto.BundleDTO)

Aggregations

BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)21 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)16 ConfigurableComponent (org.apache.nifi.components.ConfigurableComponent)4 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)4 URL (java.net.URL)3 Stateful (org.apache.nifi.annotation.behavior.Stateful)3 ValidationException (org.apache.nifi.controller.exception.ValidationException)3 ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)3 UiExtension (org.apache.nifi.ui.extension.UiExtension)3 UiExtensionMapping (org.apache.nifi.ui.extension.UiExtensionMapping)3 NiFiCoreException (org.apache.nifi.web.NiFiCoreException)3 PositionDTO (org.apache.nifi.web.api.dto.PositionDTO)3 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)3 Element (org.w3c.dom.Element)3 ScheduledState (org.apache.nifi.controller.ScheduledState)2 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)2 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)2 DummyProcessor (org.apache.nifi.controller.service.mock.DummyProcessor)2 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)2 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)2