From 1caf9c6892d583d5f644e5c1fef1d1f8a6b3f74b Mon Sep 17 00:00:00 2001 From: Daniel Barcelona Date: Fri, 29 Mar 2019 09:58:29 +0100 Subject: [PATCH] Fixes for local and EC2 --- client/pom.xml | 3 +- core/pom.xml | 12 ++++ server/pom.xml | 1 - server/src/main/bin/server.sh | 39 ++++++++++--- .../java/org/infinispan/creson/Server.java | 14 ++--- .../src/main/resources/jgroups-creson-udp.xml | 56 +++++++++++++++++++ 6 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 server/src/main/resources/jgroups-creson-udp.xml diff --git a/client/pom.xml b/client/pom.xml index f15fcf4..7bbb7e8 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -8,9 +8,8 @@ ../ - org.infinispan infinispan-creson-client - infinispan-creson-server + infinispan-creson-client The client side of the CRESON framework. diff --git a/core/pom.xml b/core/pom.xml index 4bdf5ae..4f02e36 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -99,6 +99,18 @@ ${skipTests} + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + test-jar + + + + diff --git a/server/pom.xml b/server/pom.xml index 08cee4c..7ef7e5c 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -8,7 +8,6 @@ ../ - org.infinispan infinispan-creson-server infinispan-creson-server Server side of the CRESON framework. diff --git a/server/src/main/bin/server.sh b/server/src/main/bin/server.sh index 9ba26be..442200b 100755 --- a/server/src/main/bin/server.sh +++ b/server/src/main/bin/server.sh @@ -2,18 +2,37 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" CLASSPATH="${DIR}/*:${DIR}/lib/*" -JVM="-XX:+UseConcMarkSweepGC -Xms64m -Xmx1024m -Djava.net.preferIPv4Stack=true -Djgroups.tcp.address=${IP} -Dlog4j.configurationFile=${DIR}/log4j2.xml" CONFIG="jgroups-creson-tcp.xml" -if [ "${CLOUD}" == "ec2" ]; +if [[ "${CLOUD}" == "" ]]; +then + CLOUD="$1" + IP='127.0.0.1' + PORT='11222' +# EXTRA='-rf 2 -userLibs .' + CONFIG='jgroups-creson-udp.xml' +fi + +if [[ "$2" != "" ]]; +then + PORT=$2 +fi + +if [[ "${CLOUD}" == "ec2" ]]; then echo "AWS EC2 mode" CONFIG=jgroups-creson-ec2.xml - IP=`/sbin/ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'` + #IP=`/sbin/ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'` + IP=`hostname -I | sed -e 's/[[:space:]]*$//'` PIP=`curl -s checkip.amazonaws.com` - EXTRA=${EXTRA}"-proxy ${PIP}:11222 -rf 2" + EXTRA="-proxy ${PIP}:11222 -ec2 -rf 1" +elif [[ "${CLOUD}" == "vpc" ]]; +then + echo "AWS EC2 VPC mode" CONFIG=jgroups-creson-ec2.xml -elif [ "${CLOUD}" == "gcp" ]; + IP=`hostname -I | sed -e 's/[[:space:]]*$//'` + EXTRA="-ec2 -rf 1" +elif [[ "${CLOUD}" == "gcp" ]]; then echo "GCP mode" CONFIG=jgroups-creson-gcp.xml @@ -23,7 +42,7 @@ then | sed s,%BUCKET_SECRET%,${BUCKET_SECRET},g \ | sed s,%IP%,${IP},g > tmp mv tmp ${CONFIG} -elif [ "${CLOUD}" == "k8s" ]; +elif [[ "${CLOUD}" == "k8s" ]]; then echo "K8S mode" CONFIG=jgroups-creson-k8s.xml @@ -31,7 +50,9 @@ else echo "local mode" fi -mv ${CONFIG} jgroups.xml +cp ${CONFIG} jgroups.xml -echo "java -ea -cp ${CLASSPATH} ${JVM} org.infinispan.creson.Server -server ${IP}:${PORT} ${EXTRA}" -java -ea -cp ${CLASSPATH} ${JVM} org.infinispan.creson.Server -server ${IP}:${PORT} ${EXTRA} +JVM="-XX:+UseConcMarkSweepGC -Xms64m -Xmx1024m -Djava.net.preferIPv4Stack=true -Djgroups.tcp.address=${IP} -Dlog4j.configurationFile=\"${DIR}/log4j2.xml\"" +CMD="java -ea -cp \"${CLASSPATH}\" ${JVM} org.infinispan.creson.Server -server ${IP}:${PORT} ${EXTRA}" +echo ${CMD} +bash -c "$CMD" \ No newline at end of file diff --git a/server/src/main/java/org/infinispan/creson/Server.java b/server/src/main/java/org/infinispan/creson/Server.java index cf5e526..3fb1b9a 100644 --- a/server/src/main/java/org/infinispan/creson/Server.java +++ b/server/src/main/java/org/infinispan/creson/Server.java @@ -84,7 +84,7 @@ public void doMain(String[] args) { return; } - Runnable runnable = (Runnable) () -> { + Runnable runnable = () -> { File folder = new File(userLib); File[] listOfFiles = folder.listFiles(); for (File file : listOfFiles) { @@ -101,7 +101,7 @@ public void doMain(String[] args) { } ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); - scheduler.scheduleAtFixedRate(runnable,3, 3, TimeUnit.SECONDS); + scheduler.scheduleAtFixedRate(runnable, 3, 3, TimeUnit.SECONDS); String host = server.split(":")[0]; int port = Integer.valueOf( @@ -124,7 +124,7 @@ public void doMain(String[] args) { replicationFactor, maxEntries, false, - STORAGE_PATH_PREFIX + "/"+ host, + STORAGE_PATH_PREFIX + "/" + host, true, false); @@ -178,16 +178,16 @@ public static synchronized void loadLibrary(java.io.File jar) { try { java.net.URLClassLoader loader = (java.net.URLClassLoader) ClassLoader.getSystemClassLoader(); java.net.URL url = jar.toURI().toURL(); - for (java.net.URL it : java.util.Arrays.asList(loader.getURLs())) { + for (java.net.URL it : loader.getURLs()) { if (it.equals(url)) { return; } } - System.out.println("Loading "+jar.getName()); + System.out.println("Loading " + jar.getName()); java.lang.reflect.Method method = java.net.URLClassLoader.class. - getDeclaredMethod("addURL", new Class[]{java.net.URL.class}); + getDeclaredMethod("addURL", java.net.URL.class); method.setAccessible(true); /*promote the method to public access*/ - method.invoke(loader, new Object[]{url}); + method.invoke(loader, url); } catch (final java.lang.NoSuchMethodException | java.lang.IllegalAccessException | java.net.MalformedURLException | diff --git a/server/src/main/resources/jgroups-creson-udp.xml b/server/src/main/resources/jgroups-creson-udp.xml new file mode 100644 index 0000000..a9bcccc --- /dev/null +++ b/server/src/main/resources/jgroups-creson-udp.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + +