mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fix copyTemplateCmd.
This commit is contained in:
parent
0da2da852b
commit
1b3994e180
@ -147,8 +147,9 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal
|
||||
this.resourceType = ResourceType.VOLUME;
|
||||
}
|
||||
|
||||
public DownloadCommand(String secUrl, String url, VirtualMachineTemplate template, String user, String passwd, Long maxDownloadSizeInBytes) {
|
||||
public DownloadCommand(DataStoreTO store, String secUrl, String url, VirtualMachineTemplate template, String user, String passwd, Long maxDownloadSizeInBytes) {
|
||||
super(template.getUniqueName(), url, template.getFormat(), template.getAccountId());
|
||||
this._store = store;
|
||||
this.hvm = template.isRequiresHvm();
|
||||
this.checksum = template.getChecksum();
|
||||
this.id = template.getId();
|
||||
|
||||
@ -44,6 +44,8 @@ public interface TemplateDataStoreDao extends GenericDao<TemplateDataStoreVO, Lo
|
||||
|
||||
TemplateDataStoreVO findByStoreTemplate(long storeId, long templateId);
|
||||
|
||||
TemplateDataStoreVO findByStoreTemplate(long storeId, long templateId, boolean lock);
|
||||
|
||||
TemplateDataStoreVO findByTemplate(long templateId);
|
||||
|
||||
List<TemplateDataStoreVO> listByTemplate(long templateId);
|
||||
|
||||
@ -388,8 +388,7 @@ public class TemplateServiceImpl implements TemplateService {
|
||||
VMTemplateVO template = _templateDao.findById(tInfo.getId());
|
||||
DeleteTemplateCommand dtCommand = new DeleteTemplateCommand(store.getTO(), store.getUri(), tInfo.getInstallPath(), template.getId(), template.getAccountId());
|
||||
try {
|
||||
HostVO ssAhost = _ssvmMgr.pickSsvmHost(store);
|
||||
_agentMgr.sendToSecStorage(ssAhost, dtCommand, null);
|
||||
_agentMgr.sendToSecStorage(store, dtCommand, null);
|
||||
} catch (AgentUnavailableException e) {
|
||||
String err = "Failed to delete " + tInfo.getTemplateName() + " on secondary storage " + storeId + " which isn't in the database";
|
||||
s_logger.error(err);
|
||||
@ -430,16 +429,15 @@ public class TemplateServiceImpl implements TemplateService {
|
||||
}
|
||||
|
||||
|
||||
private Map<String, TemplateProp> listTemplate(DataStore ssHost) {
|
||||
ListTemplateCommand cmd = new ListTemplateCommand(ssHost.getUri());
|
||||
HostVO ssAhost = _ssvmMgr.pickSsvmHost(ssHost);
|
||||
Answer answer = _agentMgr.sendToSecStorage(ssAhost, cmd);
|
||||
private Map<String, TemplateProp> listTemplate(DataStore ssStore) {
|
||||
ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getUri());
|
||||
Answer answer = _agentMgr.sendToSecStorage(ssStore, cmd);
|
||||
if (answer != null && answer.getResult()) {
|
||||
ListTemplateAnswer tanswer = (ListTemplateAnswer)answer;
|
||||
return tanswer.getTemplateInfo();
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("can not list template for secondary storage host " + ssHost.getId());
|
||||
s_logger.debug("can not list template for secondary storage host " + ssStore.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
@ -186,6 +187,19 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendToSecStorage(DataStore ssStore, Command cmd, Listener listener) throws AgentUnavailableException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer sendToSecStorage(DataStore ssStore, Command cmd) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -206,6 +206,19 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TemplateDataStoreVO findByStoreTemplate(long storeId, long templateId, boolean lock) {
|
||||
SearchCriteria<TemplateDataStoreVO> sc = storeTemplateSearch.create();
|
||||
sc.setParameters("store_id", storeId);
|
||||
sc.setParameters("template_id", templateId);
|
||||
sc.setParameters("destroyed", false);
|
||||
if (!lock)
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
else
|
||||
return lockOneRandomRow(sc, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateDataStoreVO findByTemplate(long templateId) {
|
||||
SearchCriteria<TemplateDataStoreVO> sc = templateSearch.create();
|
||||
|
||||
@ -814,8 +814,7 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
TemplateProp vInfo = volumeInfos.get(uniqueName);
|
||||
DeleteVolumeCommand dtCommand = new DeleteVolumeCommand(store.getUri(), vInfo.getInstallPath());
|
||||
try {
|
||||
HostVO ssAhost = _ssvmMgr.pickSsvmHost(store);
|
||||
_agentMgr.sendToSecStorage(ssAhost, dtCommand, null);
|
||||
_agentMgr.sendToSecStorage(store, dtCommand, null);
|
||||
} catch (AgentUnavailableException e) {
|
||||
String err = "Failed to delete " + vInfo.getTemplateName() + " on image store " + storeId + " which isn't in the database";
|
||||
s_logger.error(err);
|
||||
@ -830,8 +829,7 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
|
||||
private Map<Long, TemplateProp> listVolume(DataStore store) {
|
||||
ListVolumeCommand cmd = new ListVolumeCommand(store.getUri());
|
||||
HostVO ssAhost = _ssvmMgr.pickSsvmHost(store);
|
||||
Answer answer = _agentMgr.sendToSecStorage(ssAhost, cmd);
|
||||
Answer answer = _agentMgr.sendToSecStorage(store, cmd);
|
||||
if (answer != null && answer.getResult()) {
|
||||
ListVolumeAnswer tanswer = (ListVolumeAnswer)answer;
|
||||
return tanswer.getTemplateInfo();
|
||||
|
||||
@ -236,12 +236,11 @@ public class CloudStackImageStoreDriverImpl implements ImageStoreDriver {
|
||||
List<UserVmVO> userVmUsingIso = _userVmDao.listByIsoId(templateId);
|
||||
// check if there is any VM using this ISO.
|
||||
if (userVmUsingIso == null || userVmUsingIso.isEmpty()) {
|
||||
HostVO ssAhost = _ssvmMgr.pickSsvmHost(store);
|
||||
// get installpath of this template on image store
|
||||
TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId, templateId);
|
||||
String installPath = tmplStore.getInstallPath();
|
||||
if (installPath != null) {
|
||||
Answer answer = _agentMgr.sendToSecStorage(ssAhost, new DeleteTemplateCommand(store.getTO(), store.getUri(), installPath, template.getId(), template.getAccountId()));
|
||||
Answer answer = _agentMgr.sendToSecStorage(store, new DeleteTemplateCommand(store.getTO(), store.getUri(), installPath, template.getId(), template.getAccountId()));
|
||||
|
||||
if (answer == null || !answer.getResult()) {
|
||||
s_logger.debug("Failed to deleted template at store: " + store.getName());
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
// under the License.
|
||||
package com.cloud.agent;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
@ -139,6 +141,10 @@ public interface AgentManager extends Manager {
|
||||
|
||||
Answer sendToSecStorage(HostVO ssHost, Command cmd);
|
||||
|
||||
void sendToSecStorage(DataStore ssStore, Command cmd, Listener listener) throws AgentUnavailableException;
|
||||
|
||||
Answer sendToSecStorage(DataStore ssStore, Command cmd);
|
||||
|
||||
/* working as a lock while agent is being loaded */
|
||||
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action);
|
||||
|
||||
|
||||
@ -39,6 +39,7 @@ import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -380,6 +381,18 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
return attache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer sendToSecStorage(DataStore ssStore, Command cmd) {
|
||||
HostVO ssAhost = _ssvmMgr.pickSsvmHost(ssStore);
|
||||
return easySend(ssAhost.getId(), cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToSecStorage(DataStore ssStore, Command cmd, Listener listener) throws AgentUnavailableException {
|
||||
HostVO ssAhost = _ssvmMgr.pickSsvmHost(ssStore);
|
||||
send(ssAhost.getId(), new Commands(cmd), listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer sendToSecStorage(HostVO ssHost, Command cmd) {
|
||||
if( ssHost.getType() == Host.Type.LocalSecondaryStorage ) {
|
||||
@ -406,6 +419,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void sendToSSVM(final long dcId, final Command cmd, final Listener listener) throws AgentUnavailableException {
|
||||
List<HostVO> ssAHosts = _ssvmMgr.listUpAndConnectingSecondaryStorageVmHost(dcId);
|
||||
if (ssAHosts == null || ssAHosts.isEmpty() ) {
|
||||
|
||||
@ -1266,11 +1266,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
String installPath = destroyedTemplateStoreVO
|
||||
.getInstallPath();
|
||||
|
||||
HostVO ssAhost = this._ssvmMgr.pickSsvmHost(store);
|
||||
if (installPath != null) {
|
||||
|
||||
Answer answer = _agentMgr.sendToSecStorage(
|
||||
ssAhost,
|
||||
Answer answer = _agentMgr.sendToSecStorage(store,
|
||||
new DeleteTemplateCommand(
|
||||
store.getTO(),
|
||||
store.getUri(),
|
||||
|
||||
@ -22,7 +22,6 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
|
||||
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
@ -38,7 +37,7 @@ public interface DownloadMonitor extends Manager{
|
||||
|
||||
public void cancelAllDownloads(Long templateId);
|
||||
|
||||
public boolean copyTemplate(VMTemplateVO template, HostVO sourceServer, HostVO destServer)
|
||||
public boolean copyTemplate(VMTemplateVO template, DataStore sourceStore, DataStore Store)
|
||||
throws StorageUnavailableException;
|
||||
|
||||
//void addSystemVMTemplatesToHost(HostVO host, Map<String, TemplateProp> templateInfos);
|
||||
|
||||
@ -106,7 +106,6 @@ import com.cloud.vm.dao.UserVmDao;
|
||||
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
|
||||
|
||||
@Component
|
||||
@Local(value = { DownloadMonitor.class })
|
||||
public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor {
|
||||
@ -147,19 +146,19 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
VMTemplateDao _templateDao = null;
|
||||
@Inject
|
||||
private AgentManager _agentMgr;
|
||||
@Inject SecondaryStorageVmManager _secMgr;
|
||||
@Inject
|
||||
SecondaryStorageVmManager _secMgr;
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
@Inject
|
||||
UserVmManager _vmMgr;
|
||||
|
||||
@Inject TemplateManager templateMgr;
|
||||
|
||||
@Inject
|
||||
TemplateManager templateMgr;
|
||||
|
||||
@Inject
|
||||
private UsageEventDao _usageEventDao;
|
||||
|
||||
|
||||
@Inject
|
||||
private ClusterDao _clusterDao;
|
||||
@Inject
|
||||
@ -182,14 +181,14 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
|
||||
Timer _timer;
|
||||
|
||||
@Inject DataStoreManager storeMgr;
|
||||
@Inject
|
||||
DataStoreManager storeMgr;
|
||||
|
||||
final Map<TemplateDataStoreVO, DownloadListener> _listenerTemplateMap = new ConcurrentHashMap<TemplateDataStoreVO, DownloadListener>();
|
||||
final Map<VMTemplateHostVO, DownloadListener> _listenerMap = new ConcurrentHashMap<VMTemplateHostVO, DownloadListener>();
|
||||
final Map<VolumeHostVO, DownloadListener> _listenerVolumeMap = new ConcurrentHashMap<VolumeHostVO, DownloadListener>();
|
||||
final Map<VolumeDataStoreVO, DownloadListener> _listenerVolMap = new ConcurrentHashMap<VolumeDataStoreVO, DownloadListener>();
|
||||
|
||||
|
||||
public void send(Long hostId, Command cmd, Listener listener) throws AgentUnavailableException {
|
||||
_agentMgr.send(hostId, new Commands(cmd), listener);
|
||||
}
|
||||
@ -237,66 +236,75 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
}
|
||||
|
||||
public boolean isTemplateUpdateable(Long templateId, Long storeId) {
|
||||
List<TemplateDataStoreVO> downloadsInProgress =
|
||||
_vmTemplateStoreDao.listByTemplateStoreDownloadStatus(templateId, storeId, Status.DOWNLOAD_IN_PROGRESS, Status.DOWNLOADED );
|
||||
List<TemplateDataStoreVO> downloadsInProgress = _vmTemplateStoreDao.listByTemplateStoreDownloadStatus(templateId, storeId,
|
||||
Status.DOWNLOAD_IN_PROGRESS, Status.DOWNLOADED);
|
||||
return (downloadsInProgress.size() == 0);
|
||||
}
|
||||
|
||||
// TODO: consider using dataMotionStrategy later
|
||||
@Override
|
||||
public boolean copyTemplate(VMTemplateVO template, HostVO sourceServer, HostVO destServer) throws StorageUnavailableException{
|
||||
public boolean copyTemplate(VMTemplateVO template, DataStore sourceStore, DataStore destStore) throws StorageUnavailableException {
|
||||
|
||||
boolean downloadJobExists = false;
|
||||
VMTemplateHostVO destTmpltHost = null;
|
||||
VMTemplateHostVO srcTmpltHost = null;
|
||||
TemplateDataStoreVO destTmpltStore = null;
|
||||
TemplateDataStoreVO srcTmpltStore = null;
|
||||
|
||||
srcTmpltHost = _vmTemplateHostDao.findByHostTemplate(sourceServer.getId(), template.getId());
|
||||
if (srcTmpltHost == null) {
|
||||
throw new InvalidParameterValueException("Template " + template.getName() + " not associated with " + sourceServer.getName());
|
||||
srcTmpltStore = this._vmTemplateStoreDao.findByStoreTemplate(sourceStore.getId(), template.getId());
|
||||
if (srcTmpltStore == null) {
|
||||
throw new InvalidParameterValueException("Template " + template.getName() + " not associated with " + sourceStore.getName());
|
||||
}
|
||||
|
||||
String url = generateCopyUrl(sourceServer, srcTmpltHost);
|
||||
// generate a storage url on ssvm to copy from
|
||||
String url = generateCopyUrl(sourceStore, srcTmpltStore);
|
||||
if (url == null) {
|
||||
s_logger.warn("Unable to start/resume copy of template " + template.getUniqueName() + " to " + destServer.getName() + ", no secondary storage vm in running state in source zone");
|
||||
throw new CloudRuntimeException("No secondary VM in running state in zone " + sourceServer.getDataCenterId());
|
||||
s_logger.warn("Unable to start/resume copy of template " + template.getUniqueName() + " to " + destStore.getName()
|
||||
+ ", no secondary storage vm in running state in source zone");
|
||||
throw new CloudRuntimeException("No secondary VM in running state in zone " + sourceStore.getScope().getScopeId());
|
||||
}
|
||||
destTmpltHost = _vmTemplateHostDao.findByHostTemplate(destServer.getId(), template.getId());
|
||||
if (destTmpltHost == null) {
|
||||
destTmpltHost = new VMTemplateHostVO(destServer.getId(), template.getId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null, "jobid0000", null, url);
|
||||
destTmpltHost.setCopy(true);
|
||||
destTmpltHost.setPhysicalSize(srcTmpltHost.getPhysicalSize());
|
||||
_vmTemplateHostDao.persist(destTmpltHost);
|
||||
} else if ((destTmpltHost.getJobId() != null) && (destTmpltHost.getJobId().length() > 2)) {
|
||||
destTmpltStore = _vmTemplateStoreDao.findByStoreTemplate(destStore.getId(), template.getId());
|
||||
if (destTmpltStore == null) {
|
||||
destTmpltStore = new TemplateDataStoreVO(destStore.getId(), template.getId(), new Date(), 0,
|
||||
VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null, "jobid0000", null, url);
|
||||
destTmpltStore.setCopy(true);
|
||||
destTmpltStore.setPhysicalSize(srcTmpltStore.getPhysicalSize());
|
||||
_vmTemplateStoreDao.persist(destTmpltStore);
|
||||
} else if ((destTmpltStore.getJobId() != null) && (destTmpltStore.getJobId().length() > 2)) {
|
||||
downloadJobExists = true;
|
||||
}
|
||||
|
||||
Long maxTemplateSizeInBytes = getMaxTemplateSizeInBytes();
|
||||
if (srcTmpltHost.getSize() > maxTemplateSizeInBytes){
|
||||
throw new CloudRuntimeException("Cant copy the template as the template's size " +srcTmpltHost.getSize()+
|
||||
" is greater than max.template.iso.size " + maxTemplateSizeInBytes);
|
||||
if (srcTmpltStore.getSize() > maxTemplateSizeInBytes) {
|
||||
throw new CloudRuntimeException("Cant copy the template as the template's size " + srcTmpltStore.getSize()
|
||||
+ " is greater than max.template.iso.size " + maxTemplateSizeInBytes);
|
||||
}
|
||||
|
||||
if(destTmpltHost != null) {
|
||||
if (destTmpltStore != null) {
|
||||
start();
|
||||
String sourceChecksum = this.templateMgr.getChecksum(srcTmpltHost.getHostId(), srcTmpltHost.getInstallPath());
|
||||
DownloadCommand dcmd =
|
||||
new DownloadCommand(destServer.getStorageUrl(), url, template, TemplateConstants.DEFAULT_HTTP_AUTH_USER, _copyAuthPasswd, maxTemplateSizeInBytes);
|
||||
String sourceChecksum = this.templateMgr.getChecksum(sourceStore, srcTmpltStore.getInstallPath());
|
||||
DownloadCommand dcmd = new DownloadCommand(destStore.getTO(), destStore.getUri(), url, template,
|
||||
TemplateConstants.DEFAULT_HTTP_AUTH_USER, _copyAuthPasswd, maxTemplateSizeInBytes);
|
||||
dcmd.setProxy(getHttpProxy());
|
||||
if (downloadJobExists) {
|
||||
dcmd = new DownloadProgressCommand(dcmd, destTmpltHost.getJobId(), RequestType.GET_OR_RESTART);
|
||||
dcmd = new DownloadProgressCommand(dcmd, destTmpltStore.getJobId(), RequestType.GET_OR_RESTART);
|
||||
}
|
||||
dcmd.setChecksum(sourceChecksum); // We need to set the checksum as the source template might be a compressed url and have cksum for compressed image. Bug #10775
|
||||
HostVO ssAhost = _ssvmMgr.pickSsvmHost(destServer);
|
||||
dcmd.setChecksum(sourceChecksum); // We need to set the checksum as
|
||||
// the source template might be a
|
||||
// compressed url and have cksum
|
||||
// for compressed image. Bug
|
||||
// #10775
|
||||
HostVO ssAhost = _ssvmMgr.pickSsvmHost(destStore);
|
||||
if (ssAhost == null) {
|
||||
s_logger.warn("There is no secondary storage VM for secondary storage host " + destServer.getName());
|
||||
s_logger.warn("There is no secondary storage VM for secondary storage host " + destStore.getName());
|
||||
return false;
|
||||
}
|
||||
DownloadListener dl = new DownloadListener(ssAhost, destServer, template, _timer, _vmTemplateHostDao, destTmpltHost.getId(), this, dcmd, _templateDao, _resourceLimitMgr, _alertMgr, _accountMgr);
|
||||
DownloadListener dl = new DownloadListener(ssAhost, destStore, template, _timer, _vmTemplateStoreDao, destTmpltStore.getId(), this, dcmd,
|
||||
_templateDao, _resourceLimitMgr, _alertMgr, _accountMgr, null);
|
||||
if (downloadJobExists) {
|
||||
dl.setCurrState(destTmpltHost.getDownloadState());
|
||||
dl.setCurrState(destTmpltStore.getDownloadState());
|
||||
}
|
||||
DownloadListener old = null;
|
||||
synchronized (_listenerMap) {
|
||||
old = _listenerMap.put(destTmpltHost, dl);
|
||||
synchronized (_listenerTemplateMap) {
|
||||
old = _listenerTemplateMap.put(destTmpltStore, dl);
|
||||
}
|
||||
if (old != null) {
|
||||
old.abandon();
|
||||
@ -306,7 +314,7 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
send(ssAhost.getId(), dcmd, dl);
|
||||
return true;
|
||||
} catch (AgentUnavailableException e) {
|
||||
s_logger.warn("Unable to start /resume COPY of template " + template.getUniqueName() + " to " + destServer.getName(), e);
|
||||
s_logger.warn("Unable to start /resume COPY of template " + template.getUniqueName() + " to " + destStore.getName(), e);
|
||||
dl.setDisconnected();
|
||||
dl.scheduleStatusCheck(RequestType.GET_OR_RESTART);
|
||||
e.printStackTrace();
|
||||
@ -327,22 +335,26 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
return scheme + "://" + hostname + "/copy/SecStorage/" + dir + "/" + path;
|
||||
}
|
||||
|
||||
private String generateCopyUrl(HostVO sourceServer, VMTemplateHostVO srcTmpltHost) {
|
||||
List<SecondaryStorageVmVO> ssVms = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, sourceServer.getDataCenterId(), State.Running);
|
||||
private String generateCopyUrl(DataStore sourceServer, TemplateDataStoreVO srcTmpltStore) {
|
||||
List<SecondaryStorageVmVO> ssVms = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, sourceServer
|
||||
.getScope().getScopeId(), State.Running);
|
||||
if (ssVms.size() > 0) {
|
||||
SecondaryStorageVmVO ssVm = ssVms.get(0);
|
||||
if (ssVm.getPublicIpAddress() == null) {
|
||||
s_logger.warn("A running secondary storage vm has a null public ip?");
|
||||
return null;
|
||||
}
|
||||
return generateCopyUrl(ssVm.getPublicIpAddress(), sourceServer.getParent(), srcTmpltHost.getInstallPath());
|
||||
//TODO: how to handle parent field from hostVO in image_store? and how we can populate that column?
|
||||
// return generateCopyUrl(ssVm.getPublicIpAddress(), sourceServer.getParent(), srcTmpltStore.getInstallPath());
|
||||
return generateCopyUrl(ssVm.getPublicIpAddress(), null, srcTmpltStore.getInstallPath());
|
||||
}
|
||||
|
||||
VMTemplateVO tmplt = _templateDao.findById(srcTmpltHost.getTemplateId());
|
||||
VMTemplateVO tmplt = _templateDao.findById(srcTmpltStore.getTemplateId());
|
||||
HypervisorType hyperType = tmplt.getHypervisorType();
|
||||
/*No secondary storage vm yet*/
|
||||
if (hyperType != null && hyperType == HypervisorType.KVM) {
|
||||
return "file://" + sourceServer.getParent() + "/" + srcTmpltHost.getInstallPath();
|
||||
//return "file://" + sourceServer.getParent() + "/" + srcTmpltStore.getInstallPath();
|
||||
return "file://" + "/" + srcTmpltStore.getInstallPath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -353,11 +365,12 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
|
||||
vmTemplateStore = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
|
||||
if (vmTemplateStore == null) {
|
||||
// This method can be invoked other places, for example, handleTemplateSync, in that case, vmTemplateStore may be null
|
||||
vmTemplateStore = new TemplateDataStoreVO(store.getId(), template.getId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null, "jobid0000", null, template.getUrl());
|
||||
// This method can be invoked other places, for example,
|
||||
// handleTemplateSync, in that case, vmTemplateStore may be null
|
||||
vmTemplateStore = new TemplateDataStoreVO(store.getId(), template.getId(), new Date(), 0,
|
||||
VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null, "jobid0000", null, template.getUrl());
|
||||
_vmTemplateStoreDao.persist(vmTemplateStore);
|
||||
} else
|
||||
if ((vmTemplateStore.getJobId() != null) && (vmTemplateStore.getJobId().length() > 2)) {
|
||||
} else if ((vmTemplateStore.getJobId() != null) && (vmTemplateStore.getJobId().length() > 2)) {
|
||||
downloadJobExists = true;
|
||||
}
|
||||
|
||||
@ -365,8 +378,7 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
String secUrl = store.getUri();
|
||||
if (vmTemplateStore != null) {
|
||||
start();
|
||||
DownloadCommand dcmd =
|
||||
new DownloadCommand(store.getTO(), secUrl, template, maxTemplateSizeInBytes);
|
||||
DownloadCommand dcmd = new DownloadCommand(store.getTO(), secUrl, template, maxTemplateSizeInBytes);
|
||||
dcmd.setProxy(getHttpProxy());
|
||||
if (downloadJobExists) {
|
||||
dcmd = new DownloadProgressCommand(dcmd, vmTemplateStore.getJobId(), RequestType.GET_OR_RESTART);
|
||||
@ -379,10 +391,14 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
s_logger.warn("There is no secondary storage VM for downloading template to image store " + store.getName());
|
||||
return;
|
||||
}
|
||||
DownloadListener dl = new DownloadListener(ssAhost, store, template, _timer, _vmTemplateStoreDao, vmTemplateStore.getId(), this, dcmd, _templateDao, _resourceLimitMgr, _alertMgr, _accountMgr, callback);
|
||||
DownloadListener dl = new DownloadListener(ssAhost, store, template, _timer, _vmTemplateStoreDao, vmTemplateStore.getId(), this, dcmd,
|
||||
_templateDao, _resourceLimitMgr, _alertMgr, _accountMgr, callback);
|
||||
if (downloadJobExists) {
|
||||
// due to handling existing download job issues, we still keep downloadState in template_store_ref to avoid big change in DownloadListener to use
|
||||
// new ObjectInDataStore.State transition. TODO: fix this later to be able to remove downloadState from template_store_ref.
|
||||
// due to handling existing download job issues, we still keep
|
||||
// downloadState in template_store_ref to avoid big change in
|
||||
// DownloadListener to use
|
||||
// new ObjectInDataStore.State transition. TODO: fix this later
|
||||
// to be able to remove downloadState from template_store_ref.
|
||||
dl.setCurrState(vmTemplateStore.getDownloadState());
|
||||
}
|
||||
DownloadListener old = null;
|
||||
@ -403,8 +419,6 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void downloadTemplateToStorage(VMTemplateVO template, DataStore store, AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
long templateId = template.getId();
|
||||
@ -415,22 +429,21 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void downloadVolumeToStorage(VolumeVO volume, DataStore store, String url, String checkSum, ImageFormat format, AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
public void downloadVolumeToStorage(VolumeVO volume, DataStore store, String url, String checkSum, ImageFormat format,
|
||||
AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
boolean downloadJobExists = false;
|
||||
VolumeDataStoreVO volumeHost = null;
|
||||
|
||||
volumeHost = _volumeStoreDao.findByStoreVolume(store.getId(), volume.getId());
|
||||
if (volumeHost == null) {
|
||||
volumeHost = new VolumeDataStoreVO(store.getId(), volume.getId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null,
|
||||
"jobid0000", null, url, checkSum, format);
|
||||
volumeHost = new VolumeDataStoreVO(store.getId(), volume.getId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED,
|
||||
null, null, "jobid0000", null, url, checkSum, format);
|
||||
_volumeStoreDao.persist(volumeHost);
|
||||
} else if ((volumeHost.getJobId() != null) && (volumeHost.getJobId().length() > 2)) {
|
||||
downloadJobExists = true;
|
||||
}
|
||||
|
||||
|
||||
Long maxVolumeSizeInBytes = getMaxVolumeSizeInBytes();
|
||||
String secUrl = store.getUri();
|
||||
if (volumeHost != null) {
|
||||
@ -447,8 +460,8 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
s_logger.warn("There is no secondary storage VM for image store " + store.getName());
|
||||
return;
|
||||
}
|
||||
DownloadListener dl = new DownloadListener(ssAhost, store, volume, _timer, _volumeStoreDao, volumeHost.getId(),
|
||||
this, dcmd, _volumeDao, _storageMgr, _resourceLimitMgr, _alertMgr, _accountMgr, callback);
|
||||
DownloadListener dl = new DownloadListener(ssAhost, store, volume, _timer, _volumeStoreDao, volumeHost.getId(), this, dcmd, _volumeDao,
|
||||
_storageMgr, _resourceLimitMgr, _alertMgr, _accountMgr, callback);
|
||||
|
||||
if (downloadJobExists) {
|
||||
dl.setCurrState(volumeHost.getDownloadState());
|
||||
@ -471,7 +484,6 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DB
|
||||
public void handleDownloadEvent(HostVO host, VMTemplateVO template, Status dnldStatus) {
|
||||
if ((dnldStatus == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) || (dnldStatus == Status.ABANDONED)) {
|
||||
@ -492,8 +504,7 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
size = vmTemplateHost.getPhysicalSize();
|
||||
template.setSize(size);
|
||||
this._templateDao.update(template.getId(), template);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
s_logger.warn("Failed to get size for template" + template.getName());
|
||||
}
|
||||
String eventType = EventTypes.EVENT_TEMPLATE_CREATE;
|
||||
@ -501,9 +512,8 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
eventType = EventTypes.EVENT_ISO_CREATE;
|
||||
}
|
||||
if (template.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
|
||||
UsageEventUtils.publishUsageEvent(eventType, template.getAccountId(), host.getDataCenterId(),
|
||||
template.getId(), template.getName(), null, template.getSourceTemplateId(), size,
|
||||
template.getClass().getName(), template.getUuid());
|
||||
UsageEventUtils.publishUsageEvent(eventType, template.getAccountId(), host.getDataCenterId(), template.getId(), template.getName(),
|
||||
null, template.getSourceTemplateId(), size, template.getClass().getName(), template.getUuid());
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
@ -531,27 +541,23 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
size = volumeHost.getPhysicalSize();
|
||||
volume.setSize(size);
|
||||
this._volumeDao.update(volume.getId(), volume);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
s_logger.warn("Failed to get size for volume" + volume.getName());
|
||||
}
|
||||
String eventType = EventTypes.EVENT_VOLUME_UPLOAD;
|
||||
if (volume.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
|
||||
UsageEventUtils.publishUsageEvent(eventType, volume.getAccountId(), host.getDataCenterId(),
|
||||
volume.getId(), volume.getName(), null, 0l, size, volume.getClass().getName(), volume.getUuid());
|
||||
UsageEventUtils.publishUsageEvent(eventType, volume.getAccountId(), host.getDataCenterId(), volume.getId(), volume.getName(), null,
|
||||
0l, size, volume.getClass().getName(), volume.getUuid());
|
||||
}
|
||||
} else if (dnldStatus == Status.DOWNLOAD_ERROR || dnldStatus == Status.ABANDONED || dnldStatus == Status.UNKNOWN) {
|
||||
// Decrement the volume and secondary storage space count
|
||||
_resourceLimitMgr.decrementResourceCount(volume.getAccountId(),
|
||||
com.cloud.configuration.Resource.ResourceType.volume);
|
||||
_resourceLimitMgr.decrementResourceCount(volume.getAccountId(), com.cloud.configuration.Resource.ResourceType.volume);
|
||||
_resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(),
|
||||
com.cloud.configuration.Resource.ResourceType.secondary_storage.getOrdinal());
|
||||
}
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void addSystemVMTemplatesToHost(HostVO host, Map<String, TemplateProp> templateInfos){
|
||||
@ -576,12 +582,10 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void cancelAllDownloads(Long templateId) {
|
||||
List<VMTemplateHostVO> downloadsInProgress =
|
||||
_vmTemplateHostDao.listByTemplateStates(templateId, VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS, VMTemplateHostVO.Status.NOT_DOWNLOADED);
|
||||
List<VMTemplateHostVO> downloadsInProgress = _vmTemplateHostDao.listByTemplateStates(templateId,
|
||||
VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS, VMTemplateHostVO.Status.NOT_DOWNLOADED);
|
||||
if (downloadsInProgress.size() > 0) {
|
||||
for (VMTemplateHostVO vmthvo : downloadsInProgress) {
|
||||
DownloadListener dl = null;
|
||||
@ -645,6 +649,4 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -55,15 +55,14 @@ public interface TemplateManager extends TemplateApiService{
|
||||
* Copies a template from its current secondary storage server to the secondary storage server in the specified zone.
|
||||
*
|
||||
* @param template
|
||||
* @param srcSecHost
|
||||
* @param srcZone
|
||||
* @param srcSecStore
|
||||
* @param destZone
|
||||
* @return true if success
|
||||
* @throws InternalErrorException
|
||||
* @throws StorageUnavailableException
|
||||
* @throws ResourceAllocationException
|
||||
*/
|
||||
boolean copy(long userId, VMTemplateVO template, HostVO srcSecHost, DataCenterVO srcZone, DataCenterVO dstZone) throws StorageUnavailableException, ResourceAllocationException;
|
||||
boolean copy(long userId, VMTemplateVO template, DataStore srcSecStore, DataCenterVO dstZone) throws StorageUnavailableException, ResourceAllocationException;
|
||||
|
||||
/**
|
||||
* Deletes a template from secondary storage servers
|
||||
@ -107,6 +106,8 @@ public interface TemplateManager extends TemplateApiService{
|
||||
|
||||
HostVO getSecondaryStorageHost(long zoneId, long tmpltId);
|
||||
|
||||
DataStore getImageStore(long zoneId, long tmpltId);
|
||||
|
||||
VMTemplateHostVO getTemplateHostRef(long zoneId, long tmpltId,
|
||||
boolean readyOnly);
|
||||
|
||||
@ -120,6 +121,8 @@ public interface TemplateManager extends TemplateApiService{
|
||||
|
||||
String getChecksum(Long hostId, String templatePath);
|
||||
|
||||
String getChecksum(DataStore store, String templatePath);
|
||||
|
||||
List<DataStore> getImageStoreByTemplate(long templateId, Long zoneId);
|
||||
|
||||
}
|
||||
|
||||
@ -125,6 +125,7 @@ import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.storage.StoragePoolHostVO;
|
||||
@ -838,6 +839,20 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChecksum(DataStore store, String templatePath) {
|
||||
|
||||
String secUrl = store.getUri();
|
||||
Answer answer;
|
||||
answer = _agentMgr.sendToSecStorage(store, new ComputeChecksumCommand(
|
||||
secUrl, templatePath));
|
||||
if (answer != null && answer.getResult()) {
|
||||
return answer.getDetails();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public VMTemplateHostVO prepareISOForCreate(VMTemplateVO template, StoragePool pool) {
|
||||
@ -897,18 +912,20 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public boolean copy(long userId, VMTemplateVO template, HostVO srcSecHost, DataCenterVO srcZone, DataCenterVO dstZone) throws StorageUnavailableException, ResourceAllocationException {
|
||||
List<HostVO> dstSecHosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(dstZone.getId());
|
||||
public boolean copy(long userId, VMTemplateVO template, DataStore srcSecStore, DataCenterVO dstZone) throws StorageUnavailableException, ResourceAllocationException {
|
||||
long tmpltId = template.getId();
|
||||
long dstZoneId = dstZone.getId();
|
||||
if (dstSecHosts == null || dstSecHosts.isEmpty() ) {
|
||||
throw new StorageUnavailableException("Destination zone is not ready", DataCenter.class, dstZone.getId());
|
||||
// find all eligible image stores for the destination zone
|
||||
List<DataStore> dstSecStores = this.dataStoreMgr.getImageStoresByScope(new ZoneScope(dstZoneId));
|
||||
if (dstSecStores == null || dstSecStores.isEmpty() ) {
|
||||
throw new StorageUnavailableException("Destination zone is not ready, no image store associated", DataCenter.class, dstZone.getId());
|
||||
}
|
||||
AccountVO account = _accountDao.findById(template.getAccountId());
|
||||
VMTemplateHostVO srcTmpltHost = _tmpltHostDao.findByHostTemplate(srcSecHost.getId(), tmpltId);
|
||||
// find the size of the template to be copied
|
||||
TemplateDataStoreVO srcTmpltStore = this._tmplStoreDao.findByStoreTemplate(srcSecStore.getId(), tmpltId);
|
||||
|
||||
_resourceLimitMgr.checkResourceLimit(account, ResourceType.template);
|
||||
_resourceLimitMgr.checkResourceLimit(account, ResourceType.secondary_storage, new Long(srcTmpltHost.getSize()));
|
||||
_resourceLimitMgr.checkResourceLimit(account, ResourceType.secondary_storage, new Long(srcTmpltStore.getSize()));
|
||||
|
||||
// Event details
|
||||
String copyEventType;
|
||||
@ -924,30 +941,31 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
for ( HostVO dstSecHost : dstSecHosts ) {
|
||||
VMTemplateHostVO dstTmpltHost = null;
|
||||
//Copy will just find one eligible image store for the destination zone and copy template there, not propagate to all image stores
|
||||
// for that zone
|
||||
for ( DataStore dstSecStore : dstSecStores ) {
|
||||
TemplateDataStoreVO dstTmpltStore = null;
|
||||
try {
|
||||
dstTmpltHost = _tmpltHostDao.findByHostTemplate(dstSecHost.getId(), tmpltId, true);
|
||||
if (dstTmpltHost != null) {
|
||||
dstTmpltHost = _tmpltHostDao.lockRow(dstTmpltHost.getId(), true);
|
||||
if (dstTmpltHost != null && dstTmpltHost.getDownloadState() == Status.DOWNLOADED) {
|
||||
if (dstTmpltHost.getDestroyed() == false) {
|
||||
return true;
|
||||
dstTmpltStore = this._tmplStoreDao.findByStoreTemplate(dstSecStore.getId(), tmpltId, true);
|
||||
if (dstTmpltStore != null) {
|
||||
dstTmpltStore = _tmplStoreDao.lockRow(dstTmpltStore.getId(), true);
|
||||
if (dstTmpltStore != null && dstTmpltStore.getDownloadState() == Status.DOWNLOADED) {
|
||||
if (dstTmpltStore.getDestroyed() == false) {
|
||||
return true; // already downloaded on this image store
|
||||
} else {
|
||||
dstTmpltHost.setDestroyed(false);
|
||||
_tmpltHostDao.update(dstTmpltHost.getId(), dstTmpltHost);
|
||||
|
||||
dstTmpltStore.setDestroyed(false);
|
||||
_tmplStoreDao.update(dstTmpltStore.getId(), dstTmpltStore);
|
||||
return true;
|
||||
}
|
||||
} else if (dstTmpltHost != null && dstTmpltHost.getDownloadState() == Status.DOWNLOAD_ERROR){
|
||||
if (dstTmpltHost.getDestroyed() == true) {
|
||||
dstTmpltHost.setDestroyed(false);
|
||||
dstTmpltHost.setDownloadState(Status.NOT_DOWNLOADED);
|
||||
dstTmpltHost.setDownloadPercent(0);
|
||||
dstTmpltHost.setCopy(true);
|
||||
dstTmpltHost.setErrorString("");
|
||||
dstTmpltHost.setJobId(null);
|
||||
_tmpltHostDao.update(dstTmpltHost.getId(), dstTmpltHost);
|
||||
} else if (dstTmpltStore != null && dstTmpltStore.getDownloadState() == Status.DOWNLOAD_ERROR){
|
||||
if (dstTmpltStore.getDestroyed() == true) {
|
||||
dstTmpltStore.setDestroyed(false);
|
||||
dstTmpltStore.setDownloadState(Status.NOT_DOWNLOADED);
|
||||
dstTmpltStore.setDownloadPercent(0);
|
||||
dstTmpltStore.setCopy(true);
|
||||
dstTmpltStore.setErrorString("");
|
||||
dstTmpltStore.setJobId(null);
|
||||
_tmplStoreDao.update(dstTmpltStore.getId(), dstTmpltStore);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -955,11 +973,11 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
if(_downloadMonitor.copyTemplate(template, srcSecHost, dstSecHost) ) {
|
||||
if(_downloadMonitor.copyTemplate(template, srcSecStore, dstSecStore) ) {
|
||||
_tmpltDao.addTemplateToZone(template, dstZoneId);
|
||||
|
||||
if(account.getId() != Account.ACCOUNT_ID_SYSTEM){
|
||||
UsageEventUtils.publishUsageEvent(copyEventType, account.getId(), dstZoneId, tmpltId, null, null, null, srcTmpltHost.getSize(),
|
||||
UsageEventUtils.publishUsageEvent(copyEventType, account.getId(), dstZoneId, tmpltId, null, null, null, srcTmpltStore.getSize(),
|
||||
template.getClass().getName(), template.getUuid());
|
||||
}
|
||||
return true;
|
||||
@ -969,6 +987,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_COPY, eventDescription = "copying template", async = true)
|
||||
public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException {
|
||||
@ -978,6 +998,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
Long destZoneId = cmd.getDestinationZoneId();
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
/*
|
||||
if (_swiftMgr.isSwiftEnabled()) {
|
||||
throw new CloudRuntimeException("copytemplate API is disabled in Swift setup, templates in Swift can be accessed by all Zones");
|
||||
}
|
||||
@ -986,6 +1007,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
throw new CloudRuntimeException(
|
||||
"copytemplate API is disabled in S3 setup -- S3 templates are accessible in all zones.");
|
||||
}
|
||||
*/
|
||||
|
||||
//Verify parameters
|
||||
if (sourceZoneId == destZoneId) {
|
||||
@ -1007,20 +1029,24 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
throw new InvalidParameterValueException("Unable to find template with id");
|
||||
}
|
||||
|
||||
HostVO dstSecHost = getSecondaryStorageHost(destZoneId, templateId);
|
||||
if ( dstSecHost != null ) {
|
||||
s_logger.debug("There is template " + templateId + " in secondary storage " + dstSecHost.getId() + " in zone " + destZoneId + " , don't need to copy");
|
||||
DataStore dstSecStore = getImageStore(destZoneId, templateId);
|
||||
if ( dstSecStore != null ) {
|
||||
s_logger.debug("There is template " + templateId + " in secondary storage " + dstSecStore.getName() + " in zone " + destZoneId + " , don't need to copy");
|
||||
return template;
|
||||
}
|
||||
|
||||
HostVO srcSecHost = getSecondaryStorageHost(sourceZoneId, templateId);
|
||||
if ( srcSecHost == null ) {
|
||||
DataStore srcSecStore = getImageStore(sourceZoneId, templateId);
|
||||
if ( srcSecStore == null ) {
|
||||
throw new InvalidParameterValueException("There is no template " + templateId + " in zone " + sourceZoneId );
|
||||
}
|
||||
if ( srcSecStore.getScope().getScopeType() == ScopeType.REGION){
|
||||
s_logger.debug("Template " + templateId + " is in region-wide secondary storage " + dstSecStore.getName() + " , don't need to copy");
|
||||
return template;
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, template);
|
||||
|
||||
boolean success = copy(userId, template, srcSecHost, sourceZone, dstZone);
|
||||
boolean success = copy(userId, template, srcSecStore, dstZone);
|
||||
|
||||
if (success){
|
||||
return template;
|
||||
@ -2073,6 +2099,23 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
return secondaryStorageHost.getStorageUrl();
|
||||
}
|
||||
|
||||
// get the image store where a template in a given zone is downloaded to, just pick one is enough.
|
||||
@Override
|
||||
public DataStore getImageStore(long zoneId, long tmpltId) {
|
||||
List<DataStore> stores = this.dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
|
||||
if (stores == null || stores.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
for (DataStore host : stores) {
|
||||
List<TemplateDataStoreVO> tmpltStore = this._tmplStoreDao.listByTemplateStoreDownloadStatus(
|
||||
tmpltId, host.getId(), VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
if ( tmpltStore != null && tmpltStore.size() > 0 ){
|
||||
return host;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostVO getSecondaryStorageHost(long zoneId, long tmpltId) {
|
||||
List<HostVO> hosts = _ssvmMgr
|
||||
|
||||
@ -21,6 +21,7 @@ import java.util.Map;
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
@ -140,6 +141,19 @@ public class MockAgentManagerImpl extends ManagerBase implements AgentManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendToSecStorage(DataStore ssStore, Command cmd, Listener listener) throws AgentUnavailableException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer sendToSecStorage(DataStore ssStore, Command cmd) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user