Skip to content

Commit 6723549

Browse files
bug 6399: extending extract functionlity for templates and ISO's 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 6721c44 commit 6723549

26 files changed

Lines changed: 651 additions & 149 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.cloud.agent.api.storage;
2+
3+
import com.cloud.agent.api.Answer;
4+
5+
public class CreateEntityDownloadURLAnswer extends Answer{
6+
7+
String resultString;
8+
short resultCode;
9+
public static final short RESULT_SUCCESS = 1;
10+
public static final short RESULT_FAILURE = 0;
11+
12+
public CreateEntityDownloadURLAnswer(String resultString, short resultCode) {
13+
super();
14+
this.resultString = resultString;
15+
this.resultCode = resultCode;
16+
}
17+
18+
public CreateEntityDownloadURLAnswer(){
19+
}
20+
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.cloud.agent.api.storage;
2+
3+
import com.cloud.agent.api.Command;
4+
5+
public class CreateEntityDownloadURLCommand extends AbstractDownloadCommand {
6+
7+
public CreateEntityDownloadURLCommand(String installPath) {
8+
super();
9+
this.installPath = installPath;
10+
}
11+
12+
public CreateEntityDownloadURLCommand() {
13+
}
14+
15+
private String installPath;
16+
17+
@Override
18+
public boolean executeInSequence() {
19+
return false;
20+
}
21+
22+
public String getInstallPath() {
23+
return installPath;
24+
}
25+
26+
public void setInstallPath(String installPath) {
27+
this.installPath = installPath;
28+
}
29+
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.cloud.agent.api.storage;
2+
3+
import com.cloud.agent.api.Answer;
4+
5+
public class DeleteEntityDownloadURLAnswer extends Answer{
6+
7+
String resultString;
8+
short resultCode;
9+
public static final short RESULT_SUCCESS = 1;
10+
public static final short RESULT_FAILURE = 0;
11+
12+
public DeleteEntityDownloadURLAnswer(String resultString, short resultCode) {
13+
super();
14+
this.resultString = resultString;
15+
this.resultCode = resultCode;
16+
}
17+
18+
public DeleteEntityDownloadURLAnswer(){
19+
}
20+
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.cloud.agent.api.storage;
2+
3+
public class DeleteEntityDownloadURLCommand extends AbstractDownloadCommand {
4+
5+
String path;
6+
7+
public DeleteEntityDownloadURLCommand(String path) {
8+
super();
9+
this.path = path;
10+
}
11+
12+
public DeleteEntityDownloadURLCommand() {
13+
super();
14+
}
15+
16+
public String getPath() {
17+
return path;
18+
}
19+
20+
public void setPath(String path) {
21+
this.path = path;
22+
}
23+
24+
25+
}

‎core/src/com/cloud/storage/Upload.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public interface Upload {
44

5-
public static enum Status {UNKNOWN, ABANDONED, UPLOADED, NOT_UPLOADED, UPLOAD_ERROR, UPLOAD_IN_PROGRESS, NOT_COPIED, COPY_IN_PROGRESS, COPY_ERROR, COPY_COMPLETE}
6-
public static enum Type {VOLUME, TEMPLATE, ISO}
5+
public static enum Status {UNKNOWN, ABANDONED, UPLOADED, NOT_UPLOADED, UPLOAD_ERROR, UPLOAD_IN_PROGRESS, NOT_COPIED, COPY_IN_PROGRESS, COPY_ERROR, COPY_COMPLETE, DOWNLOAD_URL_CREATED, DOWNLOAD_URL_NOT_CREATED, ERROR}
6+
public static enum Type {VOLUME, TEMPLATE, ISO}
7+
public static enum Mode {FTP_UPLOAD, HTTP_DOWNLOAD}
78
}

‎core/src/com/cloud/storage/UploadVO.java‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public class UploadVO implements Upload {
6565
@Enumerated(EnumType.STRING)
6666
private Type type;
6767

68+
@Column (name="mode")
69+
@Enumerated(EnumType.STRING)
70+
private Mode mode = Mode.FTP_UPLOAD;
71+
6872
@Column (name="upload_state")
6973
@Enumerated(EnumType.STRING)
7074
private Status uploadState;
@@ -122,6 +126,19 @@ public UploadVO(long hostId, long typeId, Date lastUpdated,
122126
this.jobId = jobId;
123127
this.uploadUrl = uploadUrl;
124128
}
129+
130+
public UploadVO(long hostId, long typeId, Date lastUpdated,
131+
Status uploadState, int uploadPercent, Type type,
132+
Mode mode) {
133+
super();
134+
this.hostId = hostId;
135+
this.typeId = typeId;
136+
this.lastUpdated = lastUpdated;
137+
this.uploadState = uploadState;
138+
this.uploadPercent = uploadPercent;
139+
this.type = type;
140+
this.mode = mode;
141+
}
125142

126143
protected UploadVO() {
127144
}
@@ -200,7 +217,15 @@ public void setType(Type type) {
200217
this.type = type;
201218
}
202219

203-
public String getUploadUrl() {
220+
public Mode getMode() {
221+
return mode;
222+
}
223+
224+
public void setMode(Mode mode) {
225+
this.mode = mode;
226+
}
227+
228+
public String getUploadUrl() {
204229
return uploadUrl;
205230
}
206231

‎core/src/com/cloud/storage/dao/UploadDao.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.cloud.storage.UploadVO;
66
import com.cloud.storage.Upload.Status;
77
import com.cloud.storage.Upload.Type;
8+
import com.cloud.storage.Upload.Mode;
89
import com.cloud.utils.db.GenericDao;
910

1011
public interface UploadDao extends GenericDao<UploadVO, Long> {
@@ -13,5 +14,7 @@ List<UploadVO> listByTypeUploadStatus(long typeId, Type type,
1314
Status uploadState);
1415

1516
List<UploadVO> listByHostAndUploadStatus(long sserverId, Status uploadInProgress);
17+
18+
List<UploadVO> listByModeAndStatus(Mode mode, Status uploadState);
1619

1720
}

‎core/src/com/cloud/storage/dao/UploadDaoImpl.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.cloud.storage.UploadVO;
88
import com.cloud.storage.Upload.Status;
9+
import com.cloud.storage.Upload.Mode;
910
import com.cloud.utils.db.GenericDaoBase;
1011
import com.cloud.utils.db.SearchBuilder;
1112
import com.cloud.utils.db.SearchCriteria;
@@ -15,6 +16,7 @@ public class UploadDaoImpl extends GenericDaoBase<UploadVO, Long> implements Upl
1516
public static final Logger s_logger = Logger.getLogger(UploadDaoImpl.class.getName());
1617
protected final SearchBuilder<UploadVO> typeUploadStatusSearch;
1718
protected final SearchBuilder<UploadVO> typeHostAndUploadStatusSearch;
19+
protected final SearchBuilder<UploadVO> typeModeAndStatusSearch;
1820

1921
protected static final String UPDATE_UPLOAD_INFO =
2022
"UPDATE upload SET upload_state = ?, upload_pct= ?, last_updated = ? "
@@ -37,6 +39,12 @@ public UploadDaoImpl() {
3739
typeHostAndUploadStatusSearch.and("host_id", typeHostAndUploadStatusSearch.entity().getHostId(), SearchCriteria.Op.EQ);
3840
typeHostAndUploadStatusSearch.and("upload_state", typeHostAndUploadStatusSearch.entity().getUploadState(), SearchCriteria.Op.EQ);
3941
typeHostAndUploadStatusSearch.done();
42+
43+
typeModeAndStatusSearch = createSearchBuilder();
44+
typeModeAndStatusSearch.and("mode", typeModeAndStatusSearch.entity().getMode(), SearchCriteria.Op.EQ);
45+
typeModeAndStatusSearch.and("upload_state", typeModeAndStatusSearch.entity().getUploadState(), SearchCriteria.Op.EQ);
46+
typeModeAndStatusSearch.done();
47+
4048
}
4149

4250
@Override
@@ -55,4 +63,12 @@ public List<UploadVO> listByHostAndUploadStatus(long sserverId, Status uploadSta
5563
sc.setParameters("upload_state", uploadState.toString());
5664
return listBy(sc);
5765
}
66+
67+
@Override
68+
public List<UploadVO> listByModeAndStatus(Mode mode, Status uploadState){
69+
SearchCriteria<UploadVO> sc = typeModeAndStatusSearch.create();
70+
sc.setParameters("mode", mode.toString());
71+
sc.setParameters("upload_state", uploadState.toString());
72+
return listBy(sc);
73+
}
5874
}

‎core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
import com.cloud.agent.api.StartupCommand;
4646
import com.cloud.agent.api.StartupStorageCommand;
4747
import com.cloud.agent.api.SecStorageFirewallCfgCommand.PortConfig;
48+
import com.cloud.agent.api.storage.CreateEntityDownloadURLAnswer;
49+
import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
50+
import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
4851
import com.cloud.agent.api.storage.DeleteTemplateCommand;
4952
import com.cloud.agent.api.storage.DownloadCommand;
5053
import com.cloud.agent.api.storage.DownloadProgressCommand;
@@ -117,7 +120,11 @@ public Answer executeRequest(Command cmd) {
117120
return _dlMgr.handleDownloadCommand((DownloadCommand)cmd);
118121
}else if (cmd instanceof UploadCommand) {
119122
return _upldMgr.handleUploadCommand((UploadCommand)cmd);
120-
} else if (cmd instanceof GetStorageStatsCommand) {
123+
}else if (cmd instanceof CreateEntityDownloadURLCommand){
124+
return _upldMgr.handleCreateEntityURLCommand((CreateEntityDownloadURLCommand)cmd);
125+
}else if(cmd instanceof DeleteEntityDownloadURLCommand){
126+
return _upldMgr.handleDeleteEntityDownloadURLCommand((DeleteEntityDownloadURLCommand)cmd);
127+
}else if (cmd instanceof GetStorageStatsCommand) {
121128
return execute((GetStorageStatsCommand)cmd);
122129
} else if (cmd instanceof CheckHealthCommand) {
123130
return new CheckHealthAnswer((CheckHealthCommand)cmd, true);

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

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.cloud.storage.template;
22

3+
import com.cloud.agent.api.storage.CreateEntityDownloadURLAnswer;
4+
import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
5+
import com.cloud.agent.api.storage.DeleteEntityDownloadURLAnswer;
6+
import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
37
import com.cloud.agent.api.storage.UploadAnswer;
48
import com.cloud.agent.api.storage.UploadCommand;
59
import com.cloud.storage.StorageResource;
@@ -61,4 +65,9 @@ String uploadPublicTemplate(long id, String url, String name,
6165
String cksum, String installPathPrefix, String user,
6266
String password, long maxTemplateSizeInBytes);
6367

68+
69+
CreateEntityDownloadURLAnswer handleCreateEntityURLCommand(CreateEntityDownloadURLCommand cmd);
70+
71+
DeleteEntityDownloadURLAnswer handleDeleteEntityDownloadURLCommand(DeleteEntityDownloadURLCommand cmd);
72+
6473
}

0 commit comments

Comments
 (0)