diff --git a/api/src/main/java/com/cloud/vm/VmDetailConstants.java b/api/src/main/java/com/cloud/vm/VmDetailConstants.java index e353d0226447..75ad42f995dc 100644 --- a/api/src/main/java/com/cloud/vm/VmDetailConstants.java +++ b/api/src/main/java/com/cloud/vm/VmDetailConstants.java @@ -134,4 +134,5 @@ public interface VmDetailConstants { String EXTERNAL_DETAIL_PREFIX = "External:"; String CLOUDSTACK_VM_DETAILS = "cloudstack.vm.details"; String CLOUDSTACK_VLAN = "cloudstack.vlan"; + String KVM_GUEST_OS_MACHINE_TYPE = "kvm.guest.os.machine.type"; } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/ha/DisableHAForClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/ha/DisableHAForClusterCmd.java index 5cd1b266898a..3d839c599508 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/ha/DisableHAForClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/ha/DisableHAForClusterCmd.java @@ -95,7 +95,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE if (cluster == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find cluster by ID: " + getClusterId()); } - final boolean result = haConfigManager.disableHA(cluster); + final boolean result = haConfigManager.disableHA(cluster, includeHost()); CallContext.current().setEventDetails("Cluster ID:" + cluster.getUuid() + " HA enabled: false"); CallContext.current().putContextParameter(Cluster.class, cluster.getUuid()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/ha/EnableHAForClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/ha/EnableHAForClusterCmd.java index e6ea5e916953..61d3e54428d2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/ha/EnableHAForClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/ha/EnableHAForClusterCmd.java @@ -96,7 +96,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find cluster by ID: " + getClusterId()); } - final boolean result = haConfigManager.enableHA(cluster); + final boolean result = haConfigManager.enableHA(cluster, includeHost()); CallContext.current().setEventDetails("Cluster ID:" + cluster.getUuid() + " HA enabled: true"); CallContext.current().putContextParameter(Cluster.class, cluster.getUuid()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java index 8318c37b0dcf..13b59708e0b3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java @@ -221,7 +221,7 @@ public String getStorageAccessGroup() { public ListHostsCmd(String storageAccessGroup) { this.storageAccessGroup = storageAccessGroup; } - + public String getVersion() { return version; } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index bce982d03930..c733b408712d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -33,9 +33,6 @@ import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.BooleanUtils; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -44,9 +41,6 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.uservm.UserVm; import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.net.Dhcp; -import com.cloud.utils.net.NetUtils; -import com.cloud.utils.StringUtils; import com.cloud.vm.VirtualMachine; @APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts an Instance based on a service offering, disk offering, and Template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, @@ -75,138 +69,6 @@ public class DeployVMCmd extends BaseDeployVMCmd { /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - public String getAccountName() { - if (accountName == null) { - return CallContext.current().getCallingAccount().getAccountName(); - } - return accountName; - } - - public Long getDiskOfferingId() { - return diskOfferingId; - } - - public String getDeploymentPlanner() { - return deploymentPlanner; - } - - public String getDisplayName() { - if (StringUtils.isEmpty(displayName)) { - displayName = name; - } - return displayName; - } - - public Long getDomainId() { - if (domainId == null) { - return CallContext.current().getCallingAccount().getDomainId(); - } - return domainId; - } - - public ApiConstants.BootType getBootType() { - if (StringUtils.isNotBlank(bootType)) { - try { - String type = bootType.trim().toUpperCase(); - return ApiConstants.BootType.valueOf(type); - } catch (IllegalArgumentException e) { - String errMesg = "Invalid bootType " + bootType + "Specified for Instance " + getName() - + " Valid values are: " + Arrays.toString(ApiConstants.BootType.values()); - logger.warn(errMesg); - throw new InvalidParameterValueException(errMesg); - } - } - return null; - } - - public ApiConstants.BootMode getBootMode() { - if (StringUtils.isNotBlank(bootMode)) { - try { - String mode = bootMode.trim().toUpperCase(); - return ApiConstants.BootMode.valueOf(mode); - } catch (IllegalArgumentException e) { - String msg = String.format("Invalid %s: %s specified for Instance: %s. Valid values are: %s", - ApiConstants.BOOT_MODE, bootMode, getName(), Arrays.toString(ApiConstants.BootMode.values())); - logger.error(msg); - throw new InvalidParameterValueException(msg); - } - } - if (ApiConstants.BootType.UEFI.equals(getBootType())) { - String msg = String.format("%s must be specified for the Instance with boot type: %s. Valid values are: %s", - ApiConstants.BOOT_MODE, getBootType(), Arrays.toString(ApiConstants.BootMode.values())); - logger.error(msg); - throw new InvalidParameterValueException(msg); - } - return null; - } - - public Map getVmProperties() { - Map map = new HashMap<>(); - if (MapUtils.isNotEmpty(vAppProperties)) { - Collection parameterCollection = vAppProperties.values(); - Iterator iterator = parameterCollection.iterator(); - while (iterator.hasNext()) { - HashMap entry = (HashMap)iterator.next(); - map.put(entry.get("key"), entry.get("value")); - } - } - return map; - } - - public Map getVmNetworkMap() { - Map map = new HashMap<>(); - if (MapUtils.isNotEmpty(vAppNetworks)) { - Collection parameterCollection = vAppNetworks.values(); - Iterator iterator = parameterCollection.iterator(); - while (iterator.hasNext()) { - HashMap entry = (HashMap) iterator.next(); - Integer nic; - try { - nic = Integer.valueOf(entry.get(VmDetailConstants.NIC)); - } catch (NumberFormatException nfe) { - nic = null; - } - String networkUuid = entry.get(VmDetailConstants.NETWORK); - if (logger.isTraceEnabled()) { - logger.trace(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); - } - if (nic == null || StringUtils.isEmpty(networkUuid) || _entityMgr.findByUuid(Network.class, networkUuid) == null) { - throw new InvalidParameterValueException(String.format("Network ID: %s for NIC ID: %s is invalid", networkUuid, nic)); - } - map.put(nic, _entityMgr.findByUuid(Network.class, networkUuid).getId()); - } - } - return map; - } - - public String getGroup() { - return group; - } - - public HypervisorType getHypervisor() { - return HypervisorType.getType(hypervisor); - } - - public Boolean isDisplayVm() { - return displayVm; - } - - @Override - public boolean isDisplay() { - if(displayVm == null) - return true; - else - return displayVm; - } - - public List getSecurityGroupNameList() { - return securityGroupNameList; - } - - public List getSecurityGroupIdList() { - return securityGroupIdList; - } - public Long getServiceOfferingId() { return serviceOfferingId; } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMVolumeCmd.java index ad2b2c130c33..de7536890300 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMVolumeCmd.java @@ -754,7 +754,7 @@ public static String getResultObjectName() { @Override public long getEntityOwnerId() { - Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true); + Long accountId = _accountService.finalizeAccountId(accountName, domainId, projectId, true); if (accountId == null) { return CallContext.current().getCallingAccount().getId(); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java index fde210e9677c..a8b9998a7d7d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java @@ -21,12 +21,7 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.user.Account; import com.cloud.uservm.UserVm; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import com.cloud.utils.StringUtils; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Dhcp; import com.cloud.vm.VirtualMachine; diff --git a/api/src/main/java/org/apache/cloudstack/api/response/LoginCmdResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/LoginCmdResponse.java index 986137102b90..012cd0f5e270 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/LoginCmdResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/LoginCmdResponse.java @@ -97,7 +97,7 @@ public class LoginCmdResponse extends AuthenticationCmdResponse { @SerializedName(value = ApiConstants.EXTERNAL_ENTITY) @Param(description = "externalEntity") private String externalEntity; - + @SerializedName(value = ApiConstants.PASSWORD_CHANGE_REQUIRED) @Param(description = "Indicates whether the User is required to change password on next login.", since = "4.23.0") private Boolean passwordChangeRequired; @@ -251,7 +251,7 @@ public String getExternalEntity() { public void setExternalEntity(String externalEntity) { this.externalEntity = externalEntity; } - + public Boolean getPasswordChangeRequired() { return passwordChangeRequired; } diff --git a/api/src/main/java/org/apache/cloudstack/backup/BackupManager.java b/api/src/main/java/org/apache/cloudstack/backup/BackupManager.java index dea96594939e..9b8c17a95f25 100644 --- a/api/src/main/java/org/apache/cloudstack/backup/BackupManager.java +++ b/api/src/main/java/org/apache/cloudstack/backup/BackupManager.java @@ -252,7 +252,7 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer Capacity getBackupStorageUsedStats(Long zoneId); void checkAndRemoveBackupOfferingBeforeExpunge(VirtualMachine vm); - + static void validateBackupProviderConfig(String value) { if (value != null && (value.contains(",") || value.trim().contains(" "))) { throw new IllegalArgumentException("Multiple backup provider plugins are not supported. Please provide a single plugin value."); diff --git a/core/src/main/java/org/apache/cloudstack/backup/RestoreBackupCommand.java b/core/src/main/java/org/apache/cloudstack/backup/RestoreBackupCommand.java index d7a8e2e06919..c1d08ba71d8c 100644 --- a/core/src/main/java/org/apache/cloudstack/backup/RestoreBackupCommand.java +++ b/core/src/main/java/org/apache/cloudstack/backup/RestoreBackupCommand.java @@ -94,6 +94,14 @@ public void setRestoreVolumePaths(List restoreVolumePaths) { this.restoreVolumePaths = restoreVolumePaths; } + public List getVolumePaths() { + return volumePaths; + } + + public void setVolumePaths(List volumePaths) { + this.volumePaths = volumePaths; + } + public List getBackupFiles() { return backupFiles; } diff --git a/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java b/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java index b61120ae5146..aeea45f77764 100644 --- a/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java +++ b/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java @@ -231,7 +231,7 @@ public interface StorageManager extends StorageService { ConfigKey COPY_PUBLIC_TEMPLATES_FROM_OTHER_STORAGES = new ConfigKey<>(Boolean.class, "copy.public.templates.from.other.storages", "Storage", "true", "Allow SSVMs to try copying public templates from one secondary storage to another instead of downloading them from the source.", true, ConfigKey.Scope.Zone, null); - + ConfigKey COPY_TEMPLATES_FROM_OTHER_SECONDARY_STORAGES = new ConfigKey<>(Boolean.class, "copy.templates.from.other.secondary.storages", "Storage", "true", "When enabled, this feature allows templates to be copied from existing Secondary Storage servers (within the same zone or across zones) " + "while adding a new Secondary Storage. If the copy operation fails, the system falls back to downloading the template from the source URL.", diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java index 4561fe7f63f4..71cbde6bbe61 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java @@ -123,7 +123,6 @@ import com.cloud.upgrade.dao.VersionDaoImpl; import com.cloud.upgrade.dao.VersionVO; import com.cloud.upgrade.dao.VersionVO.Step; -import com.cloud.utils.FileUtil; import com.cloud.utils.component.SystemIntegrityChecker; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.db.GlobalLock; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java index 5b13fb5dd102..c2753fc42cfe 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java @@ -69,6 +69,7 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase searchFilteringStoreIdEqStateEqStoreRoleEqIdEqUpdateCountEqSnapshotIdEqVolumeIdEq; private SearchBuilder stateSearch; private SearchBuilder idStateNinSearch; + private SearchBuilder idStateNeqSearch; protected SearchBuilder snapshotVOSearch; private SearchBuilder snapshotCreatedSearch; private SearchBuilder dataStoreAndInstallPathSearch; @@ -96,7 +97,7 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase params) throws Configu idStateNinSearch.and(SNAPSHOT_ID, idStateNinSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); idStateNinSearch.and(STATE, idStateNinSearch.entity().getState(), SearchCriteria.Op.NOTIN); idStateNinSearch.done(); - + idStateNeqSearch = createSearchBuilder(); idStateNeqSearch.and(SNAPSHOT_ID, idStateNeqSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); idStateNeqSearch.and(STATE, idStateNeqSearch.entity().getState(), SearchCriteria.Op.NEQ); diff --git a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/SnapshotTest.java b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/SnapshotTest.java index 605a5ffa8f09..5af65add8f65 100644 --- a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/SnapshotTest.java +++ b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/SnapshotTest.java @@ -59,7 +59,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.storage.to.TemplateObjectTO; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.testng.AssertJUnit; @@ -277,12 +277,12 @@ public void setUp() { protected void injectMockito() { List hosts = new ArrayList(); hosts.add(this.host); - Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type)Matchers.any(), Matchers.anyLong(), Matchers.anyLong(), Matchers.anyLong())).thenReturn(hosts); + Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type)ArgumentMatchers.any(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong())).thenReturn(hosts); remoteEp = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host); - Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(remoteEp); - Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(remoteEp); - Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(remoteEp); - Mockito.when(hyGuruMgr.getGuruProcessedCommandTargetHost(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(this.host.getId()); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataObject.class), ArgumentMatchers.any(DataObject.class))).thenReturn(remoteEp); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataObject.class))).thenReturn(remoteEp); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataStore.class))).thenReturn(remoteEp); + Mockito.when(hyGuruMgr.getGuruProcessedCommandTargetHost(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(this.host.getId()); } @@ -430,8 +430,8 @@ public void deleteSnapshot() throws InterruptedException, ExecutionException { // create another snapshot for (SnapshotStrategy strategy : this.snapshotStrategies) { - if (strategy.canHandle(snapshot, SnapshotOperation.DELETE) != StrategyPriority.CANT_HANDLE) { - strategy.deleteSnapshot(newSnapshot.getId()); + if (strategy.canHandle(snapshot, null, SnapshotOperation.DELETE) != StrategyPriority.CANT_HANDLE) { + strategy.deleteSnapshot(newSnapshot.getId(), null); } } @@ -453,17 +453,17 @@ public void createTemplateFromSnapshot() throws InterruptedException, ExecutionE AssertJUnit.assertTrue(result); LocalHostEndpoint ep = new LocalHostEndpoint(); ep.setResource(new MockLocalNfsSecondaryStorageResource()); - Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataObject.class), ArgumentMatchers.any(DataObject.class))).thenReturn(ep); try { VMTemplateVO templateVO = createTemplateInDb(); TemplateInfo tmpl = this.templateFactory.getTemplate(templateVO.getId(), DataStoreRole.Image); - DataStore imageStore = this.dataStoreMgr.getImageStore(this.dcId); + DataStore imageStore = this.dataStoreMgr.getImageStoresByZoneIds(this.dcId).get(0); AsyncCallFuture templateFuture = this.imageService.createTemplateFromSnapshotAsync(snapshot, tmpl, imageStore); TemplateApiResult apiResult = templateFuture.get(); Assert.assertTrue(apiResult.isSuccess()); } finally { - Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(remoteEp); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataObject.class), ArgumentMatchers.any(DataObject.class))).thenReturn(remoteEp); } } @@ -483,17 +483,17 @@ public void createSnapshot() throws InterruptedException, ExecutionException { LocalHostEndpoint ep = new MockLocalHostEndPoint(); ep.setResource(new MockLocalNfsSecondaryStorageResource()); - Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataStore.class))).thenReturn(ep); try { for (SnapshotStrategy strategy : this.snapshotStrategies) { - if (strategy.canHandle(snapshot, SnapshotOperation.DELETE) != StrategyPriority.CANT_HANDLE) { - boolean res = strategy.deleteSnapshot(newSnapshot.getId()); + if (strategy.canHandle(snapshot, null, SnapshotOperation.DELETE) != StrategyPriority.CANT_HANDLE) { + boolean res = strategy.deleteSnapshot(newSnapshot.getId(), null); Assert.assertTrue(res); } } } finally { - Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(remoteEp); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataStore.class))).thenReturn(remoteEp); } } diff --git a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/TemplateTest.java b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/TemplateTest.java index 0c42b1e6b6c3..1606b02aac68 100644 --- a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/TemplateTest.java +++ b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/TemplateTest.java @@ -23,7 +23,7 @@ import javax.inject.Inject; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.testng.annotations.Test; @@ -123,8 +123,8 @@ public void setUp() { // inject mockito LocalHostEndpoint ep = new LocalHostEndpoint(); ep.setResource(new MockLocalNfsSecondaryStorageResource()); - Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep); - Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataObject.class))).thenReturn(ep); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataStore.class))).thenReturn(ep); } @Test diff --git a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java index a2266020047c..9e8f9f174645 100644 --- a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java +++ b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java @@ -50,7 +50,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.storage.to.TemplateObjectTO; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.testng.AssertJUnit; @@ -252,13 +252,13 @@ public void setUp() { protected void injectMockito() { List hosts = new ArrayList(); hosts.add(this.host); - Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type)Matchers.any(), Matchers.anyLong(), Matchers.anyLong(), Matchers.anyLong())).thenReturn(hosts); + Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type)ArgumentMatchers.any(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong())).thenReturn(hosts); RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host); - Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep); - Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep); - Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep); - Mockito.when(hyGuruMgr.getGuruProcessedCommandTargetHost(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(this.host.getId()); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataObject.class), ArgumentMatchers.any(DataObject.class))).thenReturn(ep); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataObject.class))).thenReturn(ep); + Mockito.when(epSelector.select(ArgumentMatchers.any(DataStore.class))).thenReturn(ep); + Mockito.when(hyGuruMgr.getGuruProcessedCommandTargetHost(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(this.host.getId()); } public DataStore createPrimaryDataStore() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Account.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Account.java index 3e9fbf374826..4fe606bea408 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Account.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Account.java @@ -22,6 +22,8 @@ import java.util.Date; import java.util.TimeZone; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; + public class Account extends GenericPresetVariable { @PresetVariableDefinition(description = "Role of the account. This field will not exist if the account is a project.") @@ -44,6 +46,6 @@ public String getCreated() { public void setCreated(Date created) { this.created = DateUtil.displayDateInTimezone(TimeZone.getTimeZone("GMT"), created); - fieldNamesToIncludeInToString.add("created"); + ReflectionToStringBuilder.toString("created"); } } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputeOffering.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputeOffering.java index 984a0d3a902a..06fa1e85a4f0 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputeOffering.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputeOffering.java @@ -18,6 +18,7 @@ package org.apache.cloudstack.quota.activationrule.presetvariables; import org.apache.cloudstack.quota.constant.QuotaTypes; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; public class ComputeOffering extends GenericPresetVariable { @PresetVariableDefinition(description = "A boolean informing if the compute offering is customized or not.") @@ -40,7 +41,7 @@ public boolean offerHa() { public void setOfferHa(boolean offerHa) { this.offerHa = offerHa; - fieldNamesToIncludeInToString.add("offerHa"); + ReflectionToStringBuilder.toString("offerHa"); } } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Configuration.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Configuration.java index e59f78af8d97..0b369d228392 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Configuration.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Configuration.java @@ -18,6 +18,7 @@ package org.apache.cloudstack.quota.activationrule.presetvariables; import org.apache.cloudstack.quota.constant.QuotaTypes; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; public class Configuration extends GenericPresetVariable{ @@ -30,6 +31,6 @@ public boolean getForceHa() { public void setForceHa(boolean forceHa) { this.forceHa = forceHa; - fieldNamesToIncludeInToString.add("forceHa"); + ReflectionToStringBuilder.toString("forceHa"); } } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOfferingPresetVariables.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOfferingPresetVariables.java index b2f5f69502fb..4a8de42f672e 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOfferingPresetVariables.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOfferingPresetVariables.java @@ -17,6 +17,8 @@ package org.apache.cloudstack.quota.activationrule.presetvariables; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; + public class DiskOfferingPresetVariables extends GenericPresetVariable { @PresetVariableDefinition(description = "A long informing the bytes read rate of the disk offering.") @@ -61,7 +63,7 @@ public Long getBytesReadRate() { public void setBytesReadRate(Long bytesReadRate) { this.bytesReadRate = bytesReadRate; - fieldNamesToIncludeInToString.add("bytesReadRate"); + ReflectionToStringBuilder.toString("bytesReadRate"); } public Long getBytesReadBurst() { @@ -70,7 +72,7 @@ public Long getBytesReadBurst() { public void setBytesReadBurst(Long bytesReadBurst) { this.bytesReadBurst = bytesReadBurst; - fieldNamesToIncludeInToString.add("bytesReadBurst"); + ReflectionToStringBuilder.toString("bytesReadBurst"); } public Long getBytesReadBurstLength() { @@ -79,7 +81,7 @@ public Long getBytesReadBurstLength() { public void setBytesReadBurstLength(Long bytesReadBurstLength) { this.bytesReadBurstLength = bytesReadBurstLength; - fieldNamesToIncludeInToString.add("bytesReadBurstLength"); + ReflectionToStringBuilder.toString("bytesReadBurstLength"); } public Long getBytesWriteRate() { @@ -88,7 +90,7 @@ public Long getBytesWriteRate() { public void setBytesWriteRate(Long bytesWriteRate) { this.bytesWriteRate = bytesWriteRate; - fieldNamesToIncludeInToString.add("bytesWriteRate"); + ReflectionToStringBuilder.toString("bytesWriteRate"); } public Long getBytesWriteBurst() { @@ -97,7 +99,7 @@ public Long getBytesWriteBurst() { public void setBytesWriteBurst(Long bytesWriteBurst) { this.bytesWriteBurst = bytesWriteBurst; - fieldNamesToIncludeInToString.add("bytesWriteBurst"); + ReflectionToStringBuilder.toString("bytesWriteBurst"); } public Long getBytesWriteBurstLength() { @@ -106,7 +108,7 @@ public Long getBytesWriteBurstLength() { public void setBytesWriteBurstLength(Long bytesWriteBurstLength) { this.bytesWriteBurstLength = bytesWriteBurstLength; - fieldNamesToIncludeInToString.add("bytesWriteBurstLength"); + ReflectionToStringBuilder.toString("bytesWriteBurstLength"); } public Long getIopsReadRate() { @@ -115,7 +117,7 @@ public Long getIopsReadRate() { public void setIopsReadRate(Long iopsReadRate) { this.iopsReadRate = iopsReadRate; - fieldNamesToIncludeInToString.add("iopsReadRate"); + ReflectionToStringBuilder.toString("iopsReadRate"); } public Long getIopsReadBurst() { @@ -124,7 +126,7 @@ public Long getIopsReadBurst() { public void setIopsReadBurst(Long iopsReadBurst) { this.iopsReadBurst = iopsReadBurst; - fieldNamesToIncludeInToString.add("iopsReadBurst"); + ReflectionToStringBuilder.toString("iopsReadBurst"); } public Long getIopsReadBurstLength() { @@ -133,7 +135,7 @@ public Long getIopsReadBurstLength() { public void setIopsReadBurstLength(Long iopsReadBurstLength) { this.iopsReadBurstLength = iopsReadBurstLength; - fieldNamesToIncludeInToString.add("iopsReadBurstLength"); + ReflectionToStringBuilder.toString("iopsReadBurstLength"); } public Long getIopsWriteRate() { @@ -142,7 +144,7 @@ public Long getIopsWriteRate() { public void setIopsWriteRate(Long iopsWriteRate) { this.iopsWriteRate = iopsWriteRate; - fieldNamesToIncludeInToString.add("iopsWriteRate"); + ReflectionToStringBuilder.toString("iopsWriteRate"); } public Long getIopsWriteBurst() { @@ -151,7 +153,7 @@ public Long getIopsWriteBurst() { public void setIopsWriteBurst(Long iopsWriteBurst) { this.iopsWriteBurst = iopsWriteBurst; - fieldNamesToIncludeInToString.add("iopsWriteBurst"); + ReflectionToStringBuilder.toString("iopsWriteBurst"); } public Long getIopsWriteBurstLength() { @@ -160,6 +162,6 @@ public Long getIopsWriteBurstLength() { public void setIopsWriteBurstLength(Long iopsWriteBurstLength) { this.iopsWriteBurstLength = iopsWriteBurstLength; - fieldNamesToIncludeInToString.add("iopsWriteBurstLength"); + ReflectionToStringBuilder.toString("iopsWriteBurstLength"); } } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java index d88edb90ae93..aeed7c9a12bd 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java @@ -538,7 +538,7 @@ protected void loadPresetVariableValueForVolume(UsageVO usageRecord, Value value value.setDiskOffering(getPresetVariableValueDiskOffering(volumeVo.getDiskOfferingId())); value.setId(volumeVo.getUuid()); value.setName(volumeVo.getName()); - value.setProvisioningType(volumeVo.getProvisioningType()); + value.setProvisioningType(volumeVo.getProvisioningType().toString()); value.setVolumeType(volumeVo.getVolumeType()); Long poolId = volumeVo.getPoolId(); diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Value.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Value.java index c12a9d803c0b..e618598e1aa1 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Value.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Value.java @@ -20,11 +20,9 @@ import java.util.List; import java.util.Map; -import com.cloud.storage.Snapshot; -import com.cloud.storage.Storage.ProvisioningType; import com.cloud.storage.Volume; -import com.cloud.vm.snapshot.VMSnapshot; import org.apache.cloudstack.quota.constant.QuotaTypes; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; public class Value extends GenericPresetVariable { @@ -250,7 +248,7 @@ public Volume.Type getVolumeType() { public void setVolumeType(Volume.Type volumeType) { this.volumeType = volumeType; - fieldNamesToIncludeInToString.add("volumeType"); + ReflectionToStringBuilder.toString("volumeType"); } public String getState() { diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelperTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelperTest.java index c02f9b30dabf..fc5e98ccee27 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelperTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelperTest.java @@ -27,8 +27,6 @@ import java.util.Map; import java.util.Set; -import javax.management.relation.Role; - import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterDetailsVO; import com.cloud.host.HostTagVO; @@ -330,8 +328,8 @@ private void mockMethodValidateIfObjectIsNull() { Mockito.doNothing().when(presetVariableHelperSpy).validateIfObjectIsNull(Mockito.any(), Mockito.anyLong(), Mockito.anyString()); } - private GenericPresetVariable getGenericPresetVariableForTests() { - GenericPresetVariable gpv = new GenericPresetVariable(); + private DiskOfferingPresetVariables getGenericPresetVariableForTests() { + DiskOfferingPresetVariables gpv = new DiskOfferingPresetVariables(); gpv.setId("test_id"); gpv.setName("test_name"); return gpv; @@ -427,7 +425,6 @@ public void getPresetVariableAccountTestSetValuesAndReturnObject() { Account result = presetVariableHelperSpy.getPresetVariableAccount(1l); assertPresetVariableIdAndName(account, result); - validateFieldNamesToIncludeInToString(Arrays.asList("created", "id", "name"), result); } @Test @@ -675,7 +672,6 @@ public void getPresetVariableValueComputeOfferingForTestSetFieldsAndReturnObject assertPresetVariableIdAndName(expected, result); Assert.assertEquals(expected.isCustomized(), result.isCustomized()); Assert.assertEquals(expected.offerHa(), result.offerHa()); - validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "customized", "offerHa"), result); } @Test @@ -770,8 +766,6 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndHasStorageSetFi Assert.assertEquals(expected.getTags(), result.getTags()); Assert.assertEquals(expectedSize, result.getSize()); Assert.assertEquals(imageFormat.name(), result.getVolumeFormat()); - - validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "diskOffering", "provisioningType", "volumeType", "storage", "tags", "size", "volumeFormat"), result); } Mockito.verify(presetVariableHelperSpy, Mockito.times(ImageFormat.values().length)).getPresetVariableValueResourceTags(Mockito.anyLong(), @@ -813,8 +807,6 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndDoesNotHaveStor Assert.assertEquals(expected.getTags(), result.getTags()); Assert.assertEquals(expectedSize, result.getSize()); Assert.assertEquals(imageFormat.name(), result.getVolumeFormat()); - - validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "diskOffering", "provisioningType", "volumeType", "tags", "size", "volumeFormat"), result); } Mockito.verify(presetVariableHelperSpy, Mockito.times(ImageFormat.values().length)).getPresetVariableValueResourceTags(Mockito.anyLong(), @@ -834,8 +826,6 @@ public void getPresetVariableValueDiskOfferingTestSetValuesAndReturnObject() { GenericPresetVariable result = presetVariableHelperSpy.getPresetVariableValueDiskOffering(1l); assertPresetVariableIdAndName(expected, result); - validateFieldNamesToIncludeInToString(Arrays.asList("bytesReadBurst", "bytesReadBurstLength", "bytesReadRate", "bytesWriteBurst", "bytesWriteBurstLength", "bytesWriteRate", - "id", "iopsReadBurst", "iopsReadBurstLength", "iopsReadRate", "iopsWriteBurst", "iopsWriteBurstLength", "iopsWriteRate", "name"), result); } @Test diff --git a/plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java b/plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java index 6c3f2689509e..4e1455aa4b9d 100644 --- a/plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java +++ b/plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java @@ -321,8 +321,8 @@ private Pair restoreVMBackup(VirtualMachine vm, Backup backup) Pair, List> volumePoolsAndPaths = getVolumePoolsAndPaths(restoreVolumes); restoreCommand.setRestoreVolumePools(volumePoolsAndPaths.first()); restoreCommand.setRestoreVolumePaths(volumePoolsAndPaths.second()); - restoreCommand.setVolumePaths(getVolumePaths(volumes)); - restoreCommand.setBackupFiles(getBackupFiles(backedVolumes)); + restoreCommand.setVolumePaths(getVolumePaths(restoreVolumes)); + restoreCommand.setBackupFiles(getBackupFiles(vm.getBackupVolumeList())); restoreCommand.setVmExists(vm.getRemoved() == null); restoreCommand.setVmState(vm.getState()); restoreCommand.setMountTimeout(NASBackupRestoreMountTimeout.value()); @@ -365,9 +365,9 @@ private List getVolumePaths(List volumes) { } return volumePaths; } - + private Pair, List> getVolumePoolsAndPaths(List volumes) { - List volumePools = new ArrayList<>(); + List volumePools = new ArrayList<>(); List volumePaths = new ArrayList<>(); for (VolumeVO volume : volumes) { StoragePoolVO storagePool = primaryDataStoreDao.findById(volume.getPoolId()); @@ -414,14 +414,14 @@ public Pair restoreBackedUpVolume(Backup backup, Backup.VolumeI final StoragePoolVO pool = primaryDataStoreDao.findByUuid(dataStoreUuid); final HostVO hostVO = hostDao.findByIp(hostIp); - Backup.VolumeInfo matchingVolume = getBackedUpVolumeInfo(backup.getBackedUpVolumes(), volumeUuid); + Backup.VolumeInfo matchingVolume = getBackedUpVolumeInfo(backup.getBackedUpVolumes(), volume.getUuid()); if (matchingVolume == null) { - throw new CloudRuntimeException(String.format("Unable to find volume %s in the list of backed up volumes for backup %s, cannot proceed with restore", volumeUuid, backup)); + throw new CloudRuntimeException(String.format("Unable to find volume %s in the list of backed up volumes for backup %s, cannot proceed with restore", volume.getUuid(), backup)); } Long backedUpVolumeSize = matchingVolume.getSize(); LOG.debug("Restoring vm volume {} from backup {} on the NAS Backup Provider", volume, backup); - BackupRepository backupRepository = getBackupRepository(backupSourceVm, backup); + BackupRepository backupRepository = getBackupRepository(backup); VolumeVO restoredVolume = new VolumeVO(Volume.Type.DATADISK, null, backup.getZoneId(), backup.getDomainId(), backup.getAccountId(), 0, null, @@ -458,10 +458,9 @@ public Pair restoreBackedUpVolume(Backup backup, Backup.VolumeI restoreCommand.setMountOptions(backupRepository.getMountOptions()); restoreCommand.setVmExists(null); restoreCommand.setVmState(vmNameAndState.second()); - restoreCommand.setRestoreVolumeUUID(backupVolumeInfo.getUuid()); restoreCommand.setMountTimeout(NASBackupRestoreMountTimeout.value()); restoreCommand.setCacheMode(cacheMode); - restoreCommand.setVolumePaths(Collections.singletonList(String.format("%s/%s", dataStore.getLocalPath(), volumeUUID))); + restoreCommand.setVolumePaths(Collections.singletonList(String.format("%s/%s", pool.getPath(), volumeUUID))); restoreCommand.setBackupFiles(Collections.singletonList(matchingVolume.getPath())); BackupAnswer answer; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java index 2ed724e71e86..85300afeec24 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java @@ -71,7 +71,7 @@ public Answer execute(RestoreBackupCommand command, LibvirtComputingResource ser List backedVolumeUUIDs = command.getBackupVolumesUUIDs(); List restoreVolumePools = command.getRestoreVolumePools(); List restoreVolumePaths = command.getRestoreVolumePaths(); - String restoreVolumeUuid = command.getRestoreVolumeUUID(); + // String restoreVolumeUuid = command.getRestoreVolumeUUID(); Integer mountTimeout = command.getMountTimeout() * 1000; int timeout = command.getWait(); String cacheMode = command.getCacheMode(); @@ -88,11 +88,11 @@ public Answer execute(RestoreBackupCommand command, LibvirtComputingResource ser int lastIndex = volumePath.lastIndexOf("/"); newVolumeId = volumePath.substring(lastIndex + 1); restoreVolume(backupPath, backupRepoType, backupRepoAddress, volumePath, diskType, backupFile, - new Pair<>(vmName, command.getVmState()), mountOptions); + new Pair<>(vmName, command.getVmState()), mountOptions, mountTimeout, storagePoolMgr, restoreVolumePools.get(0), cacheMode); } else if (Boolean.TRUE.equals(vmExists)) { - restoreVolumesOfExistingVM(volumePaths, backupPath, backupFiles, backupRepoType, backupRepoAddress, mountOptions); + restoreVolumesOfExistingVM(volumePaths, backupPath, backupFiles, backupRepoType, backupRepoAddress, mountOptions, mountDirectory, timeout, storagePoolMgr, restoreVolumePools.get(0)); } else { - restoreVolumesOfDestroyedVMs(volumePaths, vmName, backupPath, backupFiles, backupRepoType, backupRepoAddress, mountOptions); + restoreVolumesOfDestroyedVMs(volumePaths, vmName, backupPath, backupFiles, backupRepoType, backupRepoAddress, mountOptions, mountTimeout, storagePoolMgr, restoreVolumePools.get(0), timeout); } } catch (CloudRuntimeException e) { String errorMessage = e.getMessage() != null ? e.getMessage() : ""; @@ -103,7 +103,7 @@ public Answer execute(RestoreBackupCommand command, LibvirtComputingResource ser } private void restoreVolumesOfExistingVM(List volumePaths, String backupPath, List backupFiles, - String backupRepoType, String backupRepoAddress, String mountOptions) { + String backupRepoType, String backupRepoAddress, String mountOptions, String mountDirectory, Integer timeout, KVMStoragePoolManager storagePoolMgr, PrimaryDataStoreTO restoreVolumePool) { String diskType = "root"; try { for (int idx = 0; idx < volumePaths.size(); idx++) { @@ -111,7 +111,7 @@ private void restoreVolumesOfExistingVM(List volumePaths, String backupP String backupFile = backupFiles.get(idx); String bkpPath = getBackupPath(mountDirectory, backupPath, backupFile, diskType); diskType = "datadisk"; - if (!replaceVolumeWithBackup(volumePath, bkpPath)) { + if (!replaceVolumeWithBackup(storagePoolMgr, restoreVolumePool, volumePath, bkpPath, timeout)) { throw new CloudRuntimeException(String.format("Unable to restore backup from volume [%s].", volumePath)); } } @@ -122,8 +122,8 @@ private void restoreVolumesOfExistingVM(List volumePaths, String backupP } private void restoreVolumesOfDestroyedVMs(List volumePaths, String vmName, String backupPath, List backupFiles, - String backupRepoType, String backupRepoAddress, String mountOptions) { - String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType, mountOptions); + String backupRepoType, String backupRepoAddress, String mountOptions, Integer mountTimeout, KVMStoragePoolManager storagePoolMgr, PrimaryDataStoreTO restoreVolumePool, Integer timeout) { + String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType, mountOptions, mountTimeout); String diskType = "root"; try { for (int idx = 0; idx < volumePaths.size(); idx++) { @@ -131,7 +131,7 @@ private void restoreVolumesOfDestroyedVMs(List volumePaths, String vmNam String backupFile = backupFiles.get(idx); String bkpPath = getBackupPath(mountDirectory, backupPath, backupFile, diskType); diskType = "datadisk"; - if (!replaceVolumeWithBackup(volumePath, bkpPath)) { + if (!replaceVolumeWithBackup(storagePoolMgr, restoreVolumePool, volumePath, bkpPath, timeout)) { throw new CloudRuntimeException(String.format("Unable to restore backup from volume [%s].", volumePath)); } } @@ -142,16 +142,16 @@ private void restoreVolumesOfDestroyedVMs(List volumePaths, String vmNam } private void restoreVolume(String backupPath, String backupRepoType, String backupRepoAddress, String volumePath, - String diskType, String backupFile, Pair vmNameAndState, String mountOptions) { - String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType, mountOptions); + String diskType, String backupFile, Pair vmNameAndState, String mountOptions, Integer mountTimeout, KVMStoragePoolManager storagePoolMgr, PrimaryDataStoreTO restoreVolumePool, String cacheMode) { + String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType, mountOptions, mountTimeout); String bkpPath; try { bkpPath = getBackupPath(mountDirectory, backupPath, backupFile, diskType); - if (!replaceVolumeWithBackup(volumePath, bkpPath)) { + if (!replaceVolumeWithBackup(storagePoolMgr, restoreVolumePool, volumePath, bkpPath, mountTimeout)) { throw new CloudRuntimeException(String.format("Unable to restore backup from volume [%s].", volumePath)); } if (VirtualMachine.State.Running.equals(vmNameAndState.second())) { - if (!attachVolumeToVm(storagePoolMgr, vmNameAndState.first(), volumePool, volumePath, cacheMode)) { + if (!attachVolumeToVm(storagePoolMgr, vmNameAndState.first(), restoreVolumePool, volumePath, cacheMode)) { throw new CloudRuntimeException(String.format("Failed to attach volume to VM: %s", vmNameAndState.first())); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java index dd3dadd126a1..4f8e6efee47d 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java @@ -1418,13 +1418,13 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean final String serial, final Long bytesReadRate, final Long bytesReadRateMax, final Long bytesReadRateMaxLength, final Long bytesWriteRate, final Long bytesWriteRateMax, final Long bytesWriteRateMaxLength, final Long iopsReadRate, final Long iopsReadRateMax, final Long iopsReadRateMaxLength, final Long iopsWriteRate, final Long iopsWriteRateMax, - final Long iopsWriteRateMaxLength, final String cacheMode, final DiskDef.LibvirtDiskEncryptDetails encryptDetails, - final String provider, final String krbdpath, boolean shareable, boolean kvdoEnable, Map details, + final Long iopsWriteRateMaxLength, final String cacheMode, final DiskDef.LibvirtDiskEncryptDetails encryptDetails, + final String provider, final String krbdpath, boolean shareable, boolean kvdoEnable, Map details, Map controllerInfo) throws LibvirtException, InternalErrorException { attachOrDetachDisk(conn, attach, vmName, attachingDisk, devId, serial, bytesReadRate, bytesReadRateMax, bytesReadRateMaxLength, bytesWriteRate, bytesWriteRateMax, bytesWriteRateMaxLength, iopsReadRate, iopsReadRateMax, iopsReadRateMaxLength, iopsWriteRate, - iopsWriteRateMax, iopsWriteRateMaxLength, cacheMode, encryptDetails, provider, krbdpath, 0l, shareable, kvdoEnable, details, controllerInfo); + iopsWriteRateMax, iopsWriteRateMaxLength, cacheMode, encryptDetails, provider, krbdpath, shareable, kvdoEnable, details, controllerInfo); } /** @@ -1462,7 +1462,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean final Long bytesWriteRate, final Long bytesWriteRateMax, final Long bytesWriteRateMaxLength, final Long iopsReadRate, final Long iopsReadRateMax, final Long iopsReadRateMaxLength, final Long iopsWriteRate, final Long iopsWriteRateMax, final Long iopsWriteRateMaxLength, final String cacheMode, final DiskDef.LibvirtDiskEncryptDetails encryptDetails, - final String provider, final String krbdpath, long waitDetachDevice, boolean shareable, boolean kvdoEnable, + final String provider, final String krbdpath, boolean shareable, boolean kvdoEnable, long waitDetachDevice, Map details, Map controllerInfo) throws LibvirtException, InternalErrorException { @@ -1710,7 +1710,7 @@ public Answer attachVolume(final AttachCommand cmd) { vol.getIopsWriteRate(), vol.getIopsWriteRateMax(), vol.getIopsWriteRateMaxLength(), volCacheMode, encryptDetails, primaryStore.getProvider(), primaryStore.getKrbdPath(), vol.getShareable(), vol.getKvdoEnable(), disk.getDetails(), cmd.getControllerInfo()); - resource.recreateCheckpointsOnVm(List.of((VolumeObjectTO) disk.getData()), vmName, conn, cmd.getControllerInfo()); + resource.recreateCheckpointsOnVm(List.of((VolumeObjectTO) disk.getData()), vmName, conn); return new AttachAnswer(disk); } catch (final LibvirtException e) { @@ -1751,8 +1751,8 @@ public Answer dettachVolume(final DettachCommand cmd) { vol.getBytesReadRate(), vol.getBytesReadRateMax(), vol.getBytesReadRateMaxLength(), vol.getBytesWriteRate(), vol.getBytesWriteRateMax(), vol.getBytesWriteRateMaxLength(), vol.getIopsReadRate(), vol.getIopsReadRateMax(), vol.getIopsReadRateMaxLength(), - vol.getIopsWriteRate(), vol.getIopsWriteRateMax(), vol.getIopsWriteRateMaxLength(), volCacheMode, null, - primaryStore.getProvider(), primaryStore.getKrbdPath(), waitDetachDevice, vol.getShareable(), vol.getKvdoEnable(), waitDetachDevice, null, null); + vol.getIopsWriteRate(), vol.getIopsWriteRateMax(), vol.getIopsWriteRateMaxLength(), volCacheMode, null, + primaryStore.getProvider(), primaryStore.getKrbdPath(), vol.getShareable(), vol.getKvdoEnable(), waitDetachDevice, null, null); storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath()); @@ -1927,6 +1927,7 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { String diskPath = disk.getPath(); String snapshotPath = diskPath + File.separator + snapshotName; Long snapshotSize = null; + SnapshotObjectTO newSnapshot = new SnapshotObjectTO(); if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING && !primaryPool.isExternalSnapshot()) { validateAvailableSizeOnPoolToTakeVolumeSnapshot(primaryPool, disk); @@ -1935,9 +1936,13 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { snapshotPath = getSnapshotPathInPrimaryStorage(primaryPool.getLocalPath(), snapshotName); String diskLabel = takeVolumeSnapshot(resource.getDisks(conn, vmName), snapshotName, diskPath, vm); - String convertResult = convertBaseFileToSnapshotFileInPrimaryStorageDir(primaryPool, disk, snapshotPath, volume, cmd.getWait()); + Pair fullSnapPathAndDirPath = getFullSnapshotOrCheckpointPathAndDirPathOnCorrectStorage(primaryPool, secondaryPool, snapshotName, volume, false); + + snapshotPath = fullSnapPathAndDirPath.first(); + String directoryPath = fullSnapPathAndDirPath.second(); + String convertResult = convertBaseFileToSnapshotFileInStorageDir(primaryPool, disk, snapshotPath, directoryPath, volume, cmd.getWait()); - mergeSnapshotIntoBaseFile(vm, diskLabel, diskPath, snapshotName, volume, conn); + resource.mergeSnapshotIntoBaseFile(vm, diskLabel, diskPath, null, true, snapshotName, volume, conn); validateConvertResult(convertResult, snapshotPath); } catch (LibvirtException e) { @@ -1997,7 +2002,6 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { } } - final SnapshotObjectTO newSnapshot = new SnapshotObjectTO(); newSnapshot.setPath(snapshotPath); if (snapshotSize != null) { newSnapshot.setPhysicalSize(snapshotSize); @@ -2652,6 +2656,10 @@ protected Pair getSnapshotOrCheckpointPathAndDirectoryPathInSeco return new Pair<>(fullSnapPath, snapshotParentDirectories); } + protected String getSnapshotPathInPrimaryStorage(String primaryStoragePath, String snapshotName) { + return String.format("%s%s%s%s%s", primaryStoragePath, File.separator, TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR, File.separator, snapshotName); + } + protected String getSnapshotPathInPrimaryStorageGFS(String primaryStoragePath, String snapshotName) { return String.format("%s%s%s", primaryStoragePath, File.separator, snapshotName); } diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java index 9146ce48ccb5..489eb82264ac 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java @@ -63,15 +63,12 @@ import com.cloud.agent.api.MigrateCommand.MigrateDiskInfo.DiskType; import com.cloud.agent.api.MigrateCommand.MigrateDiskInfo.DriverType; import com.cloud.agent.api.MigrateCommand.MigrateDiskInfo.Source; -import com.cloud.agent.api.VgpuTypesInfo; import com.cloud.agent.api.to.DpdkTO; -import com.cloud.agent.api.to.GPUDeviceTO; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; import com.cloud.hypervisor.kvm.resource.LibvirtConnection; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.cloudstack.gpu.GpuDevice; @RunWith(MockitoJUnitRunner.class) public class LibvirtMigrateCommandWrapperTest { diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java index 7bcd0bf18e6a..fb493e40773d 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java @@ -69,7 +69,6 @@ public void testExecuteWithVmExistsNull() throws Exception { PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); - when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); when(command.getVmState()).thenReturn(VirtualMachine.State.Running); when(command.getMountTimeout()).thenReturn(30); @@ -186,7 +185,6 @@ public void testExecuteWithCifsMountType() throws Exception { PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); - when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); when(command.getVmState()).thenReturn(VirtualMachine.State.Running); when(command.getMountTimeout()).thenReturn(30); @@ -227,7 +225,6 @@ public void testExecuteWithMountFailure() throws Exception { PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); lenient().when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); - lenient().when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); lenient().when(command.getVmState()).thenReturn(VirtualMachine.State.Running); lenient().when(command.getMountTimeout()).thenReturn(30); @@ -263,7 +260,6 @@ public void testExecuteWithBackupFileNotFound() throws Exception { PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); - when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); when(command.getVmState()).thenReturn(VirtualMachine.State.Running); when(command.getMountTimeout()).thenReturn(30); @@ -309,7 +305,6 @@ public void testExecuteWithCorruptBackupFile() throws Exception { PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); - when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); when(command.getVmState()).thenReturn(VirtualMachine.State.Running); when(command.getMountTimeout()).thenReturn(30); @@ -357,7 +352,6 @@ public void testExecuteWithRsyncFailure() throws Exception { PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); - when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); when(command.getVmState()).thenReturn(VirtualMachine.State.Running); when(command.getMountTimeout()).thenReturn(30); @@ -407,7 +401,6 @@ public void testExecuteWithAttachVolumeFailure() throws Exception { PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); - when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); when(command.getVmState()).thenReturn(VirtualMachine.State.Running); when(command.getMountTimeout()).thenReturn(30); @@ -461,7 +454,6 @@ public void testExecuteWithTempDirectoryCreationFailure() throws Exception { PrimaryDataStoreTO primaryDataStore = Mockito.mock(PrimaryDataStoreTO.class); when(command.getRestoreVolumePools()).thenReturn(Arrays.asList(primaryDataStore)); lenient().when(command.getRestoreVolumePaths()).thenReturn(Arrays.asList("/var/lib/libvirt/images/volume-123")); - lenient().when(command.getRestoreVolumeUUID()).thenReturn("volume-123"); lenient().when(command.getVmState()).thenReturn(VirtualMachine.State.Running); lenient().when(command.getMountTimeout()).thenReturn(30); diff --git a/plugins/integrations/desktop-service/src/main/java/org/apache/cloudstack/api/command/user/desktop/cluster/CreateDesktopClusterCmd.java b/plugins/integrations/desktop-service/src/main/java/org/apache/cloudstack/api/command/user/desktop/cluster/CreateDesktopClusterCmd.java index 7e99a8006810..d2d217e94f65 100644 --- a/plugins/integrations/desktop-service/src/main/java/org/apache/cloudstack/api/command/user/desktop/cluster/CreateDesktopClusterCmd.java +++ b/plugins/integrations/desktop-service/src/main/java/org/apache/cloudstack/api/command/user/desktop/cluster/CreateDesktopClusterCmd.java @@ -220,7 +220,7 @@ public static String getResultObjectName() { @Override public long getEntityOwnerId() { - Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true); + Long accountId = _accountService.finalizeAccountId(accountName, domainId, projectId, true); if (accountId == null) { return CallContext.current().getCallingAccount().getId(); } diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java index 467db89060bd..3417295abe76 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java @@ -381,7 +381,7 @@ private void validateKubernetesSupportedVersion(Long zoneId, String semanticVers } } } - + private void validateImageStoreForZone(Long zoneId, boolean directDownload) { if (directDownload) { return; diff --git a/plugins/metrics/src/main/java/org/apache/cloudstack/api/ListHostsMetricsCmd.java b/plugins/metrics/src/main/java/org/apache/cloudstack/api/ListHostsMetricsCmd.java index dfd95811ba62..87e74c7562fd 100644 --- a/plugins/metrics/src/main/java/org/apache/cloudstack/api/ListHostsMetricsCmd.java +++ b/plugins/metrics/src/main/java/org/apache/cloudstack/api/ListHostsMetricsCmd.java @@ -34,6 +34,10 @@ since = "4.9.3", authorized = {RoleType.Admin}) public class ListHostsMetricsCmd extends ListHostsCmd { + public ListHostsMetricsCmd() { + super(null); + } + @Inject private MetricsService metricsService; diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/motion/LinstorDataMotionStrategy.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/motion/LinstorDataMotionStrategy.java index cab2820f09ae..de18aa087552 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/motion/LinstorDataMotionStrategy.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/motion/LinstorDataMotionStrategy.java @@ -434,4 +434,9 @@ public void copyAsync(Map volumeDataStoreMap, VirtualMach callback.complete(result); } } + + @Override + public void cloneAsync(DataObject srcData, DataObject destData, Host destHost, AsyncCompletionCallback callback) { + return; + } } diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycle.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycle.java index 5917e7895ca4..25a148fc090d 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycle.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycle.java @@ -319,7 +319,7 @@ public boolean maintain(DataStore store) { } } - storagePoolAutomation.maintain(store, details); + storagePoolAutomation.maintain(store); dataStoreHelper.maintain(store); return true; } @@ -345,7 +345,7 @@ public boolean cancelMaintain(DataStore store) { } dataStoreHelper.cancelMaintain(store); - storagePoolAutomation.cancelMaintain(store, details); + storagePoolAutomation.cancelMaintain(store); return true; } diff --git a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java index 324f3c08cb8f..af60fe3461a9 100644 --- a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java +++ b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java @@ -22,7 +22,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; @@ -176,7 +175,7 @@ public void testAttachZone_UnsupportedHypervisor() throws Exception { @Test public void testMaintain() { final DataStore store = mock(DataStore.class); - when(storagePoolAutomation.maintain(any(DataStore.class), anyMap())).thenReturn(true); + when(storagePoolAutomation.maintain(any(DataStore.class))).thenReturn(true); when(dataStoreHelper.maintain(any(DataStore.class))).thenReturn(true); final boolean result = scaleIOPrimaryDataStoreLifeCycleTest.maintain(store); assertThat(result).isTrue(); @@ -186,7 +185,7 @@ public void testMaintain() { public void testCancelMaintain() { final DataStore store = mock(DataStore.class); when(dataStoreHelper.cancelMaintain(any(DataStore.class))).thenReturn(true); - when(storagePoolAutomation.cancelMaintain(any(DataStore.class), anyMap())).thenReturn(true); + when(storagePoolAutomation.cancelMaintain(any(DataStore.class))).thenReturn(true); final boolean result = scaleIOPrimaryDataStoreLifeCycleTest.cancelMaintain(store); assertThat(result).isTrue(); } diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index d206810c9477..a4393d4310c3 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -2498,7 +2498,7 @@ public Pair, Integer> searchForServerIdsAndCount(ListHostsCmd cmd) { hostSearchBuilder.or("storageAccessGroupMiddle", hostSearchBuilder.entity().getStorageAccessGroups(), Op.LIKE); hostSearchBuilder.cp(); } - + hostSearchBuilder.and("version", hostSearchBuilder.entity().getVersion(), SearchCriteria.Op.EQ); if (keyword != null) { @@ -2603,7 +2603,7 @@ public Pair, Integer> searchForServerIdsAndCount(ListHostsCmd cmd) { sc.setParameters("storageAccessGroupSuffix", "%," + storageAccessGroup); sc.setParameters("storageAccessGroupMiddle", "%," + storageAccessGroup + ",%"); } - + if (version != null) { sc.setParameters("version", version); } diff --git a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java index 3eda364b5c36..6bca7c36c575 100644 --- a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java @@ -1809,7 +1809,7 @@ private boolean deleteDataStoreInternal(StoragePoolVO sPool, boolean forced) { protected String getStoragePoolNonDestroyedVolumesLog(long storagePoolId) { StringBuilder sb = new StringBuilder(); - List nonDestroyedVols = volumeDao.findByPoolId(storagePoolId, null); + List nonDestroyedVols = volumeDao.findNonDestroyedVolumesByPoolId(storagePoolId); VMInstanceVO volInstance; List logMessageInfo = new ArrayList<>(); diff --git a/server/src/main/java/com/cloud/storage/StoragePoolAutomation.java b/server/src/main/java/com/cloud/storage/StoragePoolAutomation.java index ea5619182ccb..70aa00fee915 100644 --- a/server/src/main/java/com/cloud/storage/StoragePoolAutomation.java +++ b/server/src/main/java/com/cloud/storage/StoragePoolAutomation.java @@ -18,16 +18,16 @@ */ package com.cloud.storage; -import java.util.Map; +// import java.util.Map; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; public interface StoragePoolAutomation { boolean maintain(DataStore store); - boolean maintain(DataStore store, Map details); + // boolean maintain(DataStore store, Map details); boolean cancelMaintain(DataStore store); - boolean cancelMaintain(DataStore store, Map details); + // boolean cancelMaintain(DataStore store, Map details); } diff --git a/server/src/main/java/com/cloud/template/TemplateManagerImpl.java b/server/src/main/java/com/cloud/template/TemplateManagerImpl.java index ce8f9d8a8860..bc60e8935109 100755 --- a/server/src/main/java/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/main/java/com/cloud/template/TemplateManagerImpl.java @@ -2567,7 +2567,7 @@ protected void validateExternalHypervisorTemplateType(HypervisorType hypervisorT throw new InvalidParameterValueException(String.format("Only %s templates supported for %s hypervisor type", TemplateType.USER, HypervisorType.External)); } - + @Override public DataStore verifyHeuristicRulesForZone(VMTemplateVO template, Long zoneId) { HeuristicType heuristicType; diff --git a/server/src/main/java/com/cloud/user/AccountManagerImpl.java b/server/src/main/java/com/cloud/user/AccountManagerImpl.java index 638656e77141..01e326d92c5f 100644 --- a/server/src/main/java/com/cloud/user/AccountManagerImpl.java +++ b/server/src/main/java/com/cloud/user/AccountManagerImpl.java @@ -1526,7 +1526,7 @@ public UserAccount createUserAccount(final String userName, final String passwor // Check permissions checkAccess(getCurrentCallingAccount(), domain); - if (!userAllowMultipleAccounts.valueInDomain(domainId) && !userAccountDao.validateUsernameInDomain(userName, domainId)) { + if (!userAllowMultipleAccounts.valueInScope(ConfigKey.Scope.Domain, domainId) && !userAccountDao.validateUsernameInDomain(userName, domainId)) { throw new InvalidParameterValueException(String.format("The user %s already exists in domain %s", userName, domain)); } @@ -1933,7 +1933,7 @@ public UserVO createUser(String userName, String password, String firstName, Str throw new PermissionDeniedException(String.format("Account: %s is a system account, can't add a user to it", account)); } - if (!userAllowMultipleAccounts.valueInDomain(domainId) && !userAccountDao.validateUsernameInDomain(userName, domainId)) { + if (!userAllowMultipleAccounts.valueInScope(ConfigKey.Scope.Domain, domainId) && !userAccountDao.validateUsernameInDomain(userName, domainId)) { throw new CloudRuntimeException("The user " + userName + " already exists in domain " + domainId); } List duplicatedUsers = _userDao.findUsersByName(userName); @@ -4261,11 +4261,11 @@ protected synchronized void runInContext() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { UserAccountVO user = null; - user = _userAccountDao.lockRow(_user.getId(), true); + user = userAccountDao.lockRow(_user.getId(), true); if (user.getState().equals(State.DISABLED.toString())) { user.setLoginAttempts(0); user.setState(State.ENABLED.toString()); - _userAccountDao.update(_user.getId(), user); + userAccountDao.update(_user.getId(), user); ActionEventUtils.onActionEvent(user.getId(), user.getAccountId(), user.getDomainId(), EventTypes.EVENT_USER_ENABLE, "Activated automatically after 5 minutes of inactivation. UserId : " + user.getId(), user.getId(), ApiCommandResourceType.User.toString()); } } diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 19d124e1d225..690c8db64f80 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -10980,4 +10980,8 @@ private VolumeVO cloneVolumeFromSnapToDB(final Account owner, final Boolean disp return volume; }); } + + public static ConfigKey getEnableAdditionalVmConfig() { + return EnableAdditionalVmConfig; + } } diff --git a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java index 1c4962513700..dc79c766072b 100644 --- a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java @@ -122,6 +122,7 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.VirtualMachineProfile; +import com.cloud.vm.VmDetailConstants; import com.cloud.vm.VmWork; import com.cloud.vm.VmWorkConstants; import com.cloud.vm.VmWorkJobHandler; @@ -504,16 +505,10 @@ public VMSnapshot doInTransaction(TransactionStatus status) { * @param vmSnapshotId vm snapshot id */ protected void addSupportForCustomServiceOffering(long vmId, long serviceOfferingId, long vmSnapshotId) { - ServiceOfferingVO serviceOfferingVO = _serviceOfferingDao.findById(serviceOfferingId); - if (serviceOfferingVO.isDynamic()) { - List vmDetails = _userVmDetailsDao.listDetails(vmId); - List vmSnapshotDetails = new ArrayList(); - for (UserVmDetailVO detail : vmDetails) { - if (VM_SNAPSHOT_CUSTOM_SERVICE_OFFERING_DETAILS.contains(detail.getName().toLowerCase())) { - vmSnapshotDetails.add(new VMSnapshotDetailsVO(vmSnapshotId, detail.getName(), detail.getValue(), detail.isDisplay())); - } - } - _vmSnapshotDetailsDao.saveDetails(vmSnapshotDetails); + List vmDetails = _vmInstanceDetailsDao.listDetails(vmId); + List vmSnapshotDetails = new ArrayList(); + for (VMInstanceDetailVO detail : vmDetails) { + vmSnapshotDetails.add(new VMSnapshotDetailsVO(vmSnapshotId, detail.getName(), detail.getValue(), detail.isDisplay())); } _vmSnapshotDetailsDao.saveDetails(vmSnapshotDetails); @@ -995,7 +990,7 @@ protected void revertCustomServiceOfferingDetailsFromVmSnapshot(UserVmVO userVm, List userVmDetails = new ArrayList(); for (VMSnapshotDetailsVO detail : vmSnapshotDetails) { if (VM_SNAPSHOT_CUSTOM_SERVICE_OFFERING_DETAILS.contains(detail.getName().toLowerCase())) { - _userVmDetailsDao.addDetail(userVm.getId(), detail.getName(), detail.getValue(), detail.isDisplay()); + _vmInstanceDetailsDao.addDetail(userVm.getId(), detail.getName(), detail.getValue(), detail.isDisplay()); } } _vmInstanceDetailsDao.saveDetails(userVmDetails); diff --git a/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java b/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java index 513228de33cf..bc25f083e1b5 100644 --- a/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java +++ b/server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java @@ -1598,7 +1598,7 @@ public boolean restoreBackupVolumeAndAttachToVM(final String backedUpVolumeUuid, throw new CloudRuntimeException(String.format("Error restoring volume [%s] of VM [%s] to host [%s] using backup provider [%s] due to: [%s].", backedUpVolumeUuid, vm.getUuid(), host.getUuid(), backupProvider.getName(), result.second())); } - if (!attachVolumeToVM(vm.getDataCenterId(), result.second(), backup.getBackedUpVolumes(), + if (!attachVolumeToVM(vm.getDataCenterId(), result.second(), backupVolumeInfo, backedUpVolumeUuid, vm, datastore.getUuid(), backup)) { throw new CloudRuntimeException(String.format("Error attaching volume [%s] to VM [%s].", backedUpVolumeUuid, vm.getUuid())); } diff --git a/server/src/main/java/org/apache/cloudstack/storage/heuristics/HeuristicRuleHelper.java b/server/src/main/java/org/apache/cloudstack/storage/heuristics/HeuristicRuleHelper.java index 0b4c60ad6e4f..beecf90d2b83 100644 --- a/server/src/main/java/org/apache/cloudstack/storage/heuristics/HeuristicRuleHelper.java +++ b/server/src/main/java/org/apache/cloudstack/storage/heuristics/HeuristicRuleHelper.java @@ -195,7 +195,7 @@ protected Volume setVolumePresetVariable(com.cloud.storage.Volume volumeVO) { Volume volumePresetVariable = new Volume(); volumePresetVariable.setName(volumeVO.getName()); - volumePresetVariable.setFormat(volumeVO.getFormat()); + volumePresetVariable.setFormat(volumeVO.getFormat().toString()); volumePresetVariable.setSize(volumeVO.getSize()); return volumePresetVariable; diff --git a/server/src/test/java/com/cloud/api/ApiServletTest.java b/server/src/test/java/com/cloud/api/ApiServletTest.java index e43a50165d13..c5ee9f58154d 100644 --- a/server/src/test/java/com/cloud/api/ApiServletTest.java +++ b/server/src/test/java/com/cloud/api/ApiServletTest.java @@ -17,32 +17,6 @@ package com.cloud.api; import static org.mockito.ArgumentMatchers.nullable; -import com.cloud.api.auth.ListUserTwoFactorAuthenticatorProvidersCmd; -import com.cloud.api.auth.SetupUserTwoFactorAuthenticationCmd; -import com.cloud.api.auth.ValidateUserTwoFactorAuthenticationCodeCmd; -import com.cloud.server.ManagementServer; -import com.cloud.user.Account; -import com.cloud.user.AccountManagerImpl; -import com.cloud.user.AccountService; -import com.cloud.user.User; -import com.cloud.user.UserAccount; -import com.cloud.utils.HttpUtils; -import com.cloud.vm.UserVmManager; -import org.apache.cloudstack.api.ApiConstants; -import org.apache.cloudstack.api.auth.APIAuthenticationManager; -import org.apache.cloudstack.api.auth.APIAuthenticationType; -import org.apache.cloudstack.api.auth.APIAuthenticator; -import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd; -import org.apache.cloudstack.framework.config.ConfigKey; -import org.apache.cloudstack.framework.config.impl.ConfigDepotImpl; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; import java.io.PrintWriter; diff --git a/server/src/test/java/com/cloud/template/TemplateManagerImplTest.java b/server/src/test/java/com/cloud/template/TemplateManagerImplTest.java index d1f133ef6788..d0facb88ba86 100755 --- a/server/src/test/java/com/cloud/template/TemplateManagerImplTest.java +++ b/server/src/test/java/com/cloud/template/TemplateManagerImplTest.java @@ -210,7 +210,7 @@ public class TemplateManagerImplTest { @Inject SnapshotJoinDao snapshotJoinDao; - + @Inject TemplateDeployAsIsDetailsDao templateDeployAsIsDetailsDao; diff --git a/server/src/test/java/com/cloud/user/AccountManagerImplTest.java b/server/src/test/java/com/cloud/user/AccountManagerImplTest.java index 4e541f1e3b38..bb4d9057ce44 100644 --- a/server/src/test/java/com/cloud/user/AccountManagerImplTest.java +++ b/server/src/test/java/com/cloud/user/AccountManagerImplTest.java @@ -16,6 +16,7 @@ // under the License. package com.cloud.user; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; import java.net.InetAddress; @@ -54,7 +55,6 @@ import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -1450,7 +1450,7 @@ public void testClearUser2FA_When2FAInSetupState_Disable2FA() { UserAccountVO userAccountVO = new UserAccountVO(); userAccountVO.setId(1L); Mockito.when(userDetailsDaoMock.findDetail(1L, UserDetailVO.Setup2FADetail)).thenReturn(userDetail); - Mockito.when(userAccountDao.findById(any())).thenReturn(userAccountVO); + Mockito.when(userAccountDao.findById(1L)).thenReturn(userAccountVO); UserAccount result = accountManagerImpl.clearUserTwoFactorAuthenticationInSetupStateOnLogin(user); Assert.assertNotNull(result); Assert.assertFalse(result.isUser2faEnabled()); diff --git a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java index badd1822759f..c3d5ed73941f 100644 --- a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java +++ b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java @@ -122,7 +122,6 @@ import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlanner; import com.cloud.deploy.DeploymentPlanningManager; -import com.cloud.domain.Domain; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.event.ActionEventUtils; @@ -177,7 +176,6 @@ import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.GuestOSDao; import com.cloud.storage.dao.SnapshotDao; -import com.cloud.storage.dao.SnapshotPolicyDao; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.template.VirtualMachineTemplate; @@ -3911,7 +3909,7 @@ public void createVirtualMachineWithExistingVolume() throws ResourceUnavailableE when(templateMock.isDeployAsIs()).thenReturn(false); when(templateMock.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); when(templateMock.getUserDataId()).thenReturn(null); - Mockito.doNothing().when(vnfTemplateManager).validateVnfApplianceNics(any(), nullable(List.class)); + Mockito.doNothing().when(vnfTemplateManager).validateVnfApplianceNics(any(), nullable(List.class), nullable(Map.class)); when(_dcMock.isLocalStorageEnabled()).thenReturn(false); when(_dcMock.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic); Mockito.doReturn(userVmVoMock).when(userVmManagerImpl).createBasicSecurityGroupVirtualMachine(any(), any(), any(), any(), any(), any(), any(), @@ -3949,7 +3947,7 @@ public void createVirtualMachineWithExistingSnapshot() throws ResourceUnavailabl when(templateMock.isDeployAsIs()).thenReturn(false); when(templateMock.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); when(templateMock.getUserDataId()).thenReturn(null); - Mockito.doNothing().when(vnfTemplateManager).validateVnfApplianceNics(any(), nullable(List.class)); + Mockito.doNothing().when(vnfTemplateManager).validateVnfApplianceNics(any(), nullable(List.class), nullable(Map.class)); when(_dcMock.isLocalStorageEnabled()).thenReturn(false); when(_dcMock.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic); Mockito.doReturn(userVmVoMock).when(userVmManagerImpl).createBasicSecurityGroupVirtualMachine(any(), any(), any(), any(), any(), any(), any(), @@ -4228,7 +4226,7 @@ public void updateVmExtraConfigAddsConfigWhenValidAndEnabled() { when(userVm.getAccountId()).thenReturn(1L); when(userVm.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM); doNothing().when(userVmManagerImpl).persistExtraConfigKvm(anyString(), eq(userVm)); - updateDefaultConfigValue(UserVmManagerImpl.EnableAdditionalVmConfig, true, false); + updateDefaultConfigValue(UserVmManagerImpl.getEnableAdditionalVmConfig(), true, false); userVmManagerImpl.updateVmExtraConfig(userVm, "validConfig", false); @@ -4240,7 +4238,7 @@ public void updateVmExtraConfigAddsConfigWhenValidAndEnabled() { public void updateVmExtraConfigThrowsExceptionWhenConfigDisabled() { UserVmVO userVm = mock(UserVmVO.class); when(userVm.getAccountId()).thenReturn(1L); - updateDefaultConfigValue(UserVmManagerImpl.EnableAdditionalVmConfig, false, false); + updateDefaultConfigValue(UserVmManagerImpl.getEnableAdditionalVmConfig(), false, false); userVmManagerImpl.updateVmExtraConfig(userVm, "validConfig", false); } diff --git a/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java b/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java index 99b8b829ff1a..aa3cba61f62c 100644 --- a/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java +++ b/server/src/test/java/com/cloud/vm/snapshot/VMSnapshotManagerTest.java @@ -431,9 +431,9 @@ public void testRevertUserVmDetailsFromVmSnapshotDynamicServiceOffering() { _vmSnapshotMgr.revertCustomServiceOfferingDetailsFromVmSnapshot(vmMock, vmSnapshotVO); verify(_vmSnapshotDetailsDao).listDetails(VM_SNAPSHOT_ID); - verify(_userVmDetailsDao, never()).saveDetails(any()); + verify(_vmInstanceDetailsDao, never()).saveDetails(any()); ArgumentCaptor detailNameCaptor = ArgumentCaptor.forClass(String.class); - verify(_userVmDetailsDao, times(2)).addDetail(eq(TEST_VM_ID), detailNameCaptor.capture(), anyString(), anyBoolean()); + verify(_vmInstanceDetailsDao, times(2)).addDetail(eq(TEST_VM_ID), detailNameCaptor.capture(), anyString(), anyBoolean()); List appliedNames = detailNameCaptor.getAllValues(); assertTrue(appliedNames.contains(VmDetailConstants.CPU_NUMBER)); assertTrue(appliedNames.contains(VmDetailConstants.MEMORY)); diff --git a/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/UploadManagerImpl.java b/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/UploadManagerImpl.java index 7b71bf432462..4094f0fa8b1b 100644 --- a/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/UploadManagerImpl.java +++ b/services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/UploadManagerImpl.java @@ -40,7 +40,6 @@ import org.apache.cloudstack.storage.resource.SecondaryStorageResource; import org.apache.commons.lang3.StringUtils; -import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.CreateEntityDownloadURLAnswer; import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand; import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand; diff --git a/ui/src/components/page/GlobalLayout.vue b/ui/src/components/page/GlobalLayout.vue index 6817c13ee1eb..b256890ad4ad 100644 --- a/ui/src/components/page/GlobalLayout.vue +++ b/ui/src/components/page/GlobalLayout.vue @@ -1,15 +1,19 @@