Skip to content

Commit 497c60d

Browse files
Extending extract functionlity for volumes to allow download. The
extraction can have two modes FTP_UPLOAD and HTTP_DOWNLOAD. In the former one the user would provide the ftp url where the entity needs to be uploaded and in the later the user would be provided a HTTP URL where from he/she can download the entity. This url would be exposed for a specific time limit and would not function after the time limit
1 parent cfdd699 commit 497c60d

11 files changed

Lines changed: 233 additions & 71 deletions

File tree

‎core/src/com/cloud/agent/api/storage/DeleteEntityDownloadURLCommand.java‎

100644100755
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.cloud.agent.api.storage;
22

3+
import com.cloud.storage.Upload;
4+
35
public class DeleteEntityDownloadURLCommand extends AbstractDownloadCommand {
46

57
String path;
8+
Upload.Type type;
69

7-
public DeleteEntityDownloadURLCommand(String path) {
10+
public DeleteEntityDownloadURLCommand(String path, Upload.Type type) {
811
super();
912
this.path = path;
13+
this.type = type;
1014
}
1115

1216
public DeleteEntityDownloadURLCommand() {
@@ -20,6 +24,13 @@ public String getPath() {
2024
public void setPath(String path) {
2125
this.path = path;
2226
}
23-
27+
28+
public Upload.Type getType() {
29+
return type;
30+
}
31+
32+
public void setType(Upload.Type type) {
33+
this.type = type;
34+
}
2435

2536
}

‎core/src/com/cloud/event/EventTypes.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class EventTypes {
9696
public static final String EVENT_VOLUME_DELETE = "VOLUME.DELETE";
9797
public static final String EVENT_VOLUME_ATTACH = "VOLUME.ATTACH";
9898
public static final String EVENT_VOLUME_DETACH = "VOLUME.DETACH";
99+
public static final String EVENT_VOLUME_EXTRACT = "VOLUME.EXTRACT";
99100
public static final String EVENT_VOLUME_UPLOAD = "VOLUME.UPLOAD";
100101

101102
// Domains

‎core/src/com/cloud/storage/template/UploadManagerImpl.java‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.cloud.agent.api.storage.UploadCommand;
2727
import com.cloud.storage.StorageLayer;
2828
import com.cloud.storage.StorageResource;
29+
import com.cloud.storage.Upload;
2930
import com.cloud.storage.UploadVO;
3031
import com.cloud.storage.Storage.ImageFormat;
3132
import com.cloud.storage.template.TemplateUploader.UploadCompleteCallback;
@@ -338,7 +339,7 @@ public CreateEntityDownloadURLAnswer handleCreateEntityURLCommand(CreateEntityDo
338339
return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
339340
}
340341

341-
// Create a symbolic link from the actual directory to the template location
342+
// Create a symbolic link from the actual directory to the template location. The entity would be directly visible under /var/www/html/
342343
cmd.getInstallPath();
343344
command = new Script("/bin/bash", s_logger);
344345
command.add("-c");
@@ -357,6 +358,7 @@ public CreateEntityDownloadURLAnswer handleCreateEntityURLCommand(CreateEntityDo
357358
@Override
358359
public DeleteEntityDownloadURLAnswer handleDeleteEntityDownloadURLCommand(DeleteEntityDownloadURLCommand cmd){
359360

361+
//Delete the soft link
360362
s_logger.debug("handleDeleteEntityDownloadURLCommand "+cmd.getPath());
361363
Script command = new Script("/bin/bash", s_logger);
362364
command.add("-c");
@@ -367,6 +369,20 @@ public DeleteEntityDownloadURLAnswer handleDeleteEntityDownloadURLCommand(Delete
367369
s_logger.warn(errorString);
368370
return new DeleteEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
369371
}
372+
373+
// If its a volume also delete the Hard link
374+
if(cmd.getType() == Upload.Type.VOLUME){
375+
command = new Script("/bin/bash", s_logger);
376+
command.add("-c");
377+
command.add("rm -f " + publicTemplateRepo + cmd.getPath());
378+
result = command.execute();
379+
if (result != null) {
380+
String errorString = "Error in linking err=" + result;
381+
s_logger.warn(errorString);
382+
return new DeleteEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
383+
}
384+
}
385+
370386
return new DeleteEntityDownloadURLAnswer("", CreateEntityDownloadURLAnswer.RESULT_SUCCESS);
371387
}
372388

‎server/src/com/cloud/api/commands/ExtractVolumeCmd.java‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import com.cloud.api.BaseAsyncCmd;
2424
import com.cloud.api.Implementation;
2525
import com.cloud.api.Parameter;
26+
import com.cloud.api.BaseCmd.CommandType;
2627
import com.cloud.api.response.ExtractResponse;
2728
import com.cloud.event.EventTypes;
29+
import com.cloud.storage.UploadVO;
2830
import com.cloud.storage.VolumeVO;
2931
import com.cloud.user.Account;
3032

@@ -39,16 +41,19 @@ public class ExtractVolumeCmd extends BaseAsyncCmd {
3941
/////////////////////////////////////////////////////
4042

4143
//FIXME - add description
42-
@Parameter(name="id", type=CommandType.LONG, required=true)
44+
@Parameter(name="id", type=CommandType.LONG, required=true, description="the ID of the volume")
4345
private Long id;
4446

4547
//FIXME - add description
46-
@Parameter(name="url", type=CommandType.STRING, required=true)
48+
@Parameter(name="url", type=CommandType.STRING, required=false, description="the url to which the volume would be extracted")
4749
private String url;
4850

4951
//FIXME - add description
50-
@Parameter(name="zoneid", type=CommandType.LONG, required=true)
52+
@Parameter(name="zoneid", type=CommandType.LONG, required=true, description="the ID of the zone where the volume is located")
5153
private Long zoneId;
54+
55+
@Parameter(name="mode", type=CommandType.STRING, required=true, description="the mode of extraction - HTTP_DOWNLOAD or FTP_UPLOAD")
56+
private String mode;
5257

5358
/////////////////////////////////////////////////////
5459
/////////////////// Accessors ///////////////////////
@@ -65,12 +70,16 @@ public String getUrl() {
6570
public Long getZoneId() {
6671
return zoneId;
6772
}
73+
74+
public String getMode() {
75+
return mode;
76+
}
6877

6978
/////////////////////////////////////////////////////
7079
/////////////// API Implementation///////////////////
7180
/////////////////////////////////////////////////////
7281

73-
@Override
82+
@Override
7483
public String getName() {
7584
return s_name;
7685
}
@@ -79,7 +88,7 @@ public String getName() {
7988
public long getAccountId() {
8089
VolumeVO volume = ApiDBUtils.findVolumeById(getId());
8190
if (volume != null) {
82-
return volume.getId();
91+
return volume.getAccountId();
8392
}
8493

8594
// invalid id, parent this command to SYSTEM so ERROR events are tracked
@@ -88,7 +97,7 @@ public long getAccountId() {
8897

8998
@Override
9099
public String getEventType() {
91-
return EventTypes.EVENT_VOLUME_UPLOAD;
100+
return EventTypes.EVENT_VOLUME_EXTRACT;
92101
}
93102

94103
@Override
@@ -98,9 +107,22 @@ public String getEventDescription() {
98107

99108
@Override @SuppressWarnings("unchecked")
100109
public ExtractResponse getResponse() {
101-
ExtractResponse response = (ExtractResponse)getResponseObject();
102-
response.setResponseName(getName());
103-
return response;
110+
Long uploadId = (Long)getResponseObject();
111+
UploadVO uploadInfo = ApiDBUtils.findUploadById(uploadId);
112+
113+
ExtractResponse response = new ExtractResponse();
114+
response.setResponseName(getName());
115+
response.setId(id);
116+
response.setName(ApiDBUtils.findVolumeById(id).getName());
117+
response.setZoneId(zoneId);
118+
response.setZoneName(ApiDBUtils.findZoneById(zoneId).getName());
119+
response.setMode(mode);
120+
response.setUploadId(uploadId);
121+
response.setState(uploadInfo.getUploadState().toString());
122+
response.setAccountId(getAccountId());
123+
//FIX ME - Need to set the url once the gson jar is upgraded since it is throwing an error right now.
124+
//response.setUrl(uploadInfo.getUploadUrl());
125+
return response;
104126
}
105127

106128
public static String getStaticName() {

‎server/src/com/cloud/api/response/ExtractResponse.java‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public class ExtractResponse extends BaseResponse {
2929
@SerializedName("name") @Param(description="the name of the extracted object")
3030
private String name;
3131

32-
@SerializedName("uploadId") @Param(description="the upload id of extracted object")
32+
@SerializedName("extractId") @Param(description="the upload id of extracted object")
3333
private Long uploadId;
3434

3535
@SerializedName("uploadpercentage") @Param(description="the percentage of the entity uploaded to the specified location")
3636
private Integer uploadPercent;
3737

38-
@SerializedName("status") @Param(description="the status of the ")
38+
@SerializedName("status") @Param(description="the status of the extraction")
3939
private String status;
4040

4141
@SerializedName("accountid") @Param(description="the account id to which the extracted object belongs")
@@ -68,8 +68,20 @@ public class ExtractResponse extends BaseResponse {
6868
private String mode;
6969

7070
@SerializedName("url") @Param(description="if mode = upload then url of the uploaded entity. if mode = download the url from which the entity can be downloaded")
71-
private String url;
71+
private String url;
7272

73+
public ExtractResponse(){
74+
}
75+
76+
public ExtractResponse(Long volumeId, String volName, long accountId,
77+
String state, Long uploadId) {
78+
this.id = volumeId;
79+
this.name = volName;
80+
this.accountId = accountId;
81+
this.state = state;
82+
this.uploadId = uploadId;
83+
}
84+
7385
public Long getId() {
7486
return id;
7587
}

‎server/src/com/cloud/async/executor/ExtractJobResultObject.java‎

100644100755
File mode changed.

‎server/src/com/cloud/server/ManagementServer.java‎

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,9 +1207,10 @@ public interface ManagementServer {
12071207
* @param cmd the command specifying url (where the volume needs to be extracted to), zoneId (zone where the volume exists), id (the id of the volume)
12081208
* @throws URISyntaxException
12091209
* @throws InternalErrorException
1210+
* @throws PermissionDeniedException
12101211
*
12111212
*/
1212-
void extractVolume(ExtractVolumeCmd cmd) throws URISyntaxException, InternalErrorException;
1213+
Long extractVolume(ExtractVolumeCmd cmd) throws URISyntaxException, InternalErrorException, PermissionDeniedException;
12131214

12141215
/**
12151216
* return an array of available hypervisors

0 commit comments

Comments
 (0)