cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject git commit: updated refs/heads/master to c219280
Date Wed, 31 Jul 2013 00:41:13 GMT
Updated Branches:
  refs/heads/master f1fb7c3ef -> c2192808a


CLOUDSTACK-3686: Registering a template does not generate a usage event.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c2192808
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c2192808
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c2192808

Branch: refs/heads/master
Commit: c2192808aa5f7a391a79fb6c84592819c032fa45
Parents: f1fb7c3
Author: Min Chen <min.chen@citrix.com>
Authored: Tue Jul 30 17:32:55 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Tue Jul 30 17:35:12 2013 -0700

----------------------------------------------------------------------
 .../storage/image/BaseImageStoreDriverImpl.java | 12 ++++
 .../storage/volume/VolumeServiceImpl.java       | 37 ++++++++++-
 .../template/HypervisorTemplateAdapter.java     | 65 +++++++++++++-------
 3 files changed, 90 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2192808/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
index e2fc8b7..13d19d3 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
@@ -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());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2192808/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
index 559bd37..24d8d5e 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
@@ -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);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2192808/server/src/com/cloud/template/HypervisorTemplateAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/com/cloud/template/HypervisorTemplateAdapter.java
index dd6cc68..d106e91 100755
--- a/server/src/com/cloud/template/HypervisorTemplateAdapter.java
+++ b/server/src/com/cloud/template/HypervisorTemplateAdapter.java
@@ -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;
                     }


Mime
View raw message