mirror of https://github.com/apache/cloudstack.git
bug CS-10789: Put zone id in the volumehost ref table. make list volume to show the percent uploaded.
This commit is contained in:
parent
fe3200c72e
commit
9097b53eab
|
|
@ -41,9 +41,6 @@ public class UploadVolumeCmd extends BaseCmd {
|
|||
@Parameter(name=ApiConstants.FORMAT, type=CommandType.STRING, required=true, description="the format for the volume. Possible values include QCOW2, OVA, and VHD.")
|
||||
private String format;
|
||||
|
||||
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, required=true, description="the target hypervisor for the volume")
|
||||
private String hypervisor;
|
||||
|
||||
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the volume")
|
||||
private String volumeName;
|
||||
|
||||
|
|
@ -72,10 +69,6 @@ public class UploadVolumeCmd extends BaseCmd {
|
|||
return format;
|
||||
}
|
||||
|
||||
public String getHypervisor() {
|
||||
return hypervisor;
|
||||
}
|
||||
|
||||
public String getVolumeName() {
|
||||
return volumeName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,6 +142,10 @@ public class VolumeResponse extends BaseResponse implements ControlledEntityResp
|
|||
@SerializedName("isextractable")
|
||||
@Param(description = "true if the volume is extractable, false otherwise")
|
||||
private Boolean extractable;
|
||||
|
||||
@SerializedName(ApiConstants.STATUS)
|
||||
@Param(description="the status of the volume")
|
||||
private String status;
|
||||
|
||||
@Override
|
||||
public Long getObjectId() {
|
||||
|
|
@ -260,7 +264,11 @@ public class VolumeResponse extends BaseResponse implements ControlledEntityResp
|
|||
this.serviceOfferingName = serviceOfferingName;
|
||||
}
|
||||
|
||||
public void setServiceOfferingDisplayText(String serviceOfferingDisplayText) {
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void setServiceOfferingDisplayText(String serviceOfferingDisplayText) {
|
||||
this.serviceOfferingDisplayText = serviceOfferingDisplayText;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import javax.persistence.Temporal;
|
|||
import javax.persistence.TemporalType;
|
||||
|
||||
//import com.cloud.storage.VMVolumeStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
||||
|
|
@ -35,6 +36,9 @@ public class VolumeHostVO {
|
|||
@Column(name="volume_id")
|
||||
private long volumeId;
|
||||
|
||||
@Column(name="zone_id")
|
||||
private long zoneId;
|
||||
|
||||
@Column(name=GenericDaoBase.CREATED_COLUMN)
|
||||
private Date created = null;
|
||||
|
||||
|
|
@ -103,7 +107,15 @@ public class VolumeHostVO {
|
|||
}
|
||||
|
||||
|
||||
public int getDownloadPercent() {
|
||||
public long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
public void setZoneId(long zoneId) {
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
|
||||
public int getDownloadPercent() {
|
||||
return downloadPercent;
|
||||
}
|
||||
|
||||
|
|
@ -161,13 +173,14 @@ public class VolumeHostVO {
|
|||
this.volumeId = volumeId;
|
||||
}
|
||||
|
||||
public VolumeHostVO(long hostId, long volumeId, Date lastUpdated,
|
||||
public VolumeHostVO(long hostId, long volumeId, long zoneId, Date lastUpdated,
|
||||
int downloadPercent, Status downloadState,
|
||||
String localDownloadPath, String errorString, String jobId,
|
||||
String installPath, String downloadUrl, String checksum) {
|
||||
String installPath, String downloadUrl, String checksum, ImageFormat format) {
|
||||
//super();
|
||||
this.hostId = hostId;
|
||||
this.volumeId = volumeId;
|
||||
this.zoneId = zoneId;
|
||||
this.lastUpdated = lastUpdated;
|
||||
this.downloadPercent = downloadPercent;
|
||||
this.downloadState = downloadState;
|
||||
|
|
@ -177,6 +190,7 @@ public class VolumeHostVO {
|
|||
this.installPath = installPath;
|
||||
this.setDownloadUrl(downloadUrl);
|
||||
this.checksum = checksum;
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
protected VolumeHostVO() {
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ import com.cloud.storage.UploadVO;
|
|||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateSwiftVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VolumeHostVO;
|
||||
import com.cloud.storage.Volume.Type;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.DiskOfferingDao;
|
||||
|
|
@ -104,6 +105,7 @@ import com.cloud.storage.dao.VMTemplateDetailsDao;
|
|||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
import com.cloud.storage.dao.VMTemplateSwiftDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.dao.VolumeHostDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountDetailsDao;
|
||||
import com.cloud.user.AccountVO;
|
||||
|
|
@ -170,6 +172,7 @@ public class ApiDBUtils {
|
|||
private static UserVmDao _userVmDao;
|
||||
private static VlanDao _vlanDao;
|
||||
private static VolumeDao _volumeDao;
|
||||
private static VolumeHostDao _volumeHostDao;
|
||||
private static DataCenterDao _zoneDao;
|
||||
private static NetworkOfferingDao _networkOfferingDao;
|
||||
private static NetworkDao _networkDao;
|
||||
|
|
@ -222,6 +225,7 @@ public class ApiDBUtils {
|
|||
_userVmDao = locator.getDao(UserVmDao.class);
|
||||
_vlanDao = locator.getDao(VlanDao.class);
|
||||
_volumeDao = locator.getDao(VolumeDao.class);
|
||||
_volumeHostDao = locator.getDao(VolumeHostDao.class);
|
||||
_zoneDao = locator.getDao(DataCenterDao.class);
|
||||
_securityGroupDao = locator.getDao(SecurityGroupDao.class);
|
||||
_networkOfferingDao = locator.getDao(NetworkOfferingDao.class);
|
||||
|
|
@ -496,7 +500,7 @@ public class ApiDBUtils {
|
|||
public static VMTemplateHostVO findTemplateHostRef(long templateId, long zoneId) {
|
||||
return findTemplateHostRef(templateId, zoneId, false);
|
||||
}
|
||||
|
||||
|
||||
public static VMTemplateHostVO findTemplateHostRef(long templateId, long zoneId, boolean readyOnly) {
|
||||
VMTemplateVO vmTemplate = findTemplateById(templateId);
|
||||
if (vmTemplate.getHypervisorType() == HypervisorType.BareMetal) {
|
||||
|
|
@ -508,6 +512,9 @@ public class ApiDBUtils {
|
|||
}
|
||||
|
||||
|
||||
public static VolumeHostVO findVolumeHostRef(long volumeId, long zoneId) {
|
||||
return _volumeHostDao.findVolumeByZone(volumeId, zoneId);
|
||||
}
|
||||
|
||||
public static VMTemplateSwiftVO findTemplateSwiftRef(long templateId) {
|
||||
return _templateSwiftDao.findOneByTemplateId(templateId);
|
||||
|
|
|
|||
|
|
@ -1019,13 +1019,35 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
|
||||
volResponse.setCreated(volume.getCreated());
|
||||
volResponse.setState(volume.getState().toString());
|
||||
|
||||
if(volume.getState() == Volume.State.Uploading || volume.getState() == Volume.State.Uploaded){
|
||||
com.cloud.storage.VolumeHostVO volumeHostRef = ApiDBUtils.findVolumeHostRef(volume.getId(), volume.getDataCenterId());
|
||||
volResponse.setSize(volumeHostRef.getSize());
|
||||
volResponse.setCreated(volumeHostRef.getCreated());
|
||||
if (volumeHostRef.getDownloadState() != Status.DOWNLOADED) {
|
||||
String volumeStatus = "Processing";
|
||||
if (volumeHostRef.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
|
||||
if (volumeHostRef.getDownloadPercent() == 100) {
|
||||
volumeStatus = "Checking Volume";
|
||||
} else {
|
||||
volumeStatus = volumeHostRef.getDownloadPercent() + "% Uploaded";
|
||||
}
|
||||
} else {
|
||||
volumeStatus = volumeHostRef.getErrorString();
|
||||
}
|
||||
volResponse.setStatus(volumeStatus);
|
||||
} else if (volumeHostRef.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) {
|
||||
volResponse.setStatus("Upload Complete");
|
||||
} else {
|
||||
volResponse.setStatus("Successfully Installed");
|
||||
}
|
||||
}
|
||||
|
||||
populateOwner(volResponse, volume);
|
||||
|
||||
String storageType;
|
||||
try {
|
||||
if (volume.getPoolId() == null) {
|
||||
if (volume.getState() == Volume.State.Allocated) {
|
||||
if (volume.getState() == Volume.State.Allocated || volume.getState() == Volume.State.Uploaded || volume.getState() == Volume.State.Uploading) {
|
||||
/* set it as shared, so the UI can attach it to VM */
|
||||
storageType = "shared";
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -16,4 +16,6 @@ public interface VolumeHostDao extends GenericDao<VolumeHostVO, Long> {
|
|||
|
||||
List<VolumeHostVO> listDestroyed(long hostId);
|
||||
|
||||
VolumeHostVO findVolumeByZone(long zoneId, long volumeId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.cloud.utils.db.SearchCriteria;
|
|||
public class VolumeHostDaoImpl extends GenericDaoBase<VolumeHostVO, Long> implements VolumeHostDao {
|
||||
|
||||
protected final SearchBuilder<VolumeHostVO> HostVolumeSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> ZoneVolumeSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> VolumeSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> HostSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> HostDestroyedSearch;
|
||||
|
|
@ -26,6 +27,12 @@ public class VolumeHostDaoImpl extends GenericDaoBase<VolumeHostVO, Long> implem
|
|||
HostVolumeSearch.and("destroyed", HostVolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
|
||||
HostVolumeSearch.done();
|
||||
|
||||
ZoneVolumeSearch = createSearchBuilder();
|
||||
ZoneVolumeSearch.and("zone_id", ZoneVolumeSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
|
||||
ZoneVolumeSearch.and("volume_id", ZoneVolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
|
||||
ZoneVolumeSearch.and("destroyed", ZoneVolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
|
||||
ZoneVolumeSearch.done();
|
||||
|
||||
HostSearch = createSearchBuilder();
|
||||
HostSearch.and("host_id", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
HostSearch.and("destroyed", HostSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -53,6 +60,15 @@ public class VolumeHostDaoImpl extends GenericDaoBase<VolumeHostVO, Long> implem
|
|||
return findOneIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeHostVO findVolumeByZone(long volumeId, long zoneId) {
|
||||
SearchCriteria<VolumeHostVO> sc = ZoneVolumeSearch.create();
|
||||
sc.setParameters("zone_id", zoneId);
|
||||
sc.setParameters("volume_id", volumeId);
|
||||
sc.setParameters("destroyed", false);
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeHostVO findByVolumeId(long volumeId) {
|
||||
SearchCriteria<VolumeHostVO> sc = VolumeSearch.create();
|
||||
|
|
|
|||
|
|
@ -435,8 +435,8 @@ public class DownloadMonitorImpl implements DownloadMonitor {
|
|||
|
||||
volumeHost = _volumeHostDao.findByHostVolume(sserver.getId(), volume.getId());
|
||||
if (volumeHost == null) {
|
||||
volumeHost = new VolumeHostVO(sserver.getId(), volume.getId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null,
|
||||
"jobid0000", null, url, checkSum);
|
||||
volumeHost = new VolumeHostVO(sserver.getId(), volume.getId(), sserver.getDataCenterId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null,
|
||||
"jobid0000", null, url, checkSum, format);
|
||||
_volumeHostDao.persist(volumeHost);
|
||||
} else if ((volumeHost.getJobId() != null) && (volumeHost.getJobId().length() > 2)) {
|
||||
downloadJobExists = true;
|
||||
|
|
|
|||
|
|
@ -1125,6 +1125,7 @@ CREATE TABLE `cloud`.`volume_host_ref` (
|
|||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
`host_id` bigint unsigned NOT NULL,
|
||||
`volume_id` bigint unsigned NOT NULL,
|
||||
`zone_id` bigint unsigned NOT NULL,
|
||||
`created` DATETIME NOT NULL,
|
||||
`last_updated` DATETIME,
|
||||
`job_id` varchar(255),
|
||||
|
|
|
|||
Loading…
Reference in New Issue