use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.
the class TemplateManagerImpl method copy.
@Override
@DB
public boolean copy(long userId, VMTemplateVO template, DataStore srcSecStore, DataCenterVO dstZone) throws StorageUnavailableException, ResourceAllocationException {
long tmpltId = template.getId();
long dstZoneId = dstZone.getId();
// find all eligible image stores for the destination zone
List<DataStore> dstSecStores = _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());
// find the size of the template to be copied
TemplateDataStoreVO srcTmpltStore = _tmplStoreDao.findByStoreTemplate(srcSecStore.getId(), tmpltId);
_resourceLimitMgr.checkResourceLimit(account, ResourceType.template);
_resourceLimitMgr.checkResourceLimit(account, ResourceType.secondary_storage, new Long(srcTmpltStore.getSize()).longValue());
// Event details
String copyEventType;
if (template.getFormat().equals(ImageFormat.ISO)) {
copyEventType = EventTypes.EVENT_ISO_COPY;
} else {
copyEventType = EventTypes.EVENT_TEMPLATE_COPY;
}
TemplateInfo srcTemplate = _tmplFactory.getTemplate(template.getId(), srcSecStore);
// for that zone
for (DataStore dstSecStore : dstSecStores) {
TemplateDataStoreVO dstTmpltStore = _tmplStoreDao.findByStoreTemplate(dstSecStore.getId(), tmpltId);
if (dstTmpltStore != null && dstTmpltStore.getDownloadState() == Status.DOWNLOADED) {
// already downloaded on this image store
return true;
}
if (dstTmpltStore != null && dstTmpltStore.getDownloadState() != Status.DOWNLOAD_IN_PROGRESS) {
_tmplStoreDao.removeByTemplateStore(tmpltId, dstSecStore.getId());
}
AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.copyTemplate(srcTemplate, dstSecStore);
try {
TemplateApiResult result = future.get();
if (result.isFailed()) {
s_logger.debug("copy template failed for image store " + dstSecStore.getName() + ":" + result.getResult());
// try next image store
continue;
}
_tmpltDao.addTemplateToZone(template, dstZoneId);
if (account.getId() != Account.ACCOUNT_ID_SYSTEM) {
UsageEventUtils.publishUsageEvent(copyEventType, account.getId(), dstZoneId, tmpltId, null, null, null, srcTmpltStore.getPhysicalSize(), srcTmpltStore.getSize(), template.getClass().getName(), template.getUuid());
}
return true;
} catch (Exception ex) {
s_logger.debug("failed to copy template to image store:" + dstSecStore.getName() + " ,will try next one");
}
}
return false;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.
the class AncientDataMotionStrategy method getZoneScope.
private Scope getZoneScope(Scope destScope) {
ZoneScope zoneScope = null;
if (destScope instanceof ClusterScope) {
ClusterScope clusterScope = (ClusterScope) destScope;
zoneScope = new ZoneScope(clusterScope.getZoneId());
} else if (destScope instanceof HostScope) {
HostScope hostScope = (HostScope) destScope;
zoneScope = new ZoneScope(hostScope.getZoneId());
} else {
zoneScope = (ZoneScope) destScope;
}
return zoneScope;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.
the class SecondaryStorageManagerImpl method isZoneReady.
public boolean isZoneReady(Map<Long, ZoneHostInfo> zoneHostInfoMap, long dataCenterId) {
ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId);
if (zoneHostInfo != null && (zoneHostInfo.getFlags() & RunningHostInfoAgregator.ZoneHostInfo.ROUTING_HOST_MASK) != 0) {
VMTemplateVO template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
if (template == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("System vm template is not ready at data center " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
}
return false;
}
List<DataStore> stores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(dataCenterId));
if (stores.size() < 1) {
s_logger.debug("No image store added in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
return false;
}
DataStore store = templateMgr.getImageStore(dataCenterId, template.getId());
if (store == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No secondary storage available in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
}
return false;
}
boolean useLocalStorage = false;
Boolean useLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId);
if (useLocal != null) {
useLocalStorage = useLocal.booleanValue();
}
List<Pair<Long, Integer>> l = _storagePoolHostDao.getDatacenterStoragePoolHostInfo(dataCenterId, !useLocalStorage);
if (l != null && l.size() > 0 && l.get(0).second().intValue() > 0) {
return true;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Primary storage is not ready, wait until it is ready to launch secondary storage vm. dcId: " + dataCenterId + ", " + ConfigurationManagerImpl.SystemVMUseLocalStorage.key() + ": " + useLocalStorage + ". " + "If you want to use local storage to start SSVM, need to set " + ConfigurationManagerImpl.SystemVMUseLocalStorage.key() + " to true");
}
}
}
return false;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.
the class S3TemplateTest method copyTemplateToCache.
@Test(priority = 2)
public void copyTemplateToCache() {
TemplateInfo template = templateFactory.getTemplate(templateId, DataStoreRole.Image);
DataObject cacheObj = this.cacheMgr.createCacheObject(template, new ZoneScope(dcId));
assertNotNull(cacheObj, "failed to create cache object");
}
use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.
the class PrimaryDataStoreImpl method getScope.
@Override
public Scope getScope() {
StoragePoolVO vo = dataStoreDao.findById(pdsv.getId());
if (vo.getScope() == ScopeType.CLUSTER) {
return new ClusterScope(vo.getClusterId(), vo.getPodId(), vo.getDataCenterId());
} else if (vo.getScope() == ScopeType.ZONE) {
return new ZoneScope(vo.getDataCenterId());
} else if (vo.getScope() == ScopeType.HOST) {
List<StoragePoolHostVO> poolHosts = poolHostDao.listByPoolId(vo.getId());
if (poolHosts.size() > 0) {
return new HostScope(poolHosts.get(0).getHostId(), vo.getClusterId(), vo.getDataCenterId());
}
s_logger.debug("can't find a local storage in pool host table: " + vo.getId());
}
return null;
}
Aggregations