|
|
@ -1,13 +1,18 @@ |
|
|
|
package com.insigma.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.db.Session; |
|
|
|
import com.insigma.config.AppCfg; |
|
|
|
import com.insigma.entry.IndexObj; |
|
|
|
import com.insigma.entry.TabColObj; |
|
|
|
import com.insigma.service.Computer; |
|
|
|
import com.insigma.service.Database; |
|
|
|
import com.insigma.service.Middleware; |
|
|
|
import com.insigma.utils.DbUtil; |
|
|
|
import com.insigma.utils.FileUtil; |
|
|
|
import com.insigma.utils.LinuxCommandUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -30,38 +35,158 @@ public class LinuxTongWebKingBase extends Computer implements Database, Middlewa |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean runBak() { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean rebuildIndex(List<IndexObj> index) { |
|
|
|
return true; |
|
|
|
boolean retBool; |
|
|
|
log.info("创建链接..."); |
|
|
|
final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd, DbUtil.drive); |
|
|
|
String sql; |
|
|
|
try { |
|
|
|
for (IndexObj idx : index) { |
|
|
|
try { |
|
|
|
sql = String.format("DROP INDEX %s", idx.getIdx()); |
|
|
|
log.debug(sql); |
|
|
|
session.execute(sql); |
|
|
|
}finally { |
|
|
|
sql = String.format( "CREATE INDEX %s on %s (%s)", idx.getIdx(), idx.getTab(), idx.getCol()); |
|
|
|
log.debug(sql); |
|
|
|
session.execute(sql); |
|
|
|
} |
|
|
|
} |
|
|
|
retBool = true; |
|
|
|
} catch (SQLException e) { |
|
|
|
log.error("执行更新索引发生异常:{}", e.getMessage()); |
|
|
|
session.close(); |
|
|
|
retBool = false; |
|
|
|
} |
|
|
|
session.close(); |
|
|
|
return retBool; |
|
|
|
} |
|
|
|
|
|
|
|
/*** |
|
|
|
* 设置数据库参数 :注意参数的个数和位置 |
|
|
|
* @param size 顺序为 shared_buffers, effective_cache_size |
|
|
|
* @return |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public boolean setDbSize(int size) { |
|
|
|
public boolean setDbSize(int ...size) { |
|
|
|
if(size == null || size.length!=2){ |
|
|
|
log.error("请检测参数是否正确..."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
log.info("停止 数据库 服务..."); |
|
|
|
runShell("systemctl stop " + AppCfg.DB); |
|
|
|
|
|
|
|
log.info("设置 数据库 内存参数..."); |
|
|
|
FileUtil.replaceLine(AppCfg.HZB + "/kingbase/bin//TEST/kingbase.conf", |
|
|
|
"shared_buffers", |
|
|
|
String.format("shared_buffers=%dGB", size[0])); |
|
|
|
FileUtil.replaceLine(AppCfg.HZB + "/kingbase/bin//TEST/kingbase.conf", |
|
|
|
"effective_cache_size", |
|
|
|
String.format("effective_cache_size=%dGB", size[1])); |
|
|
|
|
|
|
|
log.info("启动 数据库 服务..."); |
|
|
|
runShell("systemctl start " + AppCfg.DB); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean cleanDbCache(List<String> sql, List<TabColObj> tabColObjs) { |
|
|
|
return true; |
|
|
|
public boolean cleanDbCache(List<String> sqls, List<TabColObj> tabColObjs) { |
|
|
|
boolean retBool; |
|
|
|
log.info("创建链接..."); |
|
|
|
final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd, DbUtil.drive); |
|
|
|
try { |
|
|
|
log.info("执行 预置 SQL 脚本..."); |
|
|
|
for (String sql : sqls) { |
|
|
|
log.debug(sql); |
|
|
|
session.execute(sql); |
|
|
|
} |
|
|
|
log.info("执行 清洗数据中特殊字符串 脚本..."); |
|
|
|
String sql; |
|
|
|
for (String lj : DbUtil.RUBBISH) { |
|
|
|
for (TabColObj tab : tabColObjs) { |
|
|
|
sql = String.format("update %s set %s=replace(%s, '%s', '') where %s is not null", |
|
|
|
tab.getTab(), tab.getCol(), tab.getCol(), lj, tab.getCol()); |
|
|
|
log.debug(sql); |
|
|
|
session.execute(sql); |
|
|
|
} |
|
|
|
} |
|
|
|
retBool = true; |
|
|
|
} catch (SQLException e) { |
|
|
|
log.error("执行 清洗数据中特殊字符串 发生异常:{}", e.getMessage()); |
|
|
|
e.printStackTrace(); |
|
|
|
session.close(); |
|
|
|
retBool = false; |
|
|
|
} |
|
|
|
log.info("执行 清洗数据中特殊字符串 完成..."); |
|
|
|
session.close(); |
|
|
|
return retBool; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean registrationDbService() { |
|
|
|
// TODO 无法实现
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean cleanMwCache() { |
|
|
|
log.info("停止 中间件 服务..."); |
|
|
|
runShell("systemctl stop " + AppCfg.MW); |
|
|
|
|
|
|
|
// TODO 无法确定浏览器
|
|
|
|
log.info("退出 浏览器..."); |
|
|
|
log.info("删除 浏览器 历史文件..."); |
|
|
|
log.info("解压 新浏览器 文件..."); |
|
|
|
|
|
|
|
log.info("删除 应用 缓存文件..."); |
|
|
|
runShell(String.format("rm -rf %s/TongWeb7/temp", AppCfg.HZB)); |
|
|
|
|
|
|
|
log.info("删除 应用 日志文件..."); |
|
|
|
runShell(String.format("rm -rf %s/TongWeb7/logs", AppCfg.HZB)); |
|
|
|
|
|
|
|
log.info("启动 中间件 服务..."); |
|
|
|
runShell("systemctl start " + AppCfg.MW); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/*** |
|
|
|
* 设置中间件参数 :注意参数的个数和位置 |
|
|
|
* @param size 顺序为 xms, xmx |
|
|
|
* @return |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public boolean setMwSize(int permSize, int maxPermSize, int xms, int xmx) { |
|
|
|
public boolean setMwSize(int ...size) { |
|
|
|
if(size == null || size.length!=2){ |
|
|
|
log.error("请检测参数是否正确..."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
log.info("停止 中间件 服务..."); |
|
|
|
runShell("systemctl stop " + AppCfg.MW); |
|
|
|
|
|
|
|
log.info("设置 数据库 内存参数..."); |
|
|
|
FileUtil.replaceLine(AppCfg.HZB + "/bin/external.vmoptions", |
|
|
|
"-Xms", |
|
|
|
String.format("Xms%dm", size[0])); |
|
|
|
FileUtil.replaceLine(AppCfg.HZB + "/bin/external.vmoptions", |
|
|
|
"-Xmx", |
|
|
|
String.format("-Xmx%dm", size[1])); |
|
|
|
|
|
|
|
log.info("启动 中间件 服务..."); |
|
|
|
runShell("systemctl start " + AppCfg.MW); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean registrationMwService() { |
|
|
|
// TODO 无法实现
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|