| | |
| | | import com.vci.ubcs.starter.util.HttpUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.WebUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.cloud.client.ServiceInstance; |
| | |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.ServletRequest; |
| | |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.nio.file.StandardCopyOption; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | |
| | | if(deployAppsVO.getName().isEmpty()){ |
| | | throw new ServiceException("缺少必传参数name"); |
| | | } |
| | | DeployApps deployApps = deployAppsMapper.selectOne(Wrappers.<DeployApps>query().lambda().eq(DeployApps::getServerName, deployAppsVO.getName())); |
| | | List<DeployApps> deployApps = deployAppsMapper.selectList(Wrappers.<DeployApps>query().lambda().eq(DeployApps::getServerName, deployAppsVO.getName())); |
| | | if(Func.isNotEmpty(deployApps)){ |
| | | return deployApps; |
| | | return deployApps.get(0); |
| | | } |
| | | // 未从库中查询到,需要生成服务信息保存默认信息到库中 |
| | | DeployApps defaultDeployApps = new DeployApps(); |
| | | defaultDeployApps.setLogPath(PARENTPATH + "\\" + deployAppsVO.getName().replace("-","_") + LOGPATH); |
| | | defaultDeployApps.setLogPath(PARENTPATH + deployAppsVO.getName().replace("-","_") + LOGPATH); |
| | | defaultDeployApps.setServerName(deployAppsVO.getName()); |
| | | defaultDeployApps.setStartCmd(CmdConfigEnum.START_CMD.getValue() + deployAppsVO.getName()); |
| | | defaultDeployApps.setStopCmd(CmdConfigEnum.STOP_CMD.getValue() + deployAppsVO.getName()); |
| | | defaultDeployApps.setRestartCmd(CmdConfigEnum.RESTART_CMD.getValue() + deployAppsVO.getName()); |
| | | defaultDeployApps.setServerPath(PARENTPATH + "\\" + deployAppsVO.getName().replace("-","_")); |
| | | defaultDeployApps.setServerPath(PARENTPATH + deployAppsVO.getName().replace("-","_")); |
| | | int eft = deployAppsMapper.insert(defaultDeployApps); |
| | | if (!SqlHelper.retBool(eft)) { |
| | | throw new ServiceException("生成默认服务信息到库中时失败!"); |
| | |
| | | */ |
| | | @Override |
| | | public boolean saveOrUpdateServiceInfo(DeployAppsVO deployAppsVO) throws ServiceException { |
| | | boolean b = this.saveOrUpdate(deployAppsVO); |
| | | return b; |
| | | return this.saveOrUpdate(deployAppsVO); |
| | | } |
| | | |
| | | /** |
| | |
| | | public boolean addSave(DeployApps deployApps) throws ServiceException { |
| | | if (Func.isBlank(deployApps.getServerName()) || Func.isBlank(deployApps.getServerPath())) { |
| | | throw new ServiceException("必传参数[服务名称,服务存放路径]不能为空"); |
| | | } |
| | | List<DeployApps> deployAppsList = deployAppsMapper.selectList(Wrappers.<DeployApps>query().lambda().eq(DeployApps::getServerName, deployApps.getServerName())); |
| | | if (!deployAppsList.isEmpty()) { |
| | | throw new ServiceException("新增服务的服务名重复!"); |
| | | } |
| | | return SqlHelper.retBool(deployAppsMapper.insert(deployApps)); |
| | | } |
| | |
| | | String backName = ""; |
| | | String fileType = "file"; |
| | | // 是压缩文件,因为只会存在两种情况,文件名是压缩文件,或者文件(.jar类型的文件) |
| | | // 当前时间 |
| | | String currentDateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | if (file.getContentType().equals("application/zip") || file.getContentType().equals("application/x-zip-compressed")) { |
| | | backName = file.getOriginalFilename().replace(".zip","_"+Func.formatDate(new Date())); |
| | | fileType = "zip"; |
| | | backName = file.getOriginalFilename().replace(".zip","_" + currentDateTime); |
| | | }else{ |
| | | backName = file.getOriginalFilename().replace(".","_"+Func.formatDate(new Date())+"."); |
| | | fileType = "file"; |
| | | backName = file.getOriginalFilename().replace(".","_" + currentDateTime + "."); |
| | | } |
| | | File source = new File(deployAppsDB.get(0).getServerPath() + this.SEPARATOR + file.getOriginalFilename().replace(".zip", "")); |
| | | File destination = new File(deployAppsDB.get(0).getFileBack() + this.SEPARATOR + backName); |
| | |
| | | return "The executed command is empty"; |
| | | } |
| | | // 执行Linux命令 |
| | | log.info("开始执行命令:"+cmd); |
| | | Process process = Runtime.getRuntime().exec(cmd); |
| | | // 读取命令执行结果 |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| | |
| | | } |
| | | // 等待命令执行完成 |
| | | int exitCode = process.waitFor(); |
| | | log.info("命令执行结果:" + output.toString()); |
| | | log.info("命令执行结果:" + output.toString()+":"+exitCode); |
| | | return output.toString(); |
| | | }catch (IOException | InterruptedException e){ |
| | | e.printStackTrace(); |