|
37 | 37 | import javax.inject.Inject; |
38 | 38 | import javax.naming.ConfigurationException; |
39 | 39 |
|
| 40 | +import com.cloud.event.ActionEvent; |
40 | 41 | import com.cloud.storage.StorageUtil; |
| 42 | + |
| 43 | +import org.apache.cloudstack.api.ApiCommandResourceType; |
| 44 | +import org.apache.cloudstack.context.CallContext; |
41 | 45 | import org.apache.cloudstack.secret.dao.PassphraseDao; |
42 | 46 | import org.apache.cloudstack.secret.PassphraseVO; |
43 | 47 | import org.apache.cloudstack.api.command.admin.vm.MigrateVMCmd; |
|
135 | 139 | import com.cloud.utils.component.ManagerBase; |
136 | 140 | import com.cloud.utils.db.DB; |
137 | 141 | import com.cloud.utils.db.EntityManager; |
| 142 | +import com.cloud.utils.db.UUIDManager; |
138 | 143 | import com.cloud.utils.db.Transaction; |
139 | 144 | import com.cloud.utils.db.TransactionCallback; |
140 | 145 | import com.cloud.utils.db.TransactionCallbackNoReturn; |
@@ -176,6 +181,8 @@ public enum UserVmCloneType { |
176 | 181 | @Inject |
177 | 182 | EntityManager _entityMgr; |
178 | 183 | @Inject |
| 184 | + private UUIDManager _uuidMgr; |
| 185 | + @Inject |
179 | 186 | protected TemplateManager _tmpltMgr; |
180 | 187 | @Inject |
181 | 188 | protected VolumeDao _volsDao; |
@@ -812,6 +819,7 @@ protected DiskProfile toDiskProfile(Volume vol, DiskOffering offering) { |
812 | 819 | vol.getTemplateId()); |
813 | 820 | } |
814 | 821 |
|
| 822 | + @ActionEvent(eventType = EventTypes.EVENT_VOLUME_CREATE, eventDescription = "creating ROOT volume", create = true) |
815 | 823 | @Override |
816 | 824 | public DiskProfile allocateRawVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template, Account owner, |
817 | 825 | Long deviceId) { |
@@ -871,7 +879,11 @@ public DiskProfile allocateRawVolume(Type type, String name, DiskOffering offeri |
871 | 879 | _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume, vol.isDisplayVolume()); |
872 | 880 | _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.primary_storage, vol.isDisplayVolume(), new Long(vol.getSize())); |
873 | 881 | } |
874 | | - return toDiskProfile(vol, offering); |
| 882 | + DiskProfile diskProfile = toDiskProfile(vol, offering); |
| 883 | + |
| 884 | + updateRootDiskVolumeEventDetails(type, vm, List.of(diskProfile)); |
| 885 | + |
| 886 | + return diskProfile; |
875 | 887 | } |
876 | 888 |
|
877 | 889 | private DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering offering, Long rootDisksize, Long minIops, Long maxIops, VirtualMachineTemplate template, VirtualMachine vm, |
@@ -953,6 +965,7 @@ private DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering |
953 | 965 | return toDiskProfile(vol, offering); |
954 | 966 | } |
955 | 967 |
|
| 968 | + @ActionEvent(eventType = EventTypes.EVENT_VOLUME_CREATE, eventDescription = "creating ROOT volume", create = true) |
956 | 969 | @Override |
957 | 970 | public List<DiskProfile> allocateTemplatedVolumes(Type type, String name, DiskOffering offering, Long rootDisksize, Long minIops, Long maxIops, VirtualMachineTemplate template, VirtualMachine vm, |
958 | 971 | Account owner) { |
@@ -1006,10 +1019,32 @@ public List<DiskProfile> allocateTemplatedVolumes(Type type, String name, DiskOf |
1006 | 1019 | profiles.add(diskProfile); |
1007 | 1020 | } |
1008 | 1021 |
|
| 1022 | + updateRootDiskVolumeEventDetails(type, vm, profiles); |
| 1023 | + |
1009 | 1024 | handleRootDiskControllerTpeForDeployAsIs(templateAsIsDisks, vm); |
1010 | 1025 | return profiles; |
1011 | 1026 | } |
1012 | 1027 |
|
| 1028 | + /** |
| 1029 | + * Set context information for VOLUME.CREATE event for ROOT disk. |
| 1030 | + * |
| 1031 | + * @param type - Volume Type |
| 1032 | + * @param vm - Virtual Machine |
| 1033 | + * @param diskProfiles - Disk Profiles |
| 1034 | + */ |
| 1035 | + private void updateRootDiskVolumeEventDetails(Type type, VirtualMachine vm, List<DiskProfile> diskProfiles) { |
| 1036 | + CallContext callContext = CallContext.current(); |
| 1037 | + // Update only for volume type ROOT and API command resource type Volume |
| 1038 | + if (type == Type.ROOT && callContext != null && callContext.getEventResourceType() == ApiCommandResourceType.Volume) { |
| 1039 | + List<Long> volumeIds = diskProfiles.stream().map(DiskProfile::getVolumeId).filter(volumeId -> volumeId != null).collect(Collectors.toList()); |
| 1040 | + if (!volumeIds.isEmpty()) { |
| 1041 | + callContext.setEventResourceId(volumeIds.get(0)); |
| 1042 | + } |
| 1043 | + 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())); |
| 1045 | + } |
| 1046 | + } |
| 1047 | + |
1013 | 1048 | private void handleRootDiskControllerTpeForDeployAsIs(List<DatadiskTO> disksAsIs, VirtualMachine vm) { |
1014 | 1049 | if (CollectionUtils.isNotEmpty(disksAsIs)) { |
1015 | 1050 | String diskControllerSubType = disksAsIs.get(0).getDiskControllerSubType(); |
|
0 commit comments