Skip to content

Commit f38db97

Browse files
committed
Show name in backup list in Instance tab + some changes in error, log and event strings
1 parent 75d8888 commit f38db97

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,14 +609,14 @@ public class EventTypes {
609609
public static final String EVENT_VM_BACKUP_OFFERING_REMOVE = "BACKUP.OFFERING.REMOVE";
610610
public static final String EVENT_VM_BACKUP_CREATE = "BACKUP.CREATE";
611611
public static final String EVENT_VM_BACKUP_RESTORE = "BACKUP.RESTORE";
612-
public static final String EVENT_VM_BACKUP_RESTORE_TO_VM = "BACKUP.RESTORE.TO.VM";
613612
public static final String EVENT_VM_BACKUP_DELETE = "BACKUP.DELETE";
614613
public static final String EVENT_VM_BACKUP_OFFERING_BACKUPS_DELETED = "BACKUP.OFFERING.BACKUPS.DEL";
615614
public static final String EVENT_VM_BACKUP_RESTORE_VOLUME_TO_VM = "BACKUP.RESTORE.VOLUME.TO.VM";
616615
public static final String EVENT_VM_BACKUP_SCHEDULE_CONFIGURE = "BACKUP.SCHEDULE.CONFIGURE";
617616
public static final String EVENT_VM_BACKUP_SCHEDULE_DELETE = "BACKUP.SCHEDULE.DELETE";
618617
public static final String EVENT_VM_BACKUP_USAGE_METRIC = "BACKUP.USAGE.METRIC";
619618
public static final String EVENT_VM_BACKUP_EDIT = "BACKUP.OFFERING.EDIT";
619+
public static final String EVENT_VM_CREATE_FROM_BACKUP = "VM.CREATE.FROM.BACKUP";
620620

621621
// external network device events
622622
public static final String EVENT_EXTERNAL_NVP_CONTROLLER_ADD = "PHYSICAL.NVPCONTROLLER.ADD";

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9551,8 +9551,8 @@ public UserVm restoreVMFromBackup(CreateVMFromBackupCmd cmd) throws ResourceUnav
95519551
if (!status) {
95529552
UserVmVO vmVO = _vmDao.findById(vmId);
95539553
expunge(vmVO);
9554-
logger.debug("Successfully cleaned up VM {} after create instance from backup failed", vmId);
9555-
throw new CloudRuntimeException("Unable to stop the instance before restore");
9554+
logger.debug("Successfully cleaned up Instance {} after create Instance from backup failed", vmId);
9555+
throw new CloudRuntimeException("Unable to stop the Instance before restore");
95569556
}
95579557

95589558
Long isoId = vm.getIsoId();
@@ -9568,9 +9568,9 @@ public UserVm restoreVMFromBackup(CreateVMFromBackupCmd cmd) throws ResourceUnav
95689568
UserVmVO vmVO = _vmDao.findById(vmId);
95699569
try {
95709570
expunge(vmVO);
9571-
logger.debug("Successfully cleaned up VM {} after create instance from backup failed", vmId);
9571+
logger.debug("Successfully cleaned up Instance {} after create Instance from backup failed", vmId);
95729572
} catch (Exception cleanupException) {
9573-
logger.debug("Failed to cleanup VM {} after create instance from backup failed", vmId, cleanupException);
9573+
logger.debug("Failed to cleanup Instance {} after create Instance from backup failed", vmId, cleanupException);
95749574
}
95759575
throw e;
95769576
}

server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,8 @@ public void checkDiskOfferingSizeAgainstBackup(List<DiskOfferingInfo> dataDiskOf
10191019
List<DiskOfferingInfo> dataDiskOfferingsInfoFromBackup = getDataDiskOfferingListFromBackup(backup);
10201020
int index = 0;
10211021
if (dataDiskOfferingsInfo.size() != dataDiskOfferingsInfoFromBackup.size()) {
1022-
throw new InvalidParameterValueException("Unable to restore VM with the current backup " +
1023-
"as the backup has different number of disks as the VM");
1022+
throw new InvalidParameterValueException("Unable to create Instance from Backup " +
1023+
"as the backup has a different number of disks than the Instance.");
10241024
}
10251025
for (DiskOfferingInfo diskOfferingInfo : dataDiskOfferingsInfo) {
10261026
if (index < dataDiskOfferingsInfoFromBackup.size()) {
@@ -1070,7 +1070,8 @@ public List<DiskOfferingInfo> getDataDiskOfferingListFromBackup(Backup backup) {
10701070
if (volume.getType() == Volume.Type.DATADISK) {
10711071
DiskOfferingVO diskOffering = diskOfferingDao.findByUuid(volume.getDiskOfferingId());
10721072
if (diskOffering == null || diskOffering.getState().equals(DiskOffering.State.Inactive)) {
1073-
throw new CloudRuntimeException("Unable to find the disk offering with uuid (" + volume.getDiskOfferingId() + ") stored in backup. Please specify a valid disk offering id while creating the instance");
1073+
throw new CloudRuntimeException("Unable to find the disk offering with uuid (" + volume.getDiskOfferingId() + ") stored in backup. " +
1074+
"Please specify a valid disk offering id while creating the instance");
10741075
}
10751076
Long size = volume.getSize() / (1024 * 1024 * 1024);
10761077
diskOfferingInfoList.add(new DiskOfferingInfo(diskOffering, size, volume.getMinIops(), volume.getMaxIops(), volume.getDeviceId()));
@@ -1093,7 +1094,8 @@ public Map<Long, Network.IpAddresses> getIpToNetworkMapFromBackup(Backup backup,
10931094

10941095
String networkIdsString = backup.getDetail(ApiConstants.NETWORK_IDS);
10951096
if (networkIdsString == null) {
1096-
throw new CloudRuntimeException("Backup doesn't contain network information. Please specify atleast one valid network while creating instance");
1097+
throw new CloudRuntimeException("Backup doesn't contain network information. " +
1098+
"Please specify at least one valid network while creating instance");
10971099
}
10981100
List<String> networkUuids = List.of(networkIdsString.split(","));
10991101

@@ -1117,7 +1119,8 @@ public Map<Long, Network.IpAddresses> getIpToNetworkMapFromBackup(Backup backup,
11171119
for (String networkUuid: networkUuids) {
11181120
Network network = networkDao.findByUuid(networkUuid);
11191121
if (network == null) {
1120-
throw new CloudRuntimeException("Unable to find network with the uuid " + networkUuid + "stored in backup. Please specify a valid network id while creating the instance");
1122+
throw new CloudRuntimeException("Unable to find network with the uuid " + networkUuid + "stored in backup. " +
1123+
"Please specify a valid network id while creating the instance");
11211124
}
11221125
Long networkId = network.getId();
11231126
Network.IpAddresses ipAddresses = null;
@@ -1147,12 +1150,12 @@ public boolean restoreBackupToVM(final Long backupId, final Long vmId) throws Re
11471150

11481151
VMInstanceVO vm = vmInstanceDao.findByIdIncludingRemoved(vmId);
11491152
if (vm == null) {
1150-
throw new CloudRuntimeException("VM ID " + backup.getVmId() + " couldn't be found on existing or removed VMs");
1153+
throw new CloudRuntimeException("Instance with ID " + backup.getVmId() + " couldn't be found.");
11511154
}
11521155
accountManager.checkAccess(CallContext.current().getCallingAccount(), null, true, vm);
11531156

11541157
if (vm.getRemoved() != null) {
1155-
throw new CloudRuntimeException("The VM could not be found");
1158+
throw new CloudRuntimeException("Instance with ID " + backup.getVmId() + " couldn't be found.");
11561159
}
11571160
if (!vm.getState().equals(VirtualMachine.State.Stopped)) {
11581161
throw new CloudRuntimeException("The VM should be in stopped state");
@@ -1165,7 +1168,7 @@ public boolean restoreBackupToVM(final Long backupId, final Long vmId) throws Re
11651168

11661169
List<VolumeVO> vmVolumes = volumeDao.findByInstance(vmId);
11671170
if (vmVolumes.size() != backupVolumes.size()) {
1168-
throw new CloudRuntimeException("Unable to restore VM with the current backup as the backup has different number of disks as the VM");
1171+
throw new CloudRuntimeException("Unable to create Instance from backup as the backup has a different number of disks than the Instance");
11691172
}
11701173

11711174
int index = 0;
@@ -1181,20 +1184,20 @@ public boolean restoreBackupToVM(final Long backupId, final Long vmId) throws Re
11811184

11821185
BackupOffering offering = backupOfferingDao.findByIdIncludingRemoved(backup.getBackupOfferingId());
11831186
if (offering == null) {
1184-
throw new CloudRuntimeException("Failed to find backup offering of the VM backup.");
1187+
throw new CloudRuntimeException("Failed to find backup offering");
11851188
}
11861189
final BackupProvider backupProvider = getBackupProvider(offering.getProvider());
11871190
if (!backupProvider.supportsInstanceFromBackup()) {
1188-
throw new CloudRuntimeException("Create instance from VM is not supported by the " + offering.getProvider() + " plugin.");
1191+
throw new CloudRuntimeException("Create instance from backup is not supported by the " + offering.getProvider() + " provider.");
11891192
}
11901193

11911194
String backupDetailsInMessage = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(backup, "uuid", "externalId", "newVMId", "type", "status", "date");
11921195
Long eventId = null;
11931196
try {
11941197
updateVmState(vm, VirtualMachine.Event.RestoringRequested, VirtualMachine.State.Restoring);
11951198
updateVolumeState(vm, Volume.Event.RestoreRequested, Volume.State.Restoring);
1196-
eventId = ActionEventUtils.onStartedActionEvent(User.UID_SYSTEM, vm.getAccountId(), EventTypes.EVENT_VM_BACKUP_RESTORE_TO_VM,
1197-
String.format("Restoring backup %s to VM %s", backup.getUuid(), vm.getInstanceName()),
1199+
eventId = ActionEventUtils.onStartedActionEvent(User.UID_SYSTEM, vm.getAccountId(), EventTypes.EVENT_VM_CREATE_FROM_BACKUP,
1200+
String.format("Creating Instance %s from backup %s", vm.getInstanceName(), backup.getUuid()),
11981201
vm.getId(), ApiCommandResourceType.VirtualMachine.toString(),
11991202
true, 0);
12001203

@@ -1211,16 +1214,16 @@ public boolean restoreBackupToVM(final Long backupId, final Long vmId) throws Re
12111214
} catch (Exception e) {
12121215
updateVolumeState(vm, Volume.Event.RestoreFailed, Volume.State.Ready);
12131216
updateVmState(vm, VirtualMachine.Event.RestoringFailed, VirtualMachine.State.Stopped);
1214-
logger.error(String.format("Failed to restore backup [%s] to VM %s due to: [%s].", backupDetailsInMessage, vm.getInstanceName(), e.getMessage()), e);
1215-
ActionEventUtils.onCompletedActionEvent(User.UID_SYSTEM, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_BACKUP_RESTORE_TO_VM,
1216-
String.format("Failed to restore backup %s to VM %s", backup.getUuid(), vm.getInstanceName()),
1217+
logger.error(String.format("Failed to create Instance [%s] from backup [%s] due to: [%s].", vm.getInstanceName(), backupDetailsInMessage, e.getMessage()), e);
1218+
ActionEventUtils.onCompletedActionEvent(User.UID_SYSTEM, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_CREATE_FROM_BACKUP,
1219+
String.format("Failed to create Instance %s from backup %s", vm.getInstanceName(), backup.getUuid()),
12171220
vm.getId(), ApiCommandResourceType.VirtualMachine.toString(), eventId);
1218-
throw new CloudRuntimeException(String.format("Error restoring backup [%s] to VM %s.", backupDetailsInMessage, vm.getUuid()));
1221+
throw new CloudRuntimeException(String.format("Error while creating Instance [%s] from backup [%s].", vm.getUuid(), backupDetailsInMessage));
12191222
}
12201223
updateVolumeState(vm, Volume.Event.RestoreSucceeded, Volume.State.Ready);
12211224
updateVmState(vm, VirtualMachine.Event.RestoringSuccess, VirtualMachine.State.Stopped);
1222-
ActionEventUtils.onCompletedActionEvent(User.UID_SYSTEM, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_BACKUP_RESTORE_TO_VM,
1223-
String.format("Successfully completed restoring backup %s to VM %s", backup.getUuid(), vm.getInstanceName()),
1225+
ActionEventUtils.onCompletedActionEvent(User.UID_SYSTEM, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_CREATE_FROM_BACKUP,
1226+
String.format("Successfully created Instance %s from backup %s", vm.getInstanceName(), backup.getUuid()),
12241227
vm.getId(), ApiCommandResourceType.VirtualMachine.toString(),eventId);
12251228
return true;
12261229
}
@@ -1980,7 +1983,7 @@ public void checkAndRemoveBackupOfferingBeforeExpunge(VirtualMachine vm) {
19801983
if (org.apache.commons.collections.CollectionUtils.isEmpty(backupsForVm)) {
19811984
removeVMFromBackupOffering(vm.getId(), true);
19821985
} else {
1983-
throw new CloudRuntimeException(String.format("This VM [uuid: %s, name: %s] has a "
1986+
throw new CloudRuntimeException(String.format("This Instance [uuid: %s, name: %s] has a "
19841987
+ "Backup Offering [id: %s, external id: %s] with %s backups. Please, remove the backup offering "
19851988
+ "before proceeding to VM exclusion!", vm.getUuid(), vm.getInstanceName(), vm.getBackupOfferingId(),
19861989
vm.getBackupExternalId(), backupsForVm.size()));

ui/src/views/compute/InstanceTab.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
apiName="listBackups"
6161
:resource="resource"
6262
:params="{virtualmachineid: dataResource.id}"
63-
:columns="['created', 'status', 'type', 'size', 'virtualsize']"
64-
:routerlinks="(record) => { return { created: '/backup/' + record.id } }"
63+
:columns="['name', 'status', 'size', 'virtualsize', 'type', 'created']"
64+
:routerlinks="(record) => { return { name: '/backup/' + record.id } }"
6565
:showSearch="false"/>
6666
</a-tab-pane>
6767
<a-tab-pane :tab="$t('label.securitygroups')" key="securitygroups" v-if="dataResource.securitygroup && dataResource.securitygroup.length > 0 || $store.getters.showSecurityGroups">

0 commit comments

Comments
 (0)