cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [2/8] git commit: updated refs/heads/object_store_migration to 9da56fe
Date Sat, 26 Oct 2013 04:18:45 GMT
Mark templates stored in current NFS secondary storage as cross-zones
when we invoke prepareSecondaryStorageForMigrationCmd.

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

Branch: refs/heads/object_store_migration
Commit: 1b07c3348174a56d81d951febd33d24032fe4b32
Parents: 6935dd2
Author: Min Chen <min.chen@citrix.com>
Authored: Mon Oct 21 11:52:12 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Mon Oct 21 11:52:12 2013 -0700

----------------------------------------------------------------------
 .../subsystem/api/storage/TemplateService.java  |  4 +++-
 .../storage/image/TemplateServiceImpl.java      | 11 +++++----
 .../image/db/TemplateDataStoreDaoImpl.java      | 25 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1b07c334/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateService.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateService.java
b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateService.java
index 4950597..0d8b3c1 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateService.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateService.java
@@ -36,7 +36,7 @@ public interface TemplateService {
         }
 
         public TemplateInfo getTemplate() {
-            return this.template;
+            return template;
         }
     }
 
@@ -62,5 +62,7 @@ public interface TemplateService {
 
     void addSystemVMTemplatesToSecondary(DataStore store);
     
+    void associateTemplateToZone(long templateId, Long zoneId);
+
     void associateCrosszoneTemplatesToZone(long dcId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1b07c334/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
index a68e40c..06cb652 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
@@ -28,6 +28,9 @@ import java.util.Set;
 
 import javax.inject.Inject;
 
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
 import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
 import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService;
@@ -59,9 +62,6 @@ import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
 import org.apache.cloudstack.storage.image.store.TemplateObject;
 import org.apache.cloudstack.storage.to.TemplateObjectTO;
 
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.storage.ListTemplateAnswer;
 import com.cloud.agent.api.storage.ListTemplateCommand;
@@ -73,8 +73,8 @@ import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.DataStoreRole;
-import com.cloud.storage.StoragePool;
 import com.cloud.storage.Storage.TemplateType;
+import com.cloud.storage.StoragePool;
 import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.VMTemplateZoneVO;
@@ -466,7 +466,8 @@ public class TemplateServiceImpl implements TemplateService {
     // persist entry in template_zone_ref table. zoneId can be empty for
     // region-wide image store, in that case,
     // we will associate the template to all the zones.
-    private void associateTemplateToZone(long templateId, Long zoneId) {
+    @Override
+    public void associateTemplateToZone(long templateId, Long zoneId) {
         List<Long> dcs = new ArrayList<Long>();
         if (zoneId != null) {
             dcs.add(zoneId);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1b07c334/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
index a102537..008180f 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
@@ -33,18 +33,22 @@ 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.ObjectInDataStoreStateMachine.Event;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
 import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.db.UpdateBuilder;
+import com.cloud.utils.exception.CloudRuntimeException;
 
 @Component
 public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO, Long>
implements TemplateDataStoreDao {
@@ -61,6 +65,11 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
     @Inject
     private DataStoreManager _storeMgr;
 
+    @Inject
+    private VMTemplateDao _tmpltDao;
+    @Inject
+    private TemplateService _tmplSrv;
+
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException
{
         super.configure(name, params);
@@ -368,8 +377,24 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
                 ts.setRefCnt(tmpl.getRefCnt() + 1); // increase ref_cnt so that this will
not be recycled before the content is pushed to region-wide store
                 persist(ts);
             }
+
+            // mark template as cross-zones and add template_zone association
+            for (TemplateDataStoreVO tmpl : tmpls) {
+                long templateId = tmpl.getTemplateId();
+                VMTemplateVO template = _tmpltDao.findById(templateId);
+                if (template == null) {
+                    throw new CloudRuntimeException("No template is found for template id:
" + templateId);
+                }
+                // mark the template as cross-zones
+                template.setCrossZones(true);
+                _tmpltDao.update(templateId, template);
+                // add template_zone_ref association for these cross-zone templates
+                _tmplSrv.associateTemplateToZone(templateId, null);
+            }
+
         }
 
+
     }
 
 }


Mime
View raw message