Skip to content

Commit 69524fb

Browse files
committed
CLOUDSTACK-5653:S3 object store as Secondary Storage, the template
created from different zone is not available for the other zones.
1 parent 69fb1d4 commit 69524fb

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ public interface DataStoreManager {
4242
List<DataStore> listImageStores();
4343

4444
List<DataStore> listImageCacheStores();
45+
46+
boolean isRegionStore(DataStore store);
4547
}

engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
import com.cloud.exception.ResourceAllocationException;
7676
import com.cloud.hypervisor.Hypervisor.HypervisorType;
7777
import com.cloud.storage.DataStoreRole;
78-
import com.cloud.storage.ScopeType;
7978
import com.cloud.storage.Storage.TemplateType;
8079
import com.cloud.storage.StoragePool;
8180
import com.cloud.storage.VMTemplateStorageResourceAssoc;
@@ -399,7 +398,7 @@ public void handleTemplateSync(DataStore store) {
399398
} else {
400399
s_logger.info("Template Sync did not find " + uniqueName + " on image store " + storeId + ", may request download based on available hypervisor types");
401400
if (tmpltStore != null) {
402-
if (isRegionStore(store) && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED
401+
if (_storeMgr.isRegionStore(store) && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED
403402
&& tmpltStore.getState() == State.Ready
404403
&& tmpltStore.getInstallPath() == null) {
405404
s_logger.info("Keep fake entry in template store table for migration of previous NFS to object store");
@@ -440,7 +439,7 @@ public void handleTemplateSync(DataStore store) {
440439

441440
// if this is a region store, and there is already an DOWNLOADED entry there without install_path information, which
442441
// means that this is a duplicate entry from migration of previous NFS to staging.
443-
if (isRegionStore(store)) {
442+
if (_storeMgr.isRegionStore(store)) {
444443
TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId());
445444
if (tmpltStore != null && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED && tmpltStore.getState() == State.Ready
446445
&& tmpltStore.getInstallPath() == null) {
@@ -700,18 +699,11 @@ protected Void syncTemplateCallBack(AsyncCallbackDispatcher<TemplateServiceImpl,
700699
return null;
701700
}
702701

703-
private boolean isRegionStore(DataStore store) {
704-
if (store.getScope().getScopeType() == ScopeType.ZONE && store.getScope().getScopeId() == null)
705-
return true;
706-
else
707-
return false;
708-
}
709-
710702
// This routine is used to push templates currently on cache store, but not in region store to region store.
711703
// used in migrating existing NFS secondary storage to S3.
712704
@Override
713705
public void syncTemplateToRegionStore(long templateId, DataStore store) {
714-
if (isRegionStore(store)) {
706+
if (_storeMgr.isRegionStore(store)) {
715707
// if template is on region wide object store, check if it is really downloaded there (by checking install_path). Sync template to region
716708
// wide store if it is not there physically.
717709
TemplateInfo tmplOnStore = _templateFactory.getTemplate(templateId, store);

engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
3333

3434
import com.cloud.storage.DataStoreRole;
35+
import com.cloud.storage.ScopeType;
3536
import com.cloud.utils.exception.CloudRuntimeException;
3637

3738
@Component
@@ -82,6 +83,14 @@ public DataStore getImageStore(long zoneId) {
8283
return stores.get(0);
8384
}
8485

86+
@Override
87+
public boolean isRegionStore(DataStore store) {
88+
if (store.getScope().getScopeType() == ScopeType.ZONE && store.getScope().getScopeId() == null)
89+
return true;
90+
else
91+
return false;
92+
}
93+
8594
@Override
8695
public DataStore getPrimaryDataStore(long storeId) {
8796
return primaryStoreMgr.getPrimaryDataStore(storeId);

server/src/com/cloud/template/TemplateManagerImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,8 +1405,14 @@ public VirtualMachineTemplate createPrivateTemplate(CreateTemplateCmd command) t
14051405
throw new CloudRuntimeException("Failed to create template" + result.getResult());
14061406
}
14071407

1408-
VMTemplateZoneVO templateZone = new VMTemplateZoneVO(zoneId, templateId, new Date());
1409-
_tmpltZoneDao.persist(templateZone);
1408+
// create entries in template_zone_ref table
1409+
if (_dataStoreMgr.isRegionStore(store)) {
1410+
// template created on region store
1411+
_tmpltSvr.associateTemplateToZone(templateId, null);
1412+
} else {
1413+
VMTemplateZoneVO templateZone = new VMTemplateZoneVO(zoneId, templateId, new Date());
1414+
_tmpltZoneDao.persist(templateZone);
1415+
}
14101416

14111417
privateTemplate = _tmpltDao.findById(templateId);
14121418
if (snapshotId != null) {

0 commit comments

Comments
 (0)