Search in sources :

Example 6 with ServerGroup

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()));
        }
    }
}
Also used : ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup)

Example 7 with ServerGroup

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;
}
Also used : ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup) Server(com.ibeiliao.deployment.admin.vo.server.Server)

Example 8 with ServerGroup

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());
}
Also used : ProjectModule(com.ibeiliao.deployment.admin.vo.project.ProjectModule) ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup) Server(com.ibeiliao.deployment.admin.vo.server.Server) ServerDeployHistoryPO(com.ibeiliao.deployment.admin.po.deploy.ServerDeployHistoryPO) DeployHistoryPO(com.ibeiliao.deployment.admin.po.deploy.DeployHistoryPO) ServerDeployHistoryPO(com.ibeiliao.deployment.admin.po.deploy.ServerDeployHistoryPO) AdminAccount(com.ibeiliao.deployment.admin.vo.account.AdminAccount)

Example 9 with ServerGroup

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("你没有权限操作,请联系项目负责人或超级管理员");
}
Also used : ResinConf(com.ibeiliao.deployment.transfer.vo.ResinConf) ProjectEnv(com.ibeiliao.deployment.admin.vo.global.ProjectEnv) ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup) Server(com.ibeiliao.deployment.admin.vo.server.Server) ArrayList(java.util.ArrayList) DeployHistory(com.ibeiliao.deployment.admin.vo.deploy.DeployHistory) TransferRequest(com.ibeiliao.deployment.transfer.vo.TransferRequest)

Example 10 with ServerGroup

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;
}
Also used : ResinConf(com.ibeiliao.deployment.transfer.vo.ResinConf) ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup) Server(com.ibeiliao.deployment.admin.vo.server.Server) ModuleConfPO(com.ibeiliao.deployment.admin.po.project.ModuleConfPO) ProjectModulePO(com.ibeiliao.deployment.admin.po.project.ProjectModulePO)

Aggregations

ServerGroup (com.ibeiliao.deployment.admin.vo.server.ServerGroup)14 Server (com.ibeiliao.deployment.admin.vo.server.Server)11 ProjectModule (com.ibeiliao.deployment.admin.vo.project.ProjectModule)3 ProjectEnv (com.ibeiliao.deployment.admin.vo.global.ProjectEnv)2 ResinConf (com.ibeiliao.deployment.transfer.vo.ResinConf)2 RestResult (com.ibeiliao.deployment.admin.common.RestResult)1 DeployHistoryPO (com.ibeiliao.deployment.admin.po.deploy.DeployHistoryPO)1 ServerDeployHistoryPO (com.ibeiliao.deployment.admin.po.deploy.ServerDeployHistoryPO)1 ModuleConfPO (com.ibeiliao.deployment.admin.po.project.ModuleConfPO)1 ProjectModulePO (com.ibeiliao.deployment.admin.po.project.ProjectModulePO)1 ServerPO (com.ibeiliao.deployment.admin.po.server.ServerPO)1 MenuResource (com.ibeiliao.deployment.admin.utils.resource.MenuResource)1 AdminAccount (com.ibeiliao.deployment.admin.vo.account.AdminAccount)1 DeployHistory (com.ibeiliao.deployment.admin.vo.deploy.DeployHistory)1 TransferRequest (com.ibeiliao.deployment.transfer.vo.TransferRequest)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1