fix downloading template

This commit is contained in:
Edison Su 2013-01-30 21:06:12 -08:00 committed by Edison Su
parent a22403edcd
commit ec09e34f86
9 changed files with 36 additions and 31 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -20,5 +20,5 @@ package org.apache.cloudstack.engine.subsystem.api.storage;
public interface Scope {
public ScopeType getScopeType();
public long getScopeId();
public Long getScopeId();
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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();

View File

@ -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);

View File

@ -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);