mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
bug 10681: for serviceOfferings, diskOfferings, templates/isos return records with not null Removed field on findById method call
status 10681: resolved fixed
This commit is contained in:
parent
398cea40e1
commit
25206e6257
@ -40,6 +40,7 @@ import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
@ -312,6 +313,13 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
|
||||
if (template == null) {
|
||||
throw new InvalidParameterValueException("Unable to use template " + templateId);
|
||||
}
|
||||
|
||||
if (diskOfferingId != null) {
|
||||
DiskOffering diskOffering = _configService.getDiskOffering(diskOfferingId);
|
||||
if (diskOffering == null) {
|
||||
throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
|
||||
}
|
||||
}
|
||||
|
||||
UserVm vm = null;
|
||||
if (getHypervisor() == HypervisorType.BareMetal) {
|
||||
|
||||
@ -25,6 +25,8 @@ import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.UserVmResponse;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.uservm.UserVm;
|
||||
@ -84,6 +86,12 @@ public class UpgradeVMCmd extends BaseCmd {
|
||||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("Vm Id: "+getId());
|
||||
|
||||
ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
|
||||
if (serviceOffering == null) {
|
||||
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
|
||||
}
|
||||
|
||||
UserVm result = _userVmService.upgradeVirtualMachine(this);
|
||||
if (result != null){
|
||||
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
|
||||
|
||||
@ -236,4 +236,5 @@ public interface ConfigurationService {
|
||||
|
||||
Integer getServiceOfferingNetworkRate(long serviceOfferingId);
|
||||
|
||||
DiskOffering getDiskOffering(long diskOfferingId);
|
||||
}
|
||||
|
||||
@ -31,6 +31,8 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.cloud.offering.DiskOffering;
|
||||
@ -72,7 +74,8 @@ public class DiskOfferingVO implements DiskOffering {
|
||||
@Column(name="type")
|
||||
Type type;
|
||||
|
||||
@Column(name=GenericDao.REMOVED_COLUMN)
|
||||
@Column(name=GenericDao.REMOVED)
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date removed;
|
||||
|
||||
@Column(name=GenericDao.CREATED_COLUMN)
|
||||
@ -275,5 +278,9 @@ public class DiskOfferingVO implements DiskOffering {
|
||||
|
||||
public void setUseLocalStorage(boolean useLocalStorage) {
|
||||
this.useLocalStorage = useLocalStorage;
|
||||
}
|
||||
}
|
||||
|
||||
public void setRemoved(Date removed) {
|
||||
this.removed = removed;
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,8 +77,8 @@ public class VMTemplateVO implements VirtualMachineTemplate {
|
||||
@Column(name=GenericDao.CREATED_COLUMN)
|
||||
private Date created = null;
|
||||
|
||||
@Temporal(value=TemporalType.TIMESTAMP)
|
||||
@Column(name=GenericDao.REMOVED_COLUMN)
|
||||
@Column(name=GenericDao.REMOVED)
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date removed;
|
||||
|
||||
@Column(name="account_id")
|
||||
@ -404,5 +404,9 @@ public class VMTemplateVO implements VirtualMachineTemplate {
|
||||
}
|
||||
return toString;
|
||||
}
|
||||
|
||||
|
||||
public void setRemoved(Date removed) {
|
||||
this.removed = removed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1545,8 +1545,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
}
|
||||
|
||||
// Verify input parameters
|
||||
ServiceOfferingVO offeringHandle = _serviceOfferingDao.findById(id);
|
||||
;
|
||||
ServiceOffering offeringHandle = getServiceOffering(id);
|
||||
|
||||
if (offeringHandle == null) {
|
||||
throw new InvalidParameterValueException("unable to find service offering " + id);
|
||||
}
|
||||
@ -1654,7 +1654,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
String displayText = cmd.getDisplayText();
|
||||
|
||||
// Check if diskOffering exists
|
||||
DiskOfferingVO diskOfferingHandle = _diskOfferingDao.findById(diskOfferingId);
|
||||
DiskOffering diskOfferingHandle = getDiskOffering(diskOfferingId);
|
||||
|
||||
if (diskOfferingHandle == null) {
|
||||
throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId);
|
||||
@ -1711,7 +1711,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
public boolean deleteDiskOffering(DeleteDiskOfferingCmd cmd) {
|
||||
Long diskOfferingId = cmd.getId();
|
||||
|
||||
DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
|
||||
DiskOffering offering = getDiskOffering(diskOfferingId);
|
||||
|
||||
if (offering == null) {
|
||||
throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId);
|
||||
@ -1737,12 +1737,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
}
|
||||
|
||||
// Verify service offering id
|
||||
ServiceOfferingVO offering = _serviceOfferingDao.findById(offeringId);
|
||||
ServiceOffering offering = getServiceOffering(offeringId);
|
||||
if (offering == null) {
|
||||
throw new InvalidParameterValueException("unable to find service offering " + offeringId);
|
||||
} else if (offering.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("unable to find service offering " + offeringId);
|
||||
}
|
||||
}
|
||||
|
||||
if(offering.getDefaultUse()){
|
||||
throw new InvalidParameterValueException("Default service offerings cannot be deleted");
|
||||
@ -3050,7 +3048,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
|
||||
@Override
|
||||
public ServiceOffering getServiceOffering(long serviceOfferingId) {
|
||||
return _serviceOfferingDao.findById(serviceOfferingId);
|
||||
ServiceOfferingVO offering = _serviceOfferingDao.findById(serviceOfferingId);
|
||||
if (offering != null && offering.getRemoved() == null) {
|
||||
return offering;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -3062,7 +3065,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
public Integer getServiceOfferingNetworkRate(long serviceOfferingId) {
|
||||
|
||||
// validate network offering information
|
||||
ServiceOffering offering = getServiceOffering(serviceOfferingId);
|
||||
ServiceOffering offering = _serviceOfferingDao.findById(serviceOfferingId);
|
||||
if (offering == null) {
|
||||
throw new InvalidParameterValueException("Unable to find service offering by id=" + serviceOfferingId);
|
||||
}
|
||||
@ -3082,4 +3085,15 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
|
||||
return networkRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskOffering getDiskOffering(long diskOfferingId) {
|
||||
DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
|
||||
if (offering != null && offering.getRemoved() == null) {
|
||||
return offering;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -119,6 +119,7 @@ import com.cloud.network.rules.RulesManager;
|
||||
import com.cloud.network.rules.StaticNatRule;
|
||||
import com.cloud.network.rules.dao.PortForwardingRulesDao;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
@ -336,7 +337,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
||||
return _routerDao.findById(routerId);
|
||||
}
|
||||
|
||||
ServiceOfferingVO newServiceOffering = _serviceOfferingDao.findById(serviceOfferingId);
|
||||
ServiceOffering newServiceOffering = _configMgr.getServiceOffering(serviceOfferingId);
|
||||
if (newServiceOffering == null) {
|
||||
throw new InvalidParameterValueException("Unable to find service offering with id " + serviceOfferingId);
|
||||
}
|
||||
|
||||
@ -499,21 +499,6 @@ public interface ManagementServer extends ManagementService {
|
||||
|
||||
public long getMemoryUsagebyHost(Long hostId);
|
||||
|
||||
/**
|
||||
* Finds a diskOffering by the specified ID.
|
||||
*
|
||||
* @param diskOfferingId
|
||||
* @return A DiskOffering
|
||||
*/
|
||||
DiskOfferingVO findDiskOfferingById(long diskOffering);
|
||||
|
||||
/**
|
||||
* Finds the obj associated with the private disk offering
|
||||
*
|
||||
* @return -- vo obj for private disk offering
|
||||
*/
|
||||
List<DiskOfferingVO> findPrivateDiskOffering();
|
||||
|
||||
/**
|
||||
* List private templates for which the given account/domain has been granted permission to launch instances
|
||||
*
|
||||
|
||||
@ -210,6 +210,8 @@ import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
import com.cloud.storage.upload.UploadMonitor;
|
||||
import com.cloud.template.TemplateManager;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
@ -310,6 +312,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
private final NetworkDao _networkDao;
|
||||
private final StorageManager _storageMgr;
|
||||
private final VirtualMachineManager _itMgr;
|
||||
private final TemplateManager _templateMgr;
|
||||
|
||||
private final Adapters<UserAuthenticator> _userAuthenticators;
|
||||
private final HostPodDao _hostPodDao;
|
||||
@ -394,6 +397,8 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
if (_userAuthenticators == null || !_userAuthenticators.isSet()) {
|
||||
s_logger.error("Unable to find an user authenticator.");
|
||||
}
|
||||
|
||||
_templateMgr = locator.getManager(TemplateManager.class);
|
||||
|
||||
String value = _configs.get("account.cleanup.interval");
|
||||
int cleanup = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 day.
|
||||
@ -1079,6 +1084,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
sc.addAnd("vm_type", SearchCriteria.Op.EQ, vm_type_str);
|
||||
}
|
||||
sc.addAnd("systemUse", SearchCriteria.Op.EQ, issystem);
|
||||
sc.addAnd("removed", SearchCriteria.Op.NULL);
|
||||
return _offeringsDao.search(sc, searchFilter);
|
||||
|
||||
}
|
||||
@ -1141,6 +1147,9 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
|
||||
// for this domain
|
||||
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId());
|
||||
|
||||
//don't return removed service offerings
|
||||
sc.addAnd("removed", SearchCriteria.Op.NULL);
|
||||
|
||||
// search and add for this domain
|
||||
sol.addAll(_offeringsDao.search(sc, searchFilter));
|
||||
@ -1973,8 +1982,8 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
Account account = UserContext.current().getCaller();
|
||||
|
||||
// verify that template exists
|
||||
VMTemplateVO template = findTemplateById(id);
|
||||
if (template == null) {
|
||||
VMTemplateVO template = _templateDao.findById(id);
|
||||
if (template == null || template.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("unable to find template/iso with id " + id);
|
||||
}
|
||||
|
||||
@ -3216,17 +3225,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskOfferingVO findDiskOfferingById(long diskOfferingId) {
|
||||
return _diskOfferingDao.findById(diskOfferingId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DiskOfferingVO> findPrivateDiskOffering() {
|
||||
return _diskOfferingDao.findPrivateDiskOffering();
|
||||
}
|
||||
|
||||
protected boolean templateIsCorrectType(VMTemplateVO template) {
|
||||
protected boolean templateIsCorrectType(VirtualMachineTemplate template) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -3414,7 +3413,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
throw new PermissionDeniedException("unable to list permissions for " + cmd.getMediaType() + " with id " + id);
|
||||
}
|
||||
|
||||
VMTemplateVO template = _templateDao.findById(id.longValue());
|
||||
VirtualMachineTemplate template = _templateMgr.getTemplate(id);
|
||||
if (template == null || !templateIsCorrectType(template)) {
|
||||
throw new InvalidParameterValueException("unable to find " + cmd.getMediaType() + " with id " + id);
|
||||
}
|
||||
@ -3448,6 +3447,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NULL);
|
||||
|
||||
SearchCriteria<DiskOfferingVO> sc = sb.create();
|
||||
if (keyword != null) {
|
||||
@ -3539,6 +3539,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
// For root users, preserving existing flow
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NULL);
|
||||
|
||||
// FIXME: disk offerings should search back up the hierarchy for available disk offerings...
|
||||
/*
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
package com.cloud.service.dao;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
@ -26,6 +27,7 @@ import javax.persistence.EntityExistsException;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
@ -57,12 +59,14 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
|
||||
SystemServiceOffering.and("domainId", SystemServiceOffering.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
SystemServiceOffering.and("system", SystemServiceOffering.entity().getSystemUse(), SearchCriteria.Op.EQ);
|
||||
SystemServiceOffering.and("vm_type", SystemServiceOffering.entity().getSpeed(), SearchCriteria.Op.EQ);
|
||||
SystemServiceOffering.and("removed", SystemServiceOffering.entity().getRemoved(), SearchCriteria.Op.NULL);
|
||||
SystemServiceOffering.done();
|
||||
|
||||
|
||||
PublicServiceOfferingSearch = createSearchBuilder();
|
||||
PublicServiceOfferingSearch.and("domainId", PublicServiceOfferingSearch.entity().getDomainId(), SearchCriteria.Op.NULL);
|
||||
PublicServiceOfferingSearch.and("system", PublicServiceOfferingSearch.entity().getSystemUse(), SearchCriteria.Op.EQ);
|
||||
PublicServiceOfferingSearch.and("removed", PublicServiceOfferingSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
|
||||
PublicServiceOfferingSearch.done();
|
||||
|
||||
ServiceOfferingsByKeywordSearch = createSearchBuilder();
|
||||
@ -141,5 +145,13 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
|
||||
// Assume it's conflict on unique name
|
||||
return findByName(offering.getUniqueName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Long id) {
|
||||
ServiceOfferingVO offering = createForUpdate();
|
||||
offering.setRemoved(new Date());
|
||||
|
||||
return update(id, offering);
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
@ -70,7 +71,6 @@ import com.cloud.api.commands.CreateStoragePoolCmd;
|
||||
import com.cloud.api.commands.CreateVolumeCmd;
|
||||
import com.cloud.api.commands.DeletePoolCmd;
|
||||
import com.cloud.api.commands.DeleteVolumeCmd;
|
||||
import com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;
|
||||
import com.cloud.api.commands.UpdateStoragePoolCmd;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.capacity.Capacity;
|
||||
@ -112,12 +112,13 @@ import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.HostDetailsDao;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.host.dao.HostDetailsDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.HypervisorGuruManager;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.org.Grouping;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
@ -183,8 +184,6 @@ import com.cloud.vm.dao.SecondaryStorageVmDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Local(value = { StorageManager.class, StorageService.class })
|
||||
public class StorageManagerImpl implements StorageManager, StorageService, Manager, ClusterManagerListener {
|
||||
private static final Logger s_logger = Logger.getLogger(StorageManagerImpl.class);
|
||||
@ -1663,7 +1662,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
}
|
||||
// Check that the the disk offering is specified
|
||||
DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
|
||||
if ((diskOffering == null) || !DiskOfferingVO.Type.Disk.equals(diskOffering.getType())) {
|
||||
if ((diskOffering == null) || diskOffering.getRemoved() != null || !DiskOfferingVO.Type.Disk.equals(diskOffering.getType())) {
|
||||
throw new InvalidParameterValueException("Please specify a valid disk offering.");
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
package com.cloud.storage.dao;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
@ -46,7 +47,8 @@ public class DiskOfferingDaoImpl extends GenericDaoBase<DiskOfferingVO, Long> im
|
||||
|
||||
protected DiskOfferingDaoImpl() {
|
||||
DomainIdSearch = createSearchBuilder();
|
||||
DomainIdSearch.and("domainId", DomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
DomainIdSearch.and("domainId", DomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
|
||||
DomainIdSearch.and("removed", DomainIdSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
|
||||
DomainIdSearch.done();
|
||||
|
||||
PrivateDiskOfferingSearch = createSearchBuilder();
|
||||
@ -137,5 +139,13 @@ public class DiskOfferingDaoImpl extends GenericDaoBase<DiskOfferingVO, Long> im
|
||||
// Assume it's conflict on unique name
|
||||
return findByUniqueName(offering.getUniqueName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Long id) {
|
||||
DiskOfferingVO diskOffering = createForUpdate();
|
||||
diskOffering.setRemoved(new Date());
|
||||
|
||||
return update(id, diskOffering);
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
@ -36,25 +35,20 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.info.RunningHostCountInfo;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VMTemplateZoneVO;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.db.DB;
|
||||
@ -64,8 +58,8 @@ import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.JoinBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Local(value={VMTemplateDao.class})
|
||||
public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implements VMTemplateDao {
|
||||
@ -608,5 +602,13 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
SearchCriteria<Long> sc = CountTemplatesByAccount.create();
|
||||
sc.setParameters("account", accountId);
|
||||
return customSearch(sc, null).get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Long id) {
|
||||
VMTemplateVO template = createForUpdate();
|
||||
template.setRemoved(new Date());
|
||||
|
||||
return update(id, template);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ import com.cloud.storage.VMTemplateVO;
|
||||
* TemplateManager manages the templates stored on secondary storage. It is responsible for creating private/public templates.
|
||||
* It is also responsible for downloading.
|
||||
*/
|
||||
public interface TemplateManager {
|
||||
public interface TemplateManager extends TemplateService{
|
||||
|
||||
/**
|
||||
* Creates a Template
|
||||
|
||||
@ -94,7 +94,6 @@ import com.cloud.storage.dao.VMTemplatePoolDao;
|
||||
import com.cloud.storage.dao.VMTemplateZoneDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.download.DownloadMonitor;
|
||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
import com.cloud.storage.upload.UploadMonitor;
|
||||
import com.cloud.template.TemplateAdapter.TemplateAdapterType;
|
||||
import com.cloud.user.Account;
|
||||
@ -227,7 +226,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
}
|
||||
eventId = eventId == null ? 0:eventId;
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId);
|
||||
if (template == null) {
|
||||
if (template == null || template.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find " +desc+ " with id " + templateId);
|
||||
}
|
||||
if (template.getTemplateType() == Storage.TemplateType.SYSTEM){
|
||||
@ -565,7 +564,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
}
|
||||
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId);
|
||||
if (template == null) {
|
||||
if (template == null || template.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find template with id");
|
||||
}
|
||||
|
||||
@ -806,7 +805,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
}
|
||||
|
||||
VMTemplateVO iso = _tmpltDao.findById(isoId);
|
||||
if (iso == null) {
|
||||
if (iso == null || iso.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find an ISO with id " + isoId);
|
||||
}
|
||||
|
||||
@ -884,7 +883,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
Long templateId = cmd.getId();
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId.longValue());
|
||||
VirtualMachineTemplate template = getTemplate(templateId);
|
||||
if (template == null) {
|
||||
throw new InvalidParameterValueException("unable to find template with id " + templateId);
|
||||
}
|
||||
@ -915,7 +914,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Long zoneId = cmd.getZoneId();
|
||||
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId.longValue());
|
||||
VirtualMachineTemplate template = getTemplate(templateId);;
|
||||
if (template == null) {
|
||||
throw new InvalidParameterValueException("unable to find iso with id " + templateId);
|
||||
}
|
||||
@ -945,6 +944,11 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
@Override
|
||||
public VirtualMachineTemplate getTemplate(long templateId) {
|
||||
return _tmpltDao.findById(templateId);
|
||||
VMTemplateVO template = _tmpltDao.findById(templateId);
|
||||
if (template != null && template.getRemoved() == null) {
|
||||
return template;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1727,7 +1727,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
throw new InvalidParameterValueException("unable to find virtual machine with id " + id);
|
||||
}
|
||||
|
||||
ServiceOffering offering = _configMgr.getServiceOffering(vmInstance.getServiceOfferingId());
|
||||
ServiceOffering offering = _serviceOfferingDao.findById(vmInstance.getServiceOfferingId());
|
||||
if (!offering.getOfferHA() && ha != null && ha) {
|
||||
throw new InvalidParameterValueException("Can't enable ha for the vm as it's created from the Service offering having HA disabled");
|
||||
}
|
||||
|
||||
@ -597,7 +597,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
|
||||
T startedVm = null;
|
||||
ServiceOfferingVO offering = _offeringDao.findById(vm.getServiceOfferingId());
|
||||
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
|
||||
VMTemplateVO template = _templateDao.findById(vm.getTemplateId());
|
||||
|
||||
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterIdToDeployIn(), vm.getPodIdToDeployIn(), null, null, null);
|
||||
if(planToDeploy != null){
|
||||
|
||||
@ -234,4 +234,12 @@ public class Attribute {
|
||||
public String toString() {
|
||||
return table + "." + columnName;
|
||||
}
|
||||
|
||||
public String getColumnName() {
|
||||
return columnName;
|
||||
}
|
||||
|
||||
public void setColumnName(String columnName) {
|
||||
this.columnName = columnName;
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,9 @@ public interface GenericDao<T, ID extends Serializable> {
|
||||
/**
|
||||
* This column can be used if the table wants to delay deletion.
|
||||
*/
|
||||
static final String REMOVED_COLUMN = "removed";
|
||||
static final String REMOVED_COLUMN = "cloud_removed";
|
||||
|
||||
static final String REMOVED = "removed";
|
||||
|
||||
/**
|
||||
* This column can be used if the table wants to track creation time.
|
||||
|
||||
@ -135,6 +135,18 @@ public class SqlGenerator {
|
||||
}
|
||||
|
||||
Attribute attr = new Attribute(clazz, overrides, field, tableName, embedded, isId);
|
||||
|
||||
if (attr.getColumnName().equals(GenericDao.REMOVED_COLUMN)) {
|
||||
attr.setColumnName(GenericDao.REMOVED);
|
||||
attr.setTrue(Attribute.Flag.DaoGenerated);
|
||||
attr.setFalse(Attribute.Flag.Insertable);
|
||||
attr.setFalse(Attribute.Flag.Updatable);
|
||||
attr.setTrue(Attribute.Flag.TimeStamp);
|
||||
attr.setFalse(Attribute.Flag.Time);
|
||||
attr.setFalse(Attribute.Flag.Date);
|
||||
attr.setTrue(Attribute.Flag.Nullable);
|
||||
attr.setTrue(Attribute.Flag.Removed);
|
||||
}
|
||||
|
||||
if (attr.isId()) {
|
||||
List<Attribute> attrs = _ids.get(tableName);
|
||||
@ -249,18 +261,6 @@ public class SqlGenerator {
|
||||
attr.setTrue(Attribute.Flag.Created);
|
||||
}
|
||||
|
||||
attr = findAttribute(GenericDao.REMOVED_COLUMN);
|
||||
if (attr != null && attr.field.getType() == Date.class) {
|
||||
attr.setTrue(Attribute.Flag.DaoGenerated);
|
||||
attr.setFalse(Attribute.Flag.Insertable);
|
||||
attr.setFalse(Attribute.Flag.Updatable);
|
||||
attr.setTrue(Attribute.Flag.TimeStamp);
|
||||
attr.setFalse(Attribute.Flag.Time);
|
||||
attr.setFalse(Attribute.Flag.Date);
|
||||
attr.setTrue(Attribute.Flag.Nullable);
|
||||
attr.setTrue(Attribute.Flag.Removed);
|
||||
}
|
||||
|
||||
attr = findAttribute(GenericDao.XID_COLUMN);
|
||||
if (attr != null && attr.field.getType() == String.class) {
|
||||
attr.setTrue(Attribute.Flag.DaoGenerated);
|
||||
@ -280,7 +280,11 @@ public class SqlGenerator {
|
||||
|
||||
public Attribute findAttribute(String name) {
|
||||
for (Attribute attr : _attributes) {
|
||||
if (attr.columnName == name || attr.columnName.equals(name)) {
|
||||
if (attr.columnName.equals(GenericDao.REMOVED) && attr.isUpdatable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (attr.columnName.equals(name)) {
|
||||
return attr;
|
||||
}
|
||||
}
|
||||
@ -432,7 +436,7 @@ public class SqlGenerator {
|
||||
}
|
||||
|
||||
public Pair<String, Attribute[]> buildRemoveSql() {
|
||||
Attribute attribute = findAttribute(GenericDao.REMOVED_COLUMN);
|
||||
Attribute attribute = findAttribute(GenericDao.REMOVED);
|
||||
if (attribute == null) {
|
||||
return null;
|
||||
}
|
||||
@ -515,7 +519,7 @@ public class SqlGenerator {
|
||||
}
|
||||
|
||||
public Pair<String, Attribute> getRemovedAttribute() {
|
||||
Attribute removed = findAttribute(GenericDao.REMOVED_COLUMN);
|
||||
Attribute removed = findAttribute(GenericDao.REMOVED);
|
||||
if (removed == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user