@Override
  public void execute()
      throws ResourceUnavailableException, InsufficientCapacityException,
          ResourceAllocationException {
    try {
      UserContext.current().setEventDetails("Vm Id: " + getId());

      UserVm result;
      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(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm");
      }
    } catch (ConcurrentOperationException ex) {
      s_logger.warn("Exception: ", ex);
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (StorageUnavailableException ex) {
      s_logger.warn("Exception: ", ex);
      throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ExecutionException ex) {
      s_logger.warn("Exception: ", ex);
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
  }
 @Override
 public void execute()
     throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
   UserContext.current().setEventDetails("Vm Id: " + getId());
   UserVm result = _userVmService.updateVirtualMachine(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 update vm");
   }
 }
示例#3
0
 @Override
 public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
   CallContext.current().setEventDetails("Vm Id: " + getId());
   UserVm result;
   result = _userVmService.rebootVirtualMachine(this);
   if (result != null) {
     UserVmResponse response =
         _responseGenerator
             .createUserVmResponse(ResponseView.Restricted, "virtualmachine", result)
             .get(0);
     response.setResponseName(getCommandName());
     setResponseObject(response);
   } else {
     throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reboot vm instance");
   }
 }
示例#4
0
 @Override
 public void execute() {
   try {
     UserVm userVm = _userVmService.moveVMToUser(this);
     if (userVm == null) {
       throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
     }
     UserVmResponse response =
         _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0);
     response.setResponseName(getCommandName());
     setResponseObject(response);
   } catch (Exception e) {
     e.printStackTrace();
     throw new ServerApiException(
         ApiErrorCode.INTERNAL_ERROR, "Failed to move vm " + e.getMessage());
   }
 }
示例#5
0
  @Override
  public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
    CallContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result = _userVmService.destroyVm(this);

    UserVmResponse response = new UserVmResponse();
    if (result != null) {
      List<UserVmResponse> responses =
          _responseGenerator.createUserVmResponse("virtualmachine", result);
      if (responses != null && !responses.isEmpty()) {
        response = responses.get(0);
      }
      response.setResponseName("virtualmachine");
      this.setResponseObject(response);
    } else {
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to destroy vm");
    }
  }
 @Override
 public void execute() {
   CallContext.current().setEventDetails("Vm Id: " + getVmId() + " Network Id: " + getNetworkId());
   UserVm result = _userVmService.addNicToVirtualMachine(this);
   ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
   dc.add(VMDetails.valueOf("nics"));
   EnumSet<VMDetails> details = EnumSet.copyOf(dc);
   if (result != null) {
     UserVmResponse response =
         _responseGenerator
             .createUserVmResponse(ResponseView.Restricted, "virtualmachine", details, result)
             .get(0);
     response.setResponseName(getCommandName());
     setResponseObject(response);
   } else {
     throw new ServerApiException(
         ApiErrorCode.INTERNAL_ERROR,
         "Failed to add NIC to vm. Refer to server logs for details.");
   }
 }
  @Override
  public void execute() throws ResourceAllocationException {
    CallContext.current().setEventDetails("Vm Id: " + getId());

    ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
    if (serviceOffering == null) {
      throw new InvalidParameterValueException(
          "Unable to find service offering: " + serviceOfferingId);
    }

    UserVm result = _userVmService.upgradeVirtualMachine(this);
    if (result != null) {
      UserVmResponse response =
          _responseGenerator
              .createUserVmResponse(ResponseView.Full, "virtualmachine", result)
              .get(0);
      response.setResponseName(getCommandName());
      setResponseObject(response);
    } else {
      throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade vm");
    }
  }