Skip to content

Commit 23a38bc

Browse files
author
Kelven Yang
committed
Debug & Test template copy from secondary storage to primary stroage on vmware
1 parent 63ebb00 commit 23a38bc

5 files changed

Lines changed: 65 additions & 9 deletions

File tree

‎api/src/com/cloud/storage/Storage.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,25 @@ public static enum ImageFormat {
2323
RAW(false, false, false),
2424
VHD(true, true, true),
2525
ISO(false, false, false),
26-
VMDK(true, true, true);
26+
VMDK(true, true, true, ".tar.bz2");
2727

2828
private final boolean thinProvisioned;
2929
private final boolean supportSparse;
3030
private final boolean supportSnapshot;
31+
private final String fileExtension;
3132

3233
private ImageFormat(boolean thinProvisioned, boolean supportSparse, boolean supportSnapshot) {
3334
this.thinProvisioned = thinProvisioned;
3435
this.supportSparse = supportSparse;
3536
this.supportSnapshot = supportSnapshot;
37+
fileExtension = null;
38+
}
39+
40+
private ImageFormat(boolean thinProvisioned, boolean supportSparse, boolean supportSnapshot, String fileExtension) {
41+
this.thinProvisioned = thinProvisioned;
42+
this.supportSparse = supportSparse;
43+
this.supportSnapshot = supportSnapshot;
44+
this.fileExtension = fileExtension;
3645
}
3746

3847
public boolean isThinProvisioned() {
@@ -48,7 +57,10 @@ public boolean supportSnapshot() {
4857
}
4958

5059
public String getFileExtension() {
51-
return toString().toLowerCase();
60+
if(fileExtension == null)
61+
return toString().toLowerCase();
62+
63+
return fileExtension;
5264
}
5365
}
5466

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand {
2828
String localPath;
2929
String poolUuid;
3030
long poolId;
31+
32+
//
33+
// Temporary hacking to make vmware work quickly, expose NFS raw information to allow
34+
// agent do quick copy over NFS.
35+
//
36+
// provide storage URL (it contains all information to help agent resource to mount the
37+
// storage if needed, example of such URL may be as following
38+
// nfs://192.168.10.231/export/home/kelven/vmware-test/secondary
39+
String secondaryStorageUrl;
40+
String primaryStorageUrl;
3141

3242
protected PrimaryStorageDownloadCommand() {
3343
}
@@ -54,6 +64,22 @@ public String getLocalPath() {
5464
return localPath;
5565
}
5666

67+
public void setSecondaryStorageUrl(String url) {
68+
secondaryStorageUrl = url;
69+
}
70+
71+
public String getSecondaryStorageUrl() {
72+
return secondaryStorageUrl;
73+
}
74+
75+
public void setPrimaryStorageUrl(String url) {
76+
primaryStorageUrl = url;
77+
}
78+
79+
public String getPrimaryStorageUrl() {
80+
return primaryStorageUrl;
81+
}
82+
5783
@Override
5884
public boolean executeInSequence() {
5985
return true;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,22 @@ public class VmdkProcessor implements Processor {
2020
@Override
2121
public FormatInfo process(String templatePath, ImageFormat format, String templateName) throws InternalErrorException {
2222
if (format != null) {
23-
s_logger.debug("We currently don't handle conversion from " + format + " to VMDK.");
23+
if(s_logger.isInfoEnabled())
24+
s_logger.info("We currently don't handle conversion from " + format + " to VMDK.");
2425
return null;
2526
}
2627

2728
s_logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName);
28-
String templateFilePath = templatePath + File.separator + templateName + ".tar.bz2";
29+
String templateFilePath = templatePath + File.separator + templateName + ImageFormat.VMDK.getFileExtension();
2930
if (!_storage.exists(templateFilePath)) {
30-
s_logger.debug("Unable to find the vmware template file: " + templateFilePath);
31+
if(s_logger.isInfoEnabled())
32+
s_logger.info("Unable to find the vmware template file: " + templateFilePath);
3133
return null;
3234
}
3335

3436
FormatInfo info = new FormatInfo();
3537
info.format = ImageFormat.VMDK;
36-
info.filename = templateName + ".tar.bz2";
38+
info.filename = templateName + ImageFormat.VMDK.getFileExtension();
3739
info.size = _storage.getSize(templateFilePath);
3840
info.virtualSize = info.size;
3941
return info;

‎server/src/com/cloud/template/TemplateManagerImpl.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,13 @@ public VMTemplateStoragePoolVO prepareTemplateForCreate(VMTemplateVO template, S
223223
return templateStoragePoolRef;
224224
}
225225
String url = origUrl + "/" + templateHostRef.getInstallPath();
226-
PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(template.getUniqueName(), url, template.getFormat(), template.getAccountId(), pool.getId(), pool.getUuid());
226+
PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(template.getUniqueName(), url, template.getFormat(),
227+
template.getAccountId(), pool.getId(), pool.getUuid());
228+
HostVO secondaryStorageHost = _hostDao.findSecondaryStorageHost(pool.getDataCenterId());
229+
assert(secondaryStorageHost != null);
230+
dcmd.setSecondaryStorageUrl(secondaryStorageHost.getStorageUrl());
231+
// TODO temporary hacking, hard-coded to NFS primary data store
232+
dcmd.setPrimaryStorageUrl("nfs://" + pool.getHostAddress() + pool.getPath());
227233

228234
for (StoragePoolHostVO vo : vos) {
229235
if (s_logger.isDebugEnabled()) {

‎utils/src/com/cloud/utils/DateUtil.java‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.cloud.utils;
2020

21+
import java.net.URI;
2122
import java.text.DateFormat;
2223
import java.text.ParseException;
2324
import java.text.SimpleDateFormat;
@@ -235,14 +236,22 @@ public static Date getNextRunTime(IntervalType type, String schedule, String tim
235236
throw new CloudRuntimeException("Incorrect interval: "+type.toString());
236237
}
237238

238-
239239
return scheduleTime.getTime();
240240
}
241241

242242

243243
// test only
244244
public static void main(String[] args) {
245-
245+
try {
246+
URI uri = new URI("nfs://192.168.10.231/export/home/kelven/vmware-test/secondary");
247+
System.out.println("protocol: " + uri.getScheme());
248+
System.out.println("Host: " + uri.getHost());
249+
System.out.println("path: " + uri.getPath());
250+
System.out.println("port: " + uri.getPort());
251+
} catch(Exception e) {
252+
}
253+
254+
/*
246255
TimeZone localTimezone = Calendar.getInstance().getTimeZone();
247256
TimeZone gmtTimezone = TimeZone.getTimeZone("GMT");
248257
TimeZone estTimezone = TimeZone.getTimeZone("EST");
@@ -265,6 +274,7 @@ public static void main(String[] args) {
265274
System.out.println("Parsed TZ time string : "+ dtParsed.toString());
266275
} catch (ParseException e) {
267276
}
277+
*/
268278
}
269279
}
270280

0 commit comments

Comments
 (0)