Search in sources :

Example 16 with ZoneScope

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

Example 17 with ZoneScope

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;
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope)

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

Example 19 with ZoneScope

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");
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) Test(org.testng.annotations.Test)

Example 20 with ZoneScope

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;
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope)

Aggregations

ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)23 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)17 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)6 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)6 ClusterScope (org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)4 VMTemplateVO (com.cloud.storage.VMTemplateVO)4 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)4 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)4 Answer (com.cloud.agent.api.Answer)3 NfsTO (com.cloud.agent.api.to.NfsTO)3 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)3 ConnectionException (com.cloud.exception.ConnectionException)3 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 HostVO (com.cloud.host.HostVO)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3