public static NamespaceName get(String tenant, String cluster, String namespace) { validateNamespaceName(tenant, cluster, namespace); return get(tenant + '/' + cluster + '/' + namespace); }
public static NamespaceName get(String tenant, String namespace) { validateNamespaceName(tenant, namespace); return get(tenant + '/' + namespace); }
this.localName = parts.get(2); this.partitionIndex = getPartitionIndex(completeTopicName); this.namespaceName = NamespaceName.get(tenant, namespacePortion); } else if (parts.size() == 4) { this.localName = parts.get(3); this.partitionIndex = getPartitionIndex(completeTopicName); this.namespaceName = NamespaceName.get(tenant, cluster, namespacePortion); } else { throw new IllegalArgumentException("Invalid topic name: " + completeTopicName);
public NamespaceBundle getBundle(String namespace, String bundleRange) { 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); return getBundle(NamespaceName.get(namespace), hashRange); }
@Deprecated protected void validateNamespaceName(String property, String cluster, String namespace) { try { this.namespaceName = NamespaceName.get(property, cluster, namespace); } catch (IllegalArgumentException e) { log.warn("[{}] Failed to create namespace with invalid name {}", clientAppId(), namespace, e); throw new RestException(Status.PRECONDITION_FAILED, "Namespace name is not valid"); } }
public JsonObject getBrokerResourceAvailability(String namespace) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget admin = ns.isV2() ? adminV2BrokerStats : adminBrokerStats; String json = request(admin.path("/broker-resource-availability").path(ns.toString())).get(String.class); return new Gson().fromJson(json, JsonObject.class); } catch (Exception e) { throw getApiException(e); } } }
@Override public void grantPermissionOnNamespace(String namespace, String role, Set<AuthAction> actions) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "permissions", role); request(path).post(Entity.entity(actions, MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
@Override public void setPersistence(String namespace, PersistencePolicies persistence) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "persistence"); request(path).post(Entity.entity(persistence, MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
@Override public void setRetention(String namespace, RetentionPolicies retention) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "retention"); request(path).post(Entity.entity(retention, MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
@Override public void clearNamespaceBacklog(String namespace) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "clearBacklog"); request(path).post(Entity.entity("", MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
@Override public void onUpdate(String path, LocalPolicies data, Stat stat) { final NamespaceName namespace = NamespaceName.get(getNamespaceFromPoliciesPath(path)); try { LOG.info("Policy updated for namespace {}, refreshing the bundle cache.", namespace); // invalidate the bundle cache to fetch new bundle data from the policies bundlesCache.synchronous().invalidate(namespace); } catch (Exception e) { LOG.error("Failed to update the policy change for ns {}", namespace, e); } }
@Override public void setNamespaceReplicationClusters(String namespace, Set<String> clusterIds) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "replication"); request(path).post(Entity.entity(clusterIds, MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
@Override public void unsubscribeNamespaceBundle(String namespace, String bundle, String subscription) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, bundle, "unsubscribe", subscription); request(path).post(Entity.entity("", MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
@Override public DispatchRate getDispatchRate(String namespace) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "dispatchRate"); return request(path).get(DispatchRate.class); } catch (Exception e) { throw getApiException(e); } }
@Override public int getMaxProducersPerTopic(String namespace) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "maxProducersPerTopic"); return request(path).get(Integer.class); } catch (Exception e) { throw getApiException(e); } }
@Override public Map<BacklogQuotaType, BacklogQuota> getBacklogQuotaMap(String namespace) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "backlogQuotaMap"); return request(path).get(new GenericType<Map<BacklogQuotaType, BacklogQuota>>() { }); } catch (Exception e) { throw getApiException(e); } }
@Override public int getMaxConsumersPerSubscription(String namespace) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "maxConsumersPerSubscription"); return request(path).get(Integer.class); } catch (Exception e) { throw getApiException(e); } }
@Override public void setOffloadDeleteLag(String namespace, long lag, TimeUnit unit) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "offloadDeletionLagMs"); request(path).put(Entity.entity(TimeUnit.MILLISECONDS.convert(lag, unit), MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
@Override public void clearOffloadDeleteLag(String namespace) throws PulsarAdminException { try { NamespaceName ns = NamespaceName.get(namespace); WebTarget path = namespacePath(ns, "offloadDeletionLagMs"); request(path).delete(ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
protected void validateTopicName(String property, String namespace, String encodedTopic) { String topic = Codec.decode(encodedTopic); try { this.namespaceName = NamespaceName.get(property, namespace); this.topicName = TopicName.get(domain(), namespaceName, topic); } catch (IllegalArgumentException e) { log.warn("[{}] Failed to validate topic name {}://{}/{}/{}", clientAppId(), domain(), property, namespace, topic, e); throw new RestException(Status.PRECONDITION_FAILED, "Topic name is not valid"); } this.topicName = TopicName.get(domain(), namespaceName, topic); }