Esempio n. 1
0
  @Override
  public void execute() {
    UserVm result;
    try {
      UserContext.current().setEventDetails("Vm Id: " + getEntityId());
      if (getHypervisor() == HypervisorType.BareMetal) {
        result = _bareMetalVmService.startVirtualMachine(this);
      } else {
        result = _userVmService.startVirtualMachine(this);
      }

      if (result != null) {
        UserVmResponse response =
            _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
      } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
      }
    } catch (ResourceUnavailableException ex) {
      s_logger.warn("Exception: ", ex);
      throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
      s_logger.warn("Exception: ", ex);
      throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientCapacityException ex) {
      s_logger.info(ex);
      s_logger.trace(ex);
      throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
  }
Esempio n. 2
0
  @Override
  public void execute()
      throws ResourceUnavailableException, InsufficientCapacityException,
          ResourceAllocationException {
    try {
      UserContext.current().setEventDetails("Vm Id: " + getId());
      UserVm result;
      if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
        result = _bareMetalVmService.startVirtualMachine(this);
      } else {
        result = _userVmService.startVirtualMachine(this);
      }

      if (result != null) {
        UserVmResponse response =
            _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
      } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm");
      }
    } catch (ConcurrentOperationException ex) {
      s_logger.warn("Exception: ", ex);
      throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (StorageUnavailableException ex) {
      s_logger.warn("Exception: ", ex);
      throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ExecutionException ex) {
      s_logger.warn("Exception: ", ex);
      throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    }
  }
Esempio n. 3
0
 @Override
 public void execute() {
   boolean result = _templateService.detachIso(this);
   if (result) {
     UserVm userVm = _entityMgr.findById(UserVm.class, virtualMachineId);
     UserVmResponse response =
         _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0);
     response.setResponseName(DeployVMCmd.getResultObjectName());
     this.setResponseObject(response);
   } else {
     throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to detach iso");
   }
 }
Esempio n. 4
0
 @Override
 public void execute()
     throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException,
         ConcurrentOperationException, ResourceAllocationException {
   UserVm result;
   UserContext.current().setEventDetails("Vm Id: " + getVmId());
   result = _userVmService.restoreVM(this);
   if (result != null) {
     UserVmResponse response =
         _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
     response.setResponseName(getCommandName());
     this.setResponseObject(response);
   } else {
     throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to restore vm " + getVmId());
   }
 }
Esempio n. 5
0
  @Override
  public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
    UserContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result;
    if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
      result = _bareMetalVmService.rebootVirtualMachine(this);
    } else {
      result = _userVmService.rebootVirtualMachine(this);
    }

    if (result != null) {
      UserVmResponse response = _responseGenerator.createUserVmResponse(result);
      response.setResponseName(getCommandName());
      this.setResponseObject(response);
    } else {
      throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reboot vm instance");
    }
  }
Esempio n. 6
0
  @Override
  public void execute() throws ServerApiException, ConcurrentOperationException {
    UserContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result;

    if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
      result = _bareMetalVmService.stopVirtualMachine(getId(), isForced());
    } else {
      result = _userVmService.stopVirtualMachine(getId(), isForced());
    }

    if (result != null) {
      UserVmResponse response =
          _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
      response.setResponseName(getCommandName());
      this.setResponseObject(response);
    } else {
      throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to stop vm");
    }
  }