use of com.cloud.engine.subsystem.api.storage.ZoneScope in project cosmic by MissionCriticalCloud.
the class SecondaryStorageManagerImpl method isZoneReady.
public boolean isZoneReady(final Map<Long, ZoneHostInfo> zoneHostInfoMap, final long dataCenterId) {
final ZoneHostInfo zoneHostInfo = zoneHostInfoMap.get(dataCenterId);
if (zoneHostInfo != null && (zoneHostInfo.getFlags() & RunningHostInfoAgregator.ZoneHostInfo.ROUTING_HOST_MASK) != 0) {
final VMTemplateVO template = _templateDao.findSystemVMReadyTemplate(dataCenterId, HypervisorType.Any);
if (template == null) {
logger.debug("System vm template is not ready at data center " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
return false;
}
final List<DataStore> stores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(dataCenterId));
if (stores.size() < 1) {
logger.debug("No image store added in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
return false;
}
final DataStore store = templateMgr.getImageStore(dataCenterId, template.getId());
if (store == null) {
logger.debug("No secondary storage available in zone " + dataCenterId + ", wait until it is ready to launch secondary storage vm");
return false;
}
boolean useLocalStorage = false;
final Boolean useLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId);
if (useLocal != null) {
useLocalStorage = useLocal.booleanValue();
}
final List<Pair<Long, Integer>> l = _storagePoolHostDao.getDatacenterStoragePoolHostInfo(dataCenterId, !useLocalStorage);
if (l != null && l.size() > 0 && l.get(0).second().intValue() > 0) {
return true;
} else {
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 com.cloud.engine.subsystem.api.storage.ZoneScope in project cosmic by MissionCriticalCloud.
the class SecondaryStorageManagerImpl method scanPool.
@Override
public Pair<AfterScanAction, Object> scanPool(final Long pool) {
logger.info("Scanning secondary storage pool {}", pool.toString());
final long dataCenterId = pool.longValue();
final List<SecondaryStorageVmVO> ssVms = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, Running, Migrating, Starting, Stopped, Stopping);
final int vmSize = (ssVms == null) ? 0 : ssVms.size();
final List<DataStore> ssStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(dataCenterId));
final int storeSize = (ssStores == null) ? 0 : ssStores.size();
if (storeSize > vmSize) {
final int requiredVMs = storeSize - vmSize;
logger.info("Found less ({}) secondary storage VMs than image stores ({}) in dcId={}, starting {} new VMs", vmSize, storeSize, dataCenterId, requiredVMs);
return new Pair<>(AfterScanAction.expand(requiredVMs), SecondaryStorageVm.Role.templateProcessor);
} else {
final String standByCapacity = _configDao.getValue(Config.SecStorageCapacityStandby.toString());
final String maxPerVm = _configDao.getValue(Config.SecStorageSessionMax.toString());
final int requiredCapacity = new SecondaryStorageCapacityCalculator().calculateRequiredCapacity(Integer.parseInt(standByCapacity), Integer.parseInt(maxPerVm));
if (requiredCapacity > vmSize) {
final int requiredVMs = requiredCapacity - vmSize;
logger.info("Found less ({}) secondary storage VMs than required ({}) in dcId={}, starting {} new VMs", vmSize, requiredCapacity, dataCenterId, requiredVMs);
return new Pair<>(AfterScanAction.expand(requiredVMs), SecondaryStorageVm.Role.templateProcessor);
}
}
return new Pair<>(AfterScanAction.nop(), SecondaryStorageVm.Role.templateProcessor);
}
use of com.cloud.engine.subsystem.api.storage.ZoneScope in project cosmic by MissionCriticalCloud.
the class TemplateManagerImpl method getImageStoreByTemplate.
// find image store where this template is located
@Override
public List<DataStore> getImageStoreByTemplate(final long templateId, final Long zoneId) {
// find all eligible image stores for this zone scope
final List<DataStore> imageStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
if (imageStores == null || imageStores.size() == 0) {
return null;
}
final List<DataStore> stores = new ArrayList<>();
for (final DataStore store : imageStores) {
// check if the template is stored there
final List<TemplateDataStoreVO> storeTmpl = _tmplStoreDao.listByTemplateStore(templateId, store.getId());
if (storeTmpl != null && storeTmpl.size() > 0) {
stores.add(store);
}
}
return stores;
}
use of com.cloud.engine.subsystem.api.storage.ZoneScope in project cosmic by MissionCriticalCloud.
the class TemplateManagerImpl method copy.
@Override
@DB
public boolean copy(final long userId, final VMTemplateVO template, final DataStore srcSecStore, final DataCenterVO dstZone) throws StorageUnavailableException, ResourceAllocationException {
final long tmpltId = template.getId();
final long dstZoneId = dstZone.getId();
// find all eligible image stores for the destination zone
final 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());
}
final AccountVO account = _accountDao.findById(template.getAccountId());
// find the size of the template to be copied
final 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
final String copyEventType;
if (template.getFormat().equals(ImageFormat.ISO)) {
copyEventType = EventTypes.EVENT_ISO_COPY;
} else {
copyEventType = EventTypes.EVENT_TEMPLATE_COPY;
}
final TemplateInfo srcTemplate = _tmplFactory.getTemplate(template.getId(), srcSecStore);
// for that zone
for (final DataStore dstSecStore : dstSecStores) {
final 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());
}
final AsyncCallFuture<TemplateApiResult> future = _tmpltSvr.copyTemplate(srcTemplate, dstSecStore);
try {
final 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);
return true;
} catch (final Exception ex) {
s_logger.debug("failed to copy template to image store:" + dstSecStore.getName() + " ,will try next one");
}
}
return false;
}
use of com.cloud.engine.subsystem.api.storage.ZoneScope in project cosmic by MissionCriticalCloud.
the class XenServerGuru method getCommandHostDelegation.
@Override
public Pair<Boolean, Long> getCommandHostDelegation(final long hostId, final Command cmd) {
LOGGER.debug("getCommandHostDelegation: " + cmd.getClass());
if (cmd instanceof StorageSubSystemCommand) {
final StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
c.setExecuteInSequence(true);
}
if (cmd instanceof CopyCommand) {
final CopyCommand cpyCommand = (CopyCommand) cmd;
final DataTO srcData = cpyCommand.getSrcTO();
final DataTO destData = cpyCommand.getDestTO();
if (srcData.getHypervisorType() == HypervisorType.XenServer && srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
final DataStoreTO srcStore = srcData.getDataStore();
final DataStoreTO destStore = destData.getDataStore();
if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
HostVO host = hostDao.findById(hostId);
final EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId()));
host = hostDao.findById(ep.getId());
hostDao.loadDetails(host);
final String hypervisorVersion = host.getHypervisorVersion();
final String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XS620HotFix);
if (hypervisorVersion != null && !hypervisorVersion.equalsIgnoreCase("6.1.0")) {
if (!(hypervisorVersion.equalsIgnoreCase("6.2.0") && !(snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)))) {
return new Pair<>(Boolean.TRUE, new Long(ep.getId()));
}
}
}
}
}
return new Pair<>(Boolean.FALSE, new Long(hostId));
}
Aggregations