mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
protect against missing service offering (#9235)
* protect agains missing service offering * search removed before assuming none * import * javadoc
This commit is contained in:
parent
8d02e5f808
commit
ed86dc973b
@ -54,5 +54,5 @@ public interface ServiceOfferingDao extends GenericDao<ServiceOfferingVO, Long>
|
||||
|
||||
List<ServiceOfferingVO> listPublicByCpuAndMemory(Integer cpus, Integer memory);
|
||||
|
||||
ServiceOfferingVO findServiceOfferingByComputeOnlyDiskOffering(long diskOfferingId);
|
||||
ServiceOfferingVO findServiceOfferingByComputeOnlyDiskOffering(long diskOfferingId, boolean includingRemoved);
|
||||
}
|
||||
|
||||
@ -284,10 +284,10 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceOfferingVO findServiceOfferingByComputeOnlyDiskOffering(long diskOfferingId) {
|
||||
public ServiceOfferingVO findServiceOfferingByComputeOnlyDiskOffering(long diskOfferingId, boolean includingRemoved) {
|
||||
SearchCriteria<ServiceOfferingVO> sc = SearchComputeOfferingByComputeOnlyDiskOffering.create();
|
||||
sc.setParameters("disk_offering_id", diskOfferingId);
|
||||
List<ServiceOfferingVO> vos = listBy(sc);
|
||||
List<ServiceOfferingVO> vos = includingRemoved ? listIncludingRemovedBy(sc) : listBy(sc);
|
||||
if (vos.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1109,8 +1109,8 @@ public class ApiDBUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ServiceOfferingVO findServiceOfferingByComputeOnlyDiskOffering(Long diskOfferingId) {
|
||||
ServiceOfferingVO off = s_serviceOfferingDao.findServiceOfferingByComputeOnlyDiskOffering(diskOfferingId);
|
||||
public static ServiceOfferingVO findServiceOfferingByComputeOnlyDiskOffering(Long diskOfferingId, boolean includingRemoved) {
|
||||
ServiceOfferingVO off = s_serviceOfferingDao.findServiceOfferingByComputeOnlyDiskOffering(diskOfferingId, includingRemoved);
|
||||
return off;
|
||||
}
|
||||
public static DomainVO findDomainById(Long domainId) {
|
||||
|
||||
@ -188,8 +188,8 @@ public class VolumeJoinDaoImpl extends GenericDaoBaseWithTagInformation<VolumeJo
|
||||
|
||||
if (volume.getDiskOfferingId() > 0) {
|
||||
DiskOffering computeOnlyDiskOffering = ApiDBUtils.findComputeOnlyDiskOfferingById(volume.getDiskOfferingId());
|
||||
if (computeOnlyDiskOffering != null) {
|
||||
ServiceOffering serviceOffering = ApiDBUtils.findServiceOfferingByComputeOnlyDiskOffering(volume.getDiskOfferingId());
|
||||
ServiceOffering serviceOffering = getServiceOfferingForDiskOffering(volume, computeOnlyDiskOffering);
|
||||
if (serviceOffering != null) {
|
||||
volResponse.setServiceOfferingId(String.valueOf(serviceOffering.getId()));
|
||||
volResponse.setServiceOfferingName(serviceOffering.getName());
|
||||
volResponse.setServiceOfferingDisplayText(serviceOffering.getDisplayText());
|
||||
@ -283,6 +283,26 @@ public class VolumeJoinDaoImpl extends GenericDaoBaseWithTagInformation<VolumeJo
|
||||
return volResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the {@see ServiceOffering} for the {@see Volume} with {@see DiskOffering}
|
||||
* It will first try existing ones
|
||||
* If not found it will try to get a removed one
|
||||
*
|
||||
* @param volume
|
||||
* @param computeOnlyDiskOffering
|
||||
* @return the resulting offering or null
|
||||
*/
|
||||
private static ServiceOffering getServiceOfferingForDiskOffering(VolumeJoinVO volume, DiskOffering computeOnlyDiskOffering) {
|
||||
ServiceOffering serviceOffering = null;
|
||||
if (computeOnlyDiskOffering != null) {
|
||||
serviceOffering = ApiDBUtils.findServiceOfferingByComputeOnlyDiskOffering(volume.getDiskOfferingId(), false);
|
||||
}
|
||||
if (serviceOffering == null) {
|
||||
serviceOffering = ApiDBUtils.findServiceOfferingByComputeOnlyDiskOffering(volume.getDiskOfferingId(), true);
|
||||
}
|
||||
return serviceOffering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeResponse setVolumeResponse(ResponseView view, VolumeResponse volData, VolumeJoinVO vol) {
|
||||
long tag_id = vol.getTagId();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user