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;
}
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("");
}
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("");
}
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();
}
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;
}
Aggregations