Updated Branches: refs/heads/object_store 89f351c2e -> 863b53406
Copy iso from S3 to Cache in attach iso to VM. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/863b5340 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/863b5340 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/863b5340 Branch: refs/heads/object_store Commit: 863b534066e43d30fc3f9febd425405a6574605e Parents: 89f351c Author: Min Chen <[email protected]> Authored: Fri May 24 13:56:08 2013 -0700 Committer: Min Chen <[email protected]> Committed: Fri May 24 13:56:08 2013 -0700 ---------------------------------------------------------------------- .../com/cloud/template/TemplateManagerImpl.java | 29 +++++++++++++-- 1 files changed, 26 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/863b5340/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 c828773..495e8e5 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -55,6 +55,8 @@ 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.StorageCacheManager; import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory; @@ -67,9 +69,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; import org.apache.cloudstack.framework.async.AsyncCallFuture; import org.apache.cloudstack.storage.command.AttachCommand; import org.apache.cloudstack.storage.command.CommandResult; +import org.apache.cloudstack.storage.command.CopyCommand; import org.apache.cloudstack.storage.command.DettachCommand; import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; -import org.apache.cloudstack.storage.datastore.db.ImageStoreVO; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; @@ -81,13 +83,13 @@ import org.springframework.stereotype.Component; import com.amazonaws.services.s3.model.CannedAccessControlList; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; -import com.cloud.agent.api.AttachIsoCommand; import com.cloud.agent.api.Command; import com.cloud.agent.api.ComputeChecksumCommand; import com.cloud.agent.api.storage.DestroyCommand; import com.cloud.agent.api.to.DataTO; import com.cloud.agent.api.to.DiskTO; +import com.cloud.agent.api.to.NfsTO; import com.cloud.agent.api.to.S3TO; import com.cloud.api.ApiDBUtils; import com.cloud.api.query.dao.UserVmJoinDao; @@ -272,6 +274,12 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, @Inject protected List<TemplateAdapter> _adapters; + @Inject + StorageCacheManager cacheMgr; + @Inject + EndPointSelector selector; + + private TemplateAdapter getAdapter(HypervisorType type) { TemplateAdapter adapter = null; if (type == HypervisorType.BareMetal) { @@ -1050,12 +1058,27 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, } else if (vm.getState() != State.Running) { return true; } - //FIXME: if it's s3, need to download into cache store TemplateInfo tmplt = this._tmplFactory.getTemplate(isoId, DataStoreRole.Image, vm.getDataCenterId()); if (tmplt == null) { s_logger.warn("ISO: " + isoId + " does not exist"); return false; } + if (tmplt.getDataStore() != null && !(tmplt.getDataStore().getTO() instanceof NfsTO)) { + String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString()); + int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue())); + // if it is s3, need to download into cache storage first + Scope destScope = new ZoneScope(vm.getDataCenterId()); + TemplateInfo cacheData = (TemplateInfo) cacheMgr.createCacheObject(tmplt, destScope); + CopyCommand cmd = new CopyCommand(tmplt.getTO(), cacheData.getTO(), _primaryStorageDownloadWait); + EndPoint ep = selector.select(tmplt, cacheData); + Answer answer = ep.sendMessage(cmd); + if (answer != null && answer.getResult()) { + tmplt = cacheData; + } else { + s_logger.error("Failed in copy iso from S3 to cache storage"); + return false; + } + } String vmName = vm.getInstanceName();
