Skip to content

Commit

Permalink
Create VmBackup earlier in HybridBackupCommand
Browse files Browse the repository at this point in the history
When creation of a snapshot for the HybridBackup fails, we end up with a
null pointer exception.

2024-04-17 10:29:48,296+02 ERROR [org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector] (default task-2) [76e81a20-4d1d-441b-8e6c-90f37889cd66] EVENT_ID: USER_FAILED_CREATE_SNAPSHOT(117), Failed to create Snapshot Auto-generated for Backup VM for VM xxxxx (User: admin@internal-authz).
2024-04-17 10:29:48,298+02 INFO  [org.ovirt.engine.core.bll.storage.backup.HybridBackupCommand] (default task-2) [76e81a20-4d1d-441b-8e6c-90f37889cd66] Change VM '73df70f5-09b0-4f1a-abd8-2d0b4cd5e8b2' backup 'null' phase from 'null' to 'FAILED'
2024-04-17 10:29:48,299+02 ERROR [org.ovirt.engine.core.bll.storage.backup.HybridBackupCommand] (default task-2) [76e81a20-4d1d-441b-8e6c-90f37889cd66] Command 'org.ovirt.engine.core.bll.storage.backup.HybridBackupCommand' failed: null
2024-04-17 10:29:48,299+02 ERROR [org.ovirt.engine.core.bll.storage.backup.HybridBackupCommand] (default task-2) [76e81a20-4d1d-441b-8e6c-90f37889cd66] Exception: java.lang.NullPointerException
	at org.ovirt.engine.core.dal//org.ovirt.engine.core.dao.VmBackupDaoImpl.update(VmBackupDaoImpl.java:90)
	at org.ovirt.engine.core.dal//org.ovirt.engine.core.dao.VmBackupDaoImpl.update(VmBackupDaoImpl.java:22)
	at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.storage.backup.StartVmBackupCommand.updateVmBackupPhase(StartVmBackupCommand.java:632)
	at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.storage.backup.HybridBackupCommand.executeCommand(HybridBackupCommand.java:118)
	at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.CommandBase.executeWithoutTransaction(CommandBase.java:1174)
	at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.CommandBase.executeActionInTransactionScope(CommandBase.java:1332)

This happens because VmBackupDaoImpl tries to save the BackupType into
the database (entity.getBackupType().getName()), but that value is still
null.
The BackupType is only set when calling createVmBackup.

But as we already have all the data except the snapshotId at the start
of the HybridBackup, we already call createVmBackup before creating the
snapshot and when the snapshot was created, we add it to the VmBackup
data.

This avoids the null getBackupType()

Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
  • Loading branch information
dupondje authored and sandrobonazzola committed May 27, 2024
1 parent 0a1ba82 commit ed023e5
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ protected boolean validate() {
@Override
protected void executeCommand() {
VmBackup vmBackup = getParameters().getVmBackup();
Guid vmBackupId = createVmBackup();
log.info("Created VmBackup entity '{}' for VM '{}'", vmBackupId, vmBackup.getVmId());

Guid toCheckpointId = Guid.newGuid();
ActionReturnValue returnValue = runInternalAction(
Expand All @@ -121,8 +123,7 @@ protected void executeCommand() {

auditLog(AuditLogType.USER_CREATE_SNAPSHOT);
Guid snapshotId = returnValue.getActionReturnValue();
Guid vmBackupId = createVmBackup(snapshotId);
log.info("Created VmBackup entity '{}' for VM '{}'", vmBackupId, vmBackup.getVmId());
setVmBackupSnapshot(snapshotId);
getParameters().setAutoGeneratedSnapshotId(snapshotId);
vmBackup.setDisks(getDisks());
getParameters().setToCheckpointId(toCheckpointId);
Expand Down Expand Up @@ -325,7 +326,7 @@ private CommandContext createStepsContext(StepEnum step) {
.withExecutionContext(ctx);
}

private Guid createVmBackup(Guid snapshotId) {
private Guid createVmBackup() {
VmBackup vmBackup = getParameters().getVmBackup();
Guid backupId = vmBackup.getId() != null ? vmBackup.getId() : getCommandId();
vmBackup.setId(backupId);
Expand All @@ -334,10 +335,17 @@ private Guid createVmBackup(Guid snapshotId) {
vmBackup.setCreationDate(now);
vmBackup.setModificationDate(now);
vmBackup.setBackupType(VmBackupType.Hybrid);
vmBackup.setSnapshotId(snapshotId);
getParameters().setVmBackup(vmBackup);
vmBackupDao.save(vmBackup);
persistCommandIfNeeded();
return vmBackup.getId();
}

private void setVmBackupSnapshot(Guid snapshotId) {
VmBackup vmBackup = getParameters().getVmBackup();
vmBackup.setSnapshotId(snapshotId);
getParameters().setVmBackup(vmBackup);
vmBackupDao.save(vmBackup);
persistCommandIfNeeded();
}
}

0 comments on commit ed023e5

Please sign in to comment.