Skip to content

Commit 6f80050

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 526af5e commit 6f80050

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;
@@ -394,7 +393,7 @@ public void handleTemplateSync(DataStore store) {
394393
s_logger.info("Template Sync did not find " + uniqueName + " on image store " + storeId +
395394
", may request download based on available hypervisor types");
396395
if (tmpltStore != null) {
397-
if (isRegionStore(store) && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED
396+
if (_storeMgr.isRegionStore(store) && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED
398397
&& tmpltStore.getState() == State.Ready
399398
&& tmpltStore.getInstallPath() == null) {
400399
s_logger.info("Keep fake entry in template store table for migration of previous NFS to object store");
@@ -435,7 +434,7 @@ public void handleTemplateSync(DataStore store) {
435434

436435
// if this is a region store, and there is already an DOWNLOADED entry there without install_path information, which
437436
// means that this is a duplicate entry from migration of previous NFS to staging.
438-
if (isRegionStore(store)) {
437+
if (_storeMgr.isRegionStore(store)) {
439438
TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId());
440439
if (tmpltStore != null && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED && tmpltStore.getState() == State.Ready
441440
&& tmpltStore.getInstallPath() == null) {
@@ -685,18 +684,11 @@ protected Void syncTemplateCallBack(AsyncCallbackDispatcher<TemplateServiceImpl,
685684
return null;
686685
}
687686

688-
private boolean isRegionStore(DataStore store) {
689-
if (store.getScope().getScopeType() == ScopeType.ZONE && store.getScope().getScopeId() == null)
690-
return true;
691-
else
692-
return false;
693-
}
694-
695687
// This routine is used to push templates currently on cache store, but not in region store to region store.
696688
// used in migrating existing NFS secondary storage to S3.
697689
@Override
698690
public void syncTemplateToRegionStore(long templateId, DataStore store) {
699-
if (isRegionStore(store)) {
691+
if (_storeMgr.isRegionStore(store)) {
700692
// if template is on region wide object store, check if it is really downloaded there (by checking install_path). Sync template to region
701693
// wide store if it is not there physically.
702694
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
@@ -1395,8 +1395,14 @@ public VirtualMachineTemplate createPrivateTemplate(CreateTemplateCmd command) t
13951395
throw new CloudRuntimeException("Failed to create template" + result.getResult());
13961396
}
13971397

1398-
VMTemplateZoneVO templateZone = new VMTemplateZoneVO(zoneId, templateId, new Date());
1399-
_tmpltZoneDao.persist(templateZone);
1398+
// create entries in template_zone_ref table
1399+
if (_dataStoreMgr.isRegionStore(store)) {
1400+
// template created on region store
1401+
_tmpltSvr.associateTemplateToZone(templateId, null);
1402+
} else {
1403+
VMTemplateZoneVO templateZone = new VMTemplateZoneVO(zoneId, templateId, new Date());
1404+
_tmpltZoneDao.persist(templateZone);
1405+
}
14001406

14011407
privateTemplate = _tmpltDao.findById(templateId);
14021408
if (snapshotId != null) {

0 commit comments

Comments
 (0)