Skip to content

Commit ec09e34

Browse files
Edison Susudison
authored andcommitted
fix downloading template
1 parent a22403e commit ec09e34

9 files changed

Lines changed: 36 additions & 31 deletions

File tree

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ClusterScope.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
public class ClusterScope implements Scope {
2323
private ScopeType type = ScopeType.CLUSTER;
24-
private long clusterId;
25-
private long podId;
26-
private long zoneId;
24+
private Long clusterId;
25+
private Long podId;
26+
private Long zoneId;
2727

28-
public ClusterScope(long clusterId, long podId, long zoneId) {
28+
public ClusterScope(Long clusterId, Long podId, Long zoneId) {
2929
this.clusterId = clusterId;
3030
this.podId = podId;
3131
this.zoneId = zoneId;
@@ -37,15 +37,15 @@ public ScopeType getScopeType() {
3737
}
3838

3939
@Override
40-
public long getScopeId() {
40+
public Long getScopeId() {
4141
return this.clusterId;
4242
}
4343

44-
public long getPodId() {
44+
public Long getPodId() {
4545
return this.podId;
4646
}
4747

48-
public long getZoneId() {
48+
public Long getZoneId() {
4949
return this.zoneId;
5050
}
5151

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
public class HostScope implements Scope {
2323
private ScopeType type = ScopeType.HOST;
24-
private long hostId;
25-
public HostScope(long hostId) {
24+
private Long hostId;
25+
public HostScope(Long hostId) {
2626
this.hostId = hostId;
2727
}
2828
@Override
@@ -31,7 +31,7 @@ public ScopeType getScopeType() {
3131
}
3232

3333
@Override
34-
public long getScopeId() {
34+
public Long getScopeId() {
3535
return this.hostId;
3636
}
3737
}

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/Scope.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020

2121
public interface Scope {
2222
public ScopeType getScopeType();
23-
public long getScopeId();
23+
public Long getScopeId();
2424
}

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ZoneScope.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
public class ZoneScope implements Scope {
2323
private ScopeType type = ScopeType.ZONE;
24-
private long zoneId;
24+
private Long zoneId;
2525

26-
public ZoneScope(long zoneId) {
26+
public ZoneScope(Long zoneId) {
2727
this.zoneId = zoneId;
2828
}
2929

@@ -33,7 +33,7 @@ public ScopeType getScopeType() {
3333
}
3434

3535
@Override
36-
public long getScopeId() {
36+
public Long getScopeId() {
3737
return this.zoneId;
3838
}
3939

server/src/com/cloud/storage/TemplateProfile.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.Map;
2020

21-
2221
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2322
import com.cloud.storage.Storage.ImageFormat;
2423

@@ -46,7 +45,7 @@ public class TemplateProfile {
4645
Long templateId;
4746
VMTemplateVO template;
4847
String templateTag;
49-
String imageStoreUuid;
48+
Long imageStoreId;
5049
Map details;
5150

5251
public TemplateProfile(Long templateId, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHvm,
@@ -85,11 +84,11 @@ public TemplateProfile(Long userId, VMTemplateVO template, Long zoneId) {
8584
public TemplateProfile(Long templateId, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHvm,
8685
String url, Boolean isPublic, Boolean featured, Boolean isExtractable, ImageFormat format, Long guestOsId, Long zoneId,
8786
HypervisorType hypervisorType, String accountName, Long domainId, Long accountId, String chksum, Boolean bootable, String templateTag, Map details, Boolean sshKeyEnabled,
88-
String imageStoreUuid) {
87+
Long imageStoreId) {
8988
this(templateId, userId, name, displayText, bits, passwordEnabled, requiresHvm, url, isPublic, featured, isExtractable, format, guestOsId, zoneId,
9089
hypervisorType, accountName, domainId, accountId, chksum, bootable, details, sshKeyEnabled);
9190
this.templateTag = templateTag;
92-
this.imageStoreUuid = imageStoreUuid;
91+
this.imageStoreId = imageStoreId;
9392
}
9493

9594
public Long getTemplateId() {
@@ -256,7 +255,7 @@ public Boolean getSshKeyEnabled() {
256255
return this.sshKeyEnbaled;
257256
}
258257

259-
public String getImageStoreUuid() {
260-
return this.imageStoreUuid;
258+
public Long getImageStoreId() {
259+
return this.imageStoreId;
261260
}
262261
}

server/src/com/cloud/template/HyervisorTemplateAdapter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
3535
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
3636
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
37+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
3738
import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataFactory;
3839
import org.apache.cloudstack.engine.subsystem.api.storage.ImageService;
3940
import org.apache.cloudstack.framework.async.AsyncCallFuture;
@@ -54,8 +55,8 @@
5455
import com.cloud.storage.Storage.TemplateType;
5556
import com.cloud.storage.TemplateProfile;
5657
import com.cloud.storage.VMTemplateHostVO;
57-
import com.cloud.storage.VMTemplateVO;
5858
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
59+
import com.cloud.storage.VMTemplateVO;
5960
import com.cloud.storage.VMTemplateZoneVO;
6061
import com.cloud.storage.download.DownloadMonitor;
6162
import com.cloud.storage.secondary.SecondaryStorageVmManager;
@@ -79,6 +80,7 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
7980
@Inject DownloadMonitor _downloadMonitor;
8081
@Inject SecondaryStorageVmManager _ssvmMgr;
8182
@Inject AgentManager _agentMgr;
83+
8284
@Inject DataStoreManager storeMgr;
8385
@Inject ImageService imageService;
8486
@Inject ImageDataFactory imageFactory;
@@ -89,8 +91,6 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
8991
public String getName() {
9092
return TemplateAdapterType.Hypervisor.getName();
9193
}
92-
93-
9494

9595
private String validateUrl(String url) {
9696
try {
@@ -171,7 +171,7 @@ public VMTemplateVO create(TemplateProfile profile) {
171171
throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate());
172172
}
173173

174-
DataStore imageStore = this.templateMgr.getImageStore(profile.getImageStoreUuid(), profile.getZoneId());
174+
DataStore imageStore = this.storeMgr.getDataStore(profile.getImageStoreId(), DataStoreRole.Image);
175175

176176
AsyncCallFuture<CommandResult> future = this.imageService.createTemplateAsync(this.imageFactory.getTemplate(template.getId()), imageStore);
177177
try {

server/src/com/cloud/template/TemplateAdapterBase.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Map;
2121

2222
import javax.inject.Inject;
23-
import javax.naming.ConfigurationException;
2423

2524
import org.apache.cloudstack.api.ApiConstants;
2625
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
@@ -46,10 +45,10 @@
4645
import com.cloud.hypervisor.Hypervisor.HypervisorType;
4746
import com.cloud.org.Grouping;
4847
import com.cloud.storage.GuestOS;
49-
import com.cloud.storage.VMTemplateVO;
5048
import com.cloud.storage.Storage.ImageFormat;
5149
import com.cloud.storage.Storage.TemplateType;
5250
import com.cloud.storage.TemplateProfile;
51+
import com.cloud.storage.VMTemplateVO;
5352
import com.cloud.storage.dao.VMTemplateDao;
5453
import com.cloud.storage.dao.VMTemplateHostDao;
5554
import com.cloud.storage.dao.VMTemplateZoneDao;
@@ -80,6 +79,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
8079
protected @Inject HostDao _hostDao;
8180
protected @Inject ResourceLimitService _resourceLimitMgr;
8281
protected @Inject DataStoreManager storeMgr;
82+
@Inject TemplateManager templateMgr;
8383

8484
@Override
8585
public boolean stop() {
@@ -211,10 +211,16 @@ public TemplateProfile prepare(boolean isIso, long userId, String name, String d
211211
}
212212
}
213213

214+
DataStore imageStore = this.templateMgr.getImageStore(imageStoreUuid, zoneId);
215+
if (imageStore == null) {
216+
throw new IllegalArgumentException("Cann't find an image store");
217+
}
218+
Long imageStoreId = imageStore.getId();
219+
214220
Long id = _tmpltDao.getNextInSequence(Long.class, "id");
215221
UserContext.current().setEventDetails("Id: " +id+ " name: " + name);
216222
return new TemplateProfile(id, userId, name, displayText, bits, passwordEnabled, requiresHVM, url, isPublic,
217-
featured, isExtractable, imgfmt, guestOSId, zoneId, hypervisorType, templateOwner.getAccountName(), templateOwner.getDomainId(), templateOwner.getAccountId(), chksum, bootable, templateTag, details, sshkeyEnabled, imageStoreUuid);
223+
featured, isExtractable, imgfmt, guestOSId, zoneId, hypervisorType, templateOwner.getAccountName(), templateOwner.getDomainId(), templateOwner.getAccountId(), chksum, bootable, templateTag, details, sshkeyEnabled, imageStoreId);
218224
}
219225

220226
@Override
@@ -224,7 +230,7 @@ public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocatio
224230
Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
225231
_accountMgr.checkAccess(caller, null, true, owner);
226232

227-
233+
228234

229235
return prepare(false, UserContext.current().getCallerUserId(), cmd.getTemplateName(), cmd.getDisplayText(),
230236
cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), cmd.getUrl(), cmd.isPublic(), cmd.isFeatured(),
@@ -251,7 +257,7 @@ protected VMTemplateVO persistTemplate(TemplateProfile profile) {
251257
profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(),
252258
profile.getDetails(), profile.getSshKeyEnabled());
253259

254-
260+
template.setImageDataStoreId(profile.getImageStoreId());
255261
if (zoneId == null || zoneId.longValue() == -1) {
256262
List<DataCenterVO> dcs = _dcDao.listAll();
257263

server/src/com/cloud/template/TemplateManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ VMTemplateHostVO getTemplateHostRef(long zoneId, long tmpltId,
113113

114114
Long getTemplateSize(long templateId, long zoneId);
115115

116-
DataStore getImageStore(String storeUuid, long zoneId);
116+
DataStore getImageStore(String storeUuid, Long zoneId);
117117

118118
String getChecksum(Long hostId, String templatePath);
119119

server/src/com/cloud/template/TemplateManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws U
320320
}
321321

322322
@Override
323-
public DataStore getImageStore(String storeUuid, long zoneId) {
323+
public DataStore getImageStore(String storeUuid, Long zoneId) {
324324
DataStore imageStore = null;
325325
if (storeUuid != null) {
326326
imageStore = this.dataStoreMgr.getDataStore(storeUuid, DataStoreRole.Image);

0 commit comments

Comments
 (0)