public int getBundleCount(NamespaceName namespace) throws Exception { return bundleFactory.getBundles(namespace).size(); }
protected Policies getNamespacePolicies(String property, String cluster, String namespace) { try { Policies policies = policiesCache().get(AdminResource.path("policies", property, cluster, namespace)) .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Namespace does not exist")); // fetch bundles from LocalZK-policies NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory() .getBundles(new NamespaceName(property, cluster, namespace)); BundlesData bundleData = NamespaceBundleFactory.getBundlesData(bundles); policies.bundles = bundleData != null ? bundleData : policies.bundles; return policies; } catch (RestException re) { throw re; } catch (Exception e) { log.error("[{}] Failed to get namespace policies {}/{}/{}", clientAppId(), property, cluster, namespace, e); throw new RestException(e); } }
public void removeOwnedServiceUnits(NamespaceName nsName, BundlesData bundleData) throws Exception { ownershipCache.removeOwnership(bundleFactory.getBundles(nsName, bundleData)).get(cacheTimeOutInSec, SECONDS); bundleFactory.invalidateBundleCache(nsName); }
public NamespaceBundle getBundle(DestinationName destination) throws Exception { return bundleFactory.getBundles(destination.getNamespaceObject()).findBundle(destination); }
public NamespaceBundleFactory(PulsarService pulsar, HashFunction hashFunc) { this.hashFunc = hashFunc; this.bundlesCache = Caffeine.newBuilder().buildAsync((NamespaceName namespace, Executor executor) -> { String path = AdminResource.joinPath(LOCAL_POLICIES_ROOT, namespace.toString()); if (LOG.isDebugEnabled()) { LOG.debug("Loading cache with bundles for {}", namespace); } if (pulsar == null || pulsar.getConfigurationCache() == null) { return CompletableFuture.completedFuture(getBundles(namespace, null)); } CompletableFuture<NamespaceBundles> future = new CompletableFuture<>(); // Read the static bundle data from the policies pulsar.getLocalZkCacheService().policiesCache().getAsync(path).thenAccept(policies -> { // If no policies defined for namespace, assume 1 single bundle BundlesData bundlesData = policies.map(p -> p.bundles).orElse(null); NamespaceBundles namespaceBundles = getBundles(namespace, bundlesData); future.complete(namespaceBundles); }).exceptionally(ex -> { future.completeExceptionally(ex); return null; }); return future; }); if (pulsar != null && pulsar.getConfigurationCache() != null) { pulsar.getLocalZkCacheService().policiesCache().registerListener(this); } this.pulsar = pulsar; }
protected NamespaceBundle validateNamespaceBundleRange(NamespaceName fqnn, BundlesData bundles, String bundleRange) { try { checkArgument(bundleRange.contains("_"), "Invalid bundle range"); String[] boundaries = bundleRange.split("_"); Long lowerEndpoint = Long.decode(boundaries[0]); Long upperEndpoint = Long.decode(boundaries[1]); Range<Long> hashRange = Range.range(lowerEndpoint, BoundType.CLOSED, upperEndpoint, (upperEndpoint.equals(NamespaceBundles.FULL_UPPER_BOUND)) ? BoundType.CLOSED : BoundType.OPEN); NamespaceBundle nsBundle = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundle(fqnn, hashRange); NamespaceBundles nsBundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(fqnn, bundles); nsBundles.validateBundle(nsBundle); return nsBundle; } catch (Exception e) { log.error("[{}] Failed to validate namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e); throw new RestException(e); } }
NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(nsName); Exception exception = null; for (NamespaceBundle nsBundle : bundles.getBundles()) {
NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(nsName); Exception exception = null; for (NamespaceBundle nsBundle : bundles.getBundles()) {
NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(nsName); Exception exception = null; for (NamespaceBundle nsBundle : bundles.getBundles()) {
/** * Checks whether the broker is the owner of all the namespace bundles. Otherwise, if authoritative is false, it * will throw an exception to redirect to assigned owner or leader; if authoritative is true then it will try to * acquire all the namespace bundles. * * @param fqnn * @param authoritative * @param readOnly * @param bundleData */ protected void validateNamespaceOwnershipWithBundles(String property, String cluster, String namespace, boolean authoritative, boolean readOnly, BundlesData bundleData) { NamespaceName fqnn = new NamespaceName(property, cluster, namespace); try { NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(fqnn, bundleData); for (NamespaceBundle bundle : bundles.getBundles()) { validateBundleOwnership(bundle, authoritative, readOnly); } } catch (WebApplicationException wae) { // propagate already wrapped-up WebApplicationExceptions throw wae; } catch (Exception oe) { log.debug(String.format("Failed to find owner for namespace %s", fqnn), oe); throw new RestException(oe); } }
NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(nsName); for (NamespaceBundle bundle : bundles.getBundles()) {