use of com.cloud.engine.subsystem.api.storage.ZoneScope in project cosmic by MissionCriticalCloud.
the class TemplateDataStoreDaoImpl method findByTemplateZoneReady.
@Override
public TemplateDataStoreVO findByTemplateZoneReady(final long templateId, final Long zoneId) {
List<DataStore> imgStores = null;
imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
if (imgStores != null) {
Collections.shuffle(imgStores);
for (final DataStore store : imgStores) {
final List<TemplateDataStoreVO> sRes = listByTemplateStoreStatus(templateId, store.getId(), State.Ready);
if (sRes != null && sRes.size() > 0) {
return sRes.get(0);
}
}
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.ZoneScope in project cosmic by MissionCriticalCloud.
the class TemplateServiceImpl method handleSysTemplateDownload.
@Override
public void handleSysTemplateDownload(final HypervisorType hostHyper, final Long dcId) {
final Set<VMTemplateVO> toBeDownloaded = new HashSet<>();
final List<DataStore> stores = _storeMgr.getImageStoresByScope(new ZoneScope(dcId));
if (stores == null || stores.isEmpty()) {
return;
}
/* Download all the templates in zone with the same hypervisortype */
for (final DataStore store : stores) {
final List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
final List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
for (final VMTemplateVO rtngTmplt : rtngTmplts) {
if (rtngTmplt.getHypervisorType() == hostHyper) {
toBeDownloaded.add(rtngTmplt);
}
}
for (final VMTemplateVO builtinTmplt : defaultBuiltin) {
if (builtinTmplt.getHypervisorType() == hostHyper) {
toBeDownloaded.add(builtinTmplt);
}
}
for (final VMTemplateVO template : toBeDownloaded) {
final TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
if (tmpltHost == null || tmpltHost.getState() != ObjectInDataStoreStateMachine.State.Ready) {
associateTemplateToZone(template.getId(), dcId);
s_logger.info("Downloading builtin template " + template.getUniqueName() + " to data center: " + dcId);
final TemplateInfo tmplt = _templateFactory.getTemplate(template.getId(), DataStoreRole.Image);
createTemplateAsync(tmplt, store, null);
}
}
}
}
use of com.cloud.engine.subsystem.api.storage.ZoneScope in project cosmic by MissionCriticalCloud.
the class StorageManagerImpl method createPool.
@Override
public PrimaryDataStoreInfo createPool(final CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException, ResourceUnavailableException {
final String providerName = cmd.getStorageProviderName();
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
if (storeProvider == null) {
storeProvider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
if (storeProvider == null) {
throw new InvalidParameterValueException("can't find storage provider: " + providerName);
}
}
Long clusterId = cmd.getClusterId();
Long podId = cmd.getPodId();
final Long zoneId = cmd.getZoneId();
ScopeType scopeType = ScopeType.CLUSTER;
final String scope = cmd.getScope();
if (scope != null) {
try {
scopeType = Enum.valueOf(ScopeType.class, scope.toUpperCase());
} catch (final Exception e) {
throw new InvalidParameterValueException("invalid scope for pool " + scope);
}
}
if (scopeType == ScopeType.CLUSTER && clusterId == null) {
throw new InvalidParameterValueException("cluster id can't be null, if scope is cluster");
} else if (scopeType == ScopeType.ZONE && zoneId == null) {
throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
}
HypervisorType hypervisorType = HypervisorType.KVM;
if (scopeType == ScopeType.ZONE) {
// ignore passed clusterId and podId
clusterId = null;
podId = null;
final String hypervisor = cmd.getHypervisor();
if (hypervisor != null) {
try {
hypervisorType = HypervisorType.getType(hypervisor);
} catch (final Exception e) {
throw new InvalidParameterValueException("invalid hypervisor type " + hypervisor);
}
} else {
throw new InvalidParameterValueException("Missing parameter hypervisor. Hypervisor type is required to create zone wide primary storage.");
}
if (hypervisorType != HypervisorType.KVM && hypervisorType != HypervisorType.Any) {
throw new InvalidParameterValueException("zone wide storage pool is not supported for hypervisor type " + hypervisor);
}
}
final Map<String, String> details = extractApiParamAsMap(cmd.getDetails());
final DataCenterVO zone = _dcDao.findById(cmd.getZoneId());
if (zone == null) {
throw new InvalidParameterValueException("unable to find zone by id " + zoneId);
}
// Check if zone is disabled
final Account account = CallContext.current().getCallingAccount();
if (AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
}
final Map<String, Object> params = new HashMap<>();
params.put("zoneId", zone.getId());
params.put("clusterId", clusterId);
params.put("podId", podId);
params.put("url", cmd.getUrl());
params.put("tags", cmd.getTags());
params.put("name", cmd.getStoragePoolName());
params.put("details", details);
params.put("providerName", storeProvider.getName());
params.put("managed", cmd.isManaged());
params.put("capacityBytes", cmd.getCapacityBytes());
params.put("capacityIops", cmd.getCapacityIops());
final DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
DataStore store = null;
try {
store = lifeCycle.initialize(params);
if (scopeType == ScopeType.CLUSTER) {
final ClusterScope clusterScope = new ClusterScope(clusterId, podId, zoneId);
lifeCycle.attachCluster(store, clusterScope);
} else if (scopeType == ScopeType.ZONE) {
final ZoneScope zoneScope = new ZoneScope(zoneId);
lifeCycle.attachZone(store, zoneScope, hypervisorType);
}
} catch (final Exception e) {
s_logger.debug("Failed to add data store: " + e.getMessage(), e);
try {
// not deleting data store.
if (store != null) {
lifeCycle.deleteDataStore(store);
}
} catch (final Exception ex) {
s_logger.debug("Failed to clean up storage pool: " + ex.getMessage());
}
throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
}
return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
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);
}
Aggregations