Ejemplo n.º 1
0
 /**
  * <备份虚拟机>
  *
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * 获取vncviewer连接VNC的参数
  *
  * @return
  */
 public String getClientVNC() {
   long beginRunTime = 0;
   if (logger.isDebugEnabled()) {
     beginRunTime = System.currentTimeMillis();
     logger.debug("enter getClientVNC 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 + "]";
   VncClientVO vnc = null;
   int exceptionType = 0; // 0:验证码错误 1:获取远程连接参数异常
   try {
     // 检查验证码是否正确
     String sessionCode =
         (String) ServletActionContext.getRequest().getSession().getAttribute("code");
     if (null == this.code || "".equals(this.code)) {
       fillActionResult(Constants.VERCODE_IS_NULL);
     } else if (null == sessionCode || !sessionCode.equalsIgnoreCase(this.code)) {
       fillActionResult(Constants.VERCODE_IS_ERROR);
     } else {
       exceptionType = 1;
       vnc = facade.getClientVnc(vmId);
     }
   } catch (HsCloudException e) {
     if (exceptionType == 0) {
       if (e.getClass() == new HsCloudException().getClass()) {
         HsCloudException ex = (HsCloudException) e;
         dealThrow(new HsCloudException(ex.getCode(), "getClientVNC异常", logger, e), "000");
       } else {
         dealThrow(
             new HsCloudException(Constants.VERCODE_IS_ERROR, "getClientVNC异常", logger, e), "000");
       }
       return null;
     } else {
       if (e.getClass() == new HsCloudException().getClass()) {
         HsCloudException ex = (HsCloudException) e;
         dealThrow(new HsCloudException(ex.getCode(), "getClientVNC异常", logger, e), "000");
       } else {
         dealThrow(
             new HsCloudException(Constants.VM_VNC_ERROR, "getClientVNC异常", logger, e), "000");
       }
       return null;
     }
   }
   if (exceptionType == 1 && vnc != null) {
     super.fillActionResult((Object) vnc);
   } else if (exceptionType == 1 && vnc == null) {
     super.fillActionResult(Constants.VM_VNC_ERROR);
   }
   if (logger.isDebugEnabled()) {
     long takeTime = System.currentTimeMillis() - beginRunTime;
     logger.debug("exit getVNC method.takeTime:" + takeTime + "ms");
   }
   return null;
 }
Ejemplo n.º 3
0
 /**
  * <获取虚拟机远程控制>
  *
  * @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;
 }
Ejemplo n.º 4
0
 /**
  * <用途: 主机修复 >
  *
  * @author liyunhui
  * @return
  * @see [类、类#方法、类#成员]
  */
 public String repairOS() {
   long beginRunTime = 0;
   if (logger.isDebugEnabled()) {
     beginRunTime = System.currentTimeMillis();
     logger.debug("enter repairOS 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 + "]";
   boolean bl;
   try {
     bl = facade.repairOSByVmId(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_CLOSE_ERROR, "repairOS Exception:", logger, e),
         Constants.OPTIONS_FAILURE);
     return null;
   }
   if (bl) {
     super.fillActionResult(Constants.OPTIONS_SUCCESS);
   } else {
     super.fillActionResult(Constants.VM_REPAIR_ERROR);
   }
   if (logger.isDebugEnabled()) {
     long takeTime = System.currentTimeMillis() - beginRunTime;
     logger.debug("exit repairOS method.takeTime:" + takeTime + "ms");
   }
   return null;
 }
Ejemplo n.º 5
0
 /**
  * <启动虚拟机>
  *
  * @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;
 }
Ejemplo n.º 6
0
 /**
  * <终止快照:实质就是删除超过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;
 }