/** * update new bundle-range to LocalZk (create a new node if not present) * * @param nsname * @param nsBundles * @param callback * @throws Exception */ private void updateNamespaceBundles(NamespaceName nsname, NamespaceBundles nsBundles, StatCallback callback) throws Exception { checkNotNull(nsname); checkNotNull(nsBundles); String path = joinPath(LOCAL_POLICIES_ROOT, nsname.toString()); Optional<LocalPolicies> policies = pulsar.getLocalZkCacheService().policiesCache().get(path); if (!policies.isPresent()) { // if policies is not present into localZk then create new policies this.pulsar.getLocalZkCacheService().createPolicies(path, false).get(cacheTimeOutInSec, SECONDS); policies = this.pulsar.getLocalZkCacheService().policiesCache().get(path); } policies.get().bundles = getBundlesData(nsBundles); this.pulsar.getLocalZkCache().getZooKeeper().setData(path, ObjectMapperFactory.getThreadLocal().writeValueAsBytes(policies.get()), -1, callback, null); }
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); } }