@@ -819,7 +819,7 @@ protected DiskProfile toDiskProfile(Volume vol, DiskOffering offering) {
819819 vol .getTemplateId ());
820820 }
821821
822- @ ActionEvent (eventType = EventTypes .EVENT_VOLUME_CREATE , eventDescription = "creating ROOT volume" , create = true )
822+ @ ActionEvent (eventType = EventTypes .EVENT_VOLUME_CREATE , eventDescription = "creating volume" , create = true )
823823 @ Override
824824 public DiskProfile allocateRawVolume (Type type , String name , DiskOffering offering , Long size , Long minIops , Long maxIops , VirtualMachine vm , VirtualMachineTemplate template , Account owner ,
825825 Long deviceId ) {
@@ -1035,13 +1035,13 @@ public List<DiskProfile> allocateTemplatedVolumes(Type type, String name, DiskOf
10351035 private void updateRootDiskVolumeEventDetails (Type type , VirtualMachine vm , List <DiskProfile > diskProfiles ) {
10361036 CallContext callContext = CallContext .current ();
10371037 // Update only for volume type ROOT and API command resource type Volume
1038- if (type == Type .ROOT && callContext != null && callContext .getEventResourceType () == ApiCommandResourceType .Volume ) {
1038+ if (( type == Type .ROOT || type == Type . DATADISK ) && callContext != null && callContext .getEventResourceType () == ApiCommandResourceType .Volume ) {
10391039 List <Long > volumeIds = diskProfiles .stream ().map (DiskProfile ::getVolumeId ).filter (volumeId -> volumeId != null ).collect (Collectors .toList ());
10401040 if (!volumeIds .isEmpty ()) {
10411041 callContext .setEventResourceId (volumeIds .get (0 ));
10421042 }
10431043 String volumeUuids = volumeIds .stream ().map (volumeId -> this ._uuidMgr .getUuid (Volume .class , volumeId )).collect (Collectors .joining (", " ));
1044- callContext .setEventDetails ("Volume Id: " + volumeUuids + " Vm Id: " + this ._uuidMgr .getUuid (VirtualMachine .class , vm .getId ()));
1044+ callContext .setEventDetails ("Volume Type: " + type + "Volume Id: " + volumeUuids + " Vm Id: " + this ._uuidMgr .getUuid (VirtualMachine .class , vm .getId ()));
10451045 }
10461046 }
10471047
@@ -1245,7 +1245,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
12451245 // Destroy volume if not already destroyed
12461246 boolean volumeAlreadyDestroyed = (vol .getState () == Volume .State .Destroy || vol .getState () == Volume .State .Expunged || vol .getState () == Volume .State .Expunging );
12471247 if (!volumeAlreadyDestroyed ) {
1248- volService . destroyVolume (vol . getId () );
1248+ destroyVolumeInContext (vol );
12491249 } else {
12501250 s_logger .debug (String .format ("Skipping destroy for the volume [%s] as it is in [%s] state." , volumeToString , vol .getState ().toString ()));
12511251 }
@@ -1277,6 +1277,21 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
12771277 }
12781278 }
12791279
1280+ private void destroyVolumeInContext (Volume volume ) {
1281+ // Create new context and inject correct event resource type, id and details,
1282+ // otherwise VOLUME.DESTROY event will be associated with VirtualMachine and contain VM id and other information.
1283+ CallContext volumeContext = CallContext .register (CallContext .current (), ApiCommandResourceType .Volume );
1284+ volumeContext .setEventDetails ("Volume Type: " + volume .getVolumeType () + " Volume Id: " + volume .getUuid () + " Vm Id: " + _uuidMgr .getUuid (VirtualMachine .class , volume .getInstanceId ()));
1285+ volumeContext .setEventResourceType (ApiCommandResourceType .Volume );
1286+ volumeContext .setEventResourceId (volume .getId ());
1287+ try {
1288+ _volumeApiService .destroyVolume (volume .getId ());
1289+ } finally {
1290+ // Remove volumeContext and pop vmContext back
1291+ CallContext .unregister ();
1292+ }
1293+ }
1294+
12801295 @ Override
12811296 public void revokeAccess (DataObject dataObject , Host host , DataStore dataStore ) {
12821297 DataStoreDriver dataStoreDriver = dataStore != null ? dataStore .getDriver () : null ;
@@ -2080,7 +2095,7 @@ public void destroyVolume(Volume volume) {
20802095 _resourceLimitMgr .decrementResourceCount (volume .getAccountId (), ResourceType .volume , volume .isDisplay ());
20812096 _resourceLimitMgr .decrementResourceCount (volume .getAccountId (), ResourceType .primary_storage , volume .isDisplay (), new Long (volume .getSize ()));
20822097 } else {
2083- volService . destroyVolume (volume . getId () );
2098+ destroyVolumeInContext (volume );
20842099 }
20852100 // FIXME - All this is boiler plate code and should be done as part of state transition. This shouldn't be part of orchestrator.
20862101 // publish usage event for the volume
0 commit comments