Failover and Load Balancing in Jasper Server

Failover and Load Balancing in Jasper Server

Installing jasper instances

For sample configuration I installed two Jasperserver instances:

  • On two separate application server (2 tomcat servers running on different port), and with
  • Single repository (OracleDB)

For detailed installation steps refer http://helicaltech.com/installing-jasperreports-server-6-0-1-with-oracle-db-in-windows/

I installed jasper server instances on localhost. These jasper servers are running on:

http://localhost:9080/jasperserver-pro

http://localhost:9180/jasperserver-pro

Installing Apache web server

  1. Download the Apache HTTPD Web Server from the Apache web site. Be sure to download the httpd_2.2.22-win32-x86-open_ssl MSI installer here: http://httpd.apache.org/download.cgi.
  2. Double click the MSI file saved on your Windows Desktop.

Apache HTTP server 2.2-Installation wizard will open.

  1. Click on Next button.
  2. Accept the terms in License agreement and click on Next button.
  3. On the next window again click next.
  4. Next,
  • fill in all the text boxes with the following information:

“Network Domain”: localhost

“Server Name”: localhost

“Administrator’s Email Address”: your email address

  • Make sure the radio button “for all users, on port 80, as a service – recommended” is selected.
  • Click on Next.
  1. When asked about the Setup Type, select “Typical” and click next.
  2. Give the Path where you want to install all the packages and scripts. I chose this path E:\Jaspersoft\Apache2.2\

(The ending backslash is important)

Click on OK after providing the installation path.

  1. Click “Install” to begin the installation.
  2. Once the Apache installation software has finished installing all the files on your computer, you will see a final window letting you know the installation was a success. Click the “Finish” button.
  3. To check that the software was in installed successfully, open browser and type “http://localhost/” into the address bar. You should see a page that looks like this or the words It Works!

Installing mod_jk

Mod_jk is an Apache web server module that allows the Apacheweb server to interface with the Tomcat application server. Installing it and configuring it are the keys to getting the web server and the application server working together.

Download the latest version of mod_jk

New versions of mod_jk are released as source packages, and as binary packages for select platforms.  Both are available for download from the Apache Tomcat Connector project download page.Currently, the following platforms receive binary releases: AIX, FreeBSD, iSeries, Linux, Mac OS X, Netware, Solaris, and Windows (32- and 64-bit releases).

Download the most recent release.

I downloaded “tomcat-connectors-1.2.40-windows-i386-httpd-2.2.x”.

Installing mod_jk

  1. Extract the zip file.
  2. Copy mod_jk.so and paste it inside modules directory of Apache web server (E:\Jaspersoft\Apache2.2\modules).

Jasper server configuration for failover

  1. On each jasper server instance, edit the file <web-app>/WEB-INF/web.xml.
  • Locate the listener of class RequestContextListener and replace it with the listener of class TolerantRequestContextListener. The new listener class is given in comments that you need to uncomment as follows:
<listener>

   <!--SESSION REPLICATION-->

                <!--Replace the default spring listener with the Tolerant listener to enable replication-->

                <listener-class>com.jaspersoft.jasperserver.core.util.TolerantRequestContextListener

                </listener-class>

                <!--listener-class>org.springframework.web.context.request.RequestContextListener

                </listener-class-->

</listener>
  • Locate the ClusterFilter that is given in comments and uncomment is as shown below:
<filter>

       <filter-name>ClusterFilter</filter-name>

       <filter-class>com.jaspersoft.jasperserver.war.TolerantSessionFilter</filter-class>

   </filter>

<filter>
  • Locate the corresponding mapping for the ClusterFilter and uncomment it as well. You must also uncomment the <distributable> element as well.
<filter-mapping>

       <filter-name>ClusterFilter</filter-name>

       <url-pattern>/*</url-pattern>

</filter-mapping>

<distributable/>

2. On each jasper server instance, enable session replication in your app server or web container.

For example, to enable session replication on Apache Tomcat 6.x, edit the file <tomcat>/conf/server.xml as follows:

  • Within the Engine tag add jvmRoute property as shown below:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="node2">
  • Add the Cluster definition within the <Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”node2″> configuration. This example uses Delta Manager.
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
    <Manager     className="org.apache.catalina.ha.session.DeltaManager"
                expireSessionsOnShutdown="false"
                notifyListenersOnReplication="true"/>
    
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        <Membership className="org.apache.catalina.tribes.membership.McastService"
                    address="228.0.0.4"
                    port="45564"
                    frequency="500"
                    dropTime="3000"/>

        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
        </Sender>
            
        <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                    address="auto"
                    port="4001"
                    autoBind="100"
                    selectorTimeout="5000"
                    maxThreads="6"/>
                    
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
        
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
        
    </Channel>
    
    <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
    
    <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
    
    <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
    
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
    
</Cluster>

3. On each jasper server instance, locate the following two files and uncomment the same two sections in each file:

  • web-app>/WEB-INF/ehcache.xml
  • web-app>/WEB-INF/ehcache_hibernate.xml
<cacheManagerPeerProviderFactory
       class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
        properties="peerDiscovery=automatic,multicastGroupAddress=224.0.0.1,multicastGroupPort=4446,timeToLive=1"/>
                   
    <cacheManagerPeerListenerFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="hostName=localhost,port=40111,remoteObjectPort=40112,socketTimeoutMillis=120000"/>


<cache name=...
            ...>
        <cacheEventListenerFactory
            class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,
                        replicateUpdatesViaCopy=false, replicateRemovals=true"/>
        <bootstrapCacheLoaderFactory
            class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
            properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"/>
    </cache>

Load Balancer configuration

The following changes configure the Apache HTTP server (httpd) as a load balancer.

1. Locate httpd.conf file in E:\Jaspersoft\Apache2.2\conf
2. Add following line to the end of the httpd.conf file

Include conf/mod-jk.conf

3. Create the following two files in the /conf folder of your httpd server.

4. Create the following two files in the /conf folder of your httpd server.

  • mod_jk.conf
# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs and memory
JkLogFile logs/mod_jk.log
JkLogFile logs/mod_jk.shm
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkOptions indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"
# Mount your applications
#JkMount /* loadbalancer
JkMount /jasperserver-pro loadbalancer
JkMount /jasperserver-pro/* loadbalancer
# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
#JkMountFile conf/uriworkermap.properties
# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
JkShmFile logs/jk.shm
#JkShmFile /var/log/httpd/mod_jk.shm
# Add jkstatus for managing runtime data
<Location /jkstatus>
JkMount status
Order deny,allow
Allow from all
</Location>

  • workers.properties
 # Define list of workers that will be used
# for mapping requests
worker.list=loadbalancer,status
# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=9009
worker.node1.host=localhost
worker.node1.type=ajp13
worker.node1.lbfactor=1
# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=9109
worker.node2.host=localhost
worker.node2.type=ajp13
worker.node2.lbfactor=1
# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=True
worker.list=loadbalancer
# Status worker for managing load balancer
worker.status.type=status

Installing JasperReports Server 6.0.1 with Oracle DB (in Windows)

Installing JasperReports Server 6.0.1 with Oracle DB (on Windows)

Pre-requisite

  1. Java JDK 1.6 or 1.7 should be installed.
  2. Create and set the JAVA_HOME system environment variable to point to the Java JDK location.
  3. Apache Tomcat 5.5, 6, or 7 should be installed.
  4. Oracle should be installed.
  5. Download the WAR file distribution from http://support.jaspersoft.com. The WAR file distribution comes in a file named jasperreports-server-6.0-bin.zip in compressed ZIP format.

NOTE: For demonstration I have done installation using JDK 1.7, Apache Tomcat 6, Oracle 11g XE and jasperreports-server-6.0-bin.zip

Installation Process

  1. Extract all files from jasperreports-server-6.0-bin.zip. Choose a destination, such as E:\Jaspersoft.The directory, jasperreports-server-6.0-bin, appears in the file location you choose.
  1. Copy the oracle_master.properties file for oracle from sample_conf and paste it to buildomatic
  • Copy oracle_master.properties from E:\Jaspersoft\jasperreports-server-6.0.1-bin\buildomatic\sample_conf
  • Paste it to E:\Jaspersoft\jasperreports-server-6.0.1-bin\buildomatic
  1. Rename the file you copied to default_master.properties.
  2. Edit the default_master.properties file to add the settings for DB server (oracle) and application server (Apache Tomcat 6). Following settings were added
appServerDir = E:\\Jaspersoft\\Tomcat6
dbType=oracle
dbUsername=jasperserver
dbPassword=password
sysUsername=system
sysPassword=password
dbHost=localhost
dbPort=1521
sid=xe
  1. Run the js-install scripts
  • Stop application server.
  • Start DB server.
  • Open Command Prompt as Administrator.
  • Run the js-install script as shown below:

1

The script will create and load tables for jasper server repositoryin oracle DB. It will also deploy the jasperserver-pro webapp and copy all required files in Jasperserver-pro directory.On Successful deployment following message will be displayed on command prompt.

2

  1. Setting Java options
  • Navigate to bin directory of tomcat as shown below

3

  • Right click on Tomcat6w and Run as Administrator.
  • Navigate to Java tab and set following java options
-Xms512m
 -Xmx1024m
 -XX:MaxPermSize=512m

Refer the snapshot given below:

4

7. Adding license file: Copy the jasperserver.license file in C:\Users\

5

8. Starting application server.

After JasperReports Server starts up, login to JasperReports Server by going to this URL:http://<hostname>:<port>/jasperserver-pro. For Example: http://localhost:9080/jasperserver-pro/

 

Creating a custom template with Jaspersoft Studio

Creating a custom template with Jaspersoft Studio

Create the Structure

Creating template is nothing more than a standard report where some elements have a precise and fixed name that is used by the Jaspersoft Studio engine to understand where to place every element.

The First thing is to create new report from File -> New -> Jasper Report. We can start with blank report or selecting one of the other templates as a starting point.

Now Design the template as par your requirement .Creating the template is same as that of generating the report.

I have created like this

Report Template

Now switch to the Preview mode and look if the result is what you want and if it is allright you can continue with the export operation.

Export the Template

To start the export wizard select click File -> Export as Report Template.

In the first dialog you will see all the resources that will be exported. Between these resources you can fine the template and other files used by it, in our example you will see the one image. In this step you will need also to select the destination folder, where the template and all his resources will be placed.

Template Export

When you have finished press Next.

Here you can define the categories where your template will be visible inside the New Report Wizard.  You can select any number of categories or your own category. To define a custom category you need only to type its name inside the text area on the bottom and press the Add button. Then your category will be added to Selected Categories list. Then your category will be added to Selected Categories list.

At this point you need to select the correct type of report, for example if it is a Tabular Report or a standard one.
Template Type and Categories

At this point you can see two different steps:

  • The first one, and the one that should appear follwoing this tutorial, is a congratulations step. It means that the template you designed is valid for the report type you have selected in the previous step.
  • The second one is a list of error messages if the template you designed is not valid for the selected type because of some design errors. For example for a template with Tabular type is expected a table in the summary band. If this table is not found it’s probably a design error. In this step all the design errors found are listed so you can look to what is wrong and fix it.

5(30)
 

OR

 
6(22)

 

In both the cases we can export the template and all resources by clicking the finish button.

In second case may your template should not work while generating the report.

Add the Templates location to Studio

  1. Now you have to put your custom template for studio.
  2. Navigate to Windows ->Preferences. A new Preferences window open.
  3. From the Left panel expand the category Jaspersoft Studio and select Template Locations.
  4. Click on New and browse the folder where you have saved template jrxml file.

Refer the screenshot below:
5(14)

Test the new template

  1. Open Jaspersoft studio.
  2. Navigate to File > New > Jasper Report.

A new Report wizard will open.
Template

  1. Select the template that you have added. Then Report will open as shown below:

Report Template
 
-By
Nitin Uttarwar
Helical It Solution

Domains accepting Custom Datasource as Bean

Domains accepting Custom Datasource as Bean

The following description is related to Bean data source. In general domains don’t accept bean as data source. To enable a custom data source for usage in a domain you can effect the following changes to the applicationContext-semanticLayer.xml.

Add below bean data source entry in metaDataFactoryFactory configuration code. metaDataFactoryFactory holds the list of data sources.

Code:

 <entry key="com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.BeanReportDataSource" value-ref="jdbcMetaDataFactory"/> 

After Editing it Looks like:

 <bean name="metaDataFactoryFactory" 
      class="com.jaspersoft.commons.semantic.metaapi.impl.MetaDataFactoryFactoryImpl">
    <property name="implementationObjectFactory" ref="mappingResourceFactory"/>
    <property name="dataSourceTypeMapping">
        <map>
            <entry key="com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JdbcReportDataSource"
                   value-ref="jdbcMetaDataFactory"/>
            <entry key="com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JndiJdbcReportDataSource"
                   value-ref="jndiJdbcMetaDataFactory"/>
            <entry key="com.jaspersoft.commons.semantic.datasource.SemanticLayerDataSource"
                   value-ref="domainMetaDataFactory"/>
            <entry key="com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.BeanReportDataSource"
                   value-ref="jdbcMetaDataFactory"/>
       </map>
    </property>

Within same file you will also need to add below class under dataSourceTreeDataProvider with in the same file.

Code:

 <value> com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.BeanReportDataSource 

After Editing it looks like:

 <bean name="dataSourceTreeDataProvider" 
      class="com.jaspersoft.commons.semantic.tree.DataSourceTreeDataProvider" 
      scope="prototype">
    <constructor-arg ref="repositoryService" />
    <constructor-arg>
        <list>
         <value>com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JdbcReportDataSource</value>
           <value>com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JndiJdbcReportDataSource</value>
           <value>com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.BeanReportDataSource</value>
        </list>
    </constructor-arg>

How to Configure Jasper Apache-Tomcat’s Java Heap Size?

How to Configure Jasper Apache-Tomcat’s Java Heap Size?

Identify apache-tomcat location from jasperserver installation place. Location can be look like “/opt/jasperreports-server-cp-5.0.0/apache-tomcat/bin”. If Tomcat running as a Linux Service incase it is a windows service it can be look like “C:\Jaspersoft\jasperreports-server-cp-5.5.0a\apache-tomcat\bin”

  1. Open and navigate through bin directory as shown in the screen shot below. 1
  2. Edit setenv.bat file and Update JAVA_OPTS parameter values like “-Xms512m -Xmx1024m -XX:MaxPermSize=1024m $JAVA_OPTS”.
  3. If above parameters are not exist then add those values.2