Skip to content

Commit 564cef8

Browse files
committed
More changes for uploadVolume. Create framework for upload volume progress communication between MS and SSVM.
1 parent 2e80fba commit 564cef8

19 files changed

Lines changed: 946 additions & 67 deletions

api/src/com/cloud/agent/api/storage/DownloadCommand.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.net.URI;
1616

17+
import com.cloud.storage.Volume;
1718
import com.cloud.storage.Storage.ImageFormat;
1819
import com.cloud.template.VirtualMachineTemplate;
1920

@@ -41,6 +42,10 @@ public String getPassword() {
4142
}
4243
}
4344

45+
public static enum ResourceType {
46+
VOLUME, TEMPLATE
47+
}
48+
4449
public static class Proxy {
4550
private String _host;
4651
private int _port;
@@ -97,6 +102,7 @@ public String getPassword() {
97102
private Proxy _proxy;
98103
private Long maxDownloadSizeInBytes = null;
99104
private long id;
105+
private ResourceType resourceType = ResourceType.TEMPLATE;
100106

101107
protected DownloadCommand() {
102108
}
@@ -122,6 +128,17 @@ public DownloadCommand(String secUrl, VirtualMachineTemplate template, Long maxD
122128
this.setSecUrl(secUrl);
123129
this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
124130
}
131+
132+
public DownloadCommand(String secUrl, Volume volume, Long maxDownloadSizeInBytes, String checkSum, String url) {
133+
super(volume.getName(), url, ImageFormat.VHD, volume.getAccountId());
134+
//this.hvm = volume.isRequiresHvm();
135+
this.checksum = checkSum;
136+
this.id = volume.getId();
137+
//this.description = volume.get;
138+
this.setSecUrl(secUrl);
139+
this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
140+
this.resourceType = ResourceType.VOLUME;
141+
}
125142

126143
public DownloadCommand(String secUrl, String url, VirtualMachineTemplate template, String user, String passwd, Long maxDownloadSizeInBytes) {
127144
super(template.getUniqueName(), url, template.getFormat(), template.getAccountId());
@@ -187,4 +204,14 @@ public void setProxy(Proxy proxy) {
187204
public Long getMaxDownloadSizeInBytes() {
188205
return maxDownloadSizeInBytes;
189206
}
207+
208+
209+
public ResourceType getResourceType() {
210+
return resourceType;
211+
}
212+
213+
214+
public void setResourceType(ResourceType resourceType) {
215+
this.resourceType = resourceType;
216+
}
190217
}

api/src/com/cloud/storage/StorageService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.cloud.api.commands.DeletePoolCmd;
2222
import com.cloud.api.commands.ListVolumesCmd;
2323
import com.cloud.api.commands.UpdateStoragePoolCmd;
24+
import com.cloud.api.commands.UploadVolumeCmd;
2425
import com.cloud.exception.ConcurrentOperationException;
2526
import com.cloud.exception.InsufficientCapacityException;
2627
import com.cloud.exception.PermissionDeniedException;
@@ -108,4 +109,13 @@ public interface StorageService{
108109

109110
List<? extends Volume> searchForVolumes(ListVolumesCmd cmd);
110111

112+
/**
113+
* Uploads the volume to secondary storage
114+
*
115+
* @param UploadVolumeCmd cmd
116+
*
117+
* @return Volume object
118+
*/
119+
Volume uploadVolume(UploadVolumeCmd cmd) throws ResourceAllocationException;
120+
111121
}
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
package com.cloud.storage;
2+
3+
import java.util.Date;
4+
5+
import javax.persistence.Column;
6+
import javax.persistence.Entity;
7+
import javax.persistence.EnumType;
8+
import javax.persistence.Enumerated;
9+
import javax.persistence.GeneratedValue;
10+
import javax.persistence.GenerationType;
11+
import javax.persistence.Id;
12+
import javax.persistence.Table;
13+
import javax.persistence.Temporal;
14+
import javax.persistence.TemporalType;
15+
16+
//import com.cloud.storage.VMVolumeStorageResourceAssoc.Status;
17+
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
18+
import com.cloud.utils.db.GenericDaoBase;
19+
20+
/**
21+
* Join table for storage hosts and volumes
22+
* @author Nitin
23+
*
24+
*/
25+
@Entity
26+
@Table(name="volume_host_ref")
27+
public class VolumeHostVO {
28+
@Id
29+
@GeneratedValue(strategy=GenerationType.IDENTITY)
30+
Long id;
31+
32+
@Column(name="host_id")
33+
private long hostId;
34+
35+
@Column(name="volume_id")
36+
private long volumeId;
37+
38+
@Column(name=GenericDaoBase.CREATED_COLUMN)
39+
private Date created = null;
40+
41+
@Column(name="last_updated")
42+
@Temporal(value=TemporalType.TIMESTAMP)
43+
private Date lastUpdated = null;
44+
45+
@Column (name="download_pct")
46+
private int downloadPercent;
47+
48+
@Column (name="size")
49+
private long size;
50+
51+
@Column (name="physical_size")
52+
private long physicalSize;
53+
54+
@Column (name="download_state")
55+
@Enumerated(EnumType.STRING)
56+
private Status downloadState;
57+
58+
@Column(name="checksum")
59+
private String checksum;
60+
61+
@Column (name="local_path")
62+
private String localDownloadPath;
63+
64+
@Column (name="error_str")
65+
private String errorString;
66+
67+
@Column (name="job_id")
68+
private String jobId;
69+
70+
@Column (name="install_path")
71+
private String installPath;
72+
73+
@Column (name="url")
74+
private String downloadUrl;
75+
76+
@Column(name="is_copy")
77+
private boolean isCopy = false;
78+
79+
@Column(name="destroyed")
80+
boolean destroyed = false;
81+
82+
83+
public String getInstallPath() {
84+
return installPath;
85+
}
86+
87+
public long getHostId() {
88+
return hostId;
89+
}
90+
91+
public void setHostId(long hostId) {
92+
this.hostId = hostId;
93+
}
94+
95+
96+
public long getVolumeId() {
97+
return volumeId;
98+
}
99+
100+
101+
public void setVolumeId(long volumeId) {
102+
this.volumeId = volumeId;
103+
}
104+
105+
106+
public int getDownloadPercent() {
107+
return downloadPercent;
108+
}
109+
110+
111+
public void setDownloadPercent(int downloadPercent) {
112+
this.downloadPercent = downloadPercent;
113+
}
114+
115+
116+
public void setDownloadState(Status downloadState) {
117+
this.downloadState = downloadState;
118+
}
119+
120+
121+
public long getId() {
122+
return id;
123+
}
124+
125+
126+
public Date getCreated() {
127+
return created;
128+
}
129+
130+
131+
public Date getLastUpdated() {
132+
return lastUpdated;
133+
}
134+
135+
136+
public void setLastUpdated(Date date) {
137+
lastUpdated = date;
138+
}
139+
140+
141+
public void setInstallPath(String installPath) {
142+
this.installPath = installPath;
143+
}
144+
145+
146+
public Status getDownloadState() {
147+
return downloadState;
148+
}
149+
150+
public String getChecksum() {
151+
return checksum;
152+
}
153+
154+
public void setChecksum(String checksum) {
155+
this.checksum = checksum;
156+
}
157+
158+
public VolumeHostVO(long hostId, long volumeId) {
159+
super();
160+
this.hostId = hostId;
161+
this.volumeId = volumeId;
162+
}
163+
164+
public VolumeHostVO(long hostId, long volumeId, Date lastUpdated,
165+
int downloadPercent, Status downloadState,
166+
String localDownloadPath, String errorString, String jobId,
167+
String installPath, String downloadUrl, String checksum) {
168+
//super();
169+
this.hostId = hostId;
170+
this.volumeId = volumeId;
171+
this.lastUpdated = lastUpdated;
172+
this.downloadPercent = downloadPercent;
173+
this.downloadState = downloadState;
174+
this.localDownloadPath = localDownloadPath;
175+
this.errorString = errorString;
176+
this.jobId = jobId;
177+
this.installPath = installPath;
178+
this.setDownloadUrl(downloadUrl);
179+
this.checksum = checksum;
180+
}
181+
182+
protected VolumeHostVO() {
183+
184+
}
185+
186+
187+
public void setLocalDownloadPath(String localPath) {
188+
this.localDownloadPath = localPath;
189+
}
190+
191+
192+
public String getLocalDownloadPath() {
193+
return localDownloadPath;
194+
}
195+
196+
197+
public void setErrorString(String errorString) {
198+
this.errorString = errorString;
199+
}
200+
201+
202+
public String getErrorString() {
203+
return errorString;
204+
}
205+
206+
207+
public void setJobId(String jobId) {
208+
this.jobId = jobId;
209+
}
210+
211+
212+
public String getJobId() {
213+
return jobId;
214+
}
215+
216+
217+
public boolean equals(Object obj) {
218+
if (obj instanceof VolumeHostVO) {
219+
VolumeHostVO other = (VolumeHostVO)obj;
220+
return (this.volumeId==other.getVolumeId() && this.hostId==other.getHostId());
221+
}
222+
return false;
223+
}
224+
225+
226+
public int hashCode() {
227+
Long tid = new Long(volumeId);
228+
Long hid = new Long(hostId);
229+
return tid.hashCode()+hid.hashCode();
230+
}
231+
232+
public void setSize(long size) {
233+
this.size = size;
234+
}
235+
236+
public long getSize() {
237+
return size;
238+
}
239+
240+
241+
public void setPhysicalSize(long physicalSize) {
242+
this.physicalSize = physicalSize;
243+
}
244+
245+
public long getPhysicalSize() {
246+
return physicalSize;
247+
}
248+
249+
public void setDestroyed(boolean destroyed) {
250+
this.destroyed = destroyed;
251+
}
252+
253+
public boolean getDestroyed() {
254+
return destroyed;
255+
}
256+
257+
public void setDownloadUrl(String downloadUrl) {
258+
this.downloadUrl = downloadUrl;
259+
}
260+
261+
public String getDownloadUrl() {
262+
return downloadUrl;
263+
}
264+
265+
public void setCopy(boolean isCopy) {
266+
this.isCopy = isCopy;
267+
}
268+
269+
public boolean isCopy() {
270+
return isCopy;
271+
}
272+
273+
274+
public long getVolumeSize() {
275+
return -1;
276+
}
277+
278+
279+
public String toString() {
280+
return new StringBuilder("VolumeHost[").append(id).append("-").append(volumeId).append("-").append(hostId).append(installPath).append("]").toString();
281+
}
282+
283+
}

0 commit comments

Comments
 (0)