Browse Source

增加代码控制设置3

master
VIVIMAN 3 years ago
parent
commit
2b5fcc2f8d
  1. 21
      src/main/java/com/insigma/service/impl/LinuxTongWebKingBase.java
  2. 26
      src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java
  3. 13
      src/main/java/com/insigma/ui/Test.java

21
src/main/java/com/insigma/service/impl/LinuxTongWebKingBase.java

@ -28,7 +28,7 @@ public class LinuxTongWebKingBase implements Computer, Database, Middleware {
@Override @Override
public boolean runShell(String shell) { public boolean runShell(String shell) {
log.info("准备执行shell命令..."); log.info("准备执行>> shell命令...");
try { try {
new LinuxCommandUtil(shell).run(); new LinuxCommandUtil(shell).run();
}catch (Exception e){ }catch (Exception e){
@ -40,18 +40,19 @@ public class LinuxTongWebKingBase implements Computer, Database, Middleware {
@Override @Override
public boolean runBak(String path) { public boolean runBak(String path) {
log.info("准备执行备份命令..."); log.info("准备执行>> 备份命令...");
return false; return false;
} }
@Override @Override
public boolean runRestore(String filePath) { public boolean runRestore(String filePath) {
log.info("准备执行还原命令..."); log.info("准备执行>> 还原命令...");
return false; return false;
} }
@Override @Override
public boolean rebuildIndex(List<IndexObj> index) { public boolean rebuildIndex(List<IndexObj> index) {
log.info("准备执行>> 重建索引命令...");
boolean retBool; boolean retBool;
log.info("创建链接..."); log.info("创建链接...");
final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd, DbUtil.drive); final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd, DbUtil.drive);
@ -86,6 +87,7 @@ public class LinuxTongWebKingBase implements Computer, Database, Middleware {
*/ */
@Override @Override
public boolean setDbSize(int ...size) { public boolean setDbSize(int ...size) {
log.info("准备执行>> 设置数据库内存命令...");
if(size == null || size.length!=2){ if(size == null || size.length!=2){
log.error("请检测参数是否正确..."); log.error("请检测参数是否正确...");
return false; return false;
@ -108,6 +110,7 @@ public class LinuxTongWebKingBase implements Computer, Database, Middleware {
@Override @Override
public boolean cleanDbCache(List<String> sqls, List<TabColObj> tabColObjs) { public boolean cleanDbCache(List<String> sqls, List<TabColObj> tabColObjs) {
log.info("准备执行>> 清除垃圾数据命令...");
boolean retBool; boolean retBool;
log.info("创建链接..."); log.info("创建链接...");
final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd, DbUtil.drive); final Session session = DbUtil.getSession(DbUtil.url, DbUtil.usr, DbUtil.pwd, DbUtil.drive);
@ -141,12 +144,14 @@ public class LinuxTongWebKingBase implements Computer, Database, Middleware {
@Override @Override
public boolean registrationDbService() { public boolean registrationDbService() {
log.info("准备执行>> 数据库服务注册命令...");
// TODO 无法实现 // TODO 无法实现
return true; return true;
} }
@Override @Override
public boolean cleanMwCache() { public boolean cleanMwCache() {
log.info("准备执行>> 清楚应用缓存命令...");
log.info("停止 中间件 服务..."); log.info("停止 中间件 服务...");
runShell("systemctl stop " + AppCfg.MW); runShell("systemctl stop " + AppCfg.MW);
@ -174,6 +179,7 @@ public class LinuxTongWebKingBase implements Computer, Database, Middleware {
*/ */
@Override @Override
public boolean setMwSize(int ...size) { public boolean setMwSize(int ...size) {
log.info("准备执行>> 设置应用内存命令...");
if(size == null || size.length!=2){ if(size == null || size.length!=2){
log.error("请检测参数是否正确..."); log.error("请检测参数是否正确...");
return false; return false;
@ -196,34 +202,35 @@ public class LinuxTongWebKingBase implements Computer, Database, Middleware {
@Override @Override
public boolean startDbService() { public boolean startDbService() {
log.info("启动 数据服务..."); log.info("准备执行>> 启动数据服务命令...");
runShell("systemctl start " + AppCfg.DB); runShell("systemctl start " + AppCfg.DB);
return true; return true;
} }
@Override @Override
public boolean stopDbService() { public boolean stopDbService() {
log.info("停止 数据库 服务..."); log.info("准备执行>> 停止数据库服务命令...");
runShell("systemctl stop " + AppCfg.DB); runShell("systemctl stop " + AppCfg.DB);
return true; return true;
} }
@Override @Override
public boolean startMwService() { public boolean startMwService() {
log.info("启动 中间件 服务..."); log.info("准备执行>> 启动应用服务命令...");
runShell("systemctl start " + AppCfg.MW); runShell("systemctl start " + AppCfg.MW);
return true; return true;
} }
@Override @Override
public boolean stopMwService() { public boolean stopMwService() {
log.info("停止 中间件 服务..."); log.info("准备执行>> 停止应用服务命令...");
runShell("systemctl stop " + AppCfg.MW); runShell("systemctl stop " + AppCfg.MW);
return true; return true;
} }
@Override @Override
public boolean registrationMwService() { public boolean registrationMwService() {
log.info("准备执行>> 注册应用服务命令...");
// TODO 无法实现 // TODO 无法实现
return true; return true;
} }

26
src/main/java/com/insigma/service/impl/WindowsTomcatMysql.java

@ -30,7 +30,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean runShell(String shell) { public boolean runShell(String shell) {
log.info("准备执行shell命令..."); log.info("准备执行>> shell命令...");
try { try {
new WinCommandUtil(shell).run(); new WinCommandUtil(shell).run();
}catch (Exception e){ }catch (Exception e){
@ -42,7 +42,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean runBak(String path) { public boolean runBak(String path) {
log.info("准备执行备份命令..."); log.info("准备执行>> 备份命令...");
boolean retBool; boolean retBool;
log.info("创建备份文件目录..."); log.info("创建备份文件目录...");
String format = DateTimeFormatter.BASIC_ISO_DATE.format(LocalDate.now()); String format = DateTimeFormatter.BASIC_ISO_DATE.format(LocalDate.now());
@ -103,6 +103,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean runRestore(String filePath) { public boolean runRestore(String filePath) {
log.info("准备执行>> 还原命令...");
boolean retBool; boolean retBool;
boolean b = cn.hutool.core.io.FileUtil.isFile(filePath); boolean b = cn.hutool.core.io.FileUtil.isFile(filePath);
if(b){ if(b){
@ -155,6 +156,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean rebuildIndex(List<IndexObj> index) { public boolean rebuildIndex(List<IndexObj> index) {
log.info("准备执行>> 重建索引命令...");
boolean retBool = false; boolean retBool = false;
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
@ -192,6 +194,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
*/ */
@Override @Override
public boolean setDbSize(int ...size) { public boolean setDbSize(int ...size) {
log.info("准备执行>> 设置数据库内存命令...");
if(size == null || size.length!=1){ if(size == null || size.length!=1){
log.error("请检测参数是否正确..."); log.error("请检测参数是否正确...");
return false; return false;
@ -218,6 +221,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean cleanDbCache(List<String> sqls, List<TabColObj> tabColObjs) { public boolean cleanDbCache(List<String> sqls, List<TabColObj> tabColObjs) {
log.info("准备执行>> 清除垃圾数据命令...");
boolean retBool = false; boolean retBool = false;
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING) { if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING) {
@ -254,6 +258,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean registrationDbService() { public boolean registrationDbService() {
log.info("准备执行>> 数据库服务注册命令...");
if(WinCommandUtil.RegisterUtil.registerWindows( if(WinCommandUtil.RegisterUtil.registerWindows(
String.format("SYSTEM\\ControlSet001\\Services\\%s", AppCfg.DB), String.format("SYSTEM\\ControlSet001\\Services\\%s", AppCfg.DB),
AppCfg.DB, AppCfg.DB,
@ -275,7 +280,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean cleanMwCache() { public boolean cleanMwCache() {
log.info("停止 中间件 服务..."); log.info("准备执行>> 清楚应用缓存命令...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) {
@ -314,6 +319,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
*/ */
@Override @Override
public boolean setMwSize(int ...size) { public boolean setMwSize(int ...size) {
log.info("准备执行>> 设置应用内存命令...");
if(size == null || size.length!=4){ if(size == null || size.length!=4){
log.error("请检测参数是否正确..."); log.error("请检测参数是否正确...");
return false; return false;
@ -339,6 +345,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean registrationMwService() { public boolean registrationMwService() {
log.info("准备执行>> 注册应用服务命令...");
if(WinCommandUtil.RegisterUtil.registerWindows( if(WinCommandUtil.RegisterUtil.registerWindows(
String.format("SYSTEM\\ControlSet001\\Services\\%s", AppCfg.DB), String.format("SYSTEM\\ControlSet001\\Services\\%s", AppCfg.DB),
AppCfg.MW, AppCfg.MW,
@ -378,8 +385,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean startDbService() { public boolean startDbService() {
boolean bool; log.info("准备执行>> 启动数据服务命令...");
log.info("启动 数据库 服务...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.STOPPED){ if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.STOPPED){
if (canNotRun(ws, WinServiceTool.WindowsService::startService)) { if (canNotRun(ws, WinServiceTool.WindowsService::startService)) {
@ -396,8 +402,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean stopDbService() { public boolean stopDbService() {
boolean bool; log.info("准备执行>> 停止数据库服务命令...");
log.info("停止 数据库 服务...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE); WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.DB, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) {
@ -409,8 +414,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean startMwService() { public boolean startMwService() {
boolean bool; log.info("准备执行>> 启动应用服务命令...");
log.info("启动 中间件 服务...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.STOPPED){ if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.STOPPED){
return !canNotRun(ws, WinServiceTool.WindowsService::startService); return !canNotRun(ws, WinServiceTool.WindowsService::startService);
@ -423,7 +427,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public boolean stopMwService() { public boolean stopMwService() {
log.info("停止 中间件 服务..."); log.info("准备执行>> 停止应用服务命令...");
WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE); WinServiceTool.WindowsService ws = WinServiceTool.getService(AppCfg.MW, AppCfg.CODE);
if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){ if(ws.getRunningStatus() == WinServiceTool.WindowsService.ServiceState.RUNNING){
if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) { if (canNotRun(ws, WinServiceTool.WindowsService::stopService)) {
@ -436,7 +440,7 @@ public class WindowsTomcatMysql implements Computer, Database, Middleware {
@Override @Override
public void openServer(){ public void openServer(){
log.info("准备执行>> 打开本地服务命令...");
runShell("SERVICES.MSC"); runShell("SERVICES.MSC");
log.info("打开本地服务完成!");
} }
} }

13
src/main/java/com/insigma/ui/Test.java

@ -29,7 +29,7 @@ public class Test {
if(Objects.isNull(computer) || Objects.isNull(database) || Objects.isNull(middleware)){ if(Objects.isNull(computer) || Objects.isNull(database) || Objects.isNull(middleware)){
return; return;
} }
addButton(textPanel, new JButton("执行shell命令"), e -> computer.runShell("SERVICES.MSC")); addButton(textPanel, new JButton("执行shell命令"), e -> computer.runShell("SERVICES.MSC"));
addButton(textPanel, new JButton("备份"), e -> computer.runBak(AppCfg.HZB)); addButton(textPanel, new JButton("备份"), e -> computer.runBak(AppCfg.HZB));
// addButton(textPanel, new JButton("还原"), e -> computer.runRestore("")); // addButton(textPanel, new JButton("还原"), e -> computer.runRestore(""));
addButton(textPanel, new JButton("重建索引"), e -> database.rebuildIndex(IndexObj.getData())); addButton(textPanel, new JButton("重建索引"), e -> database.rebuildIndex(IndexObj.getData()));
@ -39,11 +39,11 @@ public class Test {
addButton(textPanel, new JButton("清楚应用缓存"), e -> middleware.cleanMwCache()); addButton(textPanel, new JButton("清楚应用缓存"), e -> middleware.cleanMwCache());
addButton(textPanel, new JButton("设置中间件大小"), e -> middleware.setMwSize(128,256,512,512)); addButton(textPanel, new JButton("设置中间件大小"), e -> middleware.setMwSize(128,256,512,512));
addButton(textPanel, new JButton("注册中间件服务"), e -> middleware.registrationMwService()); addButton(textPanel, new JButton("注册中间件服务"), e -> middleware.registrationMwService());
addButton(textPanel, new JButton("启动数据库服务"), e -> database.startDbService()); addButton(textPanel, new JButton("启动数据库服务"), e -> database.startDbService());
addButton(textPanel, new JButton("停止数据库服务"), e -> database.stopDbService()); addButton(textPanel, new JButton("停止数据库服务"), e -> database.stopDbService());
addButton(textPanel, new JButton("启动中间件服务"), e -> middleware.startMwService()); addButton(textPanel, new JButton("启动中间件服务"), e -> middleware.startMwService());
addButton(textPanel, new JButton("停止中间件服务"), e -> middleware.stopMwService()); addButton(textPanel, new JButton("停止中间件服务"), e -> middleware.stopMwService());
addButton(textPanel, new JButton("打开本地服务"), e -> computer.openServer()); addButton(textPanel, new JButton("打开本地服务"), e -> computer.openServer());
} }
private static void addButton(JPanel textPanel, JButton button, ActionListener l) { private static void addButton(JPanel textPanel, JButton button, ActionListener l) {
@ -51,7 +51,6 @@ public class Test {
int k = n++; int k = n++;
button.setBounds(14 + k/12*200, 13 + k%12 * 40, 170, 35); button.setBounds(14 + k/12*200, 13 + k%12 * 40, 170, 35);
button.addActionListener(l); button.addActionListener(l);
log.debug("输出对象:{}", button);
textPanel.add(button); textPanel.add(button);
} }
} }

Loading…
Cancel
Save