Search in sources :

Example 6 with Scope

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

the class HypervisorTemplateAdapter method createTemplateAsyncCallBack.

protected Void createTemplateAsyncCallBack(AsyncCallbackDispatcher<HypervisorTemplateAdapter, TemplateApiResult> callback, CreateTemplateContext<TemplateApiResult> context) {
    TemplateApiResult result = callback.getResult();
    TemplateInfo template = context.template;
    if (result.isSuccess()) {
        VMTemplateVO tmplt = _tmpltDao.findById(template.getId());
        // need to grant permission for public templates
        if (tmplt.isPublicTemplate()) {
            _messageBus.publish(_name, TemplateManager.MESSAGE_REGISTER_PUBLIC_TEMPLATE_EVENT, PublishScope.LOCAL, tmplt.getId());
        }
        long accountId = tmplt.getAccountId();
        if (template.getSize() != null) {
            // publish usage event
            String etype = EventTypes.EVENT_TEMPLATE_CREATE;
            if (tmplt.getFormat() == ImageFormat.ISO) {
                etype = EventTypes.EVENT_ISO_CREATE;
            }
            // get physical size from template_store_ref table
            long physicalSize = 0;
            DataStore ds = template.getDataStore();
            TemplateDataStoreVO tmpltStore = _tmpltStoreDao.findByStoreTemplate(ds.getId(), template.getId());
            if (tmpltStore != null) {
                physicalSize = tmpltStore.getPhysicalSize();
            } else {
                s_logger.warn("No entry found in template_store_ref for template id: " + template.getId() + " and image store id: " + ds.getId() + " at the end of registering template!");
            }
            Scope dsScope = ds.getScope();
            if (dsScope.getScopeType() == ScopeType.ZONE) {
                if (dsScope.getScopeId() != null) {
                    UsageEventUtils.publishUsageEvent(etype, template.getAccountId(), dsScope.getScopeId(), template.getId(), template.getName(), null, null, physicalSize, template.getSize(), VirtualMachineTemplate.class.getName(), template.getUuid());
                } else {
                    s_logger.warn("Zone scope image store " + ds.getId() + " has a null scope id");
                }
            } else if (dsScope.getScopeType() == ScopeType.REGION) {
                // publish usage event for region-wide image store using a -1 zoneId for 4.2, need to revisit post-4.2
                UsageEventUtils.publishUsageEvent(etype, template.getAccountId(), -1, template.getId(), template.getName(), null, null, physicalSize, template.getSize(), VirtualMachineTemplate.class.getName(), template.getUuid());
            }
            _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.secondary_storage, template.getSize());
        }
    }
    return null;
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) PublishScope(org.apache.cloudstack.framework.messagebus.PublishScope) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) TemplateApiResult(org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult)

Example 7 with Scope

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

the class VolumeApiServiceImpl method needMoveVolume.

private boolean needMoveVolume(VolumeVO existingVolume, VolumeInfo newVolume) {
    if (existingVolume == null || existingVolume.getPoolId() == null || newVolume.getPoolId() == null) {
        return false;
    }
    DataStore storeForExistingVol = dataStoreMgr.getPrimaryDataStore(existingVolume.getPoolId());
    DataStore storeForNewVol = dataStoreMgr.getPrimaryDataStore(newVolume.getPoolId());
    Scope storeForExistingStoreScope = storeForExistingVol.getScope();
    if (storeForExistingStoreScope == null) {
        throw new CloudRuntimeException("Can't get scope of data store: " + storeForExistingVol.getId());
    }
    Scope storeForNewStoreScope = storeForNewVol.getScope();
    if (storeForNewStoreScope == null) {
        throw new CloudRuntimeException("Can't get scope of data store: " + storeForNewVol.getId());
    }
    if (storeForNewStoreScope.getScopeType() == ScopeType.ZONE) {
        return false;
    }
    if (storeForExistingStoreScope.getScopeType() != storeForNewStoreScope.getScopeType()) {
        if (storeForNewStoreScope.getScopeType() == ScopeType.CLUSTER) {
            Long vmClusterId = null;
            if (storeForExistingStoreScope.getScopeType() == ScopeType.HOST) {
                HostScope hs = (HostScope) storeForExistingStoreScope;
                vmClusterId = hs.getClusterId();
            } else if (storeForExistingStoreScope.getScopeType() == ScopeType.ZONE) {
                Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId();
                if (hostId != null) {
                    HostVO host = _hostDao.findById(hostId);
                    vmClusterId = host.getClusterId();
                }
            }
            if (storeForNewStoreScope.getScopeId().equals(vmClusterId)) {
                return false;
            } else {
                return true;
            }
        } else if (storeForNewStoreScope.getScopeType() == ScopeType.HOST && (storeForExistingStoreScope.getScopeType() == ScopeType.CLUSTER || storeForExistingStoreScope.getScopeType() == ScopeType.ZONE)) {
            Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId();
            if (storeForNewStoreScope.getScopeId().equals(hostId)) {
                return false;
            }
        }
        throw new InvalidParameterValueException("Can't move volume between scope: " + storeForNewStoreScope.getScopeType() + " and " + storeForExistingStoreScope.getScopeType());
    }
    return !storeForExistingStoreScope.isSameScope(storeForNewStoreScope);
}
Also used : Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) HostVO(com.cloud.host.HostVO)

Example 8 with Scope

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

the class VolumeServiceImpl method registerVolumeCallback.

protected Void registerVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, CreateVolumeContext<VolumeApiResult> context) {
    CreateCmdResult result = callback.getResult();
    VolumeObject vo = (VolumeObject) context.volume;
    try {
        if (result.isFailed()) {
            vo.processEvent(Event.OperationFailed);
            // delete the volume entry from volumes table in case of failure
            VolumeVO vol = volDao.findById(vo.getId());
            if (vol != null) {
                volDao.remove(vo.getId());
            }
        } else {
            vo.processEvent(Event.OperationSuccessed, result.getAnswer());
            if (vo.getSize() != null) {
                // publish usage events
                // get physical size from volume_store_ref table
                long physicalSize = 0;
                DataStore ds = vo.getDataStore();
                VolumeDataStoreVO volStore = _volumeStoreDao.findByStoreVolume(ds.getId(), vo.getId());
                if (volStore != null) {
                    physicalSize = volStore.getPhysicalSize();
                } else {
                    s_logger.warn("No entry found in volume_store_ref for volume id: " + vo.getId() + " and image store id: " + ds.getId() + " at the end of uploading volume!");
                }
                Scope dsScope = ds.getScope();
                if (dsScope.getScopeType() == ScopeType.ZONE) {
                    if (dsScope.getScopeId() != null) {
                        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_UPLOAD, vo.getAccountId(), dsScope.getScopeId(), vo.getId(), vo.getName(), null, null, physicalSize, vo.getSize(), Volume.class.getName(), vo.getUuid());
                    } else {
                        s_logger.warn("Zone scope image store " + ds.getId() + " has a null scope id");
                    }
                } else if (dsScope.getScopeType() == ScopeType.REGION) {
                    // publish usage event for region-wide image store using a -1 zoneId for 4.2, need to revisit post-4.2
                    UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_UPLOAD, vo.getAccountId(), -1, vo.getId(), vo.getName(), null, null, physicalSize, vo.getSize(), Volume.class.getName(), vo.getUuid());
                    _resourceLimitMgr.incrementResourceCount(vo.getAccountId(), ResourceType.secondary_storage, vo.getSize());
                }
            }
        }
        VolumeApiResult res = new VolumeApiResult(vo);
        context.future.complete(res);
        return null;
    } catch (Exception e) {
        s_logger.error("register volume failed: ", e);
        // delete the volume entry from volumes table in case of failure
        VolumeVO vol = volDao.findById(vo.getId());
        if (vol != null) {
            volDao.remove(vo.getId());
        }
        VolumeApiResult res = new VolumeApiResult(null);
        context.future.complete(res);
        return null;
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) Volume(com.cloud.storage.Volume) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 9 with Scope

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

the class TemplateServiceImpl method createTemplateAsyncCallBack.

protected Void createTemplateAsyncCallBack(AsyncCallbackDispatcher<TemplateServiceImpl, TemplateApiResult> callback, TemplateOpContext<TemplateApiResult> context) {
    TemplateInfo template = context.template;
    TemplateApiResult result = callback.getResult();
    if (result.isSuccess()) {
        VMTemplateVO tmplt = _templateDao.findById(template.getId());
        // need to grant permission for public templates
        if (tmplt.isPublicTemplate()) {
            _messageBus.publish(null, TemplateManager.MESSAGE_REGISTER_PUBLIC_TEMPLATE_EVENT, PublishScope.LOCAL, tmplt.getId());
        }
        long accountId = tmplt.getAccountId();
        if (template.getSize() != null) {
            // publish usage event
            String etype = EventTypes.EVENT_TEMPLATE_CREATE;
            if (tmplt.getFormat() == ImageFormat.ISO) {
                etype = EventTypes.EVENT_ISO_CREATE;
            }
            // get physical size from template_store_ref table
            long physicalSize = 0;
            DataStore ds = template.getDataStore();
            TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(ds.getId(), template.getId());
            if (tmpltStore != null) {
                physicalSize = tmpltStore.getPhysicalSize();
            } else {
                s_logger.warn("No entry found in template_store_ref for template id: " + template.getId() + " and image store id: " + ds.getId() + " at the end of registering template!");
            }
            Scope dsScope = ds.getScope();
            if (dsScope.getScopeId() != null) {
                UsageEventUtils.publishUsageEvent(etype, template.getAccountId(), dsScope.getScopeId(), template.getId(), template.getName(), null, null, physicalSize, template.getSize(), VirtualMachineTemplate.class.getName(), template.getUuid());
            } else {
                s_logger.warn("Zone scope image store " + ds.getId() + " has a null scope id");
            }
            _resourceLimitMgr.incrementResourceCount(accountId, Resource.ResourceType.secondary_storage, template.getSize());
        }
    }
    return null;
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) PublishScope(org.apache.cloudstack.framework.messagebus.PublishScope) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)

Example 10 with Scope

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

the class DefaultEndPointSelector method findEndPointForImageMove.

protected EndPoint findEndPointForImageMove(DataStore srcStore, DataStore destStore) {
    // find any xenserver/kvm host in the scope
    Scope srcScope = srcStore.getScope();
    Scope destScope = destStore.getScope();
    Scope selectedScope = null;
    Long poolId = null;
    // scope
    if (srcScope.getScopeType() != ScopeType.ZONE) {
        selectedScope = srcScope;
        poolId = srcStore.getId();
    } else if (destScope.getScopeType() != ScopeType.ZONE) {
        selectedScope = destScope;
        poolId = destStore.getId();
    } else {
        // if both are zone scope
        if (srcStore.getRole() == DataStoreRole.Primary) {
            selectedScope = srcScope;
            poolId = srcStore.getId();
        } else if (destStore.getRole() == DataStoreRole.Primary) {
            selectedScope = destScope;
            poolId = destStore.getId();
        }
    }
    return findEndPointInScope(selectedScope, findOneHostOnPrimaryStorage, poolId);
}
Also used : Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope)

Aggregations

Scope (org.apache.cloudstack.engine.subsystem.api.storage.Scope)13 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)9 HostScope (org.apache.cloudstack.engine.subsystem.api.storage.HostScope)7 ClusterScope (org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope)6 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)4 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)4 CopyCommand (org.apache.cloudstack.storage.command.CopyCommand)4 Answer (com.cloud.agent.api.Answer)3 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)3 HostVO (com.cloud.host.HostVO)3 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)3 PublishScope (org.apache.cloudstack.framework.messagebus.PublishScope)3 RemoteHostEndPoint (org.apache.cloudstack.storage.RemoteHostEndPoint)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)2 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)2 NfsTO (com.cloud.agent.api.to.NfsTO)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1