Search in sources :

Example 21 with ZoneScope

use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.

the class DownloadListener method processConnect.

@Override
public void processConnect(Host agent, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
    if (cmd instanceof StartupRoutingCommand) {
        List<HypervisorType> hypers = _resourceMgr.listAvailHypervisorInZone(agent.getId(), agent.getDataCenterId());
        HypervisorType hostHyper = agent.getHypervisorType();
        if (hypers.contains(hostHyper)) {
            return;
        }
        _imageSrv.handleSysTemplateDownload(hostHyper, agent.getDataCenterId());
        // update template_zone_ref for cross-zone templates
        _imageSrv.associateCrosszoneTemplatesToZone(agent.getDataCenterId());
    } else /* This can be removed
        else if ( cmd instanceof StartupStorageCommand) {
            StartupStorageCommand storage = (StartupStorageCommand)cmd;
            if( storage.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE ||
                    storage.getResourceType() == Storage.StorageResourceType.LOCAL_SECONDARY_STORAGE  ) {
                downloadMonitor.addSystemVMTemplatesToHost(agent, storage.getTemplateInfo());
                downloadMonitor.handleTemplateSync(agent);
                downloadMonitor.handleVolumeSync(agent);
            }
        }*/
    if (cmd instanceof StartupSecondaryStorageCommand) {
        try {
            List<DataStore> imageStores = _storeMgr.getImageStoresByScope(new ZoneScope(agent.getDataCenterId()));
            for (DataStore store : imageStores) {
                _volumeSrv.handleVolumeSync(store);
                _imageSrv.handleTemplateSync(store);
            }
        } catch (Exception e) {
            s_logger.error("Caught exception while doing template/volume sync ", e);
        }
    }
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) StartupSecondaryStorageCommand(com.cloud.agent.api.StartupSecondaryStorageCommand) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) List(java.util.List) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 22 with ZoneScope

use of org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope in project cloudstack by apache.

the class TemplateManagerImpl method prepareIso.

// for ISO, we need to consider whether to copy to cache storage or not if it is not on NFS, since our hypervisor resource always assumes that they are in NFS
@Override
public TemplateInfo prepareIso(long isoId, long dcId) {
    TemplateInfo tmplt = _tmplFactory.getTemplate(isoId, DataStoreRole.Image, dcId);
    if (tmplt == null || tmplt.getFormat() != ImageFormat.ISO) {
        s_logger.warn("ISO: " + isoId + " does not exist in vm_template table");
        return null;
    }
    if (tmplt.getDataStore() != null && !(tmplt.getDataStore().getTO() instanceof NfsTO)) {
        // if it is s3, need to download into cache storage first
        Scope destScope = new ZoneScope(dcId);
        TemplateInfo cacheData = (TemplateInfo) cacheMgr.createCacheObject(tmplt, destScope);
        if (cacheData == null) {
            s_logger.error("Failed in copy iso from S3 to cache storage");
            return null;
        }
        return cacheData;
    } else {
        return tmplt;
    }
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) PublishScope(org.apache.cloudstack.framework.messagebus.PublishScope) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 23 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)

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