private void verifyBundleInVersionedFlow(final org.apache.nifi.registry.flow.Bundle 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); } }
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); } }
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)); } } } }
private File unpack(final File narFile) { try (final JarFile nar = new JarFile(narFile)) { final Manifest manifest = nar.getManifest(); final Attributes attributes = manifest.getMainAttributes(); final String groupId = attributes.getValue(NarManifestEntry.NAR_GROUP.getManifestName()); final String narId = attributes.getValue(NarManifestEntry.NAR_ID.getManifestName()); final String version = attributes.getValue(NarManifestEntry.NAR_VERSION.getManifestName()); if (NarClassLoaders.FRAMEWORK_NAR_ID.equals(narId)) { LOGGER.error("Found a framework NAR, will not load {}", new Object[]{narFile.getAbsolutePath()}); return null; } final BundleCoordinate coordinate = new BundleCoordinate(groupId, narId, version); final Bundle bundle = extensionManager.getBundle(coordinate); if (bundle != null) { LOGGER.warn("Found existing bundle with coordinate {}, will not load {}", new Object[]{coordinate, narFile.getAbsolutePath()}); return null; } final File unpackedExtension = NarUnpacker.unpackNar(narFile, extensionsWorkingDir); NarUnpacker.mapExtension(unpackedExtension, coordinate, docsWorkingDir, extensionMapping); return unpackedExtension; } catch (Exception e) { LOGGER.error("Error unpacking " + narFile.getAbsolutePath(), e); return null; } }
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)); } } }
private BundleCoordinate toCoordinate(final Bundle bundle) { return new BundleCoordinate(bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); }
public static BundleCoordinate createBundleCoordinate(final Bundle bundle) { return new BundleCoordinate(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; }
final BundleCoordinate bundleCoordinate = new BundleCoordinate(serviceBundleGroup, serviceBundleArtifact, serviceBundleVersion); final Bundle csBundle = getExtensionManager().getBundle(bundleCoordinate); if (csBundle == null) {
unpackedNars.put(unpackedExtension, new BundleCoordinate(groupId, narId, version));
final String id = attributes.getValue(NarManifestEntry.NAR_ID.getManifestName()); final String version = attributes.getValue(NarManifestEntry.NAR_VERSION.getManifestName()); builder.coordinate(new BundleCoordinate(group, id, version)); final String dependencyVersion = attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_VERSION.getManifestName()); if (!StringUtils.isBlank(dependencyId)) { builder.dependencyCoordinate(new BundleCoordinate(dependencyGroup, dependencyId, dependencyVersion));
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());
final String id = attributes.getValue(NarManifestEntry.NAR_ID.getManifestName()); final String version = attributes.getValue(NarManifestEntry.NAR_VERSION.getManifestName()); builder.coordinate(new BundleCoordinate(group, id, version)); final String dependencyVersion = attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_VERSION.getManifestName()); if (!StringUtils.isBlank(dependencyId)) { builder.dependencyCoordinate(new BundleCoordinate(dependencyGroup, dependencyId, dependencyVersion));
final String id = attributes.getValue(NarManifestEntry.NAR_ID.getManifestName()); final String version = attributes.getValue(NarManifestEntry.NAR_VERSION.getManifestName()); builder.coordinate(new BundleCoordinate(group, id, version)); final String dependencyVersion = attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_VERSION.getManifestName()); if (!StringUtils.isBlank(dependencyId)) { builder.dependencyCoordinate(new BundleCoordinate(dependencyGroup, dependencyId, dependencyVersion));