mirror of https://github.com/apache/cloudstack.git
code refactoring
This commit is contained in:
parent
4928d9bd15
commit
fb053ca7a1
|
|
@ -665,6 +665,11 @@ public class TemplateServiceImpl implements TemplateService {
|
|||
continue;
|
||||
}
|
||||
|
||||
Map<String, TemplateProp> templates = listTemplate(store);
|
||||
if (templates == null || !templates.containsKey(tmplt.getUniqueName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tmpl.getInstallPath() == null) {
|
||||
logger.debug("Template [{}] found in image store [{}] but install path is null. Skipping.",
|
||||
tmplt.getUniqueName(), store.getName());
|
||||
|
|
@ -678,24 +683,14 @@ public class TemplateServiceImpl implements TemplateService {
|
|||
private boolean searchAndCopyWithinZone(VMTemplateVO tmplt, DataStore destStore) {
|
||||
Long destZoneId = destStore.getScope().getScopeId();
|
||||
List<DataStore> storesInSameZone = _storeMgr.getImageStoresByZoneIds(destZoneId);
|
||||
for (DataStore sourceStore : storesInSameZone) {
|
||||
Map<String, TemplateProp> existingTemplatesInSourceStore = listTemplate(sourceStore);
|
||||
if (existingTemplatesInSourceStore == null ||
|
||||
!existingTemplatesInSourceStore.containsKey(tmplt.getUniqueName())) {
|
||||
logger.debug("Template [{}] does not exist on image store [{}]; searching another.", tmplt.getUniqueName(), sourceStore.getName());
|
||||
continue;
|
||||
}
|
||||
|
||||
TemplateObject sourceTmpl = (TemplateObject) _templateFactory.getTemplate(tmplt.getId(), sourceStore);
|
||||
if (sourceTmpl.getInstallPath() == null) {
|
||||
logger.warn("Cannot copy template [{}] from image store [{}]; install path is null.", tmplt.getUniqueName(), sourceStore.getName());
|
||||
continue;
|
||||
}
|
||||
|
||||
storageOrchestrator.orchestrateTemplateCopyToImageStore(sourceTmpl, destStore);
|
||||
return true;
|
||||
TemplateObject sourceTmpl = findUsableTemplate(tmplt, storesInSameZone);
|
||||
if (sourceTmpl == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
storageOrchestrator.orchestrateTemplateCopyToImageStore(sourceTmpl, destStore);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean copyTemplateAcrossZones(DataStore destStore, TemplateObject sourceTmpl) {
|
||||
|
|
|
|||
|
|
@ -302,6 +302,8 @@ public class TemplateServiceImplTest {
|
|||
Mockito.when(storeWithNullPath.getName()).thenReturn("store-null");
|
||||
|
||||
DataStore storeWithValidPath = Mockito.mock(DataStore.class);
|
||||
Mockito.when(storeWithValidPath.getName()).thenReturn("store-valid");
|
||||
|
||||
TemplateObject tmplWithNullPath = Mockito.mock(TemplateObject.class);
|
||||
Mockito.when(tmplWithNullPath.getInstallPath()).thenReturn(null);
|
||||
|
||||
|
|
@ -311,6 +313,12 @@ public class TemplateServiceImplTest {
|
|||
Mockito.doReturn(tmplWithNullPath).when(templateDataFactoryMock).getTemplate(10L, storeWithNullPath);
|
||||
Mockito.doReturn(tmplWithValidPath).when(templateDataFactoryMock).getTemplate(10L, storeWithValidPath);
|
||||
|
||||
Map<String, TemplateProp> templates = new HashMap<>();
|
||||
templates.put("test-template", Mockito.mock(TemplateProp.class));
|
||||
|
||||
Mockito.doReturn(templates).when(templateService).listTemplate(storeWithNullPath);
|
||||
Mockito.doReturn(templates).when(templateService).listTemplate(storeWithValidPath);
|
||||
|
||||
List<DataStore> imageStores = List.of(storeWithNullPath, storeWithValidPath);
|
||||
|
||||
TemplateObject result = templateService.findUsableTemplate(template, imageStores);
|
||||
|
|
|
|||
Loading…
Reference in New Issue