summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2018-01-29 11:23:39 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-02-15 14:23:32 +0000
commit924ba9adf027dd4969896cd905a8a41ba4c30655 (patch)
tree035e2ba4ef7100bca4f097d6ca10dbf40cf11aa9 /openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src
parentb4c4dbc6bbcd9995387c0716ee57f620c7a701df (diff)
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 <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src')
-rw-r--r--openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoImpl.java7
-rw-r--r--openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/ServiceModelDaoImpl.java6
-rw-r--r--openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java61
3 files changed, 73 insertions, 1 deletions
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<ElementInfo> 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> elementInfo = zusammenAdaptor.getElementInfoByName(
+ context, elementContext, serviceModelElementId, ElementType.ServiceTemplate.name());
+ if (!elementInfo.isPresent()) {
+ return;
+ }
+ ZusammenElement zusammenElement =
+ buildStructuralElement(ElementType.ServiceTemplate, Action.UPDATE);
+ Collection<Element> 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> serviceTemplate = serviceModel.getServiceTemplate(templateName);
+ serviceTemplate.ifPresent(serviceTemplateFile -> {
+ String yaml = new ToscaExtensionYamlUtil().objectToYaml(serviceTemplateFile);
+ serviceTemplateElement.setData(new ByteArrayInputStream(yaml.getBytes()));
+ });
+ return serviceTemplateElement;
+ }
+
private Optional<ElementInfo> getServiceModelElementInfo(SessionContext context,
ElementContext elementContext) {
Collection<ElementInfo> 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());