Search in sources :

Example 1 with RestResult

use of com.ibeiliao.deployment.admin.common.RestResult in project Corgi by kevinYin.

the class EditRoleController method updateRole.

/**
 * 增加或修改角色信息
 * @param role JSON格式数据, {roleId:角色ID, rolename:角色名称, remarks:备注}
 * @param menuIds JSON格式数据,菜单ID列表 []
 * @param resIds JSON格式数据,资源ID列表 []
 * @param appIds JSON格式数据,APP ID 列表 []
 * @return result.success=true表示成功
 */
@MenuResource("增加/修改角色信息")
@RequestMapping(value = "updateRole.do", method = RequestMethod.POST)
@AdminLog
@ResponseBody
public RestResult<Object> updateRole(String role, String menuIds, String resIds, String appIds) {
    logger.info("admin#role#updateRole | 新增/修改角色 | role: " + role + ", menuIds: " + menuIds + ", resIds: " + resIds + ", appIds: " + appIds);
    ParameterUtil.assertNotBlank(role, "role不能为空");
    ParameterUtil.assertNotBlank(menuIds, "menuIds不能为空");
    ParameterUtil.assertNotBlank(resIds, "resIds不能为空");
    Map<String, Object> myRole = JsonUtil.parseObject(role, new TypeReference<HashMap<String, Object>>() {
    });
    List<Integer> menuIdList = JsonUtil.parseObject(menuIds, new TypeReference<List<Integer>>() {
    });
    List<Integer> appIdList = JsonUtil.parseObject(appIds, new TypeReference<List<Integer>>() {
    });
    List<Integer> resIdList = JsonUtil.parseObject(resIds, new TypeReference<List<Integer>>() {
    });
    logger.info("admin#role#updateRole | 新增/修改角色 | role: {}, menuIdList: {}, appIdList: {} ", JsonUtil.toJSONString(myRole), JsonUtil.toJSONString(menuIdList), JsonUtil.toJSONString(appIdList));
    Role theRole = validateRole(myRole, menuIdList, appIdList);
    roleService.authRole(theRole, ListUtils.toSet(appIdList), ListUtils.toSet(menuIdList), ListUtils.toSet(resIdList));
    return new RestResult<>(ApiCode.SUCCESS, "操作成功.");
}
Also used : Role(com.ibeiliao.deployment.admin.vo.account.Role) RestResult(com.ibeiliao.deployment.admin.common.RestResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) AdminLog(com.ibeiliao.deployment.admin.annotation.log.AdminLog) MenuResource(com.ibeiliao.deployment.admin.utils.resource.MenuResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with RestResult

use of com.ibeiliao.deployment.admin.common.RestResult in project Corgi by kevinYin.

the class CreateDeploymentController method enoughServerRes.

/**
 * 判断服务器资源是否足够
 * @param order
 * @return ApiCode.SUCCESS=足够
 * @author linyi 2017/5/11
 */
private RestResult<Object> enoughServerRes(DeploymentOrder order) {
    List<DeployHistory> histories = deployHistoryService.queryDeployHistory(order.getEnvId(), order.getModuleId(), 1, 10);
    // 静态项目不做判断
    ProjectModule module = projectModuleService.getByModuleId(order.getModuleId());
    if (module.getModuleType() == ModuleType.STATIC.getValue()) {
        return new RestResult<>(ApiCode.SUCCESS, "");
    }
    /* if (CollectionUtils.isEmpty(histories)) {
            logger.info("第一次发布");
            String jvmArgs = getJvmArgs(order.getModuleId(), order.getEnvId());
            for (int serverId : order.getServerId()) {
                Server server = serverService.getById(serverId);
                if (server == null || StringUtils.isBlank(server.getIp())) {
                    return new RestResult<>(ApiCode.FAILURE, "serverId或IP不存在, serverId: " + serverId);
                }
                RestResult<Object> result = AliyunEcsUtil.isEnoughResByIp(server.getIp(), jvmArgs);
                if (!result.isSuccess()) {
                    return result;
                }
            }
        }*/
    return new RestResult<>(ApiCode.SUCCESS, "");
}
Also used : ProjectModule(com.ibeiliao.deployment.admin.vo.project.ProjectModule) RestResult(com.ibeiliao.deployment.admin.common.RestResult) DeployHistory(com.ibeiliao.deployment.admin.vo.deploy.DeployHistory)

Example 3 with RestResult

use of com.ibeiliao.deployment.admin.common.RestResult in project Corgi by kevinYin.

the class CreateDeploymentController method listRepository.

@RequestMapping("listRepository")
@MenuResource("查询分支列表")
@ResponseBody
public RestResult<List<Map<String, Object>>> listRepository(int moduleId) {
    ProjectModule module = projectModuleService.getByModuleId(moduleId);
    List<Map<String, Object>> tags = new ArrayList<>();
    if (module != null) {
        if (module.getRepoType() == ModuleRepoType.SVN.getValue()) {
            String tagsPath = (module.getRepoUrl() + RepositoryConstants.TAGS).replaceAll("/" + RepositoryConstants.TAGS, RepositoryConstants.TAGS);
            tags.addAll(fetchSvnTags(tagsPath, module));
            String branchesPath = (module.getRepoUrl() + RepositoryConstants.BRANCHES).replaceAll("/" + RepositoryConstants.BRANCHES, RepositoryConstants.BRANCHES);
            tags.addAll(fetchSvnTags(branchesPath, module));
        } else if (module.getRepoType() == ModuleRepoType.GIT.getValue()) {
            tags.addAll(fetchGitBranches(module.getRepoUrl(), module));
        } else {
            logger.warn("不支持类型 {}, moduleId: {}", module.getRepoType(), moduleId);
        }
    } else {
        logger.error("module=null, moduleId: " + moduleId);
    }
    return new RestResult<>(tags);
}
Also used : ProjectModule(com.ibeiliao.deployment.admin.vo.project.ProjectModule) RestResult(com.ibeiliao.deployment.admin.common.RestResult) MenuResource(com.ibeiliao.deployment.admin.utils.resource.MenuResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with RestResult

use of com.ibeiliao.deployment.admin.common.RestResult in project Corgi by kevinYin.

the class CreateDeploymentController method queryModuleServer.

/**
 * 查询模块在某个环境的服务器列表
 *
 * @param moduleId 模块ID
 * @param envId    环境ID,必定大于0
 * @return
 */
@RequestMapping("queryModuleServer")
@ResponseBody
@MenuResource("查询模块服务器列表")
public RestResult<Map<String, Object>> queryModuleServer(int moduleId, int envId) {
    Assert.isTrue(moduleId > 0);
    Assert.isTrue(envId > 0);
    List<ServerGroup> groups = serverGroupService.getByModuleAndEnv(moduleId, envId);
    List<Integer> groupIds = new ArrayList<>(groups.size());
    for (ServerGroup group : groups) {
        groupIds.add(group.getGroupId());
    }
    List<Server> servers = serverService.getByGroupIds(groupIds);
    Map<String, Object> result = new HashMap<>(4);
    result.put("servers", servers);
    result.put("groups", groups);
    return new RestResult<>(result);
}
Also used : ServerGroup(com.ibeiliao.deployment.admin.vo.server.ServerGroup) RestResult(com.ibeiliao.deployment.admin.common.RestResult) Server(com.ibeiliao.deployment.admin.vo.server.Server) MenuResource(com.ibeiliao.deployment.admin.utils.resource.MenuResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with RestResult

use of com.ibeiliao.deployment.admin.common.RestResult in project Corgi by kevinYin.

the class MenuController method updateMenu.

/**
 * 重新生成系统菜单
 *
 * @return
 */
@ResponseBody
@RequestMapping("updateMenu.do")
public RestResult<Object> updateMenu(HttpServletRequest request) {
    int appId = getAppId(request);
    logger.info("将更新菜单, appId=" + appId);
    RestResult<Object> result = null;
    if (appId > 0) {
        String[] scanPath = getScanPath(appId);
        try {
            MenuItem root = SearchResource.scanMenuTree(scanPath);
            menuService.updateMenu(appId, root);
            logger.info("更新菜单成功,菜单: " + JsonUtil.toJSONString(root));
            result = new RestResult<>(ApiCode.SUCCESS, "成功");
        } catch (Exception e) {
            logger.error("重新生成系统菜单错误, appId=" + appId, e);
            result = new RestResult<>(ApiCode.FAILURE, e.getMessage());
        }
    } else {
        result = new RestResult<>(ApiCode.FAILURE, "appId为空");
    }
    return result;
}
Also used : RestResult(com.ibeiliao.deployment.admin.common.RestResult) MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RestResult (com.ibeiliao.deployment.admin.common.RestResult)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 MenuResource (com.ibeiliao.deployment.admin.utils.resource.MenuResource)8 AdminAccount (com.ibeiliao.deployment.admin.vo.account.AdminAccount)2 DeployHistory (com.ibeiliao.deployment.admin.vo.deploy.DeployHistory)2 GlobalSetting (com.ibeiliao.deployment.admin.vo.global.GlobalSetting)2 ProjectEnv (com.ibeiliao.deployment.admin.vo.global.ProjectEnv)2 ProjectModule (com.ibeiliao.deployment.admin.vo.project.ProjectModule)2 AllowAnonymous (com.ibeiliao.deployment.admin.annotation.authority.AllowAnonymous)1 AdminLog (com.ibeiliao.deployment.admin.annotation.log.AdminLog)1 AdminLoginUser (com.ibeiliao.deployment.admin.context.AdminLoginUser)1 MenuItem (com.ibeiliao.deployment.admin.utils.resource.MenuItem)1 Role (com.ibeiliao.deployment.admin.vo.account.Role)1 Server (com.ibeiliao.deployment.admin.vo.server.Server)1 ServerGroup (com.ibeiliao.deployment.admin.vo.server.ServerGroup)1 TransferResult (com.ibeiliao.deployment.transfer.vo.TransferResult)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1