fix downloading template
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/265d7c99 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/265d7c99 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/265d7c99 Branch: refs/heads/storage_refactor Commit: 265d7c99c83d0e96fe0c7d283ecb91fc458f8078 Parents: a9b7935 Author: Edison Su <[email protected]> Authored: Wed Jan 30 21:06:12 2013 -0800 Committer: Edison Su <[email protected]> Committed: Wed Feb 13 15:28:43 2013 -0800 ---------------------------------------------------------------------- .../engine/subsystem/api/storage/ClusterScope.java | 14 ++++++------ .../engine/subsystem/api/storage/HostScope.java | 6 ++-- .../engine/subsystem/api/storage/Scope.java | 2 +- .../engine/subsystem/api/storage/ZoneScope.java | 6 ++-- server/src/com/cloud/storage/TemplateProfile.java | 11 ++++----- .../cloud/template/HyervisorTemplateAdapter.java | 8 +++--- .../com/cloud/template/TemplateAdapterBase.java | 16 ++++++++++---- server/src/com/cloud/template/TemplateManager.java | 2 +- .../com/cloud/template/TemplateManagerImpl.java | 2 +- 9 files changed, 36 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/265d7c99/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ClusterScope.java ---------------------------------------------------------------------- diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ClusterScope.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ClusterScope.java index 50d5444..fce7d82 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ClusterScope.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ClusterScope.java @@ -21,11 +21,11 @@ package org.apache.cloudstack.engine.subsystem.api.storage; public class ClusterScope implements Scope { private ScopeType type = ScopeType.CLUSTER; - private long clusterId; - private long podId; - private long zoneId; + private Long clusterId; + private Long podId; + private Long zoneId; - public ClusterScope(long clusterId, long podId, long zoneId) { + public ClusterScope(Long clusterId, Long podId, Long zoneId) { this.clusterId = clusterId; this.podId = podId; this.zoneId = zoneId; @@ -37,15 +37,15 @@ public class ClusterScope implements Scope { } @Override - public long getScopeId() { + public Long getScopeId() { return this.clusterId; } - public long getPodId() { + public Long getPodId() { return this.podId; } - public long getZoneId() { + public Long getZoneId() { return this.zoneId; } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/265d7c99/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java ---------------------------------------------------------------------- diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java index da36e43..71d1952 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java @@ -21,8 +21,8 @@ package org.apache.cloudstack.engine.subsystem.api.storage; public class HostScope implements Scope { private ScopeType type = ScopeType.HOST; - private long hostId; - public HostScope(long hostId) { + private Long hostId; + public HostScope(Long hostId) { this.hostId = hostId; } @Override @@ -31,7 +31,7 @@ public class HostScope implements Scope { } @Override - public long getScopeId() { + public Long getScopeId() { return this.hostId; } } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/265d7c99/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/Scope.java ---------------------------------------------------------------------- diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/Scope.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/Scope.java index a9601a1..c1596d4 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/Scope.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/Scope.java @@ -20,5 +20,5 @@ package org.apache.cloudstack.engine.subsystem.api.storage; public interface Scope { public ScopeType getScopeType(); - public long getScopeId(); + public Long getScopeId(); } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/265d7c99/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ZoneScope.java ---------------------------------------------------------------------- diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ZoneScope.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ZoneScope.java index 7f211f4..ac277af 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ZoneScope.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ZoneScope.java @@ -21,9 +21,9 @@ package org.apache.cloudstack.engine.subsystem.api.storage; public class ZoneScope implements Scope { private ScopeType type = ScopeType.ZONE; - private long zoneId; + private Long zoneId; - public ZoneScope(long zoneId) { + public ZoneScope(Long zoneId) { this.zoneId = zoneId; } @@ -33,7 +33,7 @@ public class ZoneScope implements Scope { } @Override - public long getScopeId() { + public Long getScopeId() { return this.zoneId; } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/265d7c99/server/src/com/cloud/storage/TemplateProfile.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/TemplateProfile.java b/server/src/com/cloud/storage/TemplateProfile.java index 41bbaaa..0b55f1f 100755 --- a/server/src/com/cloud/storage/TemplateProfile.java +++ b/server/src/com/cloud/storage/TemplateProfile.java @@ -18,7 +18,6 @@ package com.cloud.storage; import java.util.Map; - import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.Storage.ImageFormat; @@ -46,7 +45,7 @@ public class TemplateProfile { Long templateId; VMTemplateVO template; String templateTag; - String imageStoreUuid; + Long imageStoreId; Map details; public TemplateProfile(Long templateId, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHvm, @@ -85,11 +84,11 @@ public class TemplateProfile { public TemplateProfile(Long templateId, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHvm, String url, Boolean isPublic, Boolean featured, Boolean isExtractable, ImageFormat format, Long guestOsId, Long zoneId, HypervisorType hypervisorType, String accountName, Long domainId, Long accountId, String chksum, Boolean bootable, String templateTag, Map details, Boolean sshKeyEnabled, - String imageStoreUuid) { + Long imageStoreId) { this(templateId, userId, name, displayText, bits, passwordEnabled, requiresHvm, url, isPublic, featured, isExtractable, format, guestOsId, zoneId, hypervisorType, accountName, domainId, accountId, chksum, bootable, details, sshKeyEnabled); this.templateTag = templateTag; - this.imageStoreUuid = imageStoreUuid; + this.imageStoreId = imageStoreId; } public Long getTemplateId() { @@ -256,7 +255,7 @@ public class TemplateProfile { return this.sshKeyEnbaled; } - public String getImageStoreUuid() { - return this.imageStoreUuid; + public Long getImageStoreId() { + return this.imageStoreId; } } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/265d7c99/server/src/com/cloud/template/HyervisorTemplateAdapter.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/template/HyervisorTemplateAdapter.java b/server/src/com/cloud/template/HyervisorTemplateAdapter.java index fa72e75..c1177f4 100755 --- a/server/src/com/cloud/template/HyervisorTemplateAdapter.java +++ b/server/src/com/cloud/template/HyervisorTemplateAdapter.java @@ -34,6 +34,7 @@ import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd; import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult; 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.DataStoreRole; import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.ImageService; import org.apache.cloudstack.framework.async.AsyncCallFuture; @@ -54,8 +55,8 @@ import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.TemplateType; import com.cloud.storage.TemplateProfile; import com.cloud.storage.VMTemplateHostVO; -import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; +import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VMTemplateZoneVO; import com.cloud.storage.download.DownloadMonitor; import com.cloud.storage.secondary.SecondaryStorageVmManager; @@ -79,6 +80,7 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem @Inject DownloadMonitor _downloadMonitor; @Inject SecondaryStorageVmManager _ssvmMgr; @Inject AgentManager _agentMgr; + @Inject DataStoreManager storeMgr; @Inject ImageService imageService; @Inject ImageDataFactory imageFactory; @@ -89,8 +91,6 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem public String getName() { return TemplateAdapterType.Hypervisor.getName(); } - - private String validateUrl(String url) { try { @@ -171,7 +171,7 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate()); } - DataStore imageStore = this.templateMgr.getImageStore(profile.getImageStoreUuid(), profile.getZoneId()); + DataStore imageStore = this.storeMgr.getDataStore(profile.getImageStoreId(), DataStoreRole.Image); AsyncCallFuture<CommandResult> future = this.imageService.createTemplateAsync(this.imageFactory.getTemplate(template.getId()), imageStore); try { http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/265d7c99/server/src/com/cloud/template/TemplateAdapterBase.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/template/TemplateAdapterBase.java b/server/src/com/cloud/template/TemplateAdapterBase.java index c5074ad..247ce63 100755 --- a/server/src/com/cloud/template/TemplateAdapterBase.java +++ b/server/src/com/cloud/template/TemplateAdapterBase.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; import javax.inject.Inject; -import javax.naming.ConfigurationException; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd; @@ -46,10 +45,10 @@ import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.org.Grouping; import com.cloud.storage.GuestOS; -import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.TemplateType; import com.cloud.storage.TemplateProfile; +import com.cloud.storage.VMTemplateVO; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.dao.VMTemplateZoneDao; @@ -80,6 +79,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat protected @Inject HostDao _hostDao; protected @Inject ResourceLimitService _resourceLimitMgr; protected @Inject DataStoreManager storeMgr; + @Inject TemplateManager templateMgr; @Override public boolean stop() { @@ -211,10 +211,16 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat } } + DataStore imageStore = this.templateMgr.getImageStore(imageStoreUuid, zoneId); + if (imageStore == null) { + throw new IllegalArgumentException("Cann't find an image store"); + } + Long imageStoreId = imageStore.getId(); + Long id = _tmpltDao.getNextInSequence(Long.class, "id"); UserContext.current().setEventDetails("Id: " +id+ " name: " + name); return new TemplateProfile(id, userId, name, displayText, bits, passwordEnabled, requiresHVM, url, isPublic, - featured, isExtractable, imgfmt, guestOSId, zoneId, hypervisorType, templateOwner.getAccountName(), templateOwner.getDomainId(), templateOwner.getAccountId(), chksum, bootable, templateTag, details, sshkeyEnabled, imageStoreUuid); + featured, isExtractable, imgfmt, guestOSId, zoneId, hypervisorType, templateOwner.getAccountName(), templateOwner.getDomainId(), templateOwner.getAccountId(), chksum, bootable, templateTag, details, sshkeyEnabled, imageStoreId); } @Override @@ -224,7 +230,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId()); _accountMgr.checkAccess(caller, null, true, owner); - + return prepare(false, UserContext.current().getCallerUserId(), cmd.getTemplateName(), cmd.getDisplayText(), cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), cmd.getUrl(), cmd.isPublic(), cmd.isFeatured(), @@ -251,7 +257,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(), profile.getDetails(), profile.getSshKeyEnabled()); - + template.setImageDataStoreId(profile.getImageStoreId()); if (zoneId == null || zoneId.longValue() == -1) { List<DataCenterVO> dcs = _dcDao.listAll(); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/265d7c99/server/src/com/cloud/template/TemplateManager.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/template/TemplateManager.java b/server/src/com/cloud/template/TemplateManager.java index 1b05461..19ba3b5 100755 --- a/server/src/com/cloud/template/TemplateManager.java +++ b/server/src/com/cloud/template/TemplateManager.java @@ -113,7 +113,7 @@ public interface TemplateManager extends TemplateService{ Long getTemplateSize(long templateId, long zoneId); - DataStore getImageStore(String storeUuid, long zoneId); + DataStore getImageStore(String storeUuid, Long zoneId); String getChecksum(Long hostId, String templatePath); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/265d7c99/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 736f712..101c3d9 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -320,7 +320,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, } @Override - public DataStore getImageStore(String storeUuid, long zoneId) { + public DataStore getImageStore(String storeUuid, Long zoneId) { DataStore imageStore = null; if (storeUuid != null) { imageStore = this.dataStoreMgr.getDataStore(storeUuid, DataStoreRole.Image);
