@Override public synchronized void copyServerTemplate(String serverTemplateId, String newServerTemplateId, String newServerTemplateName) { final ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } final Map<Capability, ServerConfig> configMap = new HashMap<Capability, ServerConfig>(serverTemplate.getConfigs().size()); for (final Map.Entry<Capability, ServerConfig> entry : serverTemplate.getConfigs().entrySet()) { configMap.put(entry.getKey(), copy(entry.getValue())); } final Collection<ContainerSpec> containerSpecs = new ArrayList<ContainerSpec>(serverTemplate.getContainersSpec().size()); for (final ContainerSpec entry : serverTemplate.getContainersSpec()) { containerSpecs.add(copy(entry, newServerTemplateId, newServerTemplateName)); } final ServerTemplate copy = new ServerTemplate(newServerTemplateId, newServerTemplateName, serverTemplate.getCapabilities(), configMap, containerSpecs); templateStorage.store(copy); }
@Override public synchronized void saveServerTemplate(ServerTemplate serverTemplate) { if (templateStorage.exists(serverTemplate.getId())) { templateStorage.update(serverTemplate); } else { templateStorage.store(serverTemplate); } notificationService.notify(new ServerTemplateUpdated(serverTemplate)); Collection<ContainerSpec> containerSpecs = serverTemplate.getContainersSpec(); if (containerSpecs != null && !containerSpecs.isEmpty()) { for (ContainerSpec containerSpec : containerSpecs) { if (containerSpec.getStatus().equals(KieContainerStatus.STARTED)) { List<Container> containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec); notificationService.notify(serverTemplate, containerSpec, containers); } } } }
templateStorage.store(serverTemplate);