Skip to content

Commit 665e951

Browse files
committed
template: Copying templates to all zones if type changed to system
1 parent 6718be0 commit 665e951

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.concurrent.ExecutionException;
2929
import java.util.concurrent.ExecutorService;
3030
import java.util.concurrent.Executors;
31+
import java.util.stream.Collectors;
3132

3233
import javax.inject.Inject;
3334
import javax.naming.ConfigurationException;
@@ -844,16 +845,19 @@ public boolean copy(long userId, VMTemplateVO template, DataStore srcSecStore, D
844845
}
845846
}
846847
return true;
847-
848848
}
849849

850850
@Override
851851
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_COPY, eventDescription = "copying template", async = true)
852852
public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException {
853853
Long templateId = cmd.getId();
854-
Long userId = CallContext.current().getCallingUserId();
855854
Long sourceZoneId = cmd.getSourceZoneId();
856855
List<Long> destZoneIds = cmd.getDestinationZoneIds();
856+
return copyTemplate(templateId, sourceZoneId, destZoneIds);
857+
}
858+
859+
private VirtualMachineTemplate copyTemplate(Long templateId, Long sourceZoneId, List<Long> destZoneIds) throws StorageUnavailableException, ResourceAllocationException {
860+
Long userId = CallContext.current().getCallingUserId();
857861
Account caller = CallContext.current().getCallingAccount();
858862

859863
// Verify parameters
@@ -2198,6 +2202,21 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
21982202
template.setDynamicallyScalable(isDynamicallyScalable);
21992203
}
22002204

2205+
if (templateType != null && templateType == TemplateType.SYSTEM) {
2206+
s_logger.info("Copying template to all zones since it will be a system template");
2207+
List<DataCenterVO> zones = _dcDao.listEnabledZones();
2208+
if (zones != null) {
2209+
List<Long> zoneIds = zones.stream().map(zone -> zone.getId()).collect(Collectors.toList());
2210+
try {
2211+
copyTemplate(id, null, zoneIds);
2212+
} catch (StorageUnavailableException e) {
2213+
throw new CloudRuntimeException("Unable to copy template to other zones : ", e);
2214+
} catch (ResourceAllocationException e) {
2215+
throw new CloudRuntimeException("Unable to copy template to other zones : ", e);
2216+
}
2217+
}
2218+
}
2219+
22012220
if (isRoutingTemplate != null) {
22022221
if (isRoutingTemplate) {
22032222
template.setTemplateType(TemplateType.ROUTING);

0 commit comments

Comments
 (0)