mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Debug & Test template copy from secondary storage to primary stroage on vmware
This commit is contained in:
		
							parent
							
								
									63ebb00434
								
							
						
					
					
						commit
						23a38bc2be
					
				| @ -23,16 +23,25 @@ public class Storage { | ||||
|         RAW(false, false, false), | ||||
|         VHD(true, true, true), | ||||
|         ISO(false, false, false), | ||||
|         VMDK(true, true, true); | ||||
|         VMDK(true, true, true, ".tar.bz2"); | ||||
|          | ||||
|         private final boolean thinProvisioned; | ||||
|         private final boolean supportSparse; | ||||
|         private final boolean supportSnapshot; | ||||
|         private final String fileExtension; | ||||
|          | ||||
|         private ImageFormat(boolean thinProvisioned, boolean supportSparse, boolean supportSnapshot) { | ||||
|             this.thinProvisioned = thinProvisioned; | ||||
|             this.supportSparse = supportSparse; | ||||
|             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() { | ||||
| @ -48,7 +57,10 @@ public class Storage { | ||||
|         } | ||||
|          | ||||
|         public String getFileExtension() { | ||||
|         	if(fileExtension == null) | ||||
|         		return toString().toLowerCase(); | ||||
|         	 | ||||
|         	return fileExtension; | ||||
|         } | ||||
|     } | ||||
|      | ||||
|  | ||||
| @ -29,6 +29,16 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand { | ||||
| 	String poolUuid; | ||||
| 	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() { | ||||
| 	} | ||||
| 
 | ||||
| @ -54,6 +64,22 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand { | ||||
|     	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 | ||||
|     public boolean executeInSequence() { | ||||
|         return true; | ||||
|  | ||||
| @ -20,20 +20,22 @@ public class VmdkProcessor implements Processor { | ||||
|     @Override | ||||
|     public FormatInfo process(String templatePath, ImageFormat format, String templateName) throws InternalErrorException { | ||||
|         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; | ||||
|         } | ||||
|          | ||||
|         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)) { | ||||
|             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; | ||||
|         } | ||||
|          | ||||
|         FormatInfo info = new FormatInfo(); | ||||
|         info.format = ImageFormat.VMDK; | ||||
|         info.filename = templateName + ".tar.bz2"; | ||||
|         info.filename = templateName + ImageFormat.VMDK.getFileExtension(); | ||||
|         info.size = _storage.getSize(templateFilePath); | ||||
|         info.virtualSize = info.size; | ||||
|         return info; | ||||
|  | ||||
| @ -223,7 +223,13 @@ public class TemplateManagerImpl implements TemplateManager { | ||||
|                 return templateStoragePoolRef; | ||||
|             } | ||||
|             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) { | ||||
|                 if (s_logger.isDebugEnabled()) { | ||||
|  | ||||
| @ -18,6 +18,7 @@ | ||||
| 
 | ||||
| package com.cloud.utils; | ||||
| 
 | ||||
| import java.net.URI; | ||||
| import java.text.DateFormat; | ||||
| import java.text.ParseException; | ||||
| import java.text.SimpleDateFormat; | ||||
| @ -235,14 +236,22 @@ public class DateUtil { | ||||
|     		throw new CloudRuntimeException("Incorrect interval: "+type.toString()); | ||||
|     	} | ||||
| 
 | ||||
| 
 | ||||
|     	return scheduleTime.getTime(); | ||||
|     } | ||||
| 
 | ||||
| 	 | ||||
| 	// test only | ||||
| 	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 gmtTimezone = TimeZone.getTimeZone("GMT"); | ||||
| 		TimeZone estTimezone = TimeZone.getTimeZone("EST"); | ||||
| @ -265,6 +274,7 @@ public class DateUtil { | ||||
| 			System.out.println("Parsed TZ time string : "+ dtParsed.toString()); | ||||
| 		} catch (ParseException e) { | ||||
| 		} | ||||
| */		 | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user