mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
fix downloading template
This commit is contained in:
parent
a22403edcd
commit
ec09e34f86
@ -21,11 +21,11 @@ package org.apache.cloudstack.engine.subsystem.api.storage;
|
|||||||
|
|
||||||
public class ClusterScope implements Scope {
|
public class ClusterScope implements Scope {
|
||||||
private ScopeType type = ScopeType.CLUSTER;
|
private ScopeType type = ScopeType.CLUSTER;
|
||||||
private long clusterId;
|
private Long clusterId;
|
||||||
private long podId;
|
private Long podId;
|
||||||
private long zoneId;
|
private Long zoneId;
|
||||||
|
|
||||||
public ClusterScope(long clusterId, long podId, long zoneId) {
|
public ClusterScope(Long clusterId, Long podId, Long zoneId) {
|
||||||
this.clusterId = clusterId;
|
this.clusterId = clusterId;
|
||||||
this.podId = podId;
|
this.podId = podId;
|
||||||
this.zoneId = zoneId;
|
this.zoneId = zoneId;
|
||||||
@ -37,15 +37,15 @@ public class ClusterScope implements Scope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getScopeId() {
|
public Long getScopeId() {
|
||||||
return this.clusterId;
|
return this.clusterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getPodId() {
|
public Long getPodId() {
|
||||||
return this.podId;
|
return this.podId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getZoneId() {
|
public Long getZoneId() {
|
||||||
return this.zoneId;
|
return this.zoneId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,8 +21,8 @@ package org.apache.cloudstack.engine.subsystem.api.storage;
|
|||||||
|
|
||||||
public class HostScope implements Scope {
|
public class HostScope implements Scope {
|
||||||
private ScopeType type = ScopeType.HOST;
|
private ScopeType type = ScopeType.HOST;
|
||||||
private long hostId;
|
private Long hostId;
|
||||||
public HostScope(long hostId) {
|
public HostScope(Long hostId) {
|
||||||
this.hostId = hostId;
|
this.hostId = hostId;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@ -31,7 +31,7 @@ public class HostScope implements Scope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getScopeId() {
|
public Long getScopeId() {
|
||||||
return this.hostId;
|
return this.hostId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,5 +20,5 @@ package org.apache.cloudstack.engine.subsystem.api.storage;
|
|||||||
|
|
||||||
public interface Scope {
|
public interface Scope {
|
||||||
public ScopeType getScopeType();
|
public ScopeType getScopeType();
|
||||||
public long getScopeId();
|
public Long getScopeId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,9 +21,9 @@ package org.apache.cloudstack.engine.subsystem.api.storage;
|
|||||||
|
|
||||||
public class ZoneScope implements Scope {
|
public class ZoneScope implements Scope {
|
||||||
private ScopeType type = ScopeType.ZONE;
|
private ScopeType type = ScopeType.ZONE;
|
||||||
private long zoneId;
|
private Long zoneId;
|
||||||
|
|
||||||
public ZoneScope(long zoneId) {
|
public ZoneScope(Long zoneId) {
|
||||||
this.zoneId = zoneId;
|
this.zoneId = zoneId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class ZoneScope implements Scope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getScopeId() {
|
public Long getScopeId() {
|
||||||
return this.zoneId;
|
return this.zoneId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,6 @@ package com.cloud.storage;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||||
import com.cloud.storage.Storage.ImageFormat;
|
import com.cloud.storage.Storage.ImageFormat;
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ public class TemplateProfile {
|
|||||||
Long templateId;
|
Long templateId;
|
||||||
VMTemplateVO template;
|
VMTemplateVO template;
|
||||||
String templateTag;
|
String templateTag;
|
||||||
String imageStoreUuid;
|
Long imageStoreId;
|
||||||
Map details;
|
Map details;
|
||||||
|
|
||||||
public TemplateProfile(Long templateId, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHvm,
|
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,
|
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,
|
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,
|
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,
|
this(templateId, userId, name, displayText, bits, passwordEnabled, requiresHvm, url, isPublic, featured, isExtractable, format, guestOsId, zoneId,
|
||||||
hypervisorType, accountName, domainId, accountId, chksum, bootable, details, sshKeyEnabled);
|
hypervisorType, accountName, domainId, accountId, chksum, bootable, details, sshKeyEnabled);
|
||||||
this.templateTag = templateTag;
|
this.templateTag = templateTag;
|
||||||
this.imageStoreUuid = imageStoreUuid;
|
this.imageStoreId = imageStoreId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getTemplateId() {
|
public Long getTemplateId() {
|
||||||
@ -256,7 +255,7 @@ public class TemplateProfile {
|
|||||||
return this.sshKeyEnbaled;
|
return this.sshKeyEnbaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getImageStoreUuid() {
|
public Long getImageStoreId() {
|
||||||
return this.imageStoreUuid;
|
return this.imageStoreId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.CommandResult;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
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.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.ImageDataFactory;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.ImageService;
|
import org.apache.cloudstack.engine.subsystem.api.storage.ImageService;
|
||||||
import org.apache.cloudstack.framework.async.AsyncCallFuture;
|
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.Storage.TemplateType;
|
||||||
import com.cloud.storage.TemplateProfile;
|
import com.cloud.storage.TemplateProfile;
|
||||||
import com.cloud.storage.VMTemplateHostVO;
|
import com.cloud.storage.VMTemplateHostVO;
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||||
|
import com.cloud.storage.VMTemplateVO;
|
||||||
import com.cloud.storage.VMTemplateZoneVO;
|
import com.cloud.storage.VMTemplateZoneVO;
|
||||||
import com.cloud.storage.download.DownloadMonitor;
|
import com.cloud.storage.download.DownloadMonitor;
|
||||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||||
@ -79,6 +80,7 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||||||
@Inject DownloadMonitor _downloadMonitor;
|
@Inject DownloadMonitor _downloadMonitor;
|
||||||
@Inject SecondaryStorageVmManager _ssvmMgr;
|
@Inject SecondaryStorageVmManager _ssvmMgr;
|
||||||
@Inject AgentManager _agentMgr;
|
@Inject AgentManager _agentMgr;
|
||||||
|
|
||||||
@Inject DataStoreManager storeMgr;
|
@Inject DataStoreManager storeMgr;
|
||||||
@Inject ImageService imageService;
|
@Inject ImageService imageService;
|
||||||
@Inject ImageDataFactory imageFactory;
|
@Inject ImageDataFactory imageFactory;
|
||||||
@ -90,8 +92,6 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||||||
return TemplateAdapterType.Hypervisor.getName();
|
return TemplateAdapterType.Hypervisor.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String validateUrl(String url) {
|
private String validateUrl(String url) {
|
||||||
try {
|
try {
|
||||||
URI uri = new URI(url);
|
URI uri = new URI(url);
|
||||||
@ -171,7 +171,7 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
|||||||
throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate());
|
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);
|
AsyncCallFuture<CommandResult> future = this.imageService.createTemplateAsync(this.imageFactory.getTemplate(template.getId()), imageStore);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -20,7 +20,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.naming.ConfigurationException;
|
|
||||||
|
|
||||||
import org.apache.cloudstack.api.ApiConstants;
|
import org.apache.cloudstack.api.ApiConstants;
|
||||||
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
|
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.hypervisor.Hypervisor.HypervisorType;
|
||||||
import com.cloud.org.Grouping;
|
import com.cloud.org.Grouping;
|
||||||
import com.cloud.storage.GuestOS;
|
import com.cloud.storage.GuestOS;
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.storage.Storage.ImageFormat;
|
import com.cloud.storage.Storage.ImageFormat;
|
||||||
import com.cloud.storage.Storage.TemplateType;
|
import com.cloud.storage.Storage.TemplateType;
|
||||||
import com.cloud.storage.TemplateProfile;
|
import com.cloud.storage.TemplateProfile;
|
||||||
|
import com.cloud.storage.VMTemplateVO;
|
||||||
import com.cloud.storage.dao.VMTemplateDao;
|
import com.cloud.storage.dao.VMTemplateDao;
|
||||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||||
import com.cloud.storage.dao.VMTemplateZoneDao;
|
import com.cloud.storage.dao.VMTemplateZoneDao;
|
||||||
@ -80,6 +79,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
|
|||||||
protected @Inject HostDao _hostDao;
|
protected @Inject HostDao _hostDao;
|
||||||
protected @Inject ResourceLimitService _resourceLimitMgr;
|
protected @Inject ResourceLimitService _resourceLimitMgr;
|
||||||
protected @Inject DataStoreManager storeMgr;
|
protected @Inject DataStoreManager storeMgr;
|
||||||
|
@Inject TemplateManager templateMgr;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean stop() {
|
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");
|
Long id = _tmpltDao.getNextInSequence(Long.class, "id");
|
||||||
UserContext.current().setEventDetails("Id: " +id+ " name: " + name);
|
UserContext.current().setEventDetails("Id: " +id+ " name: " + name);
|
||||||
return new TemplateProfile(id, userId, name, displayText, bits, passwordEnabled, requiresHVM, url, isPublic,
|
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
|
@Override
|
||||||
@ -251,7 +257,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
|
|||||||
profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(),
|
profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(),
|
||||||
profile.getDetails(), profile.getSshKeyEnabled());
|
profile.getDetails(), profile.getSshKeyEnabled());
|
||||||
|
|
||||||
|
template.setImageDataStoreId(profile.getImageStoreId());
|
||||||
if (zoneId == null || zoneId.longValue() == -1) {
|
if (zoneId == null || zoneId.longValue() == -1) {
|
||||||
List<DataCenterVO> dcs = _dcDao.listAll();
|
List<DataCenterVO> dcs = _dcDao.listAll();
|
||||||
|
|
||||||
|
|||||||
@ -113,7 +113,7 @@ public interface TemplateManager extends TemplateService{
|
|||||||
|
|
||||||
Long getTemplateSize(long templateId, long zoneId);
|
Long getTemplateSize(long templateId, long zoneId);
|
||||||
|
|
||||||
DataStore getImageStore(String storeUuid, long zoneId);
|
DataStore getImageStore(String storeUuid, Long zoneId);
|
||||||
|
|
||||||
String getChecksum(Long hostId, String templatePath);
|
String getChecksum(Long hostId, String templatePath);
|
||||||
|
|
||||||
|
|||||||
@ -320,7 +320,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataStore getImageStore(String storeUuid, long zoneId) {
|
public DataStore getImageStore(String storeUuid, Long zoneId) {
|
||||||
DataStore imageStore = null;
|
DataStore imageStore = null;
|
||||||
if (storeUuid != null) {
|
if (storeUuid != null) {
|
||||||
imageStore = this.dataStoreMgr.getDataStore(storeUuid, DataStoreRole.Image);
|
imageStore = this.dataStoreMgr.getDataStore(storeUuid, DataStoreRole.Image);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user