Wednesday, September 22, 2004

ANT logging PART I

Imagine a scenario where at the end of day the application you are developing needs to be built from source. Furthermore, the application data needs to be synced with the development database and LDAP server. One can do all this using ANT scripting thanks to the powerful and extensible architecture of ANT. But what if something, anything goes wrong with the script at runtime? What ANT safeguards exist in place for error-reporting and error-handling?

One solution is to write custom tasks during critical junctures in the ANT script to validate the results of the build process. Any errors caught by the validation process can then be logged/e-mailed to the developers for troubleshooting. Since custom ANT tasks are written in Java, the tasks are free to use JavaMail, Apache Commons Logging, or Log4j for error handling and logging.

A critical problem exists in this approach. Suppose your scripts use built-in ANT tasks or third-party tasks that terminate abnormally. In the worst case scenario, as when the tasks throw the BuildException, the entire build script would terminate with an error return code. If your validation tasks is executed after the point of error, they will never be run. In other words, when an ANT script terminates abnormally, you may never get to run your validation code, and never receive notifications of the failure.

A better solution is to configure log4j as the appender for ANT. This way you have the full gamut of Log4j appenders at your disposal. For example, you can log at the INFO-level all the ANT script messges using the RollingFileAppender, and you can e-mail all ERROR-level messages using SMTPAppender. To use Log4j as the default logger, simply place the log4j.jar file along with the log4j.properties file in the execution classpath of the ANT script, and type in the following command to execute the script:

ant -listener org.apache.tools.ant.listener.Log4jListener [target name]

Once you configure Log4j as the logger, ANT environment would still send out a one-line error message in the case of an abnormal termination. That line can then be e-mailed to the proper personnel.

Two drawbacks exist with this approach.

First, you may have more than one ANT build scripts running under the same environment. You may not wish them to have the same Log4j configurations. You may, for example, wish to e-mail different people depending on which ANT script failed. That information cannot be specified using the one-line command above.

Second, you may not wish to maintain multiple configuration files for ANT and Log4j under a single application.

The next part of this series would explore how you can overcome the abovementioned problems.


Thursday, September 16, 2004

Recall your previous command in Unix

1. set -o vi
2. Escape + k for previous command
3. Escape + j for next command

SQL query to identify list of duplicate rows

First technical post. I am going to make it a bit lighter fare. The following SQL script example shows how to identify duplicate rows in a data table.

SELECT col1, col2, count(*)
FROM t1
GROUP BY col1, col2
HAVING count(*) > 1

The query was ripped from a Microsoft article, which has further information on how to remove duplicate rows.
http://support.microsoft.com/default.aspx?scid=kb;en-us;139444

Objectives for this blog

First, the primary audience for this blog is me. I keep my accumulated technical reference for future reference.

Those who are in my field may find some snippets interesting and helpful.

Those are the goals I have set out to achieve:

1. The purpose of the journal should remain technical. In other words, no bullshit personal stuff and random ramblings except maybe this post.
2. The technical articles should remain technical. Personal opinions of specific products/companies/technologies should be expressed only with evidence.

That's it.