Skip to content

Commit 32a2f2d

Browse files
author
Dingane Hlaluku
committed
Publish volume resize event for volumes in Allocated or Ready state
Move the method that published events for volumes in Ready state from the VolumeStateListener class to the orchestrateResizeVolume method in the VolumeApiService
1 parent 5aae410 commit 32a2f2d

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

engine/schema/src/com/cloud/event/UsageEventVO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public enum DynamicParameters {
7070
private String resourceType;
7171

7272
@Column(name = "processed")
73-
boolean processed;
73+
private boolean processed;
7474

7575
@Column(name = "virtual_size")
7676
private Long virtualSize;

server/src/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,8 @@ public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationExcept
719719

720720
String userSpecifiedName = getVolumeNameFromCommand(cmd);
721721

722-
VolumeVO volume = commitVolume(cmd, caller, owner, displayVolume, zoneId, diskOfferingId, provisioningType, size, minIops, maxIops, parentVolume, userSpecifiedName,
722+
return commitVolume(cmd, caller, owner, displayVolume, zoneId, diskOfferingId, provisioningType, size, minIops, maxIops, parentVolume, userSpecifiedName,
723723
_uuidMgr.generateUuid(Volume.class, cmd.getCustomId()));
724-
725-
return volume;
726724
}
727725

728726
private VolumeVO commitVolume(final CreateVolumeCmd cmd, final Account caller, final Account owner, final Boolean displayVolume, final Long zoneId, final Long diskOfferingId,
@@ -1044,6 +1042,7 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
10441042
// the requested change
10451043

10461044
/* If this volume has never been beyond allocated state, short circuit everything and simply update the database. */
1045+
// We need to publish this event to usage_volume table
10471046
if (volume.getState() == Volume.State.Allocated) {
10481047
s_logger.debug("Volume is in the allocated state, but has never been created. Simply updating database with new size and IOPS.");
10491048

@@ -1057,7 +1056,8 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
10571056
}
10581057

10591058
_volsDao.update(volume.getId(), volume);
1060-
1059+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_RESIZE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
1060+
volume.getDiskOfferingId(), volume.getTemplateId(), volume.getSize(), Volume.class.getName(), volume.getUuid());
10611061
return volume;
10621062
}
10631063

@@ -1134,7 +1134,7 @@ private void validateIops(Long minIops, Long maxIops) {
11341134

11351135
private VolumeVO orchestrateResizeVolume(long volumeId, long currentSize, long newSize, Long newMinIops, Long newMaxIops, Integer newHypervisorSnapshotReserve, Long newDiskOfferingId,
11361136
boolean shrinkOk) {
1137-
VolumeVO volume = _volsDao.findById(volumeId);
1137+
final VolumeVO volume = _volsDao.findById(volumeId);
11381138
UserVmVO userVm = _userVmDao.findById(volume.getInstanceId());
11391139
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
11401140
boolean isManaged = storagePool.isManaged();
@@ -1209,14 +1209,8 @@ private VolumeVO orchestrateResizeVolume(long volumeId, long currentSize, long n
12091209
volService.resizeVolumeOnHypervisor(volumeId, newSize, hosts[0], instanceName);
12101210
}
12111211
}
1212-
1213-
volume.setSize(newSize);
1214-
1215-
_volsDao.update(volume.getId(), volume);
12161212
}
12171213

1218-
volume = _volsDao.findById(volume.getId());
1219-
12201214
if (newDiskOfferingId != null) {
12211215
volume.setDiskOfferingId(newDiskOfferingId);
12221216
}
@@ -1229,20 +1223,18 @@ private VolumeVO orchestrateResizeVolume(long volumeId, long currentSize, long n
12291223

12301224
/* Update resource count for the account on primary storage resource */
12311225
if (!shrinkOk) {
1232-
_resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplayVolume(), new Long(newSize - currentSize));
1226+
_resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplayVolume(), newSize - currentSize);
12331227
} else {
1234-
_resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplayVolume(), new Long(currentSize - newSize));
1228+
_resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplayVolume(), currentSize - newSize);
12351229
}
1230+
1231+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_RESIZE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
1232+
volume.getDiskOfferingId(), volume.getTemplateId(), volume.getSize(), Volume.class.getName(), volume.getUuid());
1233+
12361234
return volume;
1237-
} catch (InterruptedException e) {
1238-
s_logger.warn("failed get resize volume result", e);
1239-
throw new CloudRuntimeException(e.getMessage());
1240-
} catch (ExecutionException e) {
1241-
s_logger.warn("failed get resize volume result", e);
1242-
throw new CloudRuntimeException(e.getMessage());
1235+
12431236
} catch (Exception e) {
1244-
s_logger.warn("failed get resize volume result", e);
1245-
throw new CloudRuntimeException(e.getMessage());
1237+
throw new CloudRuntimeException("Exception caught during resize volume operation of volume UUID: " + volume.getUuid(), e);
12461238
}
12471239
}
12481240

server/src/com/cloud/storage/listener/VolumeStateListener.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> t
7676
if (transition.getToState() == State.Ready) {
7777
if (transition.getCurrentState() == State.Resizing) {
7878
// Log usage event for volumes belonging user VM's only
79-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_RESIZE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(),
80-
vol.getDiskOfferingId(), vol.getTemplateId(), vol.getSize(), Volume.class.getName(), vol.getUuid());
79+
// For the Resize Volume Event, this publishes an event with an incorrect disk offering ID, so do nothing for now
8180
} else {
8281
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), vol.getDiskOfferingId(), null, vol.getSize(),
8382
Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());

usage/src/com/cloud/usage/parser/VolumeUsageParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ private static void createUsageRecord(int type, long runningTime, Date startDate
166166
usageDesc += " (DiskOffering: " + doId + ")";
167167
}
168168

169-
UsageVO usageRecord =
170-
new UsageVO(zoneId, account.getId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs", type, new Double(usage), null, null, doId, templateId, volId,
169+
UsageVO usageRecord = new UsageVO(zoneId, account.getId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs", type, new Double(usage), null, null, doId, templateId, volId,
171170
size, startDate, endDate);
172171
s_usageDao.persist(usageRecord);
173172
}

0 commit comments

Comments
 (0)