Skip to content

Commit

Permalink
collector+manager预打包配置
Browse files Browse the repository at this point in the history
  • Loading branch information
kuixiang committed May 16, 2013
1 parent 3c068bd commit e759278
Show file tree
Hide file tree
Showing 26 changed files with 767 additions and 409 deletions.
19 changes: 19 additions & 0 deletions modules/hydra-collector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@
<build>
<finalName>hydra-collector</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>package-only-java-files</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
<classifier>assemble</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.227.48:3306/hydra-config-pressure-test
jdbc.username=root
jdbc.password=root
a=a
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="location" value="classpath:dubbo-collector.properties" />
</bean>
<!--管理端 默认提供一个属性配置 决定数据源-->
<bean id="dbPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="2" />
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:collector-dbsource.properties</value>
</list>
</property>
</bean>

<dubbo:application name="${dubbo.application.name}" owner="${dubbo.application.owner}"/>
<dubbo:registry protocol="${dubbo.registry.protocol}" address="${dubbo.registry.address}"/>
<dubbo:protocol name="${dubbo.protocol.name}" port="${dubbo.protocol.port}" />
<bean id="hydraService" class="com.jd.bdp.hydra.dubbomonitor.provider.impl.HydraServiceImpl"/>
<bean id="hydraService" class="com.jd.bdp.hydra.dubbomonitor.provider.impl.HydraMysqlServiceImpl"/>
<dubbo:service interface="com.jd.bdp.hydra.dubbomonitor.HydraService" ref="hydraService">
</dubbo:service>
<!-- 选择存储方式为mysql -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if [ -z "$BASE_DIR" ] ; then
#echo "Benchtest is at $BASE_DIR"
fi

source $BASE_DIR/bin/env-bench.sh
source $BASE_DIR/bin/env.sh

AS_USER=`whoami`
LOG_DIR="$BASE_DIR/log"
Expand Down
13 changes: 10 additions & 3 deletions modules/hydra-manager-db/src/main/resources/hydra-manager-db.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!--数据库层-->
<context:property-placeholder location="classpath:mybatis/mysql.properties" ignore-unresolvable="true" />

<!--数据库层 自己默认提供一个属性配置-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="1" />
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:mybatis/mysql.properties</value>
</list>
</property>
</bean>
<bean id="dataSourceManager" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"></property>
<property name="url" value="${jdbc.url}"></property>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.227.48:3306/hydra-config
jdbc.username=root
jdbc.password=root
jdbc.url=jdbc:mysql://localhost:3306/hydra-config
jdbc.username=
jdbc.password=
a=a
38 changes: 38 additions & 0 deletions modules/hydra-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,44 @@
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>package-only-java-files</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
<classifier>assemble</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>src/main/resources/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.jd.bdp.hydra.manager;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* User: xiangkui
* Date: 13-5-16
* Time: 下午3:29
*/
public class HydraManager {
public static void main(String[] strings) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{
"classpath*:hydra-manager.xml"
});
context.start();
while (true) {
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
38 changes: 38 additions & 0 deletions modules/hydra-manager/src/main/resources/assembly/assembly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>jd</id>
<formats>
<format>dir</format>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useProjectAttachments>true</useProjectAttachments>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>/src/main/resources</directory>
<outputDirectory>/conf</outputDirectory>
<fileMode>0755</fileMode>
<includes>
<include>**.**</include>
</includes>
<excludes>
<exclude>/assembly</exclude>
<exclude>/scripts</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>/src/main/resources/scripts</directory>
<outputDirectory>/bin</outputDirectory>
<includes>
<include>*.*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dubbo.application.name=hydra-manager
dubbo.application.owner=jd-bdp

dubbo.registry.protocol=zookeeper
dubbo.registry.address=192.168.227.49:2181

dubbo.protocol.name=dubbo
dubbo.protocol.port=20890
30 changes: 22 additions & 8 deletions modules/hydra-manager/src/main/resources/hydra-manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="classpath*:hydra-manager-db.xml" />

<dubbo:application name="hydra-manager"/>
<dubbo:registry protocol="zookeeper" address="192.168.227.48:2181"/>
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
default-autowire="byName">
<bean id="hydra-manager-proConfigure" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<!-- 系统-D参数覆盖 -->
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="location" value="classpath:hydra-manager.properties"/>
</bean>
<!--管理端 默认提供一个属性配置 决定数据源-->
<bean id="dbPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="2" />
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:manager-dbsource.properties</value>
</list>
</property>
</bean>
<import resource="classpath*:hydra-manager-db.xml"/>
<dubbo:application name="${dubbo.application.name}" owner="${dubbo.application.owner}"/>
<dubbo:registry protocol="${dubbo.registry.protocol}" address="${dubbo.registry.address}"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20890"/>
<dubbo:protocol name="${dubbo.protocol.name}" port="${dubbo.protocol.port}" />
<bean id="leaderService" class="com.jd.bdp.hydra.dubbomonitor.provider.impl.LeaderServiceImpl">
<property name="appService" ref="appService"/>
<property name="seedService" ref="seedService"/>
<property name="serviceService" ref="serviceService"/>
</bean>
<dubbo:service interface="com.jd.bdp.hydra.dubbomonitor.LeaderService" ref="leaderService" filter="-hydra">
<dubbo:service interface="com.jd.bdp.hydra.dubbomonitor.LeaderService" ref="leaderService">
</dubbo:service>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.227.48:3306/hydra-config
jdbc.username=root
jdbc.password=root
a=a
19 changes: 19 additions & 0 deletions modules/hydra-manager/src/main/resources/scripts/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

#Config your java home
#JAVA_HOME=/opt/jdk/

if [ -z "$JAVA_HOME" ]; then
export JAVA=`which java`
else
export JAVA="$JAVA_HOME/bin/java"
fi

export CLASSPATH=$CLASSPATH:$BASE_DIR/conf:$(ls $BASE_DIR/lib/*.jar | tr '\n' :)

#Server jvm args
SERVER_JVM_ARGS="-Xmx512m -Xms512m -server -cp $CLASSPATH "

if [ -z "$SERVER_ARGS" ]; then
export SERVER_ARGS="$SERVER_JVM_ARGS"
fi
111 changes: 111 additions & 0 deletions modules/hydra-manager/src/main/resources/scripts/manager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash
#project directory

MAINCLASSNAME="com.jd.bdp.hydra.manager.HydraManager"

if [ -z "$BASE_DIR" ] ; then
PRG="$0"

# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
BASE_DIR=`dirname "$PRG"`/..

# make it fully qualified
BASE_DIR=`cd "$BASE_DIR" && pwd`
#echo "Benchtest is at $BASE_DIR"
fi

source $BASE_DIR/bin/env.sh

AS_USER=`whoami`
LOG_DIR="$BASE_DIR/log"
TAIL_FILE="$BASE_DIR/log/Benchtest.log"
PID_DIR="$BASE_DIR/log"
PID_FILE="$PID_DIR/.run.pid"
CONFIG_FILE=" $BASE_DIR"


function running(){
if [ -f "$PID_FILE" ]; then
pid=$(cat "$PID_FILE")
process=`ps aux | grep " $pid " | grep -v grep`;
if [ "$process" == "" ]; then
return 1;
else
return 0;
fi
else
return 1
fi
}

function start_server() {
if running; then
echo "is running."
exit 1
fi

mkdir -p $PID_DIR
mkdir -p $LOG_DIR
chown -R $AS_USER $PID_DIR
chown -R $AS_USER $LOG_DIR

sleep 1
nohup $JAVA $SERVER_ARGS $MAINCLASSNAME $CONFIG_FILE >$TAIL_FILE &
echo $! > $PID_FILE
chmod 755 $PID_FILE
sleep 1;
tail -F $TAIL_FILE
}

function stop_server() {
if ! running; then
echo "service is not running."
exit 1
fi
count=0
pid=$(cat $PID_FILE)
while running;
do
let count=$count+1
echo "Stopping $count times"
if [ $count -gt 5 ]; then
echo "kill -9 $pid"
kill -9 $pid
else
kill $pid
fi
sleep 3;
done
echo "Stop service successfully."
rm $PID_FILE
}

function help() {
echo "Usage: startup.sh {start|stop}" >&2
echo " start: start the server"
echo " stop: stop the server"
}

command=$1
shift 1
case $command in
start)
start_server $@;
;;
stop)
stop_server $@;
;;
*)
help;
exit 1;
;;
esac
Loading

0 comments on commit e759278

Please sign in to comment.