mirror of https://github.com/apache/cloudstack.git
fix
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
e71c52281b
commit
97a4629193
|
|
@ -16,10 +16,6 @@
|
|||
// under the License.
|
||||
package com.cloud.exception;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.context.ResponseMessageResolver;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class InvalidParameterValueException extends CloudRuntimeException {
|
||||
|
|
@ -30,8 +26,4 @@ public class InvalidParameterValueException extends CloudRuntimeException {
|
|||
super(message);
|
||||
}
|
||||
|
||||
public InvalidParameterValueException(String key, Map<String, Object> metadata) {
|
||||
super(ResponseMessageResolver.resolve(key, metadata));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,8 @@
|
|||
package com.cloud.exception;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.context.ResponseMessageResolver;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.SerialVersionUID;
|
||||
|
|
@ -34,10 +32,6 @@ public class PermissionDeniedException extends CloudRuntimeException {
|
|||
super(message);
|
||||
}
|
||||
|
||||
public PermissionDeniedException(String key, Map<String, Object> metadata) {
|
||||
super(ResponseMessageResolver.resolve(key, metadata));
|
||||
}
|
||||
|
||||
public PermissionDeniedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@
|
|||
package org.apache.cloudstack.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.context.ResponseMessageResolver;
|
||||
|
||||
import com.cloud.exception.CloudException;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
|
|
@ -37,14 +34,6 @@ public class ServerApiException extends CloudRuntimeException {
|
|||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ServerApiException.class.getName()));
|
||||
}
|
||||
|
||||
public ServerApiException(ApiErrorCode errorCode, String messageKey, Map<String, Object> errorMetadata) {
|
||||
_errorCode = errorCode;
|
||||
this.messageKey = messageKey;
|
||||
this.metadata = errorMetadata;
|
||||
_description = ResponseMessageResolver.getMessage(messageKey, errorMetadata);
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ServerApiException.class.getName()));
|
||||
}
|
||||
|
||||
public ServerApiException(ApiErrorCode errorCode, String description) {
|
||||
_errorCode = errorCode;
|
||||
_description = description;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
|||
import org.apache.cloudstack.api.response.UserDataResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.error.Exceptions;
|
||||
import org.apache.cloudstack.vm.lease.VMLeaseManager;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
|
|
@ -646,7 +647,7 @@ public abstract class BaseDeployVMCmd extends BaseAsyncCreateCustomIdCmd impleme
|
|||
try {
|
||||
networkId = Long.parseLong(networkid);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidParameterValueException("vm.deploy.network.not.found.ip.map",
|
||||
throw Exceptions.invalidParameterValueException("vm.deploy.network.not.found.ip.map",
|
||||
Map.of("networkId", networkid));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,6 +142,9 @@ public class CallContext {
|
|||
}
|
||||
|
||||
public boolean isCallingAccountRootAdmin() {
|
||||
if (getCallingUserId() == User.UID_SYSTEM) {
|
||||
return false;
|
||||
}
|
||||
if (isAccountRootAdmin == null) {
|
||||
AccountService accountService;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.cloudstack.error;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
|
|
@ -26,43 +27,84 @@ import org.apache.cloudstack.context.ResponseMessageResolver;
|
|||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.utils.Ternary;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class Exceptions {
|
||||
public final class Exceptions {
|
||||
|
||||
public static InvalidParameterValueException invalidParameterValueException(String errorKey, Map<String, Object> metadata) {
|
||||
return new InvalidParameterValueException(errorKey, metadata);
|
||||
private Exceptions() {
|
||||
}
|
||||
|
||||
public static InvalidParameterValueException invalidParameterValueException(String errorKey) {
|
||||
public static InvalidParameterValueException invalidParameterValueException(final String errorKey) {
|
||||
return invalidParameterValueException(errorKey, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static PermissionDeniedException permissionDeniedException(String errorKey, Map<String, Object> metadata) {
|
||||
return new PermissionDeniedException(errorKey, metadata);
|
||||
public static InvalidParameterValueException invalidParameterValueException(final String errorKey,
|
||||
final Map<String, Object> metadata) {
|
||||
return build(errorKey, metadata, InvalidParameterValueException::new);
|
||||
}
|
||||
|
||||
public static PermissionDeniedException permissionDeniedException(String errorKey) {
|
||||
public static PermissionDeniedException permissionDeniedException(final String errorKey) {
|
||||
return permissionDeniedException(errorKey, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static ServerApiException serverApiException(ApiErrorCode errorCode, String errorKey, Map<String, Object> metadata) {
|
||||
return new ServerApiException(errorCode, errorKey, metadata);
|
||||
public static PermissionDeniedException permissionDeniedException(final String errorKey,
|
||||
final Map<String, Object> metadata) {
|
||||
return build(errorKey, metadata, PermissionDeniedException::new);
|
||||
}
|
||||
|
||||
public static ServerApiException serverApiException(ApiErrorCode errorCode, String errorKey) {
|
||||
public static ServerApiException serverApiException(final ApiErrorCode errorCode,
|
||||
final String errorKey) {
|
||||
return serverApiException(errorCode, errorKey, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static CloudRuntimeException cloudRuntimeException(String errorKey, Map<String, Object> metadata) {
|
||||
return new CloudRuntimeException(ResponseMessageResolver.resolve(errorKey, metadata));
|
||||
public static ServerApiException serverApiException(final ApiErrorCode errorCode,
|
||||
final String errorKey,
|
||||
final Map<String, Object> metadata) {
|
||||
Ternary<String, String, Map<String, Object>> data =
|
||||
ResponseMessageResolver.resolve(errorKey, metadata);
|
||||
|
||||
ServerApiException ex = new ServerApiException(errorCode, data.first());
|
||||
enrich(ex, data);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
public static CloudRuntimeException cloudRuntimeException(String errorKey) {
|
||||
return new CloudRuntimeException(ResponseMessageResolver.resolve(errorKey, Collections.emptyMap()));
|
||||
public static CloudRuntimeException cloudRuntimeException(final String errorKey) {
|
||||
return cloudRuntimeException(errorKey, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static CloudRuntimeException cloudRuntimeException(String errorKey, Map<String, Object> metadata, Throwable th) {
|
||||
return new CloudRuntimeException(ResponseMessageResolver.resolve(errorKey, metadata), th);
|
||||
public static CloudRuntimeException cloudRuntimeException(final String errorKey,
|
||||
final Map<String, Object> metadata) {
|
||||
return build(errorKey, metadata, CloudRuntimeException::new);
|
||||
}
|
||||
|
||||
public static CloudRuntimeException cloudRuntimeException(final String errorKey,
|
||||
final Map<String, Object> metadata,
|
||||
final Throwable cause) {
|
||||
Ternary<String, String, Map<String, Object>> data =
|
||||
ResponseMessageResolver.resolve(errorKey, metadata);
|
||||
|
||||
CloudRuntimeException ex = new CloudRuntimeException(data.first(), cause);
|
||||
enrich(ex, data);
|
||||
return ex;
|
||||
}
|
||||
|
||||
private static <T extends CloudRuntimeException> T build(
|
||||
final String errorKey,
|
||||
final Map<String, Object> metadata,
|
||||
final Function<String, T> exceptionSupplier) {
|
||||
|
||||
Ternary<String, String, Map<String, Object>> data =
|
||||
ResponseMessageResolver.resolve(errorKey, metadata);
|
||||
|
||||
T ex = exceptionSupplier.apply(data.first());
|
||||
enrich(ex, data);
|
||||
return ex;
|
||||
}
|
||||
|
||||
private static void enrich(final CloudRuntimeException ex,
|
||||
final Ternary<String, String, Map<String, Object>> data) {
|
||||
ex.setMessageKey(data.second());
|
||||
ex.setMetadata(data.third());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -971,7 +971,6 @@ public class VirtualMachineManagerImplTest {
|
|||
|
||||
private void prepareAndRunCheckIfNewOfferingStorageScopeMatchesStoragePool(boolean isRootOnLocal, boolean isOfferingUsingLocal) {
|
||||
Mockito.doReturn(isRootOnLocal).when(virtualMachineManagerImpl).isRootVolumeOnLocalStorage(anyLong());
|
||||
Mockito.doReturn("vmInstanceMockedToString").when(vmInstanceMock).toString();
|
||||
Mockito.doReturn(isOfferingUsingLocal).when(diskOfferingMock).isUseLocalStorage();
|
||||
virtualMachineManagerImpl.checkIfNewOfferingStorageScopeMatchesStoragePool(vmInstanceMock, diskOfferingMock);
|
||||
}
|
||||
|
|
@ -1824,7 +1823,7 @@ public class VirtualMachineManagerImplTest {
|
|||
vmTO.setName(vmName);
|
||||
when(virtualMachineManagerImpl.findClusterAndHostIdForVm(vmInstanceMock, false)).thenReturn(new Pair<>(clusterMockId, null));
|
||||
CloudRuntimeException exception = assertThrows(CloudRuntimeException.class, () -> virtualMachineManagerImpl.persistDomainForKVM(vmInstanceMock, null));
|
||||
assertEquals("No available host to persist domain XML for Instance: " + vmName, exception.getMessage());
|
||||
assertEquals("vm.unmanage.kvm.no.host", exception.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1834,7 +1833,7 @@ public class VirtualMachineManagerImplTest {
|
|||
UnmanageInstanceAnswer failureAnswer = new UnmanageInstanceAnswer(null, false, "failure");
|
||||
when(agentManagerMock.send(anyLong(), any(UnmanageInstanceCommand.class))).thenReturn(failureAnswer);
|
||||
CloudRuntimeException exception = assertThrows(CloudRuntimeException.class, () -> virtualMachineManagerImpl.persistDomainForKVM(vmInstanceMock, null));
|
||||
assertEquals("Failed to persist domain XML for Instance: " + vmName + " on host ID: " + hostMockId, exception.getMessage());
|
||||
assertEquals("vm.unmanage.kvm.persist.failed", exception.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1843,7 +1842,7 @@ public class VirtualMachineManagerImplTest {
|
|||
when(vmInstanceMock.getHostId()).thenReturn(hostMockId);
|
||||
doThrow(new AgentUnavailableException("Agent down", hostMockId)).when(agentManagerMock).send(anyLong(), any(UnmanageInstanceCommand.class));
|
||||
CloudRuntimeException exception = assertThrows(CloudRuntimeException.class, () -> virtualMachineManagerImpl.persistDomainForKVM(vmInstanceMock, null));
|
||||
assertEquals("Failed to send command to persist domain XML for Instance: " + vmName + " on host ID: " + hostMockId, exception.getMessage());
|
||||
assertEquals("vm.unmanage.kvm.command.failed", exception.getMessageKey());
|
||||
}
|
||||
|
||||
@Test(expected = ConcurrentOperationException.class)
|
||||
|
|
@ -1860,7 +1859,7 @@ public class VirtualMachineManagerImplTest {
|
|||
when(vmInstanceMock.getHostId()).thenReturn(hostMockId);
|
||||
doThrow(new OperationTimedoutException(null, hostMockId, 123L, 60, false)).when(agentManagerMock).send(anyLong(), any(UnmanageInstanceCommand.class));
|
||||
CloudRuntimeException exception = assertThrows(CloudRuntimeException.class, () -> virtualMachineManagerImpl.persistDomainForKVM(vmInstanceMock, null));
|
||||
assertEquals("Failed to send command to persist domain XML for Instance: " + vmName + " on host ID: " + hostMockId, exception.getMessage());
|
||||
assertEquals("vm.unmanage.kvm.command.failed", exception.getMessageKey());
|
||||
}
|
||||
|
||||
@Test(expected = CloudRuntimeException.class)
|
||||
|
|
|
|||
|
|
@ -8906,7 +8906,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
|
||||
PhysicalNetwork physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
|
||||
if (physicalNetwork == null) {
|
||||
throw Exceptions.invalidParameterValueException("vm.assign.physical.network.not.found", Map.of("physicalNetworkId", physicalNetworkId, "tag", requiredOfferingTags));
|
||||
throw Exceptions.invalidParameterValueException("vm.assign.physical.network.not.found",
|
||||
Map.of("physicalNetworkId", physicalNetworkId, "tag", StringUtils.toNullSafeString(requiredOfferingTags)));
|
||||
}
|
||||
|
||||
long requiredOfferingId = requiredOffering.getId();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,68 @@
|
|||
|
||||
package org.apache.cloudstack.vm;
|
||||
|
||||
import static org.apache.cloudstack.api.ApiConstants.MAX_IOPS;
|
||||
import static org.apache.cloudstack.api.ApiConstants.MIN_IOPS;
|
||||
import static org.apache.cloudstack.storage.volume.VolumeImportUnmanageService.AllowImportVolumeWithBackingFile;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.CloningInstance;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.Completed;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.ConvertingInstance;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.Importing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.api.ApiCommandResourceType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ResponseGenerator;
|
||||
import org.apache.cloudstack.api.ResponseObject;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ImportVmCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ListImportVMTasksCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ListUnmanagedInstancesCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ListVmsForImportCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.UnmanageVMInstanceCmd;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.UnmanagedInstanceResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.error.Exceptions;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.reservation.dao.ReservationDao;
|
||||
import org.apache.cloudstack.resourcelimit.Reserver;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.storage.volume.VolumeOnStorageTO;
|
||||
import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.CheckConvertInstanceAnswer;
|
||||
|
|
@ -59,8 +121,6 @@ import com.cloud.exception.AgentUnavailableException;
|
|||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import org.apache.cloudstack.error.Exceptions;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
|
|
@ -141,68 +201,9 @@ import com.cloud.vm.VirtualMachineProfileImpl;
|
|||
import com.cloud.vm.VmDetailConstants;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDetailsDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.cloud.vm.dao.VMInstanceDetailsDao;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.api.ApiCommandResourceType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ResponseGenerator;
|
||||
import org.apache.cloudstack.api.ResponseObject;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ImportVmCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ListImportVMTasksCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ListUnmanagedInstancesCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ListVmsForImportCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.UnmanageVMInstanceCmd;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.UnmanagedInstanceResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.reservation.dao.ReservationDao;
|
||||
import org.apache.cloudstack.resourcelimit.Reserver;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.storage.volume.VolumeOnStorageTO;
|
||||
import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.cloudstack.api.ApiConstants.MAX_IOPS;
|
||||
import static org.apache.cloudstack.api.ApiConstants.MIN_IOPS;
|
||||
import static org.apache.cloudstack.storage.volume.VolumeImportUnmanageService.AllowImportVolumeWithBackingFile;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.CloningInstance;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.Completed;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.ConvertingInstance;
|
||||
import static org.apache.cloudstack.vm.ImportVmTask.Step.Importing;
|
||||
|
||||
public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
||||
protected Logger logger = LogManager.getLogger(UnmanagedVMsManagerImpl.class);
|
||||
|
|
@ -3114,7 +3115,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
|||
}
|
||||
final String hypervisorType = cmd.getHypervisor();
|
||||
if (!Hypervisor.HypervisorType.KVM.toString().equalsIgnoreCase(hypervisorType)) {
|
||||
throw Exceptions.invalidParameterValueException("vm.import.kvm.list.hypervisor.not.supported", Map.of("hypervisor", hypervisorType));
|
||||
throw Exceptions.invalidParameterValueException("vm.import.kvm.list.hypervisor.not.supported",
|
||||
Map.of("hypervisor", StringUtils.defaultIfEmpty(hypervisorType, "null")));
|
||||
}
|
||||
|
||||
String keyword = cmd.getKeyword();
|
||||
|
|
|
|||
|
|
@ -1545,7 +1545,6 @@ public class UserVmManagerImplTest {
|
|||
when(accountMock.getId()).thenReturn(userId);
|
||||
when(userVmDao.findById(vmId)).thenReturn(userVmVoMock);
|
||||
when(userVmVoMock.getAccountId()).thenReturn(accountId);
|
||||
when(userVmVoMock.getUuid()).thenReturn("a967643d-7633-4ab4-ac26-9c0b63f50cc1");
|
||||
when(accountDao.findById(accountId)).thenReturn(callerAccount);
|
||||
when(userVmVoMock.getState()).thenReturn(VirtualMachine.State.Starting);
|
||||
|
||||
|
|
@ -1561,7 +1560,6 @@ public class UserVmManagerImplTest {
|
|||
when(accountMock.getId()).thenReturn(userId);
|
||||
when(userVmDao.findById(vmId)).thenReturn(userVmVoMock);
|
||||
when(userVmVoMock.getAccountId()).thenReturn(accountId);
|
||||
when(userVmVoMock.getUuid()).thenReturn("a967643d-7633-4ab4-ac26-9c0b63f50cc1");
|
||||
when(accountDao.findById(accountId)).thenReturn(callerAccount);
|
||||
when(userVmVoMock.getState()).thenReturn(VirtualMachine.State.Running);
|
||||
when(userVmVoMock.getTemplateId()).thenReturn(currentTemplateId);
|
||||
|
|
@ -1582,7 +1580,6 @@ public class UserVmManagerImplTest {
|
|||
when(accountMock.getId()).thenReturn(userId);
|
||||
when(userVmDao.findById(vmId)).thenReturn(userVmVoMock);
|
||||
when(userVmVoMock.getAccountId()).thenReturn(accountId);
|
||||
when(userVmVoMock.getUuid()).thenReturn("a967643d-7633-4ab4-ac26-9c0b63f50cc1");
|
||||
when(accountDao.findById(accountId)).thenReturn(callerAccount);
|
||||
when(userVmVoMock.getState()).thenReturn(VirtualMachine.State.Running);
|
||||
when(userVmVoMock.getTemplateId()).thenReturn(currentTemplateId);
|
||||
|
|
@ -1850,25 +1847,25 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void validateIfVmSupportsMigrationTestVmIsNullThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("There is no VM by ID [%s].", 1L);
|
||||
String expectedMessageKey = "vm.assign.vm.not.found";
|
||||
|
||||
InvalidParameterValueException assertThrows = Assert.assertThrows(expectedInvalidParameterValueException, () -> {
|
||||
userVmManagerImpl.validateIfVmSupportsMigration(null, 1L);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateIfVmSupportsMigrationTestVmIsRunningThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Unable to move VM [%s] in [%s] state.", userVmVoMock, VirtualMachine.State.Running);
|
||||
String expectedMessageKey = "vm.assign.vm.not.right.state";
|
||||
Mockito.doReturn(VirtualMachine.State.Running).when(userVmVoMock).getState();
|
||||
|
||||
InvalidParameterValueException assertThrows = Assert.assertThrows(expectedInvalidParameterValueException, () -> {
|
||||
userVmManagerImpl.validateIfVmSupportsMigration(userVmVoMock, 1L);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1879,7 +1876,7 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.validateIfVmSupportsMigration(userVmVoMock, 1L);
|
||||
});
|
||||
|
||||
Assert.assertEquals("Migration is not supported for Shared FileSystem Instances.", assertThrows.getMessage());
|
||||
Assert.assertEquals("vm.assign.sharedfs.not.supported", assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1897,29 +1894,30 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void validateOldAndNewAccountsTestOldAccountIsNullThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Invalid old account [%s] for VM in domain [%s].", userVmVoMock.getAccountId(), assignVmCmdMock.getDomainId());
|
||||
String expectedMessageKey = "vm.assign.old.account.invalid";
|
||||
|
||||
InvalidParameterValueException assertThrows = Assert.assertThrows(expectedInvalidParameterValueException, () -> {
|
||||
userVmManagerImpl.validateOldAndNewAccounts(null, accountMock, userVmVoMock.getAccountId(), "", assignVmCmdMock.getDomainId());
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateOldAndNewAccountsTestNewAccountIsNullThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Invalid new account [%s] for VM in domain [%s].", assignVmCmdMock.getAccountName(), assignVmCmdMock.getDomainId());
|
||||
String expectedMessageKey = "vm.assign.new.account.invalid";
|
||||
Mockito.doReturn("test").when(assignVmCmdMock).getAccountName();
|
||||
|
||||
InvalidParameterValueException assertThrows = Assert.assertThrows(expectedInvalidParameterValueException, () -> {
|
||||
userVmManagerImpl.validateOldAndNewAccounts(accountMock, null, 1L, assignVmCmdMock.getAccountName(), assignVmCmdMock.getDomainId());
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateOldAndNewAccountsTestNewAccountStateIsDisabledThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("The new account owner [%s] is disabled.", accountMock);
|
||||
String expectedMessageKey = "vm.assign.new.account.disabled";
|
||||
|
||||
Mockito.doReturn(Account.State.DISABLED).when(accountMock).getState();
|
||||
|
||||
|
|
@ -1927,12 +1925,12 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.validateOldAndNewAccounts(accountMock, accountMock, 1L, "", 1L);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateOldAndNewAccountsTestOldAccountIsTheSameAsNewAccountThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("The new account [%s] is the same as the old account.", accountMock);
|
||||
String expectedMessageKey = "vm.assign.same.account";
|
||||
|
||||
Mockito.doReturn(Account.State.ENABLED).when(accountMock).getState();
|
||||
|
||||
|
|
@ -1940,7 +1938,7 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.validateOldAndNewAccounts(accountMock, accountMock, 1L, "", 1L);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1963,7 +1961,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void validateIfVmHasNoRulesTestPortForwardingRulesExistThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Remove any Port Forwarding rules for VM [%s] before assigning it to another user.", userVmVoMock);
|
||||
String expectedMessageKey = "vm.assign.portforwarding.rules.exist";
|
||||
|
||||
Mockito.doReturn(portForwardingRulesListMock).when(portForwardingRulesDaoMock).listByVm(Mockito.anyLong());
|
||||
|
||||
|
|
@ -1971,12 +1969,12 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.validateIfVmHasNoRules(userVmVoMock, 1L);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateIfVmHasNoRulesTestStaticNatRulesExistThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Remove the StaticNat rules for VM [%s] before assigning it to another user.", userVmVoMock);
|
||||
String expectedMessageKey = "vm.assign.staticnat.rules.exist";
|
||||
|
||||
Mockito.doReturn(firewallRuleVoListMock).when(firewallRulesDaoMock).listStaticNatByVmId(Mockito.anyLong());
|
||||
|
||||
|
|
@ -1984,12 +1982,12 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.validateIfVmHasNoRules(userVmVoMock, 1L);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateIfVmHasNoRulesTestLoadBalancingRulesExistThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Remove the Load Balancing rules for VM [%s] before assigning it to another user.", userVmVoMock);
|
||||
String expectedMessageKey = "vm.assign.loadbalancer.rules.exist";
|
||||
|
||||
Mockito.doReturn(loadBalancerVmMapVoListMock).when(loadBalancerVmMapDaoMock).listByInstanceId(Mockito.anyLong());
|
||||
|
||||
|
|
@ -1997,12 +1995,12 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.validateIfVmHasNoRules(userVmVoMock, 1L);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateIfVmHasNoRulesTestOneToOneNatRulesExistThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Remove the One to One Nat rule for VM [%s] for IP [%s].", userVmVoMock, ipAddressVoMock.toString());
|
||||
String expectedMessageKey = "vm.assign.onetoonat.rule.exists";
|
||||
|
||||
LinkedList<IPAddressVO> ipAddressVoList = new LinkedList<>();
|
||||
|
||||
|
|
@ -2014,7 +2012,7 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.validateIfVmHasNoRules(userVmVoMock, 1L);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2048,13 +2046,13 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void validateIfNewOwnerHasAccessToTemplateTestTemplateIsNullThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Template for VM [%s] cannot be found.", userVmVoMock.getUuid());
|
||||
String expectedMessageKey = "vm.assign.template.not.found";
|
||||
|
||||
InvalidParameterValueException assertThrows = Assert.assertThrows(expectedInvalidParameterValueException, () -> {
|
||||
userVmManagerImpl.validateIfNewOwnerHasAccessToTemplate(userVmVoMock, accountMock, null);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2109,13 +2107,13 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void addDefaultNetworkToNetworkListTestDefaultNetworkIsNullThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = "Unable to find a default network to start a VM.";
|
||||
String expectedMessageKey = "vm.assign.default.network.not.found";
|
||||
|
||||
InvalidParameterValueException assertThrows = Assert.assertThrows(expectedInvalidParameterValueException, () -> {
|
||||
userVmManagerImpl.addDefaultNetworkToNetworkList(networkVoListMock, null);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2138,7 +2136,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void addSecurityGroupsToVmTestIsVmWareAndSecurityGroupIdListIsNotNullThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = "Security group feature is not supported for VMWare hypervisor.";
|
||||
String expectedMessageKey = "vm.assign.securitygroup.vmware.not.supported";
|
||||
LinkedList<Long> securityGroupIdList = new LinkedList<>();
|
||||
|
||||
Mockito.doReturn(Hypervisor.HypervisorType.VMware).when(virtualMachineTemplateMock).getHypervisorType();
|
||||
|
|
@ -2147,7 +2145,7 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.addSecurityGroupsToVm(accountMock, userVmVoMock, virtualMachineTemplateMock, securityGroupIdList, networkMock);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2180,8 +2178,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void getOfferingWithRequiredAvailabilityForNetworkCreationTestRequiredOfferingsListHasNoOfferingsThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Unable to find network offering with availability [%s] to automatically create the network as a part of VM creation.",
|
||||
NetworkOffering.Availability.Required);
|
||||
String expectedMessageKey = "vm.assign.network.offering.required.not.found";
|
||||
LinkedList<NetworkOfferingVO> requiredOfferings = new LinkedList<>();
|
||||
|
||||
Mockito.doReturn(requiredOfferings).when(networkOfferingDaoMock).listByAvailability(NetworkOffering.Availability.Required, false);
|
||||
|
|
@ -2190,25 +2187,23 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.getOfferingWithRequiredAvailabilityForNetworkCreation();
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOfferingWithRequiredAvailabilityForNetworkCreationTestFirstOfferingIsNotEnabledThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Required network offering ID [%s] is not in [%s] state.", 1L, NetworkOffering.State.Enabled);
|
||||
String expectedMessageKey = "vm.assign.network.offering.required.not.enabled";
|
||||
|
||||
Mockito.doReturn(networkOfferingVoListMock).when(networkOfferingDaoMock).listByAvailability(NetworkOffering.Availability.Required, false);
|
||||
Mockito.doReturn(networkOfferingVoMock).when(networkOfferingVoListMock).get(0);
|
||||
|
||||
Mockito.doReturn(NetworkOffering.State.Disabled).when(networkOfferingVoMock).getState();
|
||||
|
||||
Mockito.doReturn(1L).when(networkOfferingVoMock).getId();
|
||||
|
||||
InvalidParameterValueException assertThrows = Assert.assertThrows(expectedInvalidParameterValueException, () -> {
|
||||
userVmManagerImpl.getOfferingWithRequiredAvailabilityForNetworkCreation();
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test(expected = CloudRuntimeException.class)
|
||||
|
|
@ -2225,7 +2220,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void selectApplicableNetworkToCreateVmTestVirtualNetworkHasMultipleNetworksThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("More than one default isolated network has been found for account [%s]; please specify networkIDs.", accountMock);
|
||||
String expectedMessageKey = "vm.assign.multiple.default.networks";
|
||||
HashSet<NetworkVO> applicableNetworks = new HashSet<>();
|
||||
LinkedList<NetworkVO> virtualNetworks = new LinkedList<>();
|
||||
|
||||
|
|
@ -2238,7 +2233,7 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.selectApplicableNetworkToCreateVm(accountMock, _dcMock, applicableNetworks);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2419,7 +2414,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void addAdditionalNetworksToVmTestNetworkIsNullThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = "Unable to find specified Network ID.";
|
||||
String expectedMessageKey = "vm.assign.network.not.found";
|
||||
LinkedList<Long> networkIdList = new LinkedList<>();
|
||||
HashSet<NetworkVO> applicableNetworks = Mockito.spy(new HashSet<>());
|
||||
HashMap<Long, String> requestedIPv4ForNics = new HashMap<>();
|
||||
|
|
@ -2431,12 +2426,12 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.addAdditionalNetworksToVm(userVmVoMock, accountMock, networkIdList, applicableNetworks, requestedIPv4ForNics, requestedIPv6ForNics);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addAdditionalNetworksToVmTestNetworkOfferingIsSystemOnlyThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Specified network [%s] is system only and cannot be used for VM deployment.", networkMock);
|
||||
String expectedMessageKey = "vm.assign.network.system.only";
|
||||
LinkedList<Long> networkIdList = new LinkedList<>();
|
||||
HashSet<NetworkVO> applicableNetworks = Mockito.spy(new HashSet<>());
|
||||
HashMap<Long, String> requestedIPv4ForNics = new HashMap<>();
|
||||
|
|
@ -2452,7 +2447,7 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.addAdditionalNetworksToVm(userVmVoMock, accountMock, networkIdList, applicableNetworks, requestedIPv4ForNics, requestedIPv6ForNics);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2542,12 +2537,12 @@ public class UserVmManagerImplTest {
|
|||
public void createApplicableNetworkToCreateVmTestPhysicalNetworkIsNullThrowsInvalidParameterValueException() {
|
||||
Mockito.doReturn(networkOfferingVoMock).when(userVmManagerImpl).getOfferingWithRequiredAvailabilityForNetworkCreation();
|
||||
|
||||
String expectedMessage = String.format("Unable to find physical network with ID [%s] and tag [%s].", 0L, null);
|
||||
String expectedMessageKey = "vm.assign.physical.network.not.found";
|
||||
InvalidParameterValueException assertThrows = Assert.assertThrows(expectedInvalidParameterValueException, () -> {
|
||||
userVmManagerImpl.createApplicableNetworkToCreateVm(accountMock, _dcMock);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2739,7 +2734,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void implementNetworkTestImplementedNetworkCatchException() throws ResourceUnavailableException, InsufficientCapacityException {
|
||||
String expectedMessage = String.format("Failed to implement network [%s] elements and resources as a part of network provision.", networkMock);
|
||||
String expectedMessageKey = "vm.assign.network.implement.failed";
|
||||
|
||||
CallContext callContextMock = Mockito.mock(CallContext.class);
|
||||
|
||||
|
|
@ -2757,13 +2752,13 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.implementNetwork(accountMock, _dcMock, networkMock);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBasicTypeNetworkForVmTestNetworkIdListIsNotEmptyThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = "Cannot move VM with Network IDs; this is a basic zone VM.";
|
||||
String expectedMessageKey = "vm.assign.basic.zone.network.ids.not.allowed";
|
||||
LinkedList<Long> networkIdList = new LinkedList<>();
|
||||
LinkedList<Long> securityGroupIdList = new LinkedList<>();
|
||||
|
||||
|
|
@ -2774,7 +2769,7 @@ public class UserVmManagerImplTest {
|
|||
securityGroupIdList);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2814,7 +2809,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void updateAdvancedTypeNetworkForVmTestSecurityGroupIsEnabledApplicableNetworksIsEmptyThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = "No network is specified, please specify one when you move the VM. For now, please add a network to VM on NICs tab.";
|
||||
String expectedMessageKey = "vm.assign.advanced.sg.no.network";
|
||||
LinkedList<Long> securityGroupIdList = Mockito.mock(LinkedList.class);
|
||||
LinkedList<Long> networkIdList = new LinkedList<>();
|
||||
|
||||
|
|
@ -2826,7 +2821,7 @@ public class UserVmManagerImplTest {
|
|||
});
|
||||
|
||||
Mockito.verify(securityGroupManagerMock).removeInstanceFromGroups(Mockito.any());
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2852,7 +2847,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void updateAdvancedTypeNetworkForVmTestSecurityGroupIsNotEnabledSecurityGroupIdListIsNotEmptyThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = "Cannot move VM with security groups; security group feature is not enabled in this zone.";
|
||||
String expectedMessageKey = "vm.assign.securitygroup.zone.not.enabled";
|
||||
LinkedList<Long> securityGroupIdList = Mockito.mock(LinkedList.class);
|
||||
LinkedList<Long> networkIdList = new LinkedList<>();
|
||||
|
||||
|
|
@ -2865,7 +2860,7 @@ public class UserVmManagerImplTest {
|
|||
_dcMock, networkIdList, securityGroupIdList);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2961,8 +2956,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void validateIfVolumesHaveNoSnapshotsTestVolumeHasSnapshotsThrowsInvalidParameterException() {
|
||||
String expectedMessage = String.format("Snapshots exist for volume [%s]. Detach volume or remove snapshots for the volume before assigning VM to another user.",
|
||||
volumeVOMock.getName());
|
||||
String expectedMessageKey = "vm.assign.volume.snapshots.exist";
|
||||
|
||||
LinkedList<VolumeVO> volumes = new LinkedList<>();
|
||||
volumes.add(volumeVOMock);
|
||||
|
|
@ -2975,7 +2969,7 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.validateIfVolumesHaveNoSnapshots(volumes);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2991,7 +2985,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
@Test
|
||||
public void moveVmToUserTestCallerIsNotRootAdminAndDomainAdminThrowsInvalidParameterValueException() {
|
||||
String expectedMessage = String.format("Only root or domain admins are allowed to assign VMs. Caller [%s] is of type [%s].", callerAccount, callerAccount.getType());
|
||||
String expectedMessageKey = "vm.assign.permission.denied";
|
||||
|
||||
Mockito.doReturn(false).when(accountManager).isRootAdmin(Mockito.anyLong());
|
||||
Mockito.doReturn(false).when(accountManager).isDomainAdmin(Mockito.anyLong());
|
||||
|
|
@ -3000,7 +2994,7 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.moveVmToUser(assignVmCmdMock);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -3024,7 +3018,7 @@ public class UserVmManagerImplTest {
|
|||
public void moveVmToUserTestProjectIdProvidedAndDomainIdIsNullThrowsInvalidParameterValueException() throws ResourceUnavailableException, InsufficientCapacityException,
|
||||
ResourceAllocationException {
|
||||
|
||||
String expectedMessage = "Please provide a valid domain ID; cannot assign VM to a project if domain ID is NULL.";
|
||||
String expectedMessageKey = "vm.assign.domain.id.null";
|
||||
|
||||
Mockito.doReturn(true).when(accountManager).isRootAdmin(Mockito.anyLong());
|
||||
Mockito.doReturn(userVmVoMock).when(userVmDao).findById(Mockito.anyLong());
|
||||
|
|
@ -3037,7 +3031,7 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.moveVmToUser(assignVmCmdMock);
|
||||
});
|
||||
|
||||
Assert.assertEquals(expectedMessage, assertThrows.getMessage());
|
||||
Assert.assertEquals(expectedMessageKey, assertThrows.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -3800,6 +3794,7 @@ public class UserVmManagerImplTest {
|
|||
public void testApplyLeaseOnUpdateInstanceForNoLease() {
|
||||
UserVmVO userVm = Mockito.mock(UserVmVO.class);
|
||||
when(userVm.getId()).thenReturn(vmId);
|
||||
when(userVm.getUuid()).thenReturn(UUID.randomUUID().toString());
|
||||
when(vmInstanceDetailsDao.listDetailsKeyPairs(anyLong(), anyList())).thenReturn(getLeaseDetails(5, VMLeaseManager.LeaseActionExecution.DISABLED.name()));
|
||||
userVmManagerImpl.applyLeaseOnUpdateInstance(userVm, 10, VMLeaseManager.ExpiryAction.STOP);
|
||||
Mockito.verify(userVmManagerImpl, Mockito.times(0)).addLeaseDetailsForInstance(any(), any(), any());
|
||||
|
|
@ -3809,6 +3804,7 @@ public class UserVmManagerImplTest {
|
|||
public void testApplyLeaseOnUpdateInstanceForLease() {
|
||||
UserVmVO userVm = Mockito.mock(UserVmVO.class);
|
||||
when(userVm.getId()).thenReturn(vmId);
|
||||
when(userVm.getUuid()).thenReturn(UUID.randomUUID().toString());
|
||||
when(vmInstanceDetailsDao.listDetailsKeyPairs(anyLong(), anyList())).thenReturn(getLeaseDetails(5, VMLeaseManager.LeaseActionExecution.PENDING.name()));
|
||||
userVmManagerImpl.applyLeaseOnUpdateInstance(userVm, 10, VMLeaseManager.ExpiryAction.STOP);
|
||||
Mockito.verify(userVmManagerImpl, Mockito.times(1)).addLeaseDetailsForInstance(any(), any(), any());
|
||||
|
|
@ -3818,6 +3814,7 @@ public class UserVmManagerImplTest {
|
|||
public void testApplyLeaseOnUpdateInstanceForDisabledLeaseInstance() {
|
||||
UserVmVO userVm = Mockito.mock(UserVmVO.class);
|
||||
when(userVm.getId()).thenReturn(vmId);
|
||||
when(userVm.getUuid()).thenReturn(UUID.randomUUID().toString());
|
||||
when(vmInstanceDetailsDao.listDetailsKeyPairs(anyLong(), anyList())).thenReturn(getLeaseDetails(5, VMLeaseManager.LeaseActionExecution.DISABLED.name()));
|
||||
userVmManagerImpl.applyLeaseOnUpdateInstance(userVm, 10, VMLeaseManager.ExpiryAction.STOP);
|
||||
Mockito.verify(userVmManagerImpl, Mockito.times(1)).addLeaseDetailsForInstance(any(), any(), any());
|
||||
|
|
@ -4040,7 +4037,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
InvalidParameterValueException ex = assertThrows(InvalidParameterValueException.class,
|
||||
() -> userVmManagerImpl.createVirtualMachine(deployVMCmd));
|
||||
assertEquals("Deployment of virtual machine is supported only for Zone-wide storage pools", ex.getMessage());
|
||||
assertEquals("vm.deploy.volume.storage.pool.zone.required", ex.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -4056,7 +4053,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
InvalidParameterValueException ex = assertThrows(InvalidParameterValueException.class,
|
||||
() -> userVmManagerImpl.createVirtualMachine(deployVMCmd));
|
||||
assertEquals("Deployment of virtual machine is supported only for Zone-wide storage pools", ex.getMessage());
|
||||
assertEquals("vm.deploy.volume.storage.pool.zone.required", ex.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -4190,7 +4187,7 @@ public class UserVmManagerImplTest {
|
|||
InvalidParameterValueException exception = assertThrows(InvalidParameterValueException.class, () -> {
|
||||
userVmManagerImpl.unmanageUserVM(vmId, null);
|
||||
});
|
||||
assertEquals("Unable to find a VM with ID = " + vmId, exception.getMessage());
|
||||
assertEquals("vm.unmanage.vm.not.found", exception.getMessageKey());
|
||||
verify(userVmDao, never()).acquireInLockTable(anyLong());
|
||||
verify(userVmDao, never()).releaseFromLockTable(anyLong());
|
||||
}
|
||||
|
|
@ -4214,7 +4211,7 @@ public class UserVmManagerImplTest {
|
|||
CloudRuntimeException exception = assertThrows(CloudRuntimeException.class, () -> {
|
||||
userVmManagerImpl.unmanageUserVM(vmId, null);
|
||||
});
|
||||
assertEquals("Instance: test-vm is not running or stopped, cannot be unmanaged", exception.getMessage());
|
||||
assertEquals("vm.unmanage.vm.not.right.state", exception.getMessage());
|
||||
verify(userVmDao, times(1)).releaseFromLockTable(vmId);
|
||||
}
|
||||
|
||||
|
|
@ -4254,7 +4251,7 @@ public class UserVmManagerImplTest {
|
|||
userVmManagerImpl.unmanageUserVM(vmId, null);
|
||||
});
|
||||
|
||||
assertEquals("Error while unmanaging VM: " + vmUuid, exception.getMessage());
|
||||
assertEquals("vm.unmanage.failed", exception.getMessageKey());
|
||||
verify(userVmManagerImpl, never()).cleanupUnmanageVMResources(any(UserVmVO.class));
|
||||
verify(userVmManagerImpl, never()).unmanageVMFromDB(anyLong());
|
||||
verify(userVmDao, times(1)).releaseFromLockTable(vmId);
|
||||
|
|
@ -4463,7 +4460,6 @@ public class UserVmManagerImplTest {
|
|||
|
||||
private ServiceOfferingVO getMockedServiceOffering(boolean custom, boolean customSpeed) {
|
||||
ServiceOfferingVO serviceOffering = mock(ServiceOfferingVO.class);
|
||||
when(serviceOffering.getUuid()).thenReturn("offering-uuid");
|
||||
when(serviceOffering.isDynamic()).thenReturn(custom);
|
||||
when(serviceOffering.isCustomCpuSpeedSupported()).thenReturn(customSpeed);
|
||||
if (custom) {
|
||||
|
|
@ -4484,7 +4480,7 @@ public class UserVmManagerImplTest {
|
|||
ServiceOfferingVO serviceOffering = getMockedServiceOffering(true, true);
|
||||
InvalidParameterValueException ex = Assert.assertThrows(InvalidParameterValueException.class, () ->
|
||||
userVmManagerImpl.validateCustomParameters(serviceOffering, Collections.emptyMap()));
|
||||
assertEquals("Need to specify custom parameter values cpu, cpu speed and memory when using custom offering", ex.getMessage());
|
||||
assertEquals("vm.validate.serviceoffering.custom.params.missing", ex.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -4497,7 +4493,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
InvalidParameterValueException ex = Assert.assertThrows(InvalidParameterValueException.class, () ->
|
||||
userVmManagerImpl.validateCustomParameters(serviceOffering, customParameters));
|
||||
Assert.assertTrue(ex.getMessage().startsWith("The CPU speed of this offering"));
|
||||
Assert.assertEquals("vm.validate.serviceoffering.cpu.speed.not.dynamic", ex.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -4532,7 +4528,7 @@ public class UserVmManagerImplTest {
|
|||
|
||||
InvalidParameterValueException ex = Assert.assertThrows(InvalidParameterValueException.class, () ->
|
||||
userVmManagerImpl.verifyVmLimits(userVmVoMock, customParameters));
|
||||
assertEquals("CPU number, Memory and CPU speed cannot be updated for a non-dynamic offering", ex.getMessage());
|
||||
assertEquals("vm.update.non.dynamic.cpu.memory.not.updatable", ex.getMessageKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -4550,6 +4546,6 @@ public class UserVmManagerImplTest {
|
|||
|
||||
InvalidParameterValueException ex = Assert.assertThrows(InvalidParameterValueException.class, () ->
|
||||
userVmManagerImpl.verifyVmLimits(userVmVoMock, customParameters));
|
||||
Assert.assertTrue(ex.getMessage().startsWith("The CPU speed of this offering"));
|
||||
Assert.assertEquals("vm.validate.serviceoffering.cpu.speed.not.dynamic", ex.getMessageKey());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -397,6 +397,7 @@ public class UnmanagedVMsManagerImplTest {
|
|||
when(responseGenerator.createUserVmResponse(any(ResponseObject.ResponseView.class), Mockito.anyString(), any(UserVm.class))).thenReturn(userVmResponses);
|
||||
|
||||
when(vmDao.findById(virtualMachineId)).thenReturn(virtualMachine);
|
||||
when(virtualMachine.getUuid()).thenReturn(UUID.randomUUID().toString());
|
||||
when(virtualMachine.getState()).thenReturn(VirtualMachine.State.Running);
|
||||
|
||||
when(unmanagedInstanceMock.getCpuCores()).thenReturn(8);
|
||||
|
|
@ -1041,9 +1042,11 @@ public class UnmanagedVMsManagerImplTest {
|
|||
public void testValidateSelectedConversionStoragePoolForVddkFailsWhenPoolDoesNotSupportDiskOfferings() {
|
||||
long poolId = 11L;
|
||||
StoragePoolVO selectedPool = mock(StoragePoolVO.class);
|
||||
when(selectedPool.getName()).thenReturn("Pool");
|
||||
ServiceOfferingVO serviceOffering = mock(ServiceOfferingVO.class);
|
||||
DiskOfferingVO rootDiskOffering = mock(DiskOfferingVO.class);
|
||||
DiskOfferingVO dataDiskOffering = mock(DiskOfferingVO.class);
|
||||
when(dataDiskOffering.getName()).thenReturn("DataOffering");
|
||||
|
||||
when(serviceOffering.getDiskOfferingId()).thenReturn(21L);
|
||||
when(primaryDataStoreDao.findById(poolId)).thenReturn(selectedPool);
|
||||
|
|
|
|||
|
|
@ -438,4 +438,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String toNullSafeString(String str) {
|
||||
if (str == null) {
|
||||
return "null";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import java.util.Map;
|
|||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.SerialVersionUID;
|
||||
import com.cloud.utils.Ternary;
|
||||
|
||||
/**
|
||||
* wrap exceptions that you know there's no point in dealing with.
|
||||
|
|
@ -57,27 +56,6 @@ public class CloudRuntimeException extends RuntimeException implements ErrorCont
|
|||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public CloudRuntimeException(String message, String messageKey, Map<String, Object> metadata) {
|
||||
super(message);
|
||||
this.messageKey = messageKey;
|
||||
this.metadata = metadata;
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public CloudRuntimeException(Ternary<String, String, Map<String, Object>> messageKeyAndMetadata) {
|
||||
super(messageKeyAndMetadata.first());
|
||||
this.messageKey = messageKeyAndMetadata.second();
|
||||
this.metadata = messageKeyAndMetadata.third();
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
public CloudRuntimeException(Ternary<String, String, Map<String, Object>> messageKeyAndMetadata, Throwable th) {
|
||||
super(messageKeyAndMetadata.first(), th);
|
||||
this.messageKey = messageKeyAndMetadata.second();
|
||||
this.metadata = messageKeyAndMetadata.third();
|
||||
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
|
||||
}
|
||||
|
||||
protected CloudRuntimeException() {
|
||||
super();
|
||||
|
||||
|
|
@ -117,6 +95,11 @@ public class CloudRuntimeException extends RuntimeException implements ErrorCont
|
|||
|
||||
public CloudRuntimeException(Throwable t) {
|
||||
super(t.getMessage(), t);
|
||||
if (t instanceof CloudRuntimeException) {
|
||||
CloudRuntimeException cre = (CloudRuntimeException)t;
|
||||
setMessageKey(cre.getMessageKey());
|
||||
setMetadata(cre.getMetadata());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -169,7 +152,15 @@ public class CloudRuntimeException extends RuntimeException implements ErrorCont
|
|||
return messageKey;
|
||||
}
|
||||
|
||||
public void setMessageKey(String messageKey) {
|
||||
this.messageKey = messageKey;
|
||||
}
|
||||
|
||||
public Map<String, Object> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(Map<String, Object> metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue