Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restapi: incorrect href for parent href #549

Merged
merged 1 commit into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@

import org.ovirt.engine.core.bll.QueriesCommandBase;
import org.ovirt.engine.core.bll.context.EngineContext;
import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
import org.ovirt.engine.core.common.queries.IdQueryParameters;
import org.ovirt.engine.core.dao.DiskImageDao;
import org.ovirt.engine.core.dao.ImageDao;

public class GetDiskSnapshotByImageIdQuery<P extends IdQueryParameters> extends QueriesCommandBase<P> {
@Inject
private DiskImageDao diskImageDao;

@Inject
private ImageDao imageDao;

public GetDiskSnapshotByImageIdQuery(P parameters, EngineContext engineContext) {
super(parameters, engineContext);
}

@Override
protected void executeQueryCommand() {
getQueryReturnValue().setReturnValue(diskImageDao.getSnapshotById(getParameters().getId()));
DiskImage diskImage = diskImageDao.getSnapshotById(getParameters().getId());
if (diskImage == null) {
getQueryReturnValue().setReturnValue(null);
return;
}
ArtiomDivak marked this conversation as resolved.
Show resolved Hide resolved
diskImage.setParentDiskId(imageDao.get(diskImage.getParentId()).getDiskId());
ArtiomDivak marked this conversation as resolved.
Show resolved Hide resolved

getQueryReturnValue().setReturnValue(diskImage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ protected void executeQueryCommand() {

// If the 'include_template' flag requested - check if one of the disk images' parents is a template disk,
// fetch it and add to the result
if (getParameters().getIncludeTemplate()) {
Set<Guid> imageIds = imagesToReturn.stream().map(DiskImage::getImageId).collect(Collectors.toSet());
DiskImage imageWithMissingParent = imagesToReturn.stream().
filter(image -> image.hasParent() && !imageIds.contains(image.getParentId()))
.findFirst().orElse(null);
if (imageWithMissingParent != null) {
// Found image with parent guid that does not belong to the requested disk
DiskImage parentImage = diskImageDao.getAncestor(imageWithMissingParent.getImageId());
if (parentImage != null && parentImage.isTemplate()) {
Set<Guid> imageIds = imagesToReturn.stream().map(DiskImage::getImageId).collect(Collectors.toSet());
DiskImage imageWithMissingParent = imagesToReturn.stream()
.filter(image -> image.hasParent() && !imageIds.contains(image.getParentId()))
.findFirst().orElse(null);
if (imageWithMissingParent != null) {
// Found image with parent guid that does not belong to the requested disk
DiskImage parentImage = diskImageDao.getAncestor(imageWithMissingParent.getImageId());
if (parentImage != null && parentImage.isTemplate()) {
ahadas marked this conversation as resolved.
Show resolved Hide resolved
imageWithMissingParent.setParentDiskId(parentImage.getId());
if (getParameters().getIncludeTemplate()) {
imagesToReturn.add(parentImage);
} else {
log.error("Image '{}' which is a parent of image '{}', was not found",
imageWithMissingParent.getParentId(), imageWithMissingParent.getId());
}
} else {
log.error("Image '{}' which is a parent of image '{}', was not found",
imageWithMissingParent.getParentId(), imageWithMissingParent.getId());
}
}

getQueryReturnValue().setReturnValue(imagesToReturn);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import java.util.List;
import java.util.Objects;

import org.ovirt.engine.core.common.businessentities.TransientField;
import org.ovirt.engine.core.common.businessentities.VmEntityType;
import org.ovirt.engine.core.compat.Guid;

import com.fasterxml.jackson.annotation.JsonIgnore;

Expand All @@ -31,6 +33,9 @@ public abstract class Disk extends BaseDisk {
private boolean plugged;
private String logicalName;

@TransientField
private Guid parentDiskId;
ArtiomDivak marked this conversation as resolved.
Show resolved Hide resolved

/**
* Image Transfer information is only for display purposes
*/
Expand Down Expand Up @@ -174,4 +179,14 @@ public boolean isDiskSnapshot() {
public boolean isOvfStore() {
return getContentType() == DiskContentType.OVF_STORE;
}

@JsonIgnore
public Guid getParentDiskId() {
return parentDiskId;
}

@JsonIgnore
public void setParentDiskId(Guid parentDiskId) {
ArtiomDivak marked this conversation as resolved.
Show resolved Hide resolved
this.parentDiskId = parentDiskId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.ovirt.engine.api.resource.DiskSnapshotResource;
import org.ovirt.engine.core.common.action.ActionType;
import org.ovirt.engine.core.common.action.RemoveDiskSnapshotsParameters;
import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
import org.ovirt.engine.core.common.queries.IdQueryParameters;
import org.ovirt.engine.core.common.queries.QueryType;
import org.ovirt.engine.core.compat.Guid;
Expand All @@ -26,14 +27,16 @@ protected BackendDiskSnapshotResource(String id, BackendDiskSnapshotsResource pa

@Override
public DiskSnapshot get() {
DiskSnapshot diskSnapshot = performGet(QueryType.GetDiskSnapshotByImageId,
new IdQueryParameters(guid), Disk.class);
DiskImage diskImage = runQuery(QueryType.GetDiskSnapshotByImageId,
new IdQueryParameters(guid)).getReturnValue();
DiskSnapshot diskSnapshot = map(diskImage, null);
diskSnapshot.setDisk(new Disk());
diskSnapshot.getDisk().setId(diskId.toString());
diskSnapshot.getDisk().setHref(backendDiskSnapshotsResource.buildParentHref(diskId.toString(), false));
diskSnapshot.setHref(backendDiskSnapshotsResource.buildHref(diskId.toString(), diskSnapshot.getId().toString()));
if (diskSnapshot.getParent() != null) {
diskSnapshot.getParent().setHref(backendDiskSnapshotsResource.buildHref(diskId.toString(),
diskSnapshot.setHref(backendDiskSnapshotsResource.buildHref(diskId.toString(), diskSnapshot.getId()));
ArtiomDivak marked this conversation as resolved.
Show resolved Hide resolved
Guid parentDiskId = diskImage.getParentDiskId();
if (parentDiskId != null && diskSnapshot.getParent() != null) {
diskSnapshot.getParent().setHref(backendDiskSnapshotsResource.buildHref(parentDiskId.toString(),
diskSnapshot.getParent().getId()));
}
return diskSnapshot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ public DiskSnapshots list() {
protected DiskSnapshots mapCollection(List<org.ovirt.engine.core.common.businessentities.storage.Disk> entities) {
DiskSnapshots collection = new DiskSnapshots();
for (org.ovirt.engine.core.common.businessentities.storage.Disk disk : entities) {
DiskSnapshot diskSnapshot = getMapper(org.ovirt.engine.core.common.businessentities.storage.Disk.class, DiskSnapshot.class).map(disk, null);
DiskSnapshot diskSnapshot = getMapper(org.ovirt.engine.core.common.businessentities.storage.Disk.class, DiskSnapshot.class)
.map(disk, null);
diskSnapshot.setDisk(new Disk());
diskSnapshot.getDisk().setId(this.diskId.toString());
diskSnapshot.getDisk().setId(disk.getId().toString());
collection.getDiskSnapshots().add(addLinks(populate(diskSnapshot, disk), Disk.class));
diskSnapshot.setHref(buildHref(diskId.toString(), diskSnapshot.getId().toString()));
if (diskSnapshot.getParent() != null) {
diskSnapshot.getParent().setHref(buildParentHref(diskId.toString(), false));
ArtiomDivak marked this conversation as resolved.
Show resolved Hide resolved
diskSnapshot.setHref(buildHref(disk.getId().toString(), diskSnapshot.getId()));
Guid parentDiskId = disk.getParentDiskId();
if (parentDiskId != null) {
diskSnapshot.getParent().setHref(buildHref(parentDiskId.toString(),
diskSnapshot.getParent().getId()));
ArtiomDivak marked this conversation as resolved.
Show resolved Hide resolved
} else if (diskSnapshot.getParent() != null) {
ArtiomDivak marked this conversation as resolved.
Show resolved Hide resolved
diskSnapshot.getParent().setHref(buildHref(disk.getId().toString(), diskSnapshot.getParent().getId()));
}
}
return collection;
Expand Down