Skip to content

Commit 9097b53

Browse files
committed
bug CS-10789: Put zone id in the volumehost ref table. make list volume to show the percent uploaded.
1 parent fe3200c commit 9097b53

9 files changed

Lines changed: 79 additions & 16 deletions

File tree

api/src/com/cloud/api/commands/UploadVolumeCmd.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ public class UploadVolumeCmd extends BaseCmd {
4141
@Parameter(name=ApiConstants.FORMAT, type=CommandType.STRING, required=true, description="the format for the volume. Possible values include QCOW2, OVA, and VHD.")
4242
private String format;
4343

44-
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, required=true, description="the target hypervisor for the volume")
45-
private String hypervisor;
46-
4744
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the volume")
4845
private String volumeName;
4946

@@ -72,10 +69,6 @@ public String getFormat() {
7269
return format;
7370
}
7471

75-
public String getHypervisor() {
76-
return hypervisor;
77-
}
78-
7972
public String getVolumeName() {
8073
return volumeName;
8174
}

api/src/com/cloud/api/response/VolumeResponse.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public class VolumeResponse extends BaseResponse implements ControlledEntityResp
142142
@SerializedName("isextractable")
143143
@Param(description = "true if the volume is extractable, false otherwise")
144144
private Boolean extractable;
145+
146+
@SerializedName(ApiConstants.STATUS)
147+
@Param(description="the status of the volume")
148+
private String status;
145149

146150
@Override
147151
public Long getObjectId() {
@@ -260,7 +264,11 @@ public void setServiceOfferingName(String serviceOfferingName) {
260264
this.serviceOfferingName = serviceOfferingName;
261265
}
262266

263-
public void setServiceOfferingDisplayText(String serviceOfferingDisplayText) {
267+
public void setStatus(String status) {
268+
this.status = status;
269+
}
270+
271+
public void setServiceOfferingDisplayText(String serviceOfferingDisplayText) {
264272
this.serviceOfferingDisplayText = serviceOfferingDisplayText;
265273
}
266274

core/src/com/cloud/storage/VolumeHostVO.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import javax.persistence.TemporalType;
1515

1616
//import com.cloud.storage.VMVolumeStorageResourceAssoc.Status;
17+
import com.cloud.storage.Storage.ImageFormat;
1718
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
1819
import com.cloud.utils.db.GenericDaoBase;
1920

@@ -35,6 +36,9 @@ public class VolumeHostVO {
3536
@Column(name="volume_id")
3637
private long volumeId;
3738

39+
@Column(name="zone_id")
40+
private long zoneId;
41+
3842
@Column(name=GenericDaoBase.CREATED_COLUMN)
3943
private Date created = null;
4044

@@ -103,7 +107,15 @@ public void setVolumeId(long volumeId) {
103107
}
104108

105109

106-
public int getDownloadPercent() {
110+
public long getZoneId() {
111+
return zoneId;
112+
}
113+
114+
public void setZoneId(long zoneId) {
115+
this.zoneId = zoneId;
116+
}
117+
118+
public int getDownloadPercent() {
107119
return downloadPercent;
108120
}
109121

@@ -161,13 +173,14 @@ public VolumeHostVO(long hostId, long volumeId) {
161173
this.volumeId = volumeId;
162174
}
163175

164-
public VolumeHostVO(long hostId, long volumeId, Date lastUpdated,
176+
public VolumeHostVO(long hostId, long volumeId, long zoneId, Date lastUpdated,
165177
int downloadPercent, Status downloadState,
166178
String localDownloadPath, String errorString, String jobId,
167-
String installPath, String downloadUrl, String checksum) {
179+
String installPath, String downloadUrl, String checksum, ImageFormat format) {
168180
//super();
169181
this.hostId = hostId;
170182
this.volumeId = volumeId;
183+
this.zoneId = zoneId;
171184
this.lastUpdated = lastUpdated;
172185
this.downloadPercent = downloadPercent;
173186
this.downloadState = downloadState;
@@ -177,6 +190,7 @@ public VolumeHostVO(long hostId, long volumeId, Date lastUpdated,
177190
this.installPath = installPath;
178191
this.setDownloadUrl(downloadUrl);
179192
this.checksum = checksum;
193+
this.format = format;
180194
}
181195

182196
protected VolumeHostVO() {

server/src/com/cloud/api/ApiDBUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import com.cloud.storage.VMTemplateHostVO;
9292
import com.cloud.storage.VMTemplateSwiftVO;
9393
import com.cloud.storage.VMTemplateVO;
94+
import com.cloud.storage.VolumeHostVO;
9495
import com.cloud.storage.Volume.Type;
9596
import com.cloud.storage.VolumeVO;
9697
import com.cloud.storage.dao.DiskOfferingDao;
@@ -104,6 +105,7 @@
104105
import com.cloud.storage.dao.VMTemplateHostDao;
105106
import com.cloud.storage.dao.VMTemplateSwiftDao;
106107
import com.cloud.storage.dao.VolumeDao;
108+
import com.cloud.storage.dao.VolumeHostDao;
107109
import com.cloud.user.Account;
108110
import com.cloud.user.AccountDetailsDao;
109111
import com.cloud.user.AccountVO;
@@ -170,6 +172,7 @@ public class ApiDBUtils {
170172
private static UserVmDao _userVmDao;
171173
private static VlanDao _vlanDao;
172174
private static VolumeDao _volumeDao;
175+
private static VolumeHostDao _volumeHostDao;
173176
private static DataCenterDao _zoneDao;
174177
private static NetworkOfferingDao _networkOfferingDao;
175178
private static NetworkDao _networkDao;
@@ -222,6 +225,7 @@ public class ApiDBUtils {
222225
_userVmDao = locator.getDao(UserVmDao.class);
223226
_vlanDao = locator.getDao(VlanDao.class);
224227
_volumeDao = locator.getDao(VolumeDao.class);
228+
_volumeHostDao = locator.getDao(VolumeHostDao.class);
225229
_zoneDao = locator.getDao(DataCenterDao.class);
226230
_securityGroupDao = locator.getDao(SecurityGroupDao.class);
227231
_networkOfferingDao = locator.getDao(NetworkOfferingDao.class);
@@ -496,7 +500,7 @@ public static VMTemplateVO findTemplateById(Long templateId) {
496500
public static VMTemplateHostVO findTemplateHostRef(long templateId, long zoneId) {
497501
return findTemplateHostRef(templateId, zoneId, false);
498502
}
499-
503+
500504
public static VMTemplateHostVO findTemplateHostRef(long templateId, long zoneId, boolean readyOnly) {
501505
VMTemplateVO vmTemplate = findTemplateById(templateId);
502506
if (vmTemplate.getHypervisorType() == HypervisorType.BareMetal) {
@@ -508,6 +512,9 @@ public static VMTemplateHostVO findTemplateHostRef(long templateId, long zoneId,
508512
}
509513

510514

515+
public static VolumeHostVO findVolumeHostRef(long volumeId, long zoneId) {
516+
return _volumeHostDao.findVolumeByZone(volumeId, zoneId);
517+
}
511518

512519
public static VMTemplateSwiftVO findTemplateSwiftRef(long templateId) {
513520
return _templateSwiftDao.findOneByTemplateId(templateId);

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,13 +1019,35 @@ public VolumeResponse createVolumeResponse(Volume volume) {
10191019

10201020
volResponse.setCreated(volume.getCreated());
10211021
volResponse.setState(volume.getState().toString());
1022-
1022+
if(volume.getState() == Volume.State.Uploading || volume.getState() == Volume.State.Uploaded){
1023+
com.cloud.storage.VolumeHostVO volumeHostRef = ApiDBUtils.findVolumeHostRef(volume.getId(), volume.getDataCenterId());
1024+
volResponse.setSize(volumeHostRef.getSize());
1025+
volResponse.setCreated(volumeHostRef.getCreated());
1026+
if (volumeHostRef.getDownloadState() != Status.DOWNLOADED) {
1027+
String volumeStatus = "Processing";
1028+
if (volumeHostRef.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
1029+
if (volumeHostRef.getDownloadPercent() == 100) {
1030+
volumeStatus = "Checking Volume";
1031+
} else {
1032+
volumeStatus = volumeHostRef.getDownloadPercent() + "% Uploaded";
1033+
}
1034+
} else {
1035+
volumeStatus = volumeHostRef.getErrorString();
1036+
}
1037+
volResponse.setStatus(volumeStatus);
1038+
} else if (volumeHostRef.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) {
1039+
volResponse.setStatus("Upload Complete");
1040+
} else {
1041+
volResponse.setStatus("Successfully Installed");
1042+
}
1043+
}
1044+
10231045
populateOwner(volResponse, volume);
10241046

10251047
String storageType;
10261048
try {
10271049
if (volume.getPoolId() == null) {
1028-
if (volume.getState() == Volume.State.Allocated) {
1050+
if (volume.getState() == Volume.State.Allocated || volume.getState() == Volume.State.Uploaded || volume.getState() == Volume.State.Uploading) {
10291051
/* set it as shared, so the UI can attach it to VM */
10301052
storageType = "shared";
10311053
} else {

server/src/com/cloud/storage/dao/VolumeHostDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ public interface VolumeHostDao extends GenericDao<VolumeHostVO, Long> {
1616

1717
List<VolumeHostVO> listDestroyed(long hostId);
1818

19+
VolumeHostVO findVolumeByZone(long zoneId, long volumeId);
20+
1921
}

server/src/com/cloud/storage/dao/VolumeHostDaoImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
public class VolumeHostDaoImpl extends GenericDaoBase<VolumeHostVO, Long> implements VolumeHostDao {
1616

1717
protected final SearchBuilder<VolumeHostVO> HostVolumeSearch;
18+
protected final SearchBuilder<VolumeHostVO> ZoneVolumeSearch;
1819
protected final SearchBuilder<VolumeHostVO> VolumeSearch;
1920
protected final SearchBuilder<VolumeHostVO> HostSearch;
2021
protected final SearchBuilder<VolumeHostVO> HostDestroyedSearch;
@@ -26,6 +27,12 @@ public class VolumeHostDaoImpl extends GenericDaoBase<VolumeHostVO, Long> implem
2627
HostVolumeSearch.and("destroyed", HostVolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
2728
HostVolumeSearch.done();
2829

30+
ZoneVolumeSearch = createSearchBuilder();
31+
ZoneVolumeSearch.and("zone_id", ZoneVolumeSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
32+
ZoneVolumeSearch.and("volume_id", ZoneVolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
33+
ZoneVolumeSearch.and("destroyed", ZoneVolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
34+
ZoneVolumeSearch.done();
35+
2936
HostSearch = createSearchBuilder();
3037
HostSearch.and("host_id", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
3138
HostSearch.and("destroyed", HostSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
@@ -53,6 +60,15 @@ public VolumeHostVO findByHostVolume(long hostId, long volumeId) {
5360
return findOneIncludingRemovedBy(sc);
5461
}
5562

63+
@Override
64+
public VolumeHostVO findVolumeByZone(long volumeId, long zoneId) {
65+
SearchCriteria<VolumeHostVO> sc = ZoneVolumeSearch.create();
66+
sc.setParameters("zone_id", zoneId);
67+
sc.setParameters("volume_id", volumeId);
68+
sc.setParameters("destroyed", false);
69+
return findOneIncludingRemovedBy(sc);
70+
}
71+
5672
@Override
5773
public VolumeHostVO findByVolumeId(long volumeId) {
5874
SearchCriteria<VolumeHostVO> sc = VolumeSearch.create();

server/src/com/cloud/storage/download/DownloadMonitorImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ private void downloadVolumeToStorage(VolumeVO volume, HostVO sserver, String url
435435

436436
volumeHost = _volumeHostDao.findByHostVolume(sserver.getId(), volume.getId());
437437
if (volumeHost == null) {
438-
volumeHost = new VolumeHostVO(sserver.getId(), volume.getId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null,
439-
"jobid0000", null, url, checkSum);
438+
volumeHost = new VolumeHostVO(sserver.getId(), volume.getId(), sserver.getDataCenterId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null,
439+
"jobid0000", null, url, checkSum, format);
440440
_volumeHostDao.persist(volumeHost);
441441
} else if ((volumeHost.getJobId() != null) && (volumeHost.getJobId().length() > 2)) {
442442
downloadJobExists = true;

setup/db/create-schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ CREATE TABLE `cloud`.`volume_host_ref` (
11251125
`id` bigint unsigned NOT NULL auto_increment,
11261126
`host_id` bigint unsigned NOT NULL,
11271127
`volume_id` bigint unsigned NOT NULL,
1128+
`zone_id` bigint unsigned NOT NULL,
11281129
`created` DATETIME NOT NULL,
11291130
`last_updated` DATETIME,
11301131
`job_id` varchar(255),

0 commit comments

Comments
 (0)