Search in sources :

Example 1 with ManagementServerException

use of com.cloud.exception.ManagementServerException 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)

Example 2 with ManagementServerException

use of com.cloud.exception.ManagementServerException in project CloudStack-archive by CloudStack-extras.

the class MigrateVMCmd method execute.

@Override
public void execute() {
    if (getHostId() == null && getStoragePoolId() == null) {
        throw new InvalidParameterValueException("either hostId or storageId must be specified");
    }
    if (getHostId() != null && getStoragePoolId() != null) {
        throw new InvalidParameterValueException("only one of hostId and storageId can be specified");
    }
    UserVm userVm = _userVmService.getUserVm(getVirtualMachineId());
    if (userVm == null) {
        throw new InvalidParameterValueException("Unable to find the VM by id=" + getVirtualMachineId());
    }
    Host destinationHost = null;
    if (getHostId() != null) {
        destinationHost = _resourceService.getHost(getHostId());
        if (destinationHost == null) {
            throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
        }
        UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId());
    }
    StoragePool destStoragePool = null;
    if (getStoragePoolId() != null) {
        destStoragePool = _storageService.getStoragePool(getStoragePoolId());
        if (destStoragePool == null) {
            throw new InvalidParameterValueException("Unable to find the storage pool to migrate the VM");
        }
        UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to storage pool Id: " + getStoragePoolId());
    }
    try {
        VirtualMachine migratedVm = null;
        if (getHostId() != null) {
            migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
        } else if (getStoragePoolId() != null) {
            migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), destStoragePool);
        }
        if (migratedVm != null) {
            UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", (UserVm) migratedVm).get(0);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate 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 : UserVm(com.cloud.uservm.UserVm) StoragePool(com.cloud.storage.StoragePool) 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) UserVmResponse(com.cloud.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 3 with ManagementServerException

use of com.cloud.exception.ManagementServerException in project cloudstack by apache.

the class KubernetesClusterResourceModifierActionWorker method provisionKubernetesClusterNodeVms.

protected List<UserVm> provisionKubernetesClusterNodeVms(final long nodeCount, final int offset, final String publicIpAddress) throws ManagementServerException, ResourceUnavailableException, InsufficientCapacityException {
    List<UserVm> nodes = new ArrayList<>();
    for (int i = offset + 1; i <= nodeCount; i++) {
        UserVm vm = createKubernetesNode(publicIpAddress);
        addKubernetesClusterVm(kubernetesCluster.getId(), vm.getId(), false);
        if (kubernetesCluster.getNodeRootDiskSize() > 0) {
            resizeNodeVolume(vm);
        }
        startKubernetesVM(vm);
        vm = userVmDao.findById(vm.getId());
        if (vm == null) {
            throw new ManagementServerException(String.format("Failed to provision worker VM for Kubernetes cluster : %s", kubernetesCluster.getName()));
        }
        nodes.add(vm);
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(String.format("Provisioned node VM : %s in to the Kubernetes cluster : %s", vm.getDisplayName(), kubernetesCluster.getName()));
        }
    }
    return nodes;
}
Also used : UserVm(com.cloud.uservm.UserVm) ManagementServerException(com.cloud.exception.ManagementServerException) ArrayList(java.util.ArrayList)

Example 4 with ManagementServerException

use of com.cloud.exception.ManagementServerException in project cloudstack by apache.

the class KubernetesClusterResourceModifierActionWorker method resizeNodeVolume.

protected void resizeNodeVolume(final UserVm vm) throws ManagementServerException {
    try {
        if (vm.getHypervisorType() == Hypervisor.HypervisorType.VMware && templateDao.findById(vm.getTemplateId()).isDeployAsIs()) {
            List<VolumeVO> vmVols = volumeDao.findByInstance(vm.getId());
            for (VolumeVO volumeVO : vmVols) {
                if (volumeVO.getVolumeType() == Volume.Type.ROOT) {
                    ResizeVolumeCmd resizeVolumeCmd = new ResizeVolumeCmd();
                    resizeVolumeCmd = ComponentContext.inject(resizeVolumeCmd);
                    Field f = resizeVolumeCmd.getClass().getDeclaredField("size");
                    Field f1 = resizeVolumeCmd.getClass().getDeclaredField("id");
                    f.setAccessible(true);
                    f1.setAccessible(true);
                    f1.set(resizeVolumeCmd, volumeVO.getId());
                    f.set(resizeVolumeCmd, kubernetesCluster.getNodeRootDiskSize());
                    volumeService.resizeVolume(resizeVolumeCmd);
                }
            }
        }
    } catch (IllegalAccessException | NoSuchFieldException e) {
        throw new ManagementServerException(String.format("Failed to resize volume of  VM in the Kubernetes cluster : %s", kubernetesCluster.getName()), e);
    }
}
Also used : Field(java.lang.reflect.Field) ResizeVolumeCmd(org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd) VolumeVO(com.cloud.storage.VolumeVO) ManagementServerException(com.cloud.exception.ManagementServerException)

Example 5 with ManagementServerException

use of com.cloud.exception.ManagementServerException in project cloudstack by apache.

the class KubernetesClusterStartWorker method provisionKubernetesClusterAdditionalControlVms.

private List<UserVm> provisionKubernetesClusterAdditionalControlVms(final String publicIpAddress) throws InsufficientCapacityException, ManagementServerException, ResourceUnavailableException {
    List<UserVm> additionalControlVms = new ArrayList<>();
    if (kubernetesCluster.getControlNodeCount() > 1) {
        for (int i = 1; i < kubernetesCluster.getControlNodeCount(); i++) {
            UserVm vm = null;
            vm = createKubernetesAdditionalControlNode(publicIpAddress, i);
            addKubernetesClusterVm(kubernetesCluster.getId(), vm.getId(), true);
            if (kubernetesCluster.getNodeRootDiskSize() > 0) {
                resizeNodeVolume(vm);
            }
            startKubernetesVM(vm);
            vm = userVmDao.findById(vm.getId());
            if (vm == null) {
                throw new ManagementServerException(String.format("Failed to provision additional control VM for Kubernetes cluster : %s", kubernetesCluster.getName()));
            }
            additionalControlVms.add(vm);
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info(String.format("Provisioned additional control VM : %s in to the Kubernetes cluster : %s", vm.getDisplayName(), kubernetesCluster.getName()));
            }
        }
    }
    return additionalControlVms;
}
Also used : UserVm(com.cloud.uservm.UserVm) ManagementServerException(com.cloud.exception.ManagementServerException) ArrayList(java.util.ArrayList)

Aggregations

ManagementServerException (com.cloud.exception.ManagementServerException)32 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)25 UserVm (com.cloud.uservm.UserVm)18 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)17 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)16 VirtualMachine (com.cloud.vm.VirtualMachine)10 ServerApiException (com.cloud.api.ServerApiException)8 Host (com.cloud.host.Host)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 ServerApiException (org.apache.cloudstack.api.ServerApiException)6 UserVmResponse (com.cloud.api.response.UserVmResponse)5 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)5 ArrayList (java.util.ArrayList)5 StoragePool (com.cloud.storage.StoragePool)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)4 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)4 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)3 KubernetesClusterVmMapVO (com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)3 IpAddress (com.cloud.network.IpAddress)3