Hi folks,

While debugging some CC related issue, we figured that the CarbonContext
was not setting the Registry in a tenant aware manner, it was simple
returning the ST registry as follows,

- carbonContextDataHolder.getConfigSystemRegistry();
- carbonContextDataHolder.getConfigUserRegistry();

I have modified it to return the particular tenant's registries. However I
couldn't find appropriate methods to in the registryService to obtain
UserConfig registry and UserGovernance registry, so after a chat with Azeez
we decided to return null instead of returning the ST registry ..

GReg folks, how do we retrieve the tenant specific UserConfig and
UserGovernance registry ?!

Also please review the commit and holler if there are any concerns / issues
..

---------- Forwarded message ----------
From: <sha...@wso2.com>
Date: Wed, Nov 21, 2012 at 11:21 PM
Subject: [Commits] [Carbon-kernel] svn commit r148829 -
carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context
To: comm...@wso2.org


Author: shariq
Date: Wed Nov 21 23:21:17 2012
New Revision: 148829
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=148829

Log:
Set the correct tenant's registry in CarbonContext.


Modified:

 
carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context/CarbonContext.java

Modified:
carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context/CarbonContext.java
URL:
http://wso2.org/svn/browse/wso2/carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context/CarbonContext.java?rev=148829&r1=148828&r2=148829&view=diff
==============================================================================
---
carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context/CarbonContext.java
     (original)
+++
carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context/CarbonContext.java
     Wed Nov 21 23:21:17 2012
@@ -22,10 +22,12 @@
 import net.sf.jsr107cache.CacheManager;
 import org.wso2.carbon.base.CarbonBaseUtils;
 import org.wso2.carbon.context.internal.CarbonContextDataHolder;
+import org.wso2.carbon.context.internal.OSGiDataHolder;
 import org.wso2.carbon.queuing.CarbonQueue;
 import org.wso2.carbon.queuing.CarbonQueueManager;
 import org.wso2.carbon.registry.api.Registry;
 import org.wso2.carbon.user.api.UserRealm;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;

 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -49,6 +51,7 @@
     // cleaner and easy to use API around the CarbonContext holder.

     private CarbonContextDataHolder carbonContextHolder = null;
+    private static OSGiDataHolder dataHolder =
OSGiDataHolder.getInstance();

     /**
      * Creates a CarbonContext using the given CarbonContext holder as its
backing instance.
@@ -127,18 +130,51 @@
      * @return the requested registry instance.
      */
     public Registry getRegistry(RegistryType type) {
+        int tenantId = getTenantId();
         CarbonContextDataHolder carbonContextDataHolder =
getCarbonContextDataHolder();
+        Registry registry;
         switch (type) {
             case USER_CONFIGURATION:
-                return carbonContextDataHolder.getConfigUserRegistry();
+                // No registry service method to obtain user config
registry by tenant id ?!
+                return null;
+                //return carbonContextDataHolder.getConfigUserRegistry();
             case SYSTEM_CONFIGURATION:
-                return carbonContextDataHolder.getConfigSystemRegistry();
+                if (tenantId != MultitenantConstants.INVALID_TENANT_ID) {
+                    try {
+                        registry =
dataHolder.getRegistryService().getConfigSystemRegistry(tenantId);
+                        return null;
+                    } catch (Exception e) {
+                        // If we can't obtain an instance of the registry,
we'll simply return null. The
+                        // errors that lead to this situation will be
logged by the Registry Kernel.
+                    }
+                    return null;
+                }
             case USER_GOVERNANCE:
-                return carbonContextDataHolder.getGovernanceUserRegistry();
+                // No registry service method to obtain user governance
registry by tenant id ?!
+                return null;
+                //return
carbonContextDataHolder.getGovernanceUserRegistry();
             case SYSTEM_GOVERNANCE:
-                return
carbonContextDataHolder.getGovernanceSystemRegistry();
+                if (tenantId != MultitenantConstants.INVALID_TENANT_ID) {
+                    try {
+                        registry =
dataHolder.getRegistryService().getGovernanceSystemRegistry(tenantId);
+                        return registry;
+                    } catch (Exception e) {
+                        // If we can't obtain an instance of the registry,
we'll simply return null. The
+                        // errors that lead to this situation will be
logged by the Registry Kernel.
+                    }
+                    return null;
+                }
             case LOCAL_REPOSITORY:
-                return carbonContextDataHolder.getLocalRepository();
+                if (tenantId != MultitenantConstants.INVALID_TENANT_ID) {
+                    try {
+                        registry =
dataHolder.getRegistryService().getLocalRepository(tenantId);
+                        return registry;
+                    } catch (Exception e) {
+                        // If we can't obtain an instance of the registry,
we'll simply return null. The
+                        // errors that lead to this situation will be
logged by the Registry Kernel.
+                    }
+                    return null;
+                }
             default:
                 return null;
         }
_______________________________________________
Commits mailing list
comm...@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/commits



-- 
Thanks,
Shariq.
Phone: +94 777 202 225
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to