Search in sources :

Example 6 with Server

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

the class ProjectModuleServiceImpl method saveServerGroupAndServer.

private void saveServerGroupAndServer(List<ServerGroup> groups, int moduleId) {
    if (CollectionUtils.isEmpty(groups)) {
        return;
    }
    List<ServerGroup> needUpdateGroups = Lists.newArrayList();
    List<Server> needUpdateServers = Lists.newArrayList();
    List<Integer> oldServerGroupIds = Lists.newArrayList();
    List<Integer> oldServerIds = Lists.newArrayList();
    for (ServerGroup group : groups) {
        group.setModuleId(moduleId);
        if (group.getGroupId() <= 0) {
            continue;
        }
        needUpdateGroups.add(group);
        oldServerGroupIds.add(group.getGroupId());
        if (CollectionUtils.isNotEmpty(group.getServers())) {
            for (Server server : group.getServers()) {
                if (server.getServerId() > 0) {
                    oldServerIds.add(server.getServerId());
                    needUpdateServers.add(server);
                }
                server.setIp(StringUtils.trimToEmpty(server.getIp()));
            }
        }
    }
    // 删除被删除的服务器组
    serverGroupService.deleteByOldGroupIds(oldServerGroupIds, moduleId);
    // 先删除提交后不存在的服务器
    serverService.deleteByServerGroupIdsAndServerIds(oldServerGroupIds, oldServerIds);
    // 更新服务器组和服务器
    for (ServerGroup group : needUpdateGroups) {
        serverGroupService.updateGroup(group);
    }
    for (Server server : needUpdateServers) {
        serverService.updateServer(server);
    }
    // 插入新增的服务器组合服务器
    insertServerGroupAndServer(groups, moduleId);
}
Also used : ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup) Server(com.ibeiliao.deployment.admin.vo.server.Server)

Example 7 with Server

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

the class DeployHistoryServiceImpl method saveDeployServers.

private void saveDeployServers(DeployHistoryPO po, DeploymentOrder order, List<Server> servers) {
    Map<Integer, Server> serverMap = new HashMap<>(servers.size() * 4 / 3);
    for (Server server : servers) {
        serverMap.put(server.getServerId(), server);
    }
    for (int serverId : order.getServerId()) {
        ServerDeployHistoryPO serverDeployHistoryPO = new ServerDeployHistoryPO();
        serverDeployHistoryPO.setHistoryId(po.getHistoryId());
        serverDeployHistoryPO.setServerId(serverId);
        Server server = serverMap.get(serverId);
        serverDeployHistoryPO.setServerName(server.getServerName());
        serverDeployHistoryPO.setServerIp(server.getIp());
        serverDeployHistoryPO.setDeployStatus(ServerDeployResult.WAITING_FOR_DEPLOYMENT.getValue());
        serverDeployHistoryDao.insert(serverDeployHistoryPO);
    }
}
Also used : Server(com.ibeiliao.deployment.admin.vo.server.Server) ServerDeployHistoryPO(com.ibeiliao.deployment.admin.po.deploy.ServerDeployHistoryPO)

Example 8 with Server

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

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

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

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