@Override public void discoverCompatibleBundles(VersionedProcessGroup versionedGroup) { BundleUtils.discoverCompatibleBundles(controllerFacade.getExtensionManager(), versionedGroup); }
/** * Gets the cached temporary instance of the component for the given type and bundle. * * @param type type of the component * @param bundle the bundle of the component * @return the temporary component * @throws IllegalStateException if no temporary component exists for the given type and bundle */ public ConfigurableComponent getTemporaryComponent(final String type, final BundleDTO bundle) { final ExtensionManager extensionManager = getExtensionManager(); final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(extensionManager, type, bundle); final ConfigurableComponent configurableComponent = extensionManager.getTempComponent(type, bundleCoordinate); if (configurableComponent == null) { throw new IllegalStateException("Unable to obtain temporary component for " + type); } return configurableComponent; }
@Override public BundleCoordinate getCompatibleBundle(String type, BundleDTO bundleDTO) { return BundleUtils.getCompatibleBundle(controllerFacade.getExtensionManager(), type, bundleDTO); }
return findBundleForType(extensionManager, type, null); } else { return findCompatibleBundle(extensionManager, type, bundleDTO, false);
if (versionedGroup.getProcessors() != null) { versionedGroup.getProcessors().forEach(processor -> { final BundleCoordinate coordinate = BundleUtils.getCompatibleBundle(extensionManager, processor.getType(), createBundleDto(processor.getBundle())); final BundleCoordinate coordinate = BundleUtils.getCompatibleBundle(extensionManager, controllerService.getType(), createBundleDto(controllerService.getBundle())); discoverCompatibleBundles(extensionManager, processGroup); });
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)); } } }
return findBundleForType(extensionManager, type, null); } else { return findCompatibleBundle(extensionManager, type, bundleDTO, true);
private void checkBundleCompatibility(final Document configuration) { final NodeList bundleNodes = configuration.getElementsByTagName("bundle"); for (int i = 0; i < bundleNodes.getLength(); i++) { final Node bundleNode = bundleNodes.item(i); if (bundleNode instanceof Element) { final Element bundleElement = (Element) bundleNode; final Node componentNode = bundleElement.getParentNode(); if (componentNode instanceof Element) { final Element componentElement = (Element) componentNode; if (!withinTemplate(componentElement)) { final String componentType = DomUtils.getChildText(componentElement, "class"); try { BundleUtils.getBundle(extensionManager, componentType, FlowFromDOMFactory.getBundle(bundleElement)); } catch (IllegalStateException e) { throw new MissingBundleException(e.getMessage(), e); } } } } } }
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; }
@Override public ReportingTaskNode createReportingTask(final ReportingTaskDTO reportingTaskDTO) { // ensure the type is specified if (reportingTaskDTO.getType() == null) { throw new IllegalArgumentException("The reporting task type must be specified."); } try { // create the reporting task final ExtensionManager extensionManager = reportingTaskProvider.getExtensionManager(); final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(extensionManager, reportingTaskDTO.getType(), reportingTaskDTO.getBundle()); final ReportingTaskNode reportingTask = reportingTaskProvider.createReportingTask( reportingTaskDTO.getType(), reportingTaskDTO.getId(), bundleCoordinate, true); // ensure we can perform the update verifyUpdate(reportingTask, reportingTaskDTO); // perform the update configureReportingTask(reportingTask, reportingTaskDTO); return reportingTask; } catch (ReportingTaskInstantiationException rtie) { throw new NiFiCoreException(rtie.getMessage(), rtie); } }
snippet.getProcessors().forEach(processor -> { 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) { 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) {
@Override public ProcessorNode createProcessor(final String groupId, ProcessorDTO processorDTO) { if (processorDTO.getParentGroupId() != null && !flowController.getFlowManager().areGroupsSame(groupId, processorDTO.getParentGroupId())) { throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the Processor is being added."); } // ensure the type is specified if (processorDTO.getType() == null) { throw new IllegalArgumentException("The processor type must be specified."); } // get the group to add the processor to ProcessGroup group = locateProcessGroup(flowController, groupId); try { // attempt to create the processor final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(flowController.getExtensionManager(), processorDTO.getType(), processorDTO.getBundle()); ProcessorNode processor = flowController.getFlowManager().createProcessor(processorDTO.getType(), processorDTO.getId(), bundleCoordinate); // ensure we can perform the update before we add the processor to the flow verifyUpdate(processor, processorDTO); // add the processor to the group group.addProcessor(processor); // configure the processor configureProcessor(processor, processorDTO); return processor; } catch (IllegalStateException | ComponentLifeCycleException ise) { throw new NiFiCoreException(ise.getMessage(), ise); } }
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; }
final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(extensionManager, controllerServiceDTO.getType(), controllerServiceDTO.getBundle()); final ControllerServiceNode controllerService = flowManager.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getId(), bundleCoordinate, Collections.emptySet(), true, true);
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()); } }
private void updateBundle(ReportingTaskNode reportingTask, ReportingTaskDTO reportingTaskDTO) { final BundleDTO bundleDTO = reportingTaskDTO.getBundle(); if (bundleDTO != null) { final ExtensionManager extensionManager = reportingTaskProvider.getExtensionManager(); final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, reportingTask.getCanonicalClassName(), bundleDTO); final BundleCoordinate existingCoordinate = reportingTask.getBundleCoordinate(); if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) { try { // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component final ConfigurableComponent tempComponent = extensionManager.getTempComponent(reportingTask.getCanonicalClassName(), incomingCoordinate); final Set<URL> additionalUrls = reportingTask.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors()); reloadComponent.reload(reportingTask, reportingTask.getCanonicalClassName(), incomingCoordinate, additionalUrls); } catch (ReportingTaskInstantiationException e) { throw new NiFiCoreException(String.format("Unable to update reporting task %s from %s to %s due to: %s", reportingTaskDTO.getId(), reportingTask.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e); } } } }
coordinate = BundleUtils.getCompatibleBundle(extensionManager, processorDTO.getType(), processorDTO.getBundle()); } catch (final IllegalStateException e) { final BundleDTO bundleDTO = processorDTO.getBundle();
private void updateBundle(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) { final BundleDTO bundleDTO = controllerServiceDTO.getBundle(); if (bundleDTO != null) { final ExtensionManager extensionManager = serviceProvider.getExtensionManager(); final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, controllerService.getCanonicalClassName(), bundleDTO); final BundleCoordinate existingCoordinate = controllerService.getBundleCoordinate(); if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) { try { // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component final ConfigurableComponent tempComponent = extensionManager.getTempComponent(controllerService.getCanonicalClassName(), incomingCoordinate); final Set<URL> additionalUrls = controllerService.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors()); flowController.getReloadComponent().reload(controllerService, controllerService.getCanonicalClassName(), incomingCoordinate, additionalUrls); } catch (ControllerServiceInstantiationException e) { throw new NiFiCoreException(String.format("Unable to update controller service %s from %s to %s due to: %s", controllerServiceDTO.getId(), controllerService.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e); } } } }
private void updateBundle(ProcessorNode processor, ProcessorDTO processorDTO) { final BundleDTO bundleDTO = processorDTO.getBundle(); if (bundleDTO != null) { final ExtensionManager extensionManager = flowController.getExtensionManager(); final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, processor.getCanonicalClassName(), bundleDTO); final BundleCoordinate existingCoordinate = processor.getBundleCoordinate(); if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) { try { // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component final ConfigurableComponent tempComponent = extensionManager.getTempComponent(processor.getCanonicalClassName(), incomingCoordinate); final Set<URL> additionalUrls = processor.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors()); flowController.getReloadComponent().reload(processor, processor.getCanonicalClassName(), incomingCoordinate, additionalUrls); } catch (ProcessorInstantiationException e) { throw new NiFiCoreException(String.format("Unable to update processor %s from %s to %s due to: %s", processorDTO.getId(), processor.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e); } } } }
if (bundleDTO != null) { final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(serviceProvider.getExtensionManager(), controllerService.getCanonicalClassName(), bundleDTO);