Search in sources :

Example 16 with ManagementServerException

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

the class MigrateSystemVMCmd method execute.

@Override
public void execute() {
    if (getHostId() != null && getStorageId() != null) {
        throw new InvalidParameterValueException("Only one of hostId and storageId can be specified");
    }
    try {
        // FIXME : Should not be calling UserVmService to migrate all types of VMs - need a generic VM layer
        VirtualMachine migratedVm = null;
        if (getStorageId() != null) {
            // OfflineMigration performed when this parameter is specified
            StoragePool destStoragePool = _storageService.getStoragePool(getStorageId());
            if (destStoragePool == null) {
                throw new InvalidParameterValueException("Unable to find the storage pool to migrate the VM");
            }
            CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to storage pool Id: " + getStorageId());
            migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), destStoragePool);
        } else {
            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());
                }
                if (destinationHost.getType() != Host.Type.Routing) {
                    throw new InvalidParameterValueException("The specified host(" + destinationHost.getName() + ") is not suitable to migrate the VM, please specify another one");
                }
            } else if (!isAutoSelect()) {
                throw new InvalidParameterValueException("Please specify a host or storage as destination, or pass 'autoselect=true' to automatically select a destination host which do not require storage migration");
            }
            CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId());
            if (destinationHost == null) {
                migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), null);
            } else {
                migratedVm = _userVmService.migrateVirtualMachineWithVolume(getVirtualMachineId(), destinationHost, new HashMap<String, String>());
            }
        }
        if (migratedVm != null) {
            // return the generic system VM instance response
            SystemVmResponse response = _responseGenerator.createSystemVmResponse(migratedVm);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate the system vm");
        }
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    } catch (ManagementServerException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    } catch (VirtualMachineMigrationException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : SystemVmResponse(org.apache.cloudstack.api.response.SystemVmResponse) StoragePool(com.cloud.storage.StoragePool) ServerApiException(org.apache.cloudstack.api.ServerApiException) ManagementServerException(com.cloud.exception.ManagementServerException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) HashMap(java.util.HashMap) 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 17 with ManagementServerException

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

the class KubernetesClusterResourceModifierActionWorker method startKubernetesVM.

protected void startKubernetesVM(final UserVm vm) throws ManagementServerException {
    try {
        StartVMCmd startVm = new StartVMCmd();
        startVm = ComponentContext.inject(startVm);
        Field f = startVm.getClass().getDeclaredField("id");
        f.setAccessible(true);
        f.set(startVm, vm.getId());
        itMgr.advanceStart(vm.getUuid(), null, null);
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(String.format("Started VM : %s in the Kubernetes cluster : %s", vm.getDisplayName(), kubernetesCluster.getName()));
        }
    } catch (IllegalAccessException | NoSuchFieldException | OperationTimedoutException | ResourceUnavailableException | InsufficientCapacityException ex) {
        throw new ManagementServerException(String.format("Failed to start VM in the Kubernetes cluster : %s", kubernetesCluster.getName()), ex);
    }
    UserVm startVm = userVmDao.findById(vm.getId());
    if (!startVm.getState().equals(VirtualMachine.State.Running)) {
        throw new ManagementServerException(String.format("Failed to start VM in the Kubernetes cluster : %s", kubernetesCluster.getName()));
    }
}
Also used : Field(java.lang.reflect.Field) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) UserVm(com.cloud.uservm.UserVm) ManagementServerException(com.cloud.exception.ManagementServerException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StartVMCmd(org.apache.cloudstack.api.command.user.vm.StartVMCmd)

Example 18 with ManagementServerException

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

the class KubernetesClusterStartWorker method provisionKubernetesClusterControlVm.

private UserVm provisionKubernetesClusterControlVm(final Network network, final String publicIpAddress) throws ManagementServerException, InsufficientCapacityException, ResourceUnavailableException {
    UserVm k8sControlVM = null;
    k8sControlVM = createKubernetesControlNode(network, publicIpAddress);
    addKubernetesClusterVm(kubernetesCluster.getId(), k8sControlVM.getId(), true);
    if (kubernetesCluster.getNodeRootDiskSize() > 0) {
        resizeNodeVolume(k8sControlVM);
    }
    startKubernetesVM(k8sControlVM);
    k8sControlVM = userVmDao.findById(k8sControlVM.getId());
    if (k8sControlVM == null) {
        throw new ManagementServerException(String.format("Failed to provision control VM for Kubernetes cluster : %s", kubernetesCluster.getName()));
    }
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info(String.format("Provisioned the control VM : %s in to the Kubernetes cluster : %s", k8sControlVM.getDisplayName(), kubernetesCluster.getName()));
    }
    return k8sControlVM;
}
Also used : UserVm(com.cloud.uservm.UserVm) ManagementServerException(com.cloud.exception.ManagementServerException)

Example 19 with ManagementServerException

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

the class KubernetesClusterStartWorker method startKubernetesClusterNetwork.

private Network startKubernetesClusterNetwork(final DeployDestination destination) throws ManagementServerException {
    final ReservationContext context = new ReservationContextImpl(null, null, null, owner);
    Network network = networkDao.findById(kubernetesCluster.getNetworkId());
    if (network == null) {
        String msg = String.format("Network for Kubernetes cluster : %s not found", kubernetesCluster.getName());
        LOGGER.warn(msg);
        stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.CreateFailed);
        throw new ManagementServerException(msg);
    }
    try {
        networkMgr.startNetwork(network.getId(), destination, context);
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(String.format("Network : %s is started for the  Kubernetes cluster : %s", network.getName(), kubernetesCluster.getName()));
        }
    } catch (ConcurrentOperationException | ResourceUnavailableException | InsufficientCapacityException e) {
        String msg = String.format("Failed to start Kubernetes cluster : %s as unable to start associated network : %s", kubernetesCluster.getName(), network.getName());
        LOGGER.error(msg, e);
        stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.CreateFailed);
        throw new ManagementServerException(msg, e);
    }
    return network;
}
Also used : ManagementServerException(com.cloud.exception.ManagementServerException) Network(com.cloud.network.Network) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ReservationContext(com.cloud.vm.ReservationContext)

Example 20 with ManagementServerException

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

the class KubernetesClusterStartWorker method startKubernetesClusterVMs.

private void startKubernetesClusterVMs() {
    List<UserVm> clusterVms = getKubernetesClusterVMs();
    for (final UserVm vm : clusterVms) {
        if (vm == null) {
            logTransitStateAndThrow(Level.ERROR, String.format("Failed to start all VMs in Kubernetes cluster : %s", kubernetesCluster.getName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed);
        }
        try {
            resizeNodeVolume(vm);
            startKubernetesVM(vm);
        } catch (ManagementServerException ex) {
            LOGGER.warn(String.format("Failed to start VM : %s in Kubernetes cluster : %s due to ", vm.getDisplayName(), kubernetesCluster.getName()) + ex);
        // dont bail out here. proceed further to stop the reset of the VM's
        }
    }
    for (final UserVm userVm : clusterVms) {
        UserVm vm = userVmDao.findById(userVm.getId());
        if (vm == null || !vm.getState().equals(VirtualMachine.State.Running)) {
            logTransitStateAndThrow(Level.ERROR, String.format("Failed to start all VMs in Kubernetes cluster : %s", kubernetesCluster.getName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed);
        }
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ManagementServerException(com.cloud.exception.ManagementServerException)

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