use of com.ibeiliao.deployment.admin.vo.server.ServerGroup in project Corgi by kevinYin.
the class ViewProjectController method fillServerGroupIntoModule.
private void fillServerGroupIntoModule(List<ProjectModule> modules) {
if (CollectionUtils.isEmpty(modules)) {
return;
}
List<Integer> moduleIds = Lists.newArrayList();
for (ProjectModule module : modules) {
moduleIds.add(module.getModuleId());
}
List<ServerGroup> serverGroups = serverGroupService.getByModuleIds(moduleIds, true);
ArrayListMultimap<Integer, ServerGroup> moduleId2ServerGroupsMap = ArrayListMultimap.create();
for (ServerGroup group : serverGroups) {
moduleId2ServerGroupsMap.put(group.getModuleId(), group);
}
for (ProjectModule module : modules) {
if (moduleId2ServerGroupsMap.get(module.getModuleId()) != null) {
module.setServerGroups(moduleId2ServerGroupsMap.get(module.getModuleId()));
}
}
}
use of com.ibeiliao.deployment.admin.vo.server.ServerGroup in project Corgi by kevinYin.
the class DeployHistoryServiceImpl method checkServerStatus.
private List<Server> checkServerStatus(DeploymentOrder order) {
if (order.getServerId() == null || order.getServerId().length == 0) {
throw new IllegalArgumentException("服务器列表不能为空");
}
Map<Integer, Integer> serverGroupEnvMap = new HashMap<>();
List<Server> servers = serverService.getByIds(order.getServerId());
if (servers.size() != order.getServerId().length) {
throw new IllegalStateException("serverId不存在");
}
for (Server server : servers) {
if (!serverGroupEnvMap.containsKey(server.getGroupId())) {
ServerGroup serverGroup = serverGroupService.getById(server.getGroupId());
if (serverGroup == null) {
throw new IllegalArgumentException("服务器组不存在,serverId=" + server.getServerId() + ", groupId=" + server.getGroupId());
}
if (serverGroup.getEnvId() != order.getEnvId()) {
throw new IllegalArgumentException("服务器组【" + serverGroup.getGroupName() + "】所在的环境不一致");
}
serverGroupEnvMap.put(serverGroup.getGroupId(), serverGroup.getEnvId());
}
}
return servers;
}
use of com.ibeiliao.deployment.admin.vo.server.ServerGroup in project Corgi by kevinYin.
the class DeployHistoryServiceImpl method createAndSaveRestart.
private DeployHistoryPO createAndSaveRestart(long accountId, String title, int serverId) {
Server server = serverService.getById(serverId);
AdminAccount account = adminAccountService.getById(accountId);
Assert.notNull(server, "服务器不存在");
Assert.notNull(account, "管理员不存在");
ServerGroup serverGroup = serverGroupService.getById(server.getGroupId());
ProjectModule module = projectModuleService.getByModuleId(serverGroup.getModuleId());
DeployHistoryPO po = new DeployHistoryPO();
po.setTagName("");
po.setAccountId(accountId);
po.setAuditorId(0);
po.setTitle(title);
po.setCreateTime(new Date());
po.setDeployStatus(DeployStatus.WAITING_FOR_DEPLOYMENT.getValue());
po.setAuditTime(po.getCreateTime());
po.setDeployServers(1);
po.setProjectId(module.getProjectId());
po.setModuleId(module.getModuleId());
po.setModuleName(module.getModuleName());
po.setVersionNo("");
po.setIsRestart(Constants.TRUE);
po.setEnvId(serverGroup.getEnvId());
po.setRealName(account.getRealname());
deployHistoryDao.insert(po);
ServerDeployHistoryPO serverDeployHistoryPO = new ServerDeployHistoryPO();
serverDeployHistoryPO.setHistoryId(po.getHistoryId());
serverDeployHistoryPO.setServerId(serverId);
serverDeployHistoryPO.setServerName(server.getServerName());
serverDeployHistoryPO.setServerIp(server.getIp());
serverDeployHistoryPO.setDeployStatus(ServerDeployResult.WAITING_FOR_DEPLOYMENT.getValue());
serverDeployHistoryDao.insert(serverDeployHistoryPO);
return deployHistoryDao.get(po.getHistoryId());
}
use of com.ibeiliao.deployment.admin.vo.server.ServerGroup in project Corgi by kevinYin.
the class ViewProjectController method createTransferRequest.
private TransferRequest createTransferRequest(int serverId, boolean restart) throws Exception {
Server server = serverService.getById(serverId);
Assert.notNull(server, "server不存在");
ServerGroup serverGroup = serverGroupService.getById(server.getGroupId());
Assert.notNull(serverGroup, "serverGroup不存在");
ProjectModule module = projectModuleService.getByModuleId(serverGroup.getModuleId());
Project project = projectService.getProject(module.getProjectId());
ProjectEnv env = projectEnvService.getById(serverGroup.getEnvId());
long accountId = AdminContext.getAccountId();
// if (projectAccountRelationService.canModify(accountId, project.getProjectId())) {
DeployHistory deployHistory = null;
if (restart) {
deployHistory = deployHistoryService.createRestartHistory(accountId, serverId);
} else {
deployHistory = deployHistoryService.createStopHistory(accountId, serverId);
}
TransferRequest request = new TransferRequest();
request.setHistoryId(deployHistory.getHistoryId());
request.setSaveFileName(null);
request.setModuleName(module.getModuleName());
request.setEnv(env.getEnvName());
request.setProjectName(project.getProjectNo());
request.setRestartShell(module.getRestartShell());
request.setJvmArgs(getModuleJvmArgs(module.getModuleId(), serverGroup.getEnvId()));
request.setPreDeployShell(module.getPreShell());
request.setPostDeployShell(module.getPostShell());
request.setStopShell(module.getStopShell());
request.setModuleType(module.getModuleType());
List<String> serverIps = new ArrayList<>();
serverIps.add(server.getIp());
request.setTargetServerIps(serverIps);
if (module.getModuleType() == ModuleType.WEB_PROJECT.getValue()) {
ResinConf resinConf = module.getResinConf();
// 设置 [当前环境] 的域名
resinConf.setDomain(ModuleUtil.getDomainForEnv(resinConf.getDomain(), env.getEnvName()));
resinConf.setAliasDomain(ModuleUtil.getAliasDomainForEnv(resinConf.getAliasDomain(), env.getEnvName()));
request.setModuleFinalName(readFinalName(module, deployHistory.getTagName()));
request.setResinConf(resinConf);
if (!projectModuleService.isResinConfCreated(deployHistory.getModuleId()) || resinConf.isCreateEveryTime()) {
request.setCreateResinConf(true);
}
}
return request;
// }
// throw new IllegalStateException("你没有权限操作,请联系项目负责人或超级管理员");
}
use of com.ibeiliao.deployment.admin.vo.server.ServerGroup in project Corgi by kevinYin.
the class ProjectModuleServiceImpl method buildOccupyInfoMap.
private Map<String, String> buildOccupyInfoMap(ProjectModule projectModule, List<Server> allServers) {
List<ModuleConfPO> matchModuleConfList = getModuleConf(projectModule);
if (CollectionUtils.isEmpty(matchModuleConfList)) {
return Collections.emptyMap();
}
List<Integer> moduleIds = Lists.newArrayList();
for (ModuleConfPO po : matchModuleConfList) {
if (projectModule.getModuleId() > 0 && po.getModuleId() == projectModule.getModuleId()) {
continue;
}
moduleIds.add(po.getModuleId());
}
List<ServerGroup> serverGroupList = serverGroupService.getByModuleIds(moduleIds, true);
if (CollectionUtils.isEmpty(serverGroupList)) {
return Collections.emptyMap();
}
List<ProjectModulePO> modulePOs = projectModuleDao.getByModuleIds(moduleIds);
HashMap<Integer, ProjectModulePO> moduleId2ModuleMap = Maps.newHashMap();
for (ProjectModulePO modulePO : modulePOs) {
moduleId2ModuleMap.put(modulePO.getModuleId(), modulePO);
}
HashMap<Integer, ModuleConfPO> moduleId2ConfMap = Maps.newHashMap();
for (ModuleConfPO confPO : matchModuleConfList) {
moduleId2ConfMap.put(confPO.getModuleId(), confPO);
}
Set<String> moduleServerIps = Sets.newHashSet();
for (Server server : allServers) {
moduleServerIps.add(server.getIp());
}
HashMap<String, String> port2OccupyInfoMap = Maps.newHashMap();
// 找到有相同的服务器,再看看是哪个端口有冲突
for (ServerGroup group : serverGroupList) {
List<Server> servers = group.getServers();
if (CollectionUtils.isEmpty(servers)) {
continue;
}
for (Server server : servers) {
if (moduleServerIps.contains(server.getIp()) && moduleId2ModuleMap.get(group.getModuleId()) != null && moduleId2ConfMap.get(group.getModuleId()) != null) {
ProjectModulePO modulePO = moduleId2ModuleMap.get(group.getModuleId());
ModuleConfPO confPO = moduleId2ConfMap.get(group.getModuleId());
ResinConf resinConf = projectModule.getResinConf();
String occupyInfo = " 已被项目id为 " + modulePO.getProjectId() + " 的" + modulePO.getModuleNameZh() + " 模块所占用,相关服务器IP为 " + server.getIp();
if (confPO.getConfValue().contains("\"httpPort\":" + resinConf.getHttpPort())) {
port2OccupyInfoMap.put("http端口" + resinConf.getHttpPort(), occupyInfo);
}
if (confPO.getConfValue().contains("\"serverPort\":" + resinConf.getServerPort())) {
port2OccupyInfoMap.put("服务器端口" + resinConf.getServerPort(), occupyInfo);
}
if (confPO.getConfValue().contains("\"watchdogPort\":" + resinConf.getWatchdogPort())) {
port2OccupyInfoMap.put("watchdog端口" + resinConf.getWatchdogPort(), occupyInfo);
}
}
}
}
return port2OccupyInfoMap;
}
Aggregations