summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main')
-rw-r--r--openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/EnrichedServiceModelDaoImpl.java3
-rw-r--r--openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/EnrichedServiceModelDaoZusammenImpl.java29
-rw-r--r--openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/ServiceModelDaoZusammenImpl.java243
3 files changed, 154 insertions, 121 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 14eda9ee4d..348a8addbd 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
@@ -23,13 +23,10 @@ package org.openecomp.sdc.model.impl;
import org.openecomp.core.model.dao.EnrichedServiceArtifactDaoFactory;
import org.openecomp.core.model.dao.EnrichedServiceModelDao;
import org.openecomp.core.model.dao.EnrichedServiceTemplateDaoFactory;
-import org.openecomp.core.model.types.ServiceArtifact;
import org.openecomp.core.model.types.ServiceElement;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.versioning.dao.types.Version;
-import java.util.List;
-
public class EnrichedServiceModelDaoImpl extends AbstractServiceModelDao
implements EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> {
public EnrichedServiceModelDaoImpl() {
diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/EnrichedServiceModelDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/EnrichedServiceModelDaoZusammenImpl.java
index d018c9a87c..3bd2881117 100644
--- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/EnrichedServiceModelDaoZusammenImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-impl/src/main/java/org/openecomp/sdc/model/impl/zusammen/EnrichedServiceModelDaoZusammenImpl.java
@@ -1,7 +1,6 @@
package org.openecomp.sdc.model.impl.zusammen;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
-import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.ElementContext;
@@ -11,10 +10,13 @@ import org.openecomp.core.model.types.ServiceElement;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.core.zusammen.api.ZusammenUtil;
+import org.openecomp.sdc.datatypes.model.ElementType;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
+
public class EnrichedServiceModelDaoZusammenImpl extends ServiceModelDaoZusammenImpl implements
EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> {
@@ -23,28 +25,31 @@ public class EnrichedServiceModelDaoZusammenImpl extends ServiceModelDaoZusammen
public EnrichedServiceModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
super(zusammenAdaptor);
- this.name = StructureElement.EnrichedServiceModel.name();
+ this.elementType = ElementType.EnrichedServiceModel;
}
@Override
public void storeExternalArtifact(ServiceArtifact serviceArtifact) {
- ZusammenElement artifactElement = buildArtifactElement(serviceArtifact.getName(),
+ ZusammenElement artifact = buildArtifactElement(serviceArtifact.getName(),
FileUtils.toByteArray(serviceArtifact.getContent()), Action.CREATE);
- ZusammenElement artifactsElement =
- buildStructuralElement(StructureElement.Artifacts.name(), null);
- artifactsElement.addSubElement(artifactElement);
+ ZusammenElement artifacts = buildStructuralElement(ElementType.Artifacts, Action.IGNORE);
+ artifacts.addSubElement(artifact);
+
+ ZusammenElement enrichedServiceModel = buildStructuralElement(elementType, Action.IGNORE);
+ enrichedServiceModel.addSubElement(artifacts);
- ZusammenElement enrichedServiceModelElement = buildStructuralElement(name, null);
- enrichedServiceModelElement.addSubElement(artifactsElement);
+ ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE);
+ vspModel.addSubElement(enrichedServiceModel);
SessionContext context = ZusammenUtil.createSessionContext();
- Id itemId = new Id(serviceArtifact.getVspId());
- ElementContext elementContext = new ElementContext(itemId, getFirstVersionId(context, itemId));
+ ElementContext elementContext =
+ new ElementContext(serviceArtifact.getVspId(), serviceArtifact.getVersion().getId());
zusammenAdaptor
- .saveElement(context, elementContext, enrichedServiceModelElement, "add service artifact.");
+ .saveElement(context, elementContext, vspModel, "add service external artifact.");
- logger.info("Finished adding artifact to service model for vsp id -> " +
+ logger.info(
+ "Finished adding artifact to enriched service model for VendorSoftwareProduct id -> {}",
elementContext.getItemId().getValue());
}
}
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 b5e3627e61..4ae9353f42 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
@@ -8,7 +8,6 @@ import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.datatypes.item.Info;
-import com.amdocs.zusammen.datatypes.item.ItemVersion;
import org.apache.commons.io.IOUtils;
import org.openecomp.core.model.dao.ServiceModelDao;
import org.openecomp.core.model.errors.RetrieveServiceTemplateFromDbErrorBuilder;
@@ -17,14 +16,14 @@ import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.core.zusammen.api.ZusammenUtil;
import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.datatypes.model.ElementType;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.core.converter.datatypes.Constants;
+import org.openecomp.types.ElementPropertyName;
import java.io.ByteArrayInputStream;
import java.util.Collection;
@@ -33,16 +32,20 @@ import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
+
public class ServiceModelDaoZusammenImpl
implements ServiceModelDao<ToscaServiceModel, ServiceElement> {
+ private static final String BASE_PROPERTY = "base";
private static final Logger logger = LoggerFactory.getLogger(ServiceModelDaoZusammenImpl.class);
protected ZusammenAdaptor zusammenAdaptor;
- protected String name;
+ protected ElementType elementType;
public ServiceModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
this.zusammenAdaptor = zusammenAdaptor;
- this.name = StructureElement.ServiceModel.name();
+ this.elementType = ElementType.ServiceModel;
}
@Override
@@ -53,98 +56,59 @@ public class ServiceModelDaoZusammenImpl
@Override
public ToscaServiceModel getServiceModel(String vspId, Version version) {
SessionContext context = ZusammenUtil.createSessionContext();
- Id itemId = new Id(vspId);
- ElementContext elementContext = new ElementContext(itemId, getFirstVersionId(context, itemId),
- version.getStatus() == VersionStatus.Locked ? null : version.toString());
-
- Optional<ElementInfo> serviceModelElement = zusammenAdaptor
- .getElementInfoByName(context, elementContext, null, name);
-
- if (serviceModelElement.isPresent()) {
- String entryDefinitionServiceTemplate =
- serviceModelElement.get().getInfo().getProperty("base");
- Id serviceModelElementId = serviceModelElement.get().getId();
- Map<String, ServiceTemplate> serviceTemplates =
- getTemplates(context, elementContext, serviceModelElementId);
- if (serviceTemplates == null) {
- return null;
- }
- FileContentHandler artifacts = getArtifacts(context, elementContext, serviceModelElementId);
-
+ ElementContext elementContext = new ElementContext(vspId, version.getId());
- return new ToscaServiceModel(
- artifacts, serviceTemplates, entryDefinitionServiceTemplate);
- } else {
+ Optional<ElementInfo> serviceModel = getServiceModelElementInfo(context, elementContext);
+ if (!serviceModel.isPresent()) {
return null;
}
- }
-
- protected Map<String, ServiceTemplate> getTemplates(SessionContext context,
- ElementContext elementContext,
- Id serviceModelElementId) {
- Optional<ElementInfo> templatesElementInfo = zusammenAdaptor.getElementInfoByName(
- context, elementContext, serviceModelElementId, StructureElement.Templates.name());
- if (templatesElementInfo.isPresent()) {
- Collection<Element> elements = zusammenAdaptor.listElementData(context, elementContext,
- templatesElementInfo.get().getId());
-
- return elements.stream().collect(Collectors.toMap(
- element -> element.getInfo().getName(),
- this::elementToServiceTemplate));
+ Id serviceModelElementId = serviceModel.get().getId();
+ Map<String, ServiceTemplate> serviceTemplates =
+ getTemplates(context, elementContext, serviceModelElementId);
+ if (serviceTemplates == null) {
+ return null;
}
- return null;
- }
-
- protected FileContentHandler getArtifacts(SessionContext context, ElementContext elementContext,
- Id serviceModelElementId) {
- Optional<ElementInfo> artifactsElement = zusammenAdaptor.getElementInfoByName(
- context, elementContext, serviceModelElementId, StructureElement.Artifacts.name());
- if (artifactsElement.isPresent()) {
-
- Collection<Element> elements = zusammenAdaptor.listElementData(context, elementContext,
- artifactsElement.get().getId());
- FileContentHandler fileContentHandler = new FileContentHandler();
- elements.forEach(element -> fileContentHandler.addFile(element.getInfo().getName(),
- element.getData()));
- return fileContentHandler;
- }
+ FileContentHandler artifacts = getArtifacts(context, elementContext, serviceModelElementId);
+ String entryDefinitionServiceTemplate =
+ serviceModel.get().getInfo().getProperty(BASE_PROPERTY);
- return null;
+ return new ToscaServiceModel(artifacts, serviceTemplates, entryDefinitionServiceTemplate);
}
@Override
public void storeServiceModel(String vspId, Version version, ToscaServiceModel serviceModel) {
- logger.info("Storing service model for vsp id -> " + vspId);
+ logger.info("Storing service model for VendorSoftwareProduct id -> {}", vspId);
- ZusammenElement templatesElement =
- buildStructuralElement(StructureElement.Templates.name(), null);
+ ZusammenElement templatesElement = buildStructuralElement(ElementType.Templates, Action.UPDATE);
serviceModel.getServiceTemplates().entrySet().forEach(entry -> templatesElement.addSubElement(
buildServiceTemplateElement(entry.getKey(), entry.getValue(),
serviceModel.getEntryDefinitionServiceTemplate(), Action.CREATE)));
- ZusammenElement artifactsElement =
- buildStructuralElement(StructureElement.Artifacts.name(), Action.UPDATE);
+ ZusammenElement artifactsElement = buildStructuralElement(ElementType.Artifacts, Action.UPDATE);
if (Objects.nonNull(serviceModel.getArtifactFiles())) {
- serviceModel.getArtifactFiles().getFiles().entrySet().forEach(entry -> artifactsElement
- .addSubElement(buildArtifactElement(entry.getKey(), entry.getValue(), Action.CREATE)));
+ serviceModel.getArtifactFiles().getFiles().entrySet()
+ .forEach(entry -> artifactsElement.addSubElement(
+ buildArtifactElement(entry.getKey(), entry.getValue(), Action.CREATE)));
}
- ZusammenElement serviceModelElement = buildStructuralElement(name, Action.UPDATE);
+ ZusammenElement serviceModelElement = buildStructuralElement(elementType, Action.UPDATE);
serviceModelElement.getInfo()
- .addProperty("base", serviceModel.getEntryDefinitionServiceTemplate());
+ .addProperty(BASE_PROPERTY, serviceModel.getEntryDefinitionServiceTemplate());
serviceModelElement.addSubElement(templatesElement);
serviceModelElement.addSubElement(artifactsElement);
+ ZusammenElement vspModel = buildStructuralElement(ElementType.VspModel, Action.IGNORE);
+ vspModel.addSubElement(serviceModelElement);
+
SessionContext context = ZusammenUtil.createSessionContext();
- Id itemId = new Id(vspId);
- ElementContext elementContext = new ElementContext(itemId, getFirstVersionId(context, itemId));
- zusammenAdaptor
- .saveElement(context, elementContext, serviceModelElement, "Store service model");
+ ElementContext elementContext = new ElementContext(vspId, version.getId());
+ zusammenAdaptor.saveElement(context, elementContext, vspModel, "Store service model");
- logger.info("Finished storing service model for vsp id -> " + vspId);
+ logger
+ .info("Finished storing {} for VendorSoftwareProduct id -> {}", elementType.name(), vspId);
}
@Override
@@ -154,65 +118,132 @@ public class ServiceModelDaoZusammenImpl
@Override
public void deleteAll(String vspId, Version version) {
- logger.info("started deleting service model for vsp id -> " + vspId);
+ logger.info("Started deleting content of Templates and Artifacts of {} of vsp {} version {}",
+ elementType.name(), vspId, version.getId());
+
SessionContext context = ZusammenUtil.createSessionContext();
- Id itemId = new Id(vspId);
- ElementContext elementContext = new ElementContext(itemId, getFirstVersionId(context, itemId));
+ ElementContext elementContext = new ElementContext(vspId, version.getId());
+
+ Optional<ElementInfo> serviceModel = getServiceModelElementInfo(context, elementContext);
+ if (!serviceModel.isPresent()) {
+ logger.info("{} of vsp {} version {} does not exist - nothing to delete", elementType.name(),
+ vspId, version.getId());
+ return;
+ }
+
+ ZusammenElement serviceModelElement = buildElement(serviceModel.get().getId(), Action.IGNORE);
+ for (Id serviceModelSubElementId :
+ serviceModel.get().getSubElements().stream()
+ .map(ElementInfo::getId)
+ .collect(Collectors.toSet())) {
+ ElementInfo serviceModelSubElementInfo =
+ zusammenAdaptor.getElementInfo(context, elementContext, serviceModelSubElementId)
+ .orElseThrow(() -> new IllegalStateException(String.format(
+ "Element %s declared as sub element of element %s (%s) does not exist",
+ serviceModelSubElementId.getValue(),
+ serviceModel.get().getId().getValue(),
+ elementType.name())));
+
+ if (ElementType.Templates.name().equals(serviceModelSubElementInfo.getInfo().getName())
+ || ElementType.Artifacts.name().equals(serviceModelSubElementInfo.getInfo().getName())) {
+ ZusammenElement serviceModelSubElement =
+ buildElement(serviceModelSubElementId, Action.IGNORE);
+ serviceModelSubElement.setSubElements(serviceModelSubElementInfo.getSubElements().stream()
+ .map(elementInfo -> buildElement(elementInfo.getId(), Action.DELETE))
+ .collect(Collectors.toSet()));
+ serviceModelElement.addSubElement(serviceModelSubElement);
+ }
+ }
- ZusammenElement zusammenElement = ZusammenUtil.buildStructuralElement(name, Action.DELETE);
- zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "delete:" + name + ".");
- logger.info("Finished deleting service model for vsp id -> " + vspId);
+ zusammenAdaptor.saveElement(context, elementContext, serviceModelElement,
+ String.format("Delete content of Templates and Artifacts of %s", elementType.name()));
+
+ logger.info("Finished deleting content of Templates and Artifacts of {} of vsp {} version {}",
+ elementType.name(), vspId, version.getId());
}
- protected ZusammenElement buildArtifactElement(String name, byte[] artifact, Action action) {
- ZusammenElement artifactElement = new ZusammenElement();
- artifactElement.setAction(action);
- Info info = new Info();
- info.setName(name);
- info.addProperty("type", ElementType.Artifact.name());
- artifactElement.setInfo(info);
- artifactElement.setData(new ByteArrayInputStream(artifact));
+ private Optional<ElementInfo> getServiceModelElementInfo(SessionContext context,
+ ElementContext elementContext) {
+ Collection<ElementInfo> vspModelSubs = zusammenAdaptor
+ .listElementsByName(context, elementContext, null, ElementType.VspModel.name());
- return artifactElement;
+ return vspModelSubs.stream()
+ .filter(elementInfo -> elementInfo.getInfo() != null
+ && elementType.name().equals(elementInfo.getInfo().getName()))
+ .findFirst();
}
- private ServiceTemplate elementToServiceTemplate(Element element){
+ private Map<String, ServiceTemplate> getTemplates(SessionContext context,
+ ElementContext elementContext,
+ Id serviceModelElementId) {
+ Optional<ElementInfo> templatesElementInfo = zusammenAdaptor.getElementInfoByName(
+ context, elementContext, serviceModelElementId, ElementType.Templates.name());
- try {
- String yamlContent = IOUtils.toString(element.getData());
- return new ToscaExtensionYamlUtil().
- yamlToObject(yamlContent, ServiceTemplate.class);
- }catch (Exception e){
- throw new CoreException(
- new RetrieveServiceTemplateFromDbErrorBuilder(
- element.getInfo().getName(), e.getMessage()).build());
+ if (templatesElementInfo.isPresent()) {
+ Collection<Element> elements = zusammenAdaptor.listElementData(context, elementContext,
+ templatesElementInfo.get().getId());
+
+ return elements.stream().collect(Collectors.toMap(
+ element -> element.getInfo().getName(),
+ this::elementToServiceTemplate));
}
+ return null;
+ }
+
+ private FileContentHandler getArtifacts(SessionContext context, ElementContext elementContext,
+ Id serviceModelElementId) {
+ Optional<ElementInfo> artifactsElement = zusammenAdaptor.getElementInfoByName(
+ context, elementContext, serviceModelElementId, ElementType.Artifacts.name());
+
+ if (artifactsElement.isPresent()) {
+
+ Collection<Element> elements = zusammenAdaptor.listElementData(context, elementContext,
+ artifactsElement.get().getId());
+ FileContentHandler fileContentHandler = new FileContentHandler();
+ elements.forEach(element -> fileContentHandler.addFile(element.getInfo().getName(),
+ element.getData()));
+ return fileContentHandler;
+ }
+
+ return null;
}
private Element buildServiceTemplateElement(String name, ServiceTemplate serviceTemplate,
String entryDefinitionServiceTemplate,
Action action) {
- ZusammenElement zusammenElement = new ZusammenElement();
- zusammenElement.setAction(action);
+ ZusammenElement zusammenElement = buildElement(null, action);
Info info = new Info();
info.setName(name);
info.setDescription(serviceTemplate.getDescription());
- info.addProperty("type", ElementType.Servicetemplate.name());
- info.addProperty("base", entryDefinitionServiceTemplate);
+ info.addProperty(ElementPropertyName.elementType.name(), ElementType.ServiceTemplate.name());
+ info.addProperty(BASE_PROPERTY, entryDefinitionServiceTemplate);
String yaml = new ToscaExtensionYamlUtil().objectToYaml(serviceTemplate);
zusammenElement.setData(new ByteArrayInputStream(yaml.getBytes()));
zusammenElement.setInfo(info);
return zusammenElement;
}
- protected Id getFirstVersionId(SessionContext context, Id vspId) {
- Optional<ItemVersion> itemVersionOptional = zusammenAdaptor.getFirstVersion(context, vspId);
- ItemVersion itemVersion = itemVersionOptional.orElseThrow(() ->
- new RuntimeException(String.format("Vsp %s does not contain any version.", vspId))); //todo
- return itemVersion.getId();
+ protected ZusammenElement buildArtifactElement(String name, byte[] artifact, Action action) {
+ ZusammenElement artifactElement = buildElement(null, action);
+ Info info = new Info();
+ info.setName(name);
+ info.addProperty(ElementPropertyName.elementType.name(), ElementType.Artifact.name());
+ artifactElement.setInfo(info);
+ artifactElement.setData(new ByteArrayInputStream(artifact));
+
+ return artifactElement;
}
- protected ZusammenElement buildStructuralElement(String structureElement, Action action) {
- return ZusammenUtil.buildStructuralElement(structureElement, action);
+
+ private ServiceTemplate elementToServiceTemplate(Element element) {
+ try {
+ String yamlContent = IOUtils.toString(element.getData());
+ return new ToscaExtensionYamlUtil().
+ yamlToObject(yamlContent, ServiceTemplate.class);
+ }catch (Exception e){
+ throw new CoreException(
+ new RetrieveServiceTemplateFromDbErrorBuilder(
+ element.getInfo().getName(), e.getMessage()).build());
+ }
}
}