You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/05/24 21:00:06 UTC
git commit: updated refs/heads/object_store to 89f351c
Updated Branches:
refs/heads/object_store c614c6a42 -> 89f351c2e
Clean up template sync code, and update template state in template sync
phase instead of doing it in adding image store.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/89f351c2
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/89f351c2
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/89f351c2
Branch: refs/heads/object_store
Commit: 89f351c2e5365ba7472a714b66e80bd0186a9efa
Parents: c614c6a
Author: Min Chen <mi...@citrix.com>
Authored: Fri May 24 11:56:36 2013 -0700
Committer: Min Chen <mi...@citrix.com>
Committed: Fri May 24 11:56:36 2013 -0700
----------------------------------------------------------------------
.../storage/image/TemplateServiceImpl.java | 68 ++++++++-------
.../src/com/cloud/storage/StorageManagerImpl.java | 6 +-
2 files changed, 42 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/89f351c2/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 fd34971..c4d04fb 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
@@ -323,7 +323,8 @@ public class TemplateServiceImpl implements TemplateService {
tmpltStore.setErrorString(msg);
s_logger.info("msg");
if (tmplt.getUrl() == null) {
- msg = "Private Template (" + tmplt + ") with install path " + tmpltInfo.getInstallPath() + "is corrupted, please check in image store: " + tmpltStore.getDataStoreId();
+ msg = "Private Template (" + tmplt + ") with install path " + tmpltInfo.getInstallPath()
+ + "is corrupted, please check in image store: " + tmpltStore.getDataStoreId();
s_logger.warn(msg);
} else {
toBeDownloaded.add(tmplt);
@@ -340,6 +341,16 @@ public class TemplateServiceImpl implements TemplateService {
VMTemplateVO tmlpt = _templateDao.findById(tmplt.getId());
tmlpt.setSize(tmpltInfo.getSize());
_templateDao.update(tmplt.getId(), tmlpt);
+ // set template to 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 template " + tmplt.getUniqueName() + " state to Ready", e);
+ }
+ }
if (tmpltInfo.getSize() > 0 && tmplt.getUrl() != null) {
long accountId = tmplt.getAccountId();
@@ -349,8 +360,7 @@ public class TemplateServiceImpl implements TemplateService {
tmpltInfo.getSize() - UriUtils.getRemoteSize(tmplt.getUrl()));
} catch (ResourceAllocationException e) {
s_logger.warn(e.getMessage());
- _alertMgr.sendAlert(_alertMgr.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED, zoneId,
- null, e.getMessage(), e.getMessage());
+ _alertMgr.sendAlert(_alertMgr.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED, zoneId, null, e.getMessage(), e.getMessage());
} finally {
_resourceLimitMgr.recalculateResourceCount(accountId, _accountMgr.getAccount(accountId).getDomainId(),
com.cloud.configuration.Resource.ResourceType.secondary_storage.getOrdinal());
@@ -359,7 +369,8 @@ public class TemplateServiceImpl implements TemplateService {
}
_vmTemplateStoreDao.update(tmpltStore.getId(), tmpltStore);
} else {
- tmpltStore = new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, tmpltInfo.getInstallPath(), tmplt.getUrl());
+ tmpltStore = new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null,
+ tmpltInfo.getInstallPath(), tmplt.getUrl());
tmpltStore.setSize(tmpltInfo.getSize());
tmpltStore.setPhysicalSize(tmpltInfo.getPhysicalSize());
tmpltStore.setDataStoreRole(store.getRole());
@@ -370,24 +381,27 @@ public class TemplateServiceImpl implements TemplateService {
tmlpt.setSize(tmpltInfo.getSize());
_templateDao.update(tmplt.getId(), tmlpt);
associateTemplateToZone(tmplt.getId(), zoneId);
- }
- continue;
- }
- if (tmpltStore != null && tmpltStore.getDownloadState() != Status.DOWNLOADED) {
- s_logger.info("Template Sync did not find " + uniqueName + " ready on image store " + storeId + ", will request download to start/resume shortly");
- s_logger.info("Removing template " + uniqueName + " from template store table");
- // remove those leftover entries
- _vmTemplateStoreDao.remove(tmpltStore.getId());
-
- } else if (tmpltStore == null) {
- s_logger.info("Template Sync did not find " + uniqueName + " on the image store " + storeId + ", will request download shortly");
- // persist template_zone_ref table
- // TODO: we may have some bugs in removing these entries in case of failure, maybe we should pass another callback below in invoking createTemplateAsync
- // to just clear those entries.
- associateTemplateToZone(tmplt.getId(), zoneId);
+ // set template to 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 template " + tmplt.getUniqueName() + " state to Ready", e);
+ }
+ }
+ }
+ } else {
+ if (tmpltStore != null) {
+ s_logger.info("Template Sync did not find " + uniqueName + " on image store " + storeId
+ + ", may request download based on available hypervisor types");
+ s_logger.info("Removing leftover template " + uniqueName + " entry from template store table");
+ // remove those leftover entries
+ _vmTemplateStoreDao.remove(tmpltStore.getId());
+ }
}
-
}
if (toBeDownloaded.size() > 0) {
@@ -409,22 +423,14 @@ public class TemplateServiceImpl implements TemplateService {
// initiate the download
continue;
}
- // check if there is a record for this template in this store
- TemplateDataStoreVO tmpltStoreVO = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId());
- // if this is private template, and there is no record for this
- // template in this store, skip
- // TODO: don't understand this logic. What happens if we have a record for this template, still download?
+ // if this is private template, skip
if (!tmplt.isPublicTemplate() && !tmplt.isFeatured()) {
- if (tmpltStoreVO == null) {
- continue;
- }
+ continue;
}
if (availHypers.contains(tmplt.getHypervisorType())) {
- if (tmpltStoreVO != null && tmpltStoreVO.getDownloadState() == Status.DOWNLOADED) {
- continue;
- }
s_logger.info("Downloading template " + tmplt.getUniqueName() + " to image store " + store.getName());
+ associateTemplateToZone(tmplt.getId(), zoneId);
TemplateInfo tmpl = _templateFactory.getTemplate(tmplt.getId(), DataStoreRole.Image);
createTemplateAsync(tmpl, store, null);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/89f351c2/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index cbbbe94..1ac86c8 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -1751,10 +1751,14 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
if (((ImageStoreProvider) storeProvider).needDownloadSysTemplate()) {
// trigger system vm template download
this._imageSrv.downloadBootstrapSysTemplate(store);
- } else {
+ }
+ // for NFS, template store association will be populated in template sync phase
+ /*
+ else {
// populate template_store_ref table
this._imageSrv.addSystemVMTemplatesToSecondary(store);
}
+ */
// associate builtin template with zones associated with this image
// store