================================================
FILE: codeformat.xml
================================================
================================================
FILE: codetemplates.xml
================================================
/**
* @return the ${bare_field_name}
*//**
* @param ${param} the ${bare_field_name} to set
*//**
* ${tags}
*//**
* @author ${user} ${date} ${time}
* @since 1.0.0
*//**
*
*//**
* ${tags}
*//**
* ${tags}
* ${see_to_target}
*/${filecomment}
${package_declaration}
${typecomment}
${type_declaration}
// ${todo} Auto-generated catch block
${exception_var}.printStackTrace();// ${todo} Auto-generated method stub
${body_statement}${body_statement}
// ${todo} Auto-generated constructor stubreturn ${field};${field} = ${param};
================================================
FILE: docker/Dockerfile
================================================
FROM canal/otter-osbase:v1
MAINTAINER agapple (jianghang115@gmail.com)
# install otter
COPY image/ /tmp/docker/
COPY manager.deployer-*.tar.gz /home/admin/
COPY node.deployer-*.tar.gz /home/admin/
RUN \
cp -R /tmp/docker/alidata /alidata && \
chmod +x /alidata/bin/* && \
mkdir -p /home/admin && \
cp -R /tmp/docker/admin/* /home/admin/ && \
/bin/cp -f alidata/bin/lark-wait /usr/bin/lark-wait && \
mkdir -p /home/admin/manager && \
tar -xzvf /home/admin/manager.deployer-*.tar.gz -C /home/admin/manager && \
/bin/rm -f /home/admin/manager.deployer-*.tar.gz && \
mkdir -p /home/admin/node && \
tar -xzvf /home/admin/node.deployer-*.tar.gz -C /home/admin/node && \
/bin/rm -f /home/admin/node.deployer-*.tar.gz && \
mkdir -p home/admin/manager/logs && \
mkdir -p home/admin/node/logs && \
mkdir -p home/admin/zkData && \
chmod +x /home/admin/*.sh && \
chmod +x /home/admin/bin/*.sh && \
chown admin: -R /home/admin && \
yum clean all && \
true
ENV DOCKER_DEPLOY_TYPE=VM PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/scripts
WORKDIR /home/admin
ENTRYPOINT [ "/alidata/bin/main.sh" ]
CMD [ "/home/admin/app.sh" ]
================================================
FILE: docker/base/Dockerfile
================================================
FROM canal/osbase:v1
MAINTAINER agapple (jianghang115@gmail.com)
RUN \
groupadd -r mysql && useradd -r -g mysql mysql && \
yum -y install wget mysql-server --nogpgcheck && \
yum clean all && \
wget -q https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz -O /home/admin/zookeeper-3.4.13.tar.gz && \
tar -xzvf /home/admin/zookeeper-*.tar.gz -C /home/admin && \
/bin/cp -rf /home/admin/zookeeper-3.4.13/conf/zoo_sample.cfg /home/admin/zookeeper-3.4.13/conf/zoo.cfg && \
sed -i -e 's/^dataDir=\/tmp\/zookeeper$/dataDir=\/home\/admin\/zkData/' /home/admin/zookeeper-3.4.13/conf/zoo.cfg && \
sed -i -e 's/^#autopurge/autopurge/' /home/admin/zookeeper-3.4.13/conf/zoo.cfg && \
/bin/rm -f /home/admin/zookeeper-3.4.13.tar.gz && \
true
CMD ["/bin/bash"]
================================================
FILE: docker/build.sh
================================================
#!/bin/bash
current_path=`pwd`
case "`uname`" in
Darwin)
bin_abs_path=`cd $(dirname $0); pwd`
;;
Linux)
bin_abs_path=$(readlink -f $(dirname $0))
;;
*)
bin_abs_path=`cd $(dirname $0); pwd`
;;
esac
BASE=${bin_abs_path}
if [ "$1" == "base" ] ; then
docker build --no-cache -t canal/otter-osbase $BASE/base
else
rm -rf $BASE/node.*.tar.gz ;
rm -rf $BASE/manager.*.tar.gz ;
cd $BASE/../ && mvn clean package -Dmaven.test.skip -Denv=release && cd $current_path ;
cp $BASE/../target/node.deployer-*.tar.gz $BASE/
cp $BASE/../target/manager.deployer-*.tar.gz $BASE/
docker build --no-cache -t canal/otter-all $BASE/
fi
================================================
FILE: docker/image/admin/app.sh
================================================
#!/bin/bash
set -e
source /etc/profile
export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin:$PATH
touch /tmp/start.log
chown admin: /tmp/start.log
chown admin: /home/admin/manager
chown admin: /home/admin/node
chown admin: /home/admin/zkData
host=`hostname -i`
# default config
if [ -z "${RUN_MODE}" ]; then
RUN_MODE="ALL"
fi
if [ -z "${MYSQL_USER_PASSWORD}" ]; then
MYSQL_USER_PASSWORD="otter"
fi
if [ -z "${OTTER_MANAGER_MYSQL}" ]; then
OTTER_MANAGER_MYSQL="127.0.0.1:3306"
fi
# waitterm
# wait TERM/INT signal.
# see: http://veithen.github.io/2014/11/16/sigterm-propagation.html
waitterm() {
local PID
# any process to block
tail -f /dev/null &
PID="$!"
# setup trap, could do nothing, or just kill the blocker
trap "kill -TERM ${PID}" TERM INT
# wait for signal, ignore wait exit code
wait "${PID}" || true
# clear trap
trap - TERM INT
# wait blocker, ignore blocker exit code
wait "${PID}" 2>/dev/null || true
}
# waittermpid "${PIDFILE}".
# monitor process by pidfile && wait TERM/INT signal.
# if the process disappeared, return 1, means exit with ERROR.
# if TERM or INT signal received, return 0, means OK to exit.
waittermpid() {
local PIDFILE PID do_run error
PIDFILE="${1?}"
do_run=true
error=0
trap "do_run=false" TERM INT
while "${do_run}" ; do
PID="$(cat "${PIDFILE}")"
if ! ps -p "${PID}" >/dev/null 2>&1 ; then
do_run=false
error=1
else
sleep 1
fi
done
trap - TERM INT
return "${error}"
}
function checkStart() {
local name=$1
local cmd=$2
local timeout=$3
cost=5
while [ $timeout -gt 0 ]; do
ST=`eval $cmd`
if [ "$ST" == "0" ]; then
sleep 1
let timeout=timeout-1
let cost=cost+1
elif [ "$ST" == "" ]; then
sleep 1
let timeout=timeout-1
let cost=cost+1
else
break
fi
done
echo "$name start successful"
}
function start_zookeeper() {
echo "start zookeeper ..."
# start zookeeper
rm -f /home/admin/zkData/myid
sed -i '/^server\..*/d' /home/admin/zookeeper-3.4.13/conf/zoo.cfg
su admin -c "mkdir -p /home/admin/zkData; cd /home/admin/zkData; /home/admin/zookeeper-3.4.13/bin/zkServer.sh start >> /home/admin/zkData/zookeeper.log 2>&1"
sleep 5
#check start
checkStart "zookeeper" "echo stat | nc 127.0.0.1 2181 | grep -c Outstanding" 30
}
function stop_zookeeper() {
# stop zookeeper
echo "stop zookeeper"
su admin -c 'mkdir -p /home/admin/zkData; cd /home/admin/zkData; /home/admin/zookeeper-3.4.13/bin/zkServer.sh stop >> /home/admin/zkData/zookeeper.log 2>&1'
echo "stop zookeeper successful ..."
}
function start_manager() {
echo "start manager ..."
# start manager
if [ -n "${OTTER_MANAGER_MYSQL}" ] ; then
cmd="sed -i -e 's/^otter.database.driver.url.*$/otter.database.driver.url = jdbc:mysql:\/\/${OTTER_MANAGER_MYSQL}\/otter/' /home/admin/manager/conf/otter.properties"
eval $cmd
cmd="sed -i -e 's/^otter.database.driver.username.*$/otter.database.driver.username = ${MYSQL_USER}/' /home/admin/manager/conf/otter.properties"
eval $cmd
cmd="sed -i -e 's/^otter.database.driver.password.*$/otter.database.driver.password = ${MYSQL_USER_PASSWORD}/' /home/admin/manager/conf/otter.properties"
eval $cmd
cmd="sed -i -e 's/^otter.communication.manager.port.*$/otter.communication.manager.port = 8081/' /home/admin/manager/conf/otter.properties"
eval $cmd
cmd="sed -i -e 's/^otter.domainName.*$/otter.domainName = ${host}/' /home/admin/manager/conf/otter.properties"
eval $cmd
fi
su admin -c "cd /home/admin/manager/bin ; sh startup.sh 1>>/tmp/start.log 2>&1"
#check start
sleep 5
checkStart "manager" "nc 127.0.0.1 8080 -w 1 -z | wc -l" 60
}
function stop_manager() {
# stop manager
echo "stop manager"
su admin -c 'cd /home/admin/manager/bin; sh stop.sh 1>>/tmp/start.log 2>&1'
echo "stop manager successful ..."
}
function start_node() {
echo "start node ..."
# start node
cmd="sed -i -e 's/^otter.manager.address.*$/otter.manager.address = 127.0.0.1:8081/' /home/admin/node/conf/otter.properties"
eval $cmd
su admin -c 'cd /home/admin/node/bin/ && echo 1 > /home/admin/node/conf/nid && sh startup.sh 1>>/tmp/start.log 2>&1'
sleep 5
#check start
checkStart "node" "nc 127.0.0.1 2088 -w 1 -z | wc -l" 30
}
function stop_node() {
# stop node
echo "stop node"
su admin -c 'cd /home/admin/node/bin/ && sh stop.sh'
echo "stop node successful ..."
}
function start_mysql() {
echo "start mysql ..."
# start mysql
MYSQL_ROOT_PASSWORD=Hello1234
MYSQL_USER=otter
MYSQL_DATABASE=otter
if [ -z "$(ls -A /var/lib/mysql)" ]; then
mysql_install_db --user=mysql --datadir=/var/lib/mysql 1>>/tmp/start.log 2>&1
# These statements _must_ be on individual lines, and _must_ end with
# semicolons (no line breaks or comments are permitted).
# TODO proper SQL escaping on ALL the things D:
TEMP_FILE='/tmp/init.sql'
echo "update mysql.user set password=password('${MYSQL_ROOT_PASSWORD}') where user='root';" >> $TEMP_FILE
echo "grant all privileges on *.* to 'root'@'%' WITH GRANT OPTION ;" >> $TEMP_FILE
echo "create database if not exists $MYSQL_DATABASE ;" >> $TEMP_FILE
echo "create user $MYSQL_USER identified by '$MYSQL_USER_PASSWORD' ;" >> $TEMP_FILE
echo "grant all privileges on $MYSQL_DATABASE.* to '$MYSQL_USER'@'%' identified by '$MYSQL_USER_PASSWORD' ;" >> $TEMP_FILE
echo "grant all privileges on $MYSQL_DATABASE.* to '$MYSQL_USER'@'localhost' identified by '$MYSQL_USER_PASSWORD' ;" >> $TEMP_FILE
echo "flush privileges;" >> $TEMP_FILE
service mysqld start
checkStart "mysql" "echo 'show status' | mysql -s -h127.0.0.1 -P3306 -uroot | grep -c Uptime" 30
mysql -h127.0.0.1 -uroot -e "source $TEMP_FILE" 1>>/tmp/start.log 2>&1
cmd="sed -i -e 's/#OTTER_MY_ZK#/127.0.0.1:2181/' /home/admin/bin/ddl.sql"
eval $cmd
cmd="sed -i -e 's/#OTTER_NODE_HOST#/127.0.0.1/' /home/admin/bin/ddl.sql"
eval $cmd
cmd="mysql -h127.0.0.1 -u$MYSQL_USER -p$MYSQL_USER_PASSWORD $MYSQL_DATABASE -e 'source /home/admin/bin/ddl.sql' 1>>/tmp/start.log 2>&1"
eval $cmd
/bin/rm -f /home/admin/bin/ddl.sql
else
chown -R mysql:mysql /var/lib/mysql
service mysqld start
#check start
checkStart "mysql" "echo 'show status' | mysql -b -s -h127.0.0.1 -P3306 -uroot -p$MYSQL_ROOT_PASSWORD | grep -c Uptime" 30
fi
}
function stop_mysql() {
echo "stop mysql ..."
# stop mysql
service mysqld stop
echo "stop mysql successful ..."
}
echo "==> START ..."
start_mysql
start_zookeeper
start_manager
start_node
echo "you can visit manager link : http://$host:8080/ , just have fun !"
echo "==> START SUCCESSFUL ..."
tail -f /dev/null &
# wait TERM signal
waitterm
echo "==> STOP"
stop_node
stop_manager
stop_zookeeper
stop_zookeeper
stop_mysql
echo "==> STOP SUCCESSFUL ..."
================================================
FILE: docker/image/admin/bin/clean_log
================================================
# cron clean log once per minute
*/2 * * * * admin /home/admin/bin/clean_log.sh >>/tmp/clean_log.log 2>&1
================================================
FILE: docker/image/admin/bin/clean_log.sh
================================================
#!/bin/bash
# Global Settings
PATH="$HOME/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin"
export PATH
CUTOFF="85"
#获取磁盘使用率最高的分区
USAGE=$(df -h|awk 'NR>1 {gsub(/%$/,"",$5);print $5 }'|sort -nr|head -1)
before=$USAGE
baseClean(){
#删除tmp目录15天前的文件。
#更新文档时间戳
if [ -d /tmp/hsperfdata_admin ]
then
touch /tmp/hsperfdata_admin
touch /tmp/hsperfdata_admin/*
fi
find /tmp/ -type f -mtime +15 | xargs -t rm -rf >/dev/null 2>&1
now=$(df -h|awk 'NR>1 {gsub(/%$/,"",$5);print $5 }'|sort -nr|head -1)
echo "before:$before; now:$now"
}
MANAGER_DIR="/home/admin/manager/logs"
NODE_DIR="/home/admin/node/logs"
if [[ -d $MANAGER_DIR ]]; then
USAGE=$(df -h|awk 'NR>1 {gsub(/%$/,"",$5);print $5 }'|sort -nr|head -1)
if [[ $USAGE -ge 90 ]]; then
find $MANAGER_DIR -type f -mtime +7 | xargs rm -rf {}
fi
USAGE=$(df -h|awk 'NR>1 {gsub(/%$/,"",$5);print $5 }'|sort -nr|head -1)
if [[ $USAGE -ge 80 ]]; then
find $MANAGER_DIR -type f -mtime +3 | xargs rm -rf {}
fi
USAGE=$(df -h|awk 'NR>1 {gsub(/%$/,"",$5);print $5 }'|sort -nr|head -1)
if [[ $USAGE -ge 80 ]]; then
find $MANAGER_DIR -type d -empty -mtime +3 | grep -v manager | xargs rm -rf {}
find $MANAGER_DIR -type f -iname '*.tmp' | xargs rm -rf {}
fi
baseClean
exit 0
fi
if [[ -d $NODE_DIR ]]; then
USAGE=$(df -h|awk 'NR>1 {gsub(/%$/,"",$5);print $5 }'|sort -nr|head -1)
if [[ $USAGE -ge 90 ]]; then
find $NODE_DIR -type f -mtime +7 | xargs rm -rf {}
fi
USAGE=$(df -h|awk 'NR>1 {gsub(/%$/,"",$5);print $5 }'|sort -nr|head -1)
if [[ $USAGE -ge 80 ]]; then
find $NODE_DIR -type f -mtime +3 | xargs rm -rf {}
fi
USAGE=$(df -h|awk 'NR>1 {gsub(/%$/,"",$5);print $5 }'|sort -nr|head -1)
if [[ $USAGE -ge 80 ]]; then
find $NODE_DIR -type d -empty -mtime +3 | grep -v node | xargs rm -rf {}
find $NODE_DIR -type f -iname '*.tmp' | xargs rm -rf {}
fi
baseClean
exit 0
fi
================================================
FILE: docker/image/admin/bin/ddl.sql
================================================
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `otter` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */;
USE `otter`;
CREATE TABLE `ALARM_RULE` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`MONITOR_NAME` varchar(1024) DEFAULT NULL,
`RECEIVER_KEY` varchar(1024) DEFAULT NULL,
`STATUS` varchar(32) DEFAULT NULL,
`PIPELINE_ID` bigint(20) NOT NULL,
`DESCRIPTION` varchar(256) DEFAULT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`MATCH_VALUE` varchar(1024) DEFAULT NULL,
`PARAMETERS` text DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `AUTOKEEPER_CLUSTER` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`CLUSTER_NAME` varchar(200) NOT NULL,
`SERVER_LIST` varchar(1024) NOT NULL,
`DESCRIPTION` varchar(200) DEFAULT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `CANAL` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`NAME` varchar(200) DEFAULT NULL,
`DESCRIPTION` varchar(200) DEFAULT NULL,
`PARAMETERS` text DEFAULT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
UNIQUE KEY `CANALUNIQUE` (`NAME`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `CHANNEL` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`NAME` varchar(200) NOT NULL,
`DESCRIPTION` varchar(200) DEFAULT NULL,
`PARAMETERS` text DEFAULT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
UNIQUE KEY `CHANNELUNIQUE` (`NAME`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `COLUMN_PAIR` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`SOURCE_COLUMN` varchar(200) DEFAULT NULL,
`TARGET_COLUMN` varchar(200) DEFAULT NULL,
`DATA_MEDIA_PAIR_ID` bigint(20) NOT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `idx_DATA_MEDIA_PAIR_ID` (`DATA_MEDIA_PAIR_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `COLUMN_PAIR_GROUP` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`DATA_MEDIA_PAIR_ID` bigint(20) NOT NULL,
`COLUMN_PAIR_CONTENT` text DEFAULT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `idx_DATA_MEDIA_PAIR_ID` (`DATA_MEDIA_PAIR_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `DATA_MEDIA` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`NAME` varchar(200) NOT NULL,
`NAMESPACE` varchar(200) NOT NULL,
`PROPERTIES` varchar(1000) NOT NULL,
`DATA_MEDIA_SOURCE_ID` bigint(20) NOT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
UNIQUE KEY `DATAMEDIAUNIQUE` (`NAME`,`NAMESPACE`,`DATA_MEDIA_SOURCE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `DATA_MEDIA_PAIR` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`PULLWEIGHT` bigint(20) DEFAULT NULL,
`PUSHWEIGHT` bigint(20) DEFAULT NULL,
`RESOLVER` text DEFAULT NULL,
`FILTER` text DEFAULT NULL,
`SOURCE_DATA_MEDIA_ID` bigint(20) DEFAULT NULL,
`TARGET_DATA_MEDIA_ID` bigint(20) DEFAULT NULL,
`PIPELINE_ID` bigint(20) NOT NULL,
`COLUMN_PAIR_MODE` varchar(20) DEFAULT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `idx_PipelineID` (`PIPELINE_ID`,`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `DATA_MEDIA_SOURCE` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`NAME` varchar(200) NOT NULL,
`TYPE` varchar(20) NOT NULL,
`PROPERTIES` varchar(1000) NOT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
UNIQUE KEY `DATAMEDIASOURCEUNIQUE` (`NAME`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `DELAY_STAT` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`DELAY_TIME` bigint(20) NOT NULL,
`DELAY_NUMBER` bigint(20) NOT NULL,
`PIPELINE_ID` bigint(20) NOT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `idx_PipelineID_GmtModified_ID` (`PIPELINE_ID`,`GMT_MODIFIED`,`ID`),
KEY `idx_Pipeline_GmtCreate` (`PIPELINE_ID`,`GMT_CREATE`),
KEY `idx_GmtCreate_id` (`GMT_CREATE`,`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `LOG_RECORD` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`NID` varchar(200) DEFAULT NULL,
`CHANNEL_ID` varchar(200) NOT NULL,
`PIPELINE_ID` varchar(200) NOT NULL,
`TITLE` varchar(1000) DEFAULT NULL,
`MESSAGE` text DEFAULT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `logRecord_pipelineId` (`PIPELINE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `NODE` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`NAME` varchar(200) NOT NULL,
`IP` varchar(200) NOT NULL,
`PORT` bigint(20) NOT NULL,
`DESCRIPTION` varchar(200) DEFAULT NULL,
`PARAMETERS` text DEFAULT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
UNIQUE KEY `NODEUNIQUE` (`NAME`,`IP`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `PIPELINE` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`NAME` varchar(200) NOT NULL,
`DESCRIPTION` varchar(200) DEFAULT NULL,
`PARAMETERS` text DEFAULT NULL,
`CHANNEL_ID` bigint(20) NOT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
UNIQUE KEY `PIPELINEUNIQUE` (`NAME`,`CHANNEL_ID`),
KEY `idx_ChannelID` (`CHANNEL_ID`,`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `PIPELINE_NODE_RELATION` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`NODE_ID` bigint(20) NOT NULL,
`PIPELINE_ID` bigint(20) NOT NULL,
`LOCATION` varchar(20) NOT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `idx_PipelineID` (`PIPELINE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `SYSTEM_PARAMETER` (
`ID` bigint(20) unsigned NOT NULL,
`VALUE` text DEFAULT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `TABLE_HISTORY_STAT` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`FILE_SIZE` bigint(20) DEFAULT NULL,
`FILE_COUNT` bigint(20) DEFAULT NULL,
`INSERT_COUNT` bigint(20) DEFAULT NULL,
`UPDATE_COUNT` bigint(20) DEFAULT NULL,
`DELETE_COUNT` bigint(20) DEFAULT NULL,
`DATA_MEDIA_PAIR_ID` bigint(20) DEFAULT NULL,
`PIPELINE_ID` bigint(20) DEFAULT NULL,
`START_TIME` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`END_TIME` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `idx_DATA_MEDIA_PAIR_ID_END_TIME` (`DATA_MEDIA_PAIR_ID`,`END_TIME`),
KEY `idx_GmtCreate_id` (`GMT_CREATE`,`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `TABLE_STAT` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`FILE_SIZE` bigint(20) NOT NULL,
`FILE_COUNT` bigint(20) NOT NULL,
`INSERT_COUNT` bigint(20) NOT NULL,
`UPDATE_COUNT` bigint(20) NOT NULL,
`DELETE_COUNT` bigint(20) NOT NULL,
`DATA_MEDIA_PAIR_ID` bigint(20) NOT NULL,
`PIPELINE_ID` bigint(20) NOT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `idx_PipelineID_DataMediaPairID` (`PIPELINE_ID`,`DATA_MEDIA_PAIR_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `THROUGHPUT_STAT` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`TYPE` varchar(20) NOT NULL,
`NUMBER` bigint(20) NOT NULL,
`SIZE` bigint(20) NOT NULL,
`PIPELINE_ID` bigint(20) NOT NULL,
`START_TIME` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`END_TIME` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `idx_PipelineID_Type_GmtCreate_ID` (`PIPELINE_ID`,`TYPE`,`GMT_CREATE`,`ID`),
KEY `idx_PipelineID_Type_EndTime_ID` (`PIPELINE_ID`,`TYPE`,`END_TIME`,`ID`),
KEY `idx_GmtCreate_id` (`GMT_CREATE`,`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `USER` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`USERNAME` varchar(20) NOT NULL,
`PASSWORD` varchar(20) NOT NULL,
`AUTHORIZETYPE` varchar(20) NOT NULL,
`DEPARTMENT` varchar(20) NOT NULL,
`REALNAME` varchar(20) NOT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
UNIQUE KEY `USERUNIQUE` (`USERNAME`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `DATA_MATRIX` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`GROUP_KEY` varchar(200) DEFAULT NULL,
`MASTER` varchar(200) DEFAULT NULL,
`SLAVE` varchar(200) DEFAULT NULL,
`DESCRIPTION` varchar(200) DEFAULT NULL,
`GMT_CREATE` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`GMT_MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
KEY `GROUPKEY` (`GROUP_KEY`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `meta_history` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`gmt_create` datetime NOT NULL COMMENT '创建时间',
`gmt_modified` datetime NOT NULL COMMENT '修改时间',
`destination` varchar(128) DEFAULT NULL COMMENT '通道名称',
`binlog_file` varchar(64) DEFAULT NULL COMMENT 'binlog文件名',
`binlog_offest` bigint(20) DEFAULT NULL COMMENT 'binlog偏移量',
`binlog_master_id` varchar(64) DEFAULT NULL COMMENT 'binlog节点id',
`binlog_timestamp` bigint(20) DEFAULT NULL COMMENT 'binlog应用的时间戳',
`use_schema` varchar(1024) DEFAULT NULL COMMENT '执行sql时对应的schema',
`sql_schema` varchar(1024) DEFAULT NULL COMMENT '对应的schema',
`sql_table` varchar(1024) DEFAULT NULL COMMENT '对应的table',
`sql_text` longtext DEFAULT NULL COMMENT '执行的sql',
`sql_type` varchar(256) DEFAULT NULL COMMENT 'sql类型',
`extra` text DEFAULT NULL COMMENT '额外的扩展信息',
PRIMARY KEY (`id`),
UNIQUE KEY binlog_file_offest(`destination`,`binlog_master_id`,`binlog_file`,`binlog_offest`),
KEY `destination` (`destination`),
KEY `destination_timestamp` (`destination`,`binlog_timestamp`),
KEY `gmt_modified` (`gmt_modified`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='表结构变化明细表';
CREATE TABLE IF NOT EXISTS `meta_snapshot` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`gmt_create` datetime NOT NULL COMMENT '创建时间',
`gmt_modified` datetime NOT NULL COMMENT '修改时间',
`destination` varchar(128) DEFAULT NULL COMMENT '通道名称',
`binlog_file` varchar(64) DEFAULT NULL COMMENT 'binlog文件名',
`binlog_offest` bigint(20) DEFAULT NULL COMMENT 'binlog偏移量',
`binlog_master_id` varchar(64) DEFAULT NULL COMMENT 'binlog节点id',
`binlog_timestamp` bigint(20) DEFAULT NULL COMMENT 'binlog应用的时间戳',
`data` longtext DEFAULT NULL COMMENT '表结构数据',
`extra` text DEFAULT NULL COMMENT '额外的扩展信息',
PRIMARY KEY (`id`),
UNIQUE KEY binlog_file_offest(`destination`,`binlog_master_id`,`binlog_file`,`binlog_offest`),
KEY `destination` (`destination`),
KEY `destination_timestamp` (`destination`,`binlog_timestamp`),
KEY `gmt_modified` (`gmt_modified`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='表结构记录表快照表';
insert into USER(ID,USERNAME,PASSWORD,AUTHORIZETYPE,DEPARTMENT,REALNAME,GMT_CREATE,GMT_MODIFIED) values(null,'admin','801fc357a5a74743894a','ADMIN','admin','admin',now(),now());
insert into USER(ID,USERNAME,PASSWORD,AUTHORIZETYPE,DEPARTMENT,REALNAME,GMT_CREATE,GMT_MODIFIED) values(null,'guest','471e02a154a2121dc577','OPERATOR','guest','guest',now(),now());
replace into AUTOKEEPER_CLUSTER(ID,CLUSTER_NAME,SERVER_LIST,DESCRIPTION,GMT_CREATE,GMT_MODIFIED) values(1,'default','["#OTTER_MY_ZK#"]',NULL,now(),now());
replace into NODE(ID,NAME,IP,PORT,DESCRIPTION,PARAMETERS,GMT_CREATE,GMT_MODIFIED) values(1,'default','#OTTER_NODE_HOST#',2088,NULL,'{"downloadPort":2089,"mbeanPort":2090,"useExternalIp":false,"zkCluster":{"clusterName":"default","id":1}}', now(), now());
================================================
FILE: docker/image/admin/health.sh
================================================
#!/bin/sh
CHECK_URL="http://127.0.0.1:8080/ok.htm"
CHECK_POINT="ok"
CHECK_COUNT=`curl -s --connect-timeout 7 --max-time 7 $CHECK_URL | grep -c $CHECK_POINT`
if [ $CHECK_COUNT -eq 0 ]; then
echo "[FAILED]"
status=0
error=1
else
echo "[ OK ]"
status=1
error=0
fi
================================================
FILE: docker/image/alidata/bin/exec_rc_local.sh
================================================
#!/bin/bash
if [ "${SKIP_EXEC_RC_LOCAL}" = "YES" ] ; then
echo "skip /etc/rc.local: SKIP_EXEC_RC_LOCAL=${SKIP_EXEC_RC_LOCAL}"
exit
fi
if [ "${DOCKER_DEPLOY_TYPE}" = "HOST" ] ; then
echo "skip /etc/rc.local: DOCKER_DEPLOY_TYPE=${DOCKER_DEPLOY_TYPE}"
exit
fi
================================================
FILE: docker/image/alidata/bin/lark-wait
================================================
#!/bin/bash
set -e
chown admin: -R /home/admin/
source /alidata/lib/proc.sh
waitterm
================================================
FILE: docker/image/alidata/bin/main.sh
================================================
#!/bin/bash
[ -n "${DOCKER_DEPLOY_TYPE}" ] || DOCKER_DEPLOY_TYPE="VM"
echo "DOCKER_DEPLOY_TYPE=${DOCKER_DEPLOY_TYPE}"
# run init scripts
for e in $(ls /alidata/init/*) ; do
[ -x "${e}" ] || continue
echo "==> INIT $e"
$e
echo "==> EXIT CODE: $?"
done
echo "==> INIT DEFAULT"
service sshd start
service crond start
#echo "check hostname -i: `hostname -i`"
#hti_num=`hostname -i|awk '{print NF}'`
#if [ $hti_num -gt 1 ];then
# echo "hostname -i result error:`hostname -i`"
# exit 120
#fi
echo "==> INIT DONE"
echo "==> RUN ${*}"
exec "${@}"
================================================
FILE: docker/image/alidata/init/02init-sshd.sh
================================================
#!/bin/bash
# set port
if [ -z "${SSHD_PORT}" ] ; then
SSHD_PORT=22
[ "${DOCKER_DEPLOY_TYPE}" = "HOST" ] && SSHD_PORT=2222
fi
sed -r -i '/^OPTIONS=/ d' /etc/sysconfig/sshd
echo 'OPTIONS="-p '"${SSHD_PORT}"'"' >> /etc/sysconfig/sshd
# set admin ssh pulic key
if [ "${USE_ADMIN_PASSAGE}" = "YES" ] ; then
echo "set admin passage"
mkdir -p /home/admin/.ssh
chown admin:admin /home/admin/.ssh
chown admin:admin /home/admin/.ssh/authorized_keys
chmod 644 /home/admin/.ssh/authorized_keys
fi
================================================
FILE: docker/image/alidata/init/fix-hosts.py
================================================
#!/usr/bin/python
# -*- coding: utf-8 -*-
#****************************************************************#
# Create Date: 2017-01-06 17:58
#***************************************************************#
import socket
import shutil
from time import gmtime, strftime
# get host_name
host_name = socket.gethostname()
tmp_file = "/tmp/.lark-fix-host.hosts"
host_file = "/etc/hosts"
bak_file_name = "/tmp/hosts-fix-bak.%s" % ( strftime("%Y-%m-%d_%H-%M-%S", gmtime()) )
# load /etc/hosts file context
FH = open(host_file,"r")
file_lines = [ i.rstrip() for i in FH.readlines()]
FH.close()
file_lines_reverse = file_lines[::-1]
new_lines = []
bad_lines = []
last_match_line = ""
for line in file_lines_reverse:
if line.find(host_name) < 0: # 不匹配的行直接跳过
new_lines.append(line + "\n")
continue
cols = line.split()
new_cols = []
if cols[0].startswith("#"): # 跳过已经注释掉的行
new_lines.append(line + "\n")
continue
for col in cols:
if not col == host_name: # 跳过不匹配的列
new_cols.append(col)
continue
if cols[0] == "127.0.0.1": # 如果第一列是 127.0.0.1 就跳过匹配的列, 防止 hostname -i 返回 127.0.0.1
continue
# 如果已经发现过匹配的列, 就丢掉重复的列
if not len(last_match_line) == 0:
continue
new_cols.append(col)
last_match_line = line
# 跳过 xx.xx.xx.xx hostname 这样的重复列
if len(new_cols) == 1:
continue
new_l = "%s\n" % " ".join(new_cols)
new_lines.append(new_l)
# save tmp hosts
FH2=file(tmp_file,"w+")
FH2.writelines( new_lines[::-1])
FH2.close()
# mv to /etc/hosts
shutil.copy(host_file, bak_file_name)
shutil.move(tmp_file, host_file)
================================================
FILE: docker/image/alidata/lib/proc.sh
================================================
# waitterm
# wait TERM/INT signal.
# see: http://veithen.github.io/2014/11/16/sigterm-propagation.html
waitterm() {
local PID
# any process to block
tail -f /dev/null &
PID="$!"
# setup trap, could do nothing, or just kill the blocker
trap "kill -TERM ${PID}" TERM INT
# wait for signal, ignore wait exit code
wait "${PID}" || true
# clear trap
trap - TERM INT
# wait blocker, ignore blocker exit code
wait "${PID}" 2>/dev/null || true
}
# waittermpid "${PIDFILE}".
# monitor process by pidfile && wait TERM/INT signal.
# if the process disappeared, return 1, means exit with ERROR.
# if TERM or INT signal received, return 0, means OK to exit.
waittermpid() {
local PIDFILE PID do_run error
PIDFILE="${1?}"
do_run=true
error=0
trap "do_run=false" TERM INT
while "${do_run}" ; do
PID="$(cat "${PIDFILE}")"
if ! ps -p "${PID}" >/dev/null 2>&1 ; then
do_run=false
error=1
else
sleep 1
fi
done
trap - TERM INT
return "${error}"
}
================================================
FILE: docker/run.sh
================================================
#!/bin/bash
function usage() {
echo "Usage:"
echo " run.sh [CONFIG]"
echo "example:"
echo " run.sh NODE -e OTTER_MANAGER=127.0.0.1:8080"
exit
}
function check_port() {
local port=$1
local TL=$(which telnet)
if [ -f $TL ]; then
data=`echo quit | telnet 127.0.0.1 $port| grep -ic connected`
echo $data
return
fi
local NC=$(which nc)
if [ -f $NC ]; then
data=`nc -z -w 1 127.0.0.1 $port | grep -ic succeeded`
echo $data
return
fi
echo "0"
return
}
function getMyIp() {
case "`uname`" in
Darwin)
myip=`echo "show State:/Network/Global/IPv4" | scutil | grep PrimaryInterface | awk '{print $3}' | xargs ifconfig | grep inet | grep -v inet6 | awk '{print $2}'`
;;
*)
myip=`ip route get 1 | awk '{print $NF;exit}'`
;;
esac
echo $myip
}
NET_MODE=""
case "`uname`" in
Darwin)
bin_abs_path=`cd $(dirname $0); pwd`
;;
Linux)
bin_abs_path=$(readlink -f $(dirname $0))
NET_MODE="--net=host"
;;
*)
NET_MODE="--net=host"
bin_abs_path=`cd $(dirname $0); pwd`
;;
esac
BASE=${bin_abs_path}
if [ "$1" == "-h" ] ; then
usage
elif [ "$1" == "help" ] ; then
usage
fi
DATA="$BASE/data"
mkdir -p $DATA
RUN_MODE=$1
CONFIG=${@:2}
VOLUMNS="-v $DATA/mysql:/var/lib/mysql -v $DATA/zkData:/home/admin/zkData"
PORTLIST="8080 8081 2181 2088 2089 2090"
PORTS=""
for PORT in $PORTLIST ; do
#exist=`check_port $PORT`
exist="0"
if [ "$exist" == "0" ]; then
PORTS="$PORTS -p $PORT:$PORT"
else
echo "port $PORT is used , pls check"
exit 1
fi
done
MEMORY="-m 4096m"
LOCALHOST=`getMyIp`
cmd="docker run -d -it -h $LOCALHOST $CONFIG --name=otter-all $VOLUMNS $NET_MODE $PORTS $MEMORY canal/otter-all"
echo $cmd
eval $cmd
================================================
FILE: lib/install.bat
================================================
call mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.1.0.7.0 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true
call mvn install:install-file -DgroupId=org.jtester -DartifactId=jtester -Dversion=1.1.8 -Dpackaging=jar -DpomFile=jtester-1.1.8.pom -Dfile=jtester-1.1.8.jar -Dsources=jtester-1.1.8-sources.jar
call mvn install:install-file -DgroupId=mockit -DartifactId=jmockit -Dversion=0.999.10 -Dpackaging=jar -DpomFile=jmockit-0.999.10.pom -Dfile=jmockit-0.999.10.jar -Dsources=jmockit-0.999.10-sources.jar
================================================
FILE: lib/install.sh
================================================
#!/bin/bash
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.1.0.7.0 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true
mvn install:install-file -DgroupId=org.jtester -DartifactId=jtester -Dversion=1.1.8 -Dpackaging=jar -DpomFile=jtester-1.1.8.pom -Dfile=jtester-1.1.8.jar -Dsources=jtester-1.1.8-sources.jar
mvn install:install-file -DgroupId=mockit -DartifactId=jmockit -Dversion=0.999.10 -Dpackaging=jar -DpomFile=jmockit-0.999.10.pom -Dfile=jmockit-0.999.10.jar -Dsources=jmockit-0.999.10-sources.jar
================================================
FILE: lib/jmockit-0.999.10.pom
================================================
4.0.0mockitjmockit0.999.10Mainsrcjmockit.propertiesmaven-jar-plugin2.2compilejarfalseMETA-INF/MANIFEST.MFTemp.classmaven-source-plugin2.1.2attach-sourcesjarmaven-surefire-plugin2.5none:none-javaagent:"${project.build.directory}"/jmockit-${project.version}.jar**/*$***/Base*Test.class**/testng/*Test.class**/MockStateBetweenTestMethodsNGTest.classjunitjunit${junit.version}trueorg.testngtestng6.0.1trueorg.beanshellbshcom.google.injectguicecom.beustjcommanderorg.yamlsnakeyamlcommons-loggingcommons-logging1.1.1trueorg.slf4jslf4j-api1.5.8truelog4jlog4j1.2.15truejavax.jmsjmsjavax.mailmailcom.sun.jmxjmxricom.sun.jdmkjmxtools
================================================
FILE: lib/jtester-1.1.8.pom
================================================
4.0.0org.jtesterjtester1.1.8jarjtester coreorg.testngtestng6.1.1mockitjmockit0.999.10commons-dbcpcommons-dbcp1.2.2cglibcglib-nodep2.1_3org.fitnessefitnesse20111025ognlognl2.7.2org.springframeworkspring2.5.4providedorg.springframeworkspring-aspects2.5.4providedjavax.transactionjta1.1providedorg.apache.ibatisibatis-sqlmap2.3.4.726providedorg.springframeworkspring-aop2.5.4providedjavax.annotationjsr250-api1.0providedmysqlmysql-connector-java5.1.6providedcom.h2databaseh21.1.107providedcom.oracleojdbc611.1.0.7.0providedjavax.servletservlet-api2.4providedsrc/main/javatarget/classessrc/main/resourcesmaven-compiler-plugin2.0.21.51.5utf-8org.apache.maven.pluginsmaven-jar-plugin2.2maven-source-pluginattach-sourcesjar
================================================
FILE: manager/biz/pom.xml
================================================
4.0.0com.alibaba.ottermanager4.2.19-SNAPSHOT../pom.xmlcom.alibaba.ottermanager.bizjarmanager biz module for otterhttp://github.com/alibaba/ottercom.alibaba.ottershared.common${project.version}com.alibaba.ottershared.push${project.version}com.alibaba.ottercanal.instance.manager${otter_canal_version}org.springframeworkspringcglibcglib-nodeporg.apache.ibatisibatis-sqlmapcommons-dbcpcommons-dbcpmysqlmysql-connector-javacom.oracleojdbc6org.springframeworkspring-coreorg.springframeworkspring-beansorg.springframeworkspring-aoporg.springframeworkspring-contextorg.springframeworkspring-context-supportorg.springframeworkspring-txorg.springframeworkspring-jdbcorg.springframeworkspring-ormorg.springframeworkspring-weborg.springframeworkspring-webmvcorg.springframeworkspring-testjavax.mailmailcom.alibabafastjsoncom.google.guavaguavaorg.jtesterjtestertestjunitjunittest
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/autokeeper/AutoKeeperStatService.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.autokeeper;
import java.util.List;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperConnectionStat;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat;
/**
* zookeeper状态查询接口
*
* @author jianghang 2012-9-21 下午02:42:16
* @version 4.1.0
*/
public interface AutoKeeperStatService {
/**
* 根据serverIp查询对应的统计信息,包括Connection/Watch/Ephemeral等统计信息
*
* @param serverIp
* @return
*/
public AutoKeeperServerStat findServerStat(String serverIp);
/**
* 根据sessionId查询对应的统计信息,包括详细的Connection/Watch/Ephemeral等统计信息
*
* @param sessionId
* @return
*/
public AutoKeeperServerStat findServerStatBySessionId(String sessionId);
/**
* 根据sessionId查询对应的connction链接
*
* @param sessionId
* @return
*/
public AutoKeeperConnectionStat findConnectionBySessionId(String sessionId);
/**
* 根据临时节点路径查询对应的connection统计信息
*
* @param path
* @return
*/
public AutoKeeperConnectionStat findConnectionByEphemeralPath(String path);
/**
* 根据watcher路径查询对应的connection统计信息
*
* @param path
* @return
*/
public List findConnectionByWatcherPath(String path);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/autokeeper/impl/AutoKeeperCollector.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.autokeeper.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import com.alibaba.otter.manager.biz.common.exceptions.ManagerException;
import com.alibaba.otter.manager.biz.config.autokeeper.AutoKeeperClusterService;
import com.alibaba.otter.manager.biz.utils.RegexUtils;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperConnectionStat;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperEphemeralStat;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperQuorumType;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperWatchStat;
import com.alibaba.otter.shared.common.utils.cmd.Exec;
import com.alibaba.otter.shared.common.utils.cmd.Exec.Result;
import com.alibaba.otter.shared.common.utils.thread.NamedThreadFactory;
/**
* 对应的数据采集器
*
* @author jianghang 2012-9-21 下午03:05:28
* @version 4.1.0
*/
public class AutoKeeperCollector implements InitializingBean {
@Resource(name = "autoKeeperClusterService")
private AutoKeeperClusterService autoKeeperClusterService;
private static final String MODE_FOLLOWER = "Mode: follower";
private static final String MODE_LEADERER = "Mode: leader";
private static final String MODE_OBSERVER = "Mode: observer";
private static final String MODE_STANDALONE = "Mode: standalone";
private static final String NODE_COUNT = "Node count:";
private static final String STRING_LATENCY = "Latency min/avg/max:";
private static final String STRING_SENT = "Sent:";
private static final String STRING_RECEIVED = "Received:";
private static final String STRING_OUTSTANDING = "Outstanding:";
private static final String COMMA = ",";
private static final String BRACKETS = ")";
private static final String COLON = ":";
private static final String WRAP = "\n";
private static final String CMD_STAT = "echo stat | nc %s %s";
private static final String CMD_CONS = "echo cons | nc %s %s";
private static final String CMD_DUMP = "echo dump | nc %s %s";
private static final String CMD_WCHC = "echo wchc | nc %s %s";
private static final long DEFAULT_COLLECT_INTERVAL = 300;
private long delay = 1;
private int singleSize = 1;
private long collectInterval = DEFAULT_COLLECT_INTERVAL;
private AutoKeeperData autoKeeperData;
private ScheduledExecutorService collectorExecutor;
public void collectorConnectionStat(String address) {
List netAddress = splitAddress(address);
if (netAddress.isEmpty()) {
return;
}
String ip = netAddress.get(0);
String port = netAddress.get(1);
String[] cmd = { "/bin/bash", "-c", String.format(CMD_CONS, ip, port) };
String cmdresult = collector(cmd);
String[] result = cmdresult.split(WRAP);
List summary = new ArrayList();
for (String line : result) {
if (StringUtils.isBlank(line)) {
continue;
}
String[] lineArray = line.split(":");
if (2 != lineArray.length) {
continue;
}
AutoKeeperConnectionStat autoKeeperConnectionStat = new AutoKeeperConnectionStat();
autoKeeperConnectionStat.setOriginalContent(line);
String clientIp = StringUtils.trimToEmpty(line.split(":")[0].replace("/", ""));
String sessionId = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "sid=(?s).*?[,)]")).replace("sid=",
StringUtils.EMPTY).replace(COMMA,
StringUtils.EMPTY).replace(BRACKETS,
StringUtils.EMPTY);
String queued = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "queued=(?s).*?[,)]")).replace("queued=",
StringUtils.EMPTY).replace(COMMA,
StringUtils.EMPTY).replace(BRACKETS,
StringUtils.EMPTY);
String receive = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "recved=(?s).*?[,)]")).replace("recved=",
StringUtils.EMPTY).replace(COMMA,
StringUtils.EMPTY).replace(BRACKETS,
StringUtils.EMPTY);
String sent = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "sent=(?s).*?[,)]")).replace("sent=",
StringUtils.EMPTY).replace(COMMA,
StringUtils.EMPTY).replace(BRACKETS,
StringUtils.EMPTY);
String minlat = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "minlat=(?s).*?[,)]")).replace("minlat=",
StringUtils.EMPTY).replace(COMMA,
StringUtils.EMPTY).replace(BRACKETS,
StringUtils.EMPTY);
String avglat = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "avglat=(?s).*?[,)]")).replace("avglat=",
StringUtils.EMPTY).replace(COMMA,
StringUtils.EMPTY).replace(BRACKETS,
StringUtils.EMPTY);
String maxlat = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "maxlat=(?s).*?[,)]")).replace("maxlat=",
StringUtils.EMPTY).replace(COMMA,
StringUtils.EMPTY).replace(BRACKETS,
StringUtils.EMPTY);
autoKeeperConnectionStat.setServerAddress(ip);
autoKeeperConnectionStat.setClientAddress(clientIp);
autoKeeperConnectionStat.setSessionId(sessionId);
if (StringUtils.isNotEmpty(queued)) {
autoKeeperConnectionStat.setQueued(Long.parseLong(queued));
}
if (StringUtils.isNotEmpty(receive)) {
autoKeeperConnectionStat.setRecved(Long.parseLong(receive));
}
if (StringUtils.isNotEmpty(sent)) {
autoKeeperConnectionStat.setSent(Long.parseLong(sent));
}
if (StringUtils.isNotEmpty(minlat)) {
autoKeeperConnectionStat.setMinLatency(Long.parseLong(minlat));
}
if (StringUtils.isNotEmpty(avglat)) {
autoKeeperConnectionStat.setAvgLatency(Long.parseLong(avglat));
}
if (StringUtils.isNotEmpty(maxlat)) {
autoKeeperConnectionStat.setMaxLatency(Long.parseLong(maxlat));
}
summary.add(autoKeeperConnectionStat);
}
autoKeeperData.joinConnection(address, summary);
}
public void collectorServerStat(String address) {
List netAddress = splitAddress(address);
if (netAddress.isEmpty()) {
return;
}
String ip = netAddress.get(0);
String port = netAddress.get(1);
String[] cmd = { "/bin/bash", "-c", String.format(CMD_STAT, ip, port) };
String cmdresult = collector(cmd);
String[] result = cmdresult.split(WRAP);
AutoKeeperServerStat summary = new AutoKeeperServerStat();
summary.setOriginalContent(cmdresult);
for (String line : result) {
if (line.contains(MODE_FOLLOWER)) {
summary.setQuorumType(AutoKeeperQuorumType.FOLLOWER);
} else if (line.contains(MODE_LEADERER)) {
summary.setQuorumType(AutoKeeperQuorumType.LEADER);
} else if (line.contains(MODE_STANDALONE)) {
summary.setQuorumType(AutoKeeperQuorumType.STANDALONE);
} else if (line.contains(MODE_OBSERVER)) {
summary.setQuorumType(AutoKeeperQuorumType.OBSERVER);
} else if (line.contains(STRING_LATENCY)) {
List latency = Arrays.asList(StringUtils.trimToEmpty(line.replace(STRING_LATENCY,
StringUtils.EMPTY)).split("/"));
summary.setMinLatency(Long.parseLong(latency.get(0)));
summary.setAvgLatency(Long.parseLong(latency.get(1)));
summary.setMaxLatency(Long.parseLong(latency.get(2)));
} else if (line.contains(STRING_OUTSTANDING)) {
summary.setQueued(Long.parseLong(StringUtils.trimToEmpty(line.replace(STRING_OUTSTANDING,
StringUtils.EMPTY))));
} else if (line.contains(NODE_COUNT)) {
summary.setNodeCount(Long.parseLong(StringUtils.trimToEmpty(line.replace(NODE_COUNT, StringUtils.EMPTY))));
} else if (line.contains(STRING_SENT)) {
summary.setSent(Long.parseLong(StringUtils.trimToEmpty(line.replace(STRING_SENT, StringUtils.EMPTY))));
} else if (line.contains(STRING_RECEIVED)) {
summary.setRecved(Long.parseLong(StringUtils.trimToEmpty(line.replace(STRING_RECEIVED,
StringUtils.EMPTY))));
}
}
autoKeeperData.joinServer(address, summary);
}
public void collectorEphemeralStat(String address) {
List netAddress = splitAddress(address);
if (netAddress.isEmpty()) {
return;
}
String ip = netAddress.get(0);
String port = netAddress.get(1);
String[] cmd = { "/bin/bash", "-c", String.format(CMD_DUMP, ip, port) };
String cmdresult = collector(cmd);
Map> pathMap = groupSessionPath(cmdresult);
List autoKeeperEphemeralStats = new ArrayList();
for (Map.Entry> entry : pathMap.entrySet()) {
AutoKeeperEphemeralStat autoKeeperEphemeralStat = new AutoKeeperEphemeralStat();
autoKeeperEphemeralStat.setSessionId(entry.getKey());
autoKeeperEphemeralStat.setPaths(entry.getValue());
autoKeeperEphemeralStats.add(autoKeeperEphemeralStat);
}
autoKeeperData.joinEphemeral(address, autoKeeperEphemeralStats);
}
public void collectorWatchStat(String address) {
List netAddress = splitAddress(address);
if (netAddress.isEmpty()) {
return;
}
String ip = netAddress.get(0);
String port = netAddress.get(1);
String[] cmd = { "/bin/bash", "-c", String.format(CMD_WCHC, ip, port) };
String cmdresult = collector(cmd);
Map> pathMap = groupSessionPath(cmdresult);
List autoKeeperWatchStats = new ArrayList();
for (Map.Entry> entry : pathMap.entrySet()) {
AutoKeeperWatchStat autoKeeperWatchStat = new AutoKeeperWatchStat();
autoKeeperWatchStat.setSessionId(entry.getKey());
autoKeeperWatchStat.setPaths(entry.getValue());
autoKeeperWatchStats.add(autoKeeperWatchStat);
}
autoKeeperData.joinWatch(address, autoKeeperWatchStats);
}
public static String collector(String[] command) {
Result result = null;
try {
result = Exec.execute(command);
if (result.getExitCode() == 0) {
return result.getStdout();
} else {
return result.getStderr();
}
} catch (Exception e) {
throw new ManagerException(e);
}
}
private List splitAddress(String address) {
List ipPort = Arrays.asList(address.split(":"));
if (ipPort.size() != 2) {
return new ArrayList();
}
return ipPort;
}
/**
*
* key=sessionId
* value=pathList
*
*/
private Map> groupSessionPath(String cmdresult) {
String[] result = cmdresult.split(WRAP);
Map> pathMap = new HashMap>();
String sessionId = StringUtils.EMPTY;
for (String line : result) {
line = StringUtils.trimToEmpty(line);
if (StringUtils.isBlank(line)) {
continue;
}
if (line.startsWith("0x")) {
sessionId = line.replace(COLON, StringUtils.EMPTY);
pathMap.put(sessionId, new ArrayList());
} else if (line.startsWith("/")) {
List paths = pathMap.get(sessionId);
paths.add(line);
}
}
return pathMap;
}
@Override
public void afterPropertiesSet() throws Exception {
collectorExecutor = Executors.newScheduledThreadPool(singleSize, new NamedThreadFactory("collector-thread",
true));
startCollect();
}
private void startCollect() {
// 启动定时工作任务
collectorExecutor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
List autoKeeperClusters = autoKeeperClusterService.listAutoKeeperClusters();
if (!autoKeeperClusters.isEmpty()) {
autoKeeperData.persist();
for (AutoKeeperCluster autoKeeperCluster : autoKeeperClusters) {
List servers = autoKeeperCluster.getServerList();
for (String address : servers) {
collectorServerStat(address);
collectorConnectionStat(address);
collectorWatchStat(address);
collectorEphemeralStat(address);
}
}
}
}
}, delay, collectInterval, TimeUnit.SECONDS);
}
public void setAutoKeeperClusterService(AutoKeeperClusterService autoKeeperClusterService) {
this.autoKeeperClusterService = autoKeeperClusterService;
}
public void setAutoKeeperData(AutoKeeperData autoKeeperData) {
this.autoKeeperData = autoKeeperData;
}
public void setCollectInterval(long collectInterval) {
this.collectInterval = collectInterval;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/autokeeper/impl/AutoKeeperData.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.autokeeper.impl;
import java.util.List;
import java.util.Map;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperConnectionStat;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperEphemeralStat;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperWatchStat;
import com.google.common.collect.MapMaker;
/**
* join server之间的统计数据,提供当前最新和完整的数据结构方便数据查询
*
*
*
* @author jianghang 2012-9-21 下午03:02:00
* @version 4.1.0
*/
public class AutoKeeperData implements AutoKeeperPersist {
private Map serverStats = new MapMaker().makeMap(); // serverIp和server的对应关系
private Map connectionStats = new MapMaker().makeMap(); // sessionId和connection的对应关系
public void joinServer(String address, AutoKeeperServerStat summary) {
serverStats.put(address, summary);
}
public void joinConnection(String address, List connections) {
// 记录connection引用
for (AutoKeeperConnectionStat connection : connections) {
connectionStats.put(connection.getSessionId(), connection);
}
// 添加引用到server中
if (serverStats.containsKey(address)) {
serverStats.get(address).getConnectionStats().addAll(connections);
}
}
public void joinEphemeral(String address, List ephemerals) {
for (AutoKeeperEphemeralStat ephemeral : ephemerals) {
if (connectionStats.containsKey(ephemeral.getSessionId())) {
// 找到对应的connection进行关联,填充数据
connectionStats.get(ephemeral.getSessionId()).getEphemeralStats().add(ephemeral);
}
}
}
public void joinWatch(String address, List watches) {
for (AutoKeeperWatchStat watch : watches) {
if (connectionStats.containsKey(watch.getSessionId())) {
// 找到对应的connection进行关联,填充数据
connectionStats.get(watch.getSessionId()).getWatchStats().add(watch);
}
}
}
public void persist() {
serverStats.clear();
connectionStats.clear();
}
public Map getServerStats() {
return serverStats;
}
public Map getConnectionStats() {
return connectionStats;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/autokeeper/impl/AutoKeeperPersist.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.autokeeper.impl;
/**
* 数据持久化接口,会有持久化调度器定时触发
*
* @author jianghang 2012-9-21 下午03:04:37
* @version 4.1.0
*/
public interface AutoKeeperPersist {
/**
* 会有
*/
public void persist();
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/autokeeper/impl/AutoKeeperStatServiceImpl.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.autokeeper.impl;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.otter.manager.biz.autokeeper.AutoKeeperStatService;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperConnectionStat;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperEphemeralStat;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperWatchStat;
/**
* 提供autokeeper相关的数据查询接口
*
* @author simon 2012-9-28 上午11:00:07
* @version 4.1.0
*/
public class AutoKeeperStatServiceImpl implements AutoKeeperStatService {
private AutoKeeperData autoKeeperData;
public AutoKeeperServerStat findServerStat(String serverAddress) {
return autoKeeperData.getServerStats().get(serverAddress);
}
public AutoKeeperServerStat findServerStatBySessionId(String sessionId) {
String serverAddress = autoKeeperData.getConnectionStats().get(sessionId).getServerAddress();
return findServerStat(serverAddress);
}
public AutoKeeperConnectionStat findConnectionBySessionId(String sessionId) {
return autoKeeperData.getConnectionStats().get(sessionId);
}
public AutoKeeperConnectionStat findConnectionByEphemeralPath(String path) {
for (AutoKeeperConnectionStat connection : autoKeeperData.getConnectionStats().values()) {
for (AutoKeeperEphemeralStat ephemeral : connection.getEphemeralStats()) {
if (ephemeral.getPaths().contains(path)) {
return connection;
}
}
}
return null;
}
public List findConnectionByWatcherPath(String path) {
List connections = new ArrayList();
for (AutoKeeperConnectionStat connection : autoKeeperData.getConnectionStats().values()) {
for (AutoKeeperWatchStat watch : connection.getWatchStats()) {
if (watch.getPaths().contains(path)) {
connections.add(connection);
}
}
}
return connections;
}
public void setAutoKeeperData(AutoKeeperData autoKeeperData) {
this.autoKeeperData = autoKeeperData;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/DataSourceCreator.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.common;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import com.alibaba.otter.common.push.datasource.DataSourceHanlder;
import com.alibaba.otter.shared.common.model.config.data.DataMediaSource;
import com.alibaba.otter.shared.common.model.config.data.DataMediaType;
import com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource;
public class DataSourceCreator implements DisposableBean {
private static final Logger logger = LoggerFactory.getLogger(DataSourceCreator.class);
private int maxWait = 60 * 1000;
private int minIdle = 0;
private int initialSize = 1;
private int maxActive = 5;
private int maxIdle = 1;
private int numTestsPerEvictionRun = -1;
private int timeBetweenEvictionRunsMillis = 60 * 1000;
private int removeAbandonedTimeout = 10 * 60;
private int minEvictableIdleTimeMillis = 30 * 60 * 1000;
private List dataSourceHandlers;
/**
* 直接创建数据源,不做cache
*/
public DataSource createDataSource(DataMediaSource dataMediaSource) {
Assert.notNull(dataMediaSource);
DbMediaSource dbMediaSource = (DbMediaSource) dataMediaSource;
// 扩展功能,可以自定义一些自己实现的 dataSource
DataSource customDataSource = preCreate(0L, dbMediaSource);
if (customDataSource != null) {
return customDataSource;
}
return createDataSource(dbMediaSource.getUrl(),
dbMediaSource.getUsername(),
dbMediaSource.getPassword(),
dbMediaSource.getDriver(),
dbMediaSource.getType(),
dbMediaSource.getEncode());
}
public void destroyDataSource(DataSource dataSource) {
try {
// for filter to destroy custom datasource
if (letHandlerDestroyIfSupport(0L, dataSource)) {
return;
}
if (dataSource == null) {
return;
}
BasicDataSource basicDataSource = (BasicDataSource) dataSource;
basicDataSource.close();
} catch (SQLException e) {
logger.error("ERROR ## close the datasource has an error", e);
}
}
public void destroy() throws Exception {
}
/**
* 扩展功能,可以自定义一些自己实现的 dataSource
*/
private DataSource preCreate(Long pipelineId, DbMediaSource dbMediaSource) {
if (CollectionUtils.isEmpty(dataSourceHandlers)) {
return null;
}
DataSource dataSource = null;
for (DataSourceHanlder handler : dataSourceHandlers) {
if (handler.support(dbMediaSource)) {
dataSource = handler.create(pipelineId, dbMediaSource);
if (dataSource != null) {
return dataSource;
}
}
}
return null;
}
public boolean letHandlerDestroyIfSupport(Long pipelineId, DataSource source) {
boolean destroied = false;
if (CollectionUtils.isEmpty(this.dataSourceHandlers)) {
return destroied;
}
for (DataSourceHanlder handler : this.dataSourceHandlers) {
if (handler.support(source)) {
handler.destory(pipelineId);
destroied = true;
return destroied;
}
}
return destroied;
}
private DataSource createDataSource(String url, String userName, String password, String driverClassName,
DataMediaType dataMediaType, String encoding) {
BasicDataSource dbcpDs = new BasicDataSource();
dbcpDs.setInitialSize(initialSize);// 初始化连接池时创建的连接数
dbcpDs.setMaxActive(maxActive);// 连接池允许的最大并发连接数,值为非正数时表示不限制
dbcpDs.setMaxIdle(maxIdle);// 连接池中的最大空闲连接数,超过时,多余的空闲连接将会被释放,值为负数时表示不限制
dbcpDs.setMinIdle(minIdle);// 连接池中的最小空闲连接数,低于此数值时将会创建所欠缺的连接,值为0时表示不创建
dbcpDs.setMaxWait(maxWait);// 以毫秒表示的当连接池中没有可用连接时等待可用连接返回的时间,超时则抛出异常,值为-1时表示无限等待
dbcpDs.setRemoveAbandoned(true);// 是否清除已经超过removeAbandonedTimeout设置的无效连接
dbcpDs.setLogAbandoned(true);// 当清除无效链接时是否在日志中记录清除信息的标志
dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // 以秒表示清除无效链接的时限
dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// 确保连接池中没有已破损的连接
dbcpDs.setTestOnBorrow(false);// 指定连接被调用时是否经过校验
dbcpDs.setTestOnReturn(false);// 指定连接返回到池中时是否经过校验
dbcpDs.setTestWhileIdle(true);// 指定连接进入空闲状态时是否经过空闲对象驱逐进程的校验
dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // 以毫秒表示空闲对象驱逐进程由运行状态进入休眠状态的时长,值为非正数时表示不运行任何空闲对象驱逐进程
dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // 以毫秒表示连接被空闲对象驱逐进程驱逐前在池中保持空闲状态的最小时间
// 动态的参数
dbcpDs.setDriverClassName(driverClassName);
dbcpDs.setUrl(url);
dbcpDs.setUsername(userName);
dbcpDs.setPassword(password);
if (dataMediaType.isOracle()) {
dbcpDs.addConnectionProperty("restrictGetTables", "true");
// dbcpDs.setValidationQuery("select 1 from dual");
} else if (dataMediaType.isMysql()) {
// open the batch mode for mysql since 5.1.8
dbcpDs.addConnectionProperty("useServerPrepStmts", "false");
dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true");
dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 将0000-00-00的时间类型返回null
dbcpDs.addConnectionProperty("yearIsDateType", "false");// 直接返回字符串,不做year转换date处理
dbcpDs.addConnectionProperty("noDatetimeStringSync", "true");// 返回时间类型的字符串,不做时区处理
if (StringUtils.isNotEmpty(encoding)) {
if (StringUtils.equalsIgnoreCase(encoding, "utf8mb4")) {
dbcpDs.addConnectionProperty("characterEncoding", "utf8");
dbcpDs.setConnectionInitSqls(Arrays.asList("set names utf8mb4"));
} else {
dbcpDs.addConnectionProperty("characterEncoding", encoding);
}
}
// dbcpDs.setValidationQuery("select 1");
} else {
logger.error("ERROR ## Unknow database type");
}
return dbcpDs;
}
public void setMaxWait(int maxWait) {
this.maxWait = maxWait;
}
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
public void setInitialSize(int initialSize) {
this.initialSize = initialSize;
}
public void setMaxActive(int maxActive) {
this.maxActive = maxActive;
}
public void setMaxIdle(int maxIdle) {
this.maxIdle = maxIdle;
}
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
this.numTestsPerEvictionRun = numTestsPerEvictionRun;
}
public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
}
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
this.removeAbandonedTimeout = removeAbandonedTimeout;
}
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
public void setDataSourceHandlers(List dataSourceHandlers) {
this.dataSourceHandlers = dataSourceHandlers;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/alarm/AbstractAlarmService.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.common.alarm;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
/**
* 报警服务实现
*
* @author jianghang 2011-11-3 上午11:12:16
* @version 4.0.0
*/
public abstract class AbstractAlarmService implements AlarmService, InitializingBean, DisposableBean {
private static final Logger logger = LoggerFactory.getLogger(AbstractAlarmService.class);
private BlockingQueue queue = new LinkedBlockingQueue(3 * 3 * 3600);
private ExecutorService executor;
private int period = 150; // milliseconds
public void sendAlarm(AlarmMessage data) {
try {
if (!queue.offer(data, 2, TimeUnit.SECONDS)) {
logger.error(String.format("alarm sent to queue error : [%s]", data.toString()));
}
} catch (Exception e) {
logger.error(String.format("send alarm [%s] to drgoon agent error!", data.toString()), e);
}
}
private void sendAlarmInternal() {
AlarmMessage data = null;
try {
data = queue.take();
doSend(data);
logger.info(String.format("has sent alarm [%s] to drgoon agent.", data.toString()));
} catch (InterruptedException e) {
logger.warn("otter-sendAlarm-worker was interrupted", e);
} catch (Exception e) {
logger.error(String.format("send alarm [%s] to drgoon agent error!", data.toString()), e);
}
}
protected abstract void doSend(AlarmMessage data) throws Exception;
public void afterPropertiesSet() throws Exception {
executor = Executors.newFixedThreadPool(1);
executor.submit(new Runnable() {
public void run() {
while (!Thread.currentThread().isInterrupted()) {
sendAlarmInternal();
LockSupport.parkNanos(period * 1000L * 1000L);
}
}
});
}
@Override
public void destroy() throws Exception {
if (executor != null && !executor.isShutdown()) {
executor.shutdown();
executor.awaitTermination(2, TimeUnit.SECONDS);
}
if (!queue.isEmpty()) {
int size = queue.size();
logger.warn(String.format("there are %d alarms wait to be sent \n %s", size, dumpQueue()));
}
}
protected String dumpQueue() {
if (queue.isEmpty()) {
return StringUtils.EMPTY;
}
StringBuilder sb = new StringBuilder();
for (AlarmMessage data : queue) {
sb.append(data.toString()).append("\n");
}
return sb.toString();
}
// ============= setter ===============
public void setPeriod(int period) {
this.period = period;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/alarm/AlarmMessage.java
================================================
package com.alibaba.otter.manager.biz.common.alarm;
import java.io.Serializable;
import org.apache.commons.lang.builder.ToStringBuilder;
import com.alibaba.otter.shared.common.utils.OtterToStringStyle;
public class AlarmMessage implements Serializable {
private static final long serialVersionUID = 6110474591366995515L;
private String message;
private String receiveKey;
public AlarmMessage(){
}
public AlarmMessage(String message, String receiveKey){
this.message = message;
this.receiveKey = receiveKey;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getReceiveKey() {
return receiveKey;
}
public void setReceiveKey(String receiveKey) {
this.receiveKey = receiveKey;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, OtterToStringStyle.DEFAULT_STYLE);
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/alarm/AlarmService.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.common.alarm;
/**
* 报警服务service定义,暂时先简单实现:利用dragoon的报警推送机制进行短信,邮件,旺旺信息等报警
*
* @author jianghang 2011-9-26 下午10:27:44
* @version 4.0.0
*/
public interface AlarmService {
/**
* 发送基于kv的报警信息
*
*
*
* @param data
*/
public void sendAlarm(AlarmMessage data);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/alarm/DefaultAlarmService.java
================================================
package com.alibaba.otter.manager.biz.common.alarm;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import com.alibaba.otter.manager.biz.config.parameter.SystemParameterService;
import com.alibaba.otter.shared.common.model.config.parameter.SystemParameter;
/**
* 发送邮件进行报警
*
* @author jianghang 2013-9-6 上午11:42:04
* @since 4.2.2
*/
public class DefaultAlarmService extends AbstractAlarmService {
private static final String TITLE = "alarm_from_otter";
private String username;
private JavaMailSender mailSender;
private SystemParameterService systemParameterService;
public void doSend(AlarmMessage data) throws Exception {
SimpleMailMessage mail = new SimpleMailMessage(); // 只发送纯文本
mail.setFrom(username);
mail.setSubject(TITLE);// 主题
mail.setText(data.getMessage());// 邮件内容
String receiveKeys[] = StringUtils.split(StringUtils.replace(data.getReceiveKey(), ";", ","), ",");
SystemParameter systemParameter = systemParameterService.find();
List mailAddress = new ArrayList();
for (String receiveKey : receiveKeys) {
String receiver = convertToReceiver(systemParameter, receiveKey);
String strs[] = StringUtils.split(StringUtils.replace(receiver, ";", ","), ",");
for (String str : strs) {
if (isMail(str)) {
if (str != null) {
mailAddress.add(str);
}
} else if (isSms(str)) {
// do nothing
}
}
}
if (!mailAddress.isEmpty()) {
mail.setTo(mailAddress.toArray(new String[mailAddress.size()]));
doSendMail(mail);
}
}
private void doSendMail(SimpleMailMessage mail) {
if (mailSender instanceof JavaMailSenderImpl) {
JavaMailSenderImpl mailSenderImpl = (JavaMailSenderImpl) mailSender;
if (StringUtils.isNotEmpty(mailSenderImpl.getUsername())
&& StringUtils.isNotEmpty(mailSenderImpl.getPassword())) {
// 正确设置了账户/密码,才尝试发送邮件
mailSender.send(mail);
}
}
}
private boolean isMail(String receiveKey) {
return StringUtils.contains(receiveKey, '@');
}
private boolean isSms(String receiveKey) {
return false;
}
private String convertToReceiver(SystemParameter systemParameter, String receiveKey) {
if (StringUtils.equalsIgnoreCase(systemParameter.getDefaultAlarmReceiveKey(), receiveKey)) {
return systemParameter.getDefaultAlarmReceiver();
} else {
return systemParameter.getAlarmReceiver().get(receiveKey);
}
}
public void setMailSender(JavaMailSender mailSender) {
this.mailSender = mailSender;
}
public void setUsername(String username) {
this.username = username;
}
public void setSystemParameterService(SystemParameterService systemParameterService) {
this.systemParameterService = systemParameterService;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/arbitrate/ArbitrateConfigImpl.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.common.arbitrate;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.InitializingBean;
import com.alibaba.otter.manager.biz.config.channel.ChannelService;
import com.alibaba.otter.manager.biz.config.node.NodeService;
import com.alibaba.otter.shared.arbitrate.impl.config.ArbitrateConfig;
import com.alibaba.otter.shared.arbitrate.impl.config.ArbitrateConfigRegistry;
import com.alibaba.otter.shared.common.model.config.ConfigException;
import com.alibaba.otter.shared.common.model.config.channel.Channel;
import com.alibaba.otter.shared.common.model.config.node.Node;
import com.alibaba.otter.shared.common.model.config.pipeline.Pipeline;
import com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror;
import com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction;
import com.google.common.base.Function;
import com.google.common.collect.OtterMigrateMap;
/**
* manager下的基于db查询的{@linkplain ArbitrateConfig}实现
*
* @author jianghang 2011-11-3 上午11:09:24
* @version 4.0.0
*/
public class ArbitrateConfigImpl implements ArbitrateConfig, InitializingBean {
private static final Long DEFAULT_PERIOD = 60 * 1000L;
private Long timeout = DEFAULT_PERIOD;
private RefreshMemoryMirror channelCache;
private Map channelMapping;
private ChannelService channelService;
private NodeService nodeService;
private RefreshMemoryMirror nodeCache;
public ArbitrateConfigImpl(){
// 注册自己到arbitrate模块
ArbitrateConfigRegistry.regist(this);
}
public Node currentNode() {
return null;
}
public Node findNode(Long nid) {
return nodeCache.get(nid);
}
public Channel findChannel(Long channelId) {
return channelCache.get(channelId);
}
public Channel findChannelByPipelineId(Long pipelineId) {
Long channelId = channelMapping.get(pipelineId);
return channelCache.get(channelId);
}
public Pipeline findOppositePipeline(Long pipelineId) {
Long channelId = channelMapping.get(pipelineId);
Channel channel = channelCache.get(channelId);
List pipelines = channel.getPipelines();
for (Pipeline pipeline : pipelines) {
if (pipeline.getId().equals(pipelineId) == false) {// 这里假定pipeline只有两个
return pipeline;
}
}
return null;
}
public Pipeline findPipeline(Long pipelineId) {
Long channelId = channelMapping.get(pipelineId);
Channel channel = channelCache.get(channelId);
List pipelines = channel.getPipelines();
for (Pipeline pipeline : pipelines) {
if (pipeline.getId().equals(pipelineId)) {
return pipeline;
}
}
throw new ConfigException("no pipeline for pipelineId[" + pipelineId + "]");
}
public void afterPropertiesSet() throws Exception {
// 获取一下nid变量
channelMapping = OtterMigrateMap.makeComputingMap(new Function() {
public Long apply(Long pipelineId) {
// 处理下pipline -> channel映射关系不存在的情况
Channel channel = channelService.findByPipelineId(pipelineId);
if (channel == null) {
throw new ConfigException("No Such Channel by pipelineId[" + pipelineId + "]");
}
updateMapping(channel, pipelineId);// 排除下自己
channelCache.put(channel.getId(), channel);// 更新下channelCache
return channel.getId();
}
});
channelCache = new RefreshMemoryMirror(timeout, new ComputeFunction() {
public Channel apply(Long key, Channel oldValue) {
Channel channel = channelService.findById(key);
if (channel == null) {
// 其他情况直接返回内存中的旧值
return oldValue;
} else {
updateMapping(channel, null);// 排除下自己
return channel;
}
}
});
nodeCache = new RefreshMemoryMirror(timeout, new ComputeFunction() {
public Node apply(Long key, Node oldValue) {
Node node = nodeService.findById(key);
if (node == null) {
return oldValue;
} else {
return node;
}
}
});
}
private void updateMapping(Channel channel, Long excludeId) {
Long channelId = channel.getId();
List pipelines = channel.getPipelines();
for (Pipeline pipeline : pipelines) {
if (excludeId == null || !pipeline.getId().equals(excludeId)) {
channelMapping.put(pipeline.getId(), channelId);
}
}
}
public void setChannelService(ChannelService channelService) {
this.channelService = channelService;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/arbitrate/DeadNodeListener.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.common.arbitrate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import com.alibaba.otter.manager.biz.config.channel.ChannelService;
import com.alibaba.otter.manager.biz.monitor.PassiveMonitor;
import com.alibaba.otter.shared.arbitrate.ArbitrateManageService;
import com.alibaba.otter.shared.arbitrate.impl.setl.monitor.NodeMonitor;
import com.alibaba.otter.shared.arbitrate.impl.setl.monitor.listener.NodeListener;
import com.alibaba.otter.shared.common.model.config.alarm.MonitorName;
import com.alibaba.otter.shared.common.model.config.channel.Channel;
import com.alibaba.otter.shared.common.model.config.channel.ChannelStatus;
import com.alibaba.otter.shared.communication.model.arbitrate.NodeAlarmEvent;
import com.google.common.collect.Lists;
/**
* 默认的死亡节点处理
*
* @author jianghang 2011-9-26 下午10:37:40
* @version 4.0.0
*/
public class DeadNodeListener implements NodeListener, InitializingBean, DisposableBean {
private static final Logger logger = LoggerFactory.getLogger(DeadNodeListener.class);
private volatile DelayQueue queue = new DelayQueue();
private NodeMonitor nodeMonitor;
private ArbitrateManageService arbitrateManageService;
private PassiveMonitor exceptionRuleMonitor;
private ChannelService channelService;
private ExecutorService executor;
private long checkTime = 60 * 1000L; // 30秒
private volatile List currentNodes = new ArrayList(); // 当前存活节点
public DeadNodeListener(){
}
public void afterPropertiesSet() throws Exception {
nodeMonitor.addListener(this);
executor = Executors.newFixedThreadPool(1);
executor.submit(new Runnable() {
public void run() {
while (true) {
DeadNodeDelayed delay = null;
try {
delay = queue.take();
processDead(delay.getNid());
} catch (Throwable e) {
logger.error(String.format("error happened with [%s]", delay.toString()), e);
}
}
}
});
}
public synchronized void processChanged(List nodes) {
Set deadNodes = new HashSet();
for (Long node : currentNodes) {
if (!nodes.contains(node)) {
deadNodes.add(node);
}
}
currentNodes = nodes;// 切换引用,需设置为volatile保证线程安全&可见性
// 处理下dead node
if (deadNodes.size() > 0) {
for (Long nid : deadNodes) {
Delayed delayed = new DeadNodeDelayed(nid, checkTime);
if (!queue.contains(delayed)) {// 不重复添加
queue.add(new DeadNodeDelayed(nid, checkTime));
}
}
}
}
private void processDead(Long deadNode) {
List aliveNodes = nodeMonitor.getAliveNodes(true);
// 需要考虑一种网络瞬断的情况,会导致node所有出现重连,导致出现restart风暴,执行restart时需要重新check下是否存活
if (aliveNodes.contains(deadNode)) {
logger.warn("dead node[{}] happend just one moment , check it's alived", deadNode);
return;
}
// 发送一条报警信息
List channelIds = Lists.newArrayList();
List channels = channelService.listByNodeId(deadNode, ChannelStatus.START);
for (Channel channel : channels) {
channelIds.add(channel.getId());
}
Collections.sort(channelIds);
NodeAlarmEvent alarm = new NodeAlarmEvent();
alarm.setPipelineId(-1L);
alarm.setTitle(MonitorName.EXCEPTION.name());
alarm.setMessage(String.format("nid:%s is dead and restart cids:%s", String.valueOf(deadNode),
channelIds.toString()));
try {
exceptionRuleMonitor.feed(alarm, alarm.getPipelineId());
} catch (Exception e) {
logger.error(String.format("ERROR # exceptionRuleMonitor error for %s", alarm.toString()), e);
}
for (Long channelId : channelIds) {// 重启一下对应的channel
boolean result = arbitrateManageService.channelEvent().restart(channelId);
if (result) {
channelService.notifyChannel(channelId);// 推送一下配置
}
}
}
public void destroy() throws Exception {
nodeMonitor.removeListener(this);
executor.shutdownNow();
}
/**
* 构建一个基于时间的delay queue,解决一个问题:node出现网络闪段,其jvm并不是真实关闭,可以间隔几秒后check一下是否存活再判断是否进行RESTART操作
*
* @author jianghang 2012-8-29 下午01:42:47
* @version 4.1.0
*/
public static class DeadNodeDelayed implements Delayed {
// init time for nano
private static final long MILL_ORIGIN = System.currentTimeMillis();
private long nid;
private long now; // 记录具体的now的偏移时间点,单位ms
private long timeout; // 记录具体需要被delayed处理的偏移时间点,单位ms
public DeadNodeDelayed(long nid, long timeout){
this.nid = nid;
this.timeout = timeout;
this.now = System.currentTimeMillis() - MILL_ORIGIN;
}
public long getNid() {
return nid;
}
public long getNow() {
return now;
}
public long getDelay(TimeUnit unit) {
long currNow = System.currentTimeMillis() - MILL_ORIGIN;
long d = unit.convert(now + timeout - currNow, TimeUnit.MILLISECONDS);
return d;
}
public int compareTo(Delayed other) {
if (other == this) { // compare zero ONLY if same object
return 0;
} else if (other instanceof DeadNodeDelayed) {
DeadNodeDelayed x = (DeadNodeDelayed) other;
long diff = now + timeout - (x.now + x.timeout);
return (diff == 0) ? 0 : ((diff < 0) ? 1 : -1); // 时间越小的,越应该排在前面
} else {
long d = (getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS));
return (d == 0) ? 0 : ((d < 0) ? 1 : -1);
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (nid ^ (nid >>> 32));
return result;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof DeadNodeDelayed)) {
return false;
}
DeadNodeDelayed other = (DeadNodeDelayed) obj;
if (nid != other.nid) {
return false;
}
return true;
}
}
public void setNodeMonitor(NodeMonitor nodeMonitor) {
this.nodeMonitor = nodeMonitor;
}
public void setArbitrateManageService(ArbitrateManageService arbitrateManageService) {
this.arbitrateManageService = arbitrateManageService;
}
public void setChannelService(ChannelService channelService) {
this.channelService = channelService;
}
public void setExceptionRuleMonitor(PassiveMonitor exceptionRuleMonitor) {
this.exceptionRuleMonitor = exceptionRuleMonitor;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/basedao/GenericDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.common.basedao;
import java.util.List;
import java.util.Map;
/**
* @author simon 2011-10-31 上午09:40:47
*/
public interface GenericDAO {
public T insert(T entityObj);
public void delete(Long identity);
public void update(T entityObj);
public List listAll();
public List listByCondition(Map condition);
public List listByMultiId(Long... identities);
public T findById(Long identity);
public int getCount();
public int getCount(Map condition);
public boolean checkUnique(T entityObj);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/baseservice/GenericService.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.common.baseservice;
import java.util.List;
import java.util.Map;
/**
* @author simon 2011-10-31 上午10:34:17
*/
public interface GenericService {
public void create(T entityObj);
public void remove(Long identity);
public void modify(T entityObj);
public T findById(Long identity);
public List listByIds(Long... identities);
public List listAll();
public List listByCondition(Map condition);
public int getCount();
public int getCount(Map condition);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/exceptions/InvalidConfigureException.java
================================================
package com.alibaba.otter.manager.biz.common.exceptions;
public class InvalidConfigureException extends RuntimeException {
private static final long serialVersionUID = 1L;
public static enum INVALID_TYPE {
DDL, HOME
}
private INVALID_TYPE type;
public InvalidConfigureException(INVALID_TYPE type){
super(type.name());
this.type = type;
}
public INVALID_TYPE getType() {
return type;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/exceptions/ManagerException.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.common.exceptions;
/**
* ManagerException for Manager Model
*
* @author simon 2011-11-13 下午07:38:47
*/
public class ManagerException extends RuntimeException {
private static final long serialVersionUID = 1L;
public ManagerException(String cause){
super(cause);
}
public ManagerException(Throwable t){
super(t);
}
public ManagerException(String cause, Throwable t){
super(cause, t);
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/common/exceptions/RepeatConfigureException.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.common.exceptions;
/**
* @author simon 2011-11-14 下午11:04:32
*/
public class RepeatConfigureException extends RuntimeException {
private static final long serialVersionUID = 1L;
public RepeatConfigureException(String cause){
super(cause);
}
public RepeatConfigureException(Throwable t){
super(t);
}
public RepeatConfigureException(String cause, Throwable t){
super(cause, t);
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/alarm/AlarmRuleService.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.alarm;
import java.util.List;
import java.util.Map;
import com.alibaba.otter.shared.common.model.config.alarm.AlarmRule;
import com.alibaba.otter.shared.common.model.config.alarm.AlarmRuleStatus;
/**
* @author simon 2012-8-24 上午5:27:35
* @author zebin.xuzb
* @version 4.1.0
*/
public interface AlarmRuleService {
void create(AlarmRule alarmRule);
void modify(AlarmRule alarmRule);
void remove(Long alarmRuleId);
public void enableMonitor(Long alarmRuleId);
public void disableMonitor(Long alarmRuleId);
public void disableMonitor(Long alarmRuleId, String pauseTime);
List getAllAlarmRules(AlarmRuleStatus status);
AlarmRule getAlarmRuleById(Long AlarmRuleId);
/**
* 获取所有状态为 status 的 {@linkplain AlarmRule},并且按照pipelineId分区
*
* @param status
* @return
*/
Map> getAlarmRules(AlarmRuleStatus status);
List getAlarmRules(Long pipelineId);
List getAlarmRules(Long pipelineId, AlarmRuleStatus status);
List listAllAlarmRules(Map condition);
public int getCount();
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/alarm/dal/AlarmRuleDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.alarm.dal;
import java.util.List;
import java.util.Map;
import com.alibaba.otter.manager.biz.config.alarm.dal.dataobject.AlarmRuleDO;
import com.alibaba.otter.shared.common.model.config.alarm.AlarmRuleStatus;
/**
* @author simon 2012-8-24 上午5:17:00
* @version 4.1.0
*/
public interface AlarmRuleDAO {
public AlarmRuleDO insert(AlarmRuleDO entityObj);
public void update(AlarmRuleDO entityObj);
public void delete(Long id);
public AlarmRuleDO findById(Long alarmRuleId);
public List listByPipelineId(Long pipelineId);
public List listByPipelineId(Long pipelineId, AlarmRuleStatus status);
public List listAll();
public List listAllByPipeline(Map condition);
public List listByStatus(AlarmRuleStatus status);
public int getCount();
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/alarm/dal/dataobject/AlarmRuleDO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.alarm.dal.dataobject;
import java.io.Serializable;
import java.util.Date;
import com.alibaba.otter.shared.common.model.config.alarm.AlarmRuleStatus;
import com.alibaba.otter.shared.common.model.config.alarm.MonitorName;
/**
* @author simon 2012-8-22 下午3:42:34
* @version 4.1.0
*/
public class AlarmRuleDO implements Serializable {
private static final long serialVersionUID = -1284784362325347636L;
private Long id;
private Long pipelineId;
private AlarmRuleStatus status;
private MonitorName monitorName;
private String receiverKey;
private String matchValue;
private AlarmRuleParameter alarmRuleParameter = new AlarmRuleParameter();
private String description;
private Date gmtCreate;
private Date gmtModified;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getPipelineId() {
return pipelineId;
}
public void setPipelineId(Long pipelineId) {
this.pipelineId = pipelineId;
}
public AlarmRuleStatus getStatus() {
return status;
}
public void setStatus(AlarmRuleStatus status) {
this.status = status;
}
public MonitorName getMonitorName() {
return monitorName;
}
public void setMonitorName(MonitorName monitorName) {
this.monitorName = monitorName;
}
public String getReceiverKey() {
return receiverKey;
}
public void setReceiverKey(String receiverKey) {
this.receiverKey = receiverKey;
}
public String getMatchValue() {
return matchValue;
}
public void setMatchValue(String matchValue) {
this.matchValue = matchValue;
}
public AlarmRuleParameter getAlarmRuleParameter() {
return alarmRuleParameter;
}
public void setAlarmRuleParameter(AlarmRuleParameter alarmRuleParameter) {
this.alarmRuleParameter = alarmRuleParameter;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Date getGmtModified() {
return gmtModified;
}
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/alarm/dal/dataobject/AlarmRuleParameter.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.alarm.dal.dataobject;
import java.io.Serializable;
/**
* @author simon 2012-9-12 上午10:35:13
* @version 4.1.0
*/
public class AlarmRuleParameter implements Serializable {
private static final long serialVersionUID = 1570395344191530689L;
private Long intervalTime = 1800L;
private String pauseTime;
private Integer recoveryThresold = 3;
private Boolean autoRecovery = false;
public Long getIntervalTime() {
return intervalTime;
}
public void setIntervalTime(Long intervalTime) {
this.intervalTime = intervalTime;
}
public String getPauseTime() {
return pauseTime;
}
public void setPauseTime(String pauseTime) {
this.pauseTime = pauseTime;
}
public Boolean getAutoRecovery() {
return autoRecovery;
}
public void setAutoRecovery(Boolean autoRecovery) {
this.autoRecovery = autoRecovery;
}
public Integer getRecoveryThresold() {
return recoveryThresold;
}
public void setRecoveryThresold(Integer recoveryThresold) {
this.recoveryThresold = recoveryThresold;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/alarm/dal/ibatis/AlarmRuleParameterTypeHandler.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.alarm.dal.ibatis;
import java.sql.SQLException;
import com.alibaba.otter.manager.biz.config.alarm.dal.dataobject.AlarmRuleParameter;
import com.alibaba.otter.shared.common.utils.JsonUtils;
import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
/**
* 用于AlarmRuleParameter的解析
*
* @author simon
*/
public class AlarmRuleParameterTypeHandler implements TypeHandlerCallback {
@Override
public void setParameter(ParameterSetter setter, Object parameter) throws SQLException {
setter.setString(JsonUtils.marshalToString(parameter));
}
@Override
public Object getResult(ResultGetter getter) throws SQLException {
return JsonUtils.unmarshalFromString(getter.getString(), AlarmRuleParameter.class);
}
public Object valueOf(String s) {
return JsonUtils.unmarshalFromString(s, AlarmRuleParameter.class);
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/alarm/dal/ibatis/IbatisAlarmRuleDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.alarm.dal.ibatis;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.alibaba.otter.shared.common.utils.Assert;
import com.alibaba.otter.manager.biz.config.alarm.dal.AlarmRuleDAO;
import com.alibaba.otter.manager.biz.config.alarm.dal.dataobject.AlarmRuleDO;
import com.alibaba.otter.shared.common.model.config.alarm.AlarmRuleStatus;
/**
* @author simon
*/
public class IbatisAlarmRuleDAO extends SqlMapClientDaoSupport implements AlarmRuleDAO {
public AlarmRuleDO insert(AlarmRuleDO entityObj) {
Assert.assertNotNull(entityObj);
getSqlMapClientTemplate().insert("insertAlarmRule", entityObj);
return entityObj;
}
public void update(AlarmRuleDO entityObj) {
Assert.assertNotNull(entityObj);
getSqlMapClientTemplate().update("updateAlarmRule", entityObj);
}
public void delete(Long id) {
Assert.assertNotNull(id);
getSqlMapClientTemplate().update("deleteAlarmRuleById", id);
}
public AlarmRuleDO findById(Long alarmRuleId) {
Assert.assertNotNull(alarmRuleId);
AlarmRuleDO alarmRuleDo = (AlarmRuleDO) getSqlMapClientTemplate().queryForObject("findByRuleId", alarmRuleId);
return alarmRuleDo;
}
public List listByPipelineId(Long pipelineId) {
Assert.assertNotNull(pipelineId);
List alarmRuleDos = getSqlMapClientTemplate().queryForList("listAlarmByPipelineId", pipelineId);
return alarmRuleDos;
}
public List listByPipelineId(Long pipelineId, AlarmRuleStatus status) {
List alarmRuleDos = listByPipelineId(pipelineId);
List result = new ArrayList();
for (AlarmRuleDO alarmRuleDo : alarmRuleDos) {
if (alarmRuleDo.getStatus().equals(status)) {
result.add(alarmRuleDo);
}
}
return result;
}
public List listAll() {
List alarmRuleDos = getSqlMapClientTemplate().queryForList("listAllAlarmRule");
return alarmRuleDos;
}
public List listAllByPipeline(Map condition) {
List alarmRuleDos = getSqlMapClientTemplate().queryForList("listAllAlarmOrderByPipeline",
condition);
return alarmRuleDos;
}
public List listByStatus(AlarmRuleStatus status) {
List alarmRuleDos = getSqlMapClientTemplate().queryForList("listAlarmByStatus", status);
return alarmRuleDos;
}
public int getCount() {
Integer count = (Integer) getSqlMapClientTemplate().queryForObject("getAlarmRuleCount");
return count.intValue();
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/alarm/impl/AlarmRuleServiceImpl.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.alarm.impl;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.otter.manager.biz.common.exceptions.ManagerException;
import com.alibaba.otter.manager.biz.config.alarm.AlarmRuleService;
import com.alibaba.otter.manager.biz.config.alarm.dal.AlarmRuleDAO;
import com.alibaba.otter.manager.biz.config.alarm.dal.dataobject.AlarmRuleDO;
import com.alibaba.otter.manager.biz.config.alarm.dal.dataobject.AlarmRuleParameter;
import com.alibaba.otter.shared.common.model.config.alarm.AlarmRule;
import com.alibaba.otter.shared.common.model.config.alarm.AlarmRuleStatus;
import com.alibaba.otter.shared.common.utils.Assert;
/**
* @author simon 2012-8-24 上午5:29:55
* @version 4.1.0
*/
public class AlarmRuleServiceImpl implements AlarmRuleService {
private static final Logger logger = LoggerFactory.getLogger(AlarmRuleServiceImpl.class);
public static final String TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss";
private AlarmRuleDAO alarmRuleDao;
public void create(AlarmRule alarmRule) {
Assert.assertNotNull(alarmRule);
alarmRuleDao.insert(modelToDo(alarmRule));
}
public void modify(AlarmRule alarmRule) {
AlarmRuleDO alarmRuleDo = modelToDo(alarmRule);
alarmRuleDao.update(alarmRuleDo);
}
public void remove(Long alarmRuleId) {
alarmRuleDao.delete(alarmRuleId);
}
private void switchAlarmRuleStatus(Long alarmRuleId, AlarmRuleStatus alarmRuleStatus, String pauseTime) {
AlarmRuleDO alarmRuleDo = alarmRuleDao.findById(alarmRuleId);
if (null == alarmRuleDo) {
String exceptionCause = "query alarmRule:" + alarmRuleId + " return null.";
logger.error("ERROR ## " + exceptionCause);
throw new ManagerException(exceptionCause);
}
alarmRuleDo.setStatus(alarmRuleStatus);
if (alarmRuleDo.getAlarmRuleParameter() != null) {
alarmRuleDo.getAlarmRuleParameter().setPauseTime(pauseTime);
} else if (StringUtils.isNotEmpty(pauseTime)) {
alarmRuleDo.setAlarmRuleParameter(new AlarmRuleParameter());
alarmRuleDo.getAlarmRuleParameter().setPauseTime(pauseTime);
}
alarmRuleDao.update(alarmRuleDo);
}
public void enableMonitor(Long alarmRuleId) {
switchAlarmRuleStatus(alarmRuleId, AlarmRuleStatus.ENABLE, null);
}
public void disableMonitor(Long alarmRuleId) {
switchAlarmRuleStatus(alarmRuleId, AlarmRuleStatus.DISABLE, null);
}
public void disableMonitor(Long alarmRuleId, String pauseTime) {
switchAlarmRuleStatus(alarmRuleId, AlarmRuleStatus.ENABLE, pauseTime);
}
public AlarmRule getAlarmRuleById(Long AlarmRuleId) {
Assert.assertNotNull(AlarmRuleId);
return doToModel(alarmRuleDao.findById(AlarmRuleId));
}
public List getAllAlarmRules(AlarmRuleStatus status) {
Assert.assertNotNull(status);
List alarmRuleDos = alarmRuleDao.listByStatus(status);
return doToModel(alarmRuleDos);
}
public Map> getAlarmRules(AlarmRuleStatus status) {
Assert.assertNotNull(status);
List alarmRules = getAllAlarmRules(status);
Map> result = new HashMap>();
for (AlarmRule alarmRule : alarmRules) {
List rules = result.get(alarmRule.getPipelineId());
if (rules == null) {
rules = new ArrayList();
}
if (!rules.contains(alarmRule)) {
rules.add(alarmRule);
}
result.put(alarmRule.getPipelineId(), rules);
}
return result;
}
public List getAlarmRules(Long pipelineId) {
Assert.assertNotNull(pipelineId);
List alarmRuleDos = alarmRuleDao.listByPipelineId(pipelineId);
return doToModel(alarmRuleDos);
}
public List getAlarmRules(Long pipelineId, AlarmRuleStatus status) {
Assert.assertNotNull(pipelineId);
Assert.assertNotNull(status);
List alarmRuleDos = alarmRuleDao.listByPipelineId(pipelineId, status);
return doToModel(alarmRuleDos);
}
public List listAllAlarmRules(Map condition) {
List alarmRules = doToModel(alarmRuleDao.listAllByPipeline(condition));
return alarmRules;
}
public int getCount() {
return alarmRuleDao.getCount();
}
private AlarmRule doToModel(AlarmRuleDO alarmRuleDo) {
AlarmRule alarmRule = new AlarmRule();
alarmRule.setId(alarmRuleDo.getId());
alarmRule.setMatchValue(alarmRuleDo.getMatchValue());
alarmRule.setMonitorName(alarmRuleDo.getMonitorName());
alarmRule.setReceiverKey(alarmRuleDo.getReceiverKey());
// 如果数据库里面的数据为空,则返回默认值
alarmRule.setIntervalTime(alarmRuleDo.getAlarmRuleParameter() == null ? 1800L : alarmRuleDo.getAlarmRuleParameter().getIntervalTime());
String pauseTime = alarmRuleDo.getAlarmRuleParameter() == null ? null : alarmRuleDo.getAlarmRuleParameter().getPauseTime();
if (StringUtils.isNotEmpty(pauseTime)) {
SimpleDateFormat format = new SimpleDateFormat(TIMESTAMP_FORMAT);
try {
alarmRule.setPauseTime(format.parse(pauseTime));
} catch (ParseException e) {
throw new ManagerException(e);
}
}
alarmRule.setAutoRecovery(alarmRuleDo.getAlarmRuleParameter() == null ? false : alarmRuleDo.getAlarmRuleParameter().getAutoRecovery());
alarmRule.setRecoveryThresold(alarmRuleDo.getAlarmRuleParameter() == null ? 3 : alarmRuleDo.getAlarmRuleParameter().getRecoveryThresold());
alarmRule.setPipelineId(alarmRuleDo.getPipelineId());
alarmRule.setStatus(alarmRuleDo.getStatus());
alarmRule.setDescription(alarmRuleDo.getDescription());
alarmRule.setGmtCreate(alarmRuleDo.getGmtCreate());
alarmRule.setGmtModified(alarmRuleDo.getGmtModified());
return alarmRule;
}
private List doToModel(List alarmRuleDos) {
List alarmRules = new ArrayList();
for (AlarmRuleDO alarmRuleDo : alarmRuleDos) {
alarmRules.add(doToModel(alarmRuleDo));
}
return alarmRules;
}
private AlarmRuleDO modelToDo(AlarmRule alarmRule) {
AlarmRuleDO alarmRuleDo = new AlarmRuleDO();
alarmRuleDo.setId(alarmRule.getId());
alarmRuleDo.setMatchValue(alarmRule.getMatchValue());
alarmRuleDo.setMonitorName(alarmRule.getMonitorName());
alarmRuleDo.setReceiverKey(alarmRule.getReceiverKey());
alarmRuleDo.setPipelineId(alarmRule.getPipelineId());
alarmRuleDo.setStatus(alarmRule.getStatus());
alarmRuleDo.setDescription(alarmRule.getDescription());
alarmRuleDo.setGmtCreate(alarmRule.getGmtCreate());
alarmRuleDo.setGmtModified(alarmRule.getGmtModified());
AlarmRuleParameter alarmRuleParameter = new AlarmRuleParameter();
alarmRuleParameter.setIntervalTime(alarmRule.getIntervalTime());
if (alarmRule.getPauseTime() != null) {
SimpleDateFormat format = new SimpleDateFormat(TIMESTAMP_FORMAT);
alarmRuleParameter.setPauseTime(format.format(alarmRule.getPauseTime()));
}
alarmRuleParameter.setAutoRecovery(alarmRule.getAutoRecovery());
alarmRuleParameter.setRecoveryThresold(alarmRule.getRecoveryThresold());
alarmRuleDo.setAlarmRuleParameter(alarmRuleParameter);
return alarmRuleDo;
}
public void setAlarmRuleDao(AlarmRuleDAO alarmRuleDao) {
this.alarmRuleDao = alarmRuleDao;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/autokeeper/AutoKeeperClusterService.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.autokeeper;
import java.util.List;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster;
/**
* @author simon 2012-9-24 下午5:35:01
* @version 4.1.0
*/
public interface AutoKeeperClusterService {
public AutoKeeperCluster findAutoKeeperClusterById(Long id);
public List listAutoKeeperClusters();
public void modifyAutoKeeperCluster(AutoKeeperCluster autoKeeperCluster);
public void createAutoKeeperCluster(AutoKeeperCluster autoKeeperCluster);
public void removeAutoKeeperCluster(Long id);
public Integer getCount();
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/autokeeper/dal/AutoKeeperClusterDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.autokeeper.dal;
import java.util.List;
import com.alibaba.otter.manager.biz.config.autokeeper.dal.dataobject.AutoKeeperClusterDO;
public interface AutoKeeperClusterDAO {
public AutoKeeperClusterDO findAutoKeeperClusterById(Long id);
public List listAutoKeeperClusters();
public void updateAutoKeeperCluster(AutoKeeperClusterDO autoKeeperClusterDo);
public void insertAutoKeeperClusterDO(AutoKeeperClusterDO autoKeeperClusterDo);
public void delete(Long clusterId);
public Integer getCount();
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/autokeeper/dal/dataobject/AutoKeeperClusterDO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.autokeeper.dal.dataobject;
import java.util.Date;
import org.apache.commons.lang.builder.ToStringBuilder;
import com.alibaba.otter.shared.common.utils.OtterToStringStyle;
/**
* zk集群监控对象
*
* @author jianghang 2012-9-21 下午01:54:17
* @version 4.1.0
*/
public class AutoKeeperClusterDO {
private Long id;
private String clusterName;
private String serverList; // 机器列表
private String description; // 描述
private Date gmtCreate;
private Date gmtModified;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public String getServerList() {
return serverList;
}
public void setServerList(String serverList) {
this.serverList = serverList;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Date getGmtModified() {
return gmtModified;
}
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
public String toString() {
return ToStringBuilder.reflectionToString(this, OtterToStringStyle.DEFAULT_STYLE);
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/autokeeper/dal/ibatis/IbatisAutoKeeperClusterDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.autokeeper.dal.ibatis;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.alibaba.otter.shared.common.utils.Assert;
import com.alibaba.otter.manager.biz.config.autokeeper.dal.AutoKeeperClusterDAO;
import com.alibaba.otter.manager.biz.config.autokeeper.dal.dataobject.AutoKeeperClusterDO;
/**
* 类IbatisAutoKeeperClusterDAO.java的实现描述:TODO 类实现描述
*
* @author simon 2012-9-24 下午5:17:17
* @version 4.1.0
*/
public class IbatisAutoKeeperClusterDAO extends SqlMapClientDaoSupport implements AutoKeeperClusterDAO {
@Override
public AutoKeeperClusterDO findAutoKeeperClusterById(Long id) {
Assert.assertNotNull(id);
return (AutoKeeperClusterDO) getSqlMapClientTemplate().queryForObject("findAutoKeeperClusterById", id);
}
@Override
public List listAutoKeeperClusters() {
List autoKeeperClusterDOs = getSqlMapClientTemplate().queryForList("listAutoKeeperClusters");
return autoKeeperClusterDOs;
}
@Override
public void updateAutoKeeperCluster(AutoKeeperClusterDO autoKeeperClusterDo) {
Assert.assertNotNull(autoKeeperClusterDo);
getSqlMapClientTemplate().update("updateAutoKeeperCluster", autoKeeperClusterDo);
}
@Override
public void insertAutoKeeperClusterDO(AutoKeeperClusterDO autoKeeperClusterDo) {
Assert.assertNotNull(autoKeeperClusterDo);
getSqlMapClientTemplate().insert("insertAutoKeeperCluster", autoKeeperClusterDo);
}
@Override
public void delete(Long clusterId) {
Assert.assertNotNull(clusterId);
getSqlMapClientTemplate().insert("deleteAutoKeeperClusterById", clusterId);
}
@Override
public Integer getCount() {
Integer count = (Integer) getSqlMapClientTemplate().queryForObject("getAutoKeeperClusterCount");
return count.intValue();
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/autokeeper/impl/AutoKeeperClusterServiceImpl.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.autokeeper.impl;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.otter.manager.biz.config.autokeeper.AutoKeeperClusterService;
import com.alibaba.otter.manager.biz.config.autokeeper.dal.AutoKeeperClusterDAO;
import com.alibaba.otter.manager.biz.config.autokeeper.dal.dataobject.AutoKeeperClusterDO;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster;
import com.alibaba.otter.shared.common.utils.JsonUtils;
/**
* 类AutoKeeperClusterServiceImpl.java的实现描述:TODO 类实现描述
*
* @author simon 2012-9-24 下午5:44:43
* @version 4.1.0
*/
public class AutoKeeperClusterServiceImpl implements AutoKeeperClusterService {
private AutoKeeperClusterDAO autoKeeperClusterDao;
@Override
public AutoKeeperCluster findAutoKeeperClusterById(Long id) {
AutoKeeperClusterDO autoKeeperClusterDO = autoKeeperClusterDao.findAutoKeeperClusterById(id);
return autoKeeperClusterDO == null ? null : doToModel(autoKeeperClusterDO);
}
@Override
public List listAutoKeeperClusters() {
return doToModel(autoKeeperClusterDao.listAutoKeeperClusters());
}
@Override
public void modifyAutoKeeperCluster(AutoKeeperCluster autoKeeperCluster) {
autoKeeperClusterDao.updateAutoKeeperCluster(modelToDo(autoKeeperCluster));
}
@Override
public void createAutoKeeperCluster(AutoKeeperCluster autoKeeperCluster) {
autoKeeperClusterDao.insertAutoKeeperClusterDO(modelToDo(autoKeeperCluster));
}
@Override
public void removeAutoKeeperCluster(Long id) {
autoKeeperClusterDao.delete(id);
}
private AutoKeeperCluster doToModel(AutoKeeperClusterDO autoKeeperClusterDo) {
AutoKeeperCluster autoKeeperCluster = new AutoKeeperCluster();
autoKeeperCluster.setId(autoKeeperClusterDo.getId());
autoKeeperCluster.setClusterName(autoKeeperClusterDo.getClusterName());
autoKeeperCluster.setDescription(autoKeeperClusterDo.getDescription());
autoKeeperCluster.setServerList(JsonUtils.unmarshalFromString(autoKeeperClusterDo.getServerList(),
new TypeReference>() {
}));
autoKeeperCluster.setGmtCreate(autoKeeperClusterDo.getGmtCreate());
autoKeeperCluster.setGmtModified(autoKeeperClusterDo.getGmtModified());
return autoKeeperCluster;
}
public Integer getCount() {
return autoKeeperClusterDao.getCount();
}
private List doToModel(List autoKeeperClusterDos) {
List autoKeeperClusters = new ArrayList();
for (AutoKeeperClusterDO autoKeeperClusterDo : autoKeeperClusterDos) {
autoKeeperClusters.add(doToModel(autoKeeperClusterDo));
}
return autoKeeperClusters;
}
private AutoKeeperClusterDO modelToDo(AutoKeeperCluster autoKeeperCluster) {
AutoKeeperClusterDO autokeeperClusterDo = new AutoKeeperClusterDO();
autokeeperClusterDo.setId(autoKeeperCluster.getId());
autokeeperClusterDo.setClusterName(autoKeeperCluster.getClusterName());
autokeeperClusterDo.setDescription(autoKeeperCluster.getDescription());
autokeeperClusterDo.setServerList(JsonUtils.marshalToString(autoKeeperCluster.getServerList()));
autokeeperClusterDo.setGmtCreate(autoKeeperCluster.getGmtCreate());
autokeeperClusterDo.setGmtModified(autoKeeperCluster.getGmtModified());
return autokeeperClusterDo;
}
public void setAutoKeeperClusterDao(AutoKeeperClusterDAO autoKeeperClusterDao) {
this.autoKeeperClusterDao = autoKeeperClusterDao;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/canal/CanalService.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.canal;
import java.util.List;
import java.util.Map;
import com.alibaba.otter.canal.instance.manager.model.Canal;
/**
* @author sarah.lij 2012-7-25 下午04:02:20
*/
public interface CanalService {
public void create(Canal canal);
public void remove(Long canalId);
public void modify(Canal canal);
public List listByIds(Long... identities);
public List listAll();
public Canal findById(Long canalId);
public Canal findByName(String name);
public int getCount(Map condition);
public List listByCondition(Map condition);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/canal/dal/CanalDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.canal.dal;
import com.alibaba.otter.manager.biz.common.basedao.GenericDAO;
import com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO;
/**
* @author sarah.lij 2012-7-25 下午05:05:37
*/
public interface CanalDAO extends GenericDAO {
public CanalDO findByName(String name);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/canal/dal/dataobject/CanalDO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.canal.dal.dataobject;
import java.io.Serializable;
import java.util.Date;
import com.alibaba.otter.canal.instance.manager.model.CanalParameter;
import com.alibaba.otter.canal.instance.manager.model.CanalStatus;
/**
* 类CanalDO.java的实现描述:TODO 类实现描述
*
* @author sarah.lij 2012-7-25 下午05:11:18
*/
public class CanalDO implements Serializable {
private static final long serialVersionUID = 9148286590254926037L;
private Long id; // 唯一标示id
private String name; // canal名字
private String description; // 描述
private CanalStatus status;
private CanalParameter parameters; // 参数定义
private Date gmtCreate; // 创建时间
private Date gmtModified; // 修改时间
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public CanalStatus getStatus() {
return status;
}
public void setStatus(CanalStatus status) {
this.status = status;
}
public CanalParameter getParameters() {
return parameters;
}
public void setParameters(CanalParameter parameters) {
this.parameters = parameters;
}
public Date getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Date getGmtModified() {
return gmtModified;
}
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/canal/dal/ibatis/CanalParameterTypeHandler.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.canal.dal.ibatis;
import java.sql.SQLException;
import com.alibaba.otter.canal.instance.manager.model.CanalParameter;
import com.alibaba.otter.shared.common.utils.JsonUtils;
import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
/**
* @author sarah.lij 2012-7-25 下午05:12:52
*/
public class CanalParameterTypeHandler implements TypeHandlerCallback {
@Override
public void setParameter(ParameterSetter setter, Object parameter) throws SQLException {
setter.setString(JsonUtils.marshalToString(parameter));
}
@Override
public Object getResult(ResultGetter getter) throws SQLException {
return JsonUtils.unmarshalFromString(getter.getString(), CanalParameter.class);
}
public Object valueOf(String s) {
return JsonUtils.unmarshalFromString(s, CanalParameter.class);
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/canal/dal/ibatis/IbatisCanalDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.canal.dal.ibatis;
import java.util.List;
import java.util.Map;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.alibaba.otter.shared.common.utils.Assert;
import com.alibaba.otter.manager.biz.config.canal.dal.CanalDAO;
import com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO;
/**
* @author sarah.lij 2012-7-25 下午05:12:29
*/
public class IbatisCanalDAO extends SqlMapClientDaoSupport implements CanalDAO {
public CanalDO insert(CanalDO canal) {
Assert.assertNotNull(canal);
getSqlMapClientTemplate().insert("insertCanal", canal);
return canal;
}
public void delete(Long canalId) {
Assert.assertNotNull(canalId);
getSqlMapClientTemplate().delete("deleteCanalById", canalId);
}
public void update(CanalDO canal) {
Assert.assertNotNull(canal);
getSqlMapClientTemplate().update("updateCanal", canal);
}
public List listAll() {
return (List) getSqlMapClientTemplate().queryForList("listCanals");
}
public List listByMultiId(Long... identities) {
List canalDos = getSqlMapClientTemplate().queryForList("listCanalByIds", identities);
return canalDos;
}
public boolean checkUnique(CanalDO canal) {
int count = (Integer) getSqlMapClientTemplate().queryForObject("checkCanalUnique", canal);
return count == 0 ? true : false;
}
public CanalDO findByName(String name) {
Assert.assertNotNull(name);
return (CanalDO) getSqlMapClientTemplate().queryForObject("findCanalByName", name);
}
public CanalDO findById(Long identity) {
throw new UnsupportedOperationException();
}
public int getCount() {
return 0;
}
public int getCount(Map condition) {
Integer count = (Integer) getSqlMapClientTemplate().queryForObject("getCanalCount", condition);
return count.intValue();
}
public List listByCondition(Map condition) {
List canalDos = getSqlMapClientTemplate().queryForList("listCanals", condition);
return canalDos;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/canal/impl/CanalServiceImpl.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.canal.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import com.alibaba.otter.canal.instance.manager.model.Canal;
import com.alibaba.otter.canal.instance.manager.model.CanalParameter;
import com.alibaba.otter.manager.biz.common.exceptions.ManagerException;
import com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException;
import com.alibaba.otter.manager.biz.config.autokeeper.AutoKeeperClusterService;
import com.alibaba.otter.manager.biz.config.canal.CanalService;
import com.alibaba.otter.manager.biz.config.canal.dal.CanalDAO;
import com.alibaba.otter.manager.biz.config.canal.dal.dataobject.CanalDO;
import com.alibaba.otter.manager.biz.config.node.impl.NodeServiceImpl;
import com.alibaba.otter.shared.arbitrate.ArbitrateViewService;
import com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster;
import com.alibaba.otter.shared.common.utils.Assert;
import com.alibaba.otter.shared.common.utils.JsonUtils;
/**
* @author sarah.lij 2012-7-25 下午04:04:43
*/
public class CanalServiceImpl implements CanalService {
private static final Logger logger = LoggerFactory.getLogger(NodeServiceImpl.class);
private CanalDAO canalDao;
private TransactionTemplate transactionTemplate;
private AutoKeeperClusterService autoKeeperClusterService;
private ArbitrateViewService arbitrateViewService;
/**
* 添加
*/
public void create(final Canal canal) {
Assert.assertNotNull(canal);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
CanalDO canalDO = modelToDo(canal);
canalDO.setId(0L);
if (!canalDao.checkUnique(canalDO)) {
String exceptionCause = "exist the same repeat canal in the database.";
logger.warn("WARN ## " + exceptionCause);
throw new RepeatConfigureException(exceptionCause);
}
canalDao.insert(canalDO);
canal.setId(canalDO.getId());
} catch (RepeatConfigureException rce) {
throw rce;
} catch (Exception e) {
logger.error("ERROR ## create canal has an exception!");
throw new ManagerException(e);
}
}
});
}
/**
* 删除
*/
public void remove(final Long canalId) {
Assert.assertNotNull(canalId);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
Canal canal = findById(canalId);
canalDao.delete(canalId);
arbitrateViewService.removeCanal(canal.getName()); // 删除canal节点信息
} catch (Exception e) {
logger.error("ERROR ## remove canal(" + canalId + ") has an exception!");
throw new ManagerException(e);
}
}
});
}
/**
* 修改
*/
public void modify(final Canal canal) {
Assert.assertNotNull(canal);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
CanalDO canalDo = modelToDo(canal);
if (canalDao.checkUnique(canalDo)) {
canalDao.update(canalDo);
} else {
String exceptionCause = "exist the same repeat canal in the database.";
logger.warn("WARN ## " + exceptionCause);
throw new RepeatConfigureException(exceptionCause);
}
} catch (RepeatConfigureException rce) {
throw rce;
} catch (Exception e) {
logger.error("ERROR ## modify canal(" + canal.getId() + ") has an exception!");
throw new ManagerException(e);
}
}
});
}
public List listByIds(Long... identities) {
List canals = new ArrayList();
try {
List canalDos = null;
if (identities.length < 1) {
canalDos = canalDao.listAll();
if (canalDos.isEmpty()) {
logger.debug("DEBUG ## couldn't query any canal, maybe hasn't create any canal.");
return canals;
}
} else {
canalDos = canalDao.listByMultiId(identities);
if (canalDos.isEmpty()) {
String exceptionCause = "couldn't query any canal by canalIds:" + Arrays.toString(identities);
logger.error("ERROR ## " + exceptionCause);
throw new ManagerException(exceptionCause);
}
}
canals = doToModel(canalDos);
} catch (Exception e) {
logger.error("ERROR ## query channels has an exception!");
throw new ManagerException(e);
}
return canals;
}
public List listAll() {
return listByIds();
}
public Canal findById(Long canalId) {
Assert.assertNotNull(canalId);
List canals = listByIds(canalId);
if (canals.size() != 1) {
String exceptionCause = "query canalId:" + canalId + " return null.";
logger.error("ERROR ## " + exceptionCause);
throw new ManagerException(exceptionCause);
}
return canals.get(0);
}
public Canal findByName(String name) {
Assert.assertNotNull(name);
CanalDO canalDo = canalDao.findByName(name);
if (canalDo == null) {
String exceptionCause = "query name:" + name + " return null.";
logger.error("ERROR ## " + exceptionCause);
throw new ManagerException(exceptionCause);
}
return doToModel(canalDo);
}
@Override
public int getCount(Map condition) {
return canalDao.getCount(condition);
}
@Override
public List listByCondition(Map condition) {
List canalDos = canalDao.listByCondition(condition);
if (canalDos.isEmpty()) {
logger.debug("DEBUG ## couldn't query any canal by the condition:" + JsonUtils.marshalToString(condition));
return new ArrayList();
}
return doToModel(canalDos);
}
/**
* 用于Model对象转化为DO对象
*
* @param canal
* @return CanalDO
*/
private CanalDO modelToDo(Canal canal) {
CanalDO canalDo = new CanalDO();
try {
canalDo.setId(canal.getId());
canalDo.setName(canal.getName());
canalDo.setStatus(canal.getStatus());
canalDo.setDescription(canal.getDesc());
canalDo.setParameters(canal.getCanalParameter());
canalDo.setGmtCreate(canal.getGmtCreate());
canalDo.setGmtModified(canal.getGmtModified());
} catch (Exception e) {
logger.error("ERROR ## change the canal Model to Do has an exception");
throw new ManagerException(e);
}
return canalDo;
}
/**
* 用于DO对象转化为Model对象
*
* @param canalDo
* @return Canal
*/
private Canal doToModel(CanalDO canalDo) {
Canal canal = new Canal();
try {
canal.setId(canalDo.getId());
canal.setName(canalDo.getName());
canal.setStatus(canalDo.getStatus());
canal.setDesc(canalDo.getDescription());
CanalParameter parameter = canalDo.getParameters();
AutoKeeperCluster zkCluster = autoKeeperClusterService.findAutoKeeperClusterById(parameter.getZkClusterId());
if (zkCluster != null) {
parameter.setZkClusters(Arrays.asList(StringUtils.join(zkCluster.getServerList(), ',')));
}
canal.setCanalParameter(canalDo.getParameters());
canal.setGmtCreate(canalDo.getGmtCreate());
canal.setGmtModified(canalDo.getGmtModified());
} catch (Exception e) {
logger.error("ERROR ## change the canal Do to Model has an exception");
throw new ManagerException(e);
}
return canal;
}
private List doToModel(List canalDos) {
List canals = new ArrayList();
for (CanalDO canalDo : canalDos) {
canals.add(doToModel(canalDo));
}
return canals;
}
/* ------------------------setter / getter--------------------------- */
public void setCanalDao(CanalDAO canalDao) {
this.canalDao = canalDao;
}
public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
this.transactionTemplate = transactionTemplate;
}
public void setAutoKeeperClusterService(AutoKeeperClusterService autoKeeperClusterService) {
this.autoKeeperClusterService = autoKeeperClusterService;
}
public void setArbitrateViewService(ArbitrateViewService arbitrateViewService) {
this.arbitrateViewService = arbitrateViewService;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/channel/ChannelService.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.channel;
import java.util.List;
import java.util.Map;
import com.alibaba.otter.manager.biz.common.baseservice.GenericService;
import com.alibaba.otter.shared.common.model.config.channel.Channel;
import com.alibaba.otter.shared.common.model.config.channel.ChannelStatus;
/**
* @author simon
*/
public interface ChannelService extends GenericService {
public Channel findByPipelineId(Long pipelineId);
public Channel findByIdWithoutColumn(Long pipelineId);
public List listByPipelineIds(Long... pipelineIds);
public List listByNodeId(Long nodeId);
public List listOnlyChannels(Long... identities);
public List listAllChannelId();
public List listByNodeId(Long nodeId, ChannelStatus... status);
public List listByConditionWithoutColumn(Map condition);
public void stopChannel(Long channelId);
public void notifyChannel(Long channelId);
public void startChannel(Long channelId);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/channel/dal/ChannelDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.channel.dal;
import java.util.List;
import com.alibaba.otter.manager.biz.common.basedao.GenericDAO;
import com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO;
/**
* @author simon
*/
public interface ChannelDAO extends GenericDAO {
public List listChannelPks();
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/channel/dal/dataobject/ChannelDO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.channel.dal.dataobject;
import java.io.Serializable;
import java.util.Date;
import com.alibaba.otter.shared.common.model.config.channel.ChannelParameter;
import com.alibaba.otter.shared.common.model.config.channel.ChannelStatus;
/**
* @author simon
*/
public class ChannelDO implements Serializable {
private static final long serialVersionUID = 3708730560311969117L;
private Long id; // 唯一标示id
private String name; // channel命名
private ChannelStatus status; // 运行状态
private String description; // 描述信息
private ChannelParameter parameters; // 配置参数
private Date gmtCreate;
private Date gmtModified;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ChannelStatus getStatus() {
return status;
}
public void setStatus(ChannelStatus status) {
this.status = status;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public ChannelParameter getParameters() {
return parameters;
}
public void setParameters(ChannelParameter parameters) {
this.parameters = parameters;
}
public Date getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Date getGmtModified() {
return gmtModified;
}
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/channel/dal/ibatis/ChannelParameterTypeHandler.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.channel.dal.ibatis;
import java.sql.SQLException;
import com.alibaba.otter.shared.common.model.config.channel.ChannelParameter;
import com.alibaba.otter.shared.common.utils.JsonUtils;
import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
/**
* 用于ChannelParameter的解析
*
* @author simon
*/
public class ChannelParameterTypeHandler implements TypeHandlerCallback {
@Override
public void setParameter(ParameterSetter setter, Object parameter) throws SQLException {
setter.setString(JsonUtils.marshalToString(parameter));
}
@Override
public Object getResult(ResultGetter getter) throws SQLException {
return JsonUtils.unmarshalFromString(getter.getString(), ChannelParameter.class);
}
public Object valueOf(String s) {
return JsonUtils.unmarshalFromString(s, ChannelParameter.class);
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/channel/dal/ibatis/IbatisChannelDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.channel.dal.ibatis;
import java.util.List;
import java.util.Map;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.alibaba.otter.shared.common.utils.Assert;
import com.alibaba.otter.manager.biz.config.channel.dal.ChannelDAO;
import com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO;
/**
* Channel的DAO层,ibatis的实现,主要是CRUD操作。
*
* @author simon
*/
public class IbatisChannelDAO extends SqlMapClientDaoSupport implements ChannelDAO {
public ChannelDO insert(ChannelDO entityObj) {
Assert.assertNotNull(entityObj);
getSqlMapClientTemplate().insert("insertChannel", entityObj);
return entityObj;
}
public void delete(Long identity) {
Assert.assertNotNull(identity);
getSqlMapClientTemplate().delete("deleteChannelById", identity);
}
public void update(ChannelDO entityObj) {
Assert.assertNotNull(entityObj);
getSqlMapClientTemplate().update("updateChannel", entityObj);
}
public boolean checkUnique(ChannelDO entityObj) {
Assert.assertNotNull(entityObj);
int count = (Integer) getSqlMapClientTemplate().queryForObject("checkChannelUnique", entityObj);
return count == 0 ? true : false;
}
public List listAll() {
List channels = getSqlMapClientTemplate().queryForList("listChannels");
return channels;
}
public List listChannelPks() {
List channels = getSqlMapClientTemplate().queryForList("listChannelPks");
return channels;
}
public List listByCondition(Map condition) {
List channelDos = getSqlMapClientTemplate().queryForList("listChannels", condition);
return channelDos;
}
public int getCount() {
Integer count = (Integer) getSqlMapClientTemplate().queryForObject("getChannelCount");
return count.intValue();
}
public int getCount(Map condition) {
Integer count = (Integer) getSqlMapClientTemplate().queryForObject("getChannelCount", condition);
return count.intValue();
}
public List listByMultiId(Long... identities) {
List channelDos = getSqlMapClientTemplate().queryForList("listChannelByIds", identities);
return channelDos;
}
public ChannelDO findById(Long identity) {
Assert.assertNotNull(identity);
return (ChannelDO) getSqlMapClientTemplate().queryForObject("findChannelById", identity);
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/channel/impl/ChannelServiceImpl.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.channel.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException;
import com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException.INVALID_TYPE;
import com.alibaba.otter.manager.biz.common.exceptions.ManagerException;
import com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException;
import com.alibaba.otter.manager.biz.config.channel.ChannelService;
import com.alibaba.otter.manager.biz.config.channel.dal.ChannelDAO;
import com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO;
import com.alibaba.otter.manager.biz.config.parameter.SystemParameterService;
import com.alibaba.otter.manager.biz.config.pipeline.PipelineService;
import com.alibaba.otter.manager.biz.remote.ConfigRemoteService;
import com.alibaba.otter.shared.arbitrate.ArbitrateManageService;
import com.alibaba.otter.shared.common.model.config.channel.Channel;
import com.alibaba.otter.shared.common.model.config.channel.ChannelStatus;
import com.alibaba.otter.shared.common.model.config.parameter.SystemParameter;
import com.alibaba.otter.shared.common.model.config.pipeline.Pipeline;
import com.alibaba.otter.shared.common.model.config.pipeline.PipelineParameter;
import com.alibaba.otter.shared.common.utils.Assert;
import com.alibaba.otter.shared.common.utils.JsonUtils;
/**
* 主要提供增加、删除、修改、列表功能; 提供开启和停止channel方法,需要调用仲裁器方法
*
* @author simon
*/
public class ChannelServiceImpl implements ChannelService {
private static final Logger logger = LoggerFactory.getLogger(ChannelServiceImpl.class);
private SystemParameterService systemParameterService;
private ArbitrateManageService arbitrateManageService;
private TransactionTemplate transactionTemplate;
private ConfigRemoteService configRemoteService;
private PipelineService pipelineService;
private ChannelDAO channelDao;
/**
* 添加Channel
*/
public void create(final Channel channel) {
Assert.assertNotNull(channel);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
ChannelDO channelDo = modelToDo(channel);
channelDo.setId(0L);
if (!channelDao.checkUnique(channelDo)) {
String exceptionCause = "exist the same name channel in the database.";
logger.warn("WARN ## " + exceptionCause);
throw new RepeatConfigureException(exceptionCause);
}
channelDao.insert(channelDo);
arbitrateManageService.channelEvent().init(channelDo.getId());
} catch (RepeatConfigureException rce) {
throw rce;
} catch (Exception e) {
logger.error("ERROR ## create channel has an exception ", e);
throw new ManagerException(e);
}
}
});
}
/**
* 修改Channel
*/
public void modify(Channel channel) {
Assert.assertNotNull(channel);
try {
ChannelDO channelDo = modelToDo(channel);
if (channelDao.checkUnique(channelDo)) {
channelDao.update(channelDo);
} else {
String exceptionCause = "exist the same name channel in the database.";
logger.warn("WARN ## " + exceptionCause);
throw new RepeatConfigureException(exceptionCause);
}
} catch (RepeatConfigureException rce) {
throw rce;
} catch (Exception e) {
logger.error("ERROR ## modify channel has an exception ", e);
throw new ManagerException(e);
}
}
/**
* 删除Channel
*/
public void remove(final Long channelId) {
Assert.assertNotNull(channelId);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
arbitrateManageService.channelEvent().destory(channelId);
channelDao.delete(channelId);
} catch (Exception e) {
logger.error("ERROR ## remove channel has an exception ", e);
throw new ManagerException(e);
}
}
});
}
/*--------------------优化内容:listAll、listByIds、findById合并-------------------------------*/
public List listByIds(Long... identities) {
List channels = new ArrayList();
try {
List channelDos = null;
if (identities.length < 1) {
channelDos = channelDao.listAll();
if (channelDos.isEmpty()) {
logger.debug("DEBUG ## couldn't query any channel, maybe hasn't create any channel.");
return channels;
}
} else {
channelDos = channelDao.listByMultiId(identities);
if (channelDos.isEmpty()) {
String exceptionCause = "couldn't query any channel by channelIds:" + Arrays.toString(identities);
logger.error("ERROR ## " + exceptionCause);
throw new ManagerException(exceptionCause);
}
}
channels = doToModel(channelDos);
} catch (Exception e) {
logger.error("ERROR ## query channels has an exception!");
throw new ManagerException(e);
}
return channels;
}
/**
* 列出所有的Channel对象
*/
public List listAll() {
return listByIds();
}
public List listOnlyChannels(Long... identities) {
List channels = new ArrayList();
try {
List channelDos = null;
if (identities.length < 1) {
channelDos = channelDao.listAll();
if (channelDos.isEmpty()) {
logger.debug("DEBUG ## couldn't query any channel, maybe hasn't create any channel.");
return channels;
}
} else {
channelDos = channelDao.listByMultiId(identities);
if (channelDos.isEmpty()) {
String exceptionCause = "couldn't query any channel by channelIds:" + Arrays.toString(identities);
logger.error("ERROR ## " + exceptionCause);
throw new ManagerException(exceptionCause);
}
}
channels = doToModelOnlyChannels(channelDos);
} catch (Exception e) {
logger.error("ERROR ## query channels has an exception!");
throw new ManagerException(e);
}
return channels;
}
public List listByCondition(Map condition) {
List channelDos = channelDao.listByCondition(condition);
if (channelDos.isEmpty()) {
logger.debug("DEBUG ## couldn't query any channel by the condition:" + JsonUtils.marshalToString(condition));
return new ArrayList();
}
return doToModel(channelDos);
}
public List listByConditionWithoutColumn(Map condition) {
List channelDos = channelDao.listByCondition(condition);
if (channelDos.isEmpty()) {
logger.debug("DEBUG ## couldn't query any channel by the condition:" + JsonUtils.marshalToString(condition));
return new ArrayList();
}
return doToModelWithColumn(channelDos);
}
public List listAllChannelId() {
List channelDos = channelDao.listChannelPks();
List channelPks = new ArrayList();
if (channelDos.isEmpty()) {
logger.debug("DEBUG ## couldn't query any channel");
}
for (ChannelDO channelDo : channelDos) {
channelPks.add(channelDo.getId());
}
return channelPks;
}
/**
*
*
* @param channelDO
* @return Channel
*/
private List doToModel(List channelDos) {
List channels = new ArrayList();
try {
// 1.将ChannelID单独拿出来
List channelIds = new ArrayList();
for (ChannelDO channelDo : channelDos) {
channelIds.add(channelDo.getId());
}
Long[] idArray = new Long[channelIds.size()];
// 拿到所有的Pipeline进行ChannelID过滤,避免重复查询。
List pipelines = pipelineService.listByChannelIds(channelIds.toArray(idArray));
SystemParameter systemParameter = systemParameterService.find();
for (ChannelDO channelDo : channelDos) {
Channel channel = new Channel();
channel.setId(channelDo.getId());
channel.setName(channelDo.getName());
channel.setDescription(channelDo.getDescription());
ChannelStatus channelStatus = arbitrateManageService.channelEvent().status(channelDo.getId());
channel.setStatus(null == channelStatus ? ChannelStatus.STOP : channelStatus);
channel.setParameters(channelDo.getParameters());
channel.setGmtCreate(channelDo.getGmtCreate());
channel.setGmtModified(channelDo.getGmtModified());
// 遍历,将该Channel节点下的Pipeline提取出来。
List subPipelines = new ArrayList();
for (Pipeline pipeline : pipelines) {
if (pipeline.getChannelId().equals(channelDo.getId())) {
// 合并PipelineParameter和ChannelParameter
PipelineParameter parameter = new PipelineParameter();
parameter.merge(systemParameter);
parameter.merge(channel.getParameters());
// 最后复制pipelineId参数
parameter.merge(pipeline.getParameters());
pipeline.setParameters(parameter);
subPipelines.add(pipeline);
}
}
channel.setPipelines(subPipelines);
channels.add(channel);
}
} catch (Exception e) {
logger.error("ERROR ## change the channels DO to Model has an exception");
throw new ManagerException(e);
}
return channels;
}
private List doToModelWithColumn(List channelDos) {
List channels = new ArrayList();
try {
// 1.将ChannelID单独拿出来
List channelIds = new ArrayList();
for (ChannelDO channelDo : channelDos) {
channelIds.add(channelDo.getId());
}
Long[] idArray = new Long[channelIds.size()];
// 拿到所有的Pipeline进行ChannelID过滤,避免重复查询。
List pipelines = pipelineService.listByChannelIdsWithoutColumn(channelIds.toArray(idArray));
SystemParameter systemParameter = systemParameterService.find();
for (ChannelDO channelDo : channelDos) {
Channel channel = new Channel();
channel.setId(channelDo.getId());
channel.setName(channelDo.getName());
channel.setDescription(channelDo.getDescription());
ChannelStatus channelStatus = arbitrateManageService.channelEvent().status(channelDo.getId());
channel.setStatus(null == channelStatus ? ChannelStatus.STOP : channelStatus);
channel.setParameters(channelDo.getParameters());
channel.setGmtCreate(channelDo.getGmtCreate());
channel.setGmtModified(channelDo.getGmtModified());
// 遍历,将该Channel节点下的Pipeline提取出来。
List subPipelines = new ArrayList();
for (Pipeline pipeline : pipelines) {
if (pipeline.getChannelId().equals(channelDo.getId())) {
// 合并PipelineParameter和ChannelParameter
PipelineParameter parameter = new PipelineParameter();
parameter.merge(systemParameter);
parameter.merge(channel.getParameters());
// 最后复制pipelineId参数
parameter.merge(pipeline.getParameters());
pipeline.setParameters(parameter);
subPipelines.add(pipeline);
}
}
channel.setPipelines(subPipelines);
channels.add(channel);
}
} catch (Exception e) {
logger.error("ERROR ## change the channels DO to Model has an exception");
throw new ManagerException(e);
}
return channels;
}
private List doToModelOnlyChannels(List channelDos) {
List channels = new ArrayList();
try {
// 1.将ChannelID单独拿出来
List channelIds = new ArrayList();
for (ChannelDO channelDo : channelDos) {
channelIds.add(channelDo.getId());
}
for (ChannelDO channelDo : channelDos) {
Channel channel = new Channel();
channel.setId(channelDo.getId());
channel.setName(channelDo.getName());
channel.setDescription(channelDo.getDescription());
ChannelStatus channelStatus = arbitrateManageService.channelEvent().status(channelDo.getId());
channel.setStatus(null == channelStatus ? ChannelStatus.STOP : channelStatus);
channel.setParameters(channelDo.getParameters());
channel.setGmtCreate(channelDo.getGmtCreate());
channel.setGmtModified(channelDo.getGmtModified());
// 遍历,将该Channel节点下的Pipeline提取出来。
List subPipelines = new ArrayList();
channel.setPipelines(subPipelines);
channels.add(channel);
}
} catch (Exception e) {
logger.error("ERROR ## change the channels doToModelOnlyChannels has an exception");
throw new ManagerException(e);
}
return channels;
}
/* ------------------------setter / getter--------------------------- */
public void setPipelineService(PipelineService pipelineService) {
this.pipelineService = pipelineService;
}
public void setChannelDao(ChannelDAO channelDao) {
this.channelDao = channelDao;
}
public void setArbitrateManageService(ArbitrateManageService arbitrateManageService) {
this.arbitrateManageService = arbitrateManageService;
}
public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
this.transactionTemplate = transactionTemplate;
}
public void setConfigRemoteService(ConfigRemoteService configRemoteService) {
this.configRemoteService = configRemoteService;
}
public void setSystemParameterService(SystemParameterService systemParameterService) {
this.systemParameterService = systemParameterService;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/datacolumnpair/DataColumnPairGroupService.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.datacolumnpair;
import java.util.List;
import java.util.Map;
import com.alibaba.otter.manager.biz.common.baseservice.GenericService;
import com.alibaba.otter.shared.common.model.config.data.ColumnGroup;
/**
* 类DataColumnPairGroupService.java的实现描述:TODO 类实现描述
*
* @author simon 2012-4-20 下午4:08:24
*/
public interface DataColumnPairGroupService extends GenericService {
public void removeByDataMediaPairId(Long dataMediaPairId);
public List listByDataMediaPairId(Long dataMediaPairId);
public Map> listByDataMediaPairIds(Long... dataMediaPairId);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/datacolumnpair/DataColumnPairService.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.datacolumnpair;
import java.util.List;
import java.util.Map;
import com.alibaba.otter.manager.biz.common.baseservice.GenericService;
import com.alibaba.otter.shared.common.model.config.data.ColumnPair;
/**
* 类DataColumnPairService.java的实现描述:TODO 类实现描述
*
* @author simon 2012-4-20 下午4:07:47
*/
public interface DataColumnPairService extends GenericService {
public List listByDataMediaPairId(Long dataMediaPairId);
public Map> listByDataMediaPairIds(Long... dataMediaPairIds);
public void createBatch(List dataColumnPairs);
public void removeByDataMediaPairId(Long dataMediaPairId);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/datacolumnpair/dal/DataColumnPairDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.datacolumnpair.dal;
import java.util.List;
import com.alibaba.otter.manager.biz.common.basedao.GenericDAO;
import com.alibaba.otter.manager.biz.config.datacolumnpair.dal.dataobject.DataColumnPairDO;
/**
* 类DataColumnPairDAO.java的实现描述:TODO 类实现描述
*
* @author simon 2012-4-20 下午4:08:55
*/
public interface DataColumnPairDAO extends GenericDAO {
public List listByDataMediaPairId(Long dataMediaPairId);
public List listByDataMediaPairIds(Long... dataMediaPairIds);
public void insertBatch(List dataColumnPairDos);
public void deleteByDataMediaPairId(Long dataMediaPairId);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/datacolumnpair/dal/DataColumnPairGroupDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.datacolumnpair.dal;
import java.util.List;
import com.alibaba.otter.manager.biz.common.basedao.GenericDAO;
import com.alibaba.otter.manager.biz.config.datacolumnpair.dal.dataobject.DataColumnPairGroupDO;
/**
* 类DataColumnPairGroupDAO.java的实现描述:TODO 类实现描述
*
* @author simon 2012-4-20 下午4:09:09
*/
public interface DataColumnPairGroupDAO extends GenericDAO {
public void deleteByDataMediaPairId(Long dataMediaPairId);
public List ListByDataMediaPairId(Long dataMediaPairId);
public List ListByDataMediaPairIds(Long... dataMediaPairIds);
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/datacolumnpair/dal/dataobject/DataColumnPairDO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.datacolumnpair.dal.dataobject;
import java.io.Serializable;
import java.util.Date;
/**
* 类DataColumnPairDO.java的实现描述:TODO 类实现描述
*
* @author simon 2012-4-20 下午4:09:38
*/
public class DataColumnPairDO implements Serializable {
private static final long serialVersionUID = 194553152360180533L;
private Long id;
private String sourceColumnName; // 源字段
private String targetColumnName; // 目标字段
private Long dataMediaPairId;
private Date gmtCreate;
private Date gmtModified;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getSourceColumnName() {
return sourceColumnName;
}
public void setSourceColumnName(String sourceColumnName) {
this.sourceColumnName = sourceColumnName;
}
public String getTargetColumnName() {
return targetColumnName;
}
public void setTargetColumnName(String targetColumnName) {
this.targetColumnName = targetColumnName;
}
public Long getDataMediaPairId() {
return dataMediaPairId;
}
public void setDataMediaPairId(Long dataMediaPairId) {
this.dataMediaPairId = dataMediaPairId;
}
public Date getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Date getGmtModified() {
return gmtModified;
}
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/datacolumnpair/dal/dataobject/DataColumnPairGroupDO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.datacolumnpair.dal.dataobject;
import java.io.Serializable;
import java.util.Date;
/**
* 类DataColumnPairGroupDO.java的实现描述:TODO 类实现描述
*
* @author simon 2012-4-20 下午4:09:50
*/
public class DataColumnPairGroupDO implements Serializable {
private static final long serialVersionUID = 7205447225855754450L;
private Long id;
private String columnPairContent;
private Long dataMediaPairId;
private Date gmtCreate;
private Date gmtModified;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getColumnPairContent() {
return columnPairContent;
}
public void setColumnPairContent(String columnPairContent) {
this.columnPairContent = columnPairContent;
}
public Long getDataMediaPairId() {
return dataMediaPairId;
}
public void setDataMediaPairId(Long dataMediaPairId) {
this.dataMediaPairId = dataMediaPairId;
}
public Date getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Date gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Date getGmtModified() {
return gmtModified;
}
public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/datacolumnpair/dal/ibatis/IbatisDataColumnPairDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.datacolumnpair.dal.ibatis;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.alibaba.otter.shared.common.utils.Assert;
import com.alibaba.otter.manager.biz.config.datacolumnpair.dal.DataColumnPairDAO;
import com.alibaba.otter.manager.biz.config.datacolumnpair.dal.dataobject.DataColumnPairDO;
import com.alibaba.otter.manager.biz.config.datacolumnpair.dal.dataobject.DataColumnPairGroupDO;
/**
* 类IbatisDataColumnPairDAO.java的实现描述:TODO 类实现描述
*
* @author simon 2012-4-20 下午4:10:48
*/
public class IbatisDataColumnPairDAO extends SqlMapClientDaoSupport implements DataColumnPairDAO {
public DataColumnPairGroupDO insert(DataColumnPairGroupDO dataColumnPairDo) {
Assert.assertNotNull(dataColumnPairDo);
getSqlMapClientTemplate().insert("insertDataColumnPair", dataColumnPairDo);
return dataColumnPairDo;
}
public void insertBatch(List dataColumnPairDos) {
try {
getSqlMapClientTemplate().getSqlMapClient().startBatch();
Iterator it = dataColumnPairDos.iterator();
while (it.hasNext()) {
DataColumnPairDO dataColumnPairDo = (DataColumnPairDO) it.next();
getSqlMapClientTemplate().getSqlMapClient().insert("insertDataColumnPair", dataColumnPairDo);
}
getSqlMapClientTemplate().getSqlMapClient().executeBatch();
} catch (SQLException ex1) {
ex1.printStackTrace();
}
}
public void delete(Long dataColumnPairId) {
Assert.assertNotNull(dataColumnPairId);
getSqlMapClientTemplate().delete("deleteDataColumnPairById", dataColumnPairId);
}
public void deleteByDataMediaPairId(Long dataMediaPairId) {
Assert.assertNotNull(dataMediaPairId);
getSqlMapClientTemplate().delete("deleteDataColumnPairByDataMediaPairId", dataMediaPairId);
}
public void update(DataColumnPairGroupDO dataColumnPairDo) {
Assert.assertNotNull(dataColumnPairDo);
getSqlMapClientTemplate().update("updateDataColumnPair", dataColumnPairDo);
}
public List listAll() {
List dataColumnPairGroupDos = getSqlMapClientTemplate().queryForList("listDataColumnPairs");
return dataColumnPairGroupDos;
}
public List listByCondition(Map condition) {
return null;
}
public List listByMultiId(Long... identities) {
return null;
}
public DataColumnPairDO findById(Long identity) {
Assert.assertNotNull(identity);
return (DataColumnPairDO) getSqlMapClientTemplate().queryForObject("findDataColumnPairById", identity);
}
public int getCount() {
return 0;
}
public int getCount(Map condition) {
return 0;
}
public boolean checkUnique(DataColumnPairGroupDO entityObj) {
return false;
}
public List listByDataMediaPairId(Long dataMediaPairId) {
List dataColumnPairDos = getSqlMapClientTemplate().queryForList("listDataColumnPairByDataMediaPairId",
dataMediaPairId);
return dataColumnPairDos;
}
public List listByDataMediaPairIds(Long... dataMediaPairIds) {
List dataColumnPairDos = getSqlMapClientTemplate().queryForList("listDataColumnPairByDataMediaPairIds",
dataMediaPairIds);
return dataColumnPairDos;
}
public DataColumnPairDO insert(DataColumnPairDO entityObj) {
// TODO Auto-generated method stub
return null;
}
public void update(DataColumnPairDO entityObj) {
// TODO Auto-generated method stub
}
public boolean checkUnique(DataColumnPairDO entityObj) {
// TODO Auto-generated method stub
return false;
}
}
================================================
FILE: manager/biz/src/main/java/com/alibaba/otter/manager/biz/config/datacolumnpair/dal/ibatis/IbatisDataColumnPairGroupDAO.java
================================================
/*
* Copyright (C) 2010-2101 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.otter.manager.biz.config.datacolumnpair.dal.ibatis;
import java.util.List;
import java.util.Map;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.alibaba.otter.shared.common.utils.Assert;
import com.alibaba.otter.manager.biz.config.datacolumnpair.dal.DataColumnPairGroupDAO;
import com.alibaba.otter.manager.biz.config.datacolumnpair.dal.dataobject.DataColumnPairGroupDO;
/**
* 类IbatisDataColumnPairGroupDAO.java的实现描述:TODO 类实现描述
*
* @author simon 2012-4-20 下午4:11:06
*/
public class IbatisDataColumnPairGroupDAO extends SqlMapClientDaoSupport implements DataColumnPairGroupDAO {
public DataColumnPairGroupDO insert(DataColumnPairGroupDO entityObj) {
Assert.assertNotNull(entityObj);
getSqlMapClientTemplate().insert("insertDataColumnPairGroup", entityObj);
return entityObj;
}
public void delete(Long identity) {
// TODO Auto-generated method stub
}
public void deleteByDataMediaPairId(Long dataMediaPairId) {
Assert.assertNotNull(dataMediaPairId);
getSqlMapClientTemplate().delete("deleteDataColumnPairGroupByDataMediaPairId", dataMediaPairId);
}
public void update(DataColumnPairGroupDO entityObj) {
// TODO Auto-generated method stub
}
public List listAll() {
// TODO Auto-generated method stub
return null;
}
public List ListByDataMediaPairId(Long dataMediaPairId) {
Assert.assertNotNull(dataMediaPairId);
List dataColumnPairGroupDos = getSqlMapClientTemplate().queryForList("listDataColumnPairGroupByDataMediaPairId",
dataMediaPairId);
return dataColumnPairGroupDos;
}
public List ListByDataMediaPairIds(Long... dataMediaPairIds) {
Assert.assertNotNull(dataMediaPairIds);
List dataColumnPairGroupDos = getSqlMapClientTemplate().queryForList("listDataColumnPairGroupByDataMediaPairIds",
dataMediaPairIds);
return dataColumnPairGroupDos;
}
public List listByCondition(Map condition) {
// TODO Auto-generated method stub
return null;
}
public List