mirror of https://github.com/apache/cloudstack.git
bug 8195: add on-demand download for buildin templates, only download these buildin centos template after when you adding a host for the hypervisor
status 8195: resolved fixed
This commit is contained in:
parent
47d6614cfb
commit
cfd8cdbf20
|
|
@ -26,8 +26,6 @@ public final class TemplateConstants {
|
|||
public static final String DEFAULT_TMPLT_FIRST_LEVEL_DIR = "tmpl/";
|
||||
|
||||
public static final String DEFAULT_SYSTEM_VM_TEMPLATE_PATH = "template/tmpl/1/";
|
||||
public static final long DEFAULT_SYSTEM_VM_DB_ID = 1L;
|
||||
public static final long DEFAULT_BUILTIN_VM_DB_ID = 2L;
|
||||
|
||||
public static final String DEFAULT_SYSTEM_VM_TMPLT_NAME = "routing";
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package com.cloud.dc.dao;
|
|||
import java.util.List;
|
||||
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface ClusterDao extends GenericDao<ClusterVO, Long> {
|
||||
|
|
@ -27,4 +28,5 @@ public interface ClusterDao extends GenericDao<ClusterVO, Long> {
|
|||
ClusterVO findBy(String name, long podId);
|
||||
List<ClusterVO> listByHyTypeWithoutGuid(String hyType);
|
||||
List<ClusterVO> listByZoneId(long zoneId);
|
||||
List<HypervisorType> getAvailableHypervisorInZone(long zoneId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@
|
|||
*/
|
||||
package com.cloud.dc.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
|
@ -31,6 +33,7 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
|
|||
|
||||
protected final SearchBuilder<ClusterVO> PodSearch;
|
||||
protected final SearchBuilder<ClusterVO> HyTypeWithoutGuidSearch;
|
||||
protected final SearchBuilder<ClusterVO> AvailHyperSearch;
|
||||
protected final SearchBuilder<ClusterVO> ZoneSearch;
|
||||
protected ClusterDaoImpl() {
|
||||
super();
|
||||
|
|
@ -48,6 +51,11 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
|
|||
ZoneSearch = createSearchBuilder();
|
||||
ZoneSearch.and("dataCenterId", ZoneSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||
ZoneSearch.done();
|
||||
|
||||
AvailHyperSearch = createSearchBuilder();
|
||||
AvailHyperSearch.and("zoneId", AvailHyperSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
AvailHyperSearch.groupBy(AvailHyperSearch.entity().getHypervisorType());
|
||||
AvailHyperSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -81,4 +89,17 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
|
|||
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HypervisorType> getAvailableHypervisorInZone(long zoneId) {
|
||||
SearchCriteria<ClusterVO> sc = AvailHyperSearch.create();
|
||||
sc.setParameters("zoneId", zoneId);
|
||||
List<ClusterVO> clusters = listBy(sc);
|
||||
List<HypervisorType> hypers = new ArrayList<HypervisorType>(4);
|
||||
for (ClusterVO cluster : clusters) {
|
||||
hypers.add(cluster.getHypervisorType());
|
||||
}
|
||||
|
||||
return hypers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import com.cloud.host.HostVO;
|
|||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.info.RunningHostCountInfo;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
|
|
@ -137,5 +138,7 @@ public interface HostDao extends GenericDao<HostVO, Long> {
|
|||
|
||||
void loadDetails(HostVO host);
|
||||
|
||||
HostVO findConsoleProxyHost(String name, Type type);
|
||||
HostVO findConsoleProxyHost(String name, Type type);
|
||||
|
||||
List<HypervisorType> getAvailHypervisorInZone(long hostId, long zoneId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import com.cloud.host.HostVO;
|
|||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.info.RunningHostCountInfo;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
|
|
@ -81,6 +82,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
protected final SearchBuilder<HostVO> MaintenanceCountSearch;
|
||||
protected final SearchBuilder<HostVO> ClusterSearch;
|
||||
protected final SearchBuilder<HostVO> ConsoleProxyHostSearch;
|
||||
protected final SearchBuilder<HostVO> AvailHypevisorInZone;
|
||||
|
||||
protected final Attribute _statusAttr;
|
||||
protected final Attribute _msIdAttr;
|
||||
|
|
@ -206,6 +208,13 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
UnmanagedExternalNetworkApplianceSearch.and("types", UnmanagedExternalNetworkApplianceSearch.entity().getType(), SearchCriteria.Op.IN);
|
||||
UnmanagedExternalNetworkApplianceSearch.and("lastPinged", UnmanagedExternalNetworkApplianceSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
|
||||
UnmanagedExternalNetworkApplianceSearch.done();
|
||||
|
||||
AvailHypevisorInZone = createSearchBuilder();
|
||||
AvailHypevisorInZone.and("zoneId", AvailHypevisorInZone.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
AvailHypevisorInZone.and("hostId", AvailHypevisorInZone.entity().getId(), SearchCriteria.Op.NEQ);
|
||||
AvailHypevisorInZone.and("type", AvailHypevisorInZone.entity().getType(), SearchCriteria.Op.EQ);
|
||||
AvailHypevisorInZone.groupBy(AvailHypevisorInZone.entity().getHypervisorType());
|
||||
AvailHypevisorInZone.done();
|
||||
|
||||
_statusAttr = _allAttributes.get("status");
|
||||
_msIdAttr = _allAttributes.get("managementServerId");
|
||||
|
|
@ -616,6 +625,20 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
assert tg != null : "how can this be wrong!";
|
||||
|
||||
return s_seqFetcher.getNextSequence(Long.class, tg, hostId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HypervisorType> getAvailHypervisorInZone(long hostId, long zoneId) {
|
||||
SearchCriteria<HostVO> sc = AvailHypevisorInZone.create();
|
||||
sc.setParameters("zoneId", zoneId);
|
||||
sc.setParameters("hostId", hostId);
|
||||
sc.setParameters("type", Host.Type.Routing);
|
||||
List<HostVO> hosts = listBy(sc);
|
||||
List<HypervisorType> hypers = new ArrayList<HypervisorType>(4);
|
||||
for (HostVO host : hosts) {
|
||||
hypers.add(host.getHypervisorType());
|
||||
}
|
||||
return hypers;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import com.cloud.agent.api.AgentControlCommand;
|
|||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupRoutingCommand;
|
||||
import com.cloud.agent.api.StartupStorageCommand;
|
||||
import com.cloud.agent.api.storage.DownloadAnswer;
|
||||
import com.cloud.agent.api.storage.DownloadCommand;
|
||||
|
|
@ -276,24 +277,25 @@ public class DownloadListener implements Listener {
|
|||
|
||||
@Override
|
||||
public void processConnect(HostVO agent, StartupCommand cmd) throws ConnectionException {
|
||||
if (!(cmd instanceof StartupStorageCommand)) {
|
||||
if (!((cmd instanceof StartupStorageCommand) || (cmd instanceof StartupRoutingCommand))) {
|
||||
return;
|
||||
}
|
||||
if (cmd.getGuid().startsWith("iso:")) {
|
||||
//FIXME: do not download template for ISO secondary
|
||||
return;
|
||||
}
|
||||
|
||||
long agentId = agent.getId();
|
||||
|
||||
StartupStorageCommand storage = (StartupStorageCommand)cmd;
|
||||
if (storage.getResourceType() == Storage.StorageResourceType.STORAGE_HOST ||
|
||||
storage.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE )
|
||||
{
|
||||
downloadMonitor.handleTemplateSync(agentId, storage.getTemplateInfo());
|
||||
if (cmd instanceof StartupRoutingCommand) {
|
||||
downloadMonitor.handleSysTemplateDownload(agent);
|
||||
} else {
|
||||
//downloadMonitor.handlePoolTemplateSync(storage.getPoolInfo(), storage.getTemplateInfo());
|
||||
//no need to do anything. The storagepoolmonitor will initiate template sync.
|
||||
if (cmd.getGuid().startsWith("iso:")) {
|
||||
//FIXME: do not download template for ISO secondary
|
||||
return;
|
||||
}
|
||||
|
||||
long agentId = agent.getId();
|
||||
|
||||
StartupStorageCommand storage = (StartupStorageCommand)cmd;
|
||||
if (storage.getResourceType() == Storage.StorageResourceType.STORAGE_HOST ||
|
||||
storage.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE )
|
||||
{
|
||||
downloadMonitor.handleTemplateSync(agentId, storage.getTemplateInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package com.cloud.storage.download;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
|
@ -43,4 +44,7 @@ public interface DownloadMonitor extends Manager{
|
|||
public void copyTemplate(VMTemplateVO template, HostVO sourceServer, HostVO destServer)
|
||||
throws InvalidParameterValueException, StorageUnavailableException;
|
||||
|
||||
/*When new host added, take a look at if there are templates needed to be downloaded for the same hypervisor as the host*/
|
||||
void handleSysTemplateDownload(HostVO hostId);
|
||||
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@ import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
|
|||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.UsageEventVO;
|
||||
|
|
@ -105,6 +106,11 @@ public class DownloadMonitorImpl implements DownloadMonitor {
|
|||
|
||||
@Inject
|
||||
private UsageEventDao _usageEventDao;
|
||||
|
||||
@Inject
|
||||
private ClusterDao _clusterDao;
|
||||
@Inject
|
||||
private HostDao _hostDao;
|
||||
|
||||
private String _name;
|
||||
private Boolean _sslCopy = new Boolean(false);
|
||||
|
|
@ -381,7 +387,47 @@ public class DownloadMonitorImpl implements DownloadMonitor {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSysTemplateDownload(HostVO host) {
|
||||
List<HypervisorType> hypers = _hostDao.getAvailHypervisorInZone(host.getId(), host.getDataCenterId());
|
||||
HypervisorType hostHyper = host.getHypervisorType();
|
||||
if (hypers.contains(hostHyper)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<VMTemplateVO> toBeDownloaded = new HashSet<VMTemplateVO>();
|
||||
List<HostVO> ssHosts = _hostDao.listBy(Host.Type.SecondaryStorage, host.getDataCenterId());
|
||||
if (ssHosts == null || ssHosts.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
HostVO sshost = ssHosts.get(0);
|
||||
/*Download all the templates in zone with the same hypervisortype*/
|
||||
|
||||
List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
|
||||
List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
|
||||
|
||||
|
||||
for (VMTemplateVO rtngTmplt : rtngTmplts) {
|
||||
if (rtngTmplt.getHypervisorType() == hostHyper) {
|
||||
toBeDownloaded.add(rtngTmplt);
|
||||
}
|
||||
}
|
||||
|
||||
for (VMTemplateVO builtinTmplt : defaultBuiltin) {
|
||||
if (builtinTmplt.getHypervisorType() == hostHyper) {
|
||||
toBeDownloaded.add(builtinTmplt);
|
||||
}
|
||||
}
|
||||
|
||||
for (VMTemplateVO template: toBeDownloaded) {
|
||||
VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(sshost.getId(), template.getId());
|
||||
if (tmpltHost == null) {
|
||||
downloadTemplateToStorage(template, sshost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleTemplateSync(long sserverId, Map<String, TemplateInfo> templateInfos) {
|
||||
HostVO storageHost = _serverDao.findById(sserverId);
|
||||
|
|
@ -389,26 +435,26 @@ public class DownloadMonitorImpl implements DownloadMonitor {
|
|||
s_logger.warn("Huh? Agent id " + sserverId + " does not correspond to a row in hosts table?");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Set<VMTemplateVO> toBeDownloaded = new HashSet<VMTemplateVO>();
|
||||
List<VMTemplateVO> allTemplates = _templateDao.listAllInZone(storageHost.getDataCenterId());
|
||||
List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
|
||||
List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
|
||||
|
||||
if (rtngTmplts != null) {
|
||||
for (VMTemplateVO rtngTmplt : rtngTmplts) {
|
||||
if (!allTemplates.contains(rtngTmplt)) {
|
||||
allTemplates.add(rtngTmplt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rtngTmplts != null) {
|
||||
for (VMTemplateVO rtngTmplt : rtngTmplts) {
|
||||
if (!allTemplates.contains(rtngTmplt)) {
|
||||
allTemplates.add(rtngTmplt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultBuiltin != null) {
|
||||
for (VMTemplateVO builtinTmplt : defaultBuiltin) {
|
||||
if (!allTemplates.contains(builtinTmplt)) {
|
||||
allTemplates.add(builtinTmplt);
|
||||
}
|
||||
}
|
||||
for (VMTemplateVO builtinTmplt : defaultBuiltin) {
|
||||
if (!allTemplates.contains(builtinTmplt)) {
|
||||
allTemplates.add(builtinTmplt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toBeDownloaded.addAll(allTemplates);
|
||||
|
|
@ -471,9 +517,13 @@ public class DownloadMonitorImpl implements DownloadMonitor {
|
|||
if (sserver == null) {
|
||||
throw new CloudRuntimeException("Unable to find host from id");
|
||||
}
|
||||
/*Only download templates whose hypervirsor type is in the zone*/
|
||||
List<HypervisorType> availHypers = _clusterDao.getAvailableHypervisorInZone(sserver.getDataCenterId());
|
||||
for (VMTemplateVO tmplt: toBeDownloaded) {
|
||||
s_logger.debug("Template " + tmplt.getName() + " needs to be downloaded to " + sserver.getName());
|
||||
downloadTemplateToStorage(tmplt, sserver);
|
||||
if (availHypers.contains(tmplt.getHypervisorType())) {
|
||||
s_logger.debug("Template " + tmplt.getName() + " needs to be downloaded to " + sserver.getName());
|
||||
downloadTemplateToStorage(tmplt, sserver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -258,7 +258,6 @@ public class SecondaryStorageDiscoverer extends DiscovererBase implements Discov
|
|||
if (_useServiceVM) {
|
||||
for (HostVO h: hosts) {
|
||||
_hostDao.disconnect(h, Event.AgentDisconnected, msId);
|
||||
associateSystemVmTemplate(h.getId(), h.getDataCenterId());
|
||||
}
|
||||
}
|
||||
for (HostVO h: hosts) {
|
||||
|
|
@ -267,24 +266,8 @@ public class SecondaryStorageDiscoverer extends DiscovererBase implements Discov
|
|||
|
||||
}
|
||||
|
||||
protected void associateSystemVmTemplate(long hostId, long dcId) {
|
||||
VMTemplateVO tmplt = _tmpltDao.findById(TemplateConstants.DEFAULT_SYSTEM_VM_DB_ID);
|
||||
if (tmplt == null) {
|
||||
throw new CloudRuntimeException("Cannot find routing template in vm_template table. Check your configuration");
|
||||
}
|
||||
VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(hostId, TemplateConstants.DEFAULT_SYSTEM_VM_DB_ID);
|
||||
if (tmpltHost == null) {
|
||||
VMTemplateHostVO vmTemplateHost = new VMTemplateHostVO(hostId, TemplateConstants.DEFAULT_SYSTEM_VM_DB_ID, new Date(), 100, VMTemplateStorageResourceAssoc.Status.DOWNLOADED, null, null, null, TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH, null);
|
||||
_vmTemplateHostDao.persist(vmTemplateHost);
|
||||
}
|
||||
}
|
||||
|
||||
private void associateTemplatesToZone(long hostId, long dcId){
|
||||
VMTemplateZoneVO tmpltZone = _vmTemplateZoneDao.findByZoneTemplate(dcId, TemplateConstants.DEFAULT_SYSTEM_VM_DB_ID);
|
||||
if (tmpltZone == null) {
|
||||
VMTemplateZoneVO vmTemplateZone = new VMTemplateZoneVO(dcId, TemplateConstants.DEFAULT_SYSTEM_VM_DB_ID, new Date());
|
||||
_vmTemplateZoneDao.persist(vmTemplateZone);
|
||||
}
|
||||
VMTemplateZoneVO tmpltZone;
|
||||
|
||||
List<VMTemplateVO> allTemplates = _vmTemplateDao.listAll();
|
||||
for (VMTemplateVO vt: allTemplates){
|
||||
|
|
|
|||
Loading…
Reference in New Issue