Integrate Java Tango servers with Astor

Integrate Java Tango servers with Astor#

audience:administrators audience:developers lang:java

Problem overview#

One wants to control Java Tango servers using Astor after deployment.

Detailed cases#

Simplify deployment and integration of new Java Tango servers with existing Tango environment. Give users ability to use well known tools for controlling and monitoring Java Tango servers.

Solution overview#

The following describes solutions for linux. Windows users may use the same strategy except bash files must be replaced with corresponding batch files.

There are two possible ways we can prepare this receipt:

  1. Generate fat jar, i.e. executable jar that contains everything.

 1    <!—pom.xml –>
 2     3    <build>
 4            <plugins>
 5                <plugin>
 6                    <artifactId>maven-assembly-plugin</artifactId>
 7                    <!—assemble executable jar with all dependencies –>
 8                    <configuration>
 9                        <appendAssemblyId>false</appendAssemblyId>
10                        <descriptorRefs>
11                            <descriptorRef>jar-with-dependencies</descriptorRef>
12                        </descriptorRefs>
13                        <archive>
14                            <manifest>
15                                <mainClass>hzg.wpn.tango.TestServer</mainClass>
16                            </manifest>
17                        </archive>
18                    </configuration>
19                </plugin>
20            </plugins>
21        </build>
22    

Executing mvn assembly:single produces one big jar file in the target folder, i.e. TestServer-1.4.jar.

To use our server we just copy it to some location on the target machine and use the following bash script:

1    #!/bin/bash
2
3    /usr/bin/java -jar /absolute/path/to/our/jar $1 hzg.wpn.tango.TestServer $1

Do not mind the last two parameters they are here to workaround an issue.

This script is saved into /usr/lib/tango/server/TestServer. /usr/lib/tango/server can be replaced with any other location where Starter can find the script, i.e. defined in StartDsPath property.

We need to specify an absolute path to the jar file as Astor runs servers from /var/tmp/ds.log folder

PROS

  • It is much easier to deal with immutable artifacts

CONS

  • A lot of duplication, imagine 1000 servers each requiring 17MB

  1. Use exploded assembly, i.e. first package everything into tar.gz

 1    <!—pom.xml –>
 2    <build>
 3            <plugins>
 4                <plugin>
 5                    <artifactId>maven-assembly-plugin</artifactId>
 6                    <configuration>
 7                        <appendAssemblyId>false</appendAssemblyId>
 8                        <descriptors>
 9                            <descriptor>src/main/assembly.xml</descriptor>
10                        </descriptors>
11                    </configuration>
12                </plugin>
13            </plugins>
14        </build>
15    <!—src/main/assembly.xml –>
16    <assembly schemaLocation="http://maven.apache.org/xsd/assembly-1.0.0.xsd">
17        <id>distr</id>
18        <formats>
19            <format>tar.gz</format>
20        </formats>
21        <dependencySets>
22            <dependencySet>
23                <outputDirectory>/lib</outputDirectory>
24                <fileMode>0777</fileMode>
25            </dependencySet>
26        </dependencySets>
27        <fileSets>
28            <fileSet>
29                <directory>conf</directory>
30                <outputDirectory>/conf</outputDirectory>
31            </fileSet>
32        </fileSets>
33    </assembly>

When deployed it is extracted from the archive and copied to some place e.g. SERVER_ROOT. Exploded archive has the following structure:

SERVER_ROOT\
            |- lib\
            |      |- *.jar
            |
            |- conf\
                    |- test.xml

Startup bash script may look like this:

1    #!/bin/bash
2
3    # import essential environmental variables like absolute path to our server root aka SERVER_ROOT
4    . /etc/tangorc
5
6    /usr/bin/java -cp $SERVER_ROOT/lib/* -Dconf=$SERVER_ROOT/conf/test.xml hzg.wpn.tango.TestServer

Again the script is in /usr/lib/tango/server/TestServer. /usr/lib/tango/server can be replaced with any other location where Starter can find the script, i.e. defined in StartDsPath property.

We need to specify an absolute path to the lib and conf folders as Astor runs servers from /var/tmp/ds.log folder:

PROS:

  • if there are several servers common dependencies can be placed into a single location, hence save some disc space

  • server may use external resources (like conf in the example above), just make sure to use absolute paths

CONS:

  • dealing with exploded assemblies quickly becomes messy

Both solutions assume that maven is used to handle project’s lifecycle.