@@ -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 ()));
0 commit comments