Skip to content

Commit 025ae71

Browse files
committed
Schema change and UT fix
1 parent 3ba0d96 commit 025ae71

File tree

6 files changed

+15
-97
lines changed

6 files changed

+15
-97
lines changed

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41930to41940.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

engine/schema/src/main/java/com/cloud/usage/dao/UsageVolumeDaoImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import javax.annotation.PostConstruct;
2828

29-
import org.apache.log4j.Logger;
3029
import org.springframework.stereotype.Component;
3130

3231
import com.cloud.usage.UsageVolumeVO;

engine/schema/src/main/resources/META-INF/db/schema-41930to41940.sql

Lines changed: 0 additions & 27 deletions
This file was deleted.

engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@
2121

2222
-- Increase length of scripts_version column to 128 due to md5sum to sha512sum change
2323
CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('cloud.domain_router', 'scripts_version', 'scripts_version', 'VARCHAR(128)');
24+
25+
-- Add vm_id column to usage_event table for volume usage events
26+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.usage_event','vm_id', 'bigint UNSIGNED NULL COMMENT "VM ID associated with volume usage events"');
27+
CALL `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.usage_event','vm_id', 'bigint UNSIGNED NULL COMMENT "VM ID associated with volume usage events"');
28+
29+
-- Add vm_id column to cloud_usage.usage_volume table
30+
CALL `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.usage_volume','vm_id', 'bigint UNSIGNED NULL COMMENT "VM ID associated with the volume usage"');

server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ public class UserVmManagerImplTest {
449449
private DiskOfferingVO largerDisdkOffering = prepareDiskOffering(10l * GiB_TO_BYTES, 2l, 10L, 20L);
450450
Class<InvalidParameterValueException> expectedInvalidParameterValueException = InvalidParameterValueException.class;
451451
Class<CloudRuntimeException> expectedCloudRuntimeException = CloudRuntimeException.class;
452-
private MockedStatic<UsageEventUtils> usageEventUtilsMocked;
453452

454453
@Before
455454
public void beforeTest() {
@@ -473,13 +472,11 @@ public void beforeTest() {
473472
lenient().doNothing().when(resourceLimitMgr).decrementResourceCount(anyLong(), any(Resource.ResourceType.class), anyLong());
474473

475474
Mockito.when(virtualMachineProfile.getId()).thenReturn(vmId);
476-
usageEventUtilsMocked = Mockito.mockStatic(UsageEventUtils.class);
477475
}
478476

479477
@After
480478
public void afterTest() {
481479
CallContext.unregister();
482-
usageEventUtilsMocked.close();
483480
}
484481

485482
@Test
@@ -1105,10 +1102,12 @@ public void testResetVMUserDataSuccessResetWithUserdataId() {
11051102
public void recoverRootVolumeTestDestroyState() {
11061103
Mockito.doReturn(Volume.State.Destroy).when(volumeVOMock).getState();
11071104

1108-
userVmManagerImpl.recoverRootVolume(volumeVOMock, vmId);
1105+
try (MockedStatic<UsageEventUtils> ignored = Mockito.mockStatic(UsageEventUtils.class)) {
1106+
userVmManagerImpl.recoverRootVolume(volumeVOMock, vmId);
11091107

1110-
Mockito.verify(volumeApiService).recoverVolume(volumeVOMock.getId());
1111-
Mockito.verify(volumeDaoMock).attachVolume(volumeVOMock.getId(), vmId, UserVmManagerImpl.ROOT_DEVICE_ID);
1108+
Mockito.verify(volumeApiService).recoverVolume(volumeVOMock.getId());
1109+
Mockito.verify(volumeDaoMock).attachVolume(volumeVOMock.getId(), vmId, UserVmManagerImpl.ROOT_DEVICE_ID);
1110+
}
11121111
}
11131112

11141113
@Test(expected = InvalidParameterValueException.class)

usage/src/main/java/com/cloud/usage/UsageManagerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ private void createIPHelperEvent(UsageEventVO event) {
14321432
private void deleteExistingSecondaryStorageUsageForVolume(long volId, long accountId, Date deletedDate) {
14331433
List<UsageStorageVO> storageVOs = _usageStorageDao.listById(accountId, volId, StorageTypes.VOLUME);
14341434
for (UsageStorageVO storageVO : storageVOs) {
1435-
s_logger.debug(String.format("Setting the volume with id: {} to 'deleted' in the usage_storage table for account: {}.", volId, accountId));
1435+
logger.debug(String.format("Setting the volume with id: {} to 'deleted' in the usage_storage table for account: {}.", volId, accountId));
14361436
storageVO.setDeleted(deletedDate);
14371437
_usageStorageDao.update(storageVO);
14381438
}
@@ -1442,7 +1442,7 @@ private void deleteExistingInstanceVolumeUsage(long volId, long accountId, Date
14421442
List<UsageVolumeVO> volumesVOs = _usageVolumeDao.listByVolumeId(volId, accountId);
14431443
for (UsageVolumeVO volumesVO : volumesVOs) {
14441444
if (volumesVO.getVmId() != null) {
1445-
s_logger.debug(String.format("Setting the volume with id: {} for instance id: {} to 'deleted' in the usage_volume table for account {}.",
1445+
logger.debug(String.format("Setting the volume with id: {} for instance id: {} to 'deleted' in the usage_volume table for account {}.",
14461446
volumesVO.getVolumeId(), volumesVO.getVmId(), accountId));
14471447
volumesVO.setDeleted(deletedDate);
14481448
_usageVolumeDao.update(volumesVO.getId(), volumesVO);
@@ -1453,7 +1453,7 @@ private void deleteExistingInstanceVolumeUsage(long volId, long accountId, Date
14531453
private void deleteExistingVolumeUsage(long volId, long accountId, Date deletedDate) {
14541454
List<UsageVolumeVO> volumesVOs = _usageVolumeDao.listByVolumeId(volId, accountId);
14551455
for (UsageVolumeVO volumesVO : volumesVOs) {
1456-
s_logger.debug(String.format("Setting the volume with id: {} to 'deleted' in the usage_storage table for account: {}.", volId, accountId));
1456+
logger.debug(String.format("Setting the volume with id: {} to 'deleted' in the usage_storage table for account: {}.", volId, accountId));
14571457
volumesVO.setDeleted(deletedDate);
14581458
_usageVolumeDao.update(volumesVO.getId(), volumesVO);
14591459
}

0 commit comments

Comments
 (0)