Re: [Dev] Writing an OSGI Component to Create a Tenant during ESB Startup

2016-08-16 Thread Danushka Fernando
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 
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 : +9450661
>
> On Tue, Aug 16, 2016 at 7:04 AM, Sanjiva Weerawarana 
> 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 
>> 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
>>> 
>>> ​
>>>
>>> Thanks,
>>> Maheeka
>>>
>>> Maheeka Jayasuriya
>>> Senior Software Engineer
>>> Mobile : +9450661
>>>
>>> On Thu, Aug 11, 2016 at 11:36 AM, Kishanthan Thangarajah <
>>> kishant...@wso2.com> 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 <
 kishant...@wso2.com> wrote:

>
>
> On Thu, Aug 11, 2016 at 7:56 AM, Maheeka Jayasuriya 
> 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"
>>
>> *

Re: [Dev] Writing an OSGI Component to Create a Tenant during ESB Startup

2016-08-16 Thread Maheeka Jayasuriya
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 : +9450661

On Tue, Aug 16, 2016 at 7:04 AM, Sanjiva Weerawarana 
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 
> 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
>> 
>> ​
>>
>> Thanks,
>> Maheeka
>>
>> Maheeka Jayasuriya
>> Senior Software Engineer
>> Mobile : +9450661
>>
>> On Thu, Aug 11, 2016 at 11:36 AM, Kishanthan Thangarajah <
>> kishant...@wso2.com> 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 <
>>> kishant...@wso2.com> wrote:
>>>


 On Thu, Aug 11, 2016 at 7:56 AM, Maheeka Jayasuriya 
 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 

Re: [Dev] Writing an OSGI Component to Create a Tenant during ESB Startup

2016-08-15 Thread Sanjiva Weerawarana
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 
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
> 
> ​
>
> Thanks,
> Maheeka
>
> Maheeka Jayasuriya
> Senior Software Engineer
> Mobile : +9450661
>
> On Thu, Aug 11, 2016 at 11:36 AM, Kishanthan Thangarajah <
> kishant...@wso2.com> 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 <
>> kishant...@wso2.com> wrote:
>>
>>>
>>>
>>> On Thu, Aug 11, 2016 at 7:56 AM, Maheeka Jayasuriya 
>>> 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("ad...@maheeka.com");

 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 

Re: [Dev] Writing an OSGI Component to Create a Tenant during ESB Startup

2016-08-11 Thread Kishanthan Thangarajah
Okey great.

On Thu, Aug 11, 2016 at 11:43 AM, Maheeka Jayasuriya 
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
> 
> ​
>
> Thanks,
> Maheeka
>
> Maheeka Jayasuriya
> Senior Software Engineer
> Mobile : +9450661
>
> On Thu, Aug 11, 2016 at 11:36 AM, Kishanthan Thangarajah <
> kishant...@wso2.com> 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 <
>> kishant...@wso2.com> wrote:
>>
>>>
>>>
>>> On Thu, Aug 11, 2016 at 7:56 AM, Maheeka Jayasuriya 
>>> 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("ad...@maheeka.com");

 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) {

   

Re: [Dev] Writing an OSGI Component to Create a Tenant during ESB Startup

2016-08-11 Thread Maheeka Jayasuriya
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

​

Thanks,
Maheeka

Maheeka Jayasuriya
Senior Software Engineer
Mobile : +9450661

On Thu, Aug 11, 2016 at 11:36 AM, Kishanthan Thangarajah <
kishant...@wso2.com> 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 <
> kishant...@wso2.com> wrote:
>
>>
>>
>> On Thu, Aug 11, 2016 at 7:56 AM, Maheeka Jayasuriya 
>> 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("ad...@maheeka.com");
>>>
>>> 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 

Re: [Dev] Writing an OSGI Component to Create a Tenant during ESB Startup

2016-08-11 Thread Kishanthan Thangarajah
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 <
kishant...@wso2.com> wrote:

>
>
> On Thu, Aug 11, 2016 at 7:56 AM, Maheeka Jayasuriya 
> 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("ad...@maheeka.com");
>>
>> 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 

Re: [Dev] Writing an OSGI Component to Create a Tenant during ESB Startup

2016-08-11 Thread Kishanthan Thangarajah
On Thu, Aug 11, 2016 at 7:56 AM, Maheeka Jayasuriya 
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.
> listeners.TenantMgtListener"
>
> *cardinality="1..n" policy="dynamic"
>
> *bind="setTenantMgtListenerService"
>
> *unbind="unsetTenantMgtListenerService"
>
> * @scr.reference name="default.tenant.billing.service"
>
> *interface="org.wso2.carbon.stratos.common.
> TenantBillingService"
>
> *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("ad...@maheeka.com");
>
> 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.
> engine.ListenerManager"
>
> *cardinality="1..1" policy="dynamic"
>

Re: [Dev] Writing an OSGI Component to Create a Tenant during ESB Startup

2016-08-10 Thread Maheeka Jayasuriya
+ Dmitry

Maheeka Jayasuriya
Senior Software Engineer
Mobile : +9450661

On Thu, Aug 11, 2016 at 7:56 AM, Maheeka Jayasuriya 
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.
> listeners.TenantMgtListener"
>
> *cardinality="1..n" policy="dynamic"
>
> *bind="setTenantMgtListenerService"
>
> *unbind="unsetTenantMgtListenerService"
>
> * @scr.reference name="default.tenant.billing.service"
>
> *interface="org.wso2.carbon.stratos.common.
> TenantBillingService"
>
> *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("ad...@maheeka.com");
>
> tenantInfoBean.setTenantDomain("maheeka.com");
>
> tenantInfoBean.setSuccessKey("");
>
> tenantInfoBean.setTenantId(250);
>
> 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.
> engine.ListenerManager"
>
> *cardinality="1..1" policy="dynamic"
>
> *bind="setListenerManager"
>
> *unbind="unsetListenerManager"
>
>
> Adding 

[Dev] Writing an OSGI Component to Create a Tenant during ESB Startup

2016-08-10 Thread Maheeka Jayasuriya
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.listeners.TenantMgtListener"

*cardinality="1..n" policy="dynamic"

*bind="setTenantMgtListenerService"

*unbind="unsetTenantMgtListenerService"

* @scr.reference name="default.tenant.billing.service"

*
   interface="org.wso2.carbon.stratos.common.TenantBillingService"

*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("ad...@maheeka.com");

tenantInfoBean.setTenantDomain("maheeka.com");

tenantInfoBean.setSuccessKey("");

tenantInfoBean.setTenantId(250);

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.engine.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]