Skip to content

Commit f1e5884

Browse files
committed
Enforce secondary storage copy limits and replicate templates up to capacity during template management
1 parent 97569b9 commit f1e5884

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,15 @@ protected Void createTemplateCallback(AsyncCallbackDispatcher<TemplateServiceImp
11461146
return null;
11471147
}
11481148

1149+
try {
1150+
DataStore destStore = template.getDataStore();
1151+
if (destStore != null && destStore.getScope() != null && destStore.getScope().getScopeId() != null) {
1152+
enforceSecStorageCopyLimit(template.getId(), destStore.getScope().getScopeId());
1153+
}
1154+
} catch (Exception e) {
1155+
logger.warn("Failed to enforce secstorage copy limit after template [{}] became Ready: {}", template.getUuid(), e.getMessage());
1156+
}
1157+
11491158
if (parentCallback != null) {
11501159
parentCallback.complete(result);
11511160
}
@@ -1587,6 +1596,14 @@ protected Void copyTemplateCallBack(AsyncCallbackDispatcher<TemplateServiceImpl,
15871596
destTemplate.processEvent(Event.OperationFailed);
15881597
} else {
15891598
destTemplate.processEvent(Event.OperationSucceeded, result.getAnswer());
1599+
try {
1600+
DataStore destStore = destTemplate.getDataStore();
1601+
if (destStore != null && destStore.getScope() != null && destStore.getScope().getScopeId() != null) {
1602+
enforceSecStorageCopyLimit(destTemplate.getId(), destStore.getScope().getScopeId());
1603+
}
1604+
} catch (Exception e) {
1605+
logger.warn("Failed to enforce secstorage copy limit after copy of template [{}] became Ready: {}", destTemplate.getUuid(), e.getMessage());
1606+
}
15901607
}
15911608
future.complete(res);
15921609
} catch (Exception e) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
17031703
if (isPublic != null || isFeatured != null || "reset".equalsIgnoreCase(operation)) {
17041704
for (VMTemplateZoneVO templateZone : _tmpltZoneDao.listByTemplateId(template.getId())) {
17051705
_tmpltSvr.enforceSecStorageCopyLimit(template.getId(), templateZone.getZoneId());
1706+
_tmpltSvr.replicateTemplateUpToCap(template.getId(), templateZone.getZoneId());
17061707
}
17071708
}
17081709
return true;

0 commit comments

Comments
 (0)