Juan Hernandez has uploaded a new change for review.

Change subject: tools: Use JBoss modules instead of class path
......................................................................

tools: Use JBoss modules instead of class path

Currently in order to run the tools we build the class path using mostly
the "build-classpath" script and also some ad hoc searches. This tends
to fail in environments where the jar files are installed in locations
different than expected. This patch creates a JBoss module for the
tools library and changes the scripts that starts the tools so that
they use the JBoss modules launcher instead, thus manual class path
building is no longer required.

Change-Id: Id3e4f7a4bd9a3b31ceb453f9257b2ad8eaf03f5a
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M backend/manager/tools/pom.xml
A 
backend/manager/tools/src/main/modules/org/ovirt/engine/core/tools/main/module.xml
M backend/manager/tools/src/main/shell/engine-config.sh
M backend/manager/tools/src/main/shell/engine-manage-domains.sh
M backend/manager/tools/src/main/shell/engine-notifier.sh
M backend/manager/tools/src/main/shell/engine-prolog.sh.in
M packaging/fedora/spec/ovirt-engine.spec.in
7 files changed, 109 insertions(+), 109 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/96/12096/1

diff --git a/backend/manager/tools/pom.xml b/backend/manager/tools/pom.xml
index ca8925e..9e97ce2 100644
--- a/backend/manager/tools/pom.xml
+++ b/backend/manager/tools/pom.xml
@@ -18,22 +18,6 @@
   <name>oVirt Engine Tools</name>
   <description>oVirt Engine Tools</description>
 
-  <build>
-    <plugins>
-      <plugin>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <additionalClasspathElements>
-            
<additionalClasspathElement>${basedir}/**/src/test/java</additionalClasspathElement>
-          </additionalClasspathElements>
-          <excludes>
-            <exclude>**/*Test.java</exclude>
-          </excludes>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-
   <dependencies>
 
     <dependency>
@@ -87,4 +71,27 @@
     </profile>
   </profiles>
 
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <additionalClasspathElements>
+            
<additionalClasspathElement>${basedir}/**/src/test/java</additionalClasspathElement>
+          </additionalClasspathElements>
+          <excludes>
+            <exclude>**/*Test.java</exclude>
+          </excludes>
+        </configuration>
+      </plugin>
+
+      <!-- Create the JBoss module: -->
+      <plugin>
+        <groupId>org.ovirt.engine</groupId>
+        <artifactId>jboss-modules-maven-plugin</artifactId>
+      </plugin>
+
+    </plugins>
+  </build>
+
 </project>
diff --git 
a/backend/manager/tools/src/main/modules/org/ovirt/engine/core/tools/main/module.xml
 
b/backend/manager/tools/src/main/modules/org/ovirt/engine/core/tools/main/module.xml
new file mode 100644
index 0000000..0d82a53
--- /dev/null
+++ 
b/backend/manager/tools/src/main/modules/org/ovirt/engine/core/tools/main/module.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<module xmlns="urn:jboss:module:1.0" name="org.ovirt.engine.core.tools">
+
+   <resources>
+     <resource-root path="tools.jar"/>
+   </resources>
+
+   <dependencies>
+      <module name="javax.api"/>
+      <module name="javax.mail.api"/>
+      <module name="org.apache.commons.configuration"/>
+      <module name="org.apache.commons.lang"/>
+      <module name="org.apache.commons.logging"/>
+      <module name="org.apache.log4j"/>
+      <module name="org.ovirt.engine.core.common"/>
+      <module name="org.ovirt.engine.core.compat"/>
+      <module name="org.ovirt.engine.core.dependencies"/>
+      <module name="org.ovirt.engine.core.utils"/>
+      <module name="org.postgresql"/>
+      <module name="sun.jdk"/>
+   </dependencies>
+
+</module>
diff --git a/backend/manager/tools/src/main/shell/engine-config.sh 
b/backend/manager/tools/src/main/shell/engine-config.sh
index d2ce524..7c43518 100755
--- a/backend/manager/tools/src/main/shell/engine-config.sh
+++ b/backend/manager/tools/src/main/shell/engine-config.sh
@@ -1,9 +1,7 @@
 #!/bin/bash
 #
 # This script is designed to run the configuration tool.
-# The script assumes all RPM dependencies were installed, so jar
-# files can be found under /usr/share/java. The tool's configuration
-# should be under the /etc directory.
+# The tool's configuration should be under the /etc directory.
 #
 
 # Load the prolog:
@@ -89,28 +87,21 @@
         exit 0
 fi
 
-CP=`\
-build-classpath \
-apache-commons-codec \
-apache-commons-collections \
-apache-commons-configuration \
-apache-commons-jxpath \
-apache-commons-lang \
-apache-commons-logging \
-log4j \
-ovirt-engine/compat \
-ovirt-engine/tools \
-ovirt-engine/utils \
-postgresql-jdbc \
-`
-
-# Verify all classpath elements available
-for f in $(echo $CP|sed 's/:/ /g')
-do
-        if [ ! -s $f ]; then
-                die "Error: can't run without missing JAR file: $f\n"
-        fi
-done
+#
+# Add this option to the java command line to enable remote debugging in
+# all IP addresses and port 8787:
+#
+# -Xrunjdwp:transport=dt_socket,address=0.0.0.0:8787,server=y,suspend=y
+#
+# Note that the "suspend=y" options is needed to suspend the execution
+# of the JVM till you connect with the debugger, otherwise it is
+# not possible to debug the execution of the main method.
+#
 
 # Run!
-exec "${JAVA_HOME}/bin/java" -cp .:$CP 
-Dlog4j.configuration="file:${ENGINE_ETC}/engine-config/log4j.xml" 
org.ovirt.engine.core.config.EngineConfig "$@"
+exec "${JAVA_HOME}/bin/java" \
+  -Dlog4j.configuration="file:${ENGINE_ETC}/engine-config/log4j.xml" \
+  -jar "${JBOSS_HOME}/jboss-modules.jar" \
+  -dependencies org.ovirt.engine.core.tools \
+  -class org.ovirt.engine.core.config.EngineConfig \
+  "$@"
diff --git a/backend/manager/tools/src/main/shell/engine-manage-domains.sh 
b/backend/manager/tools/src/main/shell/engine-manage-domains.sh
index ae10d9c..2297fdf 100755
--- a/backend/manager/tools/src/main/shell/engine-manage-domains.sh
+++ b/backend/manager/tools/src/main/shell/engine-manage-domains.sh
@@ -1,9 +1,7 @@
 #!/bin/bash
 #
 # This script is designed to run the manage domains utility.
-# The script assumes all RPM dependencies were installed, so jar
-# files can be found under /usr/share/java. The tool's configuration
-# should be under the /etc directory.
+# The tool's configuration should be under the /etc directory.
 #
 
 # Load the prolog:
@@ -91,34 +89,6 @@
         exit 0
 fi
 
-CP=\
-$CONF_DIR:`\
-build-classpath \
-apache-commons-codec \
-apache-commons-collections \
-apache-commons-configuration \
-apache-commons-jxpath \
-apache-commons-lang \
-apache-commons-logging \
-log4j \
-ovirt-engine/common \
-ovirt-engine/compat \
-ovirt-engine/tools \
-ovirt-engine/utils \
-postgresql-jdbc \
-springframework/spring-beans \
-springframework/spring-core \
-springframework/spring-tx \
-spring-ldap/spring-ldap-core \
-`
-
-for f in $(echo $CP|sed 's/:/ /g')
-do
-        if [ ! -s $f ]; then
-                die "Error: can't run without missing JAR file: $f\n"
-        fi
-done
-
 PROPERTIES_FILE=`mktemp`
 
 if [ ! -e $PROPERTIES_FILE ]; then
@@ -136,7 +106,23 @@
 LDAPServerPort=
 EOF
 
-"${JAVA_HOME}/bin/java" -cp .:$CP 
-Dlog4j.configuration="file:${ENGINE_ETC}/engine-manage-domains/log4j.xml" 
org.ovirt.engine.core.domains.ManageDomains "$@" 
-propertiesFile=$PROPERTIES_FILE
+#
+# Add this option to the java command line to enable remote debugging in
+# all IP addresses and port 8787:
+#
+# -Xrunjdwp:transport=dt_socket,address=0.0.0.0:8787,server=y,suspend=y
+#
+# Note that the "suspend=y" options is needed to suspend the execution
+# of the JVM till you connect with the debugger, otherwise it is
+# not possible to debug the execution of the main method.
+#
+
+"${JAVA_HOME}/bin/java" \
+  -Dlog4j.configuration="file:${ENGINE_ETC}/engine-manage-domains/log4j.xml" \
+  -jar "${JBOSS_HOME}/jboss-modules.jar" \
+  -dependencies org.ovirt.engine.core.tools \
+  -class org.ovirt.engine.core.domains.ManageDomains \
+  "$@" -propertiesFile=$PROPERTIES_FILE
 
 RET_VAL=$?
 
diff --git a/backend/manager/tools/src/main/shell/engine-notifier.sh 
b/backend/manager/tools/src/main/shell/engine-notifier.sh
index dc265ea..a0febaa 100755
--- a/backend/manager/tools/src/main/shell/engine-notifier.sh
+++ b/backend/manager/tools/src/main/shell/engine-notifier.sh
@@ -80,8 +80,6 @@
 done
 IFS=$old_IFS
 
-
-
 # Do basic checking of properties in configuration file to ensure
 # a) properties are defined
 # b) when properties are defined and reference a file system resource, that 
the resource exists.
@@ -203,43 +201,28 @@
     fi
 fi
 
-# Configure classpath for engine-notifier
-JAVA_LIB_HOME=/usr/share/java
-#JAVA_OPTS="-Xdebug 
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=127.0.0.1:8787"
-
-# Add the configuration directory to the classpath so that configuration
-# files can be loaded as resources:
-CP="${ENGINE_ETC}/notifier"
-
-# Add the required jar files from the system wide jars directory:
-jar_names='
-    commons-codec
-    commons-collections
-    commons-lang
-    commons-logging
-    javamail
-    log4j
-    ovirt-engine/common
-    ovirt-engine/compat
-    ovirt-engine/tools
-    ovirt-engine/utils
-    postgresql-jdbc
-'
-for jar_name in ${jar_names}
-do
-    jar_file=${JAVA_LIB_HOME}/${jar_name}.jar
-    if [ ! -s "${jar_file}" ]
-    then
-        die "Error: can't run without missing JAR file: ${jar_file}\n" 5
-    fi
-    CP=${CP}:${jar_file}
-done
-
 if [ -z "$NOTIFIER_PID" ]
 then
     NOTIFIER_PID=/dev/null
 fi
 
-"${JAVA_HOME}/bin/java" -cp $CP $JAVA_OPTS 
org.ovirt.engine.core.notifier.Notifier $CONF_FILE 2>/dev/null &
+#
+# Add this option to the java command line to enable remote debugging in
+# all IP addresses and port 8787:
+#
+# -Xrunjdwp:transport=dt_socket,address=0.0.0.0:8787,server=y,suspend=y
+#
+# Note that the "suspend=y" options is needed to suspend the execution
+# of the JVM till you connect with the debugger, otherwise it is
+# not possible to debug the execution of the main method.
+#
+
+"${JAVA_HOME}/bin/java" \
+  -Dlog4j.configuration="file:${ENGINE_ETC}/notifier/log4j.xml" \
+  -jar "${JBOSS_HOME}/jboss-modules.jar" \
+  -dependencies org.ovirt.engine.core.tools \
+  -class org.ovirt.engine.core.notifier.Notifier \
+  "${CONF_FILE}" \
+  2>/dev/null &
 
 echo $! >$NOTIFIER_PID
diff --git a/backend/manager/tools/src/main/shell/engine-prolog.sh.in 
b/backend/manager/tools/src/main/shell/engine-prolog.sh.in
index de140f5..44267d3 100644
--- a/backend/manager/tools/src/main/shell/engine-prolog.sh.in
+++ b/backend/manager/tools/src/main/shell/engine-prolog.sh.in
@@ -22,6 +22,14 @@
         die "Can't load configuration file \"${ENGINE_VARS}\"."
     fi
     . "${ENGINE_VARS}"
+
+    # Clean the class path:
+    CLASSPATH=""
+    export CLASSPATH
+
+    # Prepare the module path:
+    JAVA_MODULEPATH="${ENGINE_USR}/modules:${JBOSS_HOME}/modules"
+    export JAVA_MODULEPATH
 }
 
 # In addition to defining the functions we also perform some tasks that
diff --git a/packaging/fedora/spec/ovirt-engine.spec.in 
b/packaging/fedora/spec/ovirt-engine.spec.in
index 67b5331..11e7006 100644
--- a/packaging/fedora/spec/ovirt-engine.spec.in
+++ b/packaging/fedora/spec/ovirt-engine.spec.in
@@ -445,6 +445,7 @@
 compat
 dal
 searchbackend
+tools
 utils
 .
 


--
To view, visit http://gerrit.ovirt.org/12096
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id3e4f7a4bd9a3b31ceb453f9257b2ad8eaf03f5a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to