/** * <重置虚拟机操作系统> <功能详细描述> * * @return * @see [类、类#方法、类#成员] */ public String resetVmOS() { long beginRunTime = 0; if (logger.isDebugEnabled()) { beginRunTime = System.currentTimeMillis(); logger.debug("enter resetVmOS method."); } ControlPanelUser controlPanelUser = (ControlPanelUser) super.getSession().getAttribute(Constants.LOGIN_CURRENTUSER); if (controlPanelUser == null) { super.fillActionResult(Constants.OPTIONS_TIMEOUT); return null; } String vmId = controlPanelUser.getVmId(); String operateObject = "VM[vmId:" + vmId + "]"; try { facade.resetVMOS(vmId, osId, name, password, controlPanelUser, LogOperatorType.CP.getName()); facade.insertOperationLog( controlPanelUser, "发送重置操作系统命令成功", "发送重置操作系统命令", Constants.RESULT_SUCESS, operateObject); } catch (Exception e) { facade.insertOperationLog( controlPanelUser, "发送重置操作系统命令出现错误:" + e.getMessage(), "发送重置操作系统命令", Constants.RESULT_FAILURE, operateObject); dealThrow(new HsCloudException(Constants.VM_RESETOS_ERROR, "resetVmOS异常", logger, e), "000"); return null; } super.fillActionResult(Constants.OPTIONS_SUCCESS); if (logger.isDebugEnabled()) { long takeTime = System.currentTimeMillis() - beginRunTime; logger.debug("exit resetVmOS method.takeTime:" + takeTime + "ms"); } return null; }
/** * <创建备份计划> * * @return * @see [类、类#方法、类#成员] */ public String createBackupVmPlan() { long beginRunTime = 0; if (logger.isDebugEnabled()) { beginRunTime = System.currentTimeMillis(); logger.debug("enter createBackupVmPlan method."); } java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("HH:mm"); ControlPanelUser controlPanelUser = (ControlPanelUser) super.getSession().getAttribute(Constants.LOGIN_CURRENTUSER); if (controlPanelUser == null) { super.fillActionResult(Constants.OPTIONS_TIMEOUT); return null; } String result = null; String vmId = controlPanelUser.getVmId(); String operateObject = "VM[vmId:" + vmId + "]"; try { vssp = Utils.strutsJson2Object(VmSnapShotPlan.class); Date dtime = sdf.parse(planTime); Time time = new Time(dtime.getTime()); vssp.setPlanTime(time); vssp.setModifyUser(controlPanelUser.getId()); vssp.setVmId(controlPanelUser.getVmId()); VmSnapShotPlanVO vsspVO = facade.getBackupVmPlanByVmId(vmId); if (vsspVO != null) { vssp.setId(vsspVO.getId()); if (0 == vssp.getPlanType()) { vssp.setPlanTime(vsspVO.getPlanTime()); vssp.setPlanDate(vsspVO.getPlanDate()); } } result = facade.createBackupVmPlanByVmId(vssp); facade.insertOperationLog( controlPanelUser, "创建备份计划成功", "创建备份计划", Constants.RESULT_SUCESS, operateObject); } catch (Exception e) { facade.insertOperationLog( controlPanelUser, "创建备份计划出现错误:" + e.getMessage(), "创建备份计划", Constants.RESULT_FAILURE, operateObject); dealThrow( new HsCloudException(Constants.VM_BACKUP_PLAN_ERROR, "createBackupVmPlan异常", logger, e), "000"); return null; } if (result != null) { super.fillActionResult(Constants.VM_BACKUP_PLAN_ERROR); } else { super.fillActionResult(Constants.OPTIONS_SUCCESS); } if (logger.isDebugEnabled()) { long takeTime = System.currentTimeMillis() - beginRunTime; logger.debug("exit createBackupVmPlan method.takeTime:" + takeTime + "ms"); } return null; }
/** * <备份虚拟机> * * @return * @see [类、类#方法、类#成员] */ public String backupVM() { long beginRunTime = 0; if (logger.isDebugEnabled()) { beginRunTime = System.currentTimeMillis(); logger.debug("enter backupVM method."); } ControlPanelUser controlPanelUser = (ControlPanelUser) super.getSession().getAttribute(Constants.LOGIN_CURRENTUSER); if (controlPanelUser == null) { super.fillActionResult(Constants.OPTIONS_TIMEOUT); return null; } String vmId = controlPanelUser.getVmId(); String operateObject = "VM[vmId:" + vmId + "]"; String result = null; try { result = facade.backupVmByVmId( vmId, sn_name, sn_comments, sn_type, controlPanelUser, LogOperatorType.CP.getName()); facade.insertOperationLog( controlPanelUser, "发送备份虚拟机命令成功", "发送备份虚拟机命令", Constants.RESULT_SUCESS, operateObject); } catch (HsCloudException e) { facade.insertOperationLog( controlPanelUser, "发送备份虚拟机命令出现错误:" + e.getMessage(), "发送备份虚拟机命令", Constants.RESULT_FAILURE, operateObject); dealThrow( new HsCloudException(Constants.VM_BACKUP_ERROR, "createBackupVmPlan异常", logger, e), "000"); return null; } if (result != null) { super.fillActionResult(Constants.OPTIONS_SUCCESS); } else { super.fillActionResult(Constants.VM_BACKUP_ERROR); } if (null == result) { fillActionResult(Constants.VM_NO_ACTIVE); } if (logger.isDebugEnabled()) { long takeTime = System.currentTimeMillis() - beginRunTime; logger.debug("exit backupVM method.takeTime:" + takeTime + "ms"); } return null; }
/** * <获取虚拟机远程控制> * * @return * @see [类、类#方法、类#成员] */ public String getVNC() { long beginRunTime = 0; if (logger.isDebugEnabled()) { beginRunTime = System.currentTimeMillis(); logger.debug("enter getVNC method."); } String vncUrl = null; ControlPanelUser controlPanelUser = (ControlPanelUser) super.getSession().getAttribute(Constants.LOGIN_CURRENTUSER); if (controlPanelUser == null) { super.fillActionResult(Constants.OPTIONS_TIMEOUT); return null; } String vmId = controlPanelUser.getVmId(); String operateObject = "VM[vmId:" + vmId + "]"; try { vncUrl = facade.getVNCUrl(vmId); facade.insertOperationLog( controlPanelUser, "发送获取VNC远程控制命令成功", "发送获取VNC远程控制命令", Constants.RESULT_SUCESS, operateObject); } catch (HsCloudException e) { facade.insertOperationLog( controlPanelUser, "发送获取VNC远程控制命令出现错误:" + e.getMessage(), "发送获取VNC远程控制命令", Constants.RESULT_FAILURE, operateObject); dealThrow(new HsCloudException(Constants.VM_VNC_ERROR, "getVNC异常", logger, e), "000"); return null; } if (vncUrl != null) { super.fillActionResult((Object) vncUrl); } else { super.fillActionResult(Constants.VM_VNC_ERROR); } if (logger.isDebugEnabled()) { long takeTime = System.currentTimeMillis() - beginRunTime; logger.debug("exit getVNC method.takeTime:" + takeTime + "ms"); } return null; }
/** * <启动虚拟机> * * @return * @see [类、类#方法、类#成员] */ public String startVM() { long beginRunTime = 0; if (logger.isDebugEnabled()) { beginRunTime = System.currentTimeMillis(); logger.debug("enter startVM method."); } boolean result = false; ControlPanelUser controlPanelUser = (ControlPanelUser) super.getSession().getAttribute(Constants.LOGIN_CURRENTUSER); if (controlPanelUser == null) { super.fillActionResult(Constants.OPTIONS_TIMEOUT); return null; } String vmId = controlPanelUser.getVmId(); String operateObject = "VM[vmId:" + vmId + "]"; try { result = facade.startVmByVmId(vmId, controlPanelUser, LogOperatorType.CP.getName()); facade.insertOperationLog( controlPanelUser, "发送启动虚拟机命令成功", "发送启动虚拟机命令", Constants.RESULT_SUCESS, operateObject); } catch (HsCloudException e) { facade.insertOperationLog( controlPanelUser, "发送启动虚拟机命令出现错误:" + e.getMessage(), "发送启动虚拟机命令", Constants.RESULT_FAILURE, operateObject); dealThrow(new HsCloudException(Constants.VM_START_ERROR, "startVM异常", logger, e), "000"); return null; } if (result) { super.fillActionResult(Constants.OPTIONS_SUCCESS); } else { logger.error("ERROR:" + result); super.fillActionResult(Constants.VM_START_ERROR); } if (logger.isDebugEnabled()) { long takeTime = System.currentTimeMillis() - beginRunTime; logger.debug("exit startVM method.takeTime:" + takeTime + "ms"); } return null; }
/** * <终止快照:实质就是删除超过30分钟都还没有创建成功的快照> * * @return * @see [类、类#方法、类#成员] */ public String stopSnapshot() { long beginRunTime = 0; if (logger.isDebugEnabled()) { beginRunTime = System.currentTimeMillis(); logger.debug("enter stopSnapshot method."); } ControlPanelUser controlPanelUser = (ControlPanelUser) super.getSession().getAttribute(Constants.LOGIN_CURRENTUSER); if (controlPanelUser == null) { super.fillActionResult(Constants.OPTIONS_TIMEOUT); return null; } String vmId = controlPanelUser.getVmId(); boolean result = false; String operateObject = "VM[vmId:" + vmId + "]"; try { result = facade.stopSnapshot(vmId); facade.insertOperationLog( controlPanelUser, "终止快照成功", "终止快照", Constants.RESULT_SUCESS, operateObject); } catch (HsCloudException e) { facade.insertOperationLog( controlPanelUser, "终止快照出现错误:" + e.getMessage(), "终止快照", Constants.RESULT_FAILURE, operateObject); dealThrow(new HsCloudException("", "stopSnapshot异常", logger, e), ""); return null; } super.fillActionResult(result); if (logger.isDebugEnabled()) { long takeTime = System.currentTimeMillis() - beginRunTime; logger.debug("exit stopSnapshot method.takeTime:" + takeTime + "ms"); } return null; }