jerrypeng commented on a change in pull request #11643:
URL: https://github.com/apache/pulsar/pull/11643#discussion_r687390833



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupService.java
##########
@@ -233,66 +235,80 @@ public void unRegisterTenant(String resourceGroupName, 
String tenantName) throws
      * Registers a namespace as a user of a resource group.
      *
      * @param resourceGroupName
-     * @param namespaceName
+     * @param fqNamespaceName (i.e., in "tenant/Namespace" format)
      * @throws if the RG does not exist, or if the NS already references the 
RG.
      */
-    public void registerNameSpace(String resourceGroupName, String 
namespaceName) throws PulsarAdminException {
+    public void registerNameSpace(String resourceGroupName, String 
fqNamespaceName) throws PulsarAdminException {
+        // Since it is a fully qualified NS, we expect a '/' in it.
+        String[] parts = fqNamespaceName.split("/");
+        if (parts.length < 2) {
+            String errMesg = "Fully-qualified namespace " + fqNamespaceName + 
" does not have a topic in it";
+            throw new PulsarAdminException(errMesg);
+        }
+
         ResourceGroup rg = checkResourceGroupExists(resourceGroupName);
 
         // Check that the NS-name doesn't already have a RG association.
         // [If it does, that should be unregistered before putting a different 
association.]
-        ResourceGroup oldRG = this.namespaceToRGsMap.get(namespaceName);
+        ResourceGroup oldRG = this.namespaceToRGsMap.get(fqNamespaceName);
         if (oldRG != null) {
-            String errMesg = "Namespace " + namespaceName + " already 
references a resource group: " + oldRG.getID();
+            String errMesg = "Namespace " + fqNamespaceName + " already 
references a resource group: " + oldRG.getID();
             throw new PulsarAdminException(errMesg);
         }
 
-        ResourceGroupOpStatus status = rg.registerUsage(namespaceName, 
ResourceGroupRefTypes.Namespaces, true,
+        ResourceGroupOpStatus status = rg.registerUsage(fqNamespaceName, 
ResourceGroupRefTypes.Namespaces, true,
                                                         
this.resourceUsageTransportManagerMgr);
         if (status == ResourceGroupOpStatus.Exists) {
             String errMesg = String.format("Namespace {} already references 
the target resource group {}",
-                    namespaceName, resourceGroupName);
+                    fqNamespaceName, resourceGroupName);
             throw new PulsarAdminException(errMesg);
         }
 
         // Associate this NS-name with the RG.
-        this.namespaceToRGsMap.put(namespaceName, rg);
+        this.namespaceToRGsMap.put(fqNamespaceName, rg);
         rgNamespaceRegisters.labels(resourceGroupName).inc();
     }
 
-    /**
-     * Return the resource group associated with a namespace.
-     *
-     * @param namespaceName
-     * @throws if the RG does not exist, or if the NS already references the 
RG.
-     */
-    public ResourceGroup getNamespaceResourceGroup(String namespaceName) {
-        return this.namespaceToRGsMap.get(namespaceName);
-    }
-
     /**
      * UnRegisters a namespace from a resource group.
      *
      * @param resourceGroupName
-     * @param namespaceName
+     * @param fqNamespaceName i.e., in "tenant/Namespace" format)
      * @throws if the RG does not exist, or if the NS does not references the 
RG yet.
      */
-    public void unRegisterNameSpace(String resourceGroupName, String 
namespaceName) throws PulsarAdminException {
+    public void unRegisterNameSpace(String resourceGroupName, String 
fqNamespaceName) throws PulsarAdminException {
+        // Since it is a fully qualified NS, we expect a '/' in it.
+        String[] parts = fqNamespaceName.split("/");

Review comment:
       same here




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to