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;
}
}
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);
}
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;
}
Aggregations