Shalini's Weblog

JDBC Pool Manager - Max Pool Size Tuning

Tuesday Feb 10, 2009

Max pool size is the maximum number of connections to the database at any point of time. This value can be configured as a jdbc connection pool attribute "max–pool–size". The default value of this attribute is 32. 

Some databases have license restrictions on how many connections it can allow. This attribute is configured based on such parameters.  This parameter can also be configured from the Performance Advisor page in administration console of GlassFish. Some important points to note here :


  • If one or more jdbc connection pools are selected in the JDBC Pool Manager, there is an option to specify a "Max Connections" value for each pool according to the requirement. 

  • The Default Max Connections set to a certain value overrides the settings of the max–pool–size of the selected jdbc connection pools.


On a clustered environment, when new instances are added to the cluster, the max–pool–size on each instance may need a reconfiguration. This should also be based on the instance weights. A particular instance may have a higher instance weight, say, to provide faster service to privileged customers.
Steps

  • Create a node–agent called na1

  • Create a cluster "mycluster" with 2 instances "instance1" (weight 40) and "instance2" (weight 60)

  • Start the cluster "mycluster"

  • Create a new JDBC Connection pool "mypool" with default settings

  • Create a new JDBC resource referring the above connection pool for target "mycluster" : "jdbc/myresource"

  • Create an application that refers this jdbc resource on "mycluster" target


Clustered environment


  • In the performance advisor link of admin console, specify the default max connections for "mypool" as 100. Enable this rule on "mycluster" by choosing "mycluster" for target. Jdbc Rule Manager


Setting target as mycluster

After these steps, the "mycluster" should be restarted to see the max pool size reconfiguration in each of the instances "instance1" and "instance2".

You would see, for "instance1", the max pool size is recalculated to 40

instance1 log from admin console

and "instance2" to 60 based on their instance weights.

instance2 log from admin console


  • Add another new instance "instance3" to "mycluster" with weight of 100.

  • Restart "mycluster".


Once the cluster is restarted with the new instances addition, the max pool size of instance1 becomes 20, instance2 becomes 30 and instance3 becomes 50. This is based on the instance weights and the default max connections value we specified for the jdbc connection pool. instance3 gets more number of max connections to the database since its instance weight is higher.

instance1 log from admin console after instance addition
instance2 log from admin console after instance addition
instance3 log from admin console after instance addition

This is a very useful rule to configure the maximum pool size of jdbc connection pools on cluster startup. Manual intervention is prevented and this easy–to–use feature can be configured to avoid errors in complex cluster scenarios.

[1] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

JDBC Pool Manager - Steady Pool Size Tuning

Tuesday Feb 10, 2009

Sun has recently announced the "GlassFish Enterprise Manager". I would talk about a particular feature : "Performance Advisor". One of the management rules of Performance Advisor is the JDBC Pool Manager. Jdbc pool manager tunes the steady pool size and maximum pool sizes of jdbc connection pools based on the load. This blog would briefly talk about steady pool size tuning.


 Example


Consider a cricket website. On a non–match day, there will be a minimum number of requests to this website. On a match–day, even if it is a working day, people tend to use such websites to check the runs and number of wickets. The number of requests will pour in as a result and for maximum resource utilization, the steady pool size needs to go up. If done manually, the administrator will have to configure this steady pool size.


 After  a while, number of requests are bound to come down. As a result, the steady pool size would have to be brought down. This constant recomputing of steady pool size based on the load is automated by the JDBC Pool Manager.


How is it Configured?


Assume there is a jdbc connection pool : cricket–info–pool. jdbc/cric is the resource that references this pool. The cricket–info–pool is set to a default steady pool size of 8. An application that uses the jdbc resource to get information from a database is set up. Client access this application to retrieve information. JDBC Pool Manager rule can set up from admin GUI.



  • The Default Max Connections is the maximum number of connections that can be provided from the pool at any point of time.

  • The management rule tunes the steady pool size in Sampling Frequency number of seconds.

  • The sample size denoted by Number of Samples is used to calculate the moving average value for number of connections.


Marking cricket-info-pool under PoolNames will configure the rule for this connection pool.  Click on Save after entering all the details.The domain needs to be restarted now, as the rule is configured for the target "server".


On domain restart, you can observe from the server.log that the steady pool size is recalculated to a certain value. After a while, assuming there are 500 client requests for a period of 10 minutes.



The steady pool size is recalculated every 60 seconds (default sampling frequency) to a new value suitable for the current number of requests.

[1] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

JDBC support in V3 Prelude

Thursday Nov 06, 2008


The latest application server of Sun – GlassFish V3 Prelude includes JDBC support. The JDBC Connection pooling infrastructure in V3 prelude is same as that of GlassFish 9.1 application server.


Some of the cool features that could be useful to you are :



  • Connection Leak Tracing


    •  enable the connection-leak-timeout to a certain value along with connection-leak-reclaim to true to avoid the potential connection leaks in your application


  • Validation calls optimization


    • Set the validate atmost once period to a value within which the validation will be carried out atmost once.


  • Associate with thread


    • To reuse connections in a multi threaded application to avoid the overhead of getting a connection from the pool.



and many more...


Things that have changed:


Setting the pool properties/attributes using asadmin set command would be like:


asadmin set --value=10 server.resources.jdbc-connection-pool.DerbyPool.steady-pool-size



asadmin set --value=newUser server.resources.jdbc-connection-pool.DerbyPool.property.User



Note that the first asadmin set does not need a server restart whereas the second one mandates restart.



There are many more attractive things coming up in the next release of V3 for JDBC. One of them is advanced pool monitoring. The monitoring framework has undergone a major change in v3 prelude.


Try the latest V3 prelude and its connection pooling features. Any issues? Mail users-AT-glassfish.dev.java-DOT-net .

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

JDBC Pool Monitoring using Management Rules

Monday Oct 13, 2008

After my basic blog blog about creating and writing mbeans and self management rules, here is a post on how to monitor a certain attribute of a jdbc connection pool using Self Management Rule.
I would take for example, the connection validation failures. The Monitoring framework of glassfish provides statistics on various attributes including an attribute specially for the number of connection validation failures. Here are the steps :


1. First of all, enable the monitoring for JDBC Connection Pool to HIGH from the admin console or from CLI.


2. Create JDBC Connection Pool/JDBC Resource for this exercise : conValPool and jdbc/conval respectively.


3. We would be monitoring the attribute for connection validation failure on this pool conValPool.


4. The objectName for this conValPool for monitoring would be "com.sun.appserv:name=conValPool,type=jdbc–connection–pool,
category=monitor,server=server"
I got this objectName from listing all mbeans and querying the names for conValPool. Note that this mbean is specifically for monitoring this pool since the category is monitor.


5. When i open jconsole and login to it, i see that com.sun.appserv  section, there is a head called conValPool. Under this, we see a server element if we browse down the tree. On the right pane, we can see all the attributes and i would take a note of the attribute with name numconnfailedvalidation–count.
I would use this attribute in my custom mbean event.


6. Create an mbean called ValidationMonitor for getting the value of numconnfailedvalidation–count at any point of time. It would have code that gets the value as follows




MBeanServer server = ManagementFactory.getPlatformMBeanServer();
numConnFailVal = (Long) server.getAttribute(new
    ObjectName("com.sun.appserv:name=conValPool,type=jdbc–connection–pool,
    category=monitor,server=server”) , "numconnfailedvalidation–count";)



I use the getAttribute method on the MBeanServer with the above mentioned ObjectName and the attribute name. The numConnFailVal is the attribute that will be returned whenever this mbean is invoked.


7. Create an mbean called ValidationAction for the action part of the management rule. This action would be triggered every time some threshold is crossed as part of the rule that we are going to create shortly. The action as of now is going to be a simple System.out.println  to the server.log as follows




public class ValidationAction implements NotificationListener,
    com.sun.example.action.ValidationActionMBean {
    public synchronized void handleNotification(Notification notification, Object handback) {
         try {
System.out.println("Validation  Failure Threshold Notification: " +
                       notification);
          } catch(Exception ex) {
          }
     }
}




Note that the action mbean implements the NotificationListener interface.


8. Coming to the part of creating a management rule to hook up this action and event, we log into the admin console and deploy the custom mbeans created above.
Then under the Management Rules link under Configuration, create a new management rule called ValFailRule. Specify the event type as monitor and other values as follows




observed MBean value : user:impl–class–name=com.sun.example.mbeans.ValidationMonitor,
name=validationmonitor,server=server

observedAttribute value : numConnFailVal
Monitor type to Counter
Granularity period to 1000 milliseconds so that every second the rule would check for the numConnFailVal value.
Number type to long since the return value from our mbean is of type long.
Init Threshold value to 2 so after 2 failed validations, the rule is going to write something to the
server log.
Offset to 1
Select the validationaction from the list under Action section for the action mbean name.



9. The management rule is successfully setup and once you have a test running that would change the validation failure values, the rule would play its role. Whenever the numConnFailVal value goes above 2, the following can be seen in the server.log



Validation  Failure Threshold Notification:%javax.management.monitor.MonitorNotification[
 source=com.sun.appserver.selfmanagement:numbertype=long,granularityperiod=1000,offset=1,
monitortype=countermonitor,initthreshold=2,version=3,observedattribute=NumFailValidation,
differencemode=false]
[type=jmx.monitor.counter.threshold][message=]|#]

[#|2008–10–13T18:14:59.683+0530|SEVERE|sun–appserver9.1|
javax.enterprise.system.core.selfmanagement|_ThreadID=30;_ThreadName=Timer7641;
_RequestID=c409bfc3–d0de
43f6a09f5ae1be9f0e51;|Logging selfmanagement event :
monitor:SEVERE:¦#]




SEVERE messages are because the log level was set to SEVERE while the rule was created.


This is just an example of how a JDBC pool monitoring attribute can be observed via mbeans and action taken above a threshold using a management rule. Any other meaningful action could be taken instead of the above.


Hope this is useful. :)

[2] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Troubleshooting locale problems with updatetool (GlassFish v3)

Wednesday Jun 04, 2008

When launching updatetool of GlassFish v3 on ubuntu, sometimes there are locale problems like the one below :


ValueError: unknown locale: en_IN 


 Troubleshooting this :


#export LC_ALL=C


and then launch updatetool.

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

GlassFish V3 - Using JDBC Connection Pool / JDBC Resource / MySQL

Saturday May 17, 2008


This blog talks about creating a JDBC Connection Pool and an associated JDBC resource with MySQL as the Database vendor.

The
default database "sakila" of MySQL is used in this example. All these
could be done so easily with Netbeans 6.1 after installing the
GlassFish V3 plugin. 

This screencast explains how to create a JDBC Connection pool in the
administration console and its associated JDBC resource. It also shows
a HelloWorld web application that used this resource to get some values
from a table in sakila database.

Watch the screencast :

 

GlassFish V3 TP2 JDBC 

Download GlassFish V3 TP2 from https://glassfish.dev.java.net/downloads/v3-techPreview-2.html
 

[3] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Management Rules - observedmbean property

Tuesday Nov 06, 2007

My previous blog on selfmanagement and https://glassfish.dev.java.net/javaee5/selfmanagement/selfmanagement_example.html explain how to create management rules with an example.

Assumptions : 

Same example as in the above link (memory rule) taken. 

Custom Mbeans  Memory (impl-class-name:com.sun.example.mbeans.Memory) and MemoryActionBean (impl-class-name:com.sun.example.action.MemoryAction) are deployed.

Problem : 

In GUI, when a new management rule is created following the steps and with the values :

Observed Mbean : com.sun.examples.mbeans.Memory

Observed Attribute : FreeMemory 

and other values as specified in the example,

the server.log shows an error message that the rule is not configured because of some errors. The log looks like


 MemRule;monitor;|SGMT0017:
Error creating and configuring the rule : MemRule due to
IlegalArguments specified for its event type : monitor. Create the
rule with correct arugments for the configured event.|#]


Solution :

Modify the domain.xml under install_directory/domains/domain1/config/ directory - edit the management rule MemRule :

Change the line

property name="observedobject" value="com.sun.example.mbeans.Memory"

to

property name="observedmbean" value="Memory"

 
Restart the server after this change. And you will see that the error message goes away. Note here that "observedobject" is changed to "observedmbean" and the new value is the name of the custom mbean deployed with the impl-class-name : com.sun.example.mbeans.Memory.

Explanation :

In GUI, the Observed Mbean takes values like
"user:impl-class-name=com.sun.example.mbeans.Memory,name=Memory,server=server".

This value is translated into "observedobject" property in domain.xml. Hence if you specify "com.sun.example.mbeans.Memory", in domain.xml you will see this value against the property "observedobject". 

Very few know that there is another property called "observedmbean" that accepts the mbean name directly. But in GUI, there is no explicit way of specifying this observedmbean property. One has to enter the whole object name for the input "Observed Mbean" in GUI, which will get translated into "observedobject" in domain.xml. Alternatively, domain.xml can be modified with observedmbean property.

Whereas in CLI, you could just specify the parameter "observedmbean"
with value "Memory" in the command line, without even specifying the "observedobject" property.

Ex: asadmin create-management-rule --port 4848 --user admin_user
--action  MemoryActionBean --eventtype monitor --eventloglevel WARNING --eventproperties
<blah-blah>:observedmbean=Memory:<blah-blah> rule_name

This is an advantage CLI has over GUI.  

 

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Troubleshooting - Cluster startup Failure

Tuesday Oct 30, 2007

Recently i had this problem.. I setup a cluster with an instance. But was not able to start it up. 

I got a series of  java.net.ConnectException: Connection refused exceptions and the instance did not startup.

What did the wonder?

 The /etc/hosts file had the following entries:

127.0.0.1 mymachine mymachine localhost

 When i commented out this line in the hosts file and add a physical IP entry like

129.xxx.xxx.xx mymachine

 and startup the instance, it goes through fine :)

 Reason

MQ needs the hostname to map to the absolute IP and not 127.0.0.1.


[3] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Lookup from Standalone Client

Friday Oct 26, 2007

My previous blog was about accessing a JDBC resource from an ejb. 

This blog talks about accessing the JDBC resource i created in the last blog, from a standalone client.

I use the same configuration from my previous blog : jdbc/cactus for my resource that needs to be accessed.

My sample will have the following code:

InitialContext ctx = new InitialContext();

javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/cactus";)

Connection c = ds.getConnection();

insert(......);

c.close();

Compile the sample

 Run the sample

 Note the included jars in the classpath

  • appserv-rt.jar
  • javaee.jar
  • appserv-admin.jar
  • imqjmsra.jar
  • derbyclient.jar

Also, observe the system properties for the server host and naming service port.

[1] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

JDBC resource lookup from EJB

Friday Oct 26, 2007

Accessing a JDBC resource from an EJB is a fairly simple thing to do. As simple as the following:

 
1. Start domain and database

After installing GlassFishV2, start the domain domain1 and start the database. I would be using Derby in this example. Derby can be started in 2 ways    

  • <INSTALL_ROOT>/bin/asadmin start-database
  • From netbeans : Tools -> Java DB Database -> Start JavaDB Server. The port settings for the server started up can be modified in ~/.netbeans-derby/derby.properties

 Now, the database is started at port :1527 and domain is running at 4848.

2. Create a JDBC Connection pool and JDBC Resource

 Login to the Admin Console (http://localhost:4848) and navigate to Resources->JDBC->ConnectionPools. Click on New and enter the details like Name:Cacti  ResourceType:javax.sql.DataSource DatabaseVendor:Derby. In the next screen, accept the default values but don't forget to enter the following additional properties

  • DatabaseName : sampleDB
  • ConnectionAttributes : create=true (if the sampleDB does not exist)
  • Password : dbpassword
  • PortNumber : 1527 (or the customized DB port)
  • ServerName : localhost
  • User : dbuser

Click on Finish. To verify, click on the 'Cacti' connection pool you just created and do a 'Ping connection Pool".

 Navigate to Resources->JDBC->JDBCResource on the left panel of the admin console and click on New. Specify a JNDI name as "jdbc/cactus". I chose to append the name cactus with jdbc since i am accessing a database. Choose the pool name you just created "Cacti" and click on 'OK'.

3. Access the resource in your app

Suppose i have an EJB that has to use this JDBC resource. This can be done as follows in the SampleEjb.java : test() method

InitialContext ic = new InitialContext();
DataSource ds = (javax.sql.DataSource) ic.lookup("jdbc/cactus";)

Connection con = ds.getConnection();

insert("something", ...., con);

con.close();

Create the appropriate Remote and Home interfaces.  

4. Specifying the appropriate deployment descriptors:

Consider this is a web application.

application.xml

 <application>
    <display-name>Sample EJB Test</display-name>
    <module>
            <web>
                <web-uri>sample-test.war</web-uri>
                <context-root>/sample-test</context-root>
            </web>
    </module>
    <module>
            <ejb>sample-test.jar</ejb>
    </module>
</application>

ejb-jar.xml

<ejb-jar>
    <description>Sample test</description>
    <display-name>Sample test </display-name>
  <enterprise-beans>
      <session>
          <description> Sample bean </description>
          <display-name> Sample bean </display-name>
          <ejb-name>SampleRemote</ejb-name>
          <home>examples.SampleRemoteHome</home>
          <remote>examples.SampleRemote</remote>
          <ejb-class>examples.SampleEjb</ejb-class>
          <session-type>Stateless</session-type>
          <transaction-type>Bean</transaction-type>
      </session>
  </enterprise-beans>
</ejb-jar>

 sun-ejb-jar.xml

<sun-ejb-jar>
        <enterprise-beans>
                <ejb>
                        <ejb-name>SampleRemote</ejb-name>
                        <jndi-name>SampleRemote</jndi-name>
                </ejb>
        </enterprise-beans>
</sun-ejb-jar>
 

web.xml 

<web-app>
    <distributable/>
    <servlet>
        <servlet-name>SampleTestServlet</servlet-name>
        <display-name>Sample Test Servlet</display-name>
        <servlet-class>servlets.SampleTestServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SampleTestServlet</servlet-name>
        <url-pattern>/SampleTestServlet</url-pattern>
    </servlet-mapping>
</web-app>
 

5. After all this coding, the structure would look like

/opt/sample
           -src
                -examples.SampleEjb
                -examples.SampleRemoteHome
                -examples.SampleRemote
                -servlets.SampleTestServlet
           -descriptor
                -ear
                    -application.xml
                -jar
                    -ejb-jar.xml
                    -sun-ejb-jar.xml
                -web
                    -web.xml
           -web
                 -index.jsp
           -build.xml
 

Build this application, create an ear and deploy this application on the application server via the admin console.

6. The Application can be accessed via http://localhost:8080/sample-test

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

2 Machine Cluster Setup - CLI mode

Wednesday Sep 05, 2007


Build : GlassFish V2 b58c on Solaris

Namesake names of machines : Tiger.cat.com, Cactus.plant.com

Using the Command Line Interface of GlassFish, a cluster can be setup with ease across 2 machines. Heres how it can be done:

1. Download GF v2 b58c from https://glassfish.dev.java.net/downloads/v2-b58c.html

2. Unbundle GlassFish following the instructions and do a ant -f setup-cluster.xml to enable clustering support on the installation.

Do Step2 on both Tiger.cat.com and Cactus.plant.com

3. On Tiger.cat.com, do the following:

  • Under {GF_install}/bin, do "asadmin start-domain" which will start up the default domain "domain1".
  • Create a node-agent as using the command "asadmin create-node-agent --host localhost --port 4848 man-agent"
  • Create a cluster with the command "asadmin create-cluster --host localhost --port 4848 cat-cluster"
  • Create an instance with the command "asadmin create-instance --host localhost --port 4848 --nodeagent man-agent --cluster cat-cluster instance1"

Note that in all the above steps, 4848 is the admin port of the domain domain1.

  • Start the node-agent : "asadmin start-node-agent --syncinstances=true man-agent"

The "syncinstances" flag starts up the cluster and instance as well. Its default value is false.


4. On Cactus.plant.com, do the following:

  • Under {GF_install}/bin, execute "asadmin create-node-agent --host Tiger.cat.com --port 4848 animal-agent" to create a node-agent on this machine pointing to the DAS (Tiger.cat.com).

After this step, observe in the /nodeagents directory that animal-agent is created.

  • Create an instance on this machine as "asadmin create-instance --host Tiger.cat.com --port 4848 --nodeagent animal-agent --cluster cat-cluster instance2"

  • Start node-agent, while the other node-agent is running: "asadmin start-node-agent --syncinstances=true animal-agent"

 2 machine cluster is successfully setup !!!

[11] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

In-line upgrade

Thursday Aug 09, 2007

In-line upgrade is performed when "asadmin start-domain" is invoked on a particular domain. asadmin is found in install_root/bin directory. The domain on which start-domain command is invoked, is evaluated if it corresponds to the latest binaries or it matches that of an old installation. For ex: Let us consider domain1 is started, it is checked if it is a v2 domain or v1 domain or an earlier 8.x domain. If it is not a v2 domain, upgrade tool is automatically invoked. The domain is upgraded maintaining all the old configuration. It becomes ready-to-use with v2 binaries. After an upgrade, this upgraded domain can be started for further deployment and other processing.


Let me explain this with an example.

Example : SJSAS8 is installed in /opt/sjsas. The domains root is /opt/sjsas8/domains with a single domain, domain1. When GlassFish is also installed in /opt/sjsas, the binaries are upgraded in /opt/sjsas directory. The domain still exists in /opt/sjsas/domains without any configuration upgrade. To do this upgrade, execute

/opt/sjsas/bin/asadmin start-domain --domaindir /opt/sjsas/domains domain1



Actual Process :

The asadmin command recognizes an old domain in the specified domain dir and performs upgrade by invoking upgrade tool with all the inputs needed. This is an in-line upgrade viz., the domains root will remain the same before and after the upgrade for both source and target.

Upgrade tool becomes the internal process that is forked. If an upgrade is not needed, the domain is started up, as usual.



Why this new type of upgrade?

Lot of reasons...


  • Simple way of doing an upgrade

  • asadmin start-domain command is known to all

  • Ease of use without knowing the internal process

  • No need to provide any inputs like source, target or credentials

  • Only inputs provided are domain name and domain directory, where it exists

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

GlassFish Upgrade Story

Tuesday Feb 27, 2007

Why do you want to upgrade?

Well!!! Lot of reasons!!! Take the example of a browser, mozilla. In the update center, you get to know some cool feature X has been released in the next version. You want to get the new version, but do not want to lose your current data and configuration, like bookmarks etc. Mozilla upgrades in the way we want to keep our customized data. When browser is restarted after an update, you see that cool feature X along with all your previous configuration.

Would this not be cool if something like this happens in the Application Server too. There are new versions of GlassFish coming up and you might want to do the same thing - upgrade from a previous version to the latest version. The good news is, you could do that!!! And i'm going to explain just that, with some links for you.

Some of the following terms speak a lot about the Upgrade tool of GlassFish.

Side-by-Side Upgrade:

Installing application server in different locations and performing an upgrade. For ex: SJSAS8 is installed in /opt/SJSAS8 and GlassFish is installed in /opt/GlassFish. When upgrade is performed from /opt/SJSAS8 to /opt/GlassFish, it is called a side-by-side upgrade.

In-place Upgrade:

Installing application servers in the same location. For ex: SJSAS8 is installed in /opt/Appserver and you would like to install GlassFish also in the same location, to save some space, the inplace upgrade happens.

Binaries Vs Configuration:

When you install GlassFish, you would see under the install root, "bin", "lib", "domains" etc. The "domains" directory would contain all the configuration information like "deployed applications" and customized settings pertaining to each of the domains under it. The other directories are the binaries of the application server you have installed, with which new features become usable. These include the "config", "bin", "lib" etc.

Upgrade:

When an upgrade is performed, the binaries and configuration, both have to be transferred. This could be done In-place or Side-by-side (explained above). In both the cases, the transfer of binaries is done by the GlassFish installer and the configuration transfer is done by the AS Upgrade Tool. This is clearly demarcated, in the sense that, a binary upgrade could be done with/without the configuration upgrade. The configuration is not affected unless the AS Upgrade Tool is invoked.

AS Upgrade Tool Functionality:

The Upgrade tool works in these simple steps. It could be invoked in the following ways :


  • Running asupgrade from the install_root/bin directory. This invokes the GUI mode of the tool.

  • Executing asupgrade -c from the install_root/bin directory. This invokes the CLI (Command Line Interface) mode of the tool.

  • asupgrade -c has some more options as well, for mentioning the source and target locations. For details, on this, refer the Upgrade tool manual.

When upgrade tool is invoked in one of the above modes, it prompts for the source and target locations. Here source location refers to the directory of the domain that needs to be upgraded. Target refers to the GlassFish application server domains root to which the configuration is to be upgraded. In an In-place upgrade, the domains root directory will be the same.

Apart from these, the admin credentials are also prompted for. When all these details are provided, upgrade tool creates the necessary domains, transfers the configuration, transfers the applications deployed, transfer the realms and logs all these into an upgrade.log. By all these what i mean is that, the domain.xml under domain config directory is modified to incorporate all the config changes from the source.

Links:

These are some of the links that could be useful to you.
1. Prasad's blog : http://blogs.sun.com/prsad/entry/upgrading_to_glassfish
2. AS Upgrade One Pager : http://www.glassfishwiki.org/gfwiki/attach/OnePagersOrFunctionalSpecs/upgrade-one-pager.html

[1] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Photos

Monday Jan 23, 2006

These are some of the snaps taken during the Cisco party.












[1] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

GlassFish : Self Management Rules

Thursday Jan 19, 2006

Self Management is an initiative taken in GlassFish to reduce the complexity of the management tasks. Mundane management tasks are automated by means of self-configuring. System Administrators who are responsible for monitoring the application server for unpredictable conditions no longer have to detect them manually. This is an easy-to-use feature that comes in handy at the unpredictable run-time conditions. This feature enables to recover from failures by detecting and preventing them, thus improving availability (self-healing). Even security threats are detected and self-protective actions are taken in response. The framework has been developed using standard technologies.

Self Management comprises of a set of management rules. You could create different rules based on the various event types. As mentioned at glassfish.dev.java.net, the different type of events are as follows.

  • Lifecycle events
  • Monitor events
  • Log events
  • Trace events
  • Timer events
  • Notification events
This blog is more about how to create management rules easily. I will show examples for some of the different type of rules. The action we take in response to the occurrence of an event, could be anything from sending an email notification to displaying an alert or killing some processes depending on what is appropriate for the particular event.

Let us take an example of displaying a pop-up window as an alert. Action mBeans implement the NotificationListener interface. The handleNotification() method for our action will look like the following.

    public synchronized void handleNotification(Notification notification,Object handback) {
        try {
            JFrame. setDefaultLookAndFeelDecorated(true);
            JFrame myFrame = new JFrame("MyAction");
            myFrame. setSize(250, 180);
            myFrame. setLocation(300,200);
            myFrame. getContentPane().add( new Label("Action has been invoked",Label.CENTER), BorderLayout.CENTER);
            myFrame. setVisible(true);
            myFrame. show();
        } catch (Exception ex) { // Log the exception }
    }

Let us name this class as CustomAction which is in the com.sun.myrule.action package. It has a corresponding CustomActionMBean. Follow these steps to deploy the action on the application server.

1. Compile the files and make a jar out of these two files.

2. After starting the application server, open the admin console by typing http://localhost:4848 on a browser.



Figure1: Admin Console


3. On the left pane, click on "Custom MBeans". On the right pane, all the deployed mbeans are listed. To deploy our action mbean, click on Deploy. Select the jar file that you just created against the "File to upload" column and click Next.



Figure2: Custom MBeans




Figure3: Creating Custom MBeans


4. Enter a name for the mbean. This will later be used while creating the rule. Enter name as "CustomAction".

5. Enter the class name along with the package name. In this case, it is com.sun.myrule.action.CustomAction.



Figure4: Creating Custom MBeans: Step 2


6. Click Finish.

The action mbean is successfully deployed on the application server.

We will use the same action mbean for all the rules. This action mbean will be called each time an event is triggered. For more information on actions, refer to actions section in glassfish.dev.java.net

Now let us proceed and create rules.

Simple rules for creating a rule:

1. Identify the event type you need. For example : lifecycle
2. Identify the mandatory and optional properties for that event type. For example : lifecycle event requires a property called "name".
3. Identify the action mbean you would like to use for your rule.
4. You could use the Application server Command line interface (CLI) or the Graphical user interface (GUI) to create rules.
5. Make sure the server is started before proceeding with rule creation.

Example 1 : Assuming the administrator wants to be notified everytime the application server shuts down or is terminated because of a failure. Continuous monitoring is necessary for this kind of a situation. Therefore, a rule could be created mentioning a notification to be sent to the administrator when this event is triggered. Management rule bundles together the event and the action.

Let us examine how this rule could be created.

After starting the application server with the command "asadmin start-domain", use either CLI or GUI to create the rule.

CLI mode :

/bin/asadmin create-management-rule
--host localhost --port 4848 --user admin
--action CustomAction
--eventtype lifecycle
--eventloglevel WARNING --eventproperties name=shutdown
my_lifecycle_rule

GUI mode :

  • Start admin console by typing http://hostname:port on a browser, after starting the application server.
  • Go to the Management Rules tab under the Configurations tab in the left pane. This displays the list of rules deployed on the server on the right pane.




  • Figure5 : Management Rules


  • Click on New
  • Type the name of the rule as "my_lifecycle_rule".
  • Check the Status checkbox to enable the rule.
  • Enter description
  • Choose event type as lifecycle.
  • Click on Next if you are done with this page.




  • Figure6 : New Management Rule


  • In the next page, select "shutdown" against Event and enter a description if desired.
  • Select "CustomAction" listed in the action list box and click Finish.




Figure7 : New Management Rule : Step 2


The rule is successfully created and is deployed on the application server. The action will be triggered everytime the application server shuts down. Similarly, rule could be configured to take some action on ready and termination.

Example 2 : The administrator wants to be beeped once in a while regarding some status. A rule could be created to do this as follows.

CLI mode :

/bin/asadmin create-management-rule
--host localhost --port 4848 --user admin
--action CustomAction
--eventtype timer
--eventloglevel INFO
--eventproperties pattern=MM\\/dd\\/yyyy\\/HH\\:mm\\:ss:
datestring=01\\/20\\/2006\\/12\\:00\\:00:
period=30000000:
message=Hello
my_timer_rule

Note here that "/" and ":" are escape sequences. Period, mentioned in milliseconds, is the period after which the notification is to be sent after the date mentioned in datestring.

GUI mode :
  • Start admin console by typing http://hostname:port on a browser, after starting the application server.
  • Go to the Management Rules tab under the Configurations tab in the left pane. This displays the list of rules deployed on the server on the right pane.
  • Type the name of the rule as "my_timer_rule".
  • Check the Status checkbox to enable the rule.
  • Enter description
  • Choose event type as timer.
  • Click on Next if you are done with this page.
  • Enter the values for datestring, pattern and other fields.
  • Select "CustomAction" listed in the action list box and click Finish.
Another example of a rule to monitor the runtime memory of the JVM can be found here .

Like this post? del.icio.us | furl | slashdot | technorati | digg