Skip to content

Commit

Permalink
Added version number fo config files, check against JGroups version (h…
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Apr 8, 2020
1 parent c6b9c9e commit 254ea2d
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 36 deletions.
59 changes: 48 additions & 11 deletions build.xml
Expand Up @@ -277,19 +277,30 @@

<target name="copy-conf-dir" description="Copies the relevant files from ./conf to ./classes">
<copy todir="${compile.dir}/">
<fileset dir="${conf.dir}" includes="*.xml, *.properties, *.btm *.jks">
<fileset dir="${conf.dir}" includes="*.properties, *.btm *.jks">
<include name="scripts/**"/>
<exclude name="log4j*.xml"/>
<exclude name="settings.xml"/>
</fileset>
</copy>
<copy todir="${compile.dir}/">
<fileset dir="${conf.dir}" includes="*.xml">
<include name="scripts/**"/>
<exclude name="log4j*.xml"/>
<exclude name="settings.xml"/>
</fileset>
<!-- Filter chain that replaces the template values with actual values fetched from properties file -->
<filterchain>
<expandproperties />
</filterchain>
</copy>
</target>

<target name="compile-no-unittests" depends="prepare" description="Compiles all Java files except unit tests">
<javac srcdir="${src.dir}"
destdir="${compile.dir}"
source="1.8"
target="1.8"
source="11"
target="11"
classpathref="jg.classpath"
includeantruntime="false"
debug="on"
Expand All @@ -306,8 +317,8 @@
depends="prepare"
description="Compiles only tests shipped with JGroups">
<javac destdir="${compile.dir}"
source="1.8"
target="1.8"
source="11"
target="11"
classpathref="jg.classpath"
includeantruntime="false"
debug="on"
Expand All @@ -323,17 +334,43 @@
</target>


<target name="copy-configfiles-to-compile-dir"
description="Copies selected XML config files from the conf dir to the compile dir">

<!-- Location the processed files would be written to -->
<mkdir dir="${compile.dir}" />

<copy todir="${compile.dir}" verbose="false" overwrite="true" failonerror="true">
<fileset dir="${conf.dir}" includes="*.jks"/>
</copy>

<!-- Copy task that replaces values and copies the files -->
<copy todir="${compile.dir}" verbose="false" overwrite="true" failonerror="true">
<fileset dir="${conf.dir}" includes="*.xml, *.properties, *.cfg">
<exclude name="log4j*.xml"/>
<exclude name="settings.xml"/>
</fileset>
<fileset dir="${compile.dir}/schema">
<include name="*.xsd"/>
</fileset>
<!-- Filter chain that replaces the template values with actual values fetched from properties file -->
<filterchain>
<expandproperties />
</filterchain>
</copy>
</target>

<target name="jar"
description="Compiles and creates JARs in ./dist"
depends="jgroups.jar,jgroups-sources.jar">
<copy file="${doc.dir}/README" tofile="${dist.dir}/README" overwrite="true"/>

</target>


<target name="jgroups.jar"
description="Creates the jgroups.jar (includes everything)"
depends="compile-no-unittests,compile-essential-unittests,make-schema,make-keystore-no-compile">
depends="compile-no-unittests,compile-essential-unittests,make-schema,
make-keystore-no-compile,copy-configfiles-to-compile-dir">
<mkdir dir="${dist.dir}"/>
<xmlproperty file="${ant.file}" collapseAttributes="true" prefix="bnd"/>
<property name="bndclasspath" refid="jg.classpath"/>
Expand All @@ -350,7 +387,7 @@
basedir="${compile.dir}"
manifest="${conf.dir}/MANIFEST.MF"
includes="org/jgroups/**">
<fileset dir="${conf.dir}" includes="*.xml, *.properties, *.cfg, *.jks">
<fileset dir="${compile.dir}" includes="*.xml, *.properties, *.cfg, *.jks">
<exclude name="log4j*.xml"/>
<exclude name="settings.xml"/>
</fileset>
Expand Down Expand Up @@ -512,13 +549,13 @@
<include name="*.xsd"/>
</fileset>
</copy>
<!-- Leave a schema named jgrous-4.x.xsd -->
<!-- <copy todir="${compile.dir}/schema">
<!-- Leave a schema named jgrous-5.x.xsd -->
<copy todir="${compile.dir}/schema">
<fileset dir="${compile.dir}/schema">
<include name="jgroups*.xsd"/>
</fileset>
<globmapper from="jgroups*.xsd" to="jgroups.xsd"/>
</copy>-->
</copy>
</target>

<target name="clean"
Expand Down
3 changes: 2 additions & 1 deletion conf/asym-encrypt.xml
@@ -1,7 +1,8 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP />
<PING/>
<MERGE3/>
Expand Down
2 changes: 1 addition & 1 deletion conf/asym-ssl.xml
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Demo config showing how to configure ASYM_ENCRYPT with a keystore and certificates -->
<config>
<config version="${version}">
<TCP bind_addr="localhost" bind_port="7600"/>
<TCPPING initial_hosts="localhost[7600]" port_range="10"/>
<MERGE3/>
Expand Down
3 changes: 2 additions & 1 deletion conf/auth_X509.xml
@@ -1,6 +1,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP/>
<PING/>
<MERGE3/>
Expand Down
3 changes: 2 additions & 1 deletion conf/auth_fixedlist.xml
@@ -1,6 +1,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP bind_addr="localhost"
bind_port="1025"/>
<PING />
Expand Down
3 changes: 2 additions & 1 deletion conf/auth_krb5.xml
@@ -1,6 +1,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP/>
<PING />
<MERGE3 />
Expand Down
3 changes: 2 additions & 1 deletion conf/auth_regex.xml
Expand Up @@ -9,7 +9,8 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP/>
<PING/>
<MERGE3/>
Expand Down
3 changes: 2 additions & 1 deletion conf/encrypt.xml
@@ -1,7 +1,8 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP />
<PING/>
<MERGE3/>
Expand Down
3 changes: 2 additions & 1 deletion conf/fast.xml
Expand Up @@ -9,7 +9,8 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP
mcast_port="${jgroups.udp.mcast_port:45588}"
ip_ttl="0"
Expand Down
3 changes: 2 additions & 1 deletion conf/sequencer.xml
Expand Up @@ -7,7 +7,8 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP/>
<PING/>
<MERGE3/>
Expand Down
3 changes: 2 additions & 1 deletion conf/sym-encrypt.xml
Expand Up @@ -3,7 +3,8 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP />
<PING/>
<MERGE3/>
Expand Down
3 changes: 2 additions & 1 deletion conf/tcp-nio.xml
Expand Up @@ -7,7 +7,8 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<TCP_NIO2 bind_port="7800"
recv_buf_size="${tcp.recv_buf_size:130k}"
send_buf_size="${tcp.send_buf_size:130k}"
Expand Down
3 changes: 2 additions & 1 deletion conf/tcp.xml
Expand Up @@ -7,7 +7,8 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<TCP bind_port="7800"
recv_buf_size="${tcp.recv_buf_size:130k}"
send_buf_size="${tcp.send_buf_size:130k}"
Expand Down
3 changes: 2 additions & 1 deletion conf/toa.xml
Expand Up @@ -7,7 +7,8 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP bind_addr="127.0.0.1"
mcast_port="${jgroups.udp.mcast_port:45588}"
tos="8"
Expand Down
3 changes: 2 additions & 1 deletion conf/tunnel.xml
Expand Up @@ -6,7 +6,8 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:org:jgroups"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">

<TUNNEL gossip_router_hosts="${jgroups.tunnel.gossip_router_hosts:localhost[12001]}"/>
<PING/>
Expand Down
4 changes: 2 additions & 2 deletions conf/udp.xml
Expand Up @@ -4,10 +4,10 @@
stack in stacks.xml, but doesn't use streaming state transfer and flushing
author: Bela Ban
-->

<config xmlns="urn:org:jgroups"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd"
version="${version}">
<UDP
mcast_port="${jgroups.udp.mcast_port:45588}"
ip_ttl="4"
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -148,6 +148,7 @@
<include>jg-messages*.properties</include>
<include>JGROUPS_VERSION.properties</include>
</includes>
<filtering>true</filtering>
<excludes>
<exclude>*-service.xml</exclude>
<exclude>log4*.xml</exclude>
Expand Down
26 changes: 23 additions & 3 deletions src/org/jgroups/Version.java
Expand Up @@ -77,6 +77,13 @@ public class Version {
string_version=print(version);
}

public static short getMajor() {return major;}
public static short getMinor() {return minor;}
public static short getMicro() {return micro;}

public static short getMajor(short v) {return (short)((v & MAJOR_MASK) >> MAJOR_SHIFT);}
public static short getMinor(short v) {return (short)((v & MINOR_MASK) >> MINOR_SHIFT);}
public static short getMicro(short v) {return (short)(v & MICRO_MASK);}

/**
* Prints the value of the description and cvs fields to System.out.
Expand Down Expand Up @@ -120,12 +127,25 @@ public static short encode(int major, int minor, int micro) {

/** Method copied from http://www.jboss.com/index.html?module=bb&op=viewtopic&t=77231 */
public static String print(short version) {
int major=(version & MAJOR_MASK) >> MAJOR_SHIFT;
int minor=(version & MINOR_MASK) >> MINOR_SHIFT;
int micro=(version & MICRO_MASK);
int major=getMajor(version);
int minor=getMinor(version);
int micro=getMicro(version);
return major + "." + minor + "." + micro;
}

public static short parse(String ver) {
try {
Matcher versionMatcher=VERSION_REGEXP.matcher(ver);
versionMatcher.find();
short maj=Short.parseShort(versionMatcher.group(2));
short min=Short.parseShort(versionMatcher.group(3));
short mic=Short.parseShort(versionMatcher.group(4));
return encode(maj, min, mic);
}
catch(Throwable t) {
throw new IllegalArgumentException(String.format("failed parsing version '%s': %s", ver, t));
}
}

public static short[] decode(short version) {
short major=(short)((version & MAJOR_MASK) >> MAJOR_SHIFT);
Expand Down
17 changes: 17 additions & 0 deletions src/org/jgroups/conf/XmlConfigurator.java
Expand Up @@ -2,6 +2,7 @@
package org.jgroups.conf;


import org.jgroups.Version;
import org.jgroups.logging.Log;
import org.jgroups.logging.LogFactory;
import org.jgroups.util.Util;
Expand Down Expand Up @@ -165,6 +166,22 @@ public static List<ProtocolConfiguration> parseProtocols(Element root_element) t
if(!"config".equals(root_name))
throw new IOException("the configuration does not start with a <config> element: " + root_name);

// validate that version of config and JGroups match (https://issues.redhat.com/browse/JGRP-2401)
String version=root_element.getAttribute("version");
if(version != null && !version.isEmpty()) {
short ver=Version.parse(version);
if(!Version.isBinaryCompatible(ver)) {
String s=String.format("the version of the config file (%s) doesn't match the version of JGroups (%s); " +
"this might lead to problems. Please use a config from the same JGroups version",
Version.print(ver), Version.printVersion());

if(Version.getMajor() != Version.getMajor(ver))
throw new IllegalArgumentException(s);
log.warn(s);
}
}
else
log.warn("version is missing in the configuration file");
final List<ProtocolConfiguration> prot_data=new ArrayList<>();
NodeList prots=root_element.getChildNodes();
for(int i=0;i < prots.getLength();i++) {
Expand Down
10 changes: 5 additions & 5 deletions src/org/jgroups/util/XMLSchemaGenerator.java
Expand Up @@ -6,10 +6,7 @@
import org.jgroups.annotations.XmlElement;
import org.jgroups.annotations.XmlInclude;
import org.jgroups.stack.Protocol;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.*;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -80,7 +77,10 @@ public static void main(String[] args) {
Element allType = xmldoc.createElement("xs:choice");
allType.setAttribute("maxOccurs", "unbounded");
complexType.appendChild(allType);

Element attributeElement = xmldoc.createElement("xs:attribute");
attributeElement.setAttribute("version", "${version}");
attributeElement.setAttribute("type", "xs:string");
complexType.appendChild(attributeElement);
generateProtocolSchema(xmldoc, allType, PACKAGES);

Element xsElement = xmldoc.createElement("xs:element");
Expand Down
Expand Up @@ -17,7 +17,7 @@ public class SetPropertyTest {

@BeforeClass
void init() throws Exception {
ch=new JChannel();
ch=new JChannel(Util.getTestStack());
}

@AfterClass
Expand Down

0 comments on commit 254ea2d

Please sign in to comment.