Saturday, January 31, 2009

DB2 on Rails

It's time to test running Rails with DB2 as the backend.

I downloaded the information from http://www.alphaworks.ibm.com/tech/db2onrails.

I am running on Linux, so I did:

  • export DB2DIR=/opt/IBM/db2/V9.1_01
  • export DB2LIB=/opt/IBM/db2/V9.1_01/lib32
then:

  • cd Source
  • rake
It failed with the following message:

checking for SQLConnect() in -ldb2... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Looking at the mkmf.log, I see:

conftest.c:3: error: ‘SQLConnect’ undeclared (first use in this function)
conftest.c:3: error: (Each undeclared identifier is reported only once
conftest.c:3: error: for each function it appears in.)

  • It seems the environment variables were not set properly.
  • I ran it again and got the following message:
Database environment is not set up
Run ". /home/db2inst1/sqllib/db2profile" and retry


After sourcing the db2profile, I ran with the following messages:

Loaded suite tests
Started
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
Finished in 0.593455 seconds.

But I seems the shared library has been generated successfully.

  • cp ibm_db2.so /usr/local/lib/ruby/site_ruby/1.8/i686-linux/
Installing the Adapter

  • cp ibm_db2_adapter.rb /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/
  • vi /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record.rb

Well, after trying that without success, I found the following response in the forum:

Given that RAILS_CONNECTION_ADAPTERS went away, the IBM gem is no longer called "ibm_db2", and that the minimum software requirements have changed, I recommend skipping the "Toolkit for DB2 on Rails" and to start learning about the "ibm_db" gem here: http://rubyforge.org/projects/rubyibm/

N.B. The unwarranted license of DB2 Express-C is currently limited to using 2 processor cores & 2 GB of memory. However, it's still a better option than "Oracle XE".

Starting from scratch...

Monday, January 12, 2009

Ruby and DB2

The next step is my Ruby adventure is to use DB2 as the data source. This will allow to plug RoR to many applications that have DB2 as the backend.

* Some instructions on how to download the DB2 driver is described at: http://wiki.rubyonrails.org/rails/pages/IBM+DB2

* After that, let me try to scaffold a DB2-based application: Tivoli Process Automation Engine

* cd ~/Rails
* mkdir TPAE
* cd TPAE
* rails tpae
* cd tpae/config
* vi database.yml

development:
adapter: ibm_db
database: maxdb71
username: maximo
password: itsmswat
schema: maximo
host: ismdbserver.tivlab.raleigh.ibm.com
port: 50005


* rake db:migrate --trace
* It failed with the following message:
Failed to connect to the [maxdb71] due to:
* It seems the problem is related because I forgot to load the DB2 profile
* . ~db2inst1/sqllib/db2profile
* rake db:migrate --trace
* I got a different problem:
Failed to connect to the [maxdb71] due to: [IBM][CLI Driver] CLI0133E Option type out of range. SQLSTATE=HY092 SQLCODE=-99999
* export LIBPATH=/home/db2inst1/sqllib/lib
* It seems I need to read some instructions on http://www.alphaworks.ibm.com/tech/db2onrails. Another day.

Wednesday, January 7, 2009

Ruby plugin for Eclipse

I found a Ruby plugin for Eclipse at: http://update.aptana.com/update/rails/3.2/

I had first to install Eclipse Monkey, described at http://www.brain-bakery.com/projects/articles/eclipse-monkey-scripting/. Also I had to install the Aptana Studio from: http://www.aptana.com/docs/index.php/Plugging_Aptana_into_an_existing_Eclipse_configuration

There are some instructions on how to use at: http://www.ibm.com/developerworks/opensource/library/os-rubyeclipse/

Saturday, January 3, 2009

My first experience with Ruby on Rails

It's a new year, so I decided to learn a new language / environment. I chose Ruby on Rails,so here comes my experience.

I am following the tutorial at: http://www.onlamp.com/pub/a/onlamp/2006/12/14/revisiting-ruby-on-rails-revisited.html, which has been written for Rails 1.2.6. My environment thou is Rails 2.0. So, here are the steps I followed:

  • cd ~/Rails
  • rails cookbook2
  • cd cookbook2
  • rake db:create:all
  • ./script/generate scaffold Category name:string
  • rake db:migrate
  • ./script/server
Then point your browser to http://localhost:30000. It shows the RoR welcome page.

  • Go to file config/routes.rb and file the following line:
ActionController::Routing::Routes.draw do |map|
map.root :controller=> 'categories'
map.resources :categories

Now point your browser to http://localhost:3000/categories, and you are ready to create categories!

Creating the recipe table

  • ./script/generate scaffold Recipe category:references title:string description:string instructions:text
  • rake db:migrate
Now point your browser to http://localhost:3000/recipes and you're ready to create recipes!

Wednesday, November 12, 2008

Scripts to start the TPAP components

These are the scripts used to start the TPAP (CCMDB, TAMIT) components:

startmw.sh
su - db2inst1 -c "db2start"
su - ctginst1 -c "db2start"
su - idsccmdb -c "db2start"
/opt/ibm/ldap/V6.1/sbin/32/ibmdiradm -I idsccmdb
/opt/ibm/ldap/V6.1/sbin/32/ibmslapd -I idsccmdb

startwas.sh
/opt/IBM/WebSphere/AppServer/profiles/ctgDmgr01/bin/startManager.sh
/opt/IBM/WebSphere/AppServer/profiles/ctgAppSrv01/bin/startNode.sh
/opt/IBM/WebSphere/AppServer/profiles/ctgAppSrv01/bin/startServer.sh MXServer

stopwas.sh
/opt/IBM/WebSphere/AppServer/profiles/ctgAppSrv01/bin/stopServer.sh MXServer -username wasadmin -password itsmswat
/opt/IBM/WebSphere/AppServer/profiles/ctgAppSrv01/bin/stopNode.sh -username wasadmin -password itsmswat
/opt/IBM/WebSphere/AppServer/profiles/ctgDmgr01/bin/stopManager.sh -username wasadmin -password itsmswat

stopmw.sh
/opt/ibm/ldap/V6.1/sbin/32/ibmslapd -k idsccmdb
/opt/ibm/ldap/V6.1/sbin/32/ibmdiradm -k idsccmdb
su - db2inst1 -c "db2stop force"
su - ctginst1 -c "db2stop force"
su - idsccmdb -c "db2stop force"

Monday, November 10, 2008

Explaining the Initialization mode in a TDI Loop

Very often with TDI, it's necessary to put a Loop in an Assembly Line, so that the Work Entries from the Feed can be used to perform another query to retrieve some data. An example is with Tivoli Application Depdendency Discovery Manager (TADDM) and obtaining all IP addresses for a ComputerSystem. The IP addresses are attributes of the IpAddress object, which is related to an IpInterface, which is then related to a ComputerSystem object, so in order to retrieve the IP addresses of a Computer System we need to correlate ComputerSystem, IpInterface and IpAddress.

To do that using TDI (avoid the need to process XML files or write Java code), we can use the TADDM Connector, available at: Tivoli OPAL

As the TADDM Connector allows to specify the depth of the query, our first inclination is specify depth=3, which would directly return all attributes from the ComputerSystems and related object in just one shot. This approach is great and simple, but puts a lot of work on TDI (and TADDM server) to retrieve all attributes of depth 3, which can easily turn to be thousands, for each Computer System. For an environment containing about 2500 servers, it took 15 minutes to retrieve the IP addressses and dump them in a very simple Assembly Line.

A second option is to read only the attributes of ComputerSystem (at depth 1), then put a Loop to retrieve the IpInterfaces, linking them to the ComputerSystem and reading at depth 2. The Assembly Line is a little bit more complicated, and the main problem is that the AL takes 36 minutes, instead of the previous version.

The reason for this performance degradation is the fact that TDI is re-initializing the connection to TADDM for every single ComputerSystem. Looking at the Loop, by default TDI uses Initialize and Select/Lookup as the Init Options, which means that the Connector is initialized every time. Changing it to Select / Lookup only leads to a running time of mere 6 minutes!

So take good care of your TDI Loop!

Eddie, so far no JavaScript code!

Friday, November 7, 2008

Splitting multi-valued variables in TDI

In many cases, we have an entry with multiple values (separated by comma, for example), and we need to split those values and process one at a time.

Assuming there is an entry with the following values:

10.4.128.24, 10.4.128.160, 10.4.128.161, 10.4.128.220, 10.4.128.227, 10.4.128.229, 10.4.128.231, 10.4.128.232, 10.4.128.209, 10.4.129.24

Here are the steps to process each value at a time:

  • In your AL, add a script component with the following code
    multiValued = work.getString ("MultiValued");

    task.logmsg ("multi valued: " + multiValued);

    tokenizer = new java.util.StringTokenizer (multiValued, ",");
    work.setAttribute ("values", null);

    while (tokenizer.hasMoreTokens ()) {
    token = tokenizer.nextToken ();
    task.logmsg ("value: " + token);
    work.addAttributeValue ("values", token);

    }
  • Add a Loop to your AL
  • In the Loop, select Attribute Value Loop
  • In the Work Attribute Name, type values (which matches the Work Entry defined in the code above)
  • In the Loop Attribute Name, type value
  • Inside the loop, you'll have the value Work Entry with a single value to process.
That's it!