Commit e4ca7afc authored by dqjdda's avatar dqjdda
Browse files

阿里巴巴代码规范

parent 6d941c09
package me.zhengjie.modules.mnt.service;
import me.zhengjie.modules.mnt.domain.ServerDeploy;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDTO;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria;
import org.springframework.data.domain.Pageable;
......@@ -11,17 +11,51 @@ import org.springframework.data.domain.Pageable;
*/
public interface ServerDeployService {
/**
* 分页查询
* @param criteria 条件
* @param pageable 分页参数
* @return /
*/
Object queryAll(ServerDeployQueryCriteria criteria, Pageable pageable);
/**
* 查询全部数据
* @param criteria 条件
* @return /
*/
Object queryAll(ServerDeployQueryCriteria criteria);
ServerDeployDTO findById(Long id);
ServerDeployDTO create(ServerDeploy resources);
/**
* 根据ID查询
* @param id /
* @return /
*/
ServerDeployDto findById(Long id);
/**
* 创建
* @param resources /
* @return /
*/
ServerDeployDto create(ServerDeploy resources);
/**
* 编辑
* @param resources /
*/
void update(ServerDeploy resources);
/**
* 删除
* @param id /
*/
void delete(Long id);
ServerDeployDTO findByIp(String ip);
/**
* 根据IP查询
* @param ip /
* @return /
*/
ServerDeployDto findByIp(String ip);
}
......@@ -11,7 +11,7 @@ import java.sql.Timestamp;
* @date 2019-08-24
*/
@Data
public class AppDTO implements Serializable {
public class AppDto implements Serializable {
/**
* 应用编号
......@@ -26,7 +26,7 @@ public class AppDTO implements Serializable {
/**
* 端口
*/
private int port;
private Integer port;
/**
* 上传目录
......
......@@ -9,7 +9,7 @@ import java.io.Serializable;
* @date 2019-08-24
*/
@Data
public class DatabaseDTO implements Serializable {
public class DatabaseDto implements Serializable {
/**
* id
......
......@@ -13,19 +13,19 @@ import java.util.stream.Collectors;
* @date 2019-08-24
*/
@Data
public class DeployDTO implements Serializable {
public class DeployDto implements Serializable {
/**
* 部署编号
*/
private String id;
private AppDTO app;
private AppDto app;
/**
* 服务器
*/
private Set<ServerDeployDTO> deploys;
private Set<ServerDeployDto> deploys;
private String servers;
......@@ -38,7 +38,7 @@ public class DeployDTO implements Serializable {
public String getServers() {
if(CollectionUtil.isNotEmpty(deploys)){
return deploys.stream().map(ServerDeployDTO::getName).collect(Collectors.joining(","));
return deploys.stream().map(ServerDeployDto::getName).collect(Collectors.joining(","));
}
return servers;
}
......
......@@ -10,7 +10,7 @@ import java.sql.Timestamp;
* @date 2019-08-24
*/
@Data
public class DeployHistoryDTO implements Serializable {
public class DeployHistoryDto implements Serializable {
/**
* 编号
......
......@@ -10,7 +10,7 @@ import java.sql.Timestamp;
* @date 2019-08-24
*/
@Data
public class ServerDeployDTO implements Serializable {
public class ServerDeployDto implements Serializable {
private Long id;
......
......@@ -3,7 +3,7 @@ package me.zhengjie.modules.mnt.service.impl;
import me.zhengjie.modules.mnt.domain.App;
import me.zhengjie.modules.mnt.repository.AppRepository;
import me.zhengjie.modules.mnt.service.AppService;
import me.zhengjie.modules.mnt.service.dto.AppDTO;
import me.zhengjie.modules.mnt.service.dto.AppDto;
import me.zhengjie.modules.mnt.service.dto.AppQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.AppMapper;
import me.zhengjie.utils.PageUtil;
......@@ -44,7 +44,7 @@ public class AppServiceImpl implements AppService {
}
@Override
public AppDTO findById(Long id) {
public AppDto findById(Long id) {
App app = appRepository.findById(id).orElseGet(App::new);
ValidationUtil.isNull(app.getId(),"App","id",id);
return appMapper.toDto(app);
......@@ -52,7 +52,7 @@ public class AppServiceImpl implements AppService {
@Override
@Transactional(rollbackFor = Exception.class)
public AppDTO create(App resources) {
public AppDto create(App resources) {
return appMapper.toDto(appRepository.save(resources));
}
......
......@@ -4,7 +4,7 @@ import cn.hutool.core.util.IdUtil;
import me.zhengjie.modules.mnt.domain.Database;
import me.zhengjie.modules.mnt.repository.DatabaseRepository;
import me.zhengjie.modules.mnt.service.DatabaseService;
import me.zhengjie.modules.mnt.service.dto.DatabaseDTO;
import me.zhengjie.modules.mnt.service.dto.DatabaseDto;
import me.zhengjie.modules.mnt.service.dto.DatabaseQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.DatabaseMapper;
import me.zhengjie.utils.PageUtil;
......@@ -45,7 +45,7 @@ public class DatabaseServiceImpl implements DatabaseService {
}
@Override
public DatabaseDTO findById(String id) {
public DatabaseDto findById(String id) {
Database database = databaseRepository.findById(id).orElseGet(Database::new);
ValidationUtil.isNull(database.getId(),"Database","id",id);
return databaseMapper.toDto(database);
......@@ -53,7 +53,7 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
@Transactional(rollbackFor = Exception.class)
public DatabaseDTO create(Database resources) {
public DatabaseDto create(Database resources) {
resources.setId(IdUtil.simpleUUID());
return databaseMapper.toDto(databaseRepository.save(resources));
}
......
......@@ -4,7 +4,7 @@ import cn.hutool.core.util.IdUtil;
import me.zhengjie.modules.mnt.domain.DeployHistory;
import me.zhengjie.modules.mnt.repository.DeployHistoryRepository;
import me.zhengjie.modules.mnt.service.DeployHistoryService;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDTO;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDto;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.DeployHistoryMapper;
import me.zhengjie.utils.PageUtil;
......@@ -45,7 +45,7 @@ public class DeployHistoryServiceImpl implements DeployHistoryService {
}
@Override
public DeployHistoryDTO findById(String id) {
public DeployHistoryDto findById(String id) {
DeployHistory deployhistory = deployhistoryRepository.findById(id).orElseGet(DeployHistory::new);
ValidationUtil.isNull(deployhistory.getId(),"DeployHistory","id",id);
return deployhistoryMapper.toDto(deployhistory);
......@@ -53,7 +53,7 @@ public class DeployHistoryServiceImpl implements DeployHistoryService {
@Override
@Transactional(rollbackFor = Exception.class)
public DeployHistoryDTO create(DeployHistory resources) {
public DeployHistoryDto create(DeployHistory resources) {
resources.setId(IdUtil.simpleUUID());
return deployhistoryMapper.toDto(deployhistoryRepository.save(resources));
}
......
......@@ -67,30 +67,30 @@ public class DeployServiceImpl implements DeployService {
}
@Override
public List<DeployDTO> queryAll(DeployQueryCriteria criteria) {
public List<DeployDto> queryAll(DeployQueryCriteria criteria) {
return deployMapper.toDto(deployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
}
@Override
public DeployDTO findById(Long id) {
Deploy Deploy = deployRepository.findById(id).orElseGet(Deploy::new);
ValidationUtil.isNull(Deploy.getId(), "Deploy", "id", id);
return deployMapper.toDto(Deploy);
public DeployDto findById(Long id) {
Deploy deploy = deployRepository.findById(id).orElseGet(Deploy::new);
ValidationUtil.isNull(deploy.getId(), "Deploy", "id", id);
return deployMapper.toDto(deploy);
}
@Override
@Transactional(rollbackFor = Exception.class)
public DeployDTO create(Deploy resources) {
public DeployDto create(Deploy resources) {
return deployMapper.toDto(deployRepository.save(resources));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(Deploy resources) {
Deploy Deploy = deployRepository.findById(resources.getId()).orElseGet(Deploy::new);
ValidationUtil.isNull(Deploy.getId(), "Deploy", "id", resources.getId());
Deploy.copy(resources);
deployRepository.save(Deploy);
Deploy deploy = deployRepository.findById(resources.getId()).orElseGet(Deploy::new);
ValidationUtil.isNull(deploy.getId(), "Deploy", "id", resources.getId());
deploy.copy(resources);
deployRepository.save(deploy);
}
@Override
......@@ -100,8 +100,8 @@ public class DeployServiceImpl implements DeployService {
}
@Override
public String deploy(String fileSavePath, Long id) {
return deployApp(fileSavePath, id);
public void deploy(String fileSavePath, Long id) {
deployApp(fileSavePath, id);
}
/**
......@@ -111,12 +111,12 @@ public class DeployServiceImpl implements DeployService {
*/
private String deployApp(String fileSavePath, Long id) {
DeployDTO deploy = findById(id);
DeployDto deploy = findById(id);
if (deploy == null) {
sendMsg("部署信息不存在", MsgType.ERROR);
throw new BadRequestException("部署信息不存在");
}
AppDTO app = deploy.getApp();
AppDto app = deploy.getApp();
if (app == null) {
sendMsg("包对应应用信息不存在", MsgType.ERROR);
throw new BadRequestException("包对应应用信息不存在");
......@@ -126,8 +126,8 @@ public class DeployServiceImpl implements DeployService {
String uploadPath = app.getUploadPath();
StringBuilder sb = new StringBuilder();
String msg;
Set<ServerDeployDTO> deploys = deploy.getDeploys();
for (ServerDeployDTO deployDTO : deploys) {
Set<ServerDeployDto> deploys = deploy.getDeploys();
for (ServerDeployDto deployDTO : deploys) {
String ip = deployDTO.getIp();
ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip);
//判断是否第一次部署
......@@ -252,7 +252,7 @@ public class DeployServiceImpl implements DeployService {
return "执行完毕";
}
private boolean checkFile(ExecuteShellUtil executeShellUtil, AppDTO appDTO) {
private boolean checkFile(ExecuteShellUtil executeShellUtil, AppDto appDTO) {
String sb = "find " +
appDTO.getDeployPath() +
" -name " +
......@@ -346,7 +346,8 @@ public class DeployServiceImpl implements DeployService {
//删除原来应用
sendMsg("删除应用", MsgType.INFO);
//考虑到系统安全性,必须限制下操作目录
if (!deployPath.startsWith("/opt")) {
String path = "/opt";
if (!deployPath.startsWith(path)) {
throw new BadRequestException("部署路径必须在opt目录下:" + deployPath);
}
executeShellUtil.execute("rm -rf " + deployPath + FILE_SEPARATOR + resources.getAppName());
......@@ -366,7 +367,7 @@ public class DeployServiceImpl implements DeployService {
}
private ExecuteShellUtil getExecuteShellUtil(String ip) {
ServerDeployDTO serverDeployDTO = serverDeployService.findByIp(ip);
ServerDeployDto serverDeployDTO = serverDeployService.findByIp(ip);
if (serverDeployDTO == null) {
sendMsg("IP对应服务器信息不存在:" + ip, MsgType.ERROR);
throw new BadRequestException("IP对应服务器信息不存在:" + ip);
......@@ -375,7 +376,7 @@ public class DeployServiceImpl implements DeployService {
}
private ScpClientUtil getScpClientUtil(String ip) {
ServerDeployDTO serverDeployDTO = serverDeployService.findByIp(ip);
ServerDeployDto serverDeployDTO = serverDeployService.findByIp(ip);
if (serverDeployDTO == null) {
sendMsg("IP对应服务器信息不存在:" + ip, MsgType.ERROR);
throw new BadRequestException("IP对应服务器信息不存在:" + ip);
......
......@@ -3,7 +3,7 @@ package me.zhengjie.modules.mnt.service.impl;
import me.zhengjie.modules.mnt.domain.ServerDeploy;
import me.zhengjie.modules.mnt.repository.ServerDeployRepository;
import me.zhengjie.modules.mnt.service.ServerDeployService;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDTO;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.ServerDeployMapper;
import me.zhengjie.utils.PageUtil;
......@@ -44,21 +44,21 @@ public class ServerDeployServiceImpl implements ServerDeployService {
}
@Override
public ServerDeployDTO findById(Long id) {
public ServerDeployDto findById(Long id) {
ServerDeploy server = serverDeployRepository.findById(id).orElseGet(ServerDeploy::new);
ValidationUtil.isNull(server.getId(),"ServerDeploy","id",id);
return serverDeployMapper.toDto(server);
}
@Override
public ServerDeployDTO findByIp(String ip) {
public ServerDeployDto findByIp(String ip) {
ServerDeploy deploy = serverDeployRepository.findByIp(ip);
return serverDeployMapper.toDto(deploy);
}
@Override
@Transactional(rollbackFor = Exception.class)
public ServerDeployDTO create(ServerDeploy resources) {
public ServerDeployDto create(ServerDeploy resources) {
return serverDeployMapper.toDto(serverDeployRepository.save(resources));
}
......
......@@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.mnt.domain.App;
import me.zhengjie.modules.mnt.service.dto.AppDTO;
import me.zhengjie.modules.mnt.service.dto.AppDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
......@@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-08-24
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface AppMapper extends BaseMapper<AppDTO, App> {
public interface AppMapper extends BaseMapper<AppDto, App> {
}
......@@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.mnt.domain.Database;
import me.zhengjie.modules.mnt.service.dto.DatabaseDTO;
import me.zhengjie.modules.mnt.service.dto.DatabaseDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
......@@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-08-24
*/
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface DatabaseMapper extends BaseMapper<DatabaseDTO, Database> {
public interface DatabaseMapper extends BaseMapper<DatabaseDto, Database> {
}
......@@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.mnt.domain.DeployHistory;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDTO;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
......@@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-08-24
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface DeployHistoryMapper extends BaseMapper<DeployHistoryDTO, DeployHistory> {
public interface DeployHistoryMapper extends BaseMapper<DeployHistoryDto, DeployHistory> {
}
......@@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.mnt.domain.Deploy;
import me.zhengjie.modules.mnt.service.dto.DeployDTO;
import me.zhengjie.modules.mnt.service.dto.DeployDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
......@@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-08-24
*/
@Mapper(componentModel = "spring",uses = {AppMapper.class, ServerDeployMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface DeployMapper extends BaseMapper<DeployDTO, Deploy> {
public interface DeployMapper extends BaseMapper<DeployDto, Deploy> {
}
......@@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.mnt.domain.ServerDeploy;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDTO;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
......@@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-08-24
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ServerDeployMapper extends BaseMapper<ServerDeployDTO, ServerDeploy> {
public interface ServerDeployMapper extends BaseMapper<ServerDeployDto, ServerDeploy> {
}
......@@ -16,15 +16,15 @@ public class ScpClientUtil {
static private ScpClientUtil instance;
static synchronized public ScpClientUtil getInstance(String IP, int port, String username, String passward) {
static synchronized public ScpClientUtil getInstance(String ip, int port, String username, String passward) {
if (instance == null) {
instance = new ScpClientUtil(IP, port, username, passward);
instance = new ScpClientUtil(ip, port, username, passward);
}
return instance;
}
public ScpClientUtil(String IP, int port, String username, String passward) {
this.ip = IP;
public ScpClientUtil(String ip, int port, String username, String passward) {
this.ip = ip;
this.port = port;
this.username = username;
this.password = passward;
......
......@@ -5,5 +5,12 @@ package me.zhengjie.modules.mnt.websocket;
* @date: 2019-08-10 9:56
*/
public enum MsgType {
CONNECT,CLOSE,INFO,ERROR
/** 连接 */
CONNECT,
/** 关闭 */
CLOSE,
/** 信息 */
INFO,
/** 错误 */
ERROR
}
......@@ -8,6 +8,7 @@ import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* @author: ZhangHouYing
......@@ -58,7 +59,6 @@ public class WebSocketServer {
/**
* 收到客户端消息后调用的方法
*
* @param message 客户端发送过来的消息*/
@OnMessage
public void onMessage(String message, Session session) {
......@@ -73,11 +73,6 @@ public class WebSocketServer {
}
}
/**
*
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
log.error("发生错误");
......@@ -86,7 +81,7 @@ public class WebSocketServer {
/**
* 实现服务器主动推送
*/
public void sendMessage(String message) throws IOException {
private void sendMessage(String message) throws IOException {
this.session.getBasicRemote().sendText(message);
}
......@@ -105,9 +100,25 @@ public class WebSocketServer {
}else if(item.sid.equals(sid)){
item.sendMessage(message);
}
} catch (IOException e) {
continue;
}
} catch (IOException ignored) { }
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
WebSocketServer that = (WebSocketServer) o;
return Objects.equals(session, that.session) &&
Objects.equals(sid, that.sid);
}
@Override
public int hashCode() {
return Objects.hash(session, sid);
}
}
......@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.atomic.AtomicInteger;
/**
*
* @author /
* 接口限流测试类
*/
@RestController
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment