Search in sources :

Example 1 with SystemVmInstanceResponse

use of com.cloud.api.response.SystemVmInstanceResponse in project CloudStack-archive by CloudStack-extras.

the class MigrateSystemVMCmd method execute.

@Override
public void execute() {
    Host destinationHost = _resourceService.getHost(getHostId());
    if (destinationHost == null) {
        throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
    }
    try {
        UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId());
        //FIXME : Should not be calling UserVmService to migrate all types of VMs - need a generic VM layer
        VirtualMachine migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
        if (migratedVm != null) {
            // return the generic system VM instance response
            SystemVmInstanceResponse response = _responseGenerator.createSystemVmInstanceResponse(migratedVm);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate the system vm");
        }
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
    } catch (ManagementServerException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
    } catch (VirtualMachineMigrationException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : SystemVmInstanceResponse(com.cloud.api.response.SystemVmInstanceResponse) ServerApiException(com.cloud.api.ServerApiException) ManagementServerException(com.cloud.exception.ManagementServerException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Host(com.cloud.host.Host) VirtualMachineMigrationException(com.cloud.exception.VirtualMachineMigrationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

ServerApiException (com.cloud.api.ServerApiException)1 SystemVmInstanceResponse (com.cloud.api.response.SystemVmInstanceResponse)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ManagementServerException (com.cloud.exception.ManagementServerException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)1 Host (com.cloud.host.Host)1 VirtualMachine (com.cloud.vm.VirtualMachine)1