Thursday, September 29, 2011

JBoss Database Failover & High Availability Datasource

A high availability Datasource is an abstraction over a list of data sources that provide failover processing between lists of data sources. In Weblogic, we can configure multi-pool which provides us the same functionality.

The configuration of Multi pool sort of thing in JBoss is done in a different way. In Weblogic, we configure multiple data sources and configure them in one multi pool such that when a Datasource fails to connect, the servers use the second Datasource to get a connection.

In JBoss, we don’t need to configure multiple data sources rather we configure the URL’s in one Datasource file like,

<?xml version="1.0" encoding="UTF-8"?>







The main points to check are the

<connection-url>|</connection-url> : Url separated by a delimiter “|”

<url-delimiter>|</url-delimiter> :  Holder used as a delimiter

Now, we can test the Datasource from the admin-console. If we need to test the fail over capabilities, then modify the one of the URL and test the connection. You can see an error on command console and connection will be obtained from second URL.

Note: we can use connection.getMetaData().getUrl() , to find which URL is used to get the connection. In this way we can make sure the fail over is working.

More articles to come. Happy coding…
Read More

Monday, September 26, 2011

Finding with Find in Linux

Linux find command is one of the most useful command available in Linux. It is different from other linux commands since its syntax varies from all other commands. It is power full, allow you to search files by file names, time stamp, by type and even by user.
The purpose of this article is to provide a basic introduction of using the find command. The basic syntax looks as,
find   start_directory  test  options   criteria_to_match action_to_perform_on_results
There are command expressions that we can use with linux find command to get better results. Here are some of the basic expressions that we can use,

  • -print - Produce output.
  • -name - Matches filename based on the pattern provided.
  • -perm - Find files with certain permission.
  • -type - Find files with special file type.
  • -size - Find files based on file size.
  • -atime, ctime, mtime - Find files based on file times.
  • -exec - Executing command.

Print: Outputs the contents of the current directory to the screen

find ( Or) find . (Or) find –print: will print all the files in the current directory.

Name: The name expression allows finding files by names.

find /root/ -name samlist : Looks for a file named “student" starting at the root directory (searching all directories including mounted file systems).

find /etc –name “sysc*” : Finds all files that start with sysc in /etc directory.

Now let’s try

find . –name “*.log”

The above command allows you to search files in the current directory [“. “ ] and which has extension log.

We can also try to find files in multiple locations like,

find /root /etc –name “sysc*”: finds all files in both /root and /etc with name starting with sysc.

Iname : By default find command is case – sensitive, in order to make it case – insensitive, we need to use iname in place name.

find . -iname “*.log” : Find all files which end with log

Type: allows find files by type like ,

find /root –type d : show all the sub  directories in the /root directory
find /root –type f : shows all the files in /root directory.

Other basic types are,
·      b—block (buffered) special
•  c—character (unbuffered) special
•  p—named pipe (FIFO)
•  s—socket
·      d-directory
·      f-file
·      l-symbolic link

Size : This expression allows finding files by size.

find . –size 10k : find all files whose size are 10k

  -n: less than n
  +n: greater than n
  n:exactly n

Time Stamp: The find command has several options that can be used for search files based    on the time stamps,

mtimethe time that the contents of a file were last modified
atime—the time that a file was read or accessed
ctime—the time that a file’s status was changed

With Pipes and Re-direction: We can use pipes and input-output redirection along with find command like

find . -name "sam*" > samtoo: find the list of files which start with sam and then copy them to file samtoo.

find . -name "sam*" | wc –l: find the list of files which start with sam and sent the list to wc command to get the count.

Perm: allows finding files based on permissions

find /root –perm 740: find all files in /root with permission 740

find -perm 740 -size -20k : find all files with 740 permission and size less that 20k

find /home –user postgres : find all files that belong to the user postgres.

find /root –user jagadesh : find all files that belong to a user jagadesh in /root

find /home –group postgres : find all files that belong to the group postgres.

MaxDepth & MinDepth : maxdepth and mindepth allows you to find files by checking the level of directories given by us,

find /etc –maxdepth 1 –name passwd : find files in /etc and one level subdirectory for the file named passwd.the output will be


find /etc –maxdepth 2 –name passwd : find all files in /etc/ and in 2 level of sub directories which result in


Accessed, Last Accessed and Newer : we can also find files based on status of the other files like,

find . –anewer sam1 : find files that are accessed before the file sam1

Some other expressions include,

cnewer: find files whose content last is changed before the file .
find . -cnewer sam4

newer: find files that were modified more recently than this file.
find . -newer sam4

used: file was last accessed n days after its status was changed
find . -used 2

Other expressions

find . -empty -name "sa*" : find empty files


We can perform various kinds of actions on the results of the find command.

find /etc/ -maxdepth 3 -name passwd -exec wc {} \;  : find files in /etc with maxdepth of 3 for the file named passwd and send the results to wc command using exec to find the lines words information in files.

find . -name "sam*" | xargs grep "Too"  : Find files which start with sam and send the output to the xargs command to grep for the word “Too” in files.

 find . -type f -name '*.log' -ok rm {} ';' : This allows the find command to pause and get confirmation before executing the command on the files found

More about the actions in next articles. Happy Coding..
Read More

Wednesday, September 14, 2011

Farming Service In JBoss

There are other options for deploying an application in JBoss application server. One such option was using a farming service. Farming service allows us to hot deploy a application (ear, war and sar e.t.c) into the application server. The application needs to be copied directly into the farm directory located in your server profile. Once the application is copied into the farm directory to a server, the other servers which are in cluster will also get the application deployed into their farm directory locations.

Some important Points:

Consider there are 2 servers in the Cluster, prod1 and prod2.

  1. Once the application is copied into the prod1/farm directory, the prod2/farm directory will also get the copy of the application since they are in cluster.
  2. If the prod1 server is running in the cluster and prod2 is shutdown, then if the application is copied into the prod1/farm location and the prod2 is started.prod2/farm will get the application into its farm directory since they are in cluster
  3. If the application is deleted from any one server/farm location, all other servers will also remove the application from their farm locations.
  4. When we copy a application into the /farm location and then start the server to be added to already running Cluster, the /farm location content will not be replicated into the other servers /farm location since the farm service is  not aware that the content in the newly joined server is a new deployment or a already existing one that has been removed while the newly joined server is offline.
  5. Currently farm service supports only achieved files, but not the exploded directories. This is because when the directories are copied, they are copied piece by piece and in mean time any other server in the cluster may try to replicate the content in /farm directory which is not completely copied.
  6. Farming is not recommended for production environment , since

It is not atomic, that is deployment, or undeployment done on one application in prod1/farm location does not mean that it will do the same on other servers in cluster.

It may cause unexpected behavior, if farm server sitting on the disk gone bad, then the application in other server/farm locations too will undeployed or deleted.

  1. Farm service is simply an extension to the URLDeploymentScanner.
  2. The options for the Farm service are available in /deploy/Cluster/farm-deployment-jboss-beans.xml                                                                                                                                   
That is all about farming service. Practice with farm service.
More articles to come. Happy Coding.
Read More