DaanHoogland commented on a change in pull request #5903:
URL: https://github.com/apache/cloudstack/pull/5903#discussion_r795733574
##########
File path:
server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java
##########
@@ -287,24 +288,40 @@ public boolean assignVMToBackupOffering(Long vmId, Long
offeringId) {
throw new CloudRuntimeException("Failed to get the backup provider
for the zone, please contact the administrator");
}
- vm.setBackupOfferingId(offering.getId());
-
vm.setBackupVolumes(createVolumeInfoFromVolumes(volumeDao.findByInstance(vm.getId())));
- if (vmInstanceDao.update(vm.getId(), vm)) {
-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_BACKUP_OFFERING_ASSIGN,
vm.getAccountId(), vm.getDataCenterId(), vm.getId(),
- "Backup-" + vm.getHostName() + "-" + vm.getUuid(),
vm.getBackupOfferingId(), null, null,
- Backup.class.getSimpleName(), vm.getUuid());
- } else {
- throw new CloudRuntimeException("Failed to update VM assignment to
the backup offering in the DB, please try again.");
- }
+ return transactionAssignVMToBackupOffering(vm, offering,
backupProvider) != null;
+ }
- try {
- if (backupProvider.assignVMToBackupOffering(vm, offering)) {
- return vmInstanceDao.update(vm.getId(), vm);
+ private VMInstanceVO transactionAssignVMToBackupOffering(VMInstanceVO vm,
BackupOfferingVO offering, BackupProvider backupProvider) {
+ return Transaction.execute(TransactionLegacy.CLOUD_DB, new
TransactionCallback<VMInstanceVO>() {
+ @Override
+ public VMInstanceVO doInTransaction(final TransactionStatus
status) {
+ try {
+ long vmId = vm.getId();
+ vm.setBackupOfferingId(offering.getId());
+
vm.setBackupVolumes(createVolumeInfoFromVolumes(volumeDao.findByInstance(vmId)));
+
+ if (vmInstanceDao.update(vmId, vm)) {
+ if (backupProvider.assignVMToBackupOffering(vm,
offering)) {
+ vmInstanceDao.update(vmId, vm);
+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_BACKUP_OFFERING_ASSIGN,
vm.getAccountId(), vm.getDataCenterId(), vmId,
+ "Backup-" + vm.getHostName() + "-" +
vm.getUuid(), vm.getBackupOfferingId(), null, null,
+ Backup.class.getSimpleName(),
vm.getUuid());
+ LOG.debug(String.format("VM [%s] successfully
added to Backup Offering [%s].",
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(vm, "uuid",
"instanceName", "backupOfferingId", "backupVolumes"),
+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(offering, "uuid",
"name", "externalId", "provider")));
+ return vm;
+ }
+ } else {
+ throw new CloudRuntimeException("Failed to update VM
assignment to the backup offering in the DB, please try again.");
+ }
+ } catch (Exception e) {
+ LOG.error(String.format("Failed to assign VM [%s] to the
Backup Offering [%s], using provider [name: %s, class: %s], due to: [%s].",
+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(vm, "uuid",
"instanceName", "backupOfferingId", "backupVolumes"),
+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(offering, "uuid",
"name", "externalId", "provider"),
+ backupProvider.getName(),
backupProvider.getClass().getSimpleName(), e.getMessage()), e);
Review comment:
I would not want a stack trace in an error message.
How about creating the message twice, once as error and once with stacktrace
as debug?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]