Not reuse already destroyed entries in template_store_ref to make code
cleaner.

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

Branch: refs/heads/object_store
Commit: c609bc0541c047a509dca0493b8c967b9ff9d3c6
Parents: 9e1a9bf
Author: Min Chen <[email protected]>
Authored: Fri May 24 14:34:56 2013 -0700
Committer: Min Chen <[email protected]>
Committed: Fri May 24 14:34:56 2013 -0700

----------------------------------------------------------------------
 .../com/cloud/template/TemplateManagerImpl.java    |   38 ++------------
 1 files changed, 6 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c609bc05/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 ac66312..ce26837 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -707,45 +707,19 @@ public class TemplateManagerImpl extends ManagerBase 
implements TemplateManager,
         // and copy template there, not propagate to all image stores
         // for that zone
         for (DataStore dstSecStore : dstSecStores) {
-            TemplateDataStoreVO dstTmpltStore = null;
-            try {
-                dstTmpltStore = 
this._tmplStoreDao.findByStoreTemplate(dstSecStore.getId(), tmpltId, true);
-                if (dstTmpltStore != null) {
-                    dstTmpltStore = 
_tmplStoreDao.lockRow(dstTmpltStore.getId(), true);
-                    if (dstTmpltStore != null && 
dstTmpltStore.getDownloadState() == Status.DOWNLOADED) {
-                        if (dstTmpltStore.getDestroyed() == false) {
-                            return true; // already downloaded on this image
-                                         // store
-                        } else {
-                            dstTmpltStore.setDestroyed(false);
-                            _tmplStoreDao.update(dstTmpltStore.getId(), 
dstTmpltStore);
-                            return true;
-                        }
-                    } else if (dstTmpltStore != null && 
dstTmpltStore.getDownloadState() == Status.DOWNLOAD_ERROR) {
-                        if (dstTmpltStore.getDestroyed() == true) {
-                            dstTmpltStore.setDestroyed(false);
-                            
dstTmpltStore.setDownloadState(Status.NOT_DOWNLOADED);
-                            dstTmpltStore.setDownloadPercent(0);
-                            dstTmpltStore.setCopy(true);
-                            dstTmpltStore.setErrorString("");
-                            dstTmpltStore.setJobId(null);
-                            _tmplStoreDao.update(dstTmpltStore.getId(), 
dstTmpltStore);
-                        }
-                    }
-                }
-            } finally {
-                txn.commit();
+            TemplateDataStoreVO dstTmpltStore = 
this._tmplStoreDao.findByStoreTemplate(dstSecStore.getId(), tmpltId);
+            if (dstTmpltStore != null && dstTmpltStore.getDownloadState() == 
Status.DOWNLOADED) {
+                return true; // already downloaded on this image store
             }
 
             AsyncCallFuture<TemplateApiResult> future = 
this._tmpltSvr.copyTemplate(srcTemplate, dstSecStore);
             try {
                 TemplateApiResult result = future.get();
                 if (result.isFailed()) {
-                    s_logger.debug("copy template failed:" + 
result.getResult());
-                    return false;
+                    s_logger.debug("copy template failed for image store " + 
dstSecStore.getName() + ":" + result.getResult());
+                    continue; // try next image store
                 }
-                // if(_downloadMonitor.copyTemplate(template, srcSecStore,
-                // dstSecStore) ) {
+
                 _tmpltDao.addTemplateToZone(template, dstZoneId);
 
                 if (account.getId() != Account.ACCOUNT_ID_SYSTEM) {

Reply via email to