From 924ba9adf027dd4969896cd905a8a41ba4c30655 Mon Sep 17 00:00:00 2001 From: talio Date: Mon, 29 Jan 2018 11:23:39 +0200 Subject: Add Tosca model healer create a Tosca model healer for future changes in Tosca structure Change-Id: I3843e4727b6bbb383576ae6a4fb055c5b6fa001f Issue-ID: SDC-973 Signed-off-by: talio --- .../model/impl/EnrichedServiceModelDaoImpl.java | 7 +++ .../sdc/model/impl/ServiceModelDaoImpl.java | 6 +++ .../impl/zusammen/ServiceModelDaoZusammenImpl.java | 61 +++++++++++++++++++++- 3 files changed, 73 insertions(+), 1 deletion(-) (limited to 'openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java') diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoImpl.java index 348a8addbd..3bf61e5b39 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoImpl.java @@ -45,4 +45,11 @@ public class EnrichedServiceModelDaoImpl extends AbstractServiceModelDao templateDao.deleteAll(vspId, version); artifactDao.deleteAll(vspId, version); } + + @Override + public void overrideServiceModel(String vspId, Version version, ToscaServiceModel serviceModel) { + storeServiceModel(vspId, version, serviceModel); + } + + } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoImpl.java index 4ad8d7c98a..b9a703e96d 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoImpl.java @@ -39,4 +39,10 @@ public class ServiceModelDaoImpl extends AbstractServiceModelDao public void deleteAll(String vspId, Version version) { } + + @Override + public void overrideServiceModel(String vspId, Version version, + ToscaServiceModel serviceModel) { + storeServiceModel(vspId, version, serviceModel); + } } diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java index 4ae9353f42..c73a304c97 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java @@ -162,6 +162,65 @@ public class ServiceModelDaoZusammenImpl elementType.name(), vspId, version.getId()); } + @Override + public void overrideServiceModel(String vspId, + Version version, + ToscaServiceModel serviceModel) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(vspId, version.getId()); + + ZusammenElement serviceModelElement = buildStructuralElement(elementType, Action.UPDATE); + + Optional origServiceModel = getServiceModelElementInfo(context, elementContext); + if (!origServiceModel.isPresent()) { + return; + } + + Id serviceModelElementId = origServiceModel.get().getId(); + overrideServiceTemplates(serviceModelElementId, serviceModel, context, elementContext, + serviceModelElement); + serviceModelElement.getInfo() + .addProperty(BASE_PROPERTY, serviceModel.getEntryDefinitionServiceTemplate()); + + zusammenAdaptor + .saveElement(context, elementContext, serviceModelElement, "Override service model"); + } + + + private void overrideServiceTemplates(Id serviceModelElementId, + ToscaServiceModel serviceModel, + SessionContext context, + ElementContext elementContext, + ZusammenElement serviceModelElement) { + Optional elementInfo = zusammenAdaptor.getElementInfoByName( + context, elementContext, serviceModelElementId, ElementType.ServiceTemplate.name()); + if (!elementInfo.isPresent()) { + return; + } + ZusammenElement zusammenElement = + buildStructuralElement(ElementType.ServiceTemplate, Action.UPDATE); + Collection elements = zusammenAdaptor.listElementData(context, elementContext, + elementInfo.get().getId()); + + elements + .forEach(element -> zusammenElement + .addSubElement(overrideServiceTemplateInElement(element, serviceModel))); + + serviceModelElement.addSubElement(zusammenElement); + } + + private ZusammenElement overrideServiceTemplateInElement(Element element, + ToscaServiceModel serviceModel) { + ZusammenElement serviceTemplateElement = (ZusammenElement) element; + String templateName = element.getInfo().getName(); + Optional serviceTemplate = serviceModel.getServiceTemplate(templateName); + serviceTemplate.ifPresent(serviceTemplateFile -> { + String yaml = new ToscaExtensionYamlUtil().objectToYaml(serviceTemplateFile); + serviceTemplateElement.setData(new ByteArrayInputStream(yaml.getBytes())); + }); + return serviceTemplateElement; + } + private Optional getServiceModelElementInfo(SessionContext context, ElementContext elementContext) { Collection vspModelSubs = zusammenAdaptor @@ -240,7 +299,7 @@ public class ServiceModelDaoZusammenImpl String yamlContent = IOUtils.toString(element.getData()); return new ToscaExtensionYamlUtil(). yamlToObject(yamlContent, ServiceTemplate.class); - }catch (Exception e){ + } catch (Exception e) { throw new CoreException( new RetrieveServiceTemplateFromDbErrorBuilder( element.getInfo().getName(), e.getMessage()).build()); -- cgit 1.2.3-korg