|
28 | 28 | import java.util.concurrent.ExecutionException; |
29 | 29 | import java.util.concurrent.ExecutorService; |
30 | 30 | import java.util.concurrent.Executors; |
| 31 | +import java.util.stream.Collectors; |
31 | 32 |
|
32 | 33 | import javax.inject.Inject; |
33 | 34 | import javax.naming.ConfigurationException; |
@@ -844,16 +845,19 @@ public boolean copy(long userId, VMTemplateVO template, DataStore srcSecStore, D |
844 | 845 | } |
845 | 846 | } |
846 | 847 | return true; |
847 | | - |
848 | 848 | } |
849 | 849 |
|
850 | 850 | @Override |
851 | 851 | @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_COPY, eventDescription = "copying template", async = true) |
852 | 852 | public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException { |
853 | 853 | Long templateId = cmd.getId(); |
854 | | - Long userId = CallContext.current().getCallingUserId(); |
855 | 854 | Long sourceZoneId = cmd.getSourceZoneId(); |
856 | 855 | 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(); |
857 | 861 | Account caller = CallContext.current().getCallingAccount(); |
858 | 862 |
|
859 | 863 | // Verify parameters |
@@ -2198,6 +2202,21 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) { |
2198 | 2202 | template.setDynamicallyScalable(isDynamicallyScalable); |
2199 | 2203 | } |
2200 | 2204 |
|
| 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 | + |
2201 | 2220 | if (isRoutingTemplate != null) { |
2202 | 2221 | if (isRoutingTemplate) { |
2203 | 2222 | template.setTemplateType(TemplateType.ROUTING); |
|
0 commit comments