Sunday, February 3, 2013

Running Carbon 4.0.2 in Geronimo as a web-application

In this post I'll explain how to deploy Carbon 4.0.2 as a web-application in Apache Geronimo V3. I'm using the Geronimo J2EE distribution with Tomcat 7 integration for Linux platform downloaded from here

Please Note: 
WSO2 Carbon platform is a fully fledged cloud-native middleware platform with it's own set of complexities which are greater than a typical web-application or other deployable artifact.
Running WSO2 products in web-app mode or any other deployable form in 3rd party AppServers can greatly limit the capabilities of the the platform and can introduce new complexities when combined with the host AppServer's environment and complexities.
Therefore running WSO2 Products in other AppServers is not encouraged and subject to specific support conditions only.


The Steps 

The basic steps are similar to what is explained by Pradeep in his blog on running Carbon 4.0 as a web-app in Apache Tomcat. So I would suggest reading his blog to understand the basics on running Carbon based products in web-app-mode on any other Web Server.

Here I will explain the steps to deploy Carbon web-app in Geronimo and explain what are the tweaks and changes we need to do in Geronimo to run Carbon web-app.

1. Download Carbon 4.0.2 from the previous releases page here


2. Extract carbon-4.0.2 in the file-system. 

The extracted directory will be considered $CARBON_HOME from here onwards.

3. The web-app directory for Carbon is in $CARBON_HOME/webapp-mode directory. Inside it you will find the WEB-INF folder which contains the web-application descriptors and required libraries to run Carbon web-application. The structure of the WEB-INF directory is as below;



WEB-INF/
├── eclipse
│   └── launch.ini
├── lib
│   └── org.wso2.carbon.bridge-4.0.0.jar
└── web.xml

The web.xml is the web-application descriptor that includes details about the Carbon web-app. Please note that the web-app ID will be taken as the web-context root if you don't include a geronimo-web.xml descriptor specifying the Web-Context information, under your web-application. So in this case the Carbon web-app ID is : WebApp

4. Create a .war archive file with above content in WEB-INF directory so that we can deploy it in Geronimo. I'm creating the archive as carbon.war.

eg:  jar -cvf carbon.war WEB-INF/


5. Now we need to configure the carbon-repository to be used by our carbon web-application. For this create a directory named carbon_repo and copy the repository sub-directory under $CARBON_HOME, to carbon_repo directory.

We'll call this directory $CARBON_REPO from here onwards.
For me this location is at: /home/dileepa/work/carbon_repo


 carbon_repo/
                          └── repository
                                        ├── components
                                        ├── conf
                                        ├── data
                                        ├── database
                                        ├── deployment
                                        ├── logs
                                        ├── README.txt
                                        ├── resources
                                        └── tenants

Now;
  • Remove all the tomcat related jars from the  '$CARBON_REPO/repository/components/plugins' directory.  As Geronimo provides Tomcat servlet container by default we don't need these bundles in runtime.
           org.wso2.carbon.tomcat_4.0.1.jar 
           org.wso2.carbon.tomcat.ext_4.0.2.jar
           org.wso2.carbon.tomcat.fragment.dummy_4.0.0.jar
           org.wso2.carbon.tomcat.patch_4.0.1.jar
           tomcat-ha_7.0.28.wso2v1.jar
           tomcat_7.0.28.wso2v1.jar

  • Copy the jars found under $CARBON_HOME/webapp-mode/bundles to '$CARBON_REPO/repository/components/plugins'  directory. namely org.wso2.carbon.http.bridge-4.0.0.jar and org.wso2.carbon.servletbridge-4.0.0.jar
  • Now we need to configure the bundles.info to add these 2 new bundles in the runtime. Add the below 2 lines to $CARBON_REPO/repository/components/configuration/org.eclipse.equinox.simpleconfigurator/bundles.info
org.wso2.carbon.http.bridge,4.0.0,plugins/org.wso2.carbon.http.bridge-4.0.0.jar,4,true org.wso2.carbon.servletbridge,4.0.0,plugins/org.wso2.carbon.servletbridge-4.0.0.jar,4,true

6. We now need to setup the HTTPS connector configuration for tomcat in Geronimo to handle connections to carbon web-app.

To do this; add a HTTPS Connector configuration to $GERONIMO_HOME/var/catalina/server.xml

I'm configuring a new HTTPS connector for port : 8445 in Geronimo's tomcat server using the default carbon-keystore as below;
eg:

Then configure Axis2 transports in $CARBON_REPO/repository/conf/axis2.xml

    8080

 

    8445

Now configure the serverURL and the web-context root (the web-context root for our scenario is /WebApp) in carbon.xml
/WebApp
https://localhost:8445/WebApp/services/



Also change the JMX ports in carbon.xml to some other accepted port number to avoid address conflicts with host Geronimo's RMI ports.

            
            9998
            
            11112



7. Endorsing JVM provided classes
Copy the endorsed lib jars found under $CARBON_HOME/lib/endorsed to $GERONIMO_HOME/lib/endorsed to provide the endorsed libraries required for XML parsing/API etc. 

8. Configuring the Carbon Datasource in Geronimo.
We need to configure a Carbon datasource in Geronimo for the Registry and User Manager in Carbon. For this purpose please follow the blog-post on how to create an embedded-derby Carbon datasource in Geronimo. Similarly you can create the datasource using any database type and configure the master-datasources.xml to use it.

Now use the JNDI name and the URL of the created datasource with the relevant database driver in $CARBON_REPO/repository/conf/datasources/master-datasources.xml

eg: 

            WSO2_CARBON_DB
            The datasource used for registry and user manager
            
                jca:/console.dbpool/WSO2CarbonDB/JCAConnectionManager/WSO2CarbonDB
            
            
                
                    jdbc:derby:/home/dileepa/work/geronimo-tomcat7-javaee6-web-3.0.0/var/derby/WSO2_CARBON_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000
                    wso2carbon
                    wso2carbon
                    org.apache.derby.jdbc.EmbeddedDriver
                    50
                    60000
                    true
                    SELECT 1
                    30000
                
            
        

To support embedded derby database connection, you  need to add the derby embedded driver bundle to $CARBON_REPO/repository/components/plugins and add below entry to bundles.info.

derby,1.0.0,plugins/derby_1.0.0.jar,4,true
You can download the derby_1.0.0 bundle from the hosted location here.

To enable Carbon Logging, you need to make the log4j.property file available for carbon logging bundle in $CARBON_REPO/repository/components/plugins. In standalone Carbon 4 based products, this is achieved by bundling the log4j property file as a fragment bundle and deploying it on the fly as from dropins. But as we are deploying the carbon runtime in bridge mode we cannot install dropins, so we have to manually copy it to $CARBON_REPO/repository/components/plugins directory and add the relevant entry in the bundles.info as below;

org.wso2.carbon.logging.propfile,1.0.0,plugins/org.wso2.carbon.logging.propfile_1.0.0.jar,4,true 
You can download the org.wso2.carbon.logging.propfile_1.0.0.jar bundle from the hosted location here.

9. Now configure $CARBON_REPO/repository/conf/user-mgt.xml and registry.xml using the above created datasource JNDI name.
  • In user-mgt.xml change the datasource property as below;
<Property name="dataSource">jca:/console.dbpool/WSO2CarbonDB/JCAConnectionManager/WSO2CarbonDB</Property>
  • In registry.xml change the dataSource as below;
 <dataSource>jca:/console.dbpool/WSO2CarbonDB/JCAConnectionManager/WSO2CarbonDB</dataSource>

10. Now the $CARBON_REPO is configured. 
You now need to set the carbon.home system property required to run Carbon. 
Set the carbon.home system property in  $GERONIMO_HOME/etc/system.properties as below;

carbon.home=/home/dileepa/work/carbon_repo

10. Now the environment is set for deploying carbon web-app in Geronimo. So start Geronimo server by executing below command;

$GERONIMO_HOME/bin$ ./geronimo run

To deploy the carbon.war we created in step 4, deploy the carbon.war in Geronimo server by going to the Deployer section in console and giving the carbon.war archive to install.


Now when deploying carbon.war if you see below error it's due to a aries-jndi bug in 0.3.0 version discussed in ARIES-554
ERROR [DataSourceRepository] Error in registering data source: WSO2_CARBON_DB - Error in creating JNDI subcontext 'javax.naming.InitialContext@2702c693/jca:: Unable to determine caller's BundleContext
org.wso2.carbon.ndatasource.common.DataSourceException: Error in creating JNDI subcontext 'javax.naming.InitialContext@2702c693/jca:: Unable to determine caller's BundleContext
 at org.wso2.carbon.ndatasource.core.DataSourceRepository.checkAndCreateJNDISubContexts(DataSourceRepository.java:232)
 at org.wso2.carbon.ndatasource.core.DataSourceRepository.registerJNDI(DataSourceRepository.java:257)
 at org.wso2.carbon.ndatasource.core.DataSourceRepository.registerDataSource(DataSourceRepository.java:360)
 at org.wso2.carbon.ndatasource.core.DataSourceRepository.addDataSource(DataSourceRepository.java:474)
 at org.wso2.carbon.ndatasource.core.DataSourceManager.initSystemDataSource(DataSourceManager.java:182)
 at org.wso2.carbon.ndatasource.core.DataSourceManager.initSystemDataSources(DataSourceManager.java:154)
 at org.wso2.carbon.ndatasource.core.internal.DataSourceServiceComponent.initSystemDataSources(DataSourceServiceComponent.java:166)
 at org.wso2.carbon.ndatasource.core.internal.DataSourceServiceComponent.setSecretCallbackHandlerService(DataSourceServiceComponent.java:152)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Geronimo V3 comes with aries-jndi-0.3.0 installed.


To fix the JNDI issue you need to update the aries-jndi bundle and it's dependencies.
For that please follow below steps;


  • Go to OSGI bundles section in console and search for aries.jndi bundle;



  • Now you need to uninstall this bundle and install the latest available org.apache.aries.jndi.1.0.0 and it's required dependencies: org.apache.aries.util.1.0.0 and org.apache.aries.proxy.1.0.0. 
  • You can download these aries bundles from the official Aries download site.After installing the 3 new aries bundles and starting them you can rectify the JNDI error you got before.
11. Now you can re-start the Geronimo server and access the Carbon management console at : https://localhost:8445/WebApp/carbon/




You can telnet to the osgi-console of Carbon server as below;
telnet localhost 19444



Friday, February 1, 2013

Deploying Carbon bundles in Geronimo

In this post I'll explain the steps to test deploying WSO2 Carbon bundles in Apache Geronimo V3 server. Before deploying the bundles we need to setup the configuration environment required by the Carbon bundles. 
Please note that deploying Carbon bundles in Geronimo has several bundle resolution issues which need to be manually identified and rectified in order to setup all Carbon bundles to function properly. 

For this effort, I'm using the Geronimo J2EE distribution with Tomcat 7 integration for Linux platform downloaded from here
I'm using carbon-4.0.2 bundles for the deployment. You can download carbon-4.0.2 distribution from previous releases found here

1. Create CARBON_HOME directory under Geronimo home. Copy the repository directory in the carbon distribution to Geronimo home. I have highlighted the important sub-directories and configuration files for our use-case.  

Mainly we need to focus on datasources/master-datasources.xml, registry.xml and user-mgt.xml to configure the Carbon datasource and components/plugins directory to point Geronimo to find the bundle set to deploy.
eg:
GERONIMO_HOME
 |
 |── CARBON_HOME
│   └── repository│    
│       │   └── conf
│       │       ├── axis2
│       │       ├── carbon.xml
│       │       ├── datasources
│       │       │   └── master-datasources.xml
│       │       ├── etc
│       │       ├── log4j.properties
│       │       ├── osgi-debug.options
│       │       ├── README
│       │       ├── registry.xml
│       │       ├── security
│       │       ├── tomcat
│       │       │   ├── carbon
│       │       │   │   ├── META-INF
│       │       │   │   │   └── context.xml
│       │       │   │   └── WEB-INF
│       │       │   │       └── web.xml
│       │       │   ├── catalina-server.xml
│       │       │   ├── tomcat-users.xml
│       │       │   └── web.xml
│       │       └── user-mgt.xml
│       ├── carbonapps
│       ├── components
│       │   ├── dropins
│       │   ├── extensions
│       │   ├── features
│       │   ├── lib
│       │   ├── p2
│       │   ├── patches
│       │   ├── plugins



The repository directory includes all the main artifacts, bundles and configurations for Carbon.


2. Remove the tomcat related bundles from $GERONIMO_HOME/CARBON_HOME/repository/components/plugins as Geronimo provides tomcat bundle by default; 
(remove below bundles)
  org.wso2.carbon.tomcat_4.0.1.jar 
           org.wso2.carbon.tomcat.ext_4.0.2.jar
           org.wso2.carbon.tomcat.fragment.dummy_4.0.0.jar
           org.wso2.carbon.tomcat.patch_4.0.1.jar 
           tomcat_7.0.28.wso2v1.jar
           tomcat-ha_7.0.28.wso2v1.jar

Also remove org.eclipse.osgi_3.7.0.v20110613 bundle as Geronimo provides the bundle by default.


3. Create a database for WSO2 UserManager and Registry and configure WSO2Carbon DataSource in $GERONIMO_HOME/CARBON_HOME/repository/conf/datasources/master-datasources.xml.

To create the database you can use the db-scripts from CARBON_HOME/dbscripts.
For more details on this, you can refer this blog post on configuring an embedded Derby Carbon datasource in Geronimo and how to configure user-manager and registry to use it.

4. Configure carbon.home system.property required by Carbon in $GERONIMO_HOME/etc/system.properties. 
carbon.home=${karaf.base}/CARBON_HOME

5. Setup Carbon bundle installation location in Geronimo by configuring $GERONIMO_HOME/etc/hotbundles-config/org.apache.felix.fileinstall-deploy.cfg to point to CARBON_HOME/repository/components/plugins to install Carbon bundles at startup.
felix.fileinstall.dir=${karaf.base}/CARBON_HOME/repository/components/plugins

6. Optionally you can modify Geronimo server's log4j configuration to support Carbon logging by adding the configurations to $GERONIMO_HOME/var/log/server-log4j.properties.
You can find the Carbon log4j configurations in :$CARBON_HOME/repository/conf/log4j.properties

An example configuration addition is as below;

log4j.rootLogger=INFO, CONSOLE, FILE, CARBON_CONSOLE, CARBON_LOGFILE

# CARBON_CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CARBON_CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CARBON_CONSOLE.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout
# ConversionPattern will be overridden by the configuration setting in the DB
log4j.appender.CARBON_CONSOLE.layout.ConversionPattern=[%d] %P%5p {%c} - %x %m%n
log4j.appender.CARBON_CONSOLE.layout.TenantPattern=%U%@%D[%T]
log4j.appender.CARBON_CONSOLE.threshold=DEBUG


# CARBON_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout.
log4j.appender.CARBON_LOGFILE=org.apache.log4j.DailyRollingFileAppender
# Log file will be overridden by the configuration setting in the DB
# This path should be relative to WSO2 Carbon Home
log4j.appender.CARBON_LOGFILE.File=${carbon.home}/repository/logs/${instance.log}/wso2carbon${instance.log}.log
log4j.appender.CARBON_LOGFILE.Append=true
log4j.appender.CARBON_LOGFILE.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout
# ConversionPattern will be overridden by the configuration setting in the DB
log4j.appender.CARBON_LOGFILE.layout.ConversionPattern=TID: [%T] [%S] [%d] %P%5p {%c} - %x %m {%c}%n
log4j.appender.CARBON_LOGFILE.layout.TenantPattern=%U%@%D [%T] [%S]
log4j.appender.CARBON_LOGFILE.threshold=DEBUG




With above given minimal configurations you can test deploying Carbon bundles in Geronimo server. Please note that there are several bundle resolution issues which avoids complete startup of Carbon. 

For example some of the problems faced are: 
  • When using Geronimo v3, some of our bundles have import package resolution issue for javax.activation package. Some of our bundles (eg: jaxb, abdera, org.wso2.carbon.core.common, org.wso2.carbon.user.mgt.common) require package javax.activation with version [0.0.0,1.0.0) but Geronimo Spec system bundle in Geronimo provides javax.activation;version=1.1.0.  
  • We either have to override the export package version of javax.activation package to support our bundles import version range or change our bundle set not to bind to version range [0.0.0,1.0.0) for javax.activation package.
  • The bundle org.eclipse.equinox.util_1.0.300.v20110502 in plugins doesn't get resolved as it's  Missing Constraint: Bundle-RequiredExecutionEnvironment: OSGi/Minimum-1.1 in the runtime.  To resolve thisn change the OSGi execution environment property to OSGi/Minimum-1.1 in $GERONIMO_HOME/etc/config.properties
  • Carbon bundles require osgi.http.service to register servlets. Need a bundle which exposes osgi.http.service in the container for Carbon bundles to use. (eg: we can use org.eclipse.equinox.http bundle to provide osgi http service)
  • Noticed that the org.eclipse.equinox.http.helper_1.0.0.qualifier.jar doesn't get picked up automatically from plugins, because of this org.wso2.carbon.ui bundle doesn't get started. Therefore install org.eclipse.equinox.http.helper_1.0.0.qualifier.jar manually from the Geronimo console and start org.wso2.carbon.ui bundle
  • Class loading issues for org.wso2.carbon.core package
These issues require further investigations and experiments inorder to resolve completely.

Configuring a Carbon Datasource in Geronimo

In this post I will explain how create an embedded Derby database and configure a Carbon Datasource in Apache Geronimo. This configured datasource is useful if you are deploying Carbon bundles or running Carbon in web-app mode under restricted conditions in Geronimo. 

For this purpose I'm using the Geronimo J2EE distribution with Tomcat 7 integration for Linux platform downloaded from here

We can use the created database in Geronimo to configure the Carbon master datasource and use it to for UserManager and Registry in Carbon.


1. In Geronimo console go to "Datasources" and click the Using the Geronimo database pool wizard link, and complete the following steps:

Step 1: 

Select Name and Database, enter WSO2CarbonDB for the Name of Database Pool field. Select Derby embedded from the Database Type pull-down menu, and click Next




Step 2: 

Select Driver, JAR, Parameters, select org.apache.geronimo.configs/system-database/3.0.0/car from the Driver JAR pull-down menu. 


Configure the database with required configurations;


Sample configuration:


Database Name :  WSO2_CARBON_DB
Username : wso2carbon
Password : wso2carbon





Step 3: 

After creating the Database pool, run the derby.sql using the created WSO2CarbonDB pool as the datasource. The db scripts to create the Registry and User Manager Database can be found in any Carbon product at $CARBON_HOME/dbscripts directory.






Step 4: 

Now get the JNDI object name for the created database and use it to configure the WSO2_CARBON_DB datasource in $CARBON_HOME/repository/conf/datasources/master-datasource.xml

Also change the database url to point to the newly created Database location.

eg: 





            WSO2_CARBON_DB
            The datasource used for registry and user manager
            
                jca:/console.dbpool/WSO2CarbonDB/JCAConnectionManager/WSO2CarbonDB
            
             
                
   jdbc:derby:/home/test/geronimo-tomcat7-javaee6-web-3.0.0/var/derby/WSO2_CARBON_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000
                    wso2carbon
                    wso2carbon
      org.apache.derby.jdbc.EmbeddedDriver
                    50
                    60000
                    true
                    SELECT 1
                    30000
                
            





Now you can use this datasource in user-mgt.xml and registry.xml in $CARBON_HOME/repository/conf as below. This is how we configure Registry and User Manager to use a database referred by a Carbon datasource.

1. In user-mgt.xml


                admin
                
                     admin
                     admin
                
            everyone 
     jca:/console.dbpool/jdbc_WSO2CarbonDB/JCAConnectionManager/jdbc/WSO2CarbonDB
            org.wso2.carbon.user.core.config.multitenancy.SimpleRealmConfigBuilder


2. In registry.xml

 jca:/console.dbpool/jdbc_WSO2CarbonDB/JCAConnectionManager/jdbc/WSO2CarbonDB