Friday, April 28, 2006

Installing a Second MySQL

* I needed to set up several different instances of MySQL on the same Linux hosts--we needed completely separate DBMS for two separate projects.

* The following tricks were gleaned from various Google searches. Through Google, all things are possible. I have attributed helpful sites here and there but not everywhere. http://www.analysisandsolutions.com/code/mybasic.htm
was useful.

* The first DB was installed in /usr/local/mysql in the usual way.

* For the second installation, I first created a new user, "mysql_two". Put the mysql binary under this directory but don't install it yet.

* I then added entries to the /etc/sudoers file for each user who needed access to this second DB. This looks like this:
[shell-prompt> more /etc/sudoers
...
# User privilege specification
root ALL=(ALL) ALL
joeuser ALL=(mysql_two) ALL
moeuser ALL=(mysql_two) ALL

* This allows joeuser and moeuser to run all commands as mysql_two through the sudo command. For example,

[joeuser@gomoejoe> sudo -H -u mysql_two /bin/bash

allows joeuser to login as user mysql_two using the joeuser password. For multiple users, this is convenient since you don't need to share passwords. You can also be more conservative and grant permission to run only specific commands.

* The -H option in sudo sets the $HOME to mysql_two and will source /home/mysql_two/.bashrc, which willbe useful in a minute.

* Now the next problem is that you already have MySQL installed, so you need to specify different data directories, port numbers and so forth for installation #2. All of these are defined in /etc/my.cnf by default (cat this to see).

* To override these /etc/my.cnf settings for mysql_two, I used the $MYSQL_HOME environment variable. See
http://dev.mysql.com/doc/refman/5.0/en/option-files.html
. I added this env variable to the /home/mysql_two/.bashrc file:

export MYSQL_HOME=$HOME

* Catting $MYSQL_HOME/my.cnf gives
-----------------------------------------
[mysqld]
datadir=/usr/loocal/mysql_two/data
socket=/usr/local/mysql_two/mysql.sock

[mysql.server]
user=mysql_two
basedir=/usr/local/mysql_two

[safe_mysqld]
err-log=/usr/local/mysql_two/mysqld.log
pid-file=/usr/local/mysql_two/mysqld.pid
port=44070

-----------------------------------------

* Note there is a problem with this file, so keep reading.

* You can now install mysql_two. You need to vary the usual MySQL INSTALL_BINARY instructions a bit. Do the following:

[root@gomoejoe root]# mkdir /usr/local/mysql_two
[root@gomoejoe root]# chown -R mysql_two:mysql_two /usr/local/mysql_two/
[root@gomoejoe root]# su - mysql_two
[mysql_two@gomoejoe mysql_two]$ cd mysql
[mysql_two@gomoejoe mysql]$ ./scripts/mysql_install_db

Note these directories correspond to your $HOME/my.cnf settings. I put this in /usr/local so that I could run multiple mysqls on several machines with NFS mounted files. You can simplify this by just using /home/mysql_two if you are not using NFS.

* Now verify your installation with "$HOME/mysql/bin/mysqladmin -version" from the mysql_two account. You will get the following error:

[mysql_two@gomoejoe mysql]$ ./bin/mysqladmin version
./bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

* http://www.tech-recipes.com/mysql_tips762.html
had the answer. With Google and a firm place to type, I can move the Internet. I added the [client] line to $HOME/my.cnf, so it now looks like this:

[mysql_two@gridfarm005 mysql]$ more /home/mysql_two/my.cnf
[mysqld]
datadir=/usr/local/mysql_two/data
socket=/usr/local/mysql_two/mysql.sock

[mysql.server]
user=mysql_two
basedir=/usr/local/mysql_two

[client]
socket=/usr/local/mysql_two/mysql.sock
port=44070

[safe_mysqld]
err-log=/usr/local/mysql_two/mysqld.log
pid-file=/usr/local/mysql_two/mysqld.pid
port=44070


* mysqladmin -version now works.

Tuesday, April 18, 2006

Some Apache Axis Notes

* Here are some of my notes while debugging an Axis service. I'm
editing them a bit to make them more general. Hopefully these
will be useful if you are looking for a quick guide.

* I realize you can do all of this with Maven or Ant, but
sometimes you just have to roll up your sleeves and do stuff
on the command line.

* Get a clean tomcat and install axis. I'm using Axis 1.3 for
historical reasons.

* You will need to get activation.jar to make axis happy.

* I'm also using Tomcat 5.5.12 and Java 1.5.

* I separated client and server code into separate directories. Here is the
file listing.

------------------------------------------------------
[gateway@gridfarm002 ws_GenericScript]$ ls -l
total 32
drwxr-xr-x 2 gateway gateway 4096 Apr 17 23:02 bin
drwxrwxr-x 3 gateway gateway 4096 Apr 18 11:03 client
-rw-r--r-- 1 gateway gateway 1765 Apr 18 11:01 deploy.wsdd
drwxrwxr-x 2 gateway gateway 4096 Apr 18 11:00 Junk
-rw-r--r-- 1 gateway gateway 169 Apr 17 22:59 README
drwxrwxr-x 3 gateway gateway 4096 Apr 18 11:05 server
-rw-r--r-- 1 gateway gateway 676 Apr 18 11:01 undeploy.wsdd
-rw-r--r-- 1 gateway gateway 2629 Apr 17 23:03 ws_generator.jar
[gateway@gridfarm002 ws_GenericScript]$

[gateway@gridfarm002 ws_GenericScript]$ pwd
/home/gateway/SoapStringWeirdness/ws_GenericScript
[gateway@gridfarm002 ws_GenericScript]$ ls -l server/genericScript/
total 12
-rw-r--r-- 1 gateway gateway 5088 Apr 17 21:40 GenericScriptImpl.java
-rw-r--r-- 1 gateway gateway 125 Apr 17 14:36 GenericScript.java
[gateway@gridfarm002 ws_GenericScript]$

[gateway@gridfarm002 ws_GenericScript]$ ls -l client/genericScript/client/
total 4
-rw-r--r-- 1 gateway gateway 981 Apr 17 21:37 GenericScriptClient.java
--------------------------------------------------------

* Copied activation.jar and the application specific
ws_generator.jar into axis/WEB-INF/lib

* Set my classpath to include the Axis jars and the ws_generator.jar:
export $TOMCAT_HOME=/path/to/tomcat/
export CP=`echo $TOMCAT_HOME/webapps/axis/WEB-INF/lib/*.jar | tr ' ' ':'

Note I don't use CATALINA_HOME since this will cause problems if set as environment
variable. Also, I use $CP instead of $CLASSAPTH to avoid CLASSPATH problems.

* I decided that the server code (GenericScriptImpl.java), needed some simple sanity
checking methods, so I added these:

public void emptyTest() {
System.out.println(this.toString()+" empty test called");
}

public String echoTest(String toEcho) {
System.out.println(this.toString()+" echo test called");
return toEcho;
}


* Compile the server code into axis. Make sure the classes directory exists.
javac -d $TOMCAT_HOME/webapps/axis/WEB-INF/classes/ -classpath $CP server/genericScript/*.java

* Start tomcat and deploy the service. I'm using the following simplified deploy.wsdd:

<deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
<service name="GenericScript" provider="java:RPC" >
<namespace>http://soapinterop.org/</namespace>
<parameter name="className" value="genericScript.GenericScriptImpl" />
<parameter name="allowedMethods" value="*" />
</service>
</deployment>


* I use the following deploy command:
[gateway@gridfarm002 ws_GenericScript]$ java -classpath $AXIS_LIB org.apache.axis.client.AdminClient -lhttp://gf2.ucs.indiana.edu:8080/axis/services/GenericScript deploy.wsdd

* Pointed browser at the service lister to verify that the service was deployed:
http://gf2.ucs.indiana.edu:8080/axis/servlet/AxisServlet. This is linked from the
main Axis page: http://gf2.ucs.indiana.edu:8080/axis/.

* To undeploy the service, the simplest thing to do is shutdown tomcat, edit server-config.wsdd, and
cut out the service description for the no-longer-desired service. Then restart tomcat and
check the listings.

-------------------------------------------------------------------

* Now we can turn to the client. We need to generate client stubs from the WSDL. I just downloaded
this from the Axis service for simplicity: http://gf2.ucs.indiana.edu:8080/axis/services/GenericScript?wsdl.
Saved this to a file. The UNIX wget method is useful here.

* I then executed the following command in the ws_GenericScript (i.e. main) directory.

java -classpath $CP org.apache.axis.wsdl.WSDL2Java -o ./client -p genericScript.ws GenericScript.wsdl

The -p option specifies the package/directory structure for the generated files and -o specifies
the directory where the stubs are coughed up.

* Now I compile the client and the client stubs. Compile the stubs first and then compile the client.
Here is the command for compiling the client:

javac -d /tmp/ -classpath $CP client/genericScript/ws/*.java

Note I'm putting these in the /tmp/ directory. This is just to keep it separate from the service
code.

* I next compiled the client application that uses the stubs. I used this command:
javac -d /tmp/ -classpath $CP:/tmp/ client/genericScript/client/*.java

* Note the key parts of the client application are these:

String theUrl="http://path/to/service/";
genericScript.ws.GenericScriptImplService eosService=
new genericScript.ws.GenericScriptImplServiceLocator();
genericScript.ws.GenericScriptImpl eos=
eosService.getGenericScript(new URL(theUrl));

Monday, April 03, 2006

Using Maven 2 for Web Service

Following is the Quick Start Guide for using Maven 2 for the Web Service
(1) Download Maven 2 from http://maven.apache.org/download.html by selecting proper file for your machine platform
(2) Unpack the archive, eg: tar zxvf maven-2.0.tar.gz or unzip maven-2.0.zip. A directory called "maven-2.0" will be created.
(3) Add the bin directory to your PATH, eg: export PATH=/usr/local/maven-2.0/bin:$PATH or set PATH="c:\program files\maven-2.0\bin";%PATH%
(4) Make sure JAVA_HOME is set to the location of your JDK
(5) Run "mvn --version" to verify that it is correctly installed
(6) Now create Web application project by running following command
mvn archetype:create -DgroupId=example1 -DartifactId=portlet1 -DarchetypeArtifactId=maven-archetype-webapp
This command will create a new project called "portlet1" specifically for web application
(7) create folder "java" under portlet1/src/main and put all the .java files under this folder
(8) To compile the java file you may need some jar files. you can specify the jar files in pom.xml file located under portlet1 directory. when you specify particular jar file in pom.xml file, during compilation it will search that file first in http://www.ibiblio.org/maven2/(ibiblio repository). If that file is not available in ibiblio repository it will try to find out in local repository.
(9) If you want to specify the jar file required during compilation and available in ibiblio repository, add following lines in pom.xml file
<dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<scope>compile</scope>
</dependency>
E.g If you want to specify "antlr2.7.1.jar" file in pom.xml then follow this link of ibiblio repository http://www.ibiblio.org/maven2/antlr/antlr/2.7.1/antlr-2.7.1.pom and copy following three tags from .pom file under dependency tag.
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.1</version>
(10) Another possibility is, if your required jar file is not available under ibiblio repository.you can either copy that jar file into local repository or can
create remote repository. To copy the jar file into local repository you can use following command at local repository directory(~/.m2/repository in unix).
E.g. mvn install:install-file -Dfile= jar file location -DgroupId= -DartifactId= -Dversion= -Dpackaging= jar
(11) you can create a remote repository by installing all the required jar files by using above mentioned command directly to server's/webapps(E.g tomcat server/webapps/CICC) folder and can access it via URL.
E.g http://gf8.ucs.indiana.edu:9080/CICC
(12)when you are going to use jar files from remote repository you have to mention it in pom.xml file like this
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://www.ibiblio.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://gf8.ucs.indiana.edu:9080/CICC</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
(13) When you have all the required jar files for compilation of java files then you can compile all the java files by using "mvn compile" command
(14) To create war file for this project run "mvn install" command
(15) Put war file under server's/webapps folder and restart the server
(16) To make a web service you must have all the other required files from axis folder. Copy all the required files example server-config.wsdd etc from axis folder. Restart the server. Deploy web service by command java org.apache.axis.client.Adminclient deploy.wsdd
for more details follow Axis tutorial on how to deploy a web service.
(17) restart the server. and you will be able to see the deployed web service