mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Workaround an issue of null url when ListTemplateCommand is received on
SSVM side, also fix a bug in listTemplates with id passed.
This commit is contained in:
		
							parent
							
								
									bb7a72b7d6
								
							
						
					
					
						commit
						a221ecb484
					
				| @ -16,19 +16,18 @@ | ||||
| // under the License. | ||||
| package com.cloud.agent.api.storage; | ||||
| 
 | ||||
| import com.cloud.agent.api.LogLevel; | ||||
| import com.cloud.agent.api.LogLevel.Log4jLevel; | ||||
| import com.cloud.agent.api.to.DataStoreTO; | ||||
| 
 | ||||
| public class ListTemplateCommand extends StorageCommand { | ||||
|     @LogLevel(Log4jLevel.Off) | ||||
|     private DataStoreTO store; | ||||
|     private String secUrl; | ||||
| 
 | ||||
|     public ListTemplateCommand() { | ||||
|     } | ||||
| 
 | ||||
| 	public ListTemplateCommand(DataStoreTO store) { | ||||
| 	public ListTemplateCommand(DataStoreTO store, String url) { | ||||
|         this.store = store; | ||||
|         this.secUrl = url; | ||||
| 	} | ||||
| 
 | ||||
|     @Override | ||||
| @ -41,4 +40,8 @@ public class ListTemplateCommand extends StorageCommand { | ||||
|         return store; | ||||
|     } | ||||
| 
 | ||||
|     public String getSecUrl() { | ||||
|         return secUrl; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -16,15 +16,19 @@ | ||||
| // under the License. | ||||
| package com.cloud.agent.api.storage; | ||||
| 
 | ||||
| import com.cloud.agent.api.to.DataStoreTO; | ||||
| 
 | ||||
| 
 | ||||
| public class ListVolumeCommand extends StorageCommand { | ||||
| 
 | ||||
|     private DataStoreTO store; | ||||
|     private String secUrl; | ||||
| 
 | ||||
|     public ListVolumeCommand() { | ||||
|     } | ||||
| 
 | ||||
| 	public ListVolumeCommand(String secUrl) { | ||||
| 	public ListVolumeCommand(DataStoreTO store, String secUrl) { | ||||
| 	    this.store = store; | ||||
| 	    this.secUrl = secUrl; | ||||
| 	} | ||||
| 
 | ||||
| @ -37,4 +41,7 @@ public class ListVolumeCommand extends StorageCommand { | ||||
|         return secUrl; | ||||
|     } | ||||
| 
 | ||||
|     public DataStoreTO getDataStore() { | ||||
|         return store; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -327,6 +327,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S | ||||
|         return join(asList(VOLUME_ROOT_DIR, accountId, volId), S3Utils.SEPARATOR); | ||||
|     } | ||||
| 
 | ||||
|     @SuppressWarnings("unchecked") | ||||
|     protected Long determineS3VolumeIdFromKey(String key) { | ||||
|         return Long.parseLong(StringUtils.substringAfterLast(StringUtils.substringBeforeLast(key, S3Utils.SEPARATOR), S3Utils.SEPARATOR)); | ||||
|     } | ||||
| 
 | ||||
|     @SuppressWarnings("unchecked") | ||||
|     private String determineStorageTemplatePath(final String storagePath, String dataPath) { | ||||
|         return join(asList(getRootDir(storagePath), dataPath), File.separator); | ||||
| @ -1121,6 +1126,25 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     Map<Long, TemplateProp> s3ListVolume(S3TO s3) { | ||||
|         String bucket = s3.getBucketName(); | ||||
|         // List the objects in the source directory on S3 | ||||
|         final List<S3ObjectSummary> objectSummaries = S3Utils.getDirectory(s3, bucket, this.VOLUME_ROOT_DIR); | ||||
|         if (objectSummaries == null) | ||||
|             return null; | ||||
|         Map<Long, TemplateProp> tmpltInfos = new HashMap<Long, TemplateProp>(); | ||||
|         for (S3ObjectSummary objectSummary : objectSummaries) { | ||||
|             String key = objectSummary.getKey(); | ||||
|             String installPath = StringUtils.substringBeforeLast(key, S3Utils.SEPARATOR); | ||||
|             Long id = this.determineS3VolumeIdFromKey(key); | ||||
|             // TODO: how to get volume template name | ||||
|             TemplateProp tInfo = new TemplateProp(id.toString(), installPath, objectSummary.getSize(), objectSummary.getSize(), true, false); | ||||
|             tmpltInfos.put(id, tInfo); | ||||
|         } | ||||
|         return tmpltInfos; | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private Answer execute(ListTemplateCommand cmd) { | ||||
|         if (!_inSystemVM) { | ||||
|             return new Answer(cmd, true, null); | ||||
| @ -1129,9 +1153,10 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S | ||||
|         DataStoreTO store = cmd.getDataStore(); | ||||
|         if (store instanceof NfsTO) { | ||||
|             NfsTO nfs = (NfsTO) store; | ||||
|             String root = getRootDir(nfs.getUrl()); | ||||
|             String secUrl = cmd.getSecUrl(); | ||||
|             String root = getRootDir(secUrl); | ||||
|             Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root); | ||||
|             return new ListTemplateAnswer(nfs.getUrl(), templateInfos); | ||||
|             return new ListTemplateAnswer(secUrl, templateInfos); | ||||
|         } else if (store instanceof SwiftTO) { | ||||
|             SwiftTO swift = (SwiftTO) store; | ||||
|             Map<String, TemplateProp> templateInfos = swiftListTemplate(swift); | ||||
| @ -1150,9 +1175,19 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S | ||||
|             return new Answer(cmd, true, null); | ||||
|         } | ||||
| 
 | ||||
|         String root = getRootDir(cmd.getSecUrl()); | ||||
|         Map<Long, TemplateProp> templateInfos = _dlMgr.gatherVolumeInfo(root); | ||||
|         return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos); | ||||
|         DataStoreTO store = cmd.getDataStore(); | ||||
|         if (store instanceof NfsTO) { | ||||
|             NfsTO nfs = (NfsTO)store; | ||||
|             String root = getRootDir(cmd.getSecUrl()); | ||||
|             Map<Long, TemplateProp> templateInfos = _dlMgr.gatherVolumeInfo(root); | ||||
|             return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos); | ||||
|         } else if (store instanceof S3TO ){ | ||||
|             S3TO s3 = (S3TO)store; | ||||
|             Map<Long, TemplateProp> templateInfos = s3ListVolume(s3); | ||||
|             return new ListVolumeAnswer(s3.getBucketName(), templateInfos); | ||||
|         } else { | ||||
|             return new Answer(cmd, false, "Unsupported image data store: " + store); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -417,7 +417,7 @@ public class TemplateServiceImpl implements TemplateService { | ||||
| 
 | ||||
| 
 | ||||
|     private Map<String, TemplateProp> listTemplate(DataStore ssStore) { | ||||
|         ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO()); | ||||
|         ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO(), ssStore.getUri()); | ||||
|         EndPoint ep = _epSelector.select(ssStore); | ||||
|         Answer answer = ep.sendMessage(cmd); | ||||
|         if (answer != null && answer.getResult()) { | ||||
|  | ||||
| @ -828,7 +828,7 @@ public class VolumeServiceImpl implements VolumeService { | ||||
|     } | ||||
| 
 | ||||
|     private Map<Long, TemplateProp> listVolume(DataStore store) { | ||||
|         ListVolumeCommand cmd = new ListVolumeCommand(store.getUri()); | ||||
|         ListVolumeCommand cmd = new ListVolumeCommand(store.getTO(), store.getUri()); | ||||
|         EndPoint ep = _epSelector.select(store); | ||||
|         Answer answer = ep.sendMessage(cmd); | ||||
|         if (answer != null && answer.getResult()) { | ||||
|  | ||||
| @ -2643,7 +2643,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { | ||||
|             } | ||||
| 
 | ||||
|             // other criteria | ||||
|             if (keyword != null) { | ||||
|             if (templateId != null){ | ||||
|                 sc.addAnd("id", SearchCriteria.Op.EQ, templateId); | ||||
|             } | ||||
|             else if (keyword != null) { | ||||
|                 sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); | ||||
|             } else if (name != null) { | ||||
|                 sc.addAnd("name", SearchCriteria.Op.EQ, name); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user