Debug & Test template copy from secondary storage to primary stroage on vmware

This commit is contained in:
Kelven Yang 2010-08-25 18:17:20 -07:00
parent 63ebb00434
commit 23a38bc2be
5 changed files with 65 additions and 9 deletions

View File

@ -23,16 +23,25 @@ public class Storage {
RAW(false, false, false), RAW(false, false, false),
VHD(true, true, true), VHD(true, true, true),
ISO(false, false, false), ISO(false, false, false),
VMDK(true, true, true); VMDK(true, true, true, ".tar.bz2");
private final boolean thinProvisioned; private final boolean thinProvisioned;
private final boolean supportSparse; private final boolean supportSparse;
private final boolean supportSnapshot; private final boolean supportSnapshot;
private final String fileExtension;
private ImageFormat(boolean thinProvisioned, boolean supportSparse, boolean supportSnapshot) { private ImageFormat(boolean thinProvisioned, boolean supportSparse, boolean supportSnapshot) {
this.thinProvisioned = thinProvisioned; this.thinProvisioned = thinProvisioned;
this.supportSparse = supportSparse; this.supportSparse = supportSparse;
this.supportSnapshot = supportSnapshot; this.supportSnapshot = supportSnapshot;
fileExtension = null;
}
private ImageFormat(boolean thinProvisioned, boolean supportSparse, boolean supportSnapshot, String fileExtension) {
this.thinProvisioned = thinProvisioned;
this.supportSparse = supportSparse;
this.supportSnapshot = supportSnapshot;
this.fileExtension = fileExtension;
} }
public boolean isThinProvisioned() { public boolean isThinProvisioned() {
@ -48,7 +57,10 @@ public class Storage {
} }
public String getFileExtension() { public String getFileExtension() {
if(fileExtension == null)
return toString().toLowerCase(); return toString().toLowerCase();
return fileExtension;
} }
} }

View File

@ -29,6 +29,16 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand {
String poolUuid; String poolUuid;
long poolId; long poolId;
//
// Temporary hacking to make vmware work quickly, expose NFS raw information to allow
// agent do quick copy over NFS.
//
// provide storage URL (it contains all information to help agent resource to mount the
// storage if needed, example of such URL may be as following
// nfs://192.168.10.231/export/home/kelven/vmware-test/secondary
String secondaryStorageUrl;
String primaryStorageUrl;
protected PrimaryStorageDownloadCommand() { protected PrimaryStorageDownloadCommand() {
} }
@ -54,6 +64,22 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand {
return localPath; return localPath;
} }
public void setSecondaryStorageUrl(String url) {
secondaryStorageUrl = url;
}
public String getSecondaryStorageUrl() {
return secondaryStorageUrl;
}
public void setPrimaryStorageUrl(String url) {
primaryStorageUrl = url;
}
public String getPrimaryStorageUrl() {
return primaryStorageUrl;
}
@Override @Override
public boolean executeInSequence() { public boolean executeInSequence() {
return true; return true;

View File

@ -20,20 +20,22 @@ public class VmdkProcessor implements Processor {
@Override @Override
public FormatInfo process(String templatePath, ImageFormat format, String templateName) throws InternalErrorException { public FormatInfo process(String templatePath, ImageFormat format, String templateName) throws InternalErrorException {
if (format != null) { if (format != null) {
s_logger.debug("We currently don't handle conversion from " + format + " to VMDK."); if(s_logger.isInfoEnabled())
s_logger.info("We currently don't handle conversion from " + format + " to VMDK.");
return null; return null;
} }
s_logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName); s_logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName);
String templateFilePath = templatePath + File.separator + templateName + ".tar.bz2"; String templateFilePath = templatePath + File.separator + templateName + ImageFormat.VMDK.getFileExtension();
if (!_storage.exists(templateFilePath)) { if (!_storage.exists(templateFilePath)) {
s_logger.debug("Unable to find the vmware template file: " + templateFilePath); if(s_logger.isInfoEnabled())
s_logger.info("Unable to find the vmware template file: " + templateFilePath);
return null; return null;
} }
FormatInfo info = new FormatInfo(); FormatInfo info = new FormatInfo();
info.format = ImageFormat.VMDK; info.format = ImageFormat.VMDK;
info.filename = templateName + ".tar.bz2"; info.filename = templateName + ImageFormat.VMDK.getFileExtension();
info.size = _storage.getSize(templateFilePath); info.size = _storage.getSize(templateFilePath);
info.virtualSize = info.size; info.virtualSize = info.size;
return info; return info;

View File

@ -223,7 +223,13 @@ public class TemplateManagerImpl implements TemplateManager {
return templateStoragePoolRef; return templateStoragePoolRef;
} }
String url = origUrl + "/" + templateHostRef.getInstallPath(); String url = origUrl + "/" + templateHostRef.getInstallPath();
PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(template.getUniqueName(), url, template.getFormat(), template.getAccountId(), pool.getId(), pool.getUuid()); PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(template.getUniqueName(), url, template.getFormat(),
template.getAccountId(), pool.getId(), pool.getUuid());
HostVO secondaryStorageHost = _hostDao.findSecondaryStorageHost(pool.getDataCenterId());
assert(secondaryStorageHost != null);
dcmd.setSecondaryStorageUrl(secondaryStorageHost.getStorageUrl());
// TODO temporary hacking, hard-coded to NFS primary data store
dcmd.setPrimaryStorageUrl("nfs://" + pool.getHostAddress() + pool.getPath());
for (StoragePoolHostVO vo : vos) { for (StoragePoolHostVO vo : vos) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {

View File

@ -18,6 +18,7 @@
package com.cloud.utils; package com.cloud.utils;
import java.net.URI;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -235,14 +236,22 @@ public class DateUtil {
throw new CloudRuntimeException("Incorrect interval: "+type.toString()); throw new CloudRuntimeException("Incorrect interval: "+type.toString());
} }
return scheduleTime.getTime(); return scheduleTime.getTime();
} }
// test only // test only
public static void main(String[] args) { public static void main(String[] args) {
try {
URI uri = new URI("nfs://192.168.10.231/export/home/kelven/vmware-test/secondary");
System.out.println("protocol: " + uri.getScheme());
System.out.println("Host: " + uri.getHost());
System.out.println("path: " + uri.getPath());
System.out.println("port: " + uri.getPort());
} catch(Exception e) {
}
/*
TimeZone localTimezone = Calendar.getInstance().getTimeZone(); TimeZone localTimezone = Calendar.getInstance().getTimeZone();
TimeZone gmtTimezone = TimeZone.getTimeZone("GMT"); TimeZone gmtTimezone = TimeZone.getTimeZone("GMT");
TimeZone estTimezone = TimeZone.getTimeZone("EST"); TimeZone estTimezone = TimeZone.getTimeZone("EST");
@ -265,6 +274,7 @@ public class DateUtil {
System.out.println("Parsed TZ time string : "+ dtParsed.toString()); System.out.println("Parsed TZ time string : "+ dtParsed.toString());
} catch (ParseException e) { } catch (ParseException e) {
} }
*/
} }
} }