Juan Hernandez has posted comments on this change.

Change subject: restapi: Enabling disk information editing when adding a new 
template.
......................................................................


Patch Set 3:

(3 comments)

http://gerrit.ovirt.org/#/c/37808/3/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendTemplatesResource.java
File 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendTemplatesResource.java:

Line 146:         if (vm.isSetDisks() && vm.getDisks().isSetDisks()) {
Line 147:             diskToDestinationMap = new HashMap<Guid, DiskImage>();
Line 148:             for (Disk disk : vm.getDisks().getDisks()) {
Line 149:                 if (disk.isSetId()) {
Line 150:                     
org.ovirt.engine.core.common.businessentities.Disk sourceDisk = queryDisk(disk);
This means that if the template has N disks we will be running N+1 backend 
queries, and probably N+1 database queries. It would be better if all the disks 
can be retrieved with just one query. Not a big concern, as most templates will 
have only 1 disk.
Line 151: 
Line 152:                     // VM template can only have disk images
Line 153:                     if (sourceDisk.isDiskImage()) {
Line 154:                         DiskImage destinationDisk = (DiskImage) 
DiskMapper.map(disk, sourceDisk);


Line 153:                     if (sourceDisk.isDiskImage()) {
Line 154:                         DiskImage destinationDisk = (DiskImage) 
DiskMapper.map(disk, sourceDisk);
Line 155: 
Line 156:                         if (disk.isSetStorageDomains() && 
disk.getStorageDomains().isSetStorageDomains()
Line 157:                                 && 
disk.getStorageDomains().getStorageDomains().get(0).isSetId()) {
The storage domain may be an empty list:

  <disk id="...">
    <storage_domains/>
  </disk>

In this case "get(0)" will fail, you need to check it.
Line 158:                             destinationDisk.setStorageIds(new 
ArrayList<Guid>());
Line 159:                             Guid newStorageDomainId = isDomainSet ? 
storageDomainId : asGuid(disk.getStorageDomains().
Line 160:                                     
getStorageDomains().get(0).getId());
Line 161:                             
destinationDisk.getStorageIds().add(newStorageDomainId);


Line 154:                         DiskImage destinationDisk = (DiskImage) 
DiskMapper.map(disk, sourceDisk);
Line 155: 
Line 156:                         if (disk.isSetStorageDomains() && 
disk.getStorageDomains().isSetStorageDomains()
Line 157:                                 && 
disk.getStorageDomains().getStorageDomains().get(0).isSetId()) {
Line 158:                             destinationDisk.setStorageIds(new 
ArrayList<Guid>());
Consider creating the list with size 1:

  new ArrayList<>(1)

Otherwise the default is 10, and thus you waste 9.
Line 159:                             Guid newStorageDomainId = isDomainSet ? 
storageDomainId : asGuid(disk.getStorageDomains().
Line 160:                                     
getStorageDomains().get(0).getId());
Line 161:                             
destinationDisk.getStorageIds().add(newStorageDomainId);
Line 162:                         }


-- 
To view, visit http://gerrit.ovirt.org/37808
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ib0baf4e5bd7233fbc4eab2f1f671b8b15e08ba03
Gerrit-PatchSet: 3
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Amit Aviram <aavi...@redhat.com>
Gerrit-Reviewer: Ala Hino <ah...@redhat.com>
Gerrit-Reviewer: Allon Mureinik <amure...@redhat.com>
Gerrit-Reviewer: Amit Aviram <aavi...@redhat.com>
Gerrit-Reviewer: Daniel Erez <de...@redhat.com>
Gerrit-Reviewer: Freddy Rolland <froll...@redhat.com>
Gerrit-Reviewer: Juan Hernandez <juan.hernan...@redhat.com>
Gerrit-Reviewer: Liron Aravot <lara...@redhat.com>
Gerrit-Reviewer: Maor Lipchuk <mlipc...@redhat.com>
Gerrit-Reviewer: Ori Liel <ol...@redhat.com>
Gerrit-Reviewer: Tal Nisan <tni...@redhat.com>
Gerrit-Reviewer: automat...@ovirt.org
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to