bao liang
6 years ago
committed by
GitHub
469 changed files with 12721 additions and 2774 deletions
@ -0,0 +1,70 @@ |
|||||||
|
EasyScheduler提交代码流程 |
||||||
|
===== |
||||||
|
* 首先从远端仓库*https://github.com/analysys/EasyScheduler.git* fork一份代码到自己的仓库中 |
||||||
|
|
||||||
|
* 远端仓库中目前有三个分支: |
||||||
|
* master 正常交付分支 |
||||||
|
* dev 日常开发分支 |
||||||
|
* branch-1.0.0 发布版本分支 |
||||||
|
|
||||||
|
* 把自己仓库clone到本地 |
||||||
|
|
||||||
|
`git clone https://github.com/**/EasyScheduler.git` |
||||||
|
|
||||||
|
* 添加远端仓库地址,命名为upstream |
||||||
|
|
||||||
|
` git remote add upstream https://github.com/analysys/EasyScheduler.git ` |
||||||
|
|
||||||
|
* 查看仓库: |
||||||
|
|
||||||
|
` git remote -v` |
||||||
|
|
||||||
|
> 此时会有两个仓库:origin(自己的仓库)和upstream(远端仓库) |
||||||
|
|
||||||
|
* 获取远端仓库代码(已经是最新代码,就跳过) |
||||||
|
|
||||||
|
`git fetch upstream ` |
||||||
|
|
||||||
|
* 更新远端仓库代码 |
||||||
|
|
||||||
|
``` |
||||||
|
git checkout upstream/dev |
||||||
|
|
||||||
|
git pull upstream dev |
||||||
|
``` |
||||||
|
|
||||||
|
* 同步远端仓库代码到本地仓库 |
||||||
|
|
||||||
|
``` |
||||||
|
git checkout origin/dev |
||||||
|
git merge --no-ff upstream/dev |
||||||
|
|
||||||
|
``` |
||||||
|
|
||||||
|
* 在本地修改代码以后,提交到自己仓库: |
||||||
|
|
||||||
|
`git ca -m 'test commit'` |
||||||
|
`git push` |
||||||
|
|
||||||
|
* 将修改提交到远端仓库 |
||||||
|
|
||||||
|
* 在github页面,点击New pull request. |
||||||
|
<p align="center"> |
||||||
|
<img src="http://geek.analysys.cn/static/upload/221/2019-04-02/90f3abbf-70ef-4334-b8d6-9014c9cf4c7f.png" width="60%" /> |
||||||
|
</p> |
||||||
|
|
||||||
|
* 选择修改完的本地分支和要合并过去的分支,Create pull request. |
||||||
|
<p align="center"> |
||||||
|
<img src="http://geek.analysys.cn/static/upload/221/2019-04-02/fe7eecfe-2720-4736-951b-b3387cf1ae41.png" width="60%" /> |
||||||
|
</p> |
||||||
|
* 接下来由管理员负责将**Merge**完成此次pull request |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,41 @@ |
|||||||
|
#Maintin by jimmy |
||||||
|
#Email: zhengge2012@gmail.com |
||||||
|
FROM anapsix/alpine-java:8_jdk |
||||||
|
WORKDIR /tmp |
||||||
|
RUN wget http://archive.apache.org/dist/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz |
||||||
|
RUN tar -zxvf apache-maven-3.6.1-bin.tar.gz && rm apache-maven-3.6.1-bin.tar.gz |
||||||
|
RUN mv apache-maven-3.6.1 /usr/lib/mvn |
||||||
|
RUN chown -R root:root /usr/lib/mvn |
||||||
|
RUN ln -s /usr/lib/mvn/bin/mvn /usr/bin/mvn |
||||||
|
RUN wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz |
||||||
|
RUN tar -zxvf zookeeper-3.4.6.tar.gz |
||||||
|
RUN mv zookeeper-3.4.6 /opt/zookeeper |
||||||
|
RUN rm -rf zookeeper-3.4.6.tar.gz |
||||||
|
RUN echo "export ZOOKEEPER_HOME=/opt/zookeeper" >>/etc/profile |
||||||
|
RUN echo "export PATH=$PATH:$ZOOKEEPER_HOME/bin" >>/etc/profile |
||||||
|
ADD conf/zoo.cfg /opt/zookeeper/conf/zoo.cfg |
||||||
|
#RUN source /etc/profile |
||||||
|
#RUN zkServer.sh start |
||||||
|
RUN apk add --no-cache git npm nginx mariadb mariadb-client mariadb-server-utils pwgen |
||||||
|
WORKDIR /opt |
||||||
|
RUN git clone https://github.com/analysys/EasyScheduler.git |
||||||
|
WORKDIR /opt/EasyScheduler |
||||||
|
RUN mvn -U clean package assembly:assembly -Dmaven.test.skip=true |
||||||
|
RUN mv /opt/EasyScheduler/target/escheduler-1.0.0-SNAPSHOT /opt/easyscheduler |
||||||
|
WORKDIR /opt/EasyScheduler/escheduler-ui |
||||||
|
RUN npm install |
||||||
|
RUN npm audit fix |
||||||
|
RUN npm run build |
||||||
|
RUN mkdir -p /opt/escheduler/front/server |
||||||
|
RUN cp -rfv dist/* /opt/escheduler/front/server |
||||||
|
WORKDIR / |
||||||
|
RUN rm -rf /opt/EasyScheduler |
||||||
|
#configure mysql server https://github.com/yobasystems/alpine-mariadb/tree/master/alpine-mariadb-amd64 |
||||||
|
ADD conf/run.sh /scripts/run.sh |
||||||
|
RUN mkdir /docker-entrypoint-initdb.d && \ |
||||||
|
mkdir /scripts/pre-exec.d && \ |
||||||
|
mkdir /scripts/pre-init.d && \ |
||||||
|
chmod -R 755 /scripts |
||||||
|
RUN rm -rf /var/cache/apk/* |
||||||
|
EXPOSE 8888 |
||||||
|
ENTRYPOINT ["/scripts/run.sh"] |
@ -0,0 +1,31 @@ |
|||||||
|
server { |
||||||
|
listen 8888;# 访问端口 |
||||||
|
server_name localhost; |
||||||
|
#charset koi8-r; |
||||||
|
#access_log /var/log/nginx/host.access.log main; |
||||||
|
location / { |
||||||
|
root /opt/escheduler/front/server; # 静态文件目录 |
||||||
|
index index.html index.html; |
||||||
|
} |
||||||
|
location /escheduler { |
||||||
|
proxy_pass http://127.0.0.1:12345; # 接口地址 |
||||||
|
proxy_set_header Host $host; |
||||||
|
proxy_set_header X-Real-IP $remote_addr; |
||||||
|
proxy_set_header x_real_ipP $remote_addr; |
||||||
|
proxy_set_header remote_addr $remote_addr; |
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
||||||
|
proxy_http_version 1.1; |
||||||
|
proxy_connect_timeout 4s; |
||||||
|
proxy_read_timeout 30s; |
||||||
|
proxy_send_timeout 12s; |
||||||
|
proxy_set_header Upgrade $http_upgrade; |
||||||
|
proxy_set_header Connection "upgrade"; |
||||||
|
} |
||||||
|
#error_page 404 /404.html; |
||||||
|
# redirect server error pages to the static page /50x.html |
||||||
|
# |
||||||
|
error_page 500 502 503 504 /50x.html; |
||||||
|
location = /50x.html { |
||||||
|
root /usr/share/nginx/html; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,310 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
workDir=`/opt/easyscheduler` |
||||||
|
workDir=`cd ${workDir};pwd` |
||||||
|
|
||||||
|
#To be compatible with MacOS and Linux |
||||||
|
txt="" |
||||||
|
if [[ "$OSTYPE" == "darwin"* ]]; then |
||||||
|
# Mac OSX |
||||||
|
txt="''" |
||||||
|
elif [[ "$OSTYPE" == "linux-gnu" ]]; then |
||||||
|
# linux |
||||||
|
txt="" |
||||||
|
elif [[ "$OSTYPE" == "cygwin" ]]; then |
||||||
|
# POSIX compatibility layer and Linux environment emulation for Windows |
||||||
|
echo "Easy Scheduler not support Windows operating system" |
||||||
|
exit 1 |
||||||
|
elif [[ "$OSTYPE" == "msys" ]]; then |
||||||
|
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW) |
||||||
|
echo "Easy Scheduler not support Windows operating system" |
||||||
|
exit 1 |
||||||
|
elif [[ "$OSTYPE" == "win32" ]]; then |
||||||
|
echo "Easy Scheduler not support Windows operating system" |
||||||
|
exit 1 |
||||||
|
elif [[ "$OSTYPE" == "freebsd"* ]]; then |
||||||
|
# ... |
||||||
|
txt="" |
||||||
|
else |
||||||
|
# Unknown. |
||||||
|
echo "Operating system unknown, please tell us(submit issue) for better service" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
source ${workDir}/conf/config/run_config.conf |
||||||
|
source ${workDir}/conf/config/install_config.conf |
||||||
|
|
||||||
|
# mysql配置 |
||||||
|
# mysql 地址,端口 |
||||||
|
mysqlHost="127.0.0.1:3306" |
||||||
|
|
||||||
|
# mysql 数据库名称 |
||||||
|
mysqlDb="easyscheduler" |
||||||
|
|
||||||
|
# mysql 用户名 |
||||||
|
mysqlUserName="easyscheduler" |
||||||
|
|
||||||
|
# mysql 密码 |
||||||
|
mysqlPassword="easyschedulereasyscheduler" |
||||||
|
|
||||||
|
# conf/config/install_config.conf配置 |
||||||
|
# 安装路径,不要当前路径(pwd)一样 |
||||||
|
installPath="/opt/easyscheduler" |
||||||
|
|
||||||
|
# 部署用户 |
||||||
|
deployUser="escheduler" |
||||||
|
|
||||||
|
# zk集群 |
||||||
|
zkQuorum="192.168.xx.xx:2181,192.168.xx.xx:2181,192.168.xx.xx:2181" |
||||||
|
|
||||||
|
# 安装hosts |
||||||
|
ips="ark0,ark1,ark2,ark3,ark4" |
||||||
|
|
||||||
|
# conf/config/run_config.conf配置 |
||||||
|
# 运行Master的机器 |
||||||
|
masters="ark0,ark1" |
||||||
|
|
||||||
|
# 运行Worker的机器 |
||||||
|
workers="ark2,ark3,ark4" |
||||||
|
|
||||||
|
# 运行Alert的机器 |
||||||
|
alertServer="ark3" |
||||||
|
|
||||||
|
# 运行Api的机器 |
||||||
|
apiServers="ark1" |
||||||
|
|
||||||
|
# alert配置 |
||||||
|
# 邮件协议 |
||||||
|
mailProtocol="SMTP" |
||||||
|
|
||||||
|
# 邮件服务host |
||||||
|
mailServerHost="smtp.exmail.qq.com" |
||||||
|
|
||||||
|
# 邮件服务端口 |
||||||
|
mailServerPort="25" |
||||||
|
|
||||||
|
# 发送人 |
||||||
|
mailSender="xxxxxxxxxx" |
||||||
|
|
||||||
|
# 发送人密码 |
||||||
|
mailPassword="xxxxxxxxxx" |
||||||
|
|
||||||
|
# 下载Excel路径 |
||||||
|
xlsFilePath="/tmp/xls" |
||||||
|
|
||||||
|
|
||||||
|
# hadoop 配置 |
||||||
|
# 是否启动hdfs,如果启动则为true,需要配置以下hadoop相关参数; |
||||||
|
# 不启动设置为false,如果为false,以下配置不需要修改 |
||||||
|
hdfsStartupSate="false" |
||||||
|
|
||||||
|
# namenode地址,支持HA,需要将core-site.xml和hdfs-site.xml放到conf目录下 |
||||||
|
namenodeFs="hdfs://mycluster:8020" |
||||||
|
|
||||||
|
# resourcemanager HA配置,如果是单resourcemanager,这里为空即可 |
||||||
|
yarnHaIps="192.168.xx.xx,192.168.xx.xx" |
||||||
|
|
||||||
|
# 如果是单 resourcemanager,只需要配置一个主机名称,如果是resourcemanager HA,则默认配置就好 |
||||||
|
singleYarnIp="ark1" |
||||||
|
|
||||||
|
# hdfs根路径,根路径的owner必须是部署用户 |
||||||
|
hdfsPath="/escheduler" |
||||||
|
|
||||||
|
# common 配置 |
||||||
|
# 程序路径 |
||||||
|
programPath="/tmp/escheduler" |
||||||
|
|
||||||
|
#下载路径 |
||||||
|
downloadPath="/tmp/escheduler/download" |
||||||
|
|
||||||
|
# 任务执行路径 |
||||||
|
execPath="/tmp/escheduler/exec" |
||||||
|
|
||||||
|
# SHELL环境变量路径 |
||||||
|
shellEnvPath="$installPath/conf/env/.escheduler_env.sh" |
||||||
|
|
||||||
|
# Python换将变量路径 |
||||||
|
pythonEnvPath="$installPath/conf/env/escheduler_env.py" |
||||||
|
|
||||||
|
# 资源文件的后缀 |
||||||
|
resSuffixs="txt,log,sh,conf,cfg,py,java,sql,hql,xml" |
||||||
|
|
||||||
|
# 开发状态,如果是true,对于SHELL脚本可以在execPath目录下查看封装后的SHELL脚本,如果是false则执行完成直接删除 |
||||||
|
devState="true" |
||||||
|
|
||||||
|
# zk 配置 |
||||||
|
# zk根目录 |
||||||
|
zkRoot="/escheduler" |
||||||
|
|
||||||
|
# 用来记录挂掉机器的zk目录 |
||||||
|
zkDeadServers="/escheduler/dead-servers" |
||||||
|
|
||||||
|
# masters目录 |
||||||
|
zkMasters="/escheduler/masters" |
||||||
|
|
||||||
|
# workers目录 |
||||||
|
zkWorkers="/escheduler/workers" |
||||||
|
|
||||||
|
# zk master分布式锁 |
||||||
|
mastersLock="/escheduler/lock/masters" |
||||||
|
|
||||||
|
# zk worker分布式锁 |
||||||
|
workersLock="/escheduler/lock/workers" |
||||||
|
|
||||||
|
# zk master容错分布式锁 |
||||||
|
mastersFailover="/escheduler/lock/failover/masters" |
||||||
|
|
||||||
|
# zk worker容错分布式锁 |
||||||
|
workersFailover="/escheduler/lock/failover/masters" |
||||||
|
|
||||||
|
# zk session 超时 |
||||||
|
zkSessionTimeout="300" |
||||||
|
|
||||||
|
# zk 连接超时 |
||||||
|
zkConnectionTimeout="300" |
||||||
|
|
||||||
|
# zk 重试间隔 |
||||||
|
zkRetrySleep="100" |
||||||
|
|
||||||
|
# zk重试最大次数 |
||||||
|
zkRetryMaxtime="5" |
||||||
|
|
||||||
|
|
||||||
|
# master 配置 |
||||||
|
# master执行线程最大数,流程实例的最大并行度 |
||||||
|
masterExecThreads="100" |
||||||
|
|
||||||
|
# master任务执行线程最大数,每一个流程实例的最大并行度 |
||||||
|
masterExecTaskNum="20" |
||||||
|
|
||||||
|
# master心跳间隔 |
||||||
|
masterHeartbeatInterval="10" |
||||||
|
|
||||||
|
# master任务提交重试次数 |
||||||
|
masterTaskCommitRetryTimes="5" |
||||||
|
|
||||||
|
# master任务提交重试时间间隔 |
||||||
|
masterTaskCommitInterval="100" |
||||||
|
|
||||||
|
# master最大cpu平均负载,用来判断master是否还有执行能力 |
||||||
|
masterMaxCupLoadAvg="10" |
||||||
|
|
||||||
|
# master预留内存,用来判断master是否还有执行能力 |
||||||
|
masterReservedMemory="1" |
||||||
|
|
||||||
|
|
||||||
|
# worker 配置 |
||||||
|
# worker执行线程 |
||||||
|
workerExecThreads="100" |
||||||
|
|
||||||
|
# worker心跳间隔 |
||||||
|
workerHeartbeatInterval="10" |
||||||
|
|
||||||
|
# worker一次抓取任务数 |
||||||
|
workerFetchTaskNum="10" |
||||||
|
|
||||||
|
# worker最大cpu平均负载,用来判断master是否还有执行能力 |
||||||
|
workerMaxCupLoadAvg="10" |
||||||
|
|
||||||
|
# worker预留内存,用来判断master是否还有执行能力 |
||||||
|
workerReservedMemory="1" |
||||||
|
|
||||||
|
# api 配置 |
||||||
|
# api 服务端口 |
||||||
|
apiServerPort="12345" |
||||||
|
|
||||||
|
# api session 超时 |
||||||
|
apiServerSessionTimeout="7200" |
||||||
|
|
||||||
|
# api 上下文路径 |
||||||
|
apiServerContextPath="/escheduler/" |
||||||
|
|
||||||
|
# spring 最大文件大小 |
||||||
|
springMaxFileSize="1024MB" |
||||||
|
|
||||||
|
# spring 最大请求文件大小 |
||||||
|
springMaxRequestSize="1024MB" |
||||||
|
|
||||||
|
# api 最大post请求大小 |
||||||
|
apiMaxHttpPostSize="5000000" |
||||||
|
|
||||||
|
# 1,替换文件 |
||||||
|
echo "1,替换文件" |
||||||
|
sed -i ${txt} "s#spring.datasource.url.*#spring.datasource.url=jdbc:mysql://${mysqlHost}/${mysqlDb}?characterEncoding=UTF-8#g" conf/dao/data_source.properties |
||||||
|
sed -i ${txt} "s#spring.datasource.username.*#spring.datasource.username=${mysqlUserName}#g" conf/dao/data_source.properties |
||||||
|
sed -i ${txt} "s#spring.datasource.password.*#spring.datasource.password=${mysqlPassword}#g" conf/dao/data_source.properties |
||||||
|
|
||||||
|
sed -i ${txt} "s#org.quartz.dataSource.myDs.URL.*#org.quartz.dataSource.myDs.URL=jdbc:mysql://${mysqlHost}/${mysqlDb}?characterEncoding=UTF-8#g" conf/quartz.properties |
||||||
|
sed -i ${txt} "s#org.quartz.dataSource.myDs.user.*#org.quartz.dataSource.myDs.user=${mysqlUserName}#g" conf/quartz.properties |
||||||
|
sed -i ${txt} "s#org.quartz.dataSource.myDs.password.*#org.quartz.dataSource.myDs.password=${mysqlPassword}#g" conf/quartz.properties |
||||||
|
|
||||||
|
|
||||||
|
sed -i ${txt} "s#fs.defaultFS.*#fs.defaultFS=${namenodeFs}#g" conf/common/hadoop/hadoop.properties |
||||||
|
sed -i ${txt} "s#yarn.resourcemanager.ha.rm.ids.*#yarn.resourcemanager.ha.rm.ids=${yarnHaIps}#g" conf/common/hadoop/hadoop.properties |
||||||
|
sed -i ${txt} "s#yarn.application.status.address.*#yarn.application.status.address=http://${singleYarnIp}:8088/ws/v1/cluster/apps/%s#g" conf/common/hadoop/hadoop.properties |
||||||
|
|
||||||
|
sed -i ${txt} "s#data.basedir.path.*#data.basedir.path=${programPath}#g" conf/common/common.properties |
||||||
|
sed -i ${txt} "s#data.download.basedir.path.*#data.download.basedir.path=${downloadPath}#g" conf/common/common.properties |
||||||
|
sed -i ${txt} "s#process.exec.basepath.*#process.exec.basepath=${execPath}#g" conf/common/common.properties |
||||||
|
sed -i ${txt} "s#data.store2hdfs.basepath.*#data.store2hdfs.basepath=${hdfsPath}#g" conf/common/common.properties |
||||||
|
sed -i ${txt} "s#hdfs.startup.state.*#hdfs.startup.state=${hdfsStartupSate}#g" conf/common/common.properties |
||||||
|
sed -i ${txt} "s#escheduler.env.path.*#escheduler.env.path=${shellEnvPath}#g" conf/common/common.properties |
||||||
|
sed -i ${txt} "s#escheduler.env.py.*#escheduler.env.py=${pythonEnvPath}#g" conf/common/common.properties |
||||||
|
sed -i ${txt} "s#resource.view.suffixs.*#resource.view.suffixs=${resSuffixs}#g" conf/common/common.properties |
||||||
|
sed -i ${txt} "s#development.state.*#development.state=${devState}#g" conf/common/common.properties |
||||||
|
|
||||||
|
sed -i ${txt} "s#zookeeper.quorum.*#zookeeper.quorum=${zkQuorum}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.escheduler.root.*#zookeeper.escheduler.root=${zkRoot}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.escheduler.dead.servers.*#zookeeper.escheduler.dead.servers=${zkDeadServers}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.escheduler.masters.*#zookeeper.escheduler.masters=${zkMasters}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.escheduler.workers.*#zookeeper.escheduler.workers=${zkWorkers}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.escheduler.lock.masters.*#zookeeper.escheduler.lock.masters=${mastersLock}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.escheduler.lock.workers.*#zookeeper.escheduler.lock.workers=${workersLock}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.escheduler.lock.failover.masters.*#zookeeper.escheduler.lock.failover.masters=${mastersFailover}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.escheduler.lock.failover.workers.*#zookeeper.escheduler.lock.failover.workers=${workersFailover}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.session.timeout.*#zookeeper.session.timeout=${zkSessionTimeout}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.connection.timeout.*#zookeeper.connection.timeout=${zkConnectionTimeout}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.retry.sleep.*#zookeeper.retry.sleep=${zkRetrySleep}#g" conf/zookeeper.properties |
||||||
|
sed -i ${txt} "s#zookeeper.retry.maxtime.*#zookeeper.retry.maxtime=${zkRetryMaxtime}#g" conf/zookeeper.properties |
||||||
|
|
||||||
|
sed -i ${txt} "s#master.exec.threads.*#master.exec.threads=${masterExecThreads}#g" conf/master.properties |
||||||
|
sed -i ${txt} "s#master.exec.task.number.*#master.exec.task.number=${masterExecTaskNum}#g" conf/master.properties |
||||||
|
sed -i ${txt} "s#master.heartbeat.interval.*#master.heartbeat.interval=${masterHeartbeatInterval}#g" conf/master.properties |
||||||
|
sed -i ${txt} "s#master.task.commit.retryTimes.*#master.task.commit.retryTimes=${masterTaskCommitRetryTimes}#g" conf/master.properties |
||||||
|
sed -i ${txt} "s#master.task.commit.interval.*#master.task.commit.interval=${masterTaskCommitInterval}#g" conf/master.properties |
||||||
|
sed -i ${txt} "s#master.max.cpuload.avg.*#master.max.cpuload.avg=${masterMaxCupLoadAvg}#g" conf/master.properties |
||||||
|
sed -i ${txt} "s#master.reserved.memory.*#master.reserved.memory=${masterReservedMemory}#g" conf/master.properties |
||||||
|
|
||||||
|
|
||||||
|
sed -i ${txt} "s#worker.exec.threads.*#worker.exec.threads=${workerExecThreads}#g" conf/worker.properties |
||||||
|
sed -i ${txt} "s#worker.heartbeat.interval.*#worker.heartbeat.interval=${workerHeartbeatInterval}#g" conf/worker.properties |
||||||
|
sed -i ${txt} "s#worker.fetch.task.num.*#worker.fetch.task.num=${workerFetchTaskNum}#g" conf/worker.properties |
||||||
|
sed -i ${txt} "s#worker.max.cpuload.avg.*#worker.max.cpuload.avg=${workerMaxCupLoadAvg}#g" conf/worker.properties |
||||||
|
sed -i ${txt} "s#worker.reserved.memory.*#worker.reserved.memory=${workerReservedMemory}#g" conf/worker.properties |
||||||
|
|
||||||
|
|
||||||
|
sed -i ${txt} "s#server.port.*#server.port=${apiServerPort}#g" conf/application.properties |
||||||
|
sed -i ${txt} "s#server.session.timeout.*#server.session.timeout=${apiServerSessionTimeout}#g" conf/application.properties |
||||||
|
sed -i ${txt} "s#server.context-path.*#server.context-path=${apiServerContextPath}#g" conf/application.properties |
||||||
|
sed -i ${txt} "s#spring.http.multipart.max-file-size.*#spring.http.multipart.max-file-size=${springMaxFileSize}#g" conf/application.properties |
||||||
|
sed -i ${txt} "s#spring.http.multipart.max-request-size.*#spring.http.multipart.max-request-size=${springMaxRequestSize}#g" conf/application.properties |
||||||
|
sed -i ${txt} "s#server.max-http-post-size.*#server.max-http-post-size=${apiMaxHttpPostSize}#g" conf/application.properties |
||||||
|
|
||||||
|
|
||||||
|
sed -i ${txt} "s#mail.protocol.*#mail.protocol=${mailProtocol}#g" conf/alert.properties |
||||||
|
sed -i ${txt} "s#mail.server.host.*#mail.server.host=${mailServerHost}#g" conf/alert.properties |
||||||
|
sed -i ${txt} "s#mail.server.port.*#mail.server.port=${mailServerPort}#g" conf/alert.properties |
||||||
|
sed -i ${txt} "s#mail.sender.*#mail.sender=${mailSender}#g" conf/alert.properties |
||||||
|
sed -i ${txt} "s#mail.passwd.*#mail.passwd=${mailPassword}#g" conf/alert.properties |
||||||
|
sed -i ${txt} "s#xls.file.path.*#xls.file.path=${xlsFilePath}#g" conf/alert.properties |
||||||
|
|
||||||
|
|
||||||
|
sed -i ${txt} "s#installPath.*#installPath=${installPath}#g" conf/config/install_config.conf |
||||||
|
sed -i ${txt} "s#deployUser.*#deployUser=${deployUser}#g" conf/config/install_config.conf |
||||||
|
sed -i ${txt} "s#ips.*#ips=${ips}#g" conf/config/install_config.conf |
||||||
|
|
||||||
|
|
||||||
|
sed -i ${txt} "s#masters.*#masters=${masters}#g" conf/config/run_config.conf |
||||||
|
sed -i ${txt} "s#workers.*#workers=${workers}#g" conf/config/run_config.conf |
||||||
|
sed -i ${txt} "s#alertServer.*#alertServer=${alertServer}#g" conf/config/run_config.conf |
||||||
|
sed -i ${txt} "s#apiServers.*#apiServers=${apiServers}#g" conf/config/run_config.conf |
@ -0,0 +1,105 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
# execute any pre-init scripts |
||||||
|
for i in /scripts/pre-init.d/*sh |
||||||
|
do |
||||||
|
if [ -e "${i}" ]; then |
||||||
|
echo "[i] pre-init.d - processing $i" |
||||||
|
. "${i}" |
||||||
|
fi |
||||||
|
done |
||||||
|
|
||||||
|
if [ -d "/run/mysqld" ]; then |
||||||
|
echo "[i] mysqld already present, skipping creation" |
||||||
|
chown -R mysql:mysql /run/mysqld |
||||||
|
else |
||||||
|
echo "[i] mysqld not found, creating...." |
||||||
|
mkdir -p /run/mysqld |
||||||
|
chown -R mysql:mysql /run/mysqld |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -d /var/lib/mysql/mysql ]; then |
||||||
|
echo "[i] MySQL directory already present, skipping creation" |
||||||
|
chown -R mysql:mysql /var/lib/mysql |
||||||
|
else |
||||||
|
echo "[i] MySQL data directory not found, creating initial DBs" |
||||||
|
|
||||||
|
chown -R mysql:mysql /var/lib/mysql |
||||||
|
|
||||||
|
mysql_install_db --user=mysql --ldata=/var/lib/mysql > /dev/null |
||||||
|
|
||||||
|
if [ "$MYSQL_ROOT_PASSWORD" = "" ]; then |
||||||
|
MYSQL_ROOT_PASSWORD=`pwgen 16 1` |
||||||
|
echo "[i] MySQL root Password: $MYSQL_ROOT_PASSWORD" |
||||||
|
fi |
||||||
|
|
||||||
|
MYSQL_DATABASE="easyscheduler" |
||||||
|
MYSQL_USER="easyscheduler" |
||||||
|
MYSQL_PASSWORD="easyschedulereasyscheduler" |
||||||
|
|
||||||
|
tfile=`mktemp` |
||||||
|
if [ ! -f "$tfile" ]; then |
||||||
|
return 1 |
||||||
|
fi |
||||||
|
|
||||||
|
cat << EOF > $tfile |
||||||
|
USE mysql; |
||||||
|
FLUSH PRIVILEGES ; |
||||||
|
GRANT ALL ON *.* TO 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD' WITH GRANT OPTION ; |
||||||
|
GRANT ALL ON *.* TO 'root'@'localhost' identified by '$MYSQL_ROOT_PASSWORD' WITH GRANT OPTION ; |
||||||
|
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('${MYSQL_ROOT_PASSWORD}') ; |
||||||
|
DROP DATABASE IF EXISTS test ; |
||||||
|
FLUSH PRIVILEGES ; |
||||||
|
EOF |
||||||
|
|
||||||
|
if [ "$MYSQL_DATABASE" != "" ]; then |
||||||
|
echo "[i] Creating database: $MYSQL_DATABASE" |
||||||
|
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` CHARACTER SET utf8 COLLATE utf8_general_ci;" >> $tfile |
||||||
|
|
||||||
|
if [ "$MYSQL_USER" != "" ]; then |
||||||
|
echo "[i] Creating user: $MYSQL_USER with password $MYSQL_PASSWORD" |
||||||
|
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile |
||||||
|
fi |
||||||
|
fi |
||||||
|
|
||||||
|
/usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < $tfile |
||||||
|
rm -f $tfile |
||||||
|
|
||||||
|
for f in /docker-entrypoint-initdb.d/*; do |
||||||
|
case "$f" in |
||||||
|
*.sql) echo "$0: running $f"; /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;; |
||||||
|
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;; |
||||||
|
*) echo "$0: ignoring or entrypoint initdb empty $f" ;; |
||||||
|
esac |
||||||
|
echo |
||||||
|
done |
||||||
|
|
||||||
|
echo |
||||||
|
echo 'MySQL init process done. Ready for start up.' |
||||||
|
echo |
||||||
|
|
||||||
|
echo "exec /usr/bin/mysqld --user=mysql --console --skip-name-resolve --skip-networking=0" "$@" |
||||||
|
fi |
||||||
|
|
||||||
|
# execute any pre-exec scripts |
||||||
|
for i in /scripts/pre-exec.d/*sh |
||||||
|
do |
||||||
|
if [ -e "${i}" ]; then |
||||||
|
echo "[i] pre-exec.d - processing $i" |
||||||
|
. ${i} |
||||||
|
fi |
||||||
|
done |
||||||
|
|
||||||
|
mysql -ueasyscheduler -peasyschedulereasyscheduler --one-database easyscheduler -h127.0.0.1 < /opt/easyscheduler/sql/escheduler.sql |
||||||
|
mysql -ueasyscheduler -peasyschedulereasyscheduler --one-database easyscheduler -h127.0.0.1 < /opt/easyscheduler/sql/quartz.sql |
||||||
|
source /etc/profile |
||||||
|
zkServer.sh start |
||||||
|
cd /opt/easyscheduler |
||||||
|
rm -rf /etc/nginx/conf.d/default.conf |
||||||
|
sh ./bin/escheduler-daemon.sh start master-server |
||||||
|
sh ./bin/escheduler-daemon.sh start worker-server |
||||||
|
sh ./bin/escheduler-daemon.sh start api-server |
||||||
|
sh ./bin/escheduler-daemon.sh start logger-server |
||||||
|
sh ./bin/escheduler-daemon.sh start alert-server |
||||||
|
nginx -c /etc/nginx/nginx.conf |
||||||
|
exec /usr/bin/mysqld --user=mysql --console --skip-name-resolve --skip-networking=0 $@ |
@ -0,0 +1,30 @@ |
|||||||
|
# The number of milliseconds of each tick |
||||||
|
tickTime=2000 |
||||||
|
# The number of ticks that the initial |
||||||
|
# synchronization phase can take |
||||||
|
initLimit=10 |
||||||
|
# The number of ticks that can pass between |
||||||
|
# sending a request and getting an acknowledgement |
||||||
|
syncLimit=5 |
||||||
|
# the directory where the snapshot is stored. |
||||||
|
# do not use /tmp for storage, /tmp here is just |
||||||
|
# example sakes. |
||||||
|
dataDir=/tmp/zookeeper |
||||||
|
# the port at which the clients will connect |
||||||
|
clientPort=2181 |
||||||
|
# the maximum number of client connections. |
||||||
|
# increase this if you need to handle more clients |
||||||
|
#maxClientCnxns=60 |
||||||
|
# |
||||||
|
# Be sure to read the maintenance section of the |
||||||
|
# administrator guide before turning on autopurge. |
||||||
|
# |
||||||
|
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance |
||||||
|
# |
||||||
|
# The number of snapshots to retain in dataDir |
||||||
|
#autopurge.snapRetainCount=3 |
||||||
|
# Purge task interval in hours |
||||||
|
# Set to "0" to disable auto purge feature |
||||||
|
#autopurge.purgeInterval=1 |
||||||
|
dataDir=/opt/zookeeper/data |
||||||
|
dataLogDir=/opt/zookeeper/logs |
@ -0,0 +1,16 @@ |
|||||||
|
Easy Scheduler Release 1.0.1 |
||||||
|
=== |
||||||
|
Easy Scheduler 1.0.2是1.x系列中的第二个版本。更新内容具体如下: |
||||||
|
|
||||||
|
- 1,outlook TSL 发邮件支持 |
||||||
|
- 2,servlet 和 protobuf jar冲突解决 |
||||||
|
- 3,创建租户同时建立linux用户 |
||||||
|
- 4,重跑时间负数 |
||||||
|
- 5,单机和集群都可以使用install.sh一键部署 |
||||||
|
- 6,队列支持界面添加 |
||||||
|
- 7,escheduler.t_escheduler_queue 增加了create_time和update_time字段 |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,49 @@ |
|||||||
|
Easy Scheduler Release 1.0.2 |
||||||
|
=== |
||||||
|
Easy Scheduler 1.0.2是1.x系列中的第三个版本。此版本增加了调度开放接口、worker分组(指定任务运行的机器组)、任务流程及服务监控以及对oracle、clickhouse等支持,具体如下: |
||||||
|
|
||||||
|
新特性: |
||||||
|
=== |
||||||
|
- [[EasyScheduler-79](https://github.com/analysys/EasyScheduler/issues/79)] 调度通过token方式对外开放接口,可以通过api进行操作 |
||||||
|
- [[EasyScheduler-138](https://github.com/analysys/EasyScheduler/issues/138)] 可以指定任务运行的机器(组) |
||||||
|
- [[EasyScheduler-139](https://github.com/analysys/EasyScheduler/issues/139)] 任务流程监控及Master、Worker、Zookeeper运行状态监控 |
||||||
|
- [[EasyScheduler-140](https://github.com/analysys/EasyScheduler/issues/140)] 工作流定义—增加流程超时报警 |
||||||
|
- [[EasyScheduler-134](https://github.com/analysys/EasyScheduler/issues/134)] 任务类型支持Oracle、CLICKHOUSE、SQLSERVER、IMPALA |
||||||
|
- [[EasyScheduler-136](https://github.com/analysys/EasyScheduler/issues/136)] Sql任务节点可以独立选取抄送邮件用户 |
||||||
|
- [[EasyScheduler-141](https://github.com/analysys/EasyScheduler/issues/141)] 用户管理—用户可以绑定队列,用户队列级别高于租户队列级别,如果用户队列为空,则寻找租户队列 |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
增强: |
||||||
|
=== |
||||||
|
- [[EasyScheduler-154](https://github.com/analysys/EasyScheduler/issues/154)] 租户编码允许纯数字或者下划线这种的编码 |
||||||
|
|
||||||
|
|
||||||
|
修复: |
||||||
|
=== |
||||||
|
- [[EasyScheduler-135](https://github.com/analysys/EasyScheduler/issues/135)] Python任务可以指定python版本 |
||||||
|
|
||||||
|
- [[EasyScheduler-125](https://github.com/analysys/EasyScheduler/issues/125)] 用户账号中手机号无法识别联通最新号码166开头 |
||||||
|
|
||||||
|
- [[EasyScheduler-178](https://github.com/analysys/EasyScheduler/issues/178)] 修复ProcessDao里细微的拼写错误 |
||||||
|
|
||||||
|
- [[EasyScheduler-129](https://github.com/analysys/EasyScheduler/issues/129)] 租户管理中,租户编码带下划线等特殊字符无法通过校验 |
||||||
|
|
||||||
|
|
||||||
|
感谢: |
||||||
|
=== |
||||||
|
最后但最重要的是,没有以下伙伴的贡献就没有新版本的诞生: |
||||||
|
|
||||||
|
Baoqi , chubbyjiang , coreychen , chgxtony, cmdares , datuzi , dingchao, fanguanqun , 风清扬, gaojun416 , googlechorme, hyperknob , hujiang75277381 , huanzui , kinssun, ivivi727 ,jimmy, jiangzhx , kevin5210 , lidongdai , lshmouse , lenboo, lyf198972 , lgcareer , lzy305 , moranrr , millionfor , mazhong8808, programlief, qiaozhanwei , roy110 , swxchappy , sherlock111 , samz406 , swxchappy, qq389401879 , lzy305, vkingnew, William-GuoWei , woniulinux, yyl861, zhangxin1988, yangjiajun2014, yangqinlong, yangjiajun2014, zhzhenqin, zhangluck, zhanghaicheng1, zhuyizhizhi |
||||||
|
|
||||||
|
以及微信群里众多的热心伙伴!在此非常感谢! |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,38 @@ |
|||||||
|
|
||||||
|
# EasyScheduler升级文档 |
||||||
|
|
||||||
|
## 1. 备份上一版本文件和数据库。 |
||||||
|
|
||||||
|
## 2. 停止escheduler所有服务. |
||||||
|
|
||||||
|
`sh ./script/stop_all.sh` |
||||||
|
|
||||||
|
## 3. 下载新版本的安装包 |
||||||
|
|
||||||
|
- [码云下载](https://gitee.com/easyscheduler/EasyScheduler/attach_files), 下载最新版本的前后端安装包(后端简称escheduler-backend、前端简称escheduler-ui) |
||||||
|
- 以下升级操作都需要在新版本的目录进行 |
||||||
|
|
||||||
|
## 4. 数据库升级 |
||||||
|
- 修改conf/dao/data_source.properties中的下列属性 |
||||||
|
|
||||||
|
``` |
||||||
|
spring.datasource.url |
||||||
|
spring.datasource.username |
||||||
|
spring.datasource.password |
||||||
|
``` |
||||||
|
|
||||||
|
- 执行数据库升级脚本 |
||||||
|
|
||||||
|
`sh ./script/upgrade_escheduler.sh` |
||||||
|
|
||||||
|
## 5. 后端服务升级 |
||||||
|
|
||||||
|
- 修改install.sh配置内容,执行升级脚本 |
||||||
|
|
||||||
|
`sh install.sh` |
||||||
|
|
||||||
|
## 6. 前端服务升级 |
||||||
|
- 覆盖上一版本dist目录 |
||||||
|
- 重启nginx服务 |
||||||
|
|
||||||
|
`systemctl restart nginx` |
@ -0,0 +1,48 @@ |
|||||||
|
# 后端开发文档 |
||||||
|
|
||||||
|
## 环境要求 |
||||||
|
|
||||||
|
* [Mysql](http://geek.analysys.cn/topic/124) (5.5+) : 必装 |
||||||
|
* [JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html) (1.8+) : 必装 |
||||||
|
* [ZooKeeper](https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper)(3.4.6+) :必装 |
||||||
|
* [Maven](http://maven.apache.org/download.cgi)(3.3+) :必装 |
||||||
|
|
||||||
|
因EasyScheduler中escheduler-rpc模块使用到Grpc,需要用到Maven编译生成所需要的类 |
||||||
|
对Maven不熟的伙伴请参考: [maven in five minutes](http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html)(3.3+) |
||||||
|
|
||||||
|
http://maven.apache.org/install.html |
||||||
|
|
||||||
|
## 项目编译 |
||||||
|
将EasyScheduler源码下载导入Idea等开发工具后,首先转为Maven项目(右键点击后选择"Add Framework Support") |
||||||
|
|
||||||
|
* 执行编译命令: |
||||||
|
|
||||||
|
``` |
||||||
|
mvn -U clean package assembly:assembly -Dmaven.test.skip=true |
||||||
|
``` |
||||||
|
|
||||||
|
* 查看目录 |
||||||
|
|
||||||
|
正常编译完后,会在当前目录生成 target/escheduler-{version}/ |
||||||
|
|
||||||
|
``` |
||||||
|
bin |
||||||
|
conf |
||||||
|
lib |
||||||
|
script |
||||||
|
sql |
||||||
|
install.sh |
||||||
|
``` |
||||||
|
|
||||||
|
- 说明 |
||||||
|
|
||||||
|
``` |
||||||
|
bin : 基础服务启动脚本 |
||||||
|
conf : 项目配置文件 |
||||||
|
lib : 项目依赖jar包,包括各个模块jar和第三方jar |
||||||
|
script : 集群启动、停止和服务监控启停脚本 |
||||||
|
sql : 项目依赖sql文件 |
||||||
|
install.sh : 一键部署脚本 |
||||||
|
``` |
||||||
|
|
||||||
|
|
@ -0,0 +1,169 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.api.controller; |
||||||
|
|
||||||
|
|
||||||
|
import cn.escheduler.api.enums.Status; |
||||||
|
import cn.escheduler.api.service.AccessTokenService; |
||||||
|
import cn.escheduler.api.service.UsersService; |
||||||
|
import cn.escheduler.api.utils.Constants; |
||||||
|
import cn.escheduler.api.utils.Result; |
||||||
|
import cn.escheduler.dao.model.User; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.http.HttpStatus; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import static cn.escheduler.api.enums.Status.*; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* user controller |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/access-token") |
||||||
|
public class AccessTokenController extends BaseController{ |
||||||
|
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AccessTokenController.class); |
||||||
|
|
||||||
|
|
||||||
|
@Autowired |
||||||
|
private AccessTokenService accessTokenService; |
||||||
|
|
||||||
|
/** |
||||||
|
* create token |
||||||
|
* @param loginUser |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping(value = "/create") |
||||||
|
@ResponseStatus(HttpStatus.CREATED) |
||||||
|
public Result createToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam(value = "userId") int userId, |
||||||
|
@RequestParam(value = "expireTime") String expireTime, |
||||||
|
@RequestParam(value = "token") String token){ |
||||||
|
logger.info("login user {}, create token , userId : {} , token expire time : {} , token : {}", loginUser.getUserName(), |
||||||
|
userId,expireTime,token); |
||||||
|
|
||||||
|
try { |
||||||
|
Map<String, Object> result = accessTokenService.createToken(userId, expireTime, token); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(CREATE_ACCESS_TOKEN_ERROR.getMsg(),e); |
||||||
|
return error(CREATE_ACCESS_TOKEN_ERROR.getCode(), CREATE_ACCESS_TOKEN_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* create token |
||||||
|
* @param loginUser |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping(value = "/generate") |
||||||
|
@ResponseStatus(HttpStatus.CREATED) |
||||||
|
public Result generateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam(value = "userId") int userId, |
||||||
|
@RequestParam(value = "expireTime") String expireTime){ |
||||||
|
logger.info("login user {}, generate token , userId : {} , token expire time : {}",loginUser,userId,expireTime); |
||||||
|
try { |
||||||
|
Map<String, Object> result = accessTokenService.generateToken(userId, expireTime); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(GENERATE_TOKEN_ERROR.getMsg(),e); |
||||||
|
return error(GENERATE_TOKEN_ERROR.getCode(), GENERATE_TOKEN_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query access token list paging |
||||||
|
* |
||||||
|
* @param loginUser |
||||||
|
* @param pageNo |
||||||
|
* @param searchVal |
||||||
|
* @param pageSize |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value="/list-paging") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result queryAccessTokenList(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("pageNo") Integer pageNo, |
||||||
|
@RequestParam(value = "searchVal", required = false) String searchVal, |
||||||
|
@RequestParam("pageSize") Integer pageSize){ |
||||||
|
logger.info("login user {}, list access token paging, pageNo: {}, searchVal: {}, pageSize: {}", |
||||||
|
loginUser.getUserName(),pageNo,searchVal,pageSize); |
||||||
|
try{ |
||||||
|
Map<String, Object> result = checkPageParams(pageNo, pageSize); |
||||||
|
if(result.get(Constants.STATUS) != Status.SUCCESS){ |
||||||
|
return returnDataListPaging(result); |
||||||
|
} |
||||||
|
result = accessTokenService.queryAccessTokenList(loginUser, searchVal, pageNo, pageSize); |
||||||
|
return returnDataListPaging(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(QUERY_ACCESSTOKEN_LIST_PAGING_ERROR.getMsg(),e); |
||||||
|
return error(QUERY_ACCESSTOKEN_LIST_PAGING_ERROR.getCode(),QUERY_ACCESSTOKEN_LIST_PAGING_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete access token by id |
||||||
|
* @param loginUser |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping(value = "/delete") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result delAccessTokenById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam(value = "id") int id) { |
||||||
|
logger.info("login user {}, delete access token, id: {},", loginUser.getUserName(), id); |
||||||
|
try { |
||||||
|
Map<String, Object> result = accessTokenService.delAccessTokenById(loginUser, id); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(DELETE_USER_BY_ID_ERROR.getMsg(),e); |
||||||
|
return error(Status.DELETE_USER_BY_ID_ERROR.getCode(), Status.DELETE_USER_BY_ID_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* update token |
||||||
|
* @param loginUser |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping(value = "/update") |
||||||
|
@ResponseStatus(HttpStatus.CREATED) |
||||||
|
public Result updateToken(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam(value = "id") int id, |
||||||
|
@RequestParam(value = "userId") int userId, |
||||||
|
@RequestParam(value = "expireTime") String expireTime, |
||||||
|
@RequestParam(value = "token") String token){ |
||||||
|
logger.info("login user {}, update token , userId : {} , token expire time : {} , token : {}", loginUser.getUserName(), |
||||||
|
userId,expireTime,token); |
||||||
|
|
||||||
|
try { |
||||||
|
Map<String, Object> result = accessTokenService.updateToken(id,userId, expireTime, token); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(CREATE_ACCESS_TOKEN_ERROR.getMsg(),e); |
||||||
|
return error(CREATE_ACCESS_TOKEN_ERROR.getCode(), CREATE_ACCESS_TOKEN_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,129 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.api.controller; |
||||||
|
|
||||||
|
|
||||||
|
import cn.escheduler.api.service.MonitorService; |
||||||
|
import cn.escheduler.api.service.ServerService; |
||||||
|
import cn.escheduler.api.utils.Constants; |
||||||
|
import cn.escheduler.api.utils.Result; |
||||||
|
import cn.escheduler.dao.model.User; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.http.HttpStatus; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import static cn.escheduler.api.enums.Status.*; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* monitor controller |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/monitor") |
||||||
|
public class MonitorController extends BaseController{ |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(MonitorController.class); |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ServerService serverService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private MonitorService monitorService; |
||||||
|
|
||||||
|
/** |
||||||
|
* master list |
||||||
|
* @param loginUser |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value = "/master/list") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result listMaster(@RequestAttribute(value = Constants.SESSION_USER) User loginUser) { |
||||||
|
logger.info("login user: {}, query all master", loginUser.getUserName()); |
||||||
|
try{ |
||||||
|
logger.info("list master, user:{}", loginUser.getUserName()); |
||||||
|
Map<String, Object> result = serverService.queryMaster(loginUser); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(LIST_MASTERS_ERROR.getMsg(),e); |
||||||
|
return error(LIST_MASTERS_ERROR.getCode(), |
||||||
|
LIST_MASTERS_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* worker list |
||||||
|
* @param loginUser |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value = "/worker/list") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result listWorker(@RequestAttribute(value = Constants.SESSION_USER) User loginUser) { |
||||||
|
logger.info("login user: {}, query all workers", loginUser.getUserName()); |
||||||
|
try{ |
||||||
|
Map<String, Object> result = serverService.queryWorker(loginUser); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(LIST_WORKERS_ERROR.getMsg(),e); |
||||||
|
return error(LIST_WORKERS_ERROR.getCode(), |
||||||
|
LIST_WORKERS_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query database state |
||||||
|
* @param loginUser |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value = "/database") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result queryDatabaseState(@RequestAttribute(value = Constants.SESSION_USER) User loginUser) { |
||||||
|
logger.info("login user: {}, query database state", loginUser.getUserName()); |
||||||
|
try{ |
||||||
|
|
||||||
|
Map<String, Object> result = monitorService.queryDatabaseState(loginUser); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(QUERY_DATABASE_STATE_ERROR.getMsg(),e); |
||||||
|
return error(QUERY_DATABASE_STATE_ERROR.getCode(), |
||||||
|
QUERY_DATABASE_STATE_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query zookeeper state |
||||||
|
* @param loginUser |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value = "/zookeeper/list") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result queryZookeeperState(@RequestAttribute(value = Constants.SESSION_USER) User loginUser) { |
||||||
|
logger.info("login user: {}, query zookeeper state", loginUser.getUserName()); |
||||||
|
try{ |
||||||
|
Map<String, Object> result = monitorService.queryZookeeperState(loginUser); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(QUERY_ZOOKEEPER_STATE_ERROR.getMsg(),e); |
||||||
|
return error(QUERY_ZOOKEEPER_STATE_ERROR.getCode(), |
||||||
|
QUERY_ZOOKEEPER_STATE_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,144 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.api.controller; |
||||||
|
|
||||||
|
|
||||||
|
import cn.escheduler.api.enums.Status; |
||||||
|
import cn.escheduler.api.service.WorkerGroupService; |
||||||
|
import cn.escheduler.api.utils.Constants; |
||||||
|
import cn.escheduler.api.utils.Result; |
||||||
|
import cn.escheduler.dao.model.User; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.http.HttpStatus; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group controller |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/worker-group") |
||||||
|
public class WorkerGroupController extends BaseController{ |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(WorkerGroupController.class); |
||||||
|
|
||||||
|
|
||||||
|
@Autowired |
||||||
|
WorkerGroupService workerGroupService; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* create or update a worker group |
||||||
|
* @param loginUser |
||||||
|
* @param id |
||||||
|
* @param name |
||||||
|
* @param ipList |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping(value = "/save") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result saveWorkerGroup(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam(value = "id", required = false, defaultValue = "0") int id, |
||||||
|
@RequestParam(value = "name") String name, |
||||||
|
@RequestParam(value = "ipList") String ipList |
||||||
|
) { |
||||||
|
logger.info("save worker group: login user {}, id:{}, name: {}, ipList: {} ", |
||||||
|
loginUser.getUserName(), id, name, ipList); |
||||||
|
|
||||||
|
try { |
||||||
|
Map<String, Object> result = workerGroupService.saveWorkerGroup(id, name, ipList); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(Status.SAVE_ERROR.getMsg(),e); |
||||||
|
return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker groups paging |
||||||
|
* @param loginUser |
||||||
|
* @param pageNo |
||||||
|
* @param searchVal |
||||||
|
* @param pageSize |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value = "/list-paging") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result queryAllWorkerGroupsPaging(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("pageNo") Integer pageNo, |
||||||
|
@RequestParam(value = "searchVal", required = false) String searchVal, |
||||||
|
@RequestParam("pageSize") Integer pageSize |
||||||
|
) { |
||||||
|
logger.info("query all worker group paging: login user {}, pageNo:{}, pageSize:{}, searchVal:{}", |
||||||
|
loginUser.getUserName() , pageNo, pageSize, searchVal); |
||||||
|
|
||||||
|
try { |
||||||
|
Map<String, Object> result = workerGroupService.queryAllGroupPaging(pageNo, pageSize, searchVal); |
||||||
|
return returnDataListPaging(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(Status.SAVE_ERROR.getMsg(),e); |
||||||
|
return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query all worker groups |
||||||
|
* @param loginUser |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value = "/all-groups") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result queryAllWorkerGroups(@RequestAttribute(value = Constants.SESSION_USER) User loginUser |
||||||
|
) { |
||||||
|
logger.info("query all worker group: login user {}", |
||||||
|
loginUser.getUserName() ); |
||||||
|
|
||||||
|
try { |
||||||
|
Map<String, Object> result = workerGroupService.queryAllGroup(); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(Status.SAVE_ERROR.getMsg(),e); |
||||||
|
return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete worker group by id |
||||||
|
* @param loginUser |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping(value = "/delete-by-id") |
||||||
|
@ResponseStatus(HttpStatus.OK) |
||||||
|
public Result deleteById(@RequestAttribute(value = Constants.SESSION_USER) User loginUser, |
||||||
|
@RequestParam("id") Integer id |
||||||
|
) { |
||||||
|
logger.info("delete worker group: login user {}, id:{} ", |
||||||
|
loginUser.getUserName() , id); |
||||||
|
|
||||||
|
try { |
||||||
|
Map<String, Object> result = workerGroupService.deleteWorkerGroupById(id); |
||||||
|
return returnDataList(result); |
||||||
|
}catch (Exception e){ |
||||||
|
logger.error(Status.SAVE_ERROR.getMsg(),e); |
||||||
|
return error(Status.SAVE_ERROR.getCode(), Status.SAVE_ERROR.getMsg()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.api.dto; |
||||||
|
|
||||||
|
import cn.escheduler.common.enums.ExecutionStatus; |
||||||
|
|
||||||
|
/** |
||||||
|
* command state count |
||||||
|
*/ |
||||||
|
public class CommandStateCount { |
||||||
|
|
||||||
|
private int errorCount; |
||||||
|
private int normalCount; |
||||||
|
private ExecutionStatus commandState; |
||||||
|
|
||||||
|
public CommandStateCount(){} |
||||||
|
public CommandStateCount(int errorCount, int normalCount, ExecutionStatus commandState) { |
||||||
|
this.errorCount = errorCount; |
||||||
|
this.normalCount = normalCount; |
||||||
|
this.commandState = commandState; |
||||||
|
} |
||||||
|
|
||||||
|
public int getErrorCount() { |
||||||
|
return errorCount; |
||||||
|
} |
||||||
|
|
||||||
|
public void setErrorCount(int errorCount) { |
||||||
|
this.errorCount = errorCount; |
||||||
|
} |
||||||
|
|
||||||
|
public int getNormalCount() { |
||||||
|
return normalCount; |
||||||
|
} |
||||||
|
|
||||||
|
public void setNormalCount(int normalCount) { |
||||||
|
this.normalCount = normalCount; |
||||||
|
} |
||||||
|
|
||||||
|
public ExecutionStatus getCommandState() { |
||||||
|
return commandState; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCommandState(ExecutionStatus commandState) { |
||||||
|
this.commandState = commandState; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,185 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.api.service; |
||||||
|
|
||||||
|
import cn.escheduler.api.enums.Status; |
||||||
|
import cn.escheduler.api.utils.CheckUtils; |
||||||
|
import cn.escheduler.api.utils.Constants; |
||||||
|
import cn.escheduler.api.utils.PageInfo; |
||||||
|
import cn.escheduler.api.utils.Result; |
||||||
|
import cn.escheduler.common.enums.UserType; |
||||||
|
import cn.escheduler.common.utils.*; |
||||||
|
import cn.escheduler.dao.mapper.*; |
||||||
|
import cn.escheduler.dao.model.*; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* user service |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class AccessTokenService extends BaseService { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AccessTokenService.class); |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private AccessTokenMapper accessTokenMapper; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* query access token list |
||||||
|
* |
||||||
|
* @param loginUser |
||||||
|
* @param searchVal |
||||||
|
* @param pageNo |
||||||
|
* @param pageSize |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String, Object> queryAccessTokenList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { |
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
|
||||||
|
PageInfo<AccessToken> pageInfo = new PageInfo<>(pageNo, pageSize); |
||||||
|
Integer count; |
||||||
|
List<AccessToken> accessTokenList; |
||||||
|
if (loginUser.getUserType() == UserType.ADMIN_USER){ |
||||||
|
count = accessTokenMapper.countAccessTokenPaging(0,searchVal); |
||||||
|
accessTokenList = accessTokenMapper.queryAccessTokenPaging(0,searchVal, pageInfo.getStart(), pageSize); |
||||||
|
}else { |
||||||
|
count = accessTokenMapper.countAccessTokenPaging(loginUser.getId(),searchVal); |
||||||
|
accessTokenList = accessTokenMapper.queryAccessTokenPaging(loginUser.getId(),searchVal, pageInfo.getStart(), pageSize); |
||||||
|
} |
||||||
|
|
||||||
|
pageInfo.setTotalCount(count); |
||||||
|
pageInfo.setLists(accessTokenList); |
||||||
|
result.put(Constants.DATA_LIST, pageInfo); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* check |
||||||
|
* |
||||||
|
* @param result |
||||||
|
* @param bool |
||||||
|
* @param userNoOperationPerm |
||||||
|
* @param status |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private boolean check(Map<String, Object> result, boolean bool, Status userNoOperationPerm, String status) { |
||||||
|
//only admin can operate
|
||||||
|
if (bool) { |
||||||
|
result.put(Constants.STATUS, userNoOperationPerm); |
||||||
|
result.put(status, userNoOperationPerm.getMsg()); |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* create token |
||||||
|
* |
||||||
|
* @param userId |
||||||
|
* @param expireTime |
||||||
|
* @param token |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String, Object> createToken(int userId, String expireTime, String token) { |
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
|
||||||
|
AccessToken accessToken = new AccessToken(); |
||||||
|
accessToken.setUserId(userId); |
||||||
|
accessToken.setExpireTime(DateUtils.stringToDate(expireTime)); |
||||||
|
accessToken.setToken(token); |
||||||
|
accessToken.setCreateTime(new Date()); |
||||||
|
accessToken.setUpdateTime(new Date()); |
||||||
|
|
||||||
|
// insert
|
||||||
|
int insert = accessTokenMapper.insert(accessToken); |
||||||
|
|
||||||
|
if (insert > 0) { |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
} else { |
||||||
|
putMsg(result, Status.CREATE_ALERT_GROUP_ERROR); |
||||||
|
} |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* generate token |
||||||
|
* @param userId |
||||||
|
* @param expireTime |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String, Object> generateToken(int userId, String expireTime) { |
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
String token = EncryptionUtils.getMd5(userId + expireTime + String.valueOf(System.currentTimeMillis())); |
||||||
|
result.put(Constants.DATA_LIST, token); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete access token |
||||||
|
* @param loginUser |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String, Object> delAccessTokenById(User loginUser, int id) { |
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
//only admin can operate
|
||||||
|
if (!isAdmin(loginUser)) { |
||||||
|
putMsg(result, Status.USER_NOT_EXIST, id); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
accessTokenMapper.delete(id); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* update token by id |
||||||
|
* @param id |
||||||
|
* @param userId |
||||||
|
* @param expireTime |
||||||
|
* @param token |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String, Object> updateToken(int id,int userId, String expireTime, String token) { |
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
AccessToken accessToken = new AccessToken(); |
||||||
|
accessToken.setId(id); |
||||||
|
accessToken.setUserId(userId); |
||||||
|
accessToken.setExpireTime(DateUtils.stringToDate(expireTime)); |
||||||
|
accessToken.setToken(token); |
||||||
|
accessToken.setUpdateTime(new Date()); |
||||||
|
|
||||||
|
accessTokenMapper.update(accessToken); |
||||||
|
|
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,72 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.api.service; |
||||||
|
|
||||||
|
import cn.escheduler.api.enums.Status; |
||||||
|
import cn.escheduler.api.utils.Constants; |
||||||
|
import cn.escheduler.api.utils.ZookeeperMonitorUtils; |
||||||
|
import cn.escheduler.dao.MonitorDBDao; |
||||||
|
import cn.escheduler.dao.model.MonitorRecord; |
||||||
|
import cn.escheduler.dao.model.User; |
||||||
|
import cn.escheduler.dao.model.ZookeeperRecord; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* monitor service |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class MonitorService extends BaseService{ |
||||||
|
|
||||||
|
/** |
||||||
|
* query database state |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String,Object> queryDatabaseState(User loginUser) { |
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
|
||||||
|
List<MonitorRecord> monitorRecordList = MonitorDBDao.queryDatabaseState(); |
||||||
|
|
||||||
|
result.put(Constants.DATA_LIST, monitorRecordList); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
|
||||||
|
return result; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* query zookeeper state |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String,Object> queryZookeeperState(User loginUser) { |
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
|
||||||
|
List<ZookeeperRecord> zookeeperRecordList = ZookeeperMonitorUtils.zookeeperInfoList(); |
||||||
|
|
||||||
|
result.put(Constants.DATA_LIST, zookeeperRecordList); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
|
||||||
|
return result; |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,155 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.api.service; |
||||||
|
|
||||||
|
import cn.escheduler.api.enums.Status; |
||||||
|
import cn.escheduler.api.utils.Constants; |
||||||
|
import cn.escheduler.api.utils.PageInfo; |
||||||
|
import cn.escheduler.dao.mapper.WorkerGroupMapper; |
||||||
|
import cn.escheduler.dao.model.User; |
||||||
|
import cn.escheduler.dao.model.WorkerGroup; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* work group service |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class WorkerGroupService extends BaseService { |
||||||
|
|
||||||
|
|
||||||
|
@Autowired |
||||||
|
WorkerGroupMapper workerGroupMapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* create or update a worker group |
||||||
|
* @param id |
||||||
|
* @param name |
||||||
|
* @param ipList |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String, Object> saveWorkerGroup(int id, String name, String ipList){ |
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
|
||||||
|
if(StringUtils.isEmpty(name)){ |
||||||
|
putMsg(result, Status.NAME_NULL); |
||||||
|
return result; |
||||||
|
} |
||||||
|
Date now = new Date(); |
||||||
|
WorkerGroup workerGroup = null; |
||||||
|
if(id != 0){ |
||||||
|
workerGroup = workerGroupMapper.queryById(id); |
||||||
|
}else{ |
||||||
|
workerGroup = new WorkerGroup(); |
||||||
|
workerGroup.setCreateTime(now); |
||||||
|
} |
||||||
|
workerGroup.setName(name); |
||||||
|
workerGroup.setIpList(ipList); |
||||||
|
workerGroup.setUpdateTime(now); |
||||||
|
|
||||||
|
if(checkWorkerGroupNameExists(workerGroup)){ |
||||||
|
putMsg(result, Status.NAME_EXIST, workerGroup.getName()); |
||||||
|
return result; |
||||||
|
} |
||||||
|
if(workerGroup.getId() != 0 ){ |
||||||
|
workerGroupMapper.update(workerGroup); |
||||||
|
}else{ |
||||||
|
workerGroupMapper.insert(workerGroup); |
||||||
|
} |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* check worker group name exists |
||||||
|
* @param workerGroup |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private boolean checkWorkerGroupNameExists(WorkerGroup workerGroup) { |
||||||
|
|
||||||
|
List<WorkerGroup> workerGroupList = workerGroupMapper.queryWorkerGroupByName(workerGroup.getName()); |
||||||
|
|
||||||
|
if(workerGroupList.size() > 0 ){ |
||||||
|
// new group has same name..
|
||||||
|
if(workerGroup.getId() == 0){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
// update group...
|
||||||
|
for(WorkerGroup group : workerGroupList){ |
||||||
|
if(group.getId() != workerGroup.getId()){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group paging |
||||||
|
* @param pageNo |
||||||
|
* @param pageSize |
||||||
|
* @param searchVal |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String,Object> queryAllGroupPaging(Integer pageNo, Integer pageSize, String searchVal) { |
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
int count = workerGroupMapper.countPaging(searchVal); |
||||||
|
|
||||||
|
|
||||||
|
PageInfo<WorkerGroup> pageInfo = new PageInfo<>(pageNo, pageSize); |
||||||
|
List<WorkerGroup> workerGroupList = workerGroupMapper.queryListPaging(pageInfo.getStart(), pageSize, searchVal); |
||||||
|
pageInfo.setTotalCount(count); |
||||||
|
pageInfo.setLists(workerGroupList); |
||||||
|
result.put(Constants.DATA_LIST, pageInfo); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete worker group by id |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String,Object> deleteWorkerGroupById(Integer id) { |
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
|
||||||
|
int delete = workerGroupMapper.deleteById(id); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query all worker group |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public Map<String,Object> queryAllGroup() { |
||||||
|
Map<String, Object> result = new HashMap<>(5); |
||||||
|
List<WorkerGroup> workerGroupList = workerGroupMapper.queryAllWorkerGroup(); |
||||||
|
result.put(Constants.DATA_LIST, workerGroupList); |
||||||
|
putMsg(result, Status.SUCCESS); |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,211 @@ |
|||||||
|
package cn.escheduler.api.utils; |
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.apache.zookeeper.client.FourLetterWordMain; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.Scanner; |
||||||
|
|
||||||
|
/** |
||||||
|
* zookeeper状态监控:4字口诀 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public class ZooKeeperState { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ZooKeeperState.class); |
||||||
|
|
||||||
|
private final String host; |
||||||
|
private final int port; |
||||||
|
|
||||||
|
private int minLatency = -1, avgLatency = -1, maxLatency = -1; |
||||||
|
private long received = -1; |
||||||
|
private long sent = -1; |
||||||
|
private int outStanding = -1; |
||||||
|
private long zxid = -1; |
||||||
|
private String mode = null; |
||||||
|
private int nodeCount = -1; |
||||||
|
private int watches = -1; |
||||||
|
private int connections = -1; |
||||||
|
|
||||||
|
public ZooKeeperState(String connectionString) { |
||||||
|
String host = connectionString.substring(0, |
||||||
|
connectionString.indexOf(':')); |
||||||
|
int port = Integer.parseInt(connectionString.substring(connectionString |
||||||
|
.indexOf(':') + 1)); |
||||||
|
this.host = host; |
||||||
|
this.port = port; |
||||||
|
} |
||||||
|
|
||||||
|
public void getZookeeperInfo() { |
||||||
|
String content = cmd("srvr"); |
||||||
|
if (StringUtils.isNotBlank(content)) { |
||||||
|
Scanner scannerForStat = new Scanner(content); |
||||||
|
while (scannerForStat.hasNext()) { |
||||||
|
String line = scannerForStat.nextLine(); |
||||||
|
if (line.startsWith("Latency min/avg/max:")) { |
||||||
|
String[] latencys = getStringValueFromLine(line).split("/"); |
||||||
|
minLatency = Integer.parseInt(latencys[0]); |
||||||
|
avgLatency = Integer.parseInt(latencys[1]); |
||||||
|
maxLatency = Integer.parseInt(latencys[2]); |
||||||
|
} else if (line.startsWith("Received:")) { |
||||||
|
received = Long.parseLong(getStringValueFromLine(line)); |
||||||
|
} else if (line.startsWith("Sent:")) { |
||||||
|
sent = Long.parseLong(getStringValueFromLine(line)); |
||||||
|
} else if (line.startsWith("Outstanding:")) { |
||||||
|
outStanding = Integer.parseInt(getStringValueFromLine(line)); |
||||||
|
} else if (line.startsWith("Zxid:")) { |
||||||
|
zxid = Long.parseLong(getStringValueFromLine(line).substring(2), 16); |
||||||
|
} else if (line.startsWith("Mode:")) { |
||||||
|
mode = getStringValueFromLine(line); |
||||||
|
} else if (line.startsWith("Node count:")) { |
||||||
|
nodeCount = Integer.parseInt(getStringValueFromLine(line)); |
||||||
|
} |
||||||
|
} |
||||||
|
scannerForStat.close(); |
||||||
|
} |
||||||
|
|
||||||
|
String wchsText = cmd("wchs"); |
||||||
|
if (StringUtils.isNotBlank(wchsText)) { |
||||||
|
Scanner scannerForWchs = new Scanner(wchsText); |
||||||
|
while (scannerForWchs.hasNext()) { |
||||||
|
String line = scannerForWchs.nextLine(); |
||||||
|
if (line.startsWith("Total watches:")) { |
||||||
|
watches = Integer.parseInt(getStringValueFromLine(line)); |
||||||
|
} |
||||||
|
} |
||||||
|
scannerForWchs.close(); |
||||||
|
} |
||||||
|
|
||||||
|
String consText = cmd("cons"); |
||||||
|
if (StringUtils.isNotBlank(consText)) { |
||||||
|
Scanner scannerForCons = new Scanner(consText); |
||||||
|
if (StringUtils.isNotBlank(consText)) { |
||||||
|
connections = 0; |
||||||
|
} |
||||||
|
while (scannerForCons.hasNext()) { |
||||||
|
@SuppressWarnings("unused") |
||||||
|
String line = scannerForCons.nextLine(); |
||||||
|
++connections; |
||||||
|
} |
||||||
|
scannerForCons.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public boolean ruok() { |
||||||
|
return "imok\n".equals(cmd("ruok")); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private String getStringValueFromLine(String line) { |
||||||
|
return line.substring(line.indexOf(":") + 1, line.length()).replaceAll( |
||||||
|
" ", "").trim(); |
||||||
|
} |
||||||
|
|
||||||
|
private class SendThread extends Thread { |
||||||
|
private String cmd; |
||||||
|
|
||||||
|
public String ret = ""; |
||||||
|
|
||||||
|
public SendThread(String cmd) { |
||||||
|
this.cmd = cmd; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
try { |
||||||
|
ret = FourLetterWordMain.send4LetterWord(host, port, cmd); |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private String cmd(String cmd) { |
||||||
|
final int waitTimeout = 5; |
||||||
|
SendThread sendThread = new SendThread(cmd); |
||||||
|
sendThread.setName("FourLetterCmd:" + cmd); |
||||||
|
sendThread.start(); |
||||||
|
try { |
||||||
|
sendThread.join(waitTimeout * 1000); |
||||||
|
return sendThread.ret; |
||||||
|
} catch (InterruptedException e) { |
||||||
|
logger.error("send " + cmd + " to server " + host + ":" + port + " failed!", e); |
||||||
|
} |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
public Logger getLogger() { |
||||||
|
return logger; |
||||||
|
} |
||||||
|
|
||||||
|
public String getHost() { |
||||||
|
return host; |
||||||
|
} |
||||||
|
|
||||||
|
public int getPort() { |
||||||
|
return port; |
||||||
|
} |
||||||
|
|
||||||
|
public int getMinLatency() { |
||||||
|
return minLatency; |
||||||
|
} |
||||||
|
|
||||||
|
public int getAvgLatency() { |
||||||
|
return avgLatency; |
||||||
|
} |
||||||
|
|
||||||
|
public int getMaxLatency() { |
||||||
|
return maxLatency; |
||||||
|
} |
||||||
|
|
||||||
|
public long getReceived() { |
||||||
|
return received; |
||||||
|
} |
||||||
|
|
||||||
|
public long getSent() { |
||||||
|
return sent; |
||||||
|
} |
||||||
|
|
||||||
|
public int getOutStanding() { |
||||||
|
return outStanding; |
||||||
|
} |
||||||
|
|
||||||
|
public long getZxid() { |
||||||
|
return zxid; |
||||||
|
} |
||||||
|
|
||||||
|
public String getMode() { |
||||||
|
return mode; |
||||||
|
} |
||||||
|
|
||||||
|
public int getNodeCount() { |
||||||
|
return nodeCount; |
||||||
|
} |
||||||
|
|
||||||
|
public int getWatches() { |
||||||
|
return watches; |
||||||
|
} |
||||||
|
|
||||||
|
public int getConnections() { |
||||||
|
return connections; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "ZooKeeperState [host=" + host + ", port=" + port |
||||||
|
+ ", minLatency=" + minLatency + ", avgLatency=" + avgLatency |
||||||
|
+ ", maxLatency=" + maxLatency + ", received=" + received |
||||||
|
+ ", sent=" + sent + ", outStanding=" + outStanding + ", zxid=" |
||||||
|
+ zxid + ", mode=" + mode + ", nodeCount=" + nodeCount |
||||||
|
+ ", watches=" + watches + ", connections=" |
||||||
|
+ connections + "]"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,72 @@ |
|||||||
|
package cn.escheduler.api.utils; |
||||||
|
|
||||||
|
import cn.escheduler.common.zk.AbstractZKClient; |
||||||
|
import cn.escheduler.dao.model.ZookeeperRecord; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* monitor zookeeper info |
||||||
|
*/ |
||||||
|
public class ZookeeperMonitorUtils { |
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ZookeeperMonitorUtils.class); |
||||||
|
private static final String zookeeperList = AbstractZKClient.getZookeeperQuorum(); |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @return zookeeper info list |
||||||
|
*/ |
||||||
|
public static List<ZookeeperRecord> zookeeperInfoList(){ |
||||||
|
String zookeeperServers = zookeeperList.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); |
||||||
|
try{ |
||||||
|
return zookeeperInfoList(zookeeperServers); |
||||||
|
}catch(Exception e){ |
||||||
|
LOG.error(e.getMessage(),e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private static List<ZookeeperRecord> zookeeperInfoList(String zookeeperServers) { |
||||||
|
|
||||||
|
List<ZookeeperRecord> list = new ArrayList<>(5); |
||||||
|
|
||||||
|
if(StringUtils.isNotBlank(zookeeperServers)){ |
||||||
|
String[] zookeeperServersArray = zookeeperServers.split(","); |
||||||
|
|
||||||
|
for (String zookeeperServer : zookeeperServersArray) { |
||||||
|
ZooKeeperState state = new ZooKeeperState(zookeeperServer); |
||||||
|
boolean ok = state.ruok(); |
||||||
|
if(ok){ |
||||||
|
state.getZookeeperInfo(); |
||||||
|
} |
||||||
|
|
||||||
|
String hostName = zookeeperServer; |
||||||
|
int connections = state.getConnections(); |
||||||
|
int watches = state.getWatches(); |
||||||
|
long sent = state.getSent(); |
||||||
|
long received = state.getReceived(); |
||||||
|
String mode = state.getMode(); |
||||||
|
int minLatency = state.getMinLatency(); |
||||||
|
int avgLatency = state.getAvgLatency(); |
||||||
|
int maxLatency = state.getMaxLatency(); |
||||||
|
int nodeCount = state.getNodeCount(); |
||||||
|
int status = ok ? 1 : 0; |
||||||
|
Date date = new Date(); |
||||||
|
|
||||||
|
ZookeeperRecord zookeeperRecord = new ZookeeperRecord(hostName,connections,watches,sent,received,mode,minLatency,avgLatency,maxLatency,nodeCount,status,date); |
||||||
|
list.add(zookeeperRecord); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return list; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,160 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.api; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.net.URI; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.UUID; |
||||||
|
|
||||||
|
import cn.escheduler.common.utils.EncryptionUtils; |
||||||
|
import org.apache.commons.io.FileUtils; |
||||||
|
import org.apache.http.NameValuePair; |
||||||
|
import org.apache.http.client.entity.UrlEncodedFormEntity; |
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse; |
||||||
|
import org.apache.http.client.methods.HttpGet; |
||||||
|
import org.apache.http.client.methods.HttpPost; |
||||||
|
import org.apache.http.client.utils.URIBuilder; |
||||||
|
import org.apache.http.impl.client.CloseableHttpClient; |
||||||
|
import org.apache.http.impl.client.HttpClients; |
||||||
|
import org.apache.http.message.BasicNameValuePair; |
||||||
|
import org.apache.http.util.EntityUtils; |
||||||
|
import org.junit.Test; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
public class HttpClientTest { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(HttpClientTest.class); |
||||||
|
|
||||||
|
@Test |
||||||
|
public void doPOSTParam()throws Exception{ |
||||||
|
// create HttpClient
|
||||||
|
CloseableHttpClient httpclient = HttpClients.createDefault(); |
||||||
|
|
||||||
|
// create http post request
|
||||||
|
HttpPost httpPost = new HttpPost("http://127.0.0.1:12345/escheduler/projects/create"); |
||||||
|
httpPost.setHeader("token", "123"); |
||||||
|
// set parameters
|
||||||
|
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); |
||||||
|
parameters.add(new BasicNameValuePair("projectName", "qzw")); |
||||||
|
parameters.add(new BasicNameValuePair("desc", "qzw")); |
||||||
|
|
||||||
|
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(parameters); |
||||||
|
httpPost.setEntity(formEntity); |
||||||
|
|
||||||
|
|
||||||
|
CloseableHttpResponse response = null; |
||||||
|
try { |
||||||
|
// execute
|
||||||
|
response = httpclient.execute(httpPost); |
||||||
|
// eponse status code 200
|
||||||
|
if (response.getStatusLine().getStatusCode() == 200) { |
||||||
|
String content = EntityUtils.toString(response.getEntity(), "UTF-8"); |
||||||
|
System.out.println(content); |
||||||
|
} |
||||||
|
} finally { |
||||||
|
if (response != null) { |
||||||
|
response.close(); |
||||||
|
} |
||||||
|
httpclient.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* do get param path variables chinese |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void doGETParamPathVariableAndChinese()throws Exception{ |
||||||
|
// create HttpClient
|
||||||
|
CloseableHttpClient httpclient = HttpClients.createDefault(); |
||||||
|
|
||||||
|
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); |
||||||
|
// parameters.add(new BasicNameValuePair("pageSize", "10"));
|
||||||
|
|
||||||
|
// define the parameters of the request
|
||||||
|
URI uri = new URIBuilder("http://192.168.220.247:12345/escheduler/projects/%E5%85%A8%E9%83%A8%E6%B5%81%E7%A8%8B%E6%B5%8B%E8%AF%95/process/list") |
||||||
|
.build(); |
||||||
|
|
||||||
|
// create http GET request
|
||||||
|
HttpGet httpGet = new HttpGet(uri); |
||||||
|
httpGet.setHeader("token","10f5625a2a1cbf9aa710653796c5d764"); |
||||||
|
//response object
|
||||||
|
CloseableHttpResponse response = null; |
||||||
|
try { |
||||||
|
// execute http get request
|
||||||
|
response = httpclient.execute(httpGet); |
||||||
|
// reponse status code 200
|
||||||
|
if (response.getStatusLine().getStatusCode() == 200) { |
||||||
|
String content = EntityUtils.toString(response.getEntity(), "UTF-8"); |
||||||
|
logger.info("start--------------->"); |
||||||
|
logger.info(content); |
||||||
|
logger.info("end----------------->"); |
||||||
|
} |
||||||
|
} finally { |
||||||
|
if (response != null) { |
||||||
|
response.close(); |
||||||
|
} |
||||||
|
httpclient.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* do get param |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
@Test |
||||||
|
public void doGETParam()throws Exception{ |
||||||
|
// create HttpClient
|
||||||
|
CloseableHttpClient httpclient = HttpClients.createDefault(); |
||||||
|
|
||||||
|
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); |
||||||
|
parameters.add(new BasicNameValuePair("startDate", "2018-04-22 19:30:08")); |
||||||
|
parameters.add(new BasicNameValuePair("endDate", "2028-04-22 19:30:08")); |
||||||
|
parameters.add(new BasicNameValuePair("projectId", "0")); |
||||||
|
|
||||||
|
// define the parameters of the request
|
||||||
|
URI uri = new URIBuilder("http://192.168.220.247:12345/escheduler/projects/analysis/queue-count") |
||||||
|
.setParameters(parameters) |
||||||
|
.build(); |
||||||
|
|
||||||
|
// create http GET request
|
||||||
|
HttpGet httpGet = new HttpGet(uri); |
||||||
|
httpGet.setHeader("token","2aef24c052c212fab9eec78848c2258b"); |
||||||
|
//response object
|
||||||
|
CloseableHttpResponse response = null; |
||||||
|
try { |
||||||
|
// execute http get request
|
||||||
|
response = httpclient.execute(httpGet); |
||||||
|
// reponse status code 200
|
||||||
|
if (response.getStatusLine().getStatusCode() == 200) { |
||||||
|
String content = EntityUtils.toString(response.getEntity(), "UTF-8"); |
||||||
|
logger.info("start--------------->"); |
||||||
|
logger.info(content); |
||||||
|
logger.info("end----------------->"); |
||||||
|
} |
||||||
|
} finally { |
||||||
|
if (response != null) { |
||||||
|
response.close(); |
||||||
|
} |
||||||
|
httpclient.close(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,105 @@ |
|||||||
|
package cn.escheduler.api.controller; |
||||||
|
|
||||||
|
import cn.escheduler.api.enums.Status; |
||||||
|
import cn.escheduler.api.utils.Result; |
||||||
|
import cn.escheduler.common.enums.ResourceType; |
||||||
|
import cn.escheduler.common.utils.JSONUtils; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import org.junit.Assert; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||||
|
import org.springframework.http.MediaType; |
||||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||||
|
import org.springframework.test.web.servlet.MockMvc; |
||||||
|
import org.springframework.test.web.servlet.MvcResult; |
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders; |
||||||
|
import org.springframework.web.context.WebApplicationContext; |
||||||
|
|
||||||
|
import static org.junit.Assert.*; |
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
||||||
|
|
||||||
|
@RunWith(SpringRunner.class) |
||||||
|
@SpringBootTest |
||||||
|
public class MonitorControllerTest { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(MonitorControllerTest.class); |
||||||
|
public static final String SESSION_ID = "sessionId"; |
||||||
|
public static String SESSION_ID_VALUE; |
||||||
|
|
||||||
|
private MockMvc mockMvc; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private WebApplicationContext webApplicationContext; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() { |
||||||
|
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); |
||||||
|
SESSION_ID_VALUE = "bad76fc4-2eb4-4aae-b32b-d650e4beb6af"; |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void listMaster() throws Exception { |
||||||
|
|
||||||
|
MvcResult mvcResult = mockMvc.perform(get("/monitor/master/list") |
||||||
|
.header(SESSION_ID, SESSION_ID_VALUE) |
||||||
|
/* .param("type", ResourceType.FILE.name())*/ ) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
result.getCode().equals(Status.SUCCESS.getCode()); |
||||||
|
|
||||||
|
|
||||||
|
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString()); |
||||||
|
|
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); |
||||||
|
logger.info(mvcResult.getResponse().getContentAsString()); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Test |
||||||
|
public void queryDatabaseState() throws Exception { |
||||||
|
MvcResult mvcResult = mockMvc.perform(get("/monitor/database") |
||||||
|
.header(SESSION_ID, SESSION_ID_VALUE) |
||||||
|
/* .param("type", ResourceType.FILE.name())*/ ) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
result.getCode().equals(Status.SUCCESS.getCode()); |
||||||
|
|
||||||
|
|
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); |
||||||
|
logger.info(mvcResult.getResponse().getContentAsString()); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Test |
||||||
|
public void queryZookeeperState() throws Exception { |
||||||
|
MvcResult mvcResult = mockMvc.perform(get("/monitor/zookeeper/list") |
||||||
|
.header(SESSION_ID, SESSION_ID_VALUE) |
||||||
|
/* .param("type", ResourceType.FILE.name())*/ ) |
||||||
|
.andExpect(status().isOk()) |
||||||
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) |
||||||
|
.andReturn(); |
||||||
|
|
||||||
|
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); |
||||||
|
result.getCode().equals(Status.SUCCESS.getCode()); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); |
||||||
|
logger.info(mvcResult.getResponse().getContentAsString()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,104 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.common.utils; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.sql.*; |
||||||
|
|
||||||
|
public class MysqlUtil { |
||||||
|
|
||||||
|
public static final Logger logger = LoggerFactory.getLogger(MysqlUtil.class); |
||||||
|
|
||||||
|
private static MysqlUtil instance; |
||||||
|
|
||||||
|
MysqlUtil() { |
||||||
|
} |
||||||
|
|
||||||
|
public static MysqlUtil getInstance() { |
||||||
|
if (null == instance) { |
||||||
|
syncInit(); |
||||||
|
} |
||||||
|
return instance; |
||||||
|
} |
||||||
|
|
||||||
|
private static synchronized void syncInit() { |
||||||
|
if (instance == null) { |
||||||
|
instance = new MysqlUtil(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void release(ResultSet rs, Statement stmt, Connection conn) { |
||||||
|
try { |
||||||
|
if (rs != null) { |
||||||
|
rs.close(); |
||||||
|
rs = null; |
||||||
|
} |
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
if (stmt != null) { |
||||||
|
stmt.close(); |
||||||
|
stmt = null; |
||||||
|
} |
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
if (conn != null) { |
||||||
|
conn.close(); |
||||||
|
conn = null; |
||||||
|
} |
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static void realeaseResource(ResultSet rs, PreparedStatement ps, Connection conn) { |
||||||
|
MysqlUtil.getInstance().release(rs,ps,conn); |
||||||
|
if (null != rs) { |
||||||
|
try { |
||||||
|
rs.close(); |
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (null != ps) { |
||||||
|
try { |
||||||
|
ps.close(); |
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (null != conn) { |
||||||
|
try { |
||||||
|
conn.close(); |
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,150 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.common.utils; |
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.FileInputStream; |
||||||
|
import java.io.FileNotFoundException; |
||||||
|
import java.io.IOException; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.Comparator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
/** |
||||||
|
* Metadata related common classes |
||||||
|
* |
||||||
|
*/ |
||||||
|
public class SchemaUtils { |
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SchemaUtils.class); |
||||||
|
private static Pattern p = Pattern.compile("\\s*|\t|\r|\n"); |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取所有upgrade目录下的可升级的schema |
||||||
|
* Gets upgradable schemas for all upgrade directories |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@SuppressWarnings("unchecked") |
||||||
|
public static List<String> getAllSchemaList() { |
||||||
|
List<String> schemaDirList = new ArrayList<>(); |
||||||
|
File[] schemaDirArr = FileUtils.getAllDir("sql/upgrade"); |
||||||
|
if(schemaDirArr == null || schemaDirArr.length == 0) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
for(File file : schemaDirArr) { |
||||||
|
schemaDirList.add(file.getName()); |
||||||
|
} |
||||||
|
|
||||||
|
Collections.sort(schemaDirList , new Comparator() { |
||||||
|
@Override |
||||||
|
public int compare(Object o1 , Object o2){ |
||||||
|
try { |
||||||
|
String dir1 = String.valueOf(o1); |
||||||
|
String dir2 = String.valueOf(o2); |
||||||
|
String version1 = dir1.split("_")[0]; |
||||||
|
String version2 = dir2.split("_")[0]; |
||||||
|
if(version1.equals(version2)) { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
if(SchemaUtils.isAGreatVersion(version1, version2)) { |
||||||
|
return 1; |
||||||
|
} |
||||||
|
|
||||||
|
return -1; |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
return schemaDirList; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断schemaVersion是否比version版本高 |
||||||
|
* Determine whether schemaVersion is higher than version |
||||||
|
* @param schemaVersion |
||||||
|
* @param version |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isAGreatVersion(String schemaVersion, String version) { |
||||||
|
if(StringUtils.isEmpty(schemaVersion) || StringUtils.isEmpty(version)) { |
||||||
|
throw new RuntimeException("schemaVersion or version is empty"); |
||||||
|
} |
||||||
|
|
||||||
|
String[] schemaVersionArr = schemaVersion.split("\\."); |
||||||
|
String[] versionArr = version.split("\\."); |
||||||
|
int arrLength = schemaVersionArr.length < versionArr.length ? schemaVersionArr.length : versionArr.length; |
||||||
|
for(int i = 0 ; i < arrLength ; i++) { |
||||||
|
if(Integer.valueOf(schemaVersionArr[i]) > Integer.valueOf(versionArr[i])) { |
||||||
|
return true; |
||||||
|
}else if(Integer.valueOf(schemaVersionArr[i]) < Integer.valueOf(versionArr[i])) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 说明直到第arrLength-1个元素,两个版本号都一样,此时谁的arrLength大,谁的版本号就大
|
||||||
|
// If the version and schema version is the same from 0 up to the arrlength-1 element,whoever has a larger arrLength has a larger version number
|
||||||
|
return schemaVersionArr.length > versionArr.length; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the current software version number of the system |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getSoftVersion() { |
||||||
|
String soft_version; |
||||||
|
try { |
||||||
|
soft_version = FileUtils.readFile2Str(new FileInputStream(new File("sql/soft_version"))); |
||||||
|
soft_version = replaceBlank(soft_version); |
||||||
|
} catch (FileNotFoundException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
throw new RuntimeException("Failed to get the product version description file. The file could not be found", e); |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
throw new RuntimeException("Failed to get product version number description file, failed to read the file", e); |
||||||
|
} |
||||||
|
return soft_version; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 去掉字符串中的空格回车换行和制表符 |
||||||
|
* Strips the string of space carriage returns and tabs |
||||||
|
* @param str |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String replaceBlank(String str) { |
||||||
|
String dest = ""; |
||||||
|
if (str!=null) { |
||||||
|
|
||||||
|
Matcher m = p.matcher(str); |
||||||
|
dest = m.replaceAll(""); |
||||||
|
} |
||||||
|
return dest; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,317 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.common.utils; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.io.LineNumberReader; |
||||||
|
import java.io.Reader; |
||||||
|
import java.sql.*; |
||||||
|
|
||||||
|
/* |
||||||
|
* Slightly modified version of the com.ibatis.common.jdbc.ScriptRunner class
|
||||||
|
* from the iBATIS Apache project. Only removed dependency on Resource class
|
||||||
|
* and a constructor |
||||||
|
*/ |
||||||
|
/* |
||||||
|
* Copyright 2004 Clinton Begin |
||||||
|
* |
||||||
|
* 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Tool to run database scripts |
||||||
|
*/ |
||||||
|
public class ScriptRunner { |
||||||
|
|
||||||
|
public static final Logger logger = LoggerFactory.getLogger(ScriptRunner.class); |
||||||
|
|
||||||
|
private static final String DEFAULT_DELIMITER = ";"; |
||||||
|
|
||||||
|
private Connection connection; |
||||||
|
|
||||||
|
private boolean stopOnError; |
||||||
|
private boolean autoCommit; |
||||||
|
|
||||||
|
private String delimiter = DEFAULT_DELIMITER; |
||||||
|
private boolean fullLineDelimiter = false; |
||||||
|
|
||||||
|
/** |
||||||
|
* Default constructor |
||||||
|
*/ |
||||||
|
public ScriptRunner(Connection connection, boolean autoCommit, boolean stopOnError) { |
||||||
|
this.connection = connection; |
||||||
|
this.autoCommit = autoCommit; |
||||||
|
this.stopOnError = stopOnError; |
||||||
|
} |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
String dbName = "db_mmu"; |
||||||
|
String appKey = dbName.substring(dbName.lastIndexOf("_")+1, dbName.length()); |
||||||
|
System.out.println(appKey); |
||||||
|
} |
||||||
|
|
||||||
|
public void setDelimiter(String delimiter, boolean fullLineDelimiter) { |
||||||
|
this.delimiter = delimiter; |
||||||
|
this.fullLineDelimiter = fullLineDelimiter; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Runs an SQL script (read in using the Reader parameter) |
||||||
|
* |
||||||
|
* @param reader |
||||||
|
* - the source of the script |
||||||
|
*/ |
||||||
|
public void runScript(Reader reader) throws IOException, SQLException { |
||||||
|
try { |
||||||
|
boolean originalAutoCommit = connection.getAutoCommit(); |
||||||
|
try { |
||||||
|
if (originalAutoCommit != this.autoCommit) { |
||||||
|
connection.setAutoCommit(this.autoCommit); |
||||||
|
} |
||||||
|
runScript(connection, reader); |
||||||
|
} finally { |
||||||
|
connection.setAutoCommit(originalAutoCommit); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
throw e; |
||||||
|
} catch (SQLException e) { |
||||||
|
throw e; |
||||||
|
} catch (Exception e) { |
||||||
|
throw new RuntimeException("Error running script. Cause: " + e, e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void runScript(Reader reader, String dbName) throws IOException, SQLException { |
||||||
|
try { |
||||||
|
boolean originalAutoCommit = connection.getAutoCommit(); |
||||||
|
try { |
||||||
|
if (originalAutoCommit != this.autoCommit) { |
||||||
|
connection.setAutoCommit(this.autoCommit); |
||||||
|
} |
||||||
|
runScript(connection, reader, dbName); |
||||||
|
} finally { |
||||||
|
connection.setAutoCommit(originalAutoCommit); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
throw e; |
||||||
|
} catch (SQLException e) { |
||||||
|
throw e; |
||||||
|
} catch (Exception e) { |
||||||
|
throw new RuntimeException("Error running script. Cause: " + e, e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Runs an SQL script (read in using the Reader parameter) using the connection |
||||||
|
* passed in |
||||||
|
* |
||||||
|
* @param conn |
||||||
|
* - the connection to use for the script |
||||||
|
* @param reader |
||||||
|
* - the source of the script |
||||||
|
* @throws SQLException |
||||||
|
* if any SQL errors occur |
||||||
|
* @throws IOException |
||||||
|
* if there is an error reading from the Reader |
||||||
|
*/ |
||||||
|
private void runScript(Connection conn, Reader reader) throws IOException, SQLException { |
||||||
|
StringBuffer command = null; |
||||||
|
try { |
||||||
|
LineNumberReader lineReader = new LineNumberReader(reader); |
||||||
|
String line = null; |
||||||
|
while ((line = lineReader.readLine()) != null) { |
||||||
|
if (command == null) { |
||||||
|
command = new StringBuffer(); |
||||||
|
} |
||||||
|
String trimmedLine = line.trim(); |
||||||
|
if (trimmedLine.startsWith("--")) { |
||||||
|
logger.info(trimmedLine); |
||||||
|
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("//")) { |
||||||
|
// Do nothing
|
||||||
|
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("--")) { |
||||||
|
// Do nothing
|
||||||
|
|
||||||
|
} else if (trimmedLine.startsWith("delimiter")) { |
||||||
|
String newDelimiter = trimmedLine.split(" ")[1]; |
||||||
|
this.setDelimiter(newDelimiter, fullLineDelimiter); |
||||||
|
|
||||||
|
} else if (!fullLineDelimiter && trimmedLine.endsWith(getDelimiter()) |
||||||
|
|| fullLineDelimiter && trimmedLine.equals(getDelimiter())) { |
||||||
|
command.append(line.substring(0, line.lastIndexOf(getDelimiter()))); |
||||||
|
command.append(" "); |
||||||
|
Statement statement = conn.createStatement(); |
||||||
|
|
||||||
|
// logger.info(command.toString());
|
||||||
|
|
||||||
|
boolean hasResults = false; |
||||||
|
logger.info("sql:"+command.toString()); |
||||||
|
if (stopOnError) { |
||||||
|
hasResults = statement.execute(command.toString()); |
||||||
|
} else { |
||||||
|
try { |
||||||
|
statement.execute(command.toString()); |
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ResultSet rs = statement.getResultSet(); |
||||||
|
if (hasResults && rs != null) { |
||||||
|
ResultSetMetaData md = rs.getMetaData(); |
||||||
|
int cols = md.getColumnCount(); |
||||||
|
for (int i = 0; i < cols; i++) { |
||||||
|
String name = md.getColumnLabel(i); |
||||||
|
logger.info(name + "\t"); |
||||||
|
} |
||||||
|
logger.info(""); |
||||||
|
while (rs.next()) { |
||||||
|
for (int i = 0; i < cols; i++) { |
||||||
|
String value = rs.getString(i); |
||||||
|
logger.info(value + "\t"); |
||||||
|
} |
||||||
|
logger.info(""); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
command = null; |
||||||
|
try { |
||||||
|
statement.close(); |
||||||
|
} catch (Exception e) { |
||||||
|
// Ignore to workaround a bug in Jakarta DBCP
|
||||||
|
} |
||||||
|
Thread.yield(); |
||||||
|
} else { |
||||||
|
command.append(line); |
||||||
|
command.append(" "); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error("Error executing: " + command.toString()); |
||||||
|
throw e; |
||||||
|
} catch (IOException e) { |
||||||
|
e.fillInStackTrace(); |
||||||
|
logger.error("Error executing: " + command.toString()); |
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void runScript(Connection conn, Reader reader , String dbName) throws IOException, SQLException { |
||||||
|
StringBuffer command = null; |
||||||
|
String sql = ""; |
||||||
|
String appKey = dbName.substring(dbName.lastIndexOf("_")+1, dbName.length()); |
||||||
|
try { |
||||||
|
LineNumberReader lineReader = new LineNumberReader(reader); |
||||||
|
String line = null; |
||||||
|
while ((line = lineReader.readLine()) != null) { |
||||||
|
if (command == null) { |
||||||
|
command = new StringBuffer(); |
||||||
|
} |
||||||
|
String trimmedLine = line.trim(); |
||||||
|
if (trimmedLine.startsWith("--")) { |
||||||
|
logger.info(trimmedLine); |
||||||
|
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("//")) { |
||||||
|
// Do nothing
|
||||||
|
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("--")) { |
||||||
|
// Do nothing
|
||||||
|
|
||||||
|
} else if (trimmedLine.startsWith("delimiter")) { |
||||||
|
String newDelimiter = trimmedLine.split(" ")[1]; |
||||||
|
this.setDelimiter(newDelimiter, fullLineDelimiter); |
||||||
|
|
||||||
|
} else if (!fullLineDelimiter && trimmedLine.endsWith(getDelimiter()) |
||||||
|
|| fullLineDelimiter && trimmedLine.equals(getDelimiter())) { |
||||||
|
command.append(line.substring(0, line.lastIndexOf(getDelimiter()))); |
||||||
|
command.append(" "); |
||||||
|
Statement statement = conn.createStatement(); |
||||||
|
|
||||||
|
// logger.info(command.toString());
|
||||||
|
|
||||||
|
sql = command.toString().replaceAll("\\{\\{APPDB\\}\\}", dbName); |
||||||
|
boolean hasResults = false; |
||||||
|
logger.info("sql:"+sql); |
||||||
|
if (stopOnError) { |
||||||
|
hasResults = statement.execute(sql); |
||||||
|
} else { |
||||||
|
try { |
||||||
|
statement.execute(sql); |
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error(e.getMessage(),e); |
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ResultSet rs = statement.getResultSet(); |
||||||
|
if (hasResults && rs != null) { |
||||||
|
ResultSetMetaData md = rs.getMetaData(); |
||||||
|
int cols = md.getColumnCount(); |
||||||
|
for (int i = 0; i < cols; i++) { |
||||||
|
String name = md.getColumnLabel(i); |
||||||
|
logger.info(name + "\t"); |
||||||
|
} |
||||||
|
logger.info(""); |
||||||
|
while (rs.next()) { |
||||||
|
for (int i = 0; i < cols; i++) { |
||||||
|
String value = rs.getString(i); |
||||||
|
logger.info(value + "\t"); |
||||||
|
} |
||||||
|
logger.info(""); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
command = null; |
||||||
|
try { |
||||||
|
statement.close(); |
||||||
|
} catch (Exception e) { |
||||||
|
// Ignore to workaround a bug in Jakarta DBCP
|
||||||
|
} |
||||||
|
Thread.yield(); |
||||||
|
} else { |
||||||
|
command.append(line); |
||||||
|
command.append(" "); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error("Error executing: " + sql); |
||||||
|
throw e; |
||||||
|
} catch (IOException e) { |
||||||
|
e.fillInStackTrace(); |
||||||
|
logger.error("Error executing: " + sql); |
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private String getDelimiter() { |
||||||
|
return delimiter; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,145 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.dao; |
||||||
|
|
||||||
|
import cn.escheduler.common.Constants; |
||||||
|
import cn.escheduler.dao.model.MonitorRecord; |
||||||
|
import org.apache.commons.configuration.Configuration; |
||||||
|
import org.apache.commons.configuration.ConfigurationException; |
||||||
|
import org.apache.commons.configuration.PropertiesConfiguration; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.sql.*; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* database state dao |
||||||
|
*/ |
||||||
|
public class MonitorDBDao { |
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(MonitorDBDao.class); |
||||||
|
public static final String VARIABLE_NAME = "variable_name"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 加载配置文件 |
||||||
|
*/ |
||||||
|
private static Configuration conf; |
||||||
|
|
||||||
|
static { |
||||||
|
try { |
||||||
|
conf = new PropertiesConfiguration(Constants.DATA_SOURCE_PROPERTIES); |
||||||
|
}catch (ConfigurationException e){ |
||||||
|
logger.error("load configuration excetpion",e); |
||||||
|
System.exit(1); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* create connection |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private static Connection getConn() { |
||||||
|
String url = conf.getString(Constants.SPRING_DATASOURCE_URL); |
||||||
|
String username = conf.getString(Constants.SPRING_DATASOURCE_USERNAME); |
||||||
|
String password = conf.getString(Constants.SPRING_DATASOURCE_PASSWORD); |
||||||
|
Connection conn = null; |
||||||
|
try { |
||||||
|
//classloader,load driver
|
||||||
|
Class.forName(Constants.JDBC_MYSQL_CLASS_NAME); |
||||||
|
conn = DriverManager.getConnection(url, username, password); |
||||||
|
} catch (ClassNotFoundException e) { |
||||||
|
logger.error("ClassNotFoundException ", e); |
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error("SQLException ", e); |
||||||
|
} |
||||||
|
return conn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* query database state |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static List<MonitorRecord> queryDatabaseState() { |
||||||
|
List<MonitorRecord> list = new ArrayList<>(1); |
||||||
|
|
||||||
|
Connection conn = null; |
||||||
|
long maxConnections = 0; |
||||||
|
long maxUsedConnections = 0; |
||||||
|
long threadsConnections = 0; |
||||||
|
long threadsRunningConnections = 0; |
||||||
|
//mysql running state
|
||||||
|
int state = 1; |
||||||
|
|
||||||
|
|
||||||
|
MonitorRecord monitorRecord = new MonitorRecord(); |
||||||
|
try { |
||||||
|
conn = getConn(); |
||||||
|
if(conn == null){ |
||||||
|
return list; |
||||||
|
} |
||||||
|
|
||||||
|
Statement pstmt = conn.createStatement(); |
||||||
|
|
||||||
|
ResultSet rs1 = pstmt.executeQuery("show global variables"); |
||||||
|
while(rs1.next()){ |
||||||
|
if(rs1.getString(VARIABLE_NAME).toUpperCase().equals("MAX_CONNECTIONS")){ |
||||||
|
maxConnections= Long.parseLong(rs1.getString("value")); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ResultSet rs2 = pstmt.executeQuery("show global status"); |
||||||
|
while(rs2.next()){ |
||||||
|
if(rs2.getString(VARIABLE_NAME).toUpperCase().equals("MAX_USED_CONNECTIONS")){ |
||||||
|
maxUsedConnections = Long.parseLong(rs2.getString("value")); |
||||||
|
}else if(rs2.getString(VARIABLE_NAME).toUpperCase().equals("THREADS_CONNECTED")){ |
||||||
|
threadsConnections = Long.parseLong(rs2.getString("value")); |
||||||
|
}else if(rs2.getString(VARIABLE_NAME).toUpperCase().equals("THREADS_RUNNING")){ |
||||||
|
threadsRunningConnections= Long.parseLong(rs2.getString("value")); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error("SQLException ", e); |
||||||
|
state = 0; |
||||||
|
}finally { |
||||||
|
try { |
||||||
|
if(conn != null){ |
||||||
|
conn.close(); |
||||||
|
} |
||||||
|
} catch (SQLException e) { |
||||||
|
logger.error("SQLException ", e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
monitorRecord.setDate(new Date()); |
||||||
|
monitorRecord.setMaxConnections(maxConnections); |
||||||
|
monitorRecord.setMaxUsedConnections(maxUsedConnections); |
||||||
|
monitorRecord.setThreadsConnections(threadsConnections); |
||||||
|
monitorRecord.setThreadsRunningConnections(threadsRunningConnections); |
||||||
|
monitorRecord.setState(state); |
||||||
|
|
||||||
|
list.add(monitorRecord); |
||||||
|
|
||||||
|
return list; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,90 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.dao.mapper; |
||||||
|
|
||||||
|
import cn.escheduler.common.enums.UserType; |
||||||
|
import cn.escheduler.dao.model.AccessToken; |
||||||
|
import cn.escheduler.dao.model.User; |
||||||
|
import org.apache.ibatis.annotations.*; |
||||||
|
import org.apache.ibatis.type.EnumOrdinalTypeHandler; |
||||||
|
import org.apache.ibatis.type.JdbcType; |
||||||
|
|
||||||
|
import java.sql.Timestamp; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public interface AccessTokenMapper { |
||||||
|
|
||||||
|
/** |
||||||
|
* insert accessToken |
||||||
|
* @param accessToken |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@InsertProvider(type = AccessTokenMapperProvider.class, method = "insert") |
||||||
|
@Options(useGeneratedKeys = true,keyProperty = "accessToken.id") |
||||||
|
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "accessToken.id", before = false, resultType = int.class) |
||||||
|
int insert(@Param("accessToken") AccessToken accessToken); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* delete accessToken |
||||||
|
* @param accessTokenId |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@DeleteProvider(type = AccessTokenMapperProvider.class, method = "delete") |
||||||
|
int delete(@Param("accessTokenId") int accessTokenId); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* update accessToken |
||||||
|
* |
||||||
|
* @param accessToken |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@UpdateProvider(type = AccessTokenMapperProvider.class, method = "update") |
||||||
|
int update(@Param("accessToken") AccessToken accessToken); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* query access token list paging |
||||||
|
* @param searchVal |
||||||
|
* @param offset |
||||||
|
* @param pageSize |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "token", column = "token", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "expireTime", column = "expire_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE), |
||||||
|
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE), |
||||||
|
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE) |
||||||
|
}) |
||||||
|
@SelectProvider(type = AccessTokenMapperProvider.class, method = "queryAccessTokenPaging") |
||||||
|
List<AccessToken> queryAccessTokenPaging(@Param("userId") Integer userId, |
||||||
|
@Param("searchVal") String searchVal, |
||||||
|
@Param("offset") Integer offset, |
||||||
|
@Param("pageSize") Integer pageSize); |
||||||
|
|
||||||
|
/** |
||||||
|
* count access token by search value |
||||||
|
* @param searchVal |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@SelectProvider(type = AccessTokenMapperProvider.class, method = "countAccessTokenPaging") |
||||||
|
Integer countAccessTokenPaging(@Param("userId") Integer userId |
||||||
|
,@Param("searchVal") String searchVal); |
||||||
|
} |
@ -0,0 +1,136 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.dao.mapper; |
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.apache.ibatis.jdbc.SQL; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* access token mapper provider |
||||||
|
* |
||||||
|
*/ |
||||||
|
public class AccessTokenMapperProvider { |
||||||
|
|
||||||
|
private static final String TABLE_NAME = "t_escheduler_access_token"; |
||||||
|
|
||||||
|
/** |
||||||
|
* insert accessToken |
||||||
|
* |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String insert(Map<String, Object> parameter) { |
||||||
|
return new SQL() { |
||||||
|
{ |
||||||
|
INSERT_INTO(TABLE_NAME); |
||||||
|
VALUES("`user_id`", "#{accessToken.userId}"); |
||||||
|
VALUES("`token`", "#{accessToken.token}"); |
||||||
|
VALUES("`expire_time`", "#{accessToken.expireTime}");; |
||||||
|
VALUES("`create_time`", "#{accessToken.createTime}"); |
||||||
|
VALUES("`update_time`", "#{accessToken.updateTime}"); |
||||||
|
} |
||||||
|
}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete accessToken |
||||||
|
* |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String delete(Map<String, Object> parameter) { |
||||||
|
return new SQL() { |
||||||
|
{ |
||||||
|
DELETE_FROM(TABLE_NAME); |
||||||
|
|
||||||
|
WHERE("`id`=#{accessTokenId}"); |
||||||
|
} |
||||||
|
}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* update accessToken |
||||||
|
* |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String update(Map<String, Object> parameter) { |
||||||
|
return new SQL() { |
||||||
|
{ |
||||||
|
UPDATE(TABLE_NAME); |
||||||
|
|
||||||
|
SET("`user_id`=#{accessToken.userId}"); |
||||||
|
SET("`token`=#{accessToken.token}"); |
||||||
|
SET("`expire_time`=#{accessToken.expireTime}"); |
||||||
|
SET("`update_time`=#{accessToken.updateTime}"); |
||||||
|
|
||||||
|
WHERE("`id`=#{accessToken.id}"); |
||||||
|
} |
||||||
|
}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* count user number by search value |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String countAccessTokenPaging(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
SELECT("count(0)"); |
||||||
|
FROM(TABLE_NAME + " t,t_escheduler_user u"); |
||||||
|
Object searchVal = parameter.get("searchVal"); |
||||||
|
WHERE("u.id = t.user_id"); |
||||||
|
if(parameter.get("userId") != null && (int)parameter.get("userId") != 0){ |
||||||
|
WHERE(" u.id = #{userId}"); |
||||||
|
} |
||||||
|
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ |
||||||
|
WHERE(" u.user_name like concat('%', #{searchVal}, '%')"); |
||||||
|
} |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query user list paging |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String queryAccessTokenPaging(Map<String, Object> parameter) { |
||||||
|
return new SQL() { |
||||||
|
{ |
||||||
|
SELECT("t.*,u.user_name"); |
||||||
|
FROM(TABLE_NAME + " t,t_escheduler_user u"); |
||||||
|
Object searchVal = parameter.get("searchVal"); |
||||||
|
WHERE("u.id = t.user_id"); |
||||||
|
if(parameter.get("userId") != null && (int)parameter.get("userId") != 0){ |
||||||
|
WHERE(" u.id = #{userId}"); |
||||||
|
} |
||||||
|
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ |
||||||
|
WHERE(" u.user_name like concat('%', #{searchVal}, '%') "); |
||||||
|
} |
||||||
|
ORDER_BY(" t.update_time desc limit #{offset},#{pageSize} "); |
||||||
|
} |
||||||
|
}.toString(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,59 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.dao.mapper; |
||||||
|
|
||||||
|
import cn.escheduler.common.enums.*; |
||||||
|
import cn.escheduler.dao.model.Command; |
||||||
|
import cn.escheduler.dao.model.ErrorCommand; |
||||||
|
import cn.escheduler.dao.model.ExecuteStatusCount; |
||||||
|
import org.apache.ibatis.annotations.*; |
||||||
|
import org.apache.ibatis.type.EnumOrdinalTypeHandler; |
||||||
|
import org.apache.ibatis.type.JdbcType; |
||||||
|
|
||||||
|
import java.sql.Timestamp; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* command mapper |
||||||
|
*/ |
||||||
|
public interface ErrorCommandMapper { |
||||||
|
|
||||||
|
/** |
||||||
|
* inert error command |
||||||
|
* @param errorCommand |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@InsertProvider(type = ErrorCommandMapperProvider.class, method = "insert") |
||||||
|
@Options(useGeneratedKeys = true,keyProperty = "errorCommand.id") |
||||||
|
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "errorCommand.id", before = false, resultType = int.class) |
||||||
|
int insert(@Param("errorCommand") ErrorCommand errorCommand); |
||||||
|
|
||||||
|
@Results(value = { |
||||||
|
@Result(property = "state", column = "state", typeHandler = EnumOrdinalTypeHandler.class, javaType = ExecutionStatus.class, jdbcType = JdbcType.TINYINT), |
||||||
|
@Result(property = "count", column = "count", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
}) |
||||||
|
@SelectProvider(type = ErrorCommandMapperProvider.class, method = "countCommandState") |
||||||
|
List<ExecuteStatusCount> countCommandState( |
||||||
|
@Param("userId") int userId, |
||||||
|
@Param("userType") UserType userType, |
||||||
|
@Param("startTime") Date startTime, |
||||||
|
@Param("endTime") Date endTime, |
||||||
|
@Param("projectId") int projectId); |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,71 @@ |
|||||||
|
package cn.escheduler.dao.mapper; |
||||||
|
|
||||||
|
import cn.escheduler.common.enums.*; |
||||||
|
import cn.escheduler.common.utils.EnumFieldUtil; |
||||||
|
import org.apache.ibatis.jdbc.SQL; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class ErrorCommandMapperProvider { |
||||||
|
|
||||||
|
|
||||||
|
private static final String TABLE_NAME = "t_escheduler_error_command"; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* inert command |
||||||
|
* |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String insert(Map<String, Object> parameter) { |
||||||
|
return new SQL() { |
||||||
|
{ |
||||||
|
INSERT_INTO(TABLE_NAME); |
||||||
|
VALUES("`id`", "#{errorCommand.id}"); |
||||||
|
VALUES("`command_type`", EnumFieldUtil.genFieldStr("errorCommand.commandType", CommandType.class)); |
||||||
|
VALUES("`process_definition_id`", "#{errorCommand.processDefinitionId}"); |
||||||
|
VALUES("`executor_id`", "#{errorCommand.executorId}"); |
||||||
|
VALUES("`command_param`", "#{errorCommand.commandParam}"); |
||||||
|
VALUES("`task_depend_type`", EnumFieldUtil.genFieldStr("errorCommand.taskDependType", TaskDependType.class)); |
||||||
|
VALUES("`failure_strategy`", EnumFieldUtil.genFieldStr("errorCommand.failureStrategy", FailureStrategy.class)); |
||||||
|
VALUES("`warning_type`", EnumFieldUtil.genFieldStr("errorCommand.warningType", WarningType.class)); |
||||||
|
VALUES("`process_instance_priority`", EnumFieldUtil.genFieldStr("errorCommand.processInstancePriority", Priority.class)); |
||||||
|
VALUES("`warning_group_id`", "#{errorCommand.warningGroupId}"); |
||||||
|
VALUES("`schedule_time`", "#{errorCommand.scheduleTime}"); |
||||||
|
VALUES("`update_time`", "#{errorCommand.updateTime}"); |
||||||
|
VALUES("`start_time`", "#{errorCommand.startTime}"); |
||||||
|
VALUES("`worker_group_id`", "#{errorCommand.workerGroupId}"); |
||||||
|
VALUES("`message`", "#{errorCommand.message}"); |
||||||
|
} |
||||||
|
}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* count command type |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String countCommandState(Map<String, Object> parameter){ |
||||||
|
return new SQL(){ |
||||||
|
{ |
||||||
|
SELECT("command_type as state,COUNT(*) AS count"); |
||||||
|
FROM(TABLE_NAME + " cmd,t_escheduler_process_definition process"); |
||||||
|
WHERE("cmd.process_definition_id = process.id"); |
||||||
|
if(parameter.get("projectId") != null && (int)parameter.get("projectId") != 0){ |
||||||
|
WHERE( "process.project_id = #{projectId} "); |
||||||
|
}else{ |
||||||
|
if(parameter.get("userType") != null && String.valueOf(parameter.get("userType")) == "GENERAL_USER") { |
||||||
|
AND(); |
||||||
|
WHERE("process.project_id in (select id as project_id from t_escheduler_project tp where tp.user_id= #{userId} " + |
||||||
|
"union select project_id from t_escheduler_relation_project_user tr where tr.user_id= #{userId} )"); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
WHERE("cmd.start_time >= #{startTime} and cmd.update_time <= #{endTime}"); |
||||||
|
GROUP_BY("cmd.command_type"); |
||||||
|
} |
||||||
|
}.toString(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,88 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.dao.mapper; |
||||||
|
|
||||||
|
import cn.escheduler.dao.model.Queue; |
||||||
|
import org.apache.ibatis.annotations.*; |
||||||
|
import org.apache.ibatis.type.JdbcType; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* queue mapper |
||||||
|
*/ |
||||||
|
public interface MonitorMapper { |
||||||
|
|
||||||
|
/** |
||||||
|
* insert queue |
||||||
|
* @param queue |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@InsertProvider(type = QueueMapperProvider.class, method = "insert") |
||||||
|
@Options(useGeneratedKeys = true,keyProperty = "queue.id") |
||||||
|
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "queue.id", before = false, resultType = int.class) |
||||||
|
int insert(@Param("queue") Queue queue); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* delete queue |
||||||
|
* @param queueId |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@DeleteProvider(type = QueueMapperProvider.class, method = "delete") |
||||||
|
int delete(@Param("queueId") int queueId); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* update queue |
||||||
|
* |
||||||
|
* @param queue |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@UpdateProvider(type = QueueMapperProvider.class, method = "update") |
||||||
|
int update(@Param("queue") Queue queue); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* query queue by id |
||||||
|
* @param queueId |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "queueName", column = "queue_name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "queue", column = "queue", javaType = String.class, jdbcType = JdbcType.VARCHAR) |
||||||
|
}) |
||||||
|
@SelectProvider(type = QueueMapperProvider.class, method = "queryById") |
||||||
|
Queue queryById(@Param("queueId") int queueId); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* query all queue list |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "queueName", column = "queue_name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "queue", column = "queue", javaType = String.class, jdbcType = JdbcType.VARCHAR) |
||||||
|
}) |
||||||
|
@SelectProvider(type = QueueMapperProvider.class, method = "queryAllQueue") |
||||||
|
List<Queue> queryAllQueue(); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,131 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.dao.mapper; |
||||||
|
|
||||||
|
import cn.escheduler.dao.model.WorkerGroup; |
||||||
|
import org.apache.ibatis.annotations.*; |
||||||
|
import org.apache.ibatis.type.JdbcType; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group mapper |
||||||
|
*/ |
||||||
|
public interface WorkerGroupMapper { |
||||||
|
|
||||||
|
/** |
||||||
|
* query all worker group list |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = { |
||||||
|
@Result(property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "ipList", column = "ip_list", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "createTime", column = "create_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
@Result(property = "updateTime", column = "update_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
}) |
||||||
|
@SelectProvider(type = WorkerGroupMapperProvider.class, method = "queryAllWorkerGroup") |
||||||
|
List<WorkerGroup> queryAllWorkerGroup(); |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group by name |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = { |
||||||
|
@Result(property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "ipList", column = "ip_list", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "createTime", column = "create_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
@Result(property = "updateTime", column = "update_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
}) |
||||||
|
@SelectProvider(type = WorkerGroupMapperProvider.class, method = "queryWorkerGroupByName") |
||||||
|
List<WorkerGroup> queryWorkerGroupByName(@Param("name") String name); |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group paging by search value |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = { |
||||||
|
@Result(property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "ipList", column = "ip_list", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "createTime", column = "create_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
@Result(property = "updateTime", column = "update_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
}) |
||||||
|
@SelectProvider(type = WorkerGroupMapperProvider.class, method = "queryListPaging") |
||||||
|
List<WorkerGroup> queryListPaging(@Param("offset") int offset, |
||||||
|
@Param("pageSize") int pageSize, |
||||||
|
@Param("searchVal") String searchVal); |
||||||
|
|
||||||
|
/** |
||||||
|
* count worker group by search value |
||||||
|
* @param searchVal |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@SelectProvider(type = WorkerGroupMapperProvider.class, method = "countPaging") |
||||||
|
int countPaging(@Param("searchVal") String searchVal); |
||||||
|
|
||||||
|
/** |
||||||
|
* insert worker server |
||||||
|
* |
||||||
|
* @param workerGroup |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@InsertProvider(type = WorkerGroupMapperProvider.class, method = "insert") |
||||||
|
@Options(useGeneratedKeys = true,keyProperty = "workerGroup.id") |
||||||
|
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "workerGroup.id", before = false, resultType = int.class) |
||||||
|
int insert(@Param("workerGroup") WorkerGroup workerGroup); |
||||||
|
|
||||||
|
/** |
||||||
|
* update worker |
||||||
|
* |
||||||
|
* @param workerGroup |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@UpdateProvider(type = WorkerGroupMapperProvider.class, method = "update") |
||||||
|
int update(@Param("workerGroup") WorkerGroup workerGroup); |
||||||
|
|
||||||
|
/** |
||||||
|
* delete work group by id |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@DeleteProvider(type = WorkerGroupMapperProvider.class, method = "deleteById") |
||||||
|
int deleteById(@Param("id") int id); |
||||||
|
|
||||||
|
/** |
||||||
|
* query work group by id |
||||||
|
* @param id |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Results(value = { |
||||||
|
@Result(property = "id", column = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER), |
||||||
|
@Result(property = "ipList", column = "ip_list", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR), |
||||||
|
@Result(property = "createTime", column = "create_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
@Result(property = "updateTime", column = "update_time", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), |
||||||
|
}) |
||||||
|
@SelectProvider(type = WorkerGroupMapperProvider.class, method = "queryById") |
||||||
|
WorkerGroup queryById(@Param("id") int id); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,160 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.dao.mapper; |
||||||
|
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.apache.ibatis.jdbc.SQL; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group mapper provider |
||||||
|
*/ |
||||||
|
public class WorkerGroupMapperProvider { |
||||||
|
|
||||||
|
private static final String TABLE_NAME = "t_escheduler_worker_group"; |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker list |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String queryAllWorkerGroup() { |
||||||
|
return new SQL() {{ |
||||||
|
SELECT("*"); |
||||||
|
|
||||||
|
FROM(TABLE_NAME); |
||||||
|
|
||||||
|
ORDER_BY("update_time desc"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* insert worker server |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String insert(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
INSERT_INTO(TABLE_NAME); |
||||||
|
|
||||||
|
VALUES("id", "#{workerGroup.id}"); |
||||||
|
VALUES("name", "#{workerGroup.name}"); |
||||||
|
VALUES("ip_list", "#{workerGroup.ipList}"); |
||||||
|
VALUES("create_time", "#{workerGroup.createTime}"); |
||||||
|
VALUES("update_time", "#{workerGroup.updateTime}"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* update worker group |
||||||
|
* |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String update(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
UPDATE(TABLE_NAME); |
||||||
|
|
||||||
|
SET("name = #{workerGroup.name}"); |
||||||
|
SET("ip_list = #{workerGroup.ipList}"); |
||||||
|
SET("create_time = #{workerGroup.createTime}"); |
||||||
|
SET("update_time = #{workerGroup.updateTime}"); |
||||||
|
|
||||||
|
WHERE("id = #{workerGroup.id}"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* delete worker group by id |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String deleteById(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
DELETE_FROM(TABLE_NAME); |
||||||
|
|
||||||
|
WHERE("id = #{id}"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group by name |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String queryWorkerGroupByName(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
|
||||||
|
SELECT("*"); |
||||||
|
FROM(TABLE_NAME); |
||||||
|
|
||||||
|
WHERE("name = #{name}"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group by id |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String queryById(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
|
||||||
|
SELECT("*"); |
||||||
|
FROM(TABLE_NAME); |
||||||
|
|
||||||
|
WHERE("id = #{id}"); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* query worker group by id |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String queryListPaging(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
|
||||||
|
SELECT("*"); |
||||||
|
FROM(TABLE_NAME); |
||||||
|
|
||||||
|
Object searchVal = parameter.get("searchVal"); |
||||||
|
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ |
||||||
|
WHERE( " name like concat('%', #{searchVal}, '%') "); |
||||||
|
} |
||||||
|
ORDER_BY(" update_time desc limit #{offset},#{pageSize} "); |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* count worker group number by search value |
||||||
|
* @param parameter |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public String countPaging(Map<String, Object> parameter) { |
||||||
|
return new SQL() {{ |
||||||
|
SELECT("count(0)"); |
||||||
|
FROM(TABLE_NAME); |
||||||
|
Object searchVal = parameter.get("searchVal"); |
||||||
|
if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ |
||||||
|
WHERE( " name like concat('%', #{searchVal}, '%') "); |
||||||
|
} |
||||||
|
}}.toString(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,126 @@ |
|||||||
|
package cn.escheduler.dao.model; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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. |
||||||
|
*/ |
||||||
|
public class AccessToken { |
||||||
|
|
||||||
|
/** |
||||||
|
* id |
||||||
|
*/ |
||||||
|
private int id; |
||||||
|
|
||||||
|
/** |
||||||
|
* user id |
||||||
|
*/ |
||||||
|
private int userId; |
||||||
|
|
||||||
|
/** |
||||||
|
* user name |
||||||
|
*/ |
||||||
|
private String userName; |
||||||
|
|
||||||
|
/** |
||||||
|
* user token |
||||||
|
*/ |
||||||
|
private String token; |
||||||
|
|
||||||
|
/** |
||||||
|
* token expire time |
||||||
|
*/ |
||||||
|
private Date expireTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* create time |
||||||
|
*/ |
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* update time |
||||||
|
*/ |
||||||
|
private Date updateTime; |
||||||
|
|
||||||
|
public int getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(int id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public int getUserId() { |
||||||
|
return userId; |
||||||
|
} |
||||||
|
|
||||||
|
public void setUserId(int userId) { |
||||||
|
this.userId = userId; |
||||||
|
} |
||||||
|
|
||||||
|
public String getToken() { |
||||||
|
return token; |
||||||
|
} |
||||||
|
|
||||||
|
public void setToken(String token) { |
||||||
|
this.token = token; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getExpireTime() { |
||||||
|
return expireTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setExpireTime(Date expireTime) { |
||||||
|
this.expireTime = expireTime; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getCreateTime() { |
||||||
|
return createTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) { |
||||||
|
this.createTime = createTime; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getUpdateTime() { |
||||||
|
return updateTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setUpdateTime(Date updateTime) { |
||||||
|
this.updateTime = updateTime; |
||||||
|
} |
||||||
|
|
||||||
|
public String getUserName() { |
||||||
|
return userName; |
||||||
|
} |
||||||
|
|
||||||
|
public void setUserName(String userName) { |
||||||
|
this.userName = userName; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "AccessToken{" + |
||||||
|
"id=" + id + |
||||||
|
", userId=" + userId + |
||||||
|
", userName='" + userName + '\'' + |
||||||
|
", token='" + token + '\'' + |
||||||
|
", expireTime=" + expireTime + |
||||||
|
", createTime=" + createTime + |
||||||
|
", updateTime=" + updateTime + |
||||||
|
'}'; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,290 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.dao.model; |
||||||
|
|
||||||
|
import cn.escheduler.common.enums.*; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* command |
||||||
|
*/ |
||||||
|
public class ErrorCommand { |
||||||
|
|
||||||
|
/** |
||||||
|
* id |
||||||
|
*/ |
||||||
|
private int id; |
||||||
|
|
||||||
|
/** |
||||||
|
* command type |
||||||
|
*/ |
||||||
|
private CommandType commandType; |
||||||
|
|
||||||
|
/** |
||||||
|
* process definition id |
||||||
|
*/ |
||||||
|
private int processDefinitionId; |
||||||
|
|
||||||
|
/** |
||||||
|
* executor id |
||||||
|
*/ |
||||||
|
private int executorId; |
||||||
|
|
||||||
|
/** |
||||||
|
* command parameter, format json |
||||||
|
*/ |
||||||
|
private String commandParam; |
||||||
|
|
||||||
|
/** |
||||||
|
* task depend type |
||||||
|
*/ |
||||||
|
private TaskDependType taskDependType; |
||||||
|
|
||||||
|
/** |
||||||
|
* failure strategy |
||||||
|
*/ |
||||||
|
private FailureStrategy failureStrategy; |
||||||
|
|
||||||
|
/** |
||||||
|
* warning type |
||||||
|
*/ |
||||||
|
private WarningType warningType; |
||||||
|
|
||||||
|
/** |
||||||
|
* warning group id |
||||||
|
*/ |
||||||
|
private Integer warningGroupId; |
||||||
|
|
||||||
|
/** |
||||||
|
* schedule time |
||||||
|
*/ |
||||||
|
private Date scheduleTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* start time |
||||||
|
*/ |
||||||
|
private Date startTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* process instance priority |
||||||
|
*/ |
||||||
|
private Priority processInstancePriority; |
||||||
|
|
||||||
|
/** |
||||||
|
* update time |
||||||
|
*/ |
||||||
|
private Date updateTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* 执行信息 |
||||||
|
*/ |
||||||
|
private String message; |
||||||
|
|
||||||
|
/** |
||||||
|
* worker group id |
||||||
|
*/ |
||||||
|
private int workerGroupId; |
||||||
|
|
||||||
|
|
||||||
|
public ErrorCommand(Command command, String message){ |
||||||
|
this.commandType = command.getCommandType(); |
||||||
|
this.executorId = command.getExecutorId(); |
||||||
|
this.processDefinitionId = command.getProcessDefinitionId(); |
||||||
|
this.commandParam = command.getCommandParam(); |
||||||
|
this.warningType = command.getWarningType(); |
||||||
|
this.warningGroupId = command.getWarningGroupId(); |
||||||
|
this.scheduleTime = command.getScheduleTime(); |
||||||
|
this.taskDependType = command.getTaskDependType(); |
||||||
|
this.failureStrategy = command.getFailureStrategy(); |
||||||
|
this.startTime = command.getStartTime(); |
||||||
|
this.updateTime = command.getUpdateTime(); |
||||||
|
this.processInstancePriority = command.getProcessInstancePriority(); |
||||||
|
this.message = message; |
||||||
|
} |
||||||
|
|
||||||
|
public ErrorCommand( |
||||||
|
CommandType commandType, |
||||||
|
TaskDependType taskDependType, |
||||||
|
FailureStrategy failureStrategy, |
||||||
|
int executorId, |
||||||
|
int processDefinitionId, |
||||||
|
String commandParam, |
||||||
|
WarningType warningType, |
||||||
|
int warningGroupId, |
||||||
|
Date scheduleTime, |
||||||
|
Priority processInstancePriority, |
||||||
|
String message){ |
||||||
|
this.commandType = commandType; |
||||||
|
this.executorId = executorId; |
||||||
|
this.processDefinitionId = processDefinitionId; |
||||||
|
this.commandParam = commandParam; |
||||||
|
this.warningType = warningType; |
||||||
|
this.warningGroupId = warningGroupId; |
||||||
|
this.scheduleTime = scheduleTime; |
||||||
|
this.taskDependType = taskDependType; |
||||||
|
this.failureStrategy = failureStrategy; |
||||||
|
this.startTime = new Date(); |
||||||
|
this.updateTime = new Date(); |
||||||
|
this.processInstancePriority = processInstancePriority; |
||||||
|
this.message = message; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public TaskDependType getTaskDependType() { |
||||||
|
return taskDependType; |
||||||
|
} |
||||||
|
|
||||||
|
public void setTaskDependType(TaskDependType taskDependType) { |
||||||
|
this.taskDependType = taskDependType; |
||||||
|
} |
||||||
|
|
||||||
|
public int getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(int id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public CommandType getCommandType() { |
||||||
|
return commandType; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCommandType(CommandType commandType) { |
||||||
|
this.commandType = commandType; |
||||||
|
} |
||||||
|
|
||||||
|
public int getProcessDefinitionId() { |
||||||
|
return processDefinitionId; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProcessDefinitionId(int processDefinitionId) { |
||||||
|
this.processDefinitionId = processDefinitionId; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public FailureStrategy getFailureStrategy() { |
||||||
|
return failureStrategy; |
||||||
|
} |
||||||
|
|
||||||
|
public void setFailureStrategy(FailureStrategy failureStrategy) { |
||||||
|
this.failureStrategy = failureStrategy; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCommandParam(String commandParam) { |
||||||
|
this.commandParam = commandParam; |
||||||
|
} |
||||||
|
|
||||||
|
public String getCommandParam() { |
||||||
|
return commandParam; |
||||||
|
} |
||||||
|
|
||||||
|
public WarningType getWarningType() { |
||||||
|
return warningType; |
||||||
|
} |
||||||
|
|
||||||
|
public void setWarningType(WarningType warningType) { |
||||||
|
this.warningType = warningType; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getWarningGroupId() { |
||||||
|
return warningGroupId; |
||||||
|
} |
||||||
|
|
||||||
|
public void setWarningGroupId(Integer warningGroupId) { |
||||||
|
this.warningGroupId = warningGroupId; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getScheduleTime() { |
||||||
|
return scheduleTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setScheduleTime(Date scheduleTime) { |
||||||
|
this.scheduleTime = scheduleTime; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getStartTime() { |
||||||
|
return startTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setStartTime(Date startTime) { |
||||||
|
this.startTime = startTime; |
||||||
|
} |
||||||
|
|
||||||
|
public int getExecutorId() { |
||||||
|
return executorId; |
||||||
|
} |
||||||
|
|
||||||
|
public void setExecutorId(int executorId) { |
||||||
|
this.executorId = executorId; |
||||||
|
} |
||||||
|
|
||||||
|
public Priority getProcessInstancePriority() { |
||||||
|
return processInstancePriority; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProcessInstancePriority(Priority processInstancePriority) { |
||||||
|
this.processInstancePriority = processInstancePriority; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getUpdateTime() { |
||||||
|
return updateTime; |
||||||
|
} |
||||||
|
|
||||||
|
public void setUpdateTime(Date updateTime) { |
||||||
|
this.updateTime = updateTime; |
||||||
|
} |
||||||
|
|
||||||
|
public int getWorkerGroupId() { |
||||||
|
return workerGroupId; |
||||||
|
} |
||||||
|
|
||||||
|
public void setWorkerGroupId(int workerGroupId) { |
||||||
|
this.workerGroupId = workerGroupId; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "Command{" + |
||||||
|
"id=" + id + |
||||||
|
", commandType=" + commandType + |
||||||
|
", processDefinitionId=" + processDefinitionId + |
||||||
|
", executorId=" + executorId + |
||||||
|
", commandParam='" + commandParam + '\'' + |
||||||
|
", taskDependType=" + taskDependType + |
||||||
|
", failureStrategy=" + failureStrategy + |
||||||
|
", warningType=" + warningType + |
||||||
|
", warningGroupId=" + warningGroupId + |
||||||
|
", scheduleTime=" + scheduleTime + |
||||||
|
", startTime=" + startTime + |
||||||
|
", processInstancePriority=" + processInstancePriority + |
||||||
|
", updateTime=" + updateTime + |
||||||
|
", message=" + message + |
||||||
|
'}'; |
||||||
|
} |
||||||
|
|
||||||
|
public String getMessage() { |
||||||
|
return message; |
||||||
|
} |
||||||
|
|
||||||
|
public void setMessage(String message) { |
||||||
|
this.message = message; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,115 @@ |
|||||||
|
/* |
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
* contributor license agreements. See the NOTICE file distributed with |
||||||
|
* this work for additional information regarding copyright ownership. |
||||||
|
* The ASF licenses this file to You 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 cn.escheduler.dao.model; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* monitor record for database |
||||||
|
*/ |
||||||
|
public class MonitorRecord { |
||||||
|
|
||||||
|
/** |
||||||
|
* is normal or not , 1: normal |
||||||
|
*/ |
||||||
|
private int state; |
||||||
|
|
||||||
|
/** |
||||||
|
* max connections |
||||||
|
*/ |
||||||
|
private long maxConnections; |
||||||
|
|
||||||
|
/** |
||||||
|
* max used connections |
||||||
|
*/ |
||||||
|
private long maxUsedConnections; |
||||||
|
|
||||||
|
/** |
||||||
|
* threads connections |
||||||
|
*/ |
||||||
|
private long threadsConnections; |
||||||
|
|
||||||
|
/** |
||||||
|
* threads running connections |
||||||
|
*/ |
||||||
|
private long threadsRunningConnections; |
||||||
|
|
||||||
|
/** |
||||||
|
* start date |
||||||
|
*/ |
||||||
|
private Date date; |
||||||
|
|
||||||
|
public int getState() { |
||||||
|
return state; |
||||||
|
} |
||||||
|
|
||||||
|
public void setState(int state) { |
||||||
|
this.state = state; |
||||||
|
} |
||||||
|
|
||||||
|
public long getMaxConnections() { |
||||||
|
return maxConnections; |
||||||
|
} |
||||||
|
|
||||||
|
public void setMaxConnections(long maxConnections) { |
||||||
|
this.maxConnections = maxConnections; |
||||||
|
} |
||||||
|
|
||||||
|
public long getMaxUsedConnections() { |
||||||
|
return maxUsedConnections; |
||||||
|
} |
||||||
|
|
||||||
|
public void setMaxUsedConnections(long maxUsedConnections) { |
||||||
|
this.maxUsedConnections = maxUsedConnections; |
||||||
|
} |
||||||
|
|
||||||
|
public long getThreadsConnections() { |
||||||
|
return threadsConnections; |
||||||
|
} |
||||||
|
|
||||||
|
public void setThreadsConnections(long threadsConnections) { |
||||||
|
this.threadsConnections = threadsConnections; |
||||||
|
} |
||||||
|
|
||||||
|
public long getThreadsRunningConnections() { |
||||||
|
return threadsRunningConnections; |
||||||
|
} |
||||||
|
|
||||||
|
public void setThreadsRunningConnections(long threadsRunningConnections) { |
||||||
|
this.threadsRunningConnections = threadsRunningConnections; |
||||||
|
} |
||||||
|
|
||||||
|
public Date getDate() { |
||||||
|
return date; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDate(Date date) { |
||||||
|
this.date = date; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "MonitorRecord{" + |
||||||
|
"state=" + state + |
||||||
|
", maxConnections=" + maxConnections + |
||||||
|
", maxUsedConnections=" + maxUsedConnections + |
||||||
|
", threadsConnections=" + threadsConnections + |
||||||
|
", threadsRunningConnections=" + threadsRunningConnections + |
||||||
|
", date=" + date + |
||||||
|
'}'; |
||||||
|
} |
||||||
|
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue