I think random wording here is misleading. AFAIU last mail you are using the tenant id of the user to do this right. So that's not random right?
Thanks & Regards Danushka Fernando Senior Software Engineer WSO2 inc. http://wso2.com/ Mobile : +94716332729 On Tue, Aug 16, 2016 at 5:04 PM, Maheeka Jayasuriya <[email protected]> wrote: > Hi Sanjiva, > > We tested to verify that any random TenantID can be given when calling the > addTenant method of the TenantMgtAdminService. In the Integration Cloud, we > are getting the TenantID and the TenantDomain of the logged in cloud user > and setting those as environment variables in the docker file. These > environment variables are then read by the OSGI component and used as > parameters when invoking addTenant method. > > We have tested this approach with the modified docker file and the Tenant > Initializer OSGI component with ESB Analytics locally. Statistics are > published correctly and can be viewed in the Analytics Dashboard for the > particular tenant. > > Thanks, > Maheeka > > Maheeka Jayasuriya > Senior Software Engineer > Mobile : +94777750661 > > On Tue, Aug 16, 2016 at 7:04 AM, Sanjiva Weerawarana <[email protected]> > wrote: > >> Guys how can a random tenant ID work? Isn't it necessary to use the same >> tenant name that the user belongs to? Otherwise how will the data go into >> the right space across all the artifacts (e.g. ESB things, APIs, ..) that >> the user may have in the cloud? >> >> On Thu, Aug 11, 2016 at 11:43 AM, Maheeka Jayasuriya <[email protected]> >> wrote: >> >>> Hi Kishanthan, >>> >>> Yes I tested by providing a random TenantID which were not available in >>> the ESB pack earlier (screenshot attached). We are building the docker >>> image from a vanilla ESB pack and hence there won't be any other tenants in >>> the pack. >>> >>> >>> Screen Shot 2016-08-11 at 11.42.29 AM.png >>> <https://drive.google.com/a/wso2.com/file/d/0B_Ml_gi-3jYrbHpobXM3NFhsQlk/view?usp=drive_web> >>> >>> >>> Thanks, >>> Maheeka >>> >>> Maheeka Jayasuriya >>> Senior Software Engineer >>> Mobile : +94777750661 >>> >>> On Thu, Aug 11, 2016 at 11:36 AM, Kishanthan Thangarajah < >>> [email protected]> wrote: >>> >>>> No, I may be wrong. This approach will work if the given tenant-id is >>>> not taken already at the table level. >>>> >>>> On Thu, Aug 11, 2016 at 11:32 AM, Kishanthan Thangarajah < >>>> [email protected]> wrote: >>>> >>>>> >>>>> >>>>> On Thu, Aug 11, 2016 at 7:56 AM, Maheeka Jayasuriya <[email protected]> >>>>> wrote: >>>>> >>>>>> Hi Devs, >>>>>> >>>>>> >>>>>> We need to start an ESB in a docker container, with a capp deployed >>>>>> in tenant space. So in order to have the tenant space already created and >>>>>> to get the tenant initialized when the container is serving requests, we >>>>>> have tried out the following approach manually which works. >>>>>> >>>>>> >>>>>> 1. >>>>>> >>>>>> Have the capp copied to [ESB_HOME]/repository/tenants/[tenantId]/ >>>>>> when building the docker image. This tenantId may not be incremental >>>>>> and >>>>>> could be any number >>>>>> 2. >>>>>> >>>>>> Run the docker and wait for ESB to start >>>>>> 3. >>>>>> >>>>>> Invoke the TenantMgtAdminService’s addTenant method specifying >>>>>> the ‘tenantId’ and other tenant details (username, password, etc) >>>>>> 4. >>>>>> >>>>>> Invoke an API that is available in the copied capp (1) to >>>>>> initialize the tenant >>>>>> >>>>>> >>>>>> Basically, we need to have the tenant space created during ESB server >>>>>> startup. Tenant could be initialized later for the first request. >>>>>> Therefore >>>>>> we started writing an OSGI declarative component which waits for >>>>>> TenantMgtServiceComponent and calls the TenantMgtAdminService to create >>>>>> the >>>>>> tenant. The capps will be already copied to the tenant space when >>>>>> building >>>>>> the docker image. Following is what we have tried so far. >>>>>> >>>>>> >>>>>> 1. >>>>>> >>>>>> When trying to write a new OSGI component, say >>>>>> TenantInitializerComponent, we wanted to add a >>>>>> TenantMgtServiceComponent >>>>>> registered OSGI service as dependency. But there were no OSGI services >>>>>> available in either of any tenant management components. Due to this >>>>>> we >>>>>> were not able to get the TenantInitializerComponent activated. >>>>>> 2. >>>>>> >>>>>> Since there were no OSGI services of TenantMgtServiceComponent >>>>>> available, we tried by adding the dependencies of >>>>>> TenantMgtServiceComponent >>>>>> to TenantInitializerComponent as below. >>>>>> >>>>>> * @scr.reference name="org.wso2.carbon.tenant.mgt.listener.service" >>>>>> >>>>>> * interface="org.wso2.carbon.stratos.common.lis >>>>>> teners.TenantMgtListener" >>>>>> >>>>>> * cardinality="1..n" policy="dynamic" >>>>>> >>>>>> * bind="setTenantMgtListenerService" >>>>>> >>>>>> * unbind="unsetTenantMgtListenerService" >>>>>> >>>>>> * @scr.reference name="default.tenant.billing.service" >>>>>> >>>>>> * interface="org.wso2.carbon.stratos.common.Ten >>>>>> antBillingService" >>>>>> >>>>>> * cardinality="0..1" policy="dynamic" >>>>>> >>>>>> * bind="setTenantBillingService" >>>>>> >>>>>> * unbind="unsetTenantBillingService" >>>>>> >>>>>> TenantMgtListener is available in ESB and therefore set the >>>>>> cardinality to 1..n. TenantBillingService is not available in ESB and >>>>>> hence >>>>>> cardinality is 0..1. >>>>>> >>>>>> Following is the implementation in the TenantInitializerComponent’s >>>>>> activate method. >>>>>> >>>>>> TenantMgtAdminService tenantMgtAdminService = new >>>>>> TenantMgtAdminService(); >>>>>> >>>>>> TenantInfoBean tenantInfoBean = new TenantInfoBean(); >>>>>> >>>>>> tenantInfoBean.setActive(true); >>>>>> >>>>>> tenantInfoBean.setAdmin("admin"); >>>>>> >>>>>> tenantInfoBean.setAdminPassword("admin123"); >>>>>> >>>>>> tenantInfoBean.setFirstname("Maheeka"); >>>>>> >>>>>> tenantInfoBean.setLastname("Maheeka"); >>>>>> >>>>>> tenantInfoBean.setEmail("[email protected]"); >>>>>> >>>>>> tenantInfoBean.setTenantDomain("maheeka.com"); >>>>>> >>>>>> tenantInfoBean.setSuccessKey(""); >>>>>> >>>>>> tenantInfoBean.setTenantId(250); >>>>>> >>>>> >>>>> This may not work because, the tenant id is generated and returned by >>>>> the tenant persister once a new tenant is persisted properly in DB. The >>>>> tenant id is basically the row id in the table. >>>>> >>>>> Did you test this? >>>>> >>>>> >>>>> tenantInfoBean.setUsagePlan("Demo"); >>>>>> >>>>>> try { >>>>>> >>>>>> tenantMgtAdminService.addTenant(tenantInfoBean); >>>>>> >>>>>> log.info("Tenant added successfully"); >>>>>> >>>>>> } catch (Exception e) { >>>>>> >>>>>> log.error(“Error adding tenant", e); >>>>>> >>>>>> } >>>>>> >>>>>> >>>>>> However, “tenantMgtAdminService.addTenant(tenantInfoBean)” will >>>>>> invoke TenantMgtServiceComponent which is not activated by this time >>>>>> and thus throws a NPE. >>>>>> >>>>>> >>>>>> 1. >>>>>> >>>>>> Next thing we tried was using the ServerStartupObserver as >>>>>> dependency to TenantInitializerComponent. However even this time >>>>>> TenantMgtServiceComponent is not activated by the time >>>>>> TenantInitializerComponent tries to activate. According to [1], seems >>>>>> like >>>>>> ServerStartupObserver only waits till the transports are started. >>>>>> 2. >>>>>> >>>>>> If we write a BundleListener [3], we could wait for the >>>>>> TenantMgtServiceComponent to be active and perform addTenant. Since >>>>>> this >>>>>> captures all bundle statuses this might not be an effective approach. >>>>>> 3. >>>>>> >>>>>> Finally, took a look at StartupFinalizerServiceComponent. This >>>>>> seems to register a service after all the components are initialized >>>>>> as >>>>>> org.apache.axis2.engine.ListenerManager. I was able to >>>>>> successfully create the tenant by adding a reference to this service >>>>>> as >>>>>> below. >>>>>> >>>>>> * @scr.reference name="listener.manager" >>>>>> >>>>>> * interface="org.apache.axis2.engin >>>>>> e.ListenerManager" >>>>>> >>>>>> * cardinality="1..1" policy="dynamic" >>>>>> >>>>>> * bind="setListenerManager" >>>>>> >>>>>> * unbind="unsetListenerManager" >>>>>> >>>>>> >>>>>> Adding reference to org.apache.axis2.engine.ListenerManager seems to >>>>>> solve the problem. However, need to verify whether there are any other >>>>>> better ways to solve this problem. Or shall we proceed with this >>>>>> approach? >>>>>> Appreciate your feedback on this. >>>>>> >>>>>> >>>>>> Thanks Kalpa and Jayanga for helping out on the details. >>>>>> >>>>>> [1] https://docs.wso2.com/display/Carbon447/Server+Startup+Observer >>>>>> >>>>>> [2] https://github.com/wso2/carbon-kernel/blob/4.4.x/core/org.ws >>>>>> o2.carbon.core/src/main/java/org/wso2/carbon/core/internal/S >>>>>> tartupFinalizerServiceComponent.java#L199 >>>>>> >>>>>> [3] http://eclipsesource.com/blogs/2013/01/23/how-to-track-lifec >>>>>> ycle-changes-of-osgi-bundles/ >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Maheeka Jayasuriya >>>>>> Senior Software Engineer >>>>>> Mobile : +94777750661 >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> *Kishanthan Thangarajah* >>>>> Technical Lead, >>>>> Platform Technologies Team, >>>>> WSO2, Inc. >>>>> lean.enterprise.middleware >>>>> >>>>> Mobile - +94773426635 >>>>> Blog - *http://kishanthan.wordpress.com >>>>> <http://kishanthan.wordpress.com>* >>>>> Twitter - *http://twitter.com/kishanthan >>>>> <http://twitter.com/kishanthan>* >>>>> >>>> >>>> >>>> >>>> -- >>>> *Kishanthan Thangarajah* >>>> Technical Lead, >>>> Platform Technologies Team, >>>> WSO2, Inc. >>>> lean.enterprise.middleware >>>> >>>> Mobile - +94773426635 >>>> Blog - *http://kishanthan.wordpress.com >>>> <http://kishanthan.wordpress.com>* >>>> Twitter - *http://twitter.com/kishanthan >>>> <http://twitter.com/kishanthan>* >>>> >>> >>> >>> _______________________________________________ >>> Dev mailing list >>> [email protected] >>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>> >>> >> >> >> -- >> Sanjiva Weerawarana, Ph.D. >> Founder, CEO & Chief Architect; WSO2, Inc.; http://wso2.com/ >> email: [email protected]; office: (+1 650 745 4499 | +94 11 214 5345) >> x5700; cell: +94 77 787 6880 | +1 408 466 5099; voip: +1 650 265 8311 >> blog: http://sanjiva.weerawarana.org/; twitter: @sanjiva >> Lean . Enterprise . Middleware >> > > > _______________________________________________ > Dev mailing list > [email protected] > http://wso2.org/cgi-bin/mailman/listinfo/dev > >
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
