Search in sources :

Example 11 with Server

use of com.ibeiliao.deployment.admin.vo.server.Server 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)

Example 12 with Server

use of com.ibeiliao.deployment.admin.vo.server.Server in project Corgi by kevinYin.

the class ProjectModuleServiceImpl method checkResinPortOccupy.

@Override
public Map<String, String> checkResinPortOccupy(ProjectModule projectModule) {
    if (projectModule.getModuleType() == ModuleType.SERVICE.getValue() || projectModule.getResinConf() == null) {
        return Collections.emptyMap();
    }
    List<ServerGroup> serverGroups = projectModule.getServerGroups();
    if (CollectionUtils.isEmpty(serverGroups)) {
        return Collections.emptyMap();
    }
    List<Server> allServers = Lists.newArrayList();
    for (ServerGroup group : serverGroups) {
        if (CollectionUtils.isNotEmpty(group.getServers())) {
            allServers.addAll(group.getServers());
        }
    }
    if (CollectionUtils.isEmpty(allServers)) {
        return Collections.emptyMap();
    }
    return buildOccupyInfoMap(projectModule, allServers);
}
Also used : ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup) Server(com.ibeiliao.deployment.admin.vo.server.Server)

Example 13 with Server

use of com.ibeiliao.deployment.admin.vo.server.Server in project Corgi by kevinYin.

the class InitTestDataService method createModule.

private ProjectModule createModule(long accountId, Project project, List<ProjectEnv> envs) {
    ProjectModule module = new ProjectModule();
    module.setProjectId(project.getProjectId());
    module.setCompileShell("mvn -P=dev");
    module.setNeedAudit(Constants.TRUE);
    module.setModuleName("test-module");
    module.setModuleNameZh("测试模块");
    module.setModuleType(ModuleType.SERVICE.getValue());
    module.setLogName("");
    module.setPreShell("");
    module.setPostShell("");
    module.setRestartShell("/usr/local/resinpro/bin/resin.sh restart");
    module.setRepoUrl("https://a.b.com/test-project");
    module.setRepoType(ModuleRepoType.SVN.getValue());
    module.setSrcPath("");
    module.setStopShell("");
    module.setSvnAccount("test-account");
    module.setSvnPassword("test-password");
    module.setNeedAudit(Constants.TRUE);
    ProjectEnv env = envs.get(0);
    List<ServerGroup> serverGroups = new ArrayList<>();
    ServerGroup group1 = new ServerGroup();
    group1.setEnvId(env.getEnvId());
    group1.setGroupName("dev test");
    serverGroups.add(group1);
    projectModuleService.saveProjectModule(accountId, module);
    List<Server> servers = new ArrayList<>();
    final int MAX_SERVERS = 8;
    for (int i = 0; i < MAX_SERVERS; i++) {
        servers.add(createServer(i));
    }
    group1.setServers(servers);
    module.setServerGroups(serverGroups);
    projectModuleService.saveProjectModule(accountId, module);
    ProjectModule tmpModule = projectModuleService.getByModuleId(module.getModuleId());
    Assert.notNull(tmpModule);
    Assert.isTrue(tmpModule.getNeedAudit() == Constants.TRUE);
    // 要重新读一次数据
    List<ServerGroup> newServerGroups = serverGroupService.getByModuleIds(Lists.newArrayList(module.getModuleId()), false);
    module.setServerGroups(newServerGroups);
    for (ServerGroup tmpGroup : newServerGroups) {
        List<Integer> groupIds = new LinkedList<>();
        groupIds.add(tmpGroup.getGroupId());
        List<Server> newServers = serverService.getByGroupIds(groupIds);
        tmpGroup.setServers(newServers);
    }
    return module;
}
Also used : ProjectModule(com.ibeiliao.deployment.admin.vo.project.ProjectModule) ProjectEnv(com.ibeiliao.deployment.admin.vo.global.ProjectEnv) ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup) Server(com.ibeiliao.deployment.admin.vo.server.Server)

Example 14 with Server

use of com.ibeiliao.deployment.admin.vo.server.Server in project Corgi by kevinYin.

the class ModuleServiceTest method fillServerGroupInfo.

private void fillServerGroupInfo(ProjectModule module) {
    ServerGroup group = new ServerGroup();
    group.setGroupId(129);
    group.setModuleId(43);
    group.setCreateTime(new Date());
    group.setEnvId(1);
    group.setGroupName("online01111");
    Server server1 = new Server();
    server1.setServerId(22);
    server1.setGroupId(129);
    server1.setCreateTime(new Date());
    server1.setServerName("server00008888");
    server1.setIp("192.168.0.1");
    Server server2 = new Server();
    server2.setGroupId(129);
    server2.setCreateTime(new Date());
    server2.setServerName("server000099");
    server2.setIp("192.168.0.4");
    group.setServers(Lists.newArrayList(server1, server2));
    module.setServerGroups(Lists.newArrayList(group));
}
Also used : ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup) Server(com.ibeiliao.deployment.admin.vo.server.Server) Date(java.util.Date)

Example 15 with Server

use of com.ibeiliao.deployment.admin.vo.server.Server in project Corgi by kevinYin.

the class ServerGroupServiceImpl method fillInServer.

private void fillInServer(List<ServerGroup> groups) {
    List<Integer> groupIds = Lists.newArrayList();
    for (ServerGroup group : groups) {
        groupIds.add(group.getGroupId());
    }
    List<Server> servers = serverService.getByGroupIds(groupIds);
    if (CollectionUtils.isEmpty(servers)) {
        return;
    }
    ArrayListMultimap<Integer, Server> groupId2ServersMap = ArrayListMultimap.create();
    for (Server server : servers) {
        groupId2ServersMap.put(server.getGroupId(), server);
    }
    for (ServerGroup group : groups) {
        if (groupId2ServersMap.get(group.getGroupId()) != null) {
            group.setServers(groupId2ServersMap.get(group.getGroupId()));
        }
    }
}
Also used : ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup) Server(com.ibeiliao.deployment.admin.vo.server.Server)

Aggregations

Server (com.ibeiliao.deployment.admin.vo.server.Server)15 ServerGroup (com.ibeiliao.deployment.admin.vo.server.ServerGroup)11 ServerDeployHistoryPO (com.ibeiliao.deployment.admin.po.deploy.ServerDeployHistoryPO)3 ProjectModule (com.ibeiliao.deployment.admin.vo.project.ProjectModule)3 DeployHistoryPO (com.ibeiliao.deployment.admin.po.deploy.DeployHistoryPO)2 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 ModuleConfPO (com.ibeiliao.deployment.admin.po.project.ModuleConfPO)1 ProjectModulePO (com.ibeiliao.deployment.admin.po.project.ProjectModulePO)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 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1