Search in sources :

Example 16 with AppUser

use of com.sohu.cache.entity.AppUser in project cachecloud by sohutv.

the class ImportAppController method genAppDesc.

/**
     * 生成AppDesc
     * 
     * @param request
     * @return
     */
private AppDesc genAppDesc(HttpServletRequest request) {
    // 当前用户
    AppUser currentUser = getUserInfo(request);
    // 当前时间
    Date date = new Date();
    // 组装Appdesc
    AppDesc appDesc = new AppDesc();
    appDesc.setName(request.getParameter("name"));
    appDesc.setIntro(request.getParameter("intro"));
    appDesc.setOfficer(request.getParameter("officer"));
    appDesc.setType(NumberUtils.toInt(request.getParameter("type")));
    appDesc.setIsTest(NumberUtils.toInt(request.getParameter("isTest")));
    appDesc.setMemAlertValue(NumberUtils.toInt(request.getParameter("memAlertValue")));
    appDesc.setUserId(currentUser.getId());
    appDesc.setStatus(2);
    appDesc.setCreateTime(date);
    appDesc.setPassedTime(date);
    appDesc.setVerId(1);
    return appDesc;
}
Also used : AppUser(com.sohu.cache.entity.AppUser) AppDesc(com.sohu.cache.entity.AppDesc) Date(java.util.Date)

Example 17 with AppUser

use of com.sohu.cache.entity.AppUser in project cachecloud by sohutv.

the class InstanceAlertValueController method update.

/**
     * 修改配置
     */
@RequestMapping(value = "/update")
public ModelAndView update(HttpServletRequest request, HttpServletResponse response, Model model) {
    AppUser appUser = getUserInfo(request);
    String configKey = request.getParameter("configKey");
    String alertValue = request.getParameter("alertValue");
    int compareType = NumberUtils.toInt(request.getParameter("compareType"));
    int valueType = NumberUtils.toInt(request.getParameter("valueType"));
    String info = request.getParameter("info");
    int status = NumberUtils.toInt(request.getParameter("status"), -1);
    if (StringUtils.isBlank(configKey) || status > 1 || status < 0) {
        model.addAttribute("status", SuccessEnum.FAIL.value());
        model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + ",configKey=" + configKey + ",alertValue=" + alertValue + ",status=" + status);
        return new ModelAndView("");
    }
    //开始修改
    logger.warn("user {} want to change instance alert configKey={}, alertValue={}, info={}, status={}", appUser.getName(), configKey, alertValue, info, status);
    SuccessEnum successEnum;
    InstanceAlert instanceAlert = instanceAlertValueService.getByConfigKey(configKey);
    try {
        instanceAlert.setAlertValue(alertValue);
        instanceAlert.setValueType(valueType);
        instanceAlert.setInfo(info);
        instanceAlert.setStatus(status);
        instanceAlert.setCompareType(compareType);
        instanceAlertValueService.saveOrUpdate(instanceAlert);
        successEnum = SuccessEnum.SUCCESS;
    } catch (Exception e) {
        successEnum = SuccessEnum.FAIL;
        model.addAttribute("message", ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
        logger.error(e.getMessage(), e);
    }
    logger.warn("user {} want to change instance alert configKey={}, alertValue={}, info={}, status={}, result is {}", appUser.getName(), configKey, alertValue, info, status, successEnum.value());
    model.addAttribute("status", successEnum.value());
    return new ModelAndView("");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.sohu.cache.entity.AppUser) InstanceAlert(com.sohu.cache.entity.InstanceAlert) SuccessEnum(com.sohu.cache.web.enums.SuccessEnum) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with AppUser

use of com.sohu.cache.entity.AppUser in project cachecloud by sohutv.

the class InstanceAlertValueController method add.

/**
     * 添加配置
     */
@RequestMapping(value = "/add")
public ModelAndView add(HttpServletRequest request, HttpServletResponse response, Model model) {
    AppUser appUser = getUserInfo(request);
    InstanceAlert instanceAlert = getInstanceAlert(request);
    if (StringUtils.isBlank(instanceAlert.getConfigKey())) {
        model.addAttribute("status", SuccessEnum.FAIL.value());
        model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + "configKey=" + instanceAlert.getConfigKey());
        return new ModelAndView("");
    }
    logger.warn("user {} want to add instance alert, configKey is {}, alertValue is {}, info is {}, orderId is {}", appUser.getName(), instanceAlert.getConfigKey(), instanceAlert.getAlertValue(), instanceAlert.getInfo(), instanceAlert.getOrderId());
    SuccessEnum successEnum;
    try {
        instanceAlertValueService.saveOrUpdate(instanceAlert);
        successEnum = SuccessEnum.SUCCESS;
    } catch (Exception e) {
        successEnum = SuccessEnum.FAIL;
        model.addAttribute("message", ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
        logger.error(e.getMessage(), e);
    }
    logger.warn("user {} want to add instance alert, configKey is {}, alertValue is {}, info is {}, orderId is {}, result is {}", appUser.getName(), instanceAlert.getConfigKey(), instanceAlert.getAlertValue(), instanceAlert.getInfo(), instanceAlert.getOrderId(), successEnum.info());
    model.addAttribute("status", successEnum.value());
    return new ModelAndView("");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.sohu.cache.entity.AppUser) InstanceAlert(com.sohu.cache.entity.InstanceAlert) SuccessEnum(com.sohu.cache.web.enums.SuccessEnum) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with AppUser

use of com.sohu.cache.entity.AppUser in project cachecloud by sohutv.

the class InstanceManageController method doShutdownInstance.

/**
     * 下线实例
     * 
     * @param instanceId
     * @param ip
     */
@RequestMapping(value = "/shutdownInstance")
public ModelAndView doShutdownInstance(HttpServletRequest request, HttpServletResponse response, Model model, int instanceId) {
    AppUser appUser = getUserInfo(request);
    logger.warn("user {} shutdownInstance {} ", appUser.getName(), instanceId);
    boolean result = false;
    if (instanceId > 0) {
        try {
            result = instanceDeployCenter.shutdownExistInstance(instanceId);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            model.addAttribute("message", e.getMessage());
        }
    } else {
        logger.error("doShutdownInstance instanceId:{}", instanceId);
        model.addAttribute("message", "wrong param");
    }
    logger.warn("user {} shutdownInstance {}, result is {}", appUser.getName(), instanceId, result);
    if (result) {
        model.addAttribute("success", SuccessEnum.SUCCESS.value());
    } else {
        model.addAttribute("success", SuccessEnum.FAIL.value());
    }
    return new ModelAndView();
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) AppUser(com.sohu.cache.entity.AppUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with AppUser

use of com.sohu.cache.entity.AppUser in project cachecloud by sohutv.

the class BaseController method checkAppUserProvilege.

/**
     * 查看用户对于app操作的权限
     * @param request
     * @param appId
     * @return
     */
protected boolean checkAppUserProvilege(HttpServletRequest request, long appId) {
    // 当前用户
    AppUser currentUser = getUserInfo(request);
    if (currentUser == null) {
        logger.error("currentUser is empty");
        return false;
    }
    if (AppUserTypeEnum.ADMIN_USER.value().equals(currentUser.getType())) {
        return true;
    }
    // 应用用户列表
    List<AppToUser> appToUsers = appService.getAppToUserList(appId);
    if (CollectionUtils.isEmpty(appToUsers)) {
        logger.error("appId {} userList is empty", appId);
        return false;
    }
    // 应用下用户id集合
    Set<Long> appUserIdSet = new HashSet<Long>();
    for (AppToUser appToUser : appToUsers) {
        appUserIdSet.add(appToUser.getUserId());
    }
    //最终判断
    if (!appUserIdSet.contains(currentUser.getId())) {
        logger.error("currentUser {} hasn't previlege in appId {}", currentUser.getId(), appId);
        return false;
    }
    return true;
}
Also used : AppUser(com.sohu.cache.entity.AppUser) AppToUser(com.sohu.cache.entity.AppToUser) HashSet(java.util.HashSet)

Aggregations

AppUser (com.sohu.cache.entity.AppUser)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 ModelAndView (org.springframework.web.servlet.ModelAndView)15 SuccessEnum (com.sohu.cache.web.enums.SuccessEnum)8 AppAudit (com.sohu.cache.entity.AppAudit)3 InstanceConfig (com.sohu.cache.entity.InstanceConfig)3 AppDesc (com.sohu.cache.entity.AppDesc)2 AppToUser (com.sohu.cache.entity.AppToUser)2 InstanceAlert (com.sohu.cache.entity.InstanceAlert)2 BaseTest (com.sohu.test.BaseTest)2 Date (java.util.Date)2 Test (org.junit.Test)2 AppDataMigrateEnum (com.sohu.cache.constant.AppDataMigrateEnum)1 AppDailyData (com.sohu.cache.entity.AppDailyData)1 InstanceAlertValueResult (com.sohu.cache.entity.InstanceAlertValueResult)1 InstanceInfo (com.sohu.cache.entity.InstanceInfo)1 LoginResult (com.sohu.cache.entity.LoginResult)1 SystemConfig (com.sohu.cache.entity.SystemConfig)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1