private static boolean isEmpty(final ProcessGroupDTO dto) { if (dto == null) { return true; } final FlowSnippetDTO contents = dto.getContents(); if (contents == null) { return true; } return CollectionUtils.isEmpty(contents.getProcessors()) && CollectionUtils.isEmpty(contents.getConnections()) && CollectionUtils.isEmpty(contents.getFunnels()) && CollectionUtils.isEmpty(contents.getLabels()) && CollectionUtils.isEmpty(contents.getOutputPorts()) && CollectionUtils.isEmpty(contents.getProcessGroups()) && CollectionUtils.isEmpty(contents.getProcessors()) && CollectionUtils.isEmpty(contents.getRemoteProcessGroups()); }
final FlowSnippetDTO copy = new FlowSnippetDTO(); for (final ProcessGroupDTO group : original.getProcessGroups()) { groups.add(copy(group, deep)); for (final PortDTO port : original.getInputPorts()) { inputPorts.add(copy(port)); for (final PortDTO port : original.getOutputPorts()) { outputPorts.add(copy(port)); for (final LabelDTO label : original.getLabels()) { labels.add(copy(label)); for (final ProcessorDTO processor : original.getProcessors()) { processors.add(copy(processor)); for (final RemoteProcessGroupDTO remoteGroup : original.getRemoteProcessGroups()) { remoteProcessGroups.add(copy(remoteGroup)); for (final FunnelDTO funnel : original.getFunnels()) { funnels.add(copy(funnel)); for (final ConnectionDTO connection : original.getConnections()) { connections.add(copy(connection)); for (final ControllerServiceDTO controllerService : original.getControllerServices()) { controllerServices.add(copy(controllerService));
private void lookupSensitiveProperties(final FlowSnippetDTO snippet) { // ensure that contents have been specified if (snippet != null) { // go through each processor if specified if (snippet.getProcessors() != null) { lookupSensitiveProcessorProperties(snippet.getProcessors()); } if (snippet.getControllerServices() != null) { lookupSensitiveControllerServiceProperties(snippet.getControllerServices()); } // go through each process group if specified if (snippet.getProcessGroups() != null) { for (final ProcessGroupDTO group : snippet.getProcessGroups()) { lookupSensitiveProperties(group.getContents()); } } } }
private static void scrubSnippet(final FlowSnippetDTO snippet) { // ensure that contents have been specified if (snippet != null) { // go through each processor if specified if (snippet.getProcessors() != null) { scrubProcessors(snippet.getProcessors()); } // go through each connection if specified if (snippet.getConnections() != null) { scrubConnections(snippet.getConnections()); } // go through each remote process group if specified if (snippet.getRemoteProcessGroups() != null) { scrubRemoteProcessGroups(snippet.getRemoteProcessGroups()); } // go through each process group if specified if (snippet.getProcessGroups() != null) { scrubProcessGroups(snippet.getProcessGroups()); } // go through each controller service if specified if (snippet.getControllerServices() != null) { scrubControllerServices(snippet.getControllerServices()); } } }
private void removeInstanceIdentifierIfNecessary(Set<? extends ComponentDTO> componentDtos) { if (this.newTemplate) { for (ComponentDTO componentDto : componentDtos) { UUID id = new UUID(this.generateMsb(componentDto.getId()), LSB); componentDto.setId(id.toString()); id = new UUID(this.generateMsb(componentDto.getParentGroupId()), LSB); componentDto.setParentGroupId(id.toString()); if (componentDto instanceof ControllerServiceDTO) { String key = entry.getKey(); String value = props.get(key); id = new UUID(this.generateMsb(value), LSB); props.put(key, id.toString()); String key = entry.getKey(); String value = props.get(key); id = new UUID(this.generateMsb(value), LSB); props.put(key, id.toString()); id = new UUID(this.generateMsb(cdto.getId()), LSB); cdto.setId(id.toString()); id = new UUID(this.generateMsb(cdto.getGroupId()), LSB); cdto.setGroupId(id.toString()); id = new UUID(this.generateMsb(cdto.getId()), LSB); cdto.setId(id.toString()); id = new UUID(this.generateMsb(cdto.getGroupId()), LSB);
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);
private void validateSnippetContents(final FlowSnippetDTO flow) { if (flow.getProcessors() != null) { for (final ProcessorDTO processorDTO : flow.getProcessors()) { final ProcessorNode processorNode = processorDAO.getProcessor(processorDTO.getId()); processorDTO.setValidationStatus(processorNode.getValidationStatus().name()); if (flow.getInputPorts() != null) { for (final PortDTO portDTO : flow.getInputPorts()) { final Port port = inputPortDAO.getPort(portDTO.getId()); final Collection<ValidationResult> validationErrors = port.getValidationErrors(); if (flow.getOutputPorts() != null) { for (final PortDTO portDTO : flow.getOutputPorts()) { final Port port = outputPortDAO.getPort(portDTO.getId()); final Collection<ValidationResult> validationErrors = port.getValidationErrors(); if (flow.getRemoteProcessGroups() != null) { for (final RemoteProcessGroupDTO remoteProcessGroupDTO : flow.getRemoteProcessGroups()) { final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupDTO.getId());
if (snippetContents.getInputPorts() != null) { for (final PortDTO portDTO : snippetContents.getInputPorts()) { String portName = portDTO.getName(); while (existingPortNames.contains(portName)) { if (snippetContents.getOutputPorts() != null) { for (final PortDTO portDTO : snippetContents.getOutputPorts()) { String portName = portDTO.getName(); while (existingPortNames.contains(portName)) { if (snippetContents.getProcessGroups() != null) { for (final ProcessGroupDTO groupDTO : snippetContents.getProcessGroups()) {
private void updateControllerServiceIdentifiers(final FlowSnippetDTO snippet, final Map<String, String> serviceIdMap) { final Set<ProcessorDTO> processors = snippet.getProcessors(); if (processors != null) { for (final ProcessorDTO processor : processors) { updateControllerServiceIdentifiers(processor.getConfig(), serviceIdMap); } } for (final ProcessGroupDTO processGroupDto : snippet.getProcessGroups()) { updateControllerServiceIdentifiers(processGroupDto.getContents(), serviceIdMap); } }
/** * Recursively finds all ConnectionDTO's * * @param group group * @return connection dtos */ private Set<ConnectionDTO> findAllConnections(final ProcessGroupDTO group) { final Set<ConnectionDTO> conns = new HashSet<>(); conns.addAll(group.getContents().getConnections()); for (final ProcessGroupDTO childGroup : group.getContents().getProcessGroups()) { conns.addAll(findAllConnections(childGroup)); } return conns; }
final FlowSnippetDTO snippetDto = contentsByGroup.get(destinationGroupId); if (snippetDto != null) { Set<ControllerServiceDTO> services = snippetDto.getControllerServices(); if (services == null) { snippetDto.setControllerServices(Collections.singleton(svc)); } else { services.add(svc); snippetDto.setControllerServices(services); final Map<String, ProcessGroupDTO> childGroupMap = contents.getProcessGroups().stream() .collect(Collectors.toMap(childGroupDto -> childGroupDto.getId(), childGroupDto -> childGroupDto));
/** * Finds all {@link ProcessGroupDTO}s in the given {@link FlowSnippetDTO}. * @param snippet containing the child {@link ProcessGroupDTO}s to be returned * @return List of child {@link ProcessGroupDTO}s found in the given {@link FlowSnippetDTO}. */ public static List<ProcessGroupDTO> findAllProcessGroups(FlowSnippetDTO snippet) { final List<ProcessGroupDTO> allProcessGroups = new ArrayList<>(snippet.getProcessGroups()); for (final ProcessGroupDTO childGroup : snippet.getProcessGroups()) { allProcessGroups.addAll(findAllProcessGroups(childGroup.getContents())); } return allProcessGroups; }
private void verifyControllerServicesInSnippet(final FlowSnippetDTO templateContents, final Map<String, Set<BundleCoordinate>> supportedTypes) { if (templateContents.getControllerServices() != null) { templateContents.getControllerServices().forEach(controllerService -> { if (supportedTypes.containsKey(controllerService.getType())) { if (controllerService.getBundle() == null) { throw new IllegalArgumentException("Controller Service bundle must be specified."); } verifyBundleInSnippet(controllerService.getBundle(), supportedTypes.get(controllerService.getType())); } else { throw new IllegalStateException("Invalid Controller Service Type: " + controllerService.getType()); } }); } if (templateContents.getProcessGroups() != null) { templateContents.getProcessGroups().forEach(processGroup -> verifyControllerServicesInSnippet(processGroup.getContents(), supportedTypes)); } }
public void validate(final ProcessGroup group) { // validate the names of Input Ports for (final PortDTO port : dto.getInputPorts()) { if (group.getInputPortByName(port.getName()) != null) { throw new IllegalStateException("One or more of the proposed Port names is not available in the process group"); } } // validate the names of Output Ports for (final PortDTO port : dto.getOutputPorts()) { if (group.getOutputPortByName(port.getName()) != null) { throw new IllegalStateException("One or more of the proposed Port names is not available in the process group"); } } verifyComponentTypesInSnippet(); SnippetUtils.verifyNoVersionControlConflicts(dto, group); }
/** * Gets all connections that are part of the specified template. * * @param contents snippet content * @return connection dtos */ private static Collection<ConnectionDTO> getConnections(FlowSnippetDTO contents) { final Collection<ConnectionDTO> connections = new HashSet<>(); if (contents.getConnections() != null) { connections.addAll(contents.getConnections()); } return connections; }
final FlowSnippetDTO snippetDto = new FlowSnippetDTO(removeInstanceId); final String groupId = snippet.getParentGroupId(); final ProcessGroup processGroup = flowController.getFlowManager().getGroup(groupId); normalizeCoordinates(components); Set<ControllerServiceDTO> updatedControllerServices = snippetDto.getControllerServices(); if (updatedControllerServices == null) { updatedControllerServices = new HashSet<>(); snippetDto.setControllerServices(updatedControllerServices); snippetDto.setProcessors(processors); snippetDto.setConnections(connections); snippetDto.setFunnels(funnels); snippetDto.setInputPorts(inputPorts); snippetDto.setLabels(labels); snippetDto.setOutputPorts(outputPorts); snippetDto.setProcessGroups(processGroups); snippetDto.setRemoteProcessGroups(remoteProcessGroups);
/** * Discovers the compatible bundle details for the components in the specified snippet. * * @param snippet the snippet */ private void discoverCompatibleBundles(final FlowSnippetDTO snippet) { if (snippet.getProcessors() != null) { snippet.getProcessors().forEach(processor -> { final BundleCoordinate coordinate = serviceFacade.getCompatibleBundle(processor.getType(), processor.getBundle()); processor.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion())); }); } if (snippet.getControllerServices() != null) { snippet.getControllerServices().forEach(controllerService -> { final BundleCoordinate coordinate = serviceFacade.getCompatibleBundle(controllerService.getType(), controllerService.getBundle()); controllerService.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion())); }); } if (snippet.getProcessGroups() != null) { snippet.getProcessGroups().forEach(processGroup -> { discoverCompatibleBundles(processGroup.getContents()); }); } }
private void verifyProcessorsInSnippet(final FlowSnippetDTO templateContents, final Map<String, Set<BundleCoordinate>> supportedTypes) { if (templateContents.getProcessors() != null) { templateContents.getProcessors().forEach(processor -> { if (processor.getBundle() == null) { throw new IllegalArgumentException("Processor bundle must be specified."); } if (supportedTypes.containsKey(processor.getType())) { verifyBundleInSnippet(processor.getBundle(), supportedTypes.get(processor.getType())); } else { throw new IllegalStateException("Invalid Processor Type: " + processor.getType()); } }); } if (templateContents.getProcessGroups() != null) { templateContents.getProcessGroups().forEach(processGroup -> verifyProcessorsInSnippet(processGroup.getContents(), supportedTypes)); } }
allConns.addAll(dto.getConnections()); for (final ProcessGroupDTO childGroup : dto.getProcessGroups()) { allConns.addAll(findAllConnections(childGroup));
public static void verifyNoVersionControlConflicts(final FlowSnippetDTO snippetContents, final ProcessGroup destination) { final List<VersionControlInformationDTO> vcis = new ArrayList<>(); for (final ProcessGroupDTO childGroup : snippetContents.getProcessGroups()) { findAllVersionControlInfo(childGroup, vcis); } verifyNoDuplicateVersionControlInfoDtos(destination, vcis); }