public BundleDTO copy(final BundleDTO original) { if (original == null) { return null; } final BundleDTO copy = new BundleDTO(); copy.setGroup(original.getGroup()); copy.setArtifact(original.getArtifact()); copy.setVersion(original.getVersion()); return copy; }
private void addBundleFingerprint(final StringBuilder builder, final BundleDTO bundle) { if (bundle != null) { builder.append(bundle.getGroup()); builder.append(bundle.getArtifact()); builder.append(bundle.getVersion()); } else { builder.append("MISSING_BUNDLE"); } }
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; } }
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()); }
private void verifyBundleInSnippet(final BundleDTO requiredBundle, final Set<BundleCoordinate> supportedBundles) { final BundleCoordinate requiredCoordinate = new BundleCoordinate(requiredBundle.getGroup(), requiredBundle.getArtifact(), requiredBundle.getVersion()); if (!supportedBundles.contains(requiredCoordinate)) { throw new IllegalStateException("Unsupported bundle: " + requiredCoordinate); } }
/** * Creates a bundle DTO from the specified class. * * @param coordinate bundle coordinates * @return dto */ public BundleDTO createBundleDto(final BundleCoordinate coordinate) { final BundleDTO dto = new BundleDTO(); dto.setGroup(coordinate.getGroup()); dto.setArtifact(coordinate.getId()); dto.setVersion(coordinate.getVersion()); return dto; }
public static BundleDTO createBundleDto(final Bundle bundle) { return new BundleDTO(bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); } }
private BundleCoordinate getCoordinate(final String type, final BundleDTO dto) { BundleCoordinate coordinate; try { coordinate = BundleUtils.getCompatibleBundle(extensionManager, type, dto); } catch (final IllegalStateException e) { if (dto == null) { coordinate = BundleCoordinate.UNKNOWN_COORDINATE; } else { coordinate = new BundleCoordinate(dto.getGroup(), dto.getArtifact(), dto.getVersion()); } } return coordinate; }
try { final BundleCoordinate bundle = BundleUtils.getCompatibleBundle(extensionManager, processor.getType(), processor.getBundle()); processors.add(getConfigurableComponent(processor.getType(), new BundleDTO(bundle.getGroup(), bundle.getId(), bundle.getVersion()))); } catch (final IllegalStateException e) { 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) {
protected void verifyCreate(final ExtensionManager extensionManager, final String type, final BundleDTO bundle) { final List<Bundle> bundles = extensionManager.getBundles(type); if (bundle != null) { final BundleCoordinate coordinate = new BundleCoordinate(bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); if (bundles.stream().filter(b -> b.getBundleDetails().getCoordinate().equals(coordinate)).count() == 0) { throw new IllegalStateException(String.format("%s is not known to this NiFi instance.", coordinate.toString())); } } else { if (bundles.isEmpty()) { throw new IllegalStateException(String.format("%s is not known to this NiFi instance.", type)); } else if (bundles.size() > 1) { throw new IllegalStateException(String.format("Multiple versions of %s exist. Please specify the desired bundle.", type)); } } } }
/** * 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()); }); } }
/** * 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; }
private static BundleCoordinate findCompatibleBundle(final ExtensionManager extensionManager, final String type, final BundleDTO bundleDTO, final boolean allowCompatibleBundle) { final BundleCoordinate coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion()); final Bundle bundle = extensionManager.getBundle(coordinate); if (bundle == null) { if (allowCompatibleBundle) { return findBundleForType(extensionManager, type, coordinate); } else { throw new IllegalStateException(String.format("%s from %s is not known to this NiFi instance.", type, coordinate)); } } else { final List<BundleCoordinate> bundlesForType = extensionManager.getBundles(type).stream().map(b -> b.getBundleDetails().getCoordinate()).collect(Collectors.toList()); if (bundlesForType.contains(coordinate)) { return coordinate; } else { throw new IllegalStateException(String.format("Found bundle %s but does not support %s", coordinate, type)); } } }
/** * Populates the uri for the specified reporting task. */ public ReportingTaskDTO populateRemainingReportingTaskContent(final ReportingTaskDTO reportingTask) { final BundleDTO bundle = reportingTask.getBundle(); if (bundle == null) { return reportingTask; } // see if this processor has any ui extensions final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions"); if (uiExtensionMapping.hasUiExtension(reportingTask.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) { final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(reportingTask.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); for (final UiExtension uiExtension : uiExtensions) { if (UiExtensionType.ReportingTaskConfiguration.equals(uiExtension.getExtensionType())) { reportingTask.setCustomUiUrl(uiExtension.getContextPath() + "/configure"); } } } return reportingTask; }
/** * Populate the uri's for the specified processor and its relationships. */ public ProcessorDTO populateRemainingProcessorContent(ProcessorDTO processor) { // get the config details and see if there is a custom ui for this processor type ProcessorConfigDTO config = processor.getConfig(); if (config != null) { // consider legacy custom ui fist String customUiUrl = servletContext.getInitParameter(processor.getType()); if (StringUtils.isNotBlank(customUiUrl)) { config.setCustomUiUrl(customUiUrl); } else { final BundleDTO bundle = processor.getBundle(); // see if this processor has any ui extensions final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions"); if (uiExtensionMapping.hasUiExtension(processor.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) { final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(processor.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); for (final UiExtension uiExtension : uiExtensions) { if (UiExtensionType.ProcessorConfiguration.equals(uiExtension.getExtensionType())) { config.setCustomUiUrl(uiExtension.getContextPath() + "/configure"); } } } } } return processor; }
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; }
private ReportingTaskNode getOrCreateReportingTask(final FlowController controller, final ReportingTaskDTO dto, final boolean controllerInitialized, final boolean existingFlowEmpty) throws ReportingTaskInstantiationException { // create a new reporting task node when the controller is not initialized or the flow is empty if (!controllerInitialized || existingFlowEmpty) { BundleCoordinate coordinate; try { coordinate = BundleUtils.getCompatibleBundle(extensionManager, 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 ReportingTaskNode reportingTask = controller.createReportingTask(dto.getType(), dto.getId(), coordinate, false); reportingTask.setName(dto.getName()); reportingTask.setComments(dto.getComments()); reportingTask.setSchedulingPeriod(dto.getSchedulingPeriod()); reportingTask.setSchedulingStrategy(SchedulingStrategy.valueOf(dto.getSchedulingStrategy())); reportingTask.setAnnotationData(dto.getAnnotationData()); reportingTask.setProperties(dto.getProperties()); return reportingTask; } else { // otherwise return the existing reporting task node return controller.getReportingTaskNode(dto.getId()); } }
coordinate = BundleCoordinate.UNKNOWN_COORDINATE; } else { coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion());