|
41 | 41 | import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; |
42 | 42 | import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; |
43 | 43 | import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event; |
| 44 | +import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State; |
44 | 45 | import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; |
45 | 46 | import org.apache.cloudstack.engine.subsystem.api.storage.StorageCacheManager; |
46 | 47 | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory; |
|
77 | 78 | import com.cloud.storage.ScopeType; |
78 | 79 | import com.cloud.storage.Storage.TemplateType; |
79 | 80 | import com.cloud.storage.StoragePool; |
| 81 | +import com.cloud.storage.VMTemplateStorageResourceAssoc; |
80 | 82 | import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; |
81 | 83 | import com.cloud.storage.VMTemplateVO; |
82 | 84 | import com.cloud.storage.VMTemplateZoneVO; |
@@ -281,7 +283,7 @@ public void handleTemplateSync(DataStore store) { |
281 | 283 | GlobalLock syncLock = GlobalLock.getInternLock(lockString); |
282 | 284 | try { |
283 | 285 | if (syncLock.lock(3)) { |
284 | | - try{ |
| 286 | + try { |
285 | 287 | Long zoneId = store.getScope().getScopeId(); |
286 | 288 |
|
287 | 289 | Map<String, TemplateProp> templateInfos = listTemplate(store); |
@@ -393,14 +395,20 @@ public void handleTemplateSync(DataStore store) { |
393 | 395 | _templateDao.update(tmplt.getId(), tmlpt); |
394 | 396 | associateTemplateToZone(tmplt.getId(), zoneId); |
395 | 397 |
|
396 | | - |
397 | 398 | } |
398 | 399 | } else { |
399 | 400 | s_logger.info("Template Sync did not find " + uniqueName + " on image store " + storeId + ", may request download based on available hypervisor types"); |
400 | 401 | if (tmpltStore != null) { |
401 | | - s_logger.info("Removing leftover template " + uniqueName + " entry from template store table"); |
402 | | - // remove those leftover entries |
403 | | - _vmTemplateStoreDao.remove(tmpltStore.getId()); |
| 402 | + if (isRegionStore(store) && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED |
| 403 | + && tmpltStore.getState() == State.Ready |
| 404 | + && tmpltStore.getInstallPath() == null) { |
| 405 | + s_logger.info("Keep fake entry in template store table for migration of previous NFS to object store"); |
| 406 | + } |
| 407 | + else { |
| 408 | + s_logger.info("Removing leftover template " + uniqueName + " entry from template store table"); |
| 409 | + // remove those leftover entries |
| 410 | + _vmTemplateStoreDao.remove(tmpltStore.getId()); |
| 411 | + } |
404 | 412 | } |
405 | 413 | } |
406 | 414 | } |
@@ -430,6 +438,17 @@ public void handleTemplateSync(DataStore store) { |
430 | 438 | continue; |
431 | 439 | } |
432 | 440 |
|
| 441 | + // if this is a region store, and there is already an DOWNLOADED entry there without install_path information, which |
| 442 | + // means that this is a duplicate entry from migration of previous NFS to staging. |
| 443 | + if (isRegionStore(store)) { |
| 444 | + TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId()); |
| 445 | + if (tmpltStore != null && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED && tmpltStore.getState() == State.Ready |
| 446 | + && tmpltStore.getInstallPath() == null) { |
| 447 | + s_logger.info("Skip sync template for migration of previous NFS to object store"); |
| 448 | + continue; |
| 449 | + } |
| 450 | + } |
| 451 | + |
433 | 452 | if (availHypers.contains(tmplt.getHypervisorType())) { |
434 | 453 | s_logger.info("Downloading template " + tmplt.getUniqueName() + " to image store " |
435 | 454 | + store.getName()); |
@@ -474,8 +493,7 @@ public void handleTemplateSync(DataStore store) { |
474 | 493 |
|
475 | 494 | } |
476 | 495 | } |
477 | | - } |
478 | | - finally{ |
| 496 | + } finally { |
479 | 497 | syncLock.unlock(); |
480 | 498 | } |
481 | 499 | } |
|
0 commit comments