public static final String path(NamespaceBundle suname) { // The ephemeral node path for new namespaces should always have bundle name appended return OWNER_INFO_ROOT + "/" + suname.toString(); }
/** * Get resource quota for a specified service unit. * * @param suName * identifier of the <code>ServiceUnit</code> * * @return the <code>ResourceQuota</code>. */ public ResourceQuota getQuota(NamespaceBundle suName) { String suNameStr = (suName == null) ? null : suName.toString(); return this.getQuota(suNameStr); }
/** * Set resource quota for a specified <code>ServiceUnit</code>. * * @param suName * identifier of the <code>ServiceUnit</code> * @param quota * <code>ResourceQuota</code> to set. */ public void setQuota(NamespaceBundle suName, ResourceQuota quota) throws Exception { String suNameStr = (suName == null) ? null : suName.toString(); this.setQuota(suNameStr, quota); }
/** * Remove resource quota for a specified <code>ServiceUnit</code> to use the default quota. * * @param suName * identifier of the <code>ServiceUnit</code> */ public void unsetQuota(NamespaceBundle suName) throws Exception { String suNameStr = (suName == null) ? null : suName.toString(); this.unsetQuota(suNameStr); } }
public Map<String, NamespaceOwnershipStatus> getOwnedNameSpacesStatus() throws Exception { NamespaceIsolationPolicies nsIsolationPolicies = this.getLocalNamespaceIsolationPolicies(); Map<String, NamespaceOwnershipStatus> ownedNsStatus = new HashMap<String, NamespaceOwnershipStatus>(); for (OwnedBundle nsObj : this.ownershipCache.getOwnedBundles().values()) { NamespaceOwnershipStatus nsStatus = this.getNamespaceOwnershipStatus(nsObj, nsIsolationPolicies.getPolicyByNamespace(nsObj.getNamespaceBundle().getNamespaceObject())); ownedNsStatus.put(nsObj.getNamespaceBundle().toString(), nsStatus); } return ownedNsStatus; }
public void refreshTopicToStatsMaps(NamespaceBundle oldBundle) { checkNotNull(oldBundle); try { // retrieve all topics under existing old bundle List<PersistentTopic> topics = getAllTopicsFromNamespaceBundle(oldBundle.getNamespaceObject().toString(), oldBundle.toString()); if (!isEmpty(topics)) { // add topic under new split bundles which already updated into NamespaceBundleFactory.bundleCache topics.stream().forEach(t -> { addTopicToStatsMaps(DestinationName.get(t.getName()), t); }); // remove old bundle from the map synchronized (multiLayerTopicsMap) { multiLayerTopicsMap.get(oldBundle.getNamespaceObject().toString()).remove(oldBundle.toString()); } } } catch (Exception e) { log.warn("Got exception while refreshing topicStats map", e); } }
@GET @Path("/{property}/{cluster}/{namespace}/{bundle}") @ApiOperation(value = "Get resource quota of a namespace bundle.") @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") }) public ResourceQuota getNamespaceBundleResourceQuota(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange) { validateSuperUserAccess(); Policies policies = getNamespacePolicies(property, cluster, namespace); if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) { validateClusterOwnership(cluster); validateClusterForProperty(property, cluster); } NamespaceName fqnn = new NamespaceName(property, cluster, namespace); NamespaceBundle nsBundle = validateNamespaceBundleRange(fqnn, policies.bundles, bundleRange); try { return pulsar().getLocalZkCacheService().getResourceQuotaCache().getQuota(nsBundle); } catch (Exception e) { log.error("[{}] Failed to get resource quota for namespace bundle {}", clientAppId(), nsBundle.toString()); throw new RestException(e); } }
@POST @Path("/{property}/{cluster}/{namespace}/{bundle}") @ApiOperation(value = "Set resource quota on a namespace.") @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 409, message = "Concurrent modification") }) public void setNamespaceBundleResourceQuota(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, ResourceQuota quota) { validateSuperUserAccess(); validatePoliciesReadOnlyAccess(); Policies policies = getNamespacePolicies(property, cluster, namespace); if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) { validateClusterOwnership(cluster); validateClusterForProperty(property, cluster); } NamespaceName fqnn = new NamespaceName(property, cluster, namespace); NamespaceBundle nsBundle = validateNamespaceBundleRange(fqnn, policies.bundles, bundleRange); try { pulsar().getLocalZkCacheService().getResourceQuotaCache().setQuota(nsBundle, quota); log.info("[{}] Successfully set resource quota for namespace bundle {}", clientAppId(), nsBundle.toString()); } catch (KeeperException.NoNodeException e) { log.warn("[{}] Failed to set resource quota for namespace bundle {}: concurrent modification", clientAppId(), nsBundle.toString()); throw new RestException(Status.CONFLICT, "Cuncurrent modification on namespace bundle quota"); } catch (Exception e) { log.error("[{}] Failed to set resource quota for namespace bundle {}", clientAppId(), nsBundle.toString()); throw new RestException(e); } }
} catch (Exception e) { LOG.error("Failed to close topics under namespace {}", bundle.toString(), e); throw new RuntimeException(String.format("Failed to delete ownership node %s", bundle.toString()), e.getCause()); LOG.error("Failed to unload a namespace {}", bundle.toString(), e); throw new RuntimeException(e);
pulsar().getLocalZkCacheService().getResourceQuotaCache().unsetQuota(nsBundle); log.info("[{}] Successfully unset resource quota for namespace bundle {}", clientAppId(), nsBundle.toString()); } catch (KeeperException.NoNodeException e) { log.warn("[{}] Failed to unset resource quota for namespace bundle {}: concurrent modification", clientAppId(), nsBundle.toString()); throw new RestException(Status.CONFLICT, "Cuncurrent modification on namespace bundle quota"); } catch (Exception e) { log.error("[{}] Failed to unset resource quota for namespace bundle {}", clientAppId(), nsBundle.toString()); throw new RestException(e);
@PUT @Path("/{property}/{cluster}/{namespace}/{bundle}/split") @ApiOperation(value = "Split a namespace bundle") @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") }) public void splitNamespaceBundle(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) { log.info("[{}] Split namespace bundle {}/{}/{}/{}", clientAppId(), property, cluster, namespace, bundleRange); validateSuperUserAccess(); Policies policies = getNamespacePolicies(property, cluster, namespace); if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) { validateClusterOwnership(cluster); validateClusterForProperty(property, cluster); } NamespaceName fqnn = new NamespaceName(property, cluster, namespace); validatePoliciesReadOnlyAccess(); NamespaceBundle nsBundle = validateNamespaceBundleOwnership(fqnn, policies.bundles, bundleRange, authoritative, true); try { pulsar().getNamespaceService().splitAndOwnBundle(nsBundle).get(); log.info("[{}] Successfully split namespace bundle {}", clientAppId(), nsBundle.toString()); } catch (Exception e) { log.error("[{}] Failed to split namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e); throw new RestException(e); } }
@PUT @Path("/{property}/{cluster}/{namespace}/{bundle}/unload") @ApiOperation(value = "Unload a namespace bundle") @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") }) public void unloadNamespaceBundle(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) { log.info("[{}] Unloading namespace bundle {}/{}/{}/{}", clientAppId(), property, cluster, namespace, bundleRange); validateSuperUserAccess(); Policies policies = getNamespacePolicies(property, cluster, namespace); if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) { validateClusterOwnership(cluster); validateClusterForProperty(property, cluster); } NamespaceName fqnn = new NamespaceName(property, cluster, namespace); validatePoliciesReadOnlyAccess(); NamespaceBundle nsBundle = validateNamespaceBundleOwnership(fqnn, policies.bundles, bundleRange, authoritative, true); try { pulsar().getNamespaceService().unloadNamespaceBundle(nsBundle); log.info("[{}] Successfully unloaded namespace bundle {}", clientAppId(), nsBundle.toString()); } catch (Exception e) { log.error("[{}] Failed to unload namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e); throw new RestException(e); } }
log.warn("Unable to get web service url"); throw new RestException(Status.PRECONDITION_FAILED, "Failed to find ownership for ServiceUnit:" + bundle.toString());
String msg1 = format( "failed to disable bundle %s under namespace [%s] with error %s", nsname.toString(), bundle.toString(), e.getMessage()); LOG.warn(msg1, e); future.completeExceptionally(new ServiceUnitNotReadyException(msg1)); String msg = format("bundle %s not found under namespace", bundle.toString()); future.completeExceptionally(new ServiceUnitNotReadyException(msg));
private void addTopicToStatsMaps(DestinationName topicName, PersistentTopic topic) { try { NamespaceBundle namespaceBundle = pulsar.getNamespaceService().getBundle(topicName); if (namespaceBundle != null) { synchronized (multiLayerTopicsMap) { String serviceUnit = namespaceBundle.toString(); multiLayerTopicsMap // .computeIfAbsent(topicName.getNamespace(), k -> new ConcurrentOpenHashMap<>()) // .computeIfAbsent(serviceUnit, k -> new ConcurrentOpenHashMap<>()) // .put(topicName.toString(), topic); } } invalidateOfflineTopicStatCache(topicName); } catch (Exception e) { log.warn("Got exception when retrieving bundle name during create persistent topic", e); } }
public void removeTopicFromCache(String topic) { try { DestinationName destination = DestinationName.get(topic); NamespaceBundle namespaceBundle = pulsar.getNamespaceService().getBundle(destination); checkArgument(namespaceBundle instanceof NamespaceBundle); String bundleName = namespaceBundle.toString(); String namespaceName = destination.getNamespaceObject().toString(); synchronized (multiLayerTopicsMap) { ConcurrentOpenHashMap<String, ConcurrentOpenHashMap<String, PersistentTopic>> namespaceMap = multiLayerTopicsMap .get(namespaceName); ConcurrentOpenHashMap<String, PersistentTopic> bundleMap = namespaceMap.get(bundleName); bundleMap.remove(topic); if (bundleMap.isEmpty()) { namespaceMap.remove(bundleName); } if (namespaceMap.isEmpty()) { multiLayerTopicsMap.remove(namespaceName); final ClusterReplicationMetrics clusterReplicationMetrics = pulsarStats .getClusterReplicationMetrics(); replicationClients.forEach((cluster, client) -> { clusterReplicationMetrics.remove(clusterReplicationMetrics.getKeyName(namespaceName, cluster)); }); } } } catch (Exception e) { log.warn("Got exception when retrieving bundle name during removeTopicFromCache", e); } topics.remove(topic); }