use of org.apache.nifi.web.api.dto.FlowSnippetDTO 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);
}
use of org.apache.nifi.web.api.dto.FlowSnippetDTO 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.FlowSnippetDTO in project nifi by apache.
the class TestFlowController method testInstantiateSnippetWhenControllerServiceMissingBundle.
@Test(expected = IllegalArgumentException.class)
public void testInstantiateSnippetWhenControllerServiceMissingBundle() 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());
// missing bundle
csDto.setBundle(null);
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);
}
use of org.apache.nifi.web.api.dto.FlowSnippetDTO in project nifi by apache.
the class FlowFromDOMFactory method getProcessGroup.
public static ProcessGroupDTO getProcessGroup(final String parentId, final Element element, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) {
final ProcessGroupDTO dto = new ProcessGroupDTO();
final String groupId = getString(element, "id");
dto.setId(groupId);
dto.setVersionedComponentId(getString(element, "versionedComponentId"));
dto.setParentGroupId(parentId);
dto.setName(getString(element, "name"));
dto.setPosition(getPosition(DomUtils.getChild(element, "position")));
dto.setComments(getString(element, "comment"));
final Map<String, String> variables = new HashMap<>();
final NodeList variableList = DomUtils.getChildNodesByTagName(element, "variable");
for (int i = 0; i < variableList.getLength(); i++) {
final Element variableElement = (Element) variableList.item(i);
final String name = variableElement.getAttribute("name");
final String value = variableElement.getAttribute("value");
variables.put(name, value);
}
dto.setVariables(variables);
final Element versionControlInfoElement = DomUtils.getChild(element, "versionControlInformation");
dto.setVersionControlInformation(getVersionControlInformation(versionControlInfoElement));
final Set<ProcessorDTO> processors = new HashSet<>();
final Set<ConnectionDTO> connections = new HashSet<>();
final Set<FunnelDTO> funnels = new HashSet<>();
final Set<PortDTO> inputPorts = new HashSet<>();
final Set<PortDTO> outputPorts = new HashSet<>();
final Set<LabelDTO> labels = new HashSet<>();
final Set<ProcessGroupDTO> processGroups = new HashSet<>();
final Set<RemoteProcessGroupDTO> remoteProcessGroups = new HashSet<>();
NodeList nodeList = DomUtils.getChildNodesByTagName(element, "processor");
for (int i = 0; i < nodeList.getLength(); i++) {
processors.add(getProcessor((Element) nodeList.item(i), encryptor));
}
nodeList = DomUtils.getChildNodesByTagName(element, "funnel");
for (int i = 0; i < nodeList.getLength(); i++) {
funnels.add(getFunnel((Element) nodeList.item(i)));
}
nodeList = DomUtils.getChildNodesByTagName(element, "inputPort");
for (int i = 0; i < nodeList.getLength(); i++) {
inputPorts.add(getPort((Element) nodeList.item(i)));
}
nodeList = DomUtils.getChildNodesByTagName(element, "outputPort");
for (int i = 0; i < nodeList.getLength(); i++) {
outputPorts.add(getPort((Element) nodeList.item(i)));
}
nodeList = DomUtils.getChildNodesByTagName(element, "label");
for (int i = 0; i < nodeList.getLength(); i++) {
labels.add(getLabel((Element) nodeList.item(i)));
}
nodeList = DomUtils.getChildNodesByTagName(element, "processGroup");
for (int i = 0; i < nodeList.getLength(); i++) {
processGroups.add(getProcessGroup(groupId, (Element) nodeList.item(i), encryptor, encodingVersion));
}
nodeList = DomUtils.getChildNodesByTagName(element, "remoteProcessGroup");
for (int i = 0; i < nodeList.getLength(); i++) {
remoteProcessGroups.add(getRemoteProcessGroup((Element) nodeList.item(i), encryptor));
}
nodeList = DomUtils.getChildNodesByTagName(element, "connection");
for (int i = 0; i < nodeList.getLength(); i++) {
connections.add(getConnection((Element) nodeList.item(i)));
}
final FlowSnippetDTO groupContents = new FlowSnippetDTO();
groupContents.setConnections(connections);
groupContents.setFunnels(funnels);
groupContents.setInputPorts(inputPorts);
groupContents.setLabels(labels);
groupContents.setOutputPorts(outputPorts);
groupContents.setProcessGroups(processGroups);
groupContents.setProcessors(processors);
groupContents.setRemoteProcessGroups(remoteProcessGroups);
dto.setContents(groupContents);
return dto;
}
use of org.apache.nifi.web.api.dto.FlowSnippetDTO in project nifi by apache.
the class SnippetAuditor method instantiateTemplateAdvice.
/**
* Audits the instantiation of a template.
*
* @param proceedingJoinPoint join point
* @return dto
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.TemplateDAO+) && " + "execution(org.apache.nifi.web.api.dto.FlowSnippetDTO instantiateTemplate(" + "java.lang.String, java.lang.Double, java.lang.Double, java.lang.String, org.apache.nifi.web.api.dto.FlowSnippetDTO, java.lang.String))")
public FlowSnippetDTO instantiateTemplateAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
// perform the underlying operation
FlowSnippetDTO snippet = (FlowSnippetDTO) proceedingJoinPoint.proceed();
auditSnippet(snippet);
return snippet;
}
Aggregations