CacheManagerFactory expects upstream code to have created a proper
CarbonContext & populated it. Don't change any code there.

Azeez


On Mon, Aug 5, 2013 at 9:46 AM, Kasun Gajasinghe <[email protected]> wrote:

>
> Yes. I've already seen few places that only sets the tenant id after
> starting a tenant flow. These fail most of the time since these hit the
> CacheManagerFactory which throws a NPE in case the tenant domain is not
> set. For example, retrieving the registry etc.
>
> And, the deriving of the tenant domain is cached operation as I see. If
> it's available in the cache, then it's a simple Map.get. Further, if the
> tenant domain is already set, CC doesn't try to derive the tenant domain
> every time. So, wouldn't it make sense to modify CacheManagerFactory to try
> to derive the tenant domain in case it's not available?
>
> Thanks,
> KasunG
>
>
>
> On Mon, Aug 5, 2013 at 1:50 AM, Afkham Azeez <[email protected]> wrote:
>
>> Always deriving one from the other is expensive, so we expect both ID &
>> domain to be set as much as possible wherever both are available
>>
>> --
>> Afkham Azeez
>> Sent from my phone
>> On Aug 5, 2013 12:09 AM, "Kasun Gajasinghe" <[email protected]> wrote:
>>
>>> Seems the tenant domain resolving should happen in CarbonContext. The
>>> CacheManagerFactory simply do a
>>> CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
>>>
>>>
>>> On Sun, Aug 4, 2013 at 11:31 PM, Kasun Gajasinghe <[email protected]>wrote:
>>>
>>>> Hi,
>>>>
>>>> If tenant domain is not set, we can derive it via tenant id, right? But
>>>> the method getCacheManager in CacheManagerFactoryImpl [1] do not do this,
>>>> and therefore fails with a NPE. Following error was observed when a
>>>> datasource addition triggered a cluster notification, and the worker node
>>>> tried to process it. Only the tenant id is set in the cluster message.
>>>>
>>>> [1] org.wso2.carbon.caching.impl.CacheManagerFactoryImpl#getCacheManager
>>>>
>>>>
>>>> [2013-08-04 23:15:36,947] ERROR
>>>> {org.wso2.carbon.core.clustering.hazelcast.HazelcastClusterMessageListener}
>>>> -  Cannot process ClusteringMessage
>>>> org.apache.axis2.clustering.ClusteringFault: Error in handling data
>>>> source stat message: Error in updating data source 'test' from registry
>>>> [remove:false]: Tenant domain has not been set in CarbonContext
>>>>  at
>>>> org.wso2.carbon.ndatasource.core.DataSourceStatMessage.execute(DataSourceStatMessage.java:74)
>>>> at
>>>> org.wso2.carbon.core.clustering.hazelcast.HazelcastClusterMessageListener.onMessage(HazelcastClusterMessageListener.java:54)
>>>>  at
>>>> com.hazelcast.impl.ListenerManager.callListener(ListenerManager.java:419)
>>>> at
>>>> com.hazelcast.impl.ListenerManager.callListeners(ListenerManager.java:334)
>>>>  at com.hazelcast.impl.BaseManager$2.run(BaseManager.java:1392)
>>>> at
>>>> com.hazelcast.impl.executor.ParallelExecutorService$ParallelExecutorImpl$ExecutionSegment.run(ParallelExecutorService.java:212)
>>>>  at
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>>>> at
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>>>>  at java.lang.Thread.run(Thread.java:662)
>>>> at
>>>> com.hazelcast.impl.ExecutorThreadFactory$1.run(ExecutorThreadFactory.java:45)
>>>> Caused by: org.wso2.carbon.ndatasource.common.DataSourceException:
>>>> Error in updating data source 'test' from registry [remove:false]: Tenant
>>>> domain has not been set in CarbonContext
>>>> at
>>>> org.wso2.carbon.ndatasource.core.DataSourceRepository.updateDataSource(DataSourceRepository.java:186)
>>>>  at
>>>> org.wso2.carbon.ndatasource.core.DataSourceRepository.refreshUserDataSource(DataSourceRepository.java:157)
>>>> at
>>>> org.wso2.carbon.ndatasource.core.DataSourceStatMessage.execute(DataSourceStatMessage.java:71)
>>>>  ... 9 more
>>>> *Caused by: java.lang.NullPointerException: Tenant domain has not been
>>>> set in CarbonContext*
>>>> * at
>>>> org.wso2.carbon.caching.impl.CacheManagerFactoryImpl.getCacheManager(CacheManagerFactoryImpl.java:79)
>>>> *
>>>>  at
>>>> org.wso2.carbon.registry.core.utils.RegistryUtils.getCacheManager(RegistryUtils.java:289)
>>>> at
>>>> org.wso2.carbon.registry.core.utils.RegistryUtils.getResourceCache(RegistryUtils.java:272)
>>>>  at
>>>> org.wso2.carbon.registry.core.caching.CacheBackedRegistry.getCache(CacheBackedRegistry.java:62)
>>>> at
>>>> org.wso2.carbon.registry.core.caching.CacheBackedRegistry.resourceExists(CacheBackedRegistry.java:246)
>>>>  at
>>>> org.wso2.carbon.registry.core.session.UserRegistry.resourceExists(UserRegistry.java:629)
>>>> at
>>>> org.wso2.carbon.ndatasource.core.DataSourceRepository.getDataSourceMetaInfoFromRegistryPath(DataSourceRepository.java:409)
>>>>  at
>>>> org.wso2.carbon.ndatasource.core.DataSourceRepository.updateDataSource(DataSourceRepository.java:164)
>>>> ... 11 more
>>>>
>>>>
>>>> --
>>>> *Kasun Gajasinghe*
>>>> Software Engineer;
>>>> Development Technologies Team, WSO2 Inc.; http://wso2.com
>>>>
>>>>
>>>>  ,
>>>> *email: **kasung AT spamfree wso2.com
>>>>
>>>>
>>>> ** cell: **+94 (77) 678-0813*
>>>> *linked-in: *http://lk.linkedin.com/in/gajasinghe
>>>>
>>>>
>>>> *
>>>> *
>>>> *blog: **http://kasunbg.org* <http://kasunbg.org>
>>>>
>>>>
>>>> *
>>>> twitter: **http://twitter.com/kasunbg* <http://twitter.com/kasunbg>
>>>>
>>>>
>>>> *
>>>> *
>>>>
>>>
>>>
>>>
>>> --
>>> *Kasun Gajasinghe*
>>> Software Engineer;
>>> Development Technologies Team, WSO2 Inc.; http://wso2.com
>>>
>>>
>>>  ,
>>> *email: **kasung AT spamfree wso2.com
>>>
>>>
>>> ** cell: **+94 (77) 678-0813*
>>> *linked-in: *http://lk.linkedin.com/in/gajasinghe
>>>
>>>
>>> *
>>> *
>>> *blog: **http://kasunbg.org* <http://kasunbg.org>
>>>
>>>
>>> *
>>> twitter: **http://twitter.com/kasunbg* <http://twitter.com/kasunbg>
>>>
>>>
>>> *
>>> *
>>>
>>
>
>
> --
> *Kasun Gajasinghe*
> Software Engineer;
> Development Technologies Team, WSO2 Inc.; http://wso2.com
>
>
>  ,
> *email: **kasung AT spamfree wso2.com
>
>
> ** cell: **+94 (77) 678-0813*
> *linked-in: *http://lk.linkedin.com/in/gajasinghe
>
>
> *
> *
> *blog: **http://kasunbg.org* <http://kasunbg.org>
>
>
> *
> twitter: **http://twitter.com/kasunbg* <http://twitter.com/kasunbg>
>
>
> *
> *
>



-- 
*Afkham Azeez*
Director of Architecture; WSO2, Inc.; http://wso2.com
Member; Apache Software Foundation; http://www.apache.org/
* <http://www.apache.org/>**
email: **[email protected]* <[email protected]>* cell: +94 77 3320919
blog: **http://blog.afkham.org* <http://blog.afkham.org>*
twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez>
*
linked-in: **http://lk.linkedin.com/in/afkhamazeez*
*
*
*Lean . Enterprise . Middleware*
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to