mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-3686: Registering a template does not generate a usage event.
This commit is contained in:
parent
f1fb7c3efe
commit
c2192808aa
|
|
@ -137,6 +137,12 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver {
|
|||
|
||||
TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId());
|
||||
if (tmpltStoreVO != null) {
|
||||
if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
TemplateDataStoreVO updateBuilder = _templateStoreDao.createForUpdate();
|
||||
updateBuilder.setDownloadPercent(answer.getDownloadPct());
|
||||
updateBuilder.setDownloadState(answer.getDownloadStatus());
|
||||
|
|
@ -184,6 +190,12 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver {
|
|||
|
||||
VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
|
||||
if (volStoreVO != null) {
|
||||
if (volStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Volume is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
VolumeDataStoreVO updateBuilder = _volumeStoreDao.createForUpdate();
|
||||
updateBuilder.setDownloadPercent(answer.getDownloadPct());
|
||||
updateBuilder.setDownloadState(answer.getDownloadStatus());
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
|
||||
|
|
@ -67,10 +68,13 @@ import com.cloud.alert.AlertManager;
|
|||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.UsageEventUtils;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.storage.DataStoreRole;
|
||||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.storage.VMTemplateStoragePoolVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||
|
|
@ -992,12 +996,41 @@ public class VolumeServiceImpl implements VolumeService {
|
|||
vo.processEvent(Event.OperationFailed);
|
||||
} else {
|
||||
vo.processEvent(Event.OperationSuccessed, result.getAnswer());
|
||||
}
|
||||
|
||||
_resourceLimitMgr.incrementResourceCount(vo.getAccountId(), ResourceType.secondary_storage, vo.getSize());
|
||||
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);
|
||||
VolumeApiResult res = new VolumeApiResult(null);
|
||||
|
|
|
|||
|
|
@ -27,12 +27,11 @@ import javax.inject.Inject;
|
|||
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
|
||||
import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
|
||||
import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd;
|
||||
import org.apache.cloudstack.api.command.user.template.ExtractTemplateCmd;
|
||||
import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
|
||||
|
|
@ -47,20 +46,17 @@ import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.storage.PrepareOVAPackingCommand;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.UsageEventUtils;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.TemplateProfile;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VMTemplateZoneVO;
|
||||
import com.cloud.storage.dao.VMTemplateZoneDao;
|
||||
|
|
@ -154,14 +150,14 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||
|| (format.equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2")
|
||||
&& !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url
|
||||
.toLowerCase().endsWith("qcow2.gz")))
|
||||
|| (format.equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova")
|
||||
&& !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url
|
||||
.toLowerCase().endsWith("ova.gz")))
|
||||
|| (format.equalsIgnoreCase("tar") && (!url.toLowerCase().endsWith("tar")
|
||||
&& !url.toLowerCase().endsWith("tar.zip") && !url.toLowerCase().endsWith("tar.bz2") && !url
|
||||
.toLowerCase().endsWith("tar.gz")))
|
||||
|| (format.equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase()
|
||||
.endsWith("raw")))) {
|
||||
|| (format.equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova")
|
||||
&& !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url
|
||||
.toLowerCase().endsWith("ova.gz")))
|
||||
|| (format.equalsIgnoreCase("tar") && (!url.toLowerCase().endsWith("tar")
|
||||
&& !url.toLowerCase().endsWith("tar.zip") && !url.toLowerCase().endsWith("tar.bz2") && !url
|
||||
.toLowerCase().endsWith("tar.gz")))
|
||||
|| (format.equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase()
|
||||
.endsWith("raw")))) {
|
||||
throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url
|
||||
+ " is an invalid for the format " + format.toLowerCase());
|
||||
}
|
||||
|
|
@ -197,13 +193,13 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||
return template;
|
||||
}
|
||||
|
||||
private class CreateTemplateContext<T> extends AsyncRpcContext<T> {
|
||||
final TemplateInfo template;
|
||||
public CreateTemplateContext(AsyncCompletionCallback<T> callback, TemplateInfo template) {
|
||||
super(callback);
|
||||
this.template = template;
|
||||
}
|
||||
}
|
||||
private class CreateTemplateContext<T> extends AsyncRpcContext<T> {
|
||||
final TemplateInfo template;
|
||||
public CreateTemplateContext(AsyncCompletionCallback<T> callback, TemplateInfo template) {
|
||||
super(callback);
|
||||
this.template = template;
|
||||
}
|
||||
}
|
||||
|
||||
protected Void createTemplateAsyncCallBack(AsyncCallbackDispatcher<HypervisorTemplateAdapter, TemplateApiResult> callback,
|
||||
CreateTemplateContext<TemplateApiResult> context) {
|
||||
|
|
@ -217,6 +213,31 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||
VMTemplateVO tmplt = this._tmpltDao.findById(template.getId());
|
||||
long accountId = tmplt.getAccountId();
|
||||
if (template.getSize() != null) {
|
||||
// publish usage event
|
||||
// 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(EventTypes.EVENT_TEMPLATE_CREATE, 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(EventTypes.EVENT_TEMPLATE_CREATE, 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());
|
||||
}
|
||||
}
|
||||
|
|
@ -275,7 +296,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
|
|||
TemplateApiResult result = future.get();
|
||||
success = result.isSuccess();
|
||||
if (!success) {
|
||||
s_logger.warn("Failed to delete the template " + template +
|
||||
s_logger.warn("Failed to delete the template " + template +
|
||||
" from the image store: " + imageStore.getName() + " due to: " + result.getResult());
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue