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());
}
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;
}
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());
}
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());
}
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;
}
Aggregations