cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [2/2] git commit: updated refs/heads/object_store to 913e2b3
Date Fri, 24 May 2013 00:24:02 GMT
Exclude removed template from template sync.


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

Branch: refs/heads/object_store
Commit: d1704a389aaf4e0f2a09301bc105546b4935802c
Parents: 57049d5
Author: Min Chen <min.chen@citrix.com>
Authored: Thu May 23 16:43:14 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Thu May 23 17:23:25 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/storage/dao/VMTemplateDao.java   |    1 +
 .../com/cloud/storage/dao/VMTemplateDaoImpl.java   |   29 +++++--
 .../storage/image/TemplateServiceImpl.java         |   30 ++++++-
 .../datastore/driver/S3ImageStoreDriverImpl.java   |   61 ++++++--------
 .../driver/SwiftImageStoreDriverImpl.java          |   63 ++++++---------
 .../com/cloud/template/TemplateManagerImpl.java    |    2 +-
 6 files changed, 101 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d1704a38/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java
index 74822bc..b4376fd 100755
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java
@@ -50,6 +50,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>,
StateDao<
 
 	public long addTemplateToZone(VMTemplateVO tmplt, long zoneId);
 	public List<VMTemplateVO> listAllInZone(long dataCenterId);
+	public List<VMTemplateVO> listAllActive();
 
     public List<VMTemplateVO> listByHypervisorType(List<HypervisorType> hyperTypes);
 	public List<VMTemplateVO> publicIsoSearch(Boolean bootable, boolean listRemoved, Map<String,
String> tags);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d1704a38/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
index a8c2455..7bd8b6d 100755
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
@@ -110,6 +110,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
     protected SearchBuilder<VMTemplateVO> AccountIdSearch;
     protected SearchBuilder<VMTemplateVO> NameSearch;
     protected SearchBuilder<VMTemplateVO> TmpltsInZoneSearch;
+    protected SearchBuilder<VMTemplateVO> ActiveTmpltSearch;
     private SearchBuilder<VMTemplateVO> PublicSearch;
     private SearchBuilder<VMTemplateVO> NameAccountIdSearch;
     private SearchBuilder<VMTemplateVO> PublicIsoSearch;
@@ -368,6 +369,10 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
 		tmpltZoneSearch.done();
 		TmpltsInZoneSearch.done();
 
+        ActiveTmpltSearch = createSearchBuilder();
+        ActiveTmpltSearch.and("removed", ActiveTmpltSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
+
+
 		CountTemplatesByAccount = createSearchBuilder(Long.class);
 		CountTemplatesByAccount.select(null, Func.COUNT, null);
 		CountTemplatesByAccount.and("account", CountTemplatesByAccount.entity().getAccountId(),
SearchCriteria.Op.EQ);
@@ -556,12 +561,12 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         	if ((templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.community))
{
         	    dataCenterJoin = " INNER JOIN data_center dc on (h.data_center_id = dc.id)";
         	}
-        	
+
         	if (zoneType != null) {
         	    dataCenterJoin = " INNER JOIN template_host_ref thr on (t.id = thr.template_id)
INNER JOIN host h on (thr.host_id = h.id)";
                 dataCenterJoin += " INNER JOIN data_center dc on (h.data_center_id = dc.id)";
             }
-        	
+
         	if (templateFilter == TemplateFilter.sharedexecutable || templateFilter == TemplateFilter.shared
){
         	    lpjoin = " INNER JOIN launch_permission lp ON t.id = lp.template_id ";
         	}
@@ -749,7 +754,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         return templateZonePairList;
 	}
     */
-	
+
 	/*
 	private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword,
boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady,
boolean showDomr, String zoneType) {
 	    String sql = "";
@@ -781,15 +786,15 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
         		sql += " AND h.data_center_id = " +zoneId;
             }
         }else if (zoneId != null){
-        	sql += " AND tzr.zone_id = " +zoneId+ " AND tzr.removed is null" ;        	    
	
+        	sql += " AND tzr.zone_id = " +zoneId+ " AND tzr.removed is null" ;
         }else{
         	sql += " AND tzr.removed is null ";
         }
-        
-        if (zoneType != null){            
+
+        if (zoneType != null){
             sql += " AND dc.networktype = '" + zoneType + "'";
-        }   
-        
+        }
+
         if (!showDomr){
         	sql += " AND t.type != '" +Storage.TemplateType.SYSTEM.toString() + "'";
         }
@@ -854,7 +859,15 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO,
Long> implem
 		return listBy(sc);
 	}
 
+
+
 	@Override
+    public List<VMTemplateVO> listAllActive() {
+        SearchCriteria<VMTemplateVO> sc = ActiveTmpltSearch.create();
+        return listBy(sc);
+    }
+
+    @Override
 	public List<VMTemplateVO> listDefaultBuiltinTemplates() {
 		SearchCriteria<VMTemplateVO> sc = tmpltTypeSearch.create();
 		sc.setParameters("templateType", Storage.TemplateType.BUILTIN);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d1704a38/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 597bbbe..eb6e44c 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
@@ -40,11 +40,13 @@ 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.ObjectInDataStoreStateMachine;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateEvent;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
 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;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
 import org.apache.cloudstack.framework.async.AsyncCallFuture;
@@ -57,6 +59,7 @@ import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
+import org.apache.cloudstack.storage.image.manager.ImageDataManager;
 import org.apache.cloudstack.storage.image.store.TemplateObject;
 
 import com.cloud.agent.api.Answer;
@@ -64,9 +67,12 @@ import com.cloud.agent.api.storage.DeleteTemplateCommand;
 import com.cloud.agent.api.storage.ListTemplateAnswer;
 import com.cloud.agent.api.storage.ListTemplateCommand;
 import com.cloud.alert.AlertManager;
+import com.cloud.api.query.dao.UserVmJoinDao;
+import com.cloud.api.query.vo.UserVmJoinVO;
 import com.cloud.dc.DataCenterVO;
 import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.DataStoreRole;
@@ -84,6 +90,7 @@ import com.cloud.storage.template.TemplateProp;
 import com.cloud.user.AccountManager;
 import com.cloud.user.ResourceLimitService;
 import com.cloud.utils.UriUtils;
+import com.cloud.utils.fsm.NoTransitionException;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.dao.UserVmDao;
 
@@ -121,12 +128,17 @@ public class TemplateServiceImpl implements TemplateService {
     @Inject
     UserVmDao _userVmDao;
     @Inject
+    UserVmJoinDao _userVmJoinDao;
+    @Inject
     VolumeDao _volumeDao;
     @Inject
     TemplateDataFactory _templateFactory;
     @Inject VMTemplatePoolDao _tmpltPoolDao;
     @Inject
     EndPointSelector _epSelector;
+    @Inject
+    ImageDataManager imageMgr;
+
 
     class TemplateOpContext<T> extends AsyncRpcConext<T> {
         final TemplateObject template;
@@ -264,7 +276,7 @@ public class TemplateServiceImpl implements TemplateService {
         List<VMTemplateVO> allTemplates = null;
         if (zoneId == null){
             // region wide store
-            allTemplates = _templateDao.listAll();
+            allTemplates = _templateDao.listAllActive();
         }
         else{
             // zone wide store
@@ -326,7 +338,7 @@ public class TemplateServiceImpl implements TemplateService {
                         tmlpt.setSize(tmpltInfo.getSize());
                         _templateDao.update(tmplt.getId(), tmlpt);
 
-                        if (tmpltInfo.getSize() > 0) {
+                        if (tmpltInfo.getSize() > 0 && tmplt.getUrl() != null)
{
                             long accountId = tmplt.getAccountId();
                             try {
                                 _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(accountId),
@@ -418,7 +430,7 @@ public class TemplateServiceImpl implements TemplateService {
 
        for (String uniqueName : templateInfos.keySet()) {
             TemplateProp tInfo = templateInfos.get(uniqueName);
-            List<UserVmVO> userVmUsingIso = _userVmDao.listByIsoId(tInfo.getId());
+            List<UserVmJoinVO> userVmUsingIso = _userVmJoinDao.listActiveByIsoId(tInfo.getId());
             //check if there is any Vm using this ISO.
             if (userVmUsingIso == null || userVmUsingIso.isEmpty()) {
                 //TODO: we cannot directly call deleteTemplateSync here to reuse delete logic
since in this case, our db does not have this template at all.
@@ -610,6 +622,18 @@ public class TemplateServiceImpl implements TemplateService {
         long storeId = store.getId();
         List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
         for ( VMTemplateVO tmplt : rtngTmplts ) {
+            // set template ready state
+            if ( tmplt.getState() != TemplateState.Ready ){
+                try {
+                    imageMgr.getStateMachine().transitTo(tmplt, TemplateEvent.CreateRequested,
null,
+                            _templateDao);
+                    imageMgr.getStateMachine().transitTo(tmplt, TemplateEvent.OperationSucceeded,
null,
+                            _templateDao);
+                } catch (NoTransitionException e) {
+                    // non fatal though
+                    s_logger.debug("failed to update system vm template state to Ready",
e);
+                }
+            }
             TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId,
tmplt.getId());
             if ( tmpltStore == null ) {
                 tmpltStore = new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(),
100, Status.DOWNLOADED, null, null, null, TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH
+ tmplt.getId() + File.separator, tmplt.getUrl());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d1704a38/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
index 1c6e17e..3fd5930 100644
--- a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
+++ b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
@@ -291,46 +291,35 @@ public class S3ImageStoreDriverImpl implements ImageStoreDriver {
             UsageEventUtils.publishUsageEvent(eventType, account.getId(), sZoneId, templateId,
null, null, null);
         }
 
-        List<UserVmJoinVO> userVmUsingIso = _userVmJoinDao.listActiveByIsoId(templateId);
-        // check if there is any VM using this ISO.
-        if (userVmUsingIso == null || userVmUsingIso.isEmpty()) {
-             // get installpath of this template on image store
-            TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId,
templateId);
-            String installPath = tmplStore.getInstallPath();
-            if (installPath != null) {
-                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), installPath,
template.getId(), template.getAccountId());
-                EndPoint ep = _epSelector.select(templateObj);
-                Answer answer = ep.sendMessage(cmd);
+        // get installpath of this template on image store
+        TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId, templateId);
+        String installPath = tmplStore.getInstallPath();
+        if (installPath != null) {
+            DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), installPath,
template.getId(), template.getAccountId());
+            EndPoint ep = _epSelector.select(templateObj);
+            Answer answer = ep.sendMessage(cmd);
 
-                if (answer == null || !answer.getResult()) {
-                    s_logger.debug("Failed to deleted template at store: " + store.getName());
-                    CommandResult result = new CommandResult();
-                    result.setSuccess(false);
-                    result.setResult("Delete template failed");
-                    callback.complete(result);
-
-                } else {
-                    s_logger.debug("Deleted template at: " + installPath);
-                    CommandResult result = new CommandResult();
-                    result.setSuccess(true);
-                    callback.complete(result);
-                }
+            if (answer == null || !answer.getResult()) {
+                s_logger.debug("Failed to deleted template at store: " + store.getName());
+                CommandResult result = new CommandResult();
+                result.setSuccess(false);
+                result.setResult("Delete template failed");
+                callback.complete(result);
 
-                // for S3, a template can be associated with multiple zones
-                List<VMTemplateZoneVO> templateZones = templateZoneDao
-                        .listByZoneTemplate(sZoneId, templateId);
-                if (templateZones != null) {
-                    for (VMTemplateZoneVO templateZone : templateZones) {
-                        templateZoneDao.remove(templateZone.getId());
-                    }
+            } else {
+                s_logger.debug("Deleted template at: " + installPath);
+                CommandResult result = new CommandResult();
+                result.setSuccess(true);
+                callback.complete(result);
+            }
+
+            // for S3, a template can be associated with multiple zones
+            List<VMTemplateZoneVO> templateZones = templateZoneDao.listByZoneTemplate(sZoneId,
templateId);
+            if (templateZones != null) {
+                for (VMTemplateZoneVO templateZone : templateZones) {
+                    templateZoneDao.remove(templateZone.getId());
                 }
             }
-        } else{
-            // cannot delete iso due to some VMs are using this
-            s_logger.debug("Cannot delete iso since some user vms are referencing it");
-            CommandResult result = new CommandResult();
-            result.setResult("Cannot delete iso since some user vms are referencing it");
-            callback.complete(result);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d1704a38/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
index 590b653..b8f666e 100644
--- a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
+++ b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
@@ -285,48 +285,37 @@ public class SwiftImageStoreDriverImpl implements ImageStoreDriver {
             UsageEventUtils.publishUsageEvent(eventType, account.getId(), sZoneId, templateId,
null, null, null);
         }
 
-        List<UserVmJoinVO> userVmUsingIso = _userVmJoinDao.listActiveByIsoId(templateId);
-        // check if there is any VM using this ISO.
-        if (userVmUsingIso == null || userVmUsingIso.isEmpty()) {
-             // get installpath of this template on image store
-            TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId,
templateId);
-            String installPath = tmplStore.getInstallPath();
-            if (installPath != null) {
-                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), installPath,
template.getId(), template.getAccountId());
-                EndPoint ep = _epSelector.select(templateObj);
-                Answer answer = ep.sendMessage(cmd);
+        // get installpath of this template on image store
+        TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId, templateId);
+        String installPath = tmplStore.getInstallPath();
+        if (installPath != null) {
+            DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), installPath,
template.getId(), template.getAccountId());
+            EndPoint ep = _epSelector.select(templateObj);
+            Answer answer = ep.sendMessage(cmd);
 
-                if (answer == null || !answer.getResult()) {
-                    s_logger.debug("Failed to deleted template at store: " + store.getName());
-                    CommandResult result = new CommandResult();
-                    //result.setSucess(false);
-                    result.setResult("Delete template failed");
-                    callback.complete(result);
-
-                } else {
-                    s_logger.debug("Deleted template at: " + installPath);
-                    CommandResult result = new CommandResult();
-                    //result.setSucess(true);
-                    callback.complete(result);
-                }
+            if (answer == null || !answer.getResult()) {
+                s_logger.debug("Failed to deleted template at store: " + store.getName());
+                CommandResult result = new CommandResult();
+                // result.setSucess(false);
+                result.setResult("Delete template failed");
+                callback.complete(result);
+
+            } else {
+                s_logger.debug("Deleted template at: " + installPath);
+                CommandResult result = new CommandResult();
+                // result.setSucess(true);
+                callback.complete(result);
+            }
 
-                // for Swift, a template can be associated with multiple zones
-                List<VMTemplateZoneVO> templateZones = templateZoneDao
-                        .listByZoneTemplate(sZoneId, templateId);
-                if (templateZones != null) {
-                    for (VMTemplateZoneVO templateZone : templateZones) {
-                        templateZoneDao.remove(templateZone.getId());
-                    }
+            // for Swift, a template can be associated with multiple zones
+            List<VMTemplateZoneVO> templateZones = templateZoneDao.listByZoneTemplate(sZoneId,
templateId);
+            if (templateZones != null) {
+                for (VMTemplateZoneVO templateZone : templateZones) {
+                    templateZoneDao.remove(templateZone.getId());
                 }
             }
-        } else{
-            // cannot delete iso due to some VMs are using this
-            s_logger.debug("Cannot delete iso since some user vms are referencing it");
-            CommandResult result = new CommandResult();
-            result.setResult("Cannot delete iso since some user vms are referencing it");
-            callback.complete(result);
         }
-    }
+     }
 
     private void deleteSnapshot(DataObject data, AsyncCompletionCallback<CommandResult>
callback) {
         SnapshotObject snapshotObj = (SnapshotObject)data;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d1704a38/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index c5e80b0..3e3616f 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -1155,7 +1155,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
 
     	 List<UserVmJoinVO> userVmUsingIso = _userVmJoinDao.listActiveByIsoId(templateId);
          // check if there is any VM using this ISO.
-         if (!userVmUsingIso.isEmpty()) {
+         if (userVmUsingIso != null && !userVmUsingIso.isEmpty()) {
         	 throw new InvalidParameterValueException("Unable to delete iso, as it's used by
other vms");
          }
 


Mime
View raw message