On Wed, Jun 4, 2014 at 9:38 AM, Nipuni Perera <[email protected]> wrote:

> I am using DataHolder.getCarbonTomcatService(); to get CarbonTomcatService
> in the service component to read virtual host names,
>
>                 Container[] virtualhosts =
> carbonTomcatService.getTomcat().getEngine().findChildren();
>

This is fine but it would be better if you could use Tomcat
LifecycleListener to detect adding/ removing new hosts and perform above
tasks.

You can filter interested events as follows.

public void lifecycleEvent(LifecycleEvent event) {

if ((event.getSource() instanceof Host)) {
if (Lifecycle.AFTER_START_EVENT.equals(event.getType())) {

                          //Add new webapp deployer

}

if (Lifecycle.BEFORE_DESTROY_EVENT.equals(event.getType())) {

                       //remove above webapp deployer

}

}

}

Thanks !

>
> Thanks,
> Nipuni
>
>
> On Wed, Jun 4, 2014 at 9:34 AM, Sagara Gunathunga <[email protected]> wrote:
>
>>
>>
>>
>> On Wed, Jun 4, 2014 at 9:07 AM, Nipuni Perera <[email protected]> wrote:
>>
>>> Hi,
>>>
>>> I have attached the patches here. After applying changes to both
>>> carbon4-kernal and carbon-deployment, you can access webapps via virtual
>>> hosts as follows,
>>>
>>>       1.  Modify the /repository/conf/tomcat/catalina-server.xml to
>>> insert new host entries,
>>>
>>>                      <Host name="localhost" unpackWARs="true"
>>> deployOnStartup="false" autoDeploy="false"
>>> appBase="${carbon.home}/repository/deployment/server/lh">
>>>                            ......
>>>                     </Host>
>>>                      <Host name="www.vhost1.com" unpackWARs="true"
>>> deployOnStartup="false" autoDeploy="false"
>>> appBase="${carbon.home}/repository/deployment/server/webapps/">
>>>                            ......
>>>                     </Host>
>>>                      <Host name="www.vhost2.com" unpackWARs="true"
>>> deployOnStartup="false" autoDeploy="false"
>>> appBase="${carbon.home}/repository/deployment/server/vhost/">
>>>                            ......
>>>                     </Host>
>>>
>>
>> How do you identify above vhosts to be added ? reading catalina-server.xml
>> file or through a Tomcat LifecycleListener ?
>>
>> Thanks !
>>
>>
>>>      2. Add webapps to above appBase locations (eg; put "STRATOS_ROOT"
>>> inside lh, put "example.war" to webapps and "jaxrs_basic.war" to vhost)
>>>      3. Start WSO2 AS and you should be able to access the webapps via
>>> following addresses, (I haven't updated the UI yet, so that these webapps
>>> can not be accessed via "Action" column of the application list in
>>> Management console)
>>>
>>>                       http://localhost:9763/STRATOS_ROOT
>>>                       http://www.vhost1.com:9763/example
>>>
>>> http://www.vhost2.com:9763/jaxrs_basic/services/services
>>>
>>> Note: You should add following entries to /etc/hosts initially to access
>>> virtual hosts,
>>>
>>>        <your-ip-address>   <virtual-host-name>
>>>
>>>  according to the above configuration, the entries are,
>>>
>>>        <your-ip-address>   www.vhost1.com
>>>        <your-ip-address>   www.vhost2.com
>>>
>>> Thanks,
>>> Nipuni
>>>
>>>
>>> On Tue, Jun 3, 2014 at 3:14 PM, Sameera Jayasoma <[email protected]>
>>> wrote:
>>>
>>>> Great work. As per the discussion, can you attache the complete diff.
>>>> Changes to the Kernel.
>>>>
>>>>
>>>> On Tue, Jun 3, 2014 at 2:58 PM, Nipuni Perera <[email protected]> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I have implemented the above solution as below.
>>>>>
>>>>>
>>>>>    1. I created an interface Axis2DeployerProvider with a method
>>>>>    getDeployerConfigs inside org.wso2.carbon.utils.deployment.
>>>>>    2. I then created a service inside package
>>>>>    org.wso2.carbon.webapp.deployer.internal implementing the above 
>>>>> interface.
>>>>>    I also registered the service as an OSGi service inside its activate()
>>>>>    method. I implemented the logic to read  virtualhosts and their appBase
>>>>>    values and list them as an array of DeployerConfig objects.
>>>>>    3. Then I have modified getAxisConfiguration() method of
>>>>>    CarbonAxisConfigurator inside org.wso2.carbon.core to read the above 
>>>>> array
>>>>>    via,
>>>>>
>>>>>
>>>>>                                          ServiceTracker
>>>>> deployerServiceTracker =new ServiceTracker(bundleContext,
>>>>> Axis2DeployerProvider.class.getName(),null);
>>>>>                                          deployerServiceTracker.open();
>>>>>                                          Axis2DeployerProvider
>>>>> axis2DeployerProvider =
>>>>> (Axis2DeployerProvider)deployerServiceTracker.getService();
>>>>>        4. I have updated register() method in both
>>>>> Axis2DeployerRegistry GhostDeployerRegistry to add the deployers to
>>>>> deployment engine.
>>>>>
>>>>>                                           public void
>>>>> register(Bundle[] bundles, DeployerConfig[] deployerConfigs) {
>>>>>                                                 for (Bundle bundle :
>>>>> bundles) {
>>>>>
>>>>> register(bundle);
>>>>>                                                 }
>>>>>                                                 for(DeployerConfig
>>>>> deployerConfig : deployerConfigs){
>>>>>
>>>>> Deployer deployer = getDeployer(deployerConfig.getClassStr());
>>>>>
>>>>> addDeployer(deployerConfig, deployer);
>>>>>                                                 }   ....
>>>>>                                          }
>>>>>
>>>>>
>>>>>
>>>>> After the modifications webapps deploy before management console is up.
>>>>>
>>>>> Thanks,
>>>>> Nipuni
>>>>>
>>>>>
>>>>> On Tue, Jun 3, 2014 at 8:24 AM, Nipuni Perera <[email protected]> wrote:
>>>>>
>>>>>> I will implement and provide a patch.
>>>>>>
>>>>>> Thanks,
>>>>>> Nipuni
>>>>>>
>>>>>>
>>>>>> On Mon, Jun 2, 2014 at 6:14 PM, Sameera Jayasoma <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>> Looks like we have a solution this problem. We simply need to way to
>>>>>>> register deployers which cannot be declared in component.xml, because 
>>>>>>> users
>>>>>>> should be able add or remove deployers.
>>>>>>>
>>>>>>> Axis2DeployerRegistry.register() method registers all the Deployers
>>>>>>> declared in the component.xml files. These are static Deployers. Now we
>>>>>>> need to improve the Axis2DeployerRegistry.register() method handle the
>>>>>>> other type of deployers. e.g. Webapp deployers for registered virtual
>>>>>>> hosts.
>>>>>>>
>>>>>>> In this solution Axis2DeployerRegistry asks the dynamic webapp
>>>>>>> deployer list from the webapp-mgt component using an OSGi service
>>>>>>> registered by the webapp-mgt component. In order to achieve this we can
>>>>>>> introduce a generic interface. Say Axis2DeployerProvider. webapp-mgt
>>>>>>> component implements this interface and register an OSGi service. Say
>>>>>>> VirtualHostWebappDeployerProvider.
>>>>>>>
>>>>>>> Now Axis2DeployerRegistry.register() method can get all the OSGi
>>>>>>> services which implement the Axis2DeployerProvider interface and get the
>>>>>>> deployer list and register them. Easy..
>>>>>>>
>>>>>>> I guess Nipuni can implement this and provide a patch to Carbon
>>>>>>> kernel 4.3.0.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Sameera.
>>>>>>>
>>>>>>> On Mon, Jun 2, 2014 at 5:28 PM, Sameera Jayasoma <[email protected]>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> We do no recommend to register deployers programmatically. The
>>>>>>>> recommended approach is to declare them in the component.xml. This 
>>>>>>>> allows
>>>>>>>> Carbon kernel to read and register deployers before initializing Apache
>>>>>>>> Axis2 engine. If you register deployers programmatically, Carbon kernel
>>>>>>>> does not have any control. Your artifacts may get deployed after 
>>>>>>>> server has
>>>>>>>> been started. I.e. after the transports are started.
>>>>>>>>
>>>>>>>> The above approach perfectly fits if the deployers do not get added
>>>>>>>> or removed dynamically. But in your case, we cannot predict the number 
>>>>>>>> of
>>>>>>>> deployers. I.e. for every new virtual host, there will be a new webapp
>>>>>>>> deployer. Therefore we cannot list all the deployers in the 
>>>>>>>> component.xml.
>>>>>>>> Now we need to come up with a solution to support this requirement.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Sameera.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Mon, Jun 2, 2014 at 2:43 PM, Kasun Gajasinghe <[email protected]>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Mon, Jun 2, 2014 at 2:05 PM, Nipuni Perera <[email protected]>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>> I didn't change the default deployer. I only read appBase values
>>>>>>>>>> of virtual hosts and added them to the deployment engine. But the 
>>>>>>>>>> webapp
>>>>>>>>>> deployment take place just after management console is started.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>> This happens if the deployers got added after axis2 has started
>>>>>>>>> IIRC. So, we need to make sure of the order. But unfortunately, we do 
>>>>>>>>> not
>>>>>>>>> have a proper way to force this order currently.
>>>>>>>>>
>>>>>>>>> @Sameera, any ideas?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Nipuni
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Mon, Jun 2, 2014 at 12:28 PM, Kasun Gajasinghe <
>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> I do not think that you should remove the default webapp
>>>>>>>>>>> deployer from component.xml. Your should be in effect only for the
>>>>>>>>>>> additional virtual hosts.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Jun 2, 2014 at 9:25 AM, Nipuni Perera <[email protected]>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> This is working. This was due to an ip address conflict.
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks,
>>>>>>>>>>>> Nipuni
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Sun, Jun 1, 2014 at 3:41 PM, Nipuni Perera <[email protected]>
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> I am working on the $subject. According to the current
>>>>>>>>>>>>> implementation users has to put webapps inside
>>>>>>>>>>>>> repositro/depolment/server/webapss and access them via host name
>>>>>>>>>>>>> "localhost" only. I have modified carbontomcat.java to deploy 
>>>>>>>>>>>>> webapps in a
>>>>>>>>>>>>> location defined inside appBase of virtualhosts. But this needs 
>>>>>>>>>>>>> to add an
>>>>>>>>>>>>> entry to component.xml to direct the name of webapps directory to 
>>>>>>>>>>>>> the
>>>>>>>>>>>>> relevent WebAppDeployer class. (Adding an entry to component.xml 
>>>>>>>>>>>>> each time
>>>>>>>>>>>>> a new appBase is created is not preferred)
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have tried following steps when adding deployers to
>>>>>>>>>>>>> deployment engine without reading component.xml file. When reading
>>>>>>>>>>>>> component.xml file, the Axis2DeployerRegistry class adds the 
>>>>>>>>>>>>> deployers and
>>>>>>>>>>>>> relevant directory names to a deploymentEngine. In order to skip 
>>>>>>>>>>>>> reading
>>>>>>>>>>>>> component.xml, deployment engine should be updated using the 
>>>>>>>>>>>>> virtual host
>>>>>>>>>>>>> appBase values and deployer names.
>>>>>>>>>>>>>
>>>>>>>>>>>>> *Scenario 1*
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>    1.     I created a new service component class inside
>>>>>>>>>>>>>    /org/wso2/carbon/webapp/deployer/internal/ and added following,
>>>>>>>>>>>>>
>>>>>>>>>>>>>                                  CarbonTomcatService
>>>>>>>>>>>>> carbonTomcatService = DataHolder.getCarbonTomcatService();
>>>>>>>>>>>>>                                  DeploymentEngine
>>>>>>>>>>>>> deploymentEngine =
>>>>>>>>>>>>> (DeploymentEngine)(DataHolder.getServerConfigContext().getAxisConfiguration()).getConfigurator();
>>>>>>>>>>>>>
>>>>>>>>>>>>>              This gave null values to both variables.
>>>>>>>>>>>>> ("serverConfigContext" and "carbonTomcatService" variables 
>>>>>>>>>>>>> initialize
>>>>>>>>>>>>> inside service components in 
>>>>>>>>>>>>> /org/wso2/carbon/webapp/mgt/internal. So it
>>>>>>>>>>>>> seems the newly created service component classes executes first)
>>>>>>>>>>>>>
>>>>>>>>>>>>> *Scenario 2*
>>>>>>>>>>>>>
>>>>>>>>>>>>>    1.  I have created a new OSGI bundle which tries to read
>>>>>>>>>>>>>    above two variables inside its Activator class and service 
>>>>>>>>>>>>> component class.
>>>>>>>>>>>>>    I could read proper values inside the service component class 
>>>>>>>>>>>>> and update
>>>>>>>>>>>>>    deployment engine. But according to logs, this executes after 
>>>>>>>>>>>>> starting the
>>>>>>>>>>>>>    wso2 carbon.  But, the following statement does deploy the 
>>>>>>>>>>>>> webapps inside
>>>>>>>>>>>>>    the appBase.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> deploymentEngine.addDeployer(deployer, directory, extension);
>>>>>>>>>>>>>
>>>>>>>>>>>>> But I am able to access webapps using host name "localhost"
>>>>>>>>>>>>> only,  What could be the issue here?
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Nipuni
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> --
>>>>>>>>>>>>> Nipuni Perera
>>>>>>>>>>>>> Software Engineer; WSO2 Inc.; http://wso2.com
>>>>>>>>>>>>> Email: [email protected]
>>>>>>>>>>>>> Git hub profile: https://github.com/nipuni
>>>>>>>>>>>>> Mobile: +94 (71) 5626680
>>>>>>>>>>>>> <http://wso2.com>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>> Nipuni Perera
>>>>>>>>>>>> Software Engineer; WSO2 Inc.; http://wso2.com
>>>>>>>>>>>> Email: [email protected]
>>>>>>>>>>>> Git hub profile: https://github.com/nipuni
>>>>>>>>>>>> Mobile: +94 (71) 5626680
>>>>>>>>>>>> <http://wso2.com>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>>
>>>>>>>>>>> *Kasun Gajasinghe*Senior Software Engineer, WSO2 Inc.
>>>>>>>>>>> email: kasung AT spamfree wso2.com
>>>>>>>>>>> linked-in: http://lk.linkedin.com/in/gajasinghe
>>>>>>>>>>> blog: http://kasunbg.org
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> Nipuni Perera
>>>>>>>>>> Software Engineer; WSO2 Inc.; http://wso2.com
>>>>>>>>>> Email: [email protected]
>>>>>>>>>> Git hub profile: https://github.com/nipuni
>>>>>>>>>> Mobile: +94 (71) 5626680
>>>>>>>>>> <http://wso2.com>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> *Kasun Gajasinghe*Senior Software Engineer, WSO2 Inc.
>>>>>>>>> email: kasung AT spamfree wso2.com
>>>>>>>>> linked-in: http://lk.linkedin.com/in/gajasinghe
>>>>>>>>> blog: http://kasunbg.org
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Sameera Jayasoma,
>>>>>>>> Software Architect,
>>>>>>>>
>>>>>>>> WSO2, Inc. (http://wso2.com)
>>>>>>>> email: [email protected]
>>>>>>>> blog: http://sameera.adahas.org
>>>>>>>> twitter: https://twitter.com/sameerajayasoma
>>>>>>>> flickr: http://www.flickr.com/photos/sameera-jayasoma/collections
>>>>>>>> Mobile: 0094776364456
>>>>>>>>
>>>>>>>> Lean . Enterprise . Middleware
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Sameera Jayasoma,
>>>>>>> Software Architect,
>>>>>>>
>>>>>>> WSO2, Inc. (http://wso2.com)
>>>>>>> email: [email protected]
>>>>>>> blog: http://sameera.adahas.org
>>>>>>> twitter: https://twitter.com/sameerajayasoma
>>>>>>> flickr: http://www.flickr.com/photos/sameera-jayasoma/collections
>>>>>>> Mobile: 0094776364456
>>>>>>>
>>>>>>> Lean . Enterprise . Middleware
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Nipuni Perera
>>>>>> Software Engineer; WSO2 Inc.; http://wso2.com
>>>>>> Email: [email protected]
>>>>>> Git hub profile: https://github.com/nipuni
>>>>>> Mobile: +94 (71) 5626680
>>>>>> <http://wso2.com>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Nipuni Perera
>>>>> Software Engineer; WSO2 Inc.; http://wso2.com
>>>>> Email: [email protected]
>>>>> Git hub profile: https://github.com/nipuni
>>>>> Mobile: +94 (71) 5626680
>>>>> <http://wso2.com>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Sameera Jayasoma,
>>>> Software Architect,
>>>>
>>>> WSO2, Inc. (http://wso2.com)
>>>> email: [email protected]
>>>> blog: http://sameera.adahas.org
>>>> twitter: https://twitter.com/sameerajayasoma
>>>> flickr: http://www.flickr.com/photos/sameera-jayasoma/collections
>>>> Mobile: 0094776364456
>>>>
>>>> Lean . Enterprise . Middleware
>>>>
>>>>
>>>
>>>
>>> --
>>> Nipuni Perera
>>> Software Engineer; WSO2 Inc.; http://wso2.com
>>> Email: [email protected]
>>> Git hub profile: https://github.com/nipuni
>>> Mobile: +94 (71) 5626680
>>> <http://wso2.com>
>>>
>>>
>>
>>
>> --
>> Sagara Gunathunga
>>
>> Senior Technical Lead; WSO2, Inc.;  http://wso2.com
>> V.P Apache Web Services;    http://ws.apache.org/
>> Linkedin; http://www.linkedin.com/in/ssagara
>> Blog ;  http://ssagara.blogspot.com
>>
>>
>
>
> --
> Nipuni Perera
> Software Engineer; WSO2 Inc.; http://wso2.com
> Email: [email protected]
> Git hub profile: https://github.com/nipuni
> Mobile: +94 (71) 5626680
> <http://wso2.com>
>
>


-- 
Sagara Gunathunga

Senior Technical Lead; WSO2, Inc.;  http://wso2.com
V.P Apache Web Services;    http://ws.apache.org/
Linkedin; http://www.linkedin.com/in/ssagara
Blog ;  http://ssagara.blogspot.com
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to