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)); } }
private void addControllerServiceFingerprint(final StringBuilder builder, final ControllerServiceDTO dto) { builder.append(dto.getId()); builder.append(dto.getVersionedComponentId()); builder.append(dto.getType()); builder.append(dto.getName()); addBundleFingerprint(builder, dto.getBundle()); builder.append(dto.getComments()); builder.append(dto.getAnnotationData()); builder.append(dto.getState()); // get the temp instance of the ControllerService so that we know the default property values final BundleCoordinate coordinate = getCoordinate(dto.getType(), dto.getBundle()); final ConfigurableComponent configurableComponent = extensionManager.getTempComponent(dto.getType(), coordinate); if (configurableComponent == null) { logger.warn("Unable to get ControllerService of type {}; its default properties will be fingerprinted instead of being ignored.", dto.getType()); } addPropertiesFingerprint(builder, configurableComponent, dto.getProperties()); }
@Override public void verifyCreate(final ControllerServiceDTO controllerServiceDTO) { verifyCreate(serviceProvider.getExtensionManager(), controllerServiceDTO.getType(), controllerServiceDTO.getBundle()); }
@Override public ControllerServiceNode createControllerService(final ControllerServiceDTO controllerServiceDTO) { if (controllerServiceDTO.getType() == null) { throw new IllegalArgumentException("The controller service type must be specified."); final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(extensionManager, controllerServiceDTO.getType(), controllerServiceDTO.getBundle()); final ControllerServiceNode controllerService = flowManager.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getId(), bundleCoordinate, Collections.emptySet(), true, true);
/** * Populates the uri for the specified controller service. */ public ControllerServiceDTO populateRemainingControllerServiceContent(final ControllerServiceDTO controllerService) { final BundleDTO bundle = controllerService.getBundle(); // see if this processor has any ui extensions final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions"); if (uiExtensionMapping.hasUiExtension(controllerService.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) { final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(controllerService.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); for (final UiExtension uiExtension : uiExtensions) { if (UiExtensionType.ControllerServiceConfiguration.equals(uiExtension.getExtensionType())) { controllerService.setCustomUiUrl(uiExtension.getContextPath() + "/configure"); } } } return controllerService; }
final ConfigurableComponent configurableComponent = controllerFacade.getTemporaryComponent(dto.getType(), dto.getBundle()); configurableComponent.getPropertyDescriptors().forEach(descriptor -> { if (dto.getProperties().get(descriptor.getName()) == null) { logger.warn(String.format("Unable to create ControllerService of type %s to populate default values.", dto.getType()));
snippet.getControllerServices().forEach(controllerService -> { try { final BundleCoordinate bundle = BundleUtils.getCompatibleBundle(extensionManager, controllerService.getType(), controllerService.getBundle()); controllerServices.add(getConfigurableComponent(controllerService.getType(), new BundleDTO(bundle.getGroup(), bundle.getId(), bundle.getVersion()))); } catch (final IllegalStateException e) {
private static ControllerServiceNode createControllerService(final FlowController flowController, final Element controllerServiceElement, final StringEncryptor encryptor) { final ControllerServiceDTO dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor); BundleCoordinate coordinate; try { coordinate = BundleUtils.getCompatibleBundle(flowController.getExtensionManager(), dto.getType(), dto.getBundle()); } catch (final IllegalStateException e) { final BundleDTO bundleDTO = dto.getBundle(); if (bundleDTO == null) { coordinate = BundleCoordinate.UNKNOWN_COORDINATE; } else { coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion()); } } final ControllerServiceNode node = flowController.getFlowManager().createControllerService(dto.getType(), dto.getId(), coordinate, Collections.emptySet(), false, true); node.setName(dto.getName()); node.setComments(dto.getComments()); node.setVersionedComponentId(dto.getVersionedComponentId()); return node; }
/** * 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 ComponentDetails getComponentConfiguration(final ControllerServiceDTO controllerService) { return new ComponentDetails.Builder() .id(controllerService.getId()) .name(controllerService.getName()) .type(controllerService.getType()) .state(controllerService.getState()) .annotationData(controllerService.getAnnotationData()) .properties(controllerService.getProperties()) .validateErrors(controllerService.getValidationErrors()).build(); } }
public ControllerServiceDTO copy(final ControllerServiceDTO original) { final ControllerServiceDTO copy = new ControllerServiceDTO(); copy.setAnnotationData(original.getAnnotationData()); copy.setControllerServiceApis(original.getControllerServiceApis()); copy.setComments(original.getComments()); copy.setCustomUiUrl(original.getCustomUiUrl()); copy.setDescriptors(copy(original.getDescriptors())); copy.setId(original.getId()); copy.setParentGroupId(original.getParentGroupId()); copy.setName(original.getName()); copy.setProperties(copy(original.getProperties())); copy.setReferencingComponents(copy(original.getReferencingComponents())); copy.setState(original.getState()); copy.setType(original.getType()); copy.setBundle(copy(original.getBundle())); copy.setExtensionMissing(original.getExtensionMissing()); copy.setMultipleVersionsAvailable(original.getMultipleVersionsAvailable()); copy.setPersistsState(original.getPersistsState()); copy.setValidationErrors(copy(original.getValidationErrors())); copy.setValidationStatus(original.getValidationStatus()); copy.setVersionedComponentId(original.getVersionedComponentId()); return copy; }
try { for (final ControllerServiceDTO controllerServiceDTO : dto.getControllerServices()) { final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(extensionManager, controllerServiceDTO.getType(), controllerServiceDTO.getBundle()); final ControllerServiceNode serviceNode = flowManager.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getId(), bundleCoordinate, Collections.emptySet(), true,true);
@Override public ControllerServiceSchema apply(ControllerServiceDTO controllerServiceDTO) { Map<String, Object> map = new HashMap<>(); map.put(NAME_KEY, controllerServiceDTO.getName()); map.put(ID_KEY, controllerServiceDTO.getId()); map.put(TYPE_KEY, controllerServiceDTO.getType()); map.put(PROPERTIES_KEY, new HashMap<>(nullToEmpty(controllerServiceDTO.getProperties()))); String annotationData = controllerServiceDTO.getAnnotationData(); if(annotationData != null && !annotationData.isEmpty()) { map.put(ANNOTATION_DATA_KEY, annotationData); } return new ControllerServiceSchema(map); } }
@Override public ControllerServiceSchema apply(ControllerServiceDTO controllerServiceDTO) { Map<String, Object> map = new HashMap<>(); map.put(NAME_KEY, controllerServiceDTO.getName()); map.put(ID_KEY, controllerServiceDTO.getId()); map.put(TYPE_KEY, controllerServiceDTO.getType()); map.put(PROPERTIES_KEY, new HashMap<>(nullToEmpty(controllerServiceDTO.getProperties()))); String annotationData = controllerServiceDTO.getAnnotationData(); if(annotationData != null && !annotationData.isEmpty()) { map.put(ANNOTATION_DATA_KEY, annotationData); } return new ControllerServiceSchema(map); } }