diff --git a/client/conf/error-messages.json.in b/client/conf/error-messages.json.in index 6ab12e38c36..4de8651c1cb 100644 --- a/client/conf/error-messages.json.in +++ b/client/conf/error-messages.json.in @@ -87,6 +87,7 @@ "vm.removenic.concurrent.operation": "Concurrent operations on removing the Network {{network}} from the Instance {{instance}}: {{error}}.", "vm.removenic.failed": "Unable to remove the NIC {{nic}} from the Instance {{instance}}.", "vm.updatenic.nic.not.found": "Unable to update NIC as the specified NIC is not found.", + "vm.updatenic.nic.not.found.admin": "Unable to update NIC as the specified NIC ID: {{nicId} is not found.", "vm.updatenic.vm.not.found": "Unable to update NIC as the specified Instance is not found.", "vm.updatenic.vm.having.snapshots": "Unable to update NIC for the Instance {{instance}} as it has Instance Snapshots.", "vm.updatenic.nic.not.found": "Unable to update NIC for the Instance {{instance}} as the specified NIC is not found.", @@ -100,6 +101,9 @@ "vm.updatenic.default.update.failed": "Setting a default NIC failed, and we had no default nic, but we were unable to set it back to the original.", "vm.updatenic.default.no.default": "Unable to update default NIC to {{nic}} for the Instance {{instance}} and now it has no default.", "vm.updatenic.default.unknown.error": "Something strange happened, new default network {{newDefaultNetwork}} is not null, and is not equal to the network {{networkId}} of the chosen nic.", + "vm.updatenic.job.execution.failed": "Unexpected job execution result.", + "vm.updatenic.job.exception": "Exception while updating Instance {{instance}} NIC.", + "vm.updatenic.job.exception.admin": "Exception while updating Instance {{instance}} NIC. Check logs for more information.", "vm.updatenicip.nic.not.found": "There is no nic for the {{nicId}}.", "vm.updatenicip.nic.not.user.vm": "The nic is not belongs to user vm.", "vm.updatenicip.vm.not.found": "There is no vm with the nic.", @@ -119,6 +123,7 @@ "vm.upgrade.dynamic.scaling.flag.mismatch": "Unable to Scale VM: since dynamic scaling enabled flag is not same for new service offering and old service offering.", "vm.upgrade.disk.offering.strictness.mismatch": "Unable to Scale VM, since disk offering strictness flag is not same for new service offering and old service offering.", "vm.upgrade.disk.offering.id.not.same": "Unable to Scale VM, since disk offering id associated with the old service offering is not same for new service offering.", + "vm.upgrade.vm.sunning.scale.down.unsupported": "Scaling down is not supported while the VM is running. The new service offering attributes {\"memory\": {{newMemory}}, \"CPU speed\": {{newSpeed}}, \"vCPUs\": {{newCPU}}} must not be lower than the current values {\"memory\": {{currentMemory}}, \"CPU speed\": {{currentSpeed}}, \"vCPUs\": {{currentCPU}}}." "vm.scale.vgpu.not.supported": "Dynamic scaling of vGPU type is not supported. VM has vGPU Type: {{vgpuType}}.", "vm.scale.dynamic.scaling.disabled": "Dynamically scaling Instances is disabled for this zone, please contact your admin.", "vm.scale.dynamic.scaling.not.supported": "Unable to scale {{instance}} as it does not have tools to support dynamic scaling.", @@ -338,6 +343,8 @@ "vm.migrate.storage.hypervisor.not.supported": "Unsupported hypervisor {{hypervisorType}} for VM migration with storage.", "vm.migrate.storage.instance.snapshots.exist": "Instance cannot be migrated with storage because it has Instance Snapshots. Remove all Instance Snapshots first.", "vm.migrate.storage.no.volume.migration": "Migration of Instance {{instance}} from host {{srcHost}} to {{destHost}} does not involve migrating any volumes.", + "vm.migrate.host.source.prepare.failed": "Failed to prepare source host for migration of Instance {{instance}}.", + "vm.migrate.host.source.prepare.failed.admin": "Failed to prepare source host {{srcHost}} for migration of Instance {{instance}}: {{error}}.", "vm.assign.permission.denied": "Only root or domain administrators are allowed to assign VMs. Caller {{caller}} is of type {{callerType}}.", "vm.assign.domain.id.null": "Please provide a valid domain ID. Cannot assign VM to a project if domain ID is null.", "vm.assign.vm.not.found": "Unable to find Instance with specified ID for assignment.", diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index e69b23e6c2a..69e9077c80d 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -6362,9 +6362,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return BooleanUtils.isTrue((Boolean) jobResult); } } catch (ResourceUnavailableException | InsufficientCapacityException ex) { - throw new CloudRuntimeException(String.format("Exception while updating VM [%s] NIC. Check the logs for more information.", vm.getUuid())); + throw Exceptions.cloudRuntimeException("vm.updatenic.job.exception", Map.of("instance", vm)); } - throw new CloudRuntimeException("Unexpected job execution result."); + throw Exceptions.cloudRuntimeException("vm.updatenic.job.execution.failed"); } private boolean orchestrateUpdateVmNic(final VirtualMachine vm, final Nic nic, final Boolean enabled) throws ResourceUnavailableException { @@ -6418,7 +6418,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac VMInstanceVO vm = findVmById(work.getVmId()); final NicVO nic = _entityMgr.findById(NicVO.class, work.getNicId()); if (nic == null) { - throw new CloudRuntimeException(String.format("Unable to find NIC with ID %s.", work.getNicId())); + throw Exceptions.cloudRuntimeException("vm.updatenic.nic.not.found", Map.of("nicId", work.getNicId())); } final boolean result = orchestrateUpdateVmNic(vm, nic, work.isEnabled()); return new Pair<>(JobInfo.Status.SUCCEEDED, _jobMgr.marshallResultObject(result)); @@ -6486,7 +6486,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return; } final String vmInstanceName = vm.getInstanceName(); - final String srcHostUuid = _hostDao.findById(srcHostId).getUuid(); + final HostVO srcHost = _hostDao.findById(srcHostId); + final String srcHostUuid = srcHost.getUuid(); logger.info("Sending PreMigrationCommand to source host {} for VM {} with CLVM volumes", srcHostUuid, vmInstanceName); final PreMigrationCommand preMigCmd = new PreMigrationCommand(to, vmInstanceName); Answer preMigAnswer = null; @@ -6494,14 +6495,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac preMigAnswer = _agentMgr.send(srcHostId, preMigCmd); if (preMigAnswer == null || !preMigAnswer.getResult()) { final String details = preMigAnswer != null ? preMigAnswer.getDetails() : "null answer returned"; - final String msg = "Failed to prepare source host for migration: " + details; logger.error("Failed to prepare source host {} for migration of VM {}: {}", srcHostUuid, vmInstanceName, details); - throw new CloudRuntimeException(msg); + throw Exceptions.cloudRuntimeException("vm.migrate.host.source.prepare.failed", + Map.of("instance", vm, "host", srcHost, "error", details)); } logger.info("Successfully prepared source host {} for migration of VM {}", srcHostUuid, vmInstanceName); } catch (final AgentUnavailableException | OperationTimedoutException e) { logger.error("Failed to send PreMigrationCommand to source host {}: {}", srcHostUuid, e.getMessage(), e); - throw new CloudRuntimeException("Failed to prepare source host for migration: " + e.getMessage(), e); + throw Exceptions.cloudRuntimeException("vm.migrate.host.source.prepare.failed", + Map.of("instance", vm, "host", srcHost, "error", e.getMessage()), e); } } diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 9559a61350a..8fc4121c141 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -2246,9 +2246,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir boolean scalingDown = newSpeed < currentSpeed || newMemory < currentMemory || newCpu < currentCpu; if (scalingDown) { - throw new InvalidParameterValueException(String.format("Scaling down is not supported while the VM is running. The new service offering attributes " + - "{\"memory\": %s, \"CPU speed\": %s, \"vCPUs\": %s} must not be lower than the current values {\"memory\": %s, \"CPU speed\": %s, \"vCPUs\": %s}.", - newMemory, newSpeed, newCpu, currentMemory, currentSpeed, currentCpu)); + throw Exceptions.invalidParameterValueException("vm.upgrade.vm.sunning.scale.down.unsupported", Map.of( + "newMemory", newMemory, "newSpeed", newSpeed, "newCpu", newCpu, + "currentMemory", currentMemory, "currentSpeed", currentSpeed, "currentCpu", currentCpu)); } boolean sameAmountOfResourcesAsThePreviousOffering = newSpeed == currentSpeed && newMemory == currentMemory && newCpu == currentCpu; @@ -3041,7 +3041,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir } } catch (ResourceAllocationException e) { logger.error(String.format("Failed to updated VM due to: %s", e.getLocalizedMessage())); - throw new InvalidParameterValueException(e.getLocalizedMessage()); + throw Exceptions.invalidParameterValueException(e.getLocalizedMessage()); } finally { ReservationHelper.closeAll(reservations); } diff --git a/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java b/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java index 6b9d8d4bfee..23b385e7cd4 100644 --- a/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java +++ b/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java @@ -1375,12 +1375,12 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager { return; } if (BooleanUtils.isFalse(ConvertVmwareInstanceToKvmExtraParamsAllowed.value())) { - throw new ServerApiException(ApiErrorCode.PARAM_ERROR, + throw Exceptions.serverApiException(ApiErrorCode.PARAM_ERROR, "vm.import.extra.params.disabled", Collections.emptyMap()); } String allowedParamsStr = ConvertVmwareInstanceToKvmExtraParamsAllowedList.value(); if (StringUtils.isBlank(allowedParamsStr)) { - throw new ServerApiException(ApiErrorCode.PARAM_ERROR, + throw Exceptions.serverApiException(ApiErrorCode.PARAM_ERROR, "vm.import.extra.params.list.empty", Collections.emptyMap()); } List allowedParams = Arrays.asList(allowedParamsStr.split(",")); @@ -1391,7 +1391,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager { .collect(Collectors.toList()); for (String param : sanitizedParams) { if (!allowedParams.contains(param)) { - throw new ServerApiException(ApiErrorCode.PARAM_ERROR, + throw Exceptions.serverApiException(ApiErrorCode.PARAM_ERROR, "vm.import.extra.param.not.allowed", Map.of("param", param)); } } @@ -1666,15 +1666,15 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager { boolean useVddk = cmd.getUseVddk(); if ((existingVcenterId == null && vcenter == null) || (existingVcenterId != null && vcenter != null)) { - throw new ServerApiException(ApiErrorCode.PARAM_ERROR, + throw Exceptions.serverApiException(ApiErrorCode.PARAM_ERROR, "vm.import.vcenter.param.exclusive", Collections.emptyMap()); } if (existingVcenterId == null && StringUtils.isAnyBlank(vcenter, datacenterName, username, password)) { - throw new ServerApiException(ApiErrorCode.PARAM_ERROR, + throw Exceptions.serverApiException(ApiErrorCode.PARAM_ERROR, "vm.import.vcenter.params.incomplete", Collections.emptyMap()); } if (forceMsToImportVmFiles && useVddk) { - throw new ServerApiException(ApiErrorCode.PARAM_ERROR, + throw Exceptions.serverApiException(ApiErrorCode.PARAM_ERROR, "vm.import.force.ms.vddk.exclusive", Map.of("param1", ApiConstants.FORCE_MS_TO_IMPORT_VM_FILES, "param2", ApiConstants.USE_VDDK)); }