Skip to content

Commit

Permalink
Merge pull request alibaba#7 from oldmanpushcart/dev-namespace-support
Browse files Browse the repository at this point in the history
容器支持命名空间&修复JDK9下支持问题
  • Loading branch information
oldmanpushcart authored Dec 3, 2017
2 parents 104bda3 + fb72a8b commit 74ff959
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 115 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Based on this I am through the JDK6 provided Instrumentation-API implementation


#### Provides a plug-and-play module management container
In order to realize the dynamic hot-swapping of the sandbox module, the container client and the sandbox dynamic pluggable container communicate with the HTTP protocol. The bottom layer uses Jetty6 as the HTTP server.
In order to realize the dynamic hot-swapping of the sandbox module, the container client and the sandbox dynamic pluggable container communicate with the HTTP protocol. The bottom layer uses Jetty8 as the HTTP server.

### What can the JVM-SANDBOX do?

Expand Down
43 changes: 29 additions & 14 deletions bin/sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

# define sandbox's home
# will be replace by install-local.sh
typeset SANDBOX_HOME_DIR;
typeset SANDBOX_HOME_DIR
[[ -z ${SANDBOX_HOME_DIR} ]] \
&& SANDBOX_HOME_DIR=$(cd `dirname $0`; pwd)/..

# define sandbox's network
typeset SANDBOX_SERVER_NETWORK;
typeset SANDBOX_SERVER_NETWORK

# define sandbox's lib
typeset SANDBOX_LIB_DIR=${SANDBOX_HOME_DIR}/lib
Expand All @@ -24,13 +24,18 @@ typeset SANDBOX_TOKEN_FILE=${HOME}/.sandbox.token
typeset SANDBOX_JVM_OPS="-Xms128M -Xmx128M -Xnoclassgc -ea";

# define target JVM Process ID
typeset TARGET_JVM_PID;
typeset TARGET_JVM_PID

# define target SERVER network interface
typeset TARGET_SERVER_IP;
typeset TARGET_SERVER_IP
typeset DEFAULT_TARGET_SERVER_IP="0.0.0.0"

# define target SERVER network port
typeset TARGET_SERVER_PORT;
typeset TARGET_SERVER_PORT

# define target NAMESPACE
typeset TARGET_NAMESPACE
typeset DEFAULT_NAMESPACE="default"


# exit shell with err_code
Expand All @@ -44,7 +49,7 @@ exit_on_err()

# display usage
function usage() {
echo '
echo "
usage: ${0} [h] [<p:> [vlRFfu:a:A:d:m:I:P:C:]]
-h : help
Expand Down Expand Up @@ -130,7 +135,7 @@ usage: ${0} [h] [<p:> [vlRFfu:a:A:d:m:I:P:C:]]
-I : IP address
Appoint the network interface (bind ip address)
when default, use localhost
when default, use \"${DEFAULT_TARGET_SERVER_IP}\"
EXAMPLE:
${0} -p <PID> -I 192.168.0.1 -v
Expand All @@ -153,7 +158,11 @@ usage: ${0} [h] [<p:> [vlRFfu:a:A:d:m:I:P:C:]]
-S : Shutdown server
Shutdown jvm-sandbox\` server
'
-n : Namespace
Appoint the jvm-sandbox\` namespace
when default, use \"${DEFAULT_NAMESPACE}\"
"
}

# check sandbox permission
Expand Down Expand Up @@ -208,11 +217,11 @@ function attach_jvm() {
-jar ${SANDBOX_LIB_DIR}/sandbox-core.jar \
${TARGET_JVM_PID} \
"${SANDBOX_LIB_DIR}/sandbox-agent.jar" \
"${token};${TARGET_SERVER_IP};${TARGET_SERVER_PORT}" \
"token=${token};ip=${TARGET_SERVER_IP};port=${TARGET_SERVER_PORT};namespace=${TARGET_NAMESPACE}" \
|| exit_on_err 1 "attach JVM ${TARGET_JVM_PID} fail."

# get network from attach result
SANDBOX_SERVER_NETWORK=$(grep ${token} ${SANDBOX_TOKEN_FILE}|tail -1|awk -F ";" '{print $2";"$3}');
SANDBOX_SERVER_NETWORK=$(grep ${token} ${SANDBOX_TOKEN_FILE}|grep ${TARGET_NAMESPACE}|tail -1|awk -F ";" '{print $3";"$4}');
[[ -z ${SANDBOX_SERVER_NETWORK} ]] \
&& exit_on_err 1 "attach JVM ${TARGET_JVM_PID} fail, attach lose response."

Expand All @@ -234,7 +243,7 @@ function sandbox_curl_with_exit() {
function sandbox_debug_curl() {
local host=$(echo "${SANDBOX_SERVER_NETWORK}"|awk -F ";" '{print $1}')
local port=$(echo "${SANDBOX_SERVER_NETWORK}"|awk -F ";" '{print $2}')
curl -N -s "http://${host}:${port}/sandbox/${1}" \
curl -N -s "http://${host}:${port}/sandbox/${TARGET_NAMESPACE}/${1}" \
|| exit_on_err 1 "target JVM ${TARGET_JVM_PID} lose response."
}

Expand All @@ -243,7 +252,7 @@ function main() {

check_permission

while getopts "hp:vFfRu:a:A:d:m:I:P:ClS" ARG
while getopts "hp:vFfRu:a:A:d:m:I:P:ClSn:" ARG
do
case ${ARG} in
h) usage;exit;;
Expand All @@ -262,18 +271,25 @@ function main() {
P) TARGET_SERVER_PORT=${OPTARG};;
C) OP_CONNECT_ONLY=1;;
S) OP_SHUTDOWN=1;;
n) OP_NAMESPACE=1;ARG_NAMESPACE=${OPTARG};;
?) usage;exit_on_err 1;;
esac
done

reset_for_env

# reset IP
[ -z ${TARGET_SERVER_IP} ] && TARGET_SERVER_IP="0.0.0.0";
[ -z ${TARGET_SERVER_IP} ] && TARGET_SERVER_IP="${DEFAULT_TARGET_SERVER_IP}";

# reset PORT
[ -z ${TARGET_SERVER_PORT} ] && TARGET_SERVER_PORT=0;

# reset NAMESPACE
[[ ${OP_NAMESPACE} ]] \
&& TARGET_NAMESPACE=${ARG_NAMESPACE}
[[ -z ${TARGET_NAMESPACE} ]] \
&& TARGET_NAMESPACE=${DEFAULT_NAMESPACE}

if [[ ${OP_CONNECT_ONLY} ]]; then
[[ 0 -eq ${TARGET_SERVER_PORT} ]] \
&& exit_on_err 1 "server appoint PORT (-P) was missing"
Expand All @@ -282,7 +298,6 @@ function main() {
# -p was missing
[[ -z ${TARGET_JVM_PID} ]] \
&& exit_on_err 1 "PID (-p) was missing.";

attach_jvm
fi

Expand Down
2 changes: 1 addition & 1 deletion doc/JVM-SANDBOX-ReadMe-Chineies.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
基于此我通过JDK6所提供的Instrumentation-API实现了利用HotSwap技术在不重启JVM的情况下实现对任意方法的AOP增强。而且性能开销还在可以接受的范围之内。

#####2. 动态可插拔容器
为了实现沙箱模块的动态热插拔,容器客户端和沙箱动态可插拔容器采用HTTP协议进行通讯,底层用Jetty6作为HTTP服务器
为了实现沙箱模块的动态热插拔,容器客户端和沙箱动态可插拔容器采用HTTP协议进行通讯,底层用Jetty8作为HTTP服务器

#### What can the JVM-SANDBOX do?

Expand Down
2 changes: 1 addition & 1 deletion doc/JVM-SANDBOX-ReadMe-English.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Based on this I am through the JDK6 provided Instrumentation-API implementation


##### Provides a plug-and-play module management container
In order to realize the dynamic hot-swapping of the sandbox module, the container client and the sandbox dynamic pluggable container communicate with the HTTP protocol. The bottom layer uses Jetty6 as the HTTP server.
In order to realize the dynamic hot-swapping of the sandbox module, the container client and the sandbox dynamic pluggable container communicate with the HTTP protocol. The bottom layer uses Jetty8 as the HTTP server.

#### What can the JVM-SANDBOX do?

Expand Down
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sandbox.api.version>1.0.9</sandbox.api.version>
<sandbox.provider.api.version>1.0.1</sandbox.provider.api.version>
<sandbox.common.api.version>1.0.1</sandbox.common.api.version>
<sandbox.common.api.version>1.0.2</sandbox.common.api.version>
</properties>

<build>
Expand Down Expand Up @@ -177,17 +177,17 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.0.3</version>
<version>6.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>5.0.3</version>
<version>6.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>5.0.3</version>
<version>6.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand All @@ -202,6 +202,12 @@
<version>1.7.0</version>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.1</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down
Loading

0 comments on commit 74ff959

Please sign in to comment.