Search in sources :

Example 6 with ZoneScope

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;
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) ZoneHostInfo(com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) Pair(com.cloud.utils.Pair)

Example 7 with ZoneScope

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);
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) Pair(com.cloud.utils.Pair)

Example 8 with ZoneScope

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;
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 9 with ZoneScope

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;
}
Also used : TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) AccountVO(com.cloud.user.AccountVO) TemplateApiResult(com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) MalformedURLException(java.net.MalformedURLException) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) DB(com.cloud.utils.db.DB)

Example 10 with ZoneScope

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));
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) StorageSubSystemCommand(com.cloud.storage.command.StorageSubSystemCommand) DataTO(com.cloud.agent.api.to.DataTO) CopyCommand(com.cloud.storage.command.CopyCommand) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) NfsTO(com.cloud.agent.api.to.NfsTO) HostVO(com.cloud.host.HostVO) Pair(com.cloud.utils.Pair)

Aggregations

ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)20 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)5 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)5 NfsTO (com.cloud.agent.api.to.NfsTO)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)4 Answer (com.cloud.agent.api.Answer)3 ClusterScope (com.cloud.engine.subsystem.api.storage.ClusterScope)3 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)3 ConnectionException (com.cloud.exception.ConnectionException)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 HostVO (com.cloud.host.HostVO)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)3 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 HostScope (com.cloud.engine.subsystem.api.storage.HostScope)2 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)2 TemplateApiResult (com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult)2