Skip to content

Commit bfdb914

Browse files
authored
usage: publish zone id while uploading template and volume (apache#3867)
After a local template is uploaded via browser, the generated usage event with type = "TEMPLATE.CREATE" is persisted with the data store ID instead of the zone ID on the zone_id column. The fix will refactor the upload monitor logic, as after the upload completes, it sets the datastore ID on the zone ID column for the created "TEMPLATE.CREATE" usage event. This refactor will query the DB for the data store and will set its associated zone ID in the usage field. The fix produces the same behaviour as when registering a template from URL. FIx is also for uploading VOLUME from local/via browser.
1 parent c22e99c commit bfdb914

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

server/src/main/java/com/cloud/storage/ImageStoreUploadMonitorImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
import com.cloud.agent.api.Command;
5656
import com.cloud.agent.api.StartupCommand;
5757
import com.cloud.alert.AlertManager;
58+
import com.cloud.api.query.dao.TemplateJoinDao;
59+
import com.cloud.api.query.vo.TemplateJoinVO;
5860
import com.cloud.configuration.Resource;
5961
import com.cloud.event.EventTypes;
6062
import com.cloud.event.UsageEventUtils;
@@ -111,6 +113,8 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageSto
111113
private TemplateDataFactory templateFactory;
112114
@Inject
113115
private TemplateService templateService;
116+
@Inject
117+
private TemplateJoinDao templateJoinDao;
114118

115119
private long _nodeId;
116120
private ScheduledExecutorService _executor = null;
@@ -322,7 +326,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
322326

323327
// publish usage events
324328
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_UPLOAD, tmpVolume.getAccountId(),
325-
tmpVolumeDataStore.getDataStoreId(), tmpVolume.getId(), tmpVolume.getName(),
329+
tmpVolume.getDataCenterId(), tmpVolume.getId(), tmpVolume.getName(),
326330
null, null, tmpVolumeDataStore.getPhysicalSize(), tmpVolumeDataStore.getSize(),
327331
Volume.class.getName(), tmpVolume.getUuid());
328332

@@ -425,7 +429,9 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
425429
if (tmpTemplate.getFormat() == Storage.ImageFormat.ISO) {
426430
etype = EventTypes.EVENT_ISO_CREATE;
427431
}
428-
UsageEventUtils.publishUsageEvent(etype, tmpTemplate.getAccountId(), tmpTemplateDataStore.getDataStoreId(), tmpTemplate.getId(), tmpTemplate.getName(), null, null,
432+
TemplateJoinVO vo = templateJoinDao.findById(tmpTemplate.getId());
433+
assert (vo != null) : "Couldn't find the template view for given template ID";
434+
UsageEventUtils.publishUsageEvent(etype, tmpTemplate.getAccountId(), vo.getDataCenterId(), tmpTemplate.getId(), tmpTemplate.getName(), null, null,
429435
tmpTemplateDataStore.getPhysicalSize(), tmpTemplateDataStore.getSize(), VirtualMachineTemplate.class.getName(), tmpTemplate.getUuid());
430436

431437
if (s_logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)