Java Code Examples for org.apache.pulsar.common.naming.NamespaceName#toString()
The following examples show how to use
org.apache.pulsar.common.naming.NamespaceName#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdminResource.java From pulsar with Apache License 2.0 | 6 votes |
protected Policies getNamespacePolicies(NamespaceName namespaceName) { try { final String namespace = namespaceName.toString(); final String policyPath = AdminResource.path(POLICIES, namespace); Policies policies = policiesCache().get(policyPath) .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Namespace does not exist")); // fetch bundles from LocalZK-policies NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory() .getBundles(namespaceName); BundlesData bundleData = NamespaceBundleFactory.getBundlesData(bundles); policies.bundles = bundleData != null ? bundleData : policies.bundles; // hydrate the namespace polices mergeNamespaceWithDefaults(policies, namespace, policyPath); return policies; } catch (RestException re) { throw re; } catch (Exception e) { log.error("[{}] Failed to get namespace policies {}", clientAppId(), namespaceName, e); throw new RestException(e); } }
Example 2
Source File: AdminResource.java From pulsar with Apache License 2.0 | 5 votes |
protected CompletableFuture<Policies> getNamespacePoliciesAsync(NamespaceName namespaceName) { final String namespace = namespaceName.toString(); final String policyPath = AdminResource.path(POLICIES, namespace); return policiesCache().getAsync(policyPath).thenCompose(policies -> { if (policies.isPresent()) { return pulsar() .getNamespaceService() .getNamespaceBundleFactory() .getBundlesAsync(namespaceName) .thenCompose(bundles -> { BundlesData bundleData = null; try { bundleData = NamespaceBundleFactory.getBundlesData(bundles); } catch (Exception e) { log.error("[{}] Failed to get namespace policies {}", clientAppId(), namespaceName, e); return FutureUtil.failedFuture(new RestException(e)); } policies.get().bundles = bundleData != null ? bundleData : policies.get().bundles; // hydrate the namespace polices mergeNamespaceWithDefaults(policies.get(), namespace, policyPath); return CompletableFuture.completedFuture(policies.get()); }); } else { return FutureUtil.failedFuture(new RestException(Status.NOT_FOUND, "Namespace does not exist")); } }); }
Example 3
Source File: PulsarClusterMetadataSetup.java From pulsar with Apache License 2.0 | 5 votes |
static void createNamespaceIfAbsent(ZooKeeper configStoreZk, NamespaceName namespaceName, String cluster) throws KeeperException, InterruptedException, IOException { String namespacePath = POLICIES_ROOT + "/" +namespaceName.toString(); Policies policies; Stat stat = configStoreZk.exists(namespacePath, false); if (stat == null) { policies = new Policies(); policies.bundles = getBundles(16); policies.replication_clusters = Collections.singleton(cluster); createZkNode( configStoreZk, namespacePath, ObjectMapperFactory.getThreadLocal().writeValueAsBytes(policies), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } else { byte[] content = configStoreZk.getData(namespacePath, false, null); policies = ObjectMapperFactory.getThreadLocal().readValue(content, Policies.class); // Only update z-node if the list of clusters should be modified if (!policies.replication_clusters.contains(cluster)) { policies.replication_clusters.add(cluster); configStoreZk.setData(namespacePath, ObjectMapperFactory.getThreadLocal().writeValueAsBytes(policies), stat.getVersion()); } } }
Example 4
Source File: NamespaceIsolationPolicyImpl.java From pulsar with Apache License 2.0 | 5 votes |
@Override public List<URL> findPrimaryBrokers(List<URL> availableBrokers, NamespaceName namespace) { if (!this.matchNamespaces(namespace.toString())) { throw new IllegalArgumentException("Namespace " + namespace.toString() + " does not match policy"); } // find the available brokers that matches primary brokers regex list return this.getMatchedBrokers(this.primary, availableBrokers); }
Example 5
Source File: NamespaceIsolationPolicyImpl.java From pulsar with Apache License 2.0 | 5 votes |
@Override public List<URL> findSecondaryBrokers(List<URL> availableBrokers, NamespaceName namespace) { if (!this.matchNamespaces(namespace.toString())) { throw new IllegalArgumentException("Namespace " + namespace.toString() + " does not match policy"); } // find the available brokers that matches primary brokers regex list return this.getMatchedBrokers(this.secondary, availableBrokers); }