From 2853f394e73e7b56443169d1a427a06a62fe11ad Mon Sep 17 00:00:00 2001 From: dqjdda <201507802@qq.com> Date: Mon, 25 Nov 2019 10:28:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/zhengjie/modules/mnt/domain/App.java | 10 +- .../zhengjie/modules/mnt/domain/Deploy.java | 17 +- .../modules/mnt/domain/DeployHistory.java | 2 +- .../modules/mnt/repository/AppRepository.java | 2 +- .../mnt/repository/DeployRepository.java | 2 +- .../modules/mnt/rest/AppController.java | 2 +- .../modules/mnt/rest/DeployController.java | 4 +- .../modules/mnt/service/AppService.java | 4 +- .../modules/mnt/service/DeployService.java | 6 +- .../modules/mnt/service/dto/AppDTO.java | 3 + .../mnt/service/dto/AppQueryCriteria.java | 6 + .../modules/mnt/service/dto/DeployDTO.java | 11 +- .../mnt/service/dto/DeployHistoryDTO.java | 2 +- .../mnt/service/impl/AppServiceImpl.java | 7 +- .../mnt/service/impl/DeployServiceImpl.java | 189 +++++++++--------- 15 files changed, 143 insertions(+), 124 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/App.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/App.java index 2806f912..a167130e 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/App.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/App.java @@ -3,8 +3,11 @@ package me.zhengjie.modules.mnt.domain; import lombok.Data; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; +import org.hibernate.annotations.CreationTimestamp; + import javax.persistence.*; import java.io.Serializable; +import java.sql.Timestamp; /** * @author zhanghouying @@ -19,8 +22,8 @@ public class App implements Serializable { * 应用编号 */ @Id - @Column(name = "id") - private String id; + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; /** * 应用名称 @@ -64,6 +67,9 @@ public class App implements Serializable { @Column(name = "deploy_script") private String deployScript; + @CreationTimestamp + private Timestamp createTime; + public void copy(App source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/Deploy.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/Deploy.java index cd9832c0..1cd73a0c 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/Deploy.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/Deploy.java @@ -5,6 +5,7 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; import javax.persistence.*; import java.io.Serializable; +import java.util.Set; /** * @author zhanghouying @@ -19,20 +20,22 @@ public class Deploy implements Serializable { * 部署编号 */ @Id - @Column(name = "id") - private String id; + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; /** * 应用编号 */ - @Column(name = "app_id") - private String appId; + @ManyToOne + @JoinColumn(name = "app_id") + private App app; /** - * IP列表 + * 服务器 */ - @Column(name = "ip") - private String ip; + @ManyToMany + @JoinTable(name = "mnt_deploy_server", joinColumns = {@JoinColumn(name = "deploy_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "server_id",referencedColumnName = "id")}) + private Set deploys; public void copy(Deploy source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/DeployHistory.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/DeployHistory.java index 748ba7ed..76083bf1 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/DeployHistory.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/DeployHistory.java @@ -50,7 +50,7 @@ public class DeployHistory implements Serializable { * 部署编号 */ @Column(name = "deploy_id",nullable = false) - private String deployId; + private Long deployId; public void copy(DeployHistory source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/AppRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/AppRepository.java index 725d0e2b..341fe4bc 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/AppRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/AppRepository.java @@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; * @author zhanghouying * @date 2019-08-24 */ -public interface AppRepository extends JpaRepository, JpaSpecificationExecutor { +public interface AppRepository extends JpaRepository, JpaSpecificationExecutor { } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/DeployRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/DeployRepository.java index d4590d71..df5aa19b 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/DeployRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/DeployRepository.java @@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; * @author zhanghouying * @date 2019-08-24 */ -public interface DeployRepository extends JpaRepository, JpaSpecificationExecutor { +public interface DeployRepository extends JpaRepository, JpaSpecificationExecutor { } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/AppController.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/AppController.java index 080963a1..4f94d9d1 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/AppController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/AppController.java @@ -59,7 +59,7 @@ public class AppController { @ApiOperation(value = "删除App") @DeleteMapping(value = "/{id}") @PreAuthorize("@el.check('app:del')") - public ResponseEntity delete(@PathVariable String id){ + public ResponseEntity delete(@PathVariable Long id){ appService.delete(id); return new ResponseEntity(HttpStatus.OK); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployController.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployController.java index a50ae44a..e5242313 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployController.java @@ -66,7 +66,7 @@ public class DeployController { @ApiOperation(value = "删除Deploy") @DeleteMapping(value = "/{id}") @PreAuthorize("@el.check('deploy:del')") - public ResponseEntity delete(@PathVariable String id){ + public ResponseEntity delete(@PathVariable Long id){ deployService.delete(id); return new ResponseEntity(HttpStatus.OK); } @@ -76,7 +76,7 @@ public class DeployController { @PostMapping(value = "/upload") @PreAuthorize("@el.check('deploy:edit')") public ResponseEntity upload(@RequestBody MultipartFile file, HttpServletRequest request, HttpServletResponse response)throws Exception{ - String id = request.getParameter("id"); + Long id = Long.valueOf(request.getParameter("id")); String fileName = ""; if(file != null){ fileName = file.getOriginalFilename(); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/AppService.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/AppService.java index ef5dcdd4..5f246c7a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/AppService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/AppService.java @@ -31,7 +31,7 @@ public interface AppService { * @param id * @return */ - AppDTO findById(String id); + AppDTO findById(Long id); /** * create @@ -50,5 +50,5 @@ public interface AppService { * delete * @param id */ - void delete(String id); + void delete(Long id); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployService.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployService.java index 51041037..d8fc035a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployService.java @@ -32,7 +32,7 @@ public interface DeployService { * @param id * @return */ - DeployDTO findById(String id); + DeployDTO findById(Long id); /** * create @@ -54,7 +54,7 @@ public interface DeployService { * @CacheEvict(allEntries = true) * @param id */ - void delete(String id); + void delete(Long id); /** * 部署文件到服务器 @@ -62,7 +62,7 @@ public interface DeployService { * @param appId * @return */ - public String deploy(String fileSavePath, String appId); + public String deploy(String fileSavePath, Long appId); /** * 查询部署状态 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/AppDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/AppDTO.java index ef137449..97ab6fcf 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/AppDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/AppDTO.java @@ -3,6 +3,7 @@ package me.zhengjie.modules.mnt.service.dto; import lombok.Data; import java.io.Serializable; +import java.sql.Timestamp; /** @@ -52,4 +53,6 @@ public class AppDTO implements Serializable { */ private String deployScript; + private Timestamp createTime; + } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/AppQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/AppQueryCriteria.java index a52007e8..7a036789 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/AppQueryCriteria.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/AppQueryCriteria.java @@ -3,6 +3,9 @@ package me.zhengjie.modules.mnt.service.dto; import lombok.Data; import me.zhengjie.annotation.Query; +import java.sql.Timestamp; +import java.util.List; + /** * @author zhanghouying * @date 2019-08-24 @@ -15,4 +18,7 @@ public class AppQueryCriteria{ */ @Query(type = Query.Type.INNER_LIKE) private String name; + + @Query(type = Query.Type.BETWEEN) + private List createTime; } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployDTO.java index 4d65da68..e0f6cc93 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployDTO.java @@ -2,6 +2,7 @@ package me.zhengjie.modules.mnt.service.dto; import lombok.Data; import java.io.Serializable; +import java.util.Set; /** @@ -16,16 +17,12 @@ public class DeployDTO implements Serializable { */ private String id; - /** - * 应用编号 - */ - private String appId; + private AppDTO app; /** - * IP列表 + * 服务器 */ - private String ip; - + private Set deploys; /** * 服务状态 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployHistoryDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployHistoryDTO.java index 19da3b5a..fdec6cc2 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployHistoryDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployHistoryDTO.java @@ -39,5 +39,5 @@ public class DeployHistoryDTO implements Serializable { /** * 部署编号 */ - private String deployId; + private Long deployId; } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/AppServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/AppServiceImpl.java index 2a25f1af..341b1b7c 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/AppServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/AppServiceImpl.java @@ -1,6 +1,5 @@ package me.zhengjie.modules.mnt.service.impl; -import cn.hutool.core.util.IdUtil; import me.zhengjie.modules.mnt.domain.App; import me.zhengjie.modules.mnt.repository.AppRepository; import me.zhengjie.modules.mnt.service.AppService; @@ -15,7 +14,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; - import java.util.Optional; /** @@ -47,7 +45,7 @@ public class AppServiceImpl implements AppService { } @Override - public AppDTO findById(String id) { + public AppDTO findById(Long id) { Optional app = appRepository.findById(id); ValidationUtil.isNull(app,"App","id",id); return appMapper.toDto(app.get()); @@ -56,7 +54,6 @@ public class AppServiceImpl implements AppService { @Override @Transactional(rollbackFor = Exception.class) public AppDTO create(App resources) { - resources.setId(IdUtil.fastUUID()); return appMapper.toDto(appRepository.save(resources)); } @@ -72,7 +69,7 @@ public class AppServiceImpl implements AppService { @Override @Transactional(rollbackFor = Exception.class) - public void delete(String id) { + public void delete(Long id) { appRepository.deleteById(id); } } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployServiceImpl.java index e74ce771..f4d58218 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployServiceImpl.java @@ -5,8 +5,10 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import lombok.extern.slf4j.Slf4j; import me.zhengjie.exception.BadRequestException; +import me.zhengjie.modules.mnt.domain.App; import me.zhengjie.modules.mnt.domain.Deploy; import me.zhengjie.modules.mnt.domain.DeployHistory; +import me.zhengjie.modules.mnt.domain.ServerDeploy; import me.zhengjie.modules.mnt.repository.DeployRepository; import me.zhengjie.modules.mnt.service.*; import me.zhengjie.modules.mnt.service.dto.*; @@ -32,6 +34,7 @@ import java.io.IOException; import java.util.Date; import java.util.List; import java.util.Optional; +import java.util.Set; /** * @author zhanghouying @@ -74,7 +77,7 @@ public class DeployServiceImpl implements DeployService { } @Override - public DeployDTO findById(String id) { + public DeployDTO findById(Long id) { Optional Deploy = deployRepository.findById(id); ValidationUtil.isNull(Deploy, "Deploy", "id", id); return deployMapper.toDto(Deploy.get()); @@ -83,7 +86,6 @@ public class DeployServiceImpl implements DeployService { @Override @Transactional(rollbackFor = Exception.class) public DeployDTO create(Deploy resources) { - resources.setId(IdUtil.simpleUUID()); return deployMapper.toDto(deployRepository.save(resources)); } @@ -99,12 +101,12 @@ public class DeployServiceImpl implements DeployService { @Override @Transactional(rollbackFor = Exception.class) - public void delete(String id) { + public void delete(Long id) { deployRepository.deleteById(id); } @Override - public String deploy(String fileSavePath, String id) { + public String deploy(String fileSavePath, Long id) { return deployApp(fileSavePath, id); } @@ -113,14 +115,14 @@ public class DeployServiceImpl implements DeployService { * @param id * @return */ - private String deployApp(String fileSavePath, String id) { + private String deployApp(String fileSavePath, Long id) { DeployDTO deploy = findById(id); if (deploy == null) { sendMsg("部署信息不存在", MsgType.ERROR); throw new BadRequestException("部署信息不存在"); } - AppDTO app = appService.findById(deploy.getAppId()); + AppDTO app = deploy.getApp(); if (app == null) { sendMsg("包对应应用信息不存在", MsgType.ERROR); throw new BadRequestException("包对应应用信息不存在"); @@ -130,42 +132,44 @@ public class DeployServiceImpl implements DeployService { String uploadPath = app.getUploadPath(); StringBuilder sb = new StringBuilder(); String msg = ""; - String ip = deploy.getIp(); - ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip); - //判断是否第一次部署 - boolean flag = checkFile(executeShellUtil, app); - //第一步要确认服务器上有这个目录 - executeShellUtil.execute("mkdir -p " + uploadPath); - //上传文件 - msg = String.format("登陆到服务器:%s", ip); - ScpClientUtil scpClientUtil = getScpClientUtil(ip); - log.info(msg); - sendMsg(msg, MsgType.INFO); - msg = String.format("上传文件到服务器:%s
目录:%s下", ip, uploadPath); - sendMsg(msg, MsgType.INFO); - scpClientUtil.putFile(fileSavePath, uploadPath); - if (flag) { - sendMsg("停止原来应用", MsgType.INFO); - //停止应用 - stopApp(port, executeShellUtil); - sendMsg("备份原来应用", MsgType.INFO); - //备份应用 - backupApp(executeShellUtil, ip, app.getDeployPath(), app.getName(), app.getBackupPath(), id); + Set deploys = deploy.getDeploys(); + for (ServerDeployDTO deployDTO : deploys) { + String ip = deployDTO.getIp(); + ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip); + //判断是否第一次部署 + boolean flag = checkFile(executeShellUtil, app); + //第一步要确认服务器上有这个目录 + executeShellUtil.execute("mkdir -p " + uploadPath); + //上传文件 + msg = String.format("登陆到服务器:%s", ip); + ScpClientUtil scpClientUtil = getScpClientUtil(ip); + log.info(msg); + sendMsg(msg, MsgType.INFO); + msg = String.format("上传文件到服务器:%s
目录:%s下", ip, uploadPath); + sendMsg(msg, MsgType.INFO); + scpClientUtil.putFile(fileSavePath, uploadPath); + if (flag) { + sendMsg("停止原来应用", MsgType.INFO); + //停止应用 + stopApp(port, executeShellUtil); + sendMsg("备份原来应用", MsgType.INFO); + //备份应用 + backupApp(executeShellUtil, ip, app.getDeployPath(), app.getName(), app.getBackupPath(), id); + } + sendMsg("部署应用", MsgType.INFO); + //部署文件,并启动应用 + String deployScript = app.getDeployScript(); + executeShellUtil.execute(deployScript); + + sendMsg("启动应用", MsgType.INFO); + String startScript = app.getStartScript(); + executeShellUtil.execute(startScript); + //只有过5秒才能知道到底是不是启动成功了。 + sleep(5); + boolean result = checkIsRunningStatus(port, executeShellUtil); + sb.append("服务器:").append(deployDTO.getName()).append("
应用:").append(app.getName()); + sendResultMsg(result, sb); } - sendMsg("部署应用", MsgType.INFO); - //部署文件,并启动应用 - String deployScript = app.getDeployScript(); - executeShellUtil.execute(deployScript); - - sendMsg("启动应用", MsgType.INFO); - String startScript = app.getStartScript(); - executeShellUtil.execute(startScript); - //只有过5秒才能知道到底是不是启动成功了。 - sleep(5); - boolean result = checkIsRunningStatus(port, executeShellUtil); - sb.append("服务器:").append(ip).append("
应用:").append(app.getName()); - sendResultMsg(result, sb); - return "部署结束"; } @@ -177,7 +181,7 @@ public class DeployServiceImpl implements DeployService { } } - private void backupApp(ExecuteShellUtil executeShellUtil, String ip, String fileSavePath, String appName, String backupPath, String id) { + private void backupApp(ExecuteShellUtil executeShellUtil, String ip, String fileSavePath, String appName, String backupPath, Long id) { String deployDate = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN); StringBuilder sb = new StringBuilder(); if (!backupPath.endsWith(FILE_SEPARATOR)) { @@ -241,21 +245,22 @@ public class DeployServiceImpl implements DeployService { @Override public String serverStatus(Deploy resources) { - String ip = resources.getIp(); - String appId = resources.getAppId(); - AppDTO app = appService.findById(appId); - StringBuffer sb = new StringBuffer(); - ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip); - sb.append("服务器:").append(ip).append("
应用:").append(app.getName()); - boolean result = checkIsRunningStatus(app.getPort(), executeShellUtil); - if (result) { - sb.append("
正在运行"); - sendMsg(sb.toString(), MsgType.INFO); - } else { - sb.append("
已停止!"); - sendMsg(sb.toString(), MsgType.ERROR); + Set serverDeploys = resources.getDeploys(); + App app = resources.getApp(); + for (ServerDeploy serverDeploy : serverDeploys) { + StringBuilder sb = new StringBuilder(); + ExecuteShellUtil executeShellUtil = getExecuteShellUtil(serverDeploy.getIp()); + sb.append("服务器:").append(serverDeploy.getName()).append("
应用:").append(app.getName()); + boolean result = checkIsRunningStatus(app.getPort(), executeShellUtil); + if (result) { + sb.append("
正在运行"); + sendMsg(sb.toString(), MsgType.INFO); + } else { + sb.append("
已停止!"); + sendMsg(sb.toString(), MsgType.ERROR); + } + log.info(sb.toString()); } - log.info(sb.toString()); return "执行完毕"; } @@ -277,21 +282,22 @@ public class DeployServiceImpl implements DeployService { */ @Override public String startServer(Deploy resources) { - String ip = resources.getIp(); - String appId = resources.getAppId(); - AppDTO app = appService.findById(appId); - StringBuilder sb = new StringBuilder(); - ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip); - //为了防止重复启动,这里先停止应用 - stopApp(app.getPort(), executeShellUtil); - sb.append("服务器:").append(ip).append("
应用:").append(app.getName()); - sendMsg("下发启动命令", MsgType.INFO); - executeShellUtil.execute(app.getStartScript()); - //停止3秒,防止应用没有启动完成 - sleep(3); - boolean result = checkIsRunningStatus(app.getPort(), executeShellUtil); - sendResultMsg(result, sb); - log.info(sb.toString()); + Set deploys = resources.getDeploys(); + App app = resources.getApp(); + for (ServerDeploy deploy : deploys) { + StringBuilder sb = new StringBuilder(); + ExecuteShellUtil executeShellUtil = getExecuteShellUtil(deploy.getIp()); + //为了防止重复启动,这里先停止应用 + stopApp(app.getPort(), executeShellUtil); + sb.append("服务器:").append(deploy.getName()).append("
应用:").append(app.getName()); + sendMsg("下发启动命令", MsgType.INFO); + executeShellUtil.execute(app.getStartScript()); + //停止3秒,防止应用没有启动完成 + sleep(3); + boolean result = checkIsRunningStatus(app.getPort(), executeShellUtil); + sendResultMsg(result, sb); + log.info(sb.toString()); + } return "执行完毕"; } @@ -302,34 +308,35 @@ public class DeployServiceImpl implements DeployService { */ @Override public String stopServer(Deploy resources) { - String ip = resources.getIp(); - String appId = resources.getAppId(); - AppDTO app = appService.findById(appId); - StringBuffer sb = new StringBuffer(); - ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip); - sb.append("服务器:").append(ip).append("
应用:").append(app.getName()); - sendMsg("下发停止命令", MsgType.INFO); - //停止应用 - stopApp(app.getPort(), executeShellUtil); - sleep(1); - boolean result = checkIsRunningStatus(app.getPort(), executeShellUtil); - if (result) { - sb.append("
关闭失败!"); - sendMsg(sb.toString(), MsgType.ERROR); - } else { - sb.append("
关闭成功!"); - sendMsg(sb.toString(), MsgType.INFO); + Set deploys = resources.getDeploys(); + App app = resources.getApp(); + for (ServerDeploy deploy : deploys) { + StringBuffer sb = new StringBuffer(); + ExecuteShellUtil executeShellUtil = getExecuteShellUtil(deploy.getIp()); + sb.append("服务器:").append(deploy.getName()).append("
应用:").append(app.getName()); + sendMsg("下发停止命令", MsgType.INFO); + //停止应用 + stopApp(app.getPort(), executeShellUtil); + sleep(1); + boolean result = checkIsRunningStatus(app.getPort(), executeShellUtil); + if (result) { + sb.append("
关闭失败!"); + sendMsg(sb.toString(), MsgType.ERROR); + } else { + sb.append("
关闭成功!"); + sendMsg(sb.toString(), MsgType.INFO); + } + log.info(sb.toString()); } - log.info(sb.toString()); return "执行完毕"; } @Override public String serverReduction(DeployHistory resources) { - String deployId = resources.getDeployId(); + Long deployId = resources.getDeployId(); Deploy deployInfo = deployRepository.findById(deployId).get(); String deployDate = resources.getDeployDate(); - AppDTO app = appService.findById(deployInfo.getAppId()); + App app = deployInfo.getApp(); if (app == null) { sendMsg("应用信息不存在:" + resources.getAppName(), MsgType.ERROR); throw new BadRequestException("应用信息不存在:" + resources.getAppName());