diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core')
3 files changed, 121 insertions, 48 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml index 0c1fc94a97..e1fb942102 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml @@ -1,7 +1,12 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> + <name>openecomp-sdc-model-core</name> + <artifactId>openecomp-sdc-model-core</artifactId> + + <parent> <groupId>org.openecomp.sdc</groupId> <artifactId>openecomp-sdc-lib</artifactId> @@ -9,26 +14,14 @@ <relativePath>../..</relativePath> </parent> - <name>openecomp-sdc-model-core</name> - <artifactId>openecomp-sdc-model-core</artifactId> - <dependencies> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.7.10</version> - - </dependency> - <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> - <version>1.1.2</version> - + <version>${logback.version}</version> </dependency> - - <dependency> - <groupId>org.openecomp.sdc</groupId> + <groupId>org.openecomp.core</groupId> <artifactId>openecomp-utilities-lib</artifactId> <version>${project.version}</version> </dependency> @@ -42,7 +35,6 @@ <artifactId>openecomp-sdc-versioning-core</artifactId> <version>${project.version}</version> </dependency> - <dependency> <groupId>org.openecomp.sdc</groupId> <artifactId>openecomp-sdc-datatypes-lib</artifactId> @@ -52,14 +44,7 @@ <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <scope>test</scope> - <version>1.10.19</version> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <version>19.0</version> + <version>${mockito.all.version}</version> </dependency> - - </dependencies> -</project>
\ No newline at end of file +</project> diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml.versionsBackup new file mode 100644 index 0000000000..d62437122a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/pom.xml.versionsBackup @@ -0,0 +1,56 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <name>openecomp-sdc-model-core</name> + <artifactId>openecomp-sdc-model-core</artifactId> + + + <parent> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-lib</artifactId> + <version>1.0-SNAPSHOT</version> + <relativePath>../..</relativePath> + </parent> + + <dependencies> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>${logback.version}</version> + + </dependency> + + + <dependency> + <groupId>org.openecomp.core</groupId> + <artifactId>openecomp-utilities-lib</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-model-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-versioning-core</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-datatypes-lib</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <scope>test</scope> + <version>1.10.19</version> + </dependency> + + + </dependencies> +</project>
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/src/main/java/org/openecomp/sdc/model/impl/AbstractServiceModelDao.java b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/src/main/java/org/openecomp/sdc/model/impl/AbstractServiceModelDao.java index eb993f6fb1..6863e04991 100644 --- a/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/src/main/java/org/openecomp/sdc/model/impl/AbstractServiceModelDao.java +++ b/openecomp-be/lib/openecomp-sdc-model-lib/openecomp-sdc-model-core/src/main/java/org/openecomp/sdc/model/impl/AbstractServiceModelDao.java @@ -28,12 +28,17 @@ import org.openecomp.core.model.types.ServiceTemplate; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.Import; +import org.openecomp.sdc.tosca.datatypes.model.Old1610ServiceTemplate; import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; import org.openecomp.sdc.versioning.dao.VersionableDao; import org.openecomp.sdc.versioning.dao.types.Version; +import sun.misc.IOUtils; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -49,7 +54,6 @@ public class AbstractServiceModelDao implements VersionableDao { artifactDao.registerVersioning(versionableEntityType); } - /** * Gets service model. * @@ -59,22 +63,20 @@ public class AbstractServiceModelDao implements VersionableDao { */ public ToscaServiceModel getServiceModel(String vspId, Version version) { if (vspId == null || version == null) { - //throw new CoreException() throw new RuntimeException("missing service model key"); } - FileContentHandler artifactFiles = getArtifacts(vspId, version); + Map<String, org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate> serviceTemplates = - getTemplates(vspId, version); + getTemplates(vspId, + version); String entryDefinitionServiceTemplate = getServiceBase(vspId, version); return new ToscaServiceModel(artifactFiles, serviceTemplates, entryDefinitionServiceTemplate); } - public void storeExternalArtifact(ServiceArtifact serviceArtifact) { artifactDao.create(serviceArtifact); - //TODO: update last modification time } @@ -103,8 +105,7 @@ public class AbstractServiceModelDao implements VersionableDao { ServiceTemplate entityTmp; String yaml; for (Map.Entry<String, org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate> - entryTemplate : toscaServiceModel - .getServiceTemplates().entrySet()) { + entryTemplate : toscaServiceModel.getServiceTemplates().entrySet()) { entityTmp = new ServiceTemplate(); yaml = new ToscaExtensionYamlUtil().objectToYaml(entryTemplate.getValue()); @@ -116,8 +117,6 @@ public class AbstractServiceModelDao implements VersionableDao { templateDao.create(entityTmp); } - - //TODO: update last modification time } @@ -142,25 +141,18 @@ public class AbstractServiceModelDao implements VersionableDao { return null; } - - /** - * Gets service model content names. - * - * @return the service model content names - */ public List<String> getServiceModelContentNames() { - return null; } - private String getServiceBase(String vspId, Version version) { return templateDao.getBase(vspId, version); } private Map<String, org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate> getTemplates( - String vspId, Version version) { + String vspId, + Version version) { Collection<ServiceTemplate> templates = templateDao.list(vspId, version); if (templates == null) { @@ -172,8 +164,47 @@ public class AbstractServiceModelDao implements VersionableDao { private org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate getServiceTemplate( InputStream content) { - return new ToscaExtensionYamlUtil() - .yamlToObject(content, org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate.class); + String serviceTemplateContent = new String(FileUtils.toByteArray(content)); + + try{ + return new ToscaExtensionYamlUtil().yamlToObject(serviceTemplateContent, + org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate.class); + }catch (Exception e){ + System.out.println("Found vsp with old-versioned tosca service template"); + Old1610ServiceTemplate old1610ServiceTemplate = + new ToscaExtensionYamlUtil().yamlToObject(serviceTemplateContent, + Old1610ServiceTemplate.class); + + return mapOldSTToCurrentST(old1610ServiceTemplate); + } + } + + private static org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate mapOldSTToCurrentST(Old1610ServiceTemplate oldServiceTemplate){ + org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate + serviceTemplate = new org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate(); + + serviceTemplate.setArtifact_types(oldServiceTemplate.getArtifact_types()); + serviceTemplate.setCapability_types(oldServiceTemplate.getCapability_types()); + serviceTemplate.setData_types(oldServiceTemplate.getData_types()); + serviceTemplate.setDescription(oldServiceTemplate.getDescription()); + serviceTemplate.setGroup_types(oldServiceTemplate.getGroup_types()); + serviceTemplate.setInterface_types(oldServiceTemplate.getInterface_types()); + serviceTemplate.setMetadata(oldServiceTemplate.getMetadata()); + serviceTemplate.setNode_types(oldServiceTemplate.getNode_types()); + serviceTemplate.setPolicy_types(oldServiceTemplate.getPolicy_types()); + serviceTemplate.setRelationship_types(oldServiceTemplate.getRelationship_types()); + serviceTemplate.setTopology_template(oldServiceTemplate.getTopology_template()); + + List<Map<String, Import>> imports = new ArrayList<>(); + for(Map.Entry<String, Import> importEntry : oldServiceTemplate.getImports().entrySet()){ + Map<String, Import> importMap = new HashMap<>(); + importMap.put(importEntry.getKey(), importEntry.getValue()); + imports.add(importMap); + } + serviceTemplate.setImports(imports); + + return serviceTemplate; + } private FileContentHandler getArtifacts(String vspId, Version version) { @@ -183,8 +214,9 @@ public class AbstractServiceModelDao implements VersionableDao { } FileContentHandler fileContentHandler = new FileContentHandler(); - templates.stream().forEach(serviceArtifact -> fileContentHandler - .addFile(serviceArtifact.getName(), serviceArtifact.getContent())); + templates.stream().forEach( + serviceArtifact -> fileContentHandler + .addFile(serviceArtifact.getName(), serviceArtifact.getContent())); return fileContentHandler; } |