aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/tosca
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 10:28:42 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 10:51:01 +0200
commit451a3400b76511393c62a444f588a4ed15f4a549 (patch)
treee4f5873a863d1d3e55618eab48b83262f874719d /catalog-be/src/main/java/org/openecomp/sdc/be/tosca
parent5abfe4e1fb5fae4bbd5fbc340519f52075aff3ff (diff)
Initial OpenECOMP SDC commit
Change-Id: I0924d5a6ae9cdc161ae17c68d3689a30d10f407b Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/tosca')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ArtifactTypes.java37
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CSARTool.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java261
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java649
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java189
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaError.java26
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java629
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java69
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/EntrySchema.java43
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/IToscaMetadata.java33
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java60
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaCapability.java80
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaGroupTemplate.java69
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java137
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java73
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java87
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java83
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaRequirement.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java90
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateCapability.java46
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirement.java68
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTopolgyTemplate.java63
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/VfModuleToscaMetadata.java66
24 files changed, 2997 insertions, 0 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ArtifactTypes.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ArtifactTypes.java
new file mode 100644
index 0000000000..85b4493c8e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ArtifactTypes.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.util.List;
+
+import org.openecomp.sdc.generator.data.ArtifactType;
+
+public class ArtifactTypes {
+ private List<ArtifactType> artifactTypes;
+
+ public List<ArtifactType> getArtifactTypes() {
+ return artifactTypes;
+ }
+
+ public void setArtifactTypes(List<ArtifactType> artifactTypes) {
+ this.artifactTypes = artifactTypes;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CSARTool.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CSARTool.java
new file mode 100644
index 0000000000..7fecced358
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CSARTool.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import org.openecomp.sdc.be.model.Component;
+
+public class CSARTool {
+ public static byte[] createCsar(Component component) {
+
+ final String TOSCA_META_VERSION = "1.0";
+ final String CSAR_VERSION = component.getCsarVersion();
+ final String CREATED_BY = component.getCreatorFullName();
+ final String ENTRY_DEFINITIONS = component.getNormalizedName();
+
+ /*
+ * StringBuilder builder = new StringBuilder(); try( FileOutputStream f = new FileOutputStream("test.zip"); ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(f)); ){ }
+ */
+
+ return null;
+ }
+
+ public static String createToscaBlock0(String metaFileVersion, String csarVersion, String createdBy, String entryDef) {
+ final String BLOCK_0_TEMPLATE = "TOSCA-Meta-File-Version: %s";
+
+ return null;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java
new file mode 100644
index 0000000000..d1f2557413
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java
@@ -0,0 +1,261 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.resources.data.CapabilityData;
+import org.openecomp.sdc.be.resources.data.RequirementData;
+import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
+import org.openecomp.sdc.be.tosca.model.ToscaCapability;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
+import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.openecomp.sdc.be.tosca.model.ToscaRequirement;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplateCapability;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fj.data.Either;
+
+public class CapabiltyRequirementConvertor {
+ private static CapabiltyRequirementConvertor instance;
+
+ protected CapabiltyRequirementConvertor() {
+
+ }
+
+ public static synchronized CapabiltyRequirementConvertor getInstance() {
+ if (instance == null) {
+ instance = new CapabiltyRequirementConvertor();
+ }
+ return instance;
+ }
+
+ private static Logger log = LoggerFactory.getLogger(CapabiltyRequirementConvertor.class.getName());
+
+ public Either<ToscaNodeTemplate, ToscaError> convertComponentInstanceCapabilties(ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, ToscaNodeTemplate nodeTemplate) {
+
+ Map<String, List<CapabilityDefinition>> capabilitiesInst = componentInstance.getCapabilities();
+ if (capabilitiesInst != null && !capabilitiesInst.isEmpty()) {
+ Map<String, ToscaTemplateCapability> capabilties = new HashMap<>();
+ capabilitiesInst.entrySet().forEach(e -> {
+ List<CapabilityDefinition> capList = e.getValue();
+ if (capList != null && !capList.isEmpty()) {
+ capList.forEach(c -> {
+ convertOverridenProperties(componentInstance, dataTypes, capabilties, c);
+ });
+ }
+ });
+ if (capabilties != null && !capabilties.isEmpty()) {
+ nodeTemplate.setCapabilities(capabilties);
+ }
+ }
+ return Either.left(nodeTemplate);
+ }
+
+ private void convertOverridenProperties(ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, Map<String, ToscaTemplateCapability> capabilties, CapabilityDefinition c) {
+ List<ComponentInstanceProperty> properties = c.getProperties();
+ if (properties != null && !properties.isEmpty()) {
+ properties.stream().filter(p -> (p.getValueUniqueUid() != null)).forEach(p -> {
+ convertOverridenProperty(componentInstance, dataTypes, capabilties, c, p);
+ });
+ }
+ }
+
+ private void convertOverridenProperty(ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, Map<String, ToscaTemplateCapability> capabilties, CapabilityDefinition c, ComponentInstanceProperty p) {
+ if (log.isDebugEnabled()) {
+ log.debug("Exist overriden property {} for capabity {} with value {}", p.getName(), c.getName(), p.getValue());
+ }
+ ToscaTemplateCapability toscaTemplateCapability = capabilties.get(c.getName());
+ if (toscaTemplateCapability == null) {
+ toscaTemplateCapability = new ToscaTemplateCapability();
+ capabilties.put(c.getName(), toscaTemplateCapability);
+ }
+ Map<String, Object> toscaCapProp = toscaTemplateCapability.getProperties();
+ if (toscaCapProp == null) {
+ toscaCapProp = new HashMap<>();
+ }
+ Object convertedValue = convertInstanceProperty(dataTypes, componentInstance, p);
+ toscaCapProp.put(p.getName(), convertedValue);
+ toscaTemplateCapability.setProperties(toscaCapProp);
+ }
+
+ private Object convertInstanceProperty(Map<String, DataTypeDefinition> dataTypes, ComponentInstance componentInstance, ComponentInstanceProperty prop) {
+ log.debug("Convert property {} for instance {}", prop.getName(), componentInstance.getUniqueId());
+ String propertyType = prop.getType();
+ String innerType = null;
+ if (prop.getSchema() != null && prop.getSchema().getProperty() != null) {
+ innerType = prop.getSchema().getProperty().getType();
+ }
+ Object convertedValue = PropertyConvertor.getInstance().convertToToscaObject(propertyType, prop.getValue(), innerType, dataTypes);
+ return convertedValue;
+ }
+
+ public Either<ToscaNodeType, ToscaError> convertRequirements(Component component, ToscaNodeType nodeType) {
+ List<Map<String, ToscaRequirement>> toscaRequirements = convertRequirementsAsList(component);
+ if (!toscaRequirements.isEmpty()) {
+ nodeType.setRequirements(toscaRequirements);
+ }
+ log.debug("Finish convert Requirements for node type");
+
+ return Either.left(nodeType);
+ }
+
+ public Either<SubstitutionMapping, ToscaError> convertRequirements(Component component, SubstitutionMapping substitutionMapping) {
+ Map<String, ToscaRequirement> toscaRequirements = convertRequirementsAsMap(component);
+ if (!toscaRequirements.isEmpty()) {
+ substitutionMapping.setRequirements(toscaRequirements);
+ }
+ log.debug("Finish convert Requirements for node type");
+
+ return Either.left(substitutionMapping);
+ }
+
+ private List<Map<String, ToscaRequirement>> convertRequirementsAsList(Component component) {
+ Map<String, List<RequirementDefinition>> requirements = component.getRequirements();
+ List<Map<String, ToscaRequirement>> toscaRequirements = new ArrayList<>();
+ if (requirements != null) {
+ boolean isNodeType = ToscaUtils.isNodeType(component);
+ for (Map.Entry<String, List<RequirementDefinition>> entry : requirements.entrySet()) {
+ entry.getValue().stream().filter(r -> (!isNodeType || (isNodeType && component.getUniqueId().equals(r.getOwnerId())))).forEach(r -> {
+ ImmutablePair<String, ToscaRequirement> pair = convertRequirement(component, isNodeType, r);
+ Map<String, ToscaRequirement> requirement = new HashMap<>();
+
+ requirement.put(pair.left, pair.right);
+ toscaRequirements.add(requirement);
+ });
+
+ log.debug("Finish convert Requirements for node type");
+ }
+ } else {
+ log.debug("No Requirements for node type");
+ }
+ return toscaRequirements;
+ }
+
+ private Map<String, ToscaRequirement> convertRequirementsAsMap(Component component) {
+ Map<String, List<RequirementDefinition>> requirements = component.getRequirements();
+ Map<String, ToscaRequirement> toscaRequirements = new HashMap<>();
+ if (requirements != null) {
+ boolean isNodeType = ToscaUtils.isNodeType(component);
+ for (Map.Entry<String, List<RequirementDefinition>> entry : requirements.entrySet()) {
+ entry.getValue().stream().filter(r -> (!isNodeType || (isNodeType && component.getUniqueId().equals(r.getOwnerId())))).forEach(r -> {
+ ImmutablePair<String, ToscaRequirement> pair = convertRequirement(component, isNodeType, r);
+ toscaRequirements.put(pair.left, pair.right);
+ });
+
+ log.debug("Finish convert Requirements for node type");
+ }
+ } else {
+ log.debug("No Requirements for node type");
+ }
+ return toscaRequirements;
+ }
+
+ private ImmutablePair<String, ToscaRequirement> convertRequirement(Component component, boolean isNodeType, RequirementDefinition r) {
+ String name = r.getName();
+ if (!isNodeType) {
+ name = r.getOwnerName() + "." + name;
+ }
+ log.debug("the requirement {} belongs to resource {} ", name, component.getUniqueId());
+ ToscaRequirement toscaRequirement = new ToscaRequirement();
+
+ List<Object> occurences = new ArrayList<>();
+ occurences.add(Integer.valueOf(r.getMinOccurrences()));
+ if (r.getMaxOccurrences().equals(RequirementData.MAX_OCCURRENCES)) {
+ occurences.add(r.getMaxOccurrences());
+ } else {
+ occurences.add(Integer.valueOf(r.getMaxOccurrences()));
+ }
+ toscaRequirement.setOccurrences(occurences);
+ // toscaRequirement.setOccurrences(createOcurrencesRange(requirementDefinition.getMinOccurrences(),
+ // requirementDefinition.getMaxOccurrences()));
+ toscaRequirement.setNode(r.getNode());
+ toscaRequirement.setCapability(r.getCapability());
+ toscaRequirement.setRelationship(r.getRelationship());
+
+ ImmutablePair<String, ToscaRequirement> pair = new ImmutablePair<String, ToscaRequirement>(name, toscaRequirement);
+ return pair;
+ }
+
+ public Map<String, ToscaCapability> convertCapabilities(Component component, Map<String, DataTypeDefinition> dataTypes) {
+ Map<String, List<CapabilityDefinition>> capabilities = component.getCapabilities();
+ Map<String, ToscaCapability> toscaCapabilities = new HashMap<>();
+ if (capabilities != null) {
+ boolean isNodeType = ToscaUtils.isNodeType(component);
+ for (Map.Entry<String, List<CapabilityDefinition>> entry : capabilities.entrySet()) {
+ entry.getValue().stream().filter(c -> (!isNodeType || (isNodeType && component.getUniqueId().equals(c.getOwnerId())))).forEach(c -> {
+ convertCapabilty(component, toscaCapabilities, isNodeType, c, dataTypes);
+
+ });
+ }
+ } else {
+ log.debug("No Capabilities for node type");
+ }
+
+ return toscaCapabilities;
+ }
+
+ private void convertCapabilty(Component component, Map<String, ToscaCapability> toscaCapabilities, boolean isNodeType, CapabilityDefinition c, Map<String, DataTypeDefinition> dataTypes) {
+ String name = c.getName();
+ if (!isNodeType) {
+ name = c.getOwnerName() + "." + name;
+ }
+ log.debug("the capabilty {} belongs to resource {} ", name, component.getUniqueId());
+ ToscaCapability toscaCapability = new ToscaCapability();
+ toscaCapability.setDescription(c.getDescription());
+ toscaCapability.setType(c.getType());
+
+ List<Object> occurences = new ArrayList<>();
+ occurences.add(Integer.valueOf(c.getMinOccurrences()));
+ if (c.getMaxOccurrences().equals(CapabilityData.MAX_OCCURRENCES)) {
+ occurences.add(c.getMaxOccurrences());
+ } else {
+ occurences.add(Integer.valueOf(c.getMaxOccurrences()));
+ }
+ toscaCapability.setOccurrences(occurences);
+
+ toscaCapability.setValid_source_types(c.getValidSourceTypes());
+ List<ComponentInstanceProperty> properties = c.getProperties();
+ if (properties != null && !properties.isEmpty()) {
+ Map<String, ToscaProperty> toscaProperties = new HashMap<>();
+ for (PropertyDefinition property : properties) {
+ ToscaProperty toscaProperty = PropertyConvertor.getInstance().convertProperty(dataTypes, property, true);
+ toscaProperties.put(property.getName(), toscaProperty);
+ }
+ toscaCapability.setProperties(toscaProperties);
+ }
+ toscaCapabilities.put(name, toscaCapability);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
new file mode 100644
index 0000000000..c8aa188e30
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -0,0 +1,649 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.io.IOException;
+import org.apache.commons.codec.binary.Base64;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Triple;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperation;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.be.model.operations.impl.ServiceOperation;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
+import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import org.openecomp.sdc.generator.data.Artifact;
+import org.openecomp.sdc.generator.data.ArtifactType;
+import org.openecomp.sdc.generator.data.GenerationData;
+import org.openecomp.sdc.generator.impl.ArtifactGenerationServiceImpl;
+import com.google.gson.Gson;
+
+import fj.data.Either;
+
+/**
+ * @author tg851x
+ *
+ */
+@org.springframework.stereotype.Component("csar-utils")
+public class CsarUtils {
+ private static Logger log = LoggerFactory.getLogger(ToscaExportHandler.class.getName());
+
+ @Autowired
+ private ArtifactCassandraDao artifactCassandraDao;
+ @Autowired
+ private ComponentsUtils componentsUtils;
+ @Autowired
+ private ToscaExportHandler toscaExportUtils;
+ @Autowired
+ private ArtifactsBusinessLogic artifactsBusinessLogic;
+ @Autowired
+ protected ServiceOperation serviceOperation;
+
+ @javax.annotation.Resource
+ private ServiceBusinessLogic serviceBusinessLogic;
+
+ private Gson gson = new Gson();
+
+ private static final String DEFINITIONS_PATH = "Definitions/";
+ private static final String ARTIFACTS_PATH = "Artifacts/";
+ private static final String TOSCA_META_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta";
+ private static final String TOSCA_META_VERSION = "1.0";
+ private static final String CSAR_VERSION = "1.1";
+
+ /**
+ *
+ * @param component
+ * @param getFromCS
+ * @param isInCertificationRequest
+ * @param shouldLock
+ * @param inTransaction
+ * @return
+ */
+ public Either<byte[], ResponseFormat> createCsar(Component component, boolean getFromCS, boolean isInCertificationRequest, boolean shouldLock, boolean inTransaction) {
+ return createCsar(component, getFromCS, isInCertificationRequest, false, shouldLock, inTransaction);
+ }
+
+ private Either<byte[], ResponseFormat> createCsar(Component component, boolean getFromCS, boolean isInCertificationRequest, boolean mockGenerator, boolean shouldLock, boolean inTransaction) {
+ final String CREATED_BY = component.getCreatorFullName();
+
+ String fileName;
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
+ fileName = artifactDefinition.getArtifactName();
+
+ String toscaBlock0 = createToscaBlock0(TOSCA_META_VERSION, CSAR_VERSION, CREATED_BY, fileName);
+
+ byte[] toscaBlock0Byte = toscaBlock0.getBytes();
+
+ Either<byte[], ResponseFormat> generateCsarZipResponse = generateCsarZip(toscaBlock0Byte, component, getFromCS, isInCertificationRequest, mockGenerator, shouldLock, inTransaction);
+
+ if (generateCsarZipResponse.isRight()) {
+ return Either.right(generateCsarZipResponse.right().value());
+ }
+
+ return Either.left(generateCsarZipResponse.left().value());
+ }
+
+ private Either<byte[], ResponseFormat> generateCsarZip(byte[] toscaBlock0Byte, Component component, boolean getFromCS, boolean isInCertificationRequest, boolean mockGenerator, boolean shouldLock, boolean inTransaction) {
+
+ ZipOutputStream zip = null;
+ ByteArrayOutputStream out = null;
+ try {
+ out = new ByteArrayOutputStream();
+ zip = new ZipOutputStream(out);
+
+ zip.putNextEntry(new ZipEntry(TOSCA_META_PATH_FILE_NAME));
+ zip.write(toscaBlock0Byte);
+ Either<ZipOutputStream, ResponseFormat> populateZip = populateZip(component, getFromCS, zip, isInCertificationRequest, mockGenerator, shouldLock, inTransaction);
+ if (populateZip.isRight()) {
+ log.debug("Failed to populate CSAR zip file {}", populateZip.right().value());
+ return Either.right(populateZip.right().value());
+ }
+ zip = populateZip.left().value();
+
+ zip.finish();
+ byte[] byteArray = out.toByteArray();
+
+ return Either.left(byteArray);
+ } catch (IOException e) {
+ log.debug("createCsar failed IOexception", e);
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return Either.right(responseFormat);
+ } finally {
+ try {
+ if (zip != null) {
+ zip.close();
+ }
+ if (out != null) {
+ out.close();
+ }
+ } catch (Exception e) {
+ log.error("Failed to close resources ", e);
+ }
+ }
+ }
+
+ private Either<ZipOutputStream, ResponseFormat> populateZip(Component component, boolean getFromCS, ZipOutputStream zip, boolean isInCertificationRequest, boolean mockGenerator, boolean shouldLock, boolean inTransaction) {
+
+ LifecycleStateEnum lifecycleState = component.getLifecycleState();
+ String componentYaml = null;
+ Either<ToscaRepresentation, ToscaError> exportComponent = null;
+ byte[] mainYaml = null;
+ // <file name, esid, component>
+ List<Triple<String, String, Component>> dependencies = null;
+ List<ImmutablePair<Component, byte[]>> generatorInputs = new LinkedList<>();
+
+ String fileName;
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
+ fileName = artifactDefinition.getArtifactName();
+
+ if (getFromCS || !(lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN || lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
+ String esId = artifactDefinition.getEsId();
+ Either<byte[], ActionStatus> fromCassandra = getFromCassandra(esId);
+ if (fromCassandra.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(fromCassandra.right().value());
+ return Either.right(responseFormat);
+ }
+ mainYaml = fromCassandra.left().value();
+
+ } else {
+ exportComponent = toscaExportUtils.exportComponent(component);
+ if (exportComponent.isRight()) {
+ log.debug("exportComponent failed", exportComponent.right().value());
+ ActionStatus convertedFromToscaError = componentsUtils.convertFromToscaError(exportComponent.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(convertedFromToscaError);
+ return Either.right(responseFormat);
+ }
+ ToscaRepresentation exportResult = exportComponent.left().value();
+ componentYaml = exportResult.getMainYaml();
+ mainYaml = componentYaml.getBytes();
+ dependencies = exportResult.getDependencies();
+ }
+
+ try {
+ zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + fileName));
+ zip.write(mainYaml);
+
+ generatorInputs.add(new ImmutablePair<Component, byte[]>(component, mainYaml));
+
+ if (dependencies == null) {
+ Either<ToscaTemplate, ToscaError> dependenciesRes = toscaExportUtils.getDependencies(component);
+ if (dependenciesRes.isRight()) {
+ log.debug("Failed to retrieve dependencies for component {}, error {}", component.getUniqueId(), dependenciesRes.right().value());
+ ActionStatus convertFromToscaError = componentsUtils.convertFromToscaError(dependenciesRes.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(convertFromToscaError);
+ return Either.right(responseFormat);
+ }
+ dependencies = dependenciesRes.left().value().getDependencies();
+ }
+ if (dependencies != null && !dependencies.isEmpty()) {
+ for (Triple<String, String, Component> d : dependencies) {
+ String esId = d.getMiddle();
+ Component childComponent = d.getRight();
+ fileName = d.getLeft();
+ Either<byte[], ActionStatus> entryData = getEntryData(esId, childComponent);
+
+ if (entryData.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(entryData.right().value());
+ return Either.right(responseFormat);
+ }
+
+ byte[] content = entryData.left().value();
+ zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + fileName));
+ zip.write(content);
+
+ generatorInputs.add(new ImmutablePair<Component, byte[]>(childComponent, content));
+ }
+ }
+
+ List<ArtifactDefinition> aiiArtifactList = new LinkedList<>();
+ // Artifact Generation
+ if (component.getComponentType() == ComponentTypeEnum.SERVICE && (lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN || lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
+ Either<List<ArtifactDefinition>, ResponseFormat> handleAAIArtifacts = handleAAIArtifacts(component, zip, mockGenerator, shouldLock, inTransaction, generatorInputs);
+
+ if (handleAAIArtifacts.isLeft()) {
+ aiiArtifactList = handleAAIArtifacts.left().value();
+ } else {
+ log.debug("AAI Artifacts handling failed");
+ return Either.right(handleAAIArtifacts.right().value());
+ }
+
+ if (isInCertificationRequest) {
+ Either<ActionStatus, ResponseFormat> handleAllAAIArtifactsInDataModel = handleAllAAIArtifactsInDataModel(component, aiiArtifactList, shouldLock, inTransaction);
+
+ if (handleAllAAIArtifactsInDataModel.isRight()) {
+ log.debug("AAI Artifacts handling (create, update, delete) failed");
+ return Either.right(handleAllAAIArtifactsInDataModel.right().value());
+ }
+ }
+
+ }
+
+ // Collecting All Deployment Artifacts
+ Either<ZipOutputStream, ActionStatus> collectAndWriteToScarDeploymentArtifacts = collectAndWriteToScarDeploymentArtifacts(zip, component, aiiArtifactList);
+
+ if (collectAndWriteToScarDeploymentArtifacts.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ } catch (IOException e) {
+ log.debug("Failed to create CSAR zip for component {}", component.getUniqueId(), e);
+ }
+
+ return Either.left(zip);
+ }
+
+ private Either<ZipOutputStream, ActionStatus> collectAndWriteToScarDeploymentArtifacts(ZipOutputStream zip, Component component, List<ArtifactDefinition> aiiArtifactList) throws IOException {
+
+ Collection<ArtifactDefinition> deploymentArtifactsToAdd = null;
+ Collection<ArtifactDefinition> allArtifactsToAdd = new LinkedList<>();
+
+ if (component.getComponentType() == ComponentTypeEnum.SERVICE) {
+ Either<Service, StorageOperationStatus> getServiceResponse = serviceOperation.getService(component.getUniqueId());
+
+ if (getServiceResponse.isLeft()) {
+ Service service = getServiceResponse.left().value();
+
+ if (!aiiArtifactList.isEmpty()) {
+ deploymentArtifactsToAdd = service.getDeploymentArtifacts().values().stream().filter(e -> e.getGenerated() == null || !e.getGenerated()).collect(Collectors.toList());
+ allArtifactsToAdd.addAll(aiiArtifactList);
+ allArtifactsToAdd.addAll(deploymentArtifactsToAdd);
+ } else {
+ allArtifactsToAdd.addAll(service.getDeploymentArtifacts().values());
+ }
+ }
+ }
+
+ if (!allArtifactsToAdd.isEmpty()) {
+
+ for (ArtifactDefinition deploymentArtifactDefinition : allArtifactsToAdd) {
+ String artifactFileName = deploymentArtifactDefinition.getArtifactName();
+ byte[] payloadData = deploymentArtifactDefinition.getPayloadData();
+
+ if (payloadData == null) {
+ String esId = deploymentArtifactDefinition.getEsId();
+ if (esId != null) {
+ Either<byte[], ActionStatus> fromCassandra = getFromCassandra(esId);
+
+ if (fromCassandra.isRight()) {
+ return Either.right(fromCassandra.right().value());
+ }
+ payloadData = fromCassandra.left().value();
+ } else {
+ log.debug("Artifact {} payload not supplied in ArtifactDefinition and not found in DB", artifactFileName);
+ continue;
+ }
+ }
+
+ byte[] decodedPayload = null;
+
+ if (Base64.isBase64(payloadData)) {
+ // decodedPayload = Base64.getDecoder().decode(payloadData);
+ decodedPayload = Base64.decodeBase64(payloadData);
+ } else {
+ decodedPayload = payloadData;
+ }
+
+ zip.putNextEntry(new ZipEntry(ARTIFACTS_PATH + artifactFileName));
+ zip.write(decodedPayload);
+ }
+ }
+
+ return Either.left(zip);
+ }
+
+ private Either<List<ArtifactDefinition>, ResponseFormat> handleAAIArtifacts(Component component, ZipOutputStream zip, boolean mockGenerator, boolean shouldLock, boolean inTransaction, List<ImmutablePair<Component, byte[]>> generatorInputs) {
+
+ ComponentTypeEnum componentType = component.getComponentType();
+ List<Artifact> generatedArtifacts = null;
+ List<ArtifactDefinition> aaiArtifacts = null;
+
+ if (componentType == ComponentTypeEnum.SERVICE && !generatorInputs.isEmpty()) {
+ List<Artifact> convertedGeneratorInputs = convertToGeneratorArtifactsInput(generatorInputs);
+
+ Either<List<Artifact>, ResponseFormat> generatorResponse;
+
+ if (mockGenerator) {
+ generatorResponse = artifactGenerator(convertedGeneratorInputs, ArtifactType.OTHER, component);
+ } else {
+ generatorResponse = artifactGenerator(convertedGeneratorInputs, ArtifactType.AAI, component);
+ }
+
+ if (generatorResponse.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, component.getComponentType().getValue(), component.getName(), generatorResponse.toString());
+ return Either.right(responseFormat);
+ }
+
+ generatedArtifacts = generatorResponse.left().value();
+
+ aaiArtifacts = convertToArtifactDefinitionFromArtifactGeneratedData(generatedArtifacts);
+
+ }
+
+ return Either.left(aaiArtifacts);
+ }
+
+ private Either<ActionStatus, ResponseFormat> handleAllAAIArtifactsInDataModel(Component component, List<ArtifactDefinition> artifactsFromAAI, boolean shouldLock, boolean inTransaction) {
+
+ Either<ActionStatus, ResponseFormat> handleAAIArtifactsResponse = null;
+ User lastComponentUpdater = null;
+
+ List<ArtifactDefinition> aaiArtifatcsToCreate = getAAIArtifatcsForCreate(artifactsFromAAI, component);
+ List<ArtifactDefinition> aaiArtifatcsToDelete = getAAIArtifatcsForDelete(artifactsFromAAI, component);
+ List<ArtifactDefinition> aaiArtifatcsToUpdate = getAAIArtifatcsForUpdate(artifactsFromAAI, component);
+
+ String lastUpdaterUserId = component.getLastUpdaterUserId();
+ Either<User, ResponseFormat> validateUserExists = artifactsBusinessLogic.validateUserExists(lastUpdaterUserId, "CSAR creation util", true);
+
+ if (validateUserExists.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, component.getComponentType().getValue(), component.getName(), "User not found");
+ return Either.right(responseFormat);
+ }
+
+ lastComponentUpdater = validateUserExists.left().value();
+
+ handleAAIArtifactsResponse = handleAAIArtifactsInDataModelByOperationType(component, aaiArtifatcsToDelete, ArtifactOperation.Delete, lastComponentUpdater, shouldLock, inTransaction);
+
+ if (handleAAIArtifactsResponse.isRight()) {
+ return handleAAIArtifactsResponse;
+ }
+
+ handleAAIArtifactsResponse = handleAAIArtifactsInDataModelByOperationType(component, aaiArtifatcsToCreate, ArtifactOperation.Create, lastComponentUpdater, shouldLock, inTransaction);
+
+ if (handleAAIArtifactsResponse.isRight()) {
+ return handleAAIArtifactsResponse;
+ }
+
+ return handleAAIArtifactsInDataModelByOperationType(component, aaiArtifatcsToUpdate, ArtifactOperation.Update, lastComponentUpdater, shouldLock, inTransaction);
+ }
+
+ private List<ArtifactDefinition> getAAIArtifatcsForUpdate(List<ArtifactDefinition> artifactsFromAAI, Component component) {
+
+ Set<String> componetDeploymentArtifactLables = component.getDeploymentArtifacts().keySet();
+ Set<String> componetInformationalArtifactLables = component.getArtifacts().keySet();
+
+ List<ArtifactDefinition> artifactsAaiUpdate = artifactsFromAAI.stream().filter(e -> (componetDeploymentArtifactLables.contains(e.getArtifactLabel()) || componetInformationalArtifactLables.contains(e.getArtifactLabel())))
+ .filter(e -> checkAaiForUpdate(component, e)).collect(Collectors.toList());
+
+ return artifactsAaiUpdate;
+ }
+
+ private boolean checkAaiForUpdate(Component component, ArtifactDefinition artifactDefinition) {
+ ArtifactDefinition artifactDefinitionComp = component.getDeploymentArtifacts().get(artifactDefinition.getArtifactLabel());
+
+ if (artifactDefinitionComp == null) {
+ log.warn("Failed to get {} artifact", artifactDefinition.getArtifactLabel());
+ return false;
+ }
+
+ // Old Artifacts before the generated flag introduction if contains "aai" ignore case prefix updated
+ if (artifactDefinitionComp.getGenerated() == null) {
+ if (artifactDefinitionComp.getArtifactLabel().toLowerCase().startsWith("aai")) {
+ return true;
+ } else {
+ log.warn("The artifact {} flag is null but AAI prefix is abssent Not updated", artifactDefinition.getArtifactLabel());
+ }
+ } else {
+ if (artifactDefinition.getGenerated()) {
+ return true;
+ } else {
+ log.warn("Generated artifact {} was already uploaded manually", artifactDefinition.getArtifactLabel());
+ }
+ }
+ return false;
+ }
+
+ private List<ArtifactDefinition> getAAIArtifatcsForDelete(List<ArtifactDefinition> artifactsFromAAI, Component component) {
+
+ Set<String> aaiLabels = artifactsFromAAI.stream().map(e -> e.getArtifactLabel()).collect(Collectors.toSet());
+
+ List<ArtifactDefinition> artifactsForDeleteDeployment = component.getDeploymentArtifacts().values().stream().
+ // Filter Out Artifacts that are not contained in artifacts returned
+ // from AAI API
+ filter(e -> !aaiLabels.contains(e.getArtifactLabel())).collect(Collectors.toList());
+
+ List<ArtifactDefinition> artifactsForDeleteInformational = component.getArtifacts().values().stream().
+ // Filter Out Artifacts that are not contained in artifacts returned
+ // from AAI API
+ filter(e -> !aaiLabels.contains(e.getArtifactLabel())).collect(Collectors.toList());
+
+ artifactsForDeleteDeployment.addAll(artifactsForDeleteInformational);
+
+ return artifactsForDeleteDeployment.stream().filter(e -> (e.getGenerated() != null && e.getGenerated().equals(Boolean.TRUE)) || (e.getGenerated() == null && e.getArtifactLabel().toLowerCase().startsWith("aai"))).collect(Collectors.toList());
+ }
+
+ private List<ArtifactDefinition> getAAIArtifatcsForCreate(List<ArtifactDefinition> artifactsFromAAI, Component component) {
+
+ Set<String> componentDeploymentLabels = component.getDeploymentArtifacts().keySet();
+ Set<String> componentInfoLabels = component.getArtifacts().keySet();
+
+ // If the artifact label does not exist in the service -
+ // store the artifact (generate uuid and version, "generated" flag is TRUE)
+ return artifactsFromAAI.stream().filter(e -> !componentDeploymentLabels.contains(e.getArtifactLabel()) && !componentInfoLabels.contains(e.getArtifactLabel())).collect(Collectors.toList());
+ }
+
+ private Either<ActionStatus, ResponseFormat> handleAAIArtifactsInDataModelByOperationType(Component component, List<ArtifactDefinition> generatedArtifactsDefinitions, ArtifactOperation operationType, User user, boolean shouldLock,
+ boolean inTransaction) {
+
+ String componentUniqueId = component.getUniqueId();
+ ComponentTypeEnum componentType = component.getComponentType();
+
+ for (ArtifactDefinition artDef : generatedArtifactsDefinitions) {
+ String data = gson.toJson(artDef);
+ String dataMD5 = GeneralUtility.calculateMD5ByString(data);
+ String artifactUniqueId = null;
+
+ if (operationType.equals(ArtifactOperation.Update) || operationType.equals(ArtifactOperation.Delete)) {
+ String artifactLabel = artDef.getArtifactLabel();
+ ArtifactDefinition artifactDefinition = component.getDeploymentArtifacts().get(artifactLabel);
+ if (artifactDefinition != null) {
+ artifactUniqueId = artifactDefinition.getUniqueId();
+ }
+ }
+
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> validateAndHandleArtifact = artifactsBusinessLogic.validateAndHandleArtifact(componentUniqueId, componentType, operationType, artifactUniqueId, artDef, dataMD5, data, null,
+ null, null, user, component, shouldLock, inTransaction);
+
+ if (validateAndHandleArtifact.isRight()) {
+ if (ArtifactOperation.Create == operationType || ArtifactOperation.Update == operationType) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, componentType.getValue(), component.getName(), validateAndHandleArtifact.right().value().toString());
+
+ Either.right(responseFormat);
+ } else {
+ log.warn("Generated artifact {} could not be deleted", artDef.getArtifactLabel());
+ }
+ }
+ }
+
+ return Either.left(ActionStatus.OK);
+ }
+
+ private List<ArtifactDefinition> convertToArtifactDefinitionFromArtifactGeneratedData(List<Artifact> generatorOutput) {
+ List<ArtifactDefinition> artifactDefList = new LinkedList<>();
+
+ for (Artifact artifact : generatorOutput) {
+ ArtifactDefinition newEntry = new ArtifactDefinition();
+ newEntry.setArtifactName(artifact.getName());
+ newEntry.setArtifactType(artifact.getType());
+ newEntry.setArtifactGroupType(ArtifactGroupTypeEnum.findType(artifact.getGroupType()));
+ newEntry.setDescription(artifact.getDescription());
+
+ // Normalizing the artifact label to match those stored in DB
+ String normalizeArtifactLabel = ValidationUtils.normalizeArtifactLabel(artifact.getLabel());
+ newEntry.setArtifactLabel(normalizeArtifactLabel);
+ newEntry.setPayload(artifact.getPayload());
+ newEntry.setArtifactChecksum(artifact.getChecksum());
+ // Flag that set to true in case that the artifact is generated by AI&I generator
+ newEntry.setGenerated(Boolean.TRUE);
+
+ artifactDefList.add(newEntry);
+ }
+
+ return artifactDefList;
+ }
+
+ // List<ImmutablePair<Component, byte[] artifactBytes>>
+ // artifact stored by label
+ private List<Artifact> convertToGeneratorArtifactsInput(List<ImmutablePair<Component, byte[]>> inputs) {
+ List<Artifact> listOfArtifactsInput = new LinkedList<>();
+ for (ImmutablePair<Component, byte[]> triple : inputs) {
+ Component component = triple.getLeft();
+
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
+
+ String artifactName = artifactDefinition.getArtifactName();
+ String artifactType = artifactDefinition.getArtifactType();
+ String artifactGroupType = artifactDefinition.getArtifactGroupType().getType();
+ String artifactDescription = artifactDefinition.getDescription();
+ String artifactLabel = artifactDefinition.getArtifactLabel();
+ byte[] right = triple.getRight();
+ // The md5 calculated on the uncoded data
+ String md5Hex = DigestUtils.md5Hex(right);
+ // byte[] payload = Base64.getEncoder().encode(right);
+ byte[] payload = Base64.encodeBase64(right);
+ String artifactVersion = artifactDefinition.getArtifactVersion();
+
+ Artifact convertedArtifact = new Artifact(artifactType, artifactGroupType, md5Hex, payload);
+ convertedArtifact.setName(artifactName);
+ convertedArtifact.setDescription(artifactDescription);
+ convertedArtifact.setLabel(artifactLabel);
+ convertedArtifact.setVersion(artifactVersion);
+
+ listOfArtifactsInput.add(convertedArtifact);
+ }
+
+ return listOfArtifactsInput;
+ }
+
+ private Either<byte[], ActionStatus> getEntryData(String esId, Component childComponent) {
+ byte[] content;
+ if (esId == null || esId.isEmpty()) {
+ Either<ToscaRepresentation, ToscaError> exportRes = toscaExportUtils.exportComponent(childComponent);
+ if (exportRes.isRight()) {
+ log.debug("Failed to export tosca template for child component {} error {}", childComponent.getUniqueId(), exportRes.right().value());
+ return Either.right(componentsUtils.convertFromToscaError(exportRes.right().value()));
+ }
+ content = exportRes.left().value().getMainYaml().getBytes();
+ } else {
+ Either<byte[], ActionStatus> fromCassandra = getFromCassandra(esId);
+ if (fromCassandra.isRight()) {
+ return Either.right(fromCassandra.right().value());
+ } else {
+ content = fromCassandra.left().value();
+ }
+ }
+ return Either.left(content);
+ }
+
+ private Either<byte[], ActionStatus> getFromCassandra(String esId) {
+ Either<ESArtifactData, CassandraOperationStatus> artifactResponse = artifactCassandraDao.getArtifact(esId);
+
+ if (artifactResponse.isRight()) {
+ log.debug("In createCsar fetching of artifact from CS failed");
+ log.debug("Failed to fetch from Cassandra by id {} error {} ", esId, artifactResponse.right().value());
+
+ StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(artifactResponse.right().value());
+ ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
+ return Either.right(convertedFromStorageResponse);
+ } else {
+ ESArtifactData artifactData = artifactResponse.left().value();
+ return Either.left(artifactData.getDataAsArray());
+
+ }
+ }
+
+ private String createToscaBlock0(String metaFileVersion, String csarVersion, String createdBy, String entryDef) {
+ final String BLOCK_0_TEMPLATE = "TOSCA-Meta-File-Version: %s\nCSAR-Version: %s\nCreated-By: %s\nEntry-Definitions: Definitions/%s\n";
+ String readyBlock = String.format(BLOCK_0_TEMPLATE, metaFileVersion, csarVersion, createdBy, entryDef);
+ return readyBlock;
+ }
+
+ private Either<List<Artifact>, ResponseFormat> artifactGenerator(List<Artifact> artifactList, ArtifactType type, Component component) {
+
+ ArtifactGenerationServiceImpl artifactGenerationServiceImpl = new ArtifactGenerationServiceImpl();
+ ArtifactTypes artifactTypes = new ArtifactTypes();
+ List<ArtifactType> artifactTypesList = new LinkedList<>();
+ ArtifactType otherType;
+
+ if (type == null) {
+ otherType = ArtifactType.OTHER;
+ } else {
+ otherType = type;
+ }
+
+ artifactTypesList.add(otherType);
+ artifactTypes.setArtifactTypes(artifactTypesList);
+
+ String configJson = gson.toJson(artifactTypes);
+ GenerationData generatedArtifacts = artifactGenerationServiceImpl.generateArtifact(artifactList, configJson);
+
+ Map<String, List<String>> errorData = generatedArtifacts.getErrorData();
+
+ if (!errorData.isEmpty()) {
+ Set<String> keySet = errorData.keySet();
+
+ for (String key : keySet) {
+ List<String> errorList = errorData.get(key);
+ log.debug("The Artifact Generator Failed - {} with following: {}", key, errorList);
+ }
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, component.getComponentType().getValue(), component.getName(), errorData.toString());
+ return Either.right(responseFormat);
+ }
+
+ return Either.left(generatedArtifacts.getResultData());
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
new file mode 100644
index 0000000000..544b85361d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
@@ -0,0 +1,189 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.model.tosca.converters.ToscaMapValueConverter;
+import org.openecomp.sdc.be.model.tosca.converters.ToscaValueConverter;
+import org.openecomp.sdc.be.tosca.model.EntrySchema;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
+import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.stream.JsonReader;
+
+import fj.data.Either;
+
+public class PropertyConvertor {
+ private static PropertyConvertor instance;
+ private JsonParser jsonParser = new JsonParser();
+ private static Logger log = LoggerFactory.getLogger(PropertyConvertor.class.getName());
+
+ protected PropertyConvertor() {
+
+ }
+
+ public static synchronized PropertyConvertor getInstance() {
+ if (instance == null) {
+ instance = new PropertyConvertor();
+ }
+ return instance;
+ }
+
+ public Either<ToscaNodeType, ToscaError> convertProperties(Component component, ToscaNodeType toscaNodeType, Map<String, DataTypeDefinition> dataTypes) {
+
+ if (component instanceof Resource) {
+ Resource resource = (Resource) component;
+ List<PropertyDefinition> props = resource.getProperties();
+ if (props != null) {
+ Map<String, ToscaProperty> properties = new HashMap<>();
+
+ // take only the properties of this resource
+ props.stream().filter(p -> component.getUniqueId().equals(p.getParentUniqueId())).forEach(property -> {
+ ToscaProperty prop = convertProperty(dataTypes, property, false);
+
+ properties.put(property.getName(), prop);
+
+ });
+ if (!properties.isEmpty()) {
+ toscaNodeType.setProperties(properties);
+ }
+ }
+ }
+ return Either.left(toscaNodeType);
+ }
+
+ public ToscaProperty convertProperty(Map<String, DataTypeDefinition> dataTypes, PropertyDefinition property, boolean isCapabiltyProperty) {
+ ToscaProperty prop = new ToscaProperty();
+
+ String innerType = null;
+ SchemaDefinition schema = property.getSchema();
+ if (schema != null && schema.getProperty() != null && schema.getProperty().getType() != null && !schema.getProperty().getType().isEmpty()) {
+ innerType = schema.getProperty().getType();
+ EntrySchema eschema = new EntrySchema();
+ eschema.setType(innerType);
+ eschema.setDescription(schema.getProperty().getDescription());
+ prop.setEntry_schema(eschema);
+ }
+ log.debug("try to convert property {} from type {} with default value {}", property.getName(), property.getType(), property.getDefaultValue());
+ prop.setDefaultp(convertToToscaObject(property.getType(), property.getDefaultValue(), innerType, dataTypes));
+ prop.setType(property.getType());
+ prop.setDescription(property.getDescription());
+ if (isCapabiltyProperty) {
+ prop.setStatus(property.getStatus());
+ prop.setRequired(property.isRequired());
+ }
+ return prop;
+ }
+
+ public Object convertToToscaObject(String propertyType, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) {
+ log.debug("try to convert propertyType {} , value {}, innerType {}", propertyType, value, innerType);
+ if (value == null) {
+ return value;
+ }
+
+ ToscaMapValueConverter mapConverterInst = ToscaMapValueConverter.getInstance();
+ ToscaValueConverter innerConverter = null;
+ Boolean isScalar = true;
+
+ ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
+ if (type == null) {
+ log.debug("isn't prederfined type, get from all data types");
+ DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
+ if (innerType == null) {
+ innerType = propertyType;
+ }
+
+ if ((type = mapConverterInst.isScalarType(dataTypeDefinition)) != null) {
+ log.debug("This is scalar type. get suitable converter for type {}", type);
+ innerConverter = type.getValueConverter();
+ } else {
+ isScalar = false;
+ }
+ } else {
+ ToscaPropertyType typeIfScalar = ToscaPropertyType.getTypeIfScalar(type.getType());
+ if (typeIfScalar == null) {
+ isScalar = false;
+ }
+
+ innerConverter = type.getValueConverter();
+ if (ToscaPropertyType.STRING.equals(type) && value.startsWith("/")) {
+ return innerConverter.convertToToscaValue(value, innerType, dataTypes);
+ }
+ }
+ JsonElement jsonElement = null;
+ try {
+ StringReader reader = new StringReader(value);
+ JsonReader jsonReader = new JsonReader(reader);
+ jsonReader.setLenient(true);
+
+ jsonElement = jsonParser.parse(jsonReader);
+
+ if (value.equals("")) {
+ return value;
+ }
+
+ if (jsonElement.isJsonPrimitive() && isScalar) {
+ log.debug("It's well defined type. convert it");
+ ToscaValueConverter converter = type.getValueConverter();
+ return converter.convertToToscaValue(value, innerType, dataTypes);
+ } else {
+ log.debug("It's data type or inputs in primitive type. convert as map");
+ Object convertedValue;
+ if (innerConverter != null && (ToscaPropertyType.MAP.equals(type) || ToscaPropertyType.LIST.equals(type))) {
+ convertedValue = innerConverter.convertToToscaValue(value, innerType, dataTypes);
+ } else {
+ if (isScalar) {
+ // complex json for scalar type
+ convertedValue = mapConverterInst.handleComplexJsonValue(jsonElement);
+ } else {
+ if (innerConverter != null) {
+ convertedValue = innerConverter.convertToToscaValue(value, innerType, dataTypes);
+ } else {
+ convertedValue = mapConverterInst.convertDataTypeToToscaMap(innerType, dataTypes, innerConverter, isScalar, jsonElement);
+ }
+ }
+ }
+ return convertedValue;
+ }
+
+ } catch (JsonSyntaxException e) {
+ log.debug("convertToToscaValue failed to parse json value :", e);
+ return null;
+ }
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaError.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaError.java
new file mode 100644
index 0000000000..94dd559d2d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaError.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+public enum ToscaError {
+
+ NODE_TYPE_CAPABILITY_ERROR, NOT_SUPPORTED_TOSCA_TYPE, NODE_TYPE_REQUIREMENT_ERROR, GENERAL_ERROR
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
new file mode 100644
index 0000000000..1bf940ffc0
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -0,0 +1,629 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.beans.IntrospectionException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.ImmutableTriple;
+import org.apache.commons.lang3.tuple.Triple;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupProperty;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.IResourceOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.tosca.model.IToscaMetadata;
+import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
+import org.openecomp.sdc.be.tosca.model.ToscaCapability;
+import org.openecomp.sdc.be.tosca.model.ToscaGroupTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
+import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement;
+import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate;
+import org.openecomp.sdc.be.tosca.model.VfModuleToscaMetadata;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.DumperOptions.FlowStyle;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.introspector.BeanAccess;
+import org.yaml.snakeyaml.introspector.Property;
+import org.yaml.snakeyaml.introspector.PropertyUtils;
+import org.yaml.snakeyaml.nodes.MappingNode;
+import org.yaml.snakeyaml.nodes.Node;
+import org.yaml.snakeyaml.nodes.NodeTuple;
+import org.yaml.snakeyaml.nodes.Tag;
+import org.yaml.snakeyaml.representer.Represent;
+import org.yaml.snakeyaml.representer.Representer;
+
+import fj.data.Either;
+
+@org.springframework.stereotype.Component("tosca-export-handler")
+public class ToscaExportHandler {
+
+ @Autowired
+ private ApplicationDataTypeCache dataTypeCache;
+
+ @Autowired
+ private IResourceOperation resourceOperation;
+
+ private CapabiltyRequirementConvertor capabiltyRequirementConvertor = CapabiltyRequirementConvertor.getInstance();
+ private PropertyConvertor propertyConvertor = PropertyConvertor.getInstance();
+
+ private static Logger log = LoggerFactory.getLogger(ToscaExportHandler.class.getName());
+
+ public static final String TOSCA_VERSION = "tosca_simple_yaml_1_0";
+ public static final String SERVICE_NODE_TYPE_PREFIX = "org.openecomp.service.";
+ public static final String IMPORTS_FILE_KEY = "file";
+ public static final String TOSCA_TEMPLATE_NAME = "-template.yml";
+ public static final String ASSET_TOSCA_TEMPLATE = "assettoscatemplate";
+ public static final String VF_MODULE_TYPE_KEY = "vf_module_type";
+ public static final String VF_MODULE_DESC_KEY = "vf_module_description";
+ public static final String VOLUME_GROUP_KEY = "volume_group";
+ public static final String VF_MODULE_TYPE_BASE = "Base";
+ public static final String VF_MODULE_TYPE_EXPANSION = "Expansion";
+
+ public Either<ToscaRepresentation, ToscaError> exportComponent(Component component) {
+
+ Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertToToscaTemplate(component);
+ if (toscaTemplateRes.isRight()) {
+ return Either.right(toscaTemplateRes.right().value());
+ }
+
+ CustomRepresenter representer = new CustomRepresenter();
+ DumperOptions options = new DumperOptions();
+ options.setAllowReadOnlyProperties(false);
+ options.setPrettyFlow(true);
+
+ options.setDefaultFlowStyle(FlowStyle.FLOW);
+ options.setCanonical(false);
+
+ ToscaTemplate toscaTemplate = toscaTemplateRes.left().value();
+ representer.addClassTag(toscaTemplate.getClass(), Tag.MAP);
+
+ representer.setPropertyUtils(new UnsortedPropertyUtils());
+ Yaml yaml = new Yaml(representer, options);
+
+ String yamlAsString = yaml.dumpAsMap(toscaTemplate);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactHeader());
+ sb.append(yamlAsString);
+ sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactFooter());
+
+ ToscaRepresentation toscaRepresentation = new ToscaRepresentation();
+ toscaRepresentation.setMainYaml(sb.toString());
+ toscaRepresentation.setDependencies(toscaTemplate.getDependencies());
+
+ return Either.left(toscaRepresentation);
+ }
+
+ public Either<ToscaTemplate, ToscaError> getDependencies(Component component) {
+ ToscaTemplate toscaTemplate = new ToscaTemplate(null);
+ Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports = fillImports(component, toscaTemplate);
+ if (fillImports.isRight()) {
+ return Either.right(fillImports.right().value());
+ }
+ return Either.left(fillImports.left().value().left);
+ }
+
+ private Either<ToscaTemplate, ToscaError> convertToToscaTemplate(Component component) {
+ log.debug("start tosca export for {}", component.getUniqueId());
+ ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION);
+
+ toscaTemplate.setMetadata(convertMetadata(component, false));
+
+ Map<String, ToscaNodeType> node_types = new HashMap<>();
+ if (ToscaUtils.isNodeType(component)) {
+ log.debug("convert component as node type");
+ return convertNodeType(component, toscaTemplate, node_types);
+ } else {
+ log.debug("convert component as topology template");
+ return convertToscaTemplate(component, toscaTemplate);
+ }
+
+ }
+
+ private Either<ToscaTemplate, ToscaError> convertToscaTemplate(Component component, ToscaTemplate toscaNode) {
+
+ Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> importsRes = fillImports(component, toscaNode);
+ if (importsRes.isRight()) {
+ return Either.right(importsRes.right().value());
+ }
+ toscaNode = importsRes.left().value().left;
+
+ Map<String, Component> componentCache = importsRes.left().value().right;
+ Either<Map<String, DataTypeDefinition>, TitanOperationStatus> dataTypesEither = dataTypeCache.getAll();
+ if (dataTypesEither.isRight()) {
+ log.debug("Failed to retrieve all data types {}", dataTypesEither.right().value());
+ return Either.right(ToscaError.GENERAL_ERROR);
+ }
+ Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
+
+ ToscaTopolgyTemplate topology_template = new ToscaTopolgyTemplate();
+
+ Either<ToscaTopolgyTemplate, ToscaError> inputs = fillInputs(component, topology_template, dataTypes);
+ if (inputs.isRight()) {
+ return Either.right(inputs.right().value());
+ }
+ topology_template = inputs.left().value();
+
+ List<ComponentInstance> componentInstances = component.getComponentInstances();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = component.getComponentInstancesProperties();
+ List<GroupDefinition> groups = component.getGroups();
+ if (componentInstances != null && !componentInstances.isEmpty()) {
+
+ Either<Map<String, ToscaNodeTemplate>, ToscaError> node_templates = convertNodeTemplates(component, componentInstances, componentInstancesProperties, componentCache, dataTypes);
+ if (node_templates.isRight()) {
+ return Either.right(node_templates.right().value());
+ }
+ log.debug("node templates converted");
+
+ topology_template.setNode_templates(node_templates.left().value());
+ }
+ if (groups != null && !groups.isEmpty()) {
+ Map<String, ToscaGroupTemplate> groupsMap = new HashMap<String, ToscaGroupTemplate>();
+ for (GroupDefinition group : groups) {
+ ToscaGroupTemplate toscaGroup = convertGroup(group, component);
+ groupsMap.put(group.getName(), toscaGroup);
+
+ }
+ topology_template.setGroups(groupsMap);
+ log.debug("groups converted");
+
+ }
+
+ SubstitutionMapping substitutionMapping = new SubstitutionMapping();
+ String toscaResourceName = null;
+ switch (component.getComponentType()) {
+ case RESOURCE:
+ toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getToscaResourceName();
+ break;
+ case SERVICE:
+ toscaResourceName = SERVICE_NODE_TYPE_PREFIX + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
+ break;
+ default:
+ log.debug("Not supported component type {}", component.getComponentType());
+ return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
+ }
+ substitutionMapping.setNode_type(toscaResourceName);
+
+ Either<SubstitutionMapping, ToscaError> capabilities = convertCapabilities(component, substitutionMapping, dataTypes);
+ if (capabilities.isRight()) {
+ return Either.right(capabilities.right().value());
+ }
+ substitutionMapping = capabilities.left().value();
+
+ Either<SubstitutionMapping, ToscaError> requirements = capabiltyRequirementConvertor.convertRequirements(component, substitutionMapping);
+ if (requirements.isRight()) {
+ return Either.right(requirements.right().value());
+ }
+ substitutionMapping = requirements.left().value();
+
+ topology_template.setSubstitution_mappings(substitutionMapping);
+
+ toscaNode.setTopology_template(topology_template);
+ return Either.left(toscaNode);
+ }
+
+ private Either<ToscaTopolgyTemplate, ToscaError> fillInputs(Component component, ToscaTopolgyTemplate topology_template, Map<String, DataTypeDefinition> dataTypes) {
+ if (log.isDebugEnabled())
+ log.debug("fillInputs for component {}", component.getUniqueId());
+ List<InputDefinition> inputDef = component.getInputs();
+ Map<String, ToscaProperty> inputs = new HashMap<>();
+
+ if (inputDef != null) {
+ inputDef.forEach(i -> {
+ ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false);
+ inputs.put(i.getName(), property);
+ });
+ if (inputs != null && !inputs.isEmpty()) {
+ topology_template.setInputs(inputs);
+ }
+ }
+ return Either.left(topology_template);
+ }
+
+ private ToscaMetadata convertMetadata(Component component, boolean isInstance) {
+ ToscaMetadata toscaMetadata = new ToscaMetadata();
+ toscaMetadata.setName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
+ toscaMetadata.setInvariantUUID(component.getInvariantUUID());
+ toscaMetadata.setUUID(component.getUUID());
+ toscaMetadata.setDescription(component.getDescription());
+
+ List<CategoryDefinition> categories = component.getCategories();
+ CategoryDefinition categoryDefinition = categories.get(0);
+ toscaMetadata.setCategory(categoryDefinition.getName());
+
+ if (isInstance) {
+ toscaMetadata.setVersion(component.getVersion());
+ }
+ switch (component.getComponentType()) {
+ case RESOURCE:
+ Resource resource = (Resource) component;
+ toscaMetadata.setType(resource.getResourceType().name());
+ toscaMetadata.setSubcategory(categoryDefinition.getSubcategories().get(0).getName());
+ if (!isInstance) {
+ toscaMetadata.setResourceVendor(resource.getVendorName());
+ toscaMetadata.setResourceVendorRelease(resource.getVendorRelease());
+ }
+ break;
+ case SERVICE:
+ toscaMetadata.setType(component.getComponentType().getValue());
+ if (!isInstance) {
+ toscaMetadata.setServiceEcompNaming(false);
+ toscaMetadata.setServiceHoming(false);
+ }
+ break;
+ default:
+ log.debug("Not supported component type {}", component.getComponentType());
+ }
+ return toscaMetadata;
+ }
+
+ private Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports(Component component, ToscaTemplate toscaTemplate) {
+ Map<String, Component> componentCache = new HashMap<>();
+ if (!ToscaUtils.isNodeType(component)) {
+ List<ComponentInstance> componentInstances = component.getComponentInstances();
+ if (componentInstances != null && !componentInstances.isEmpty()) {
+ List<Map<String, Map<String, String>>> imports = new LinkedList<Map<String, Map<String, String>>>();
+ List<Triple<String, String, Component>> dependecies = new ArrayList<>();
+
+ componentInstances.forEach(ci -> {
+ createDependency(componentCache, imports, dependecies, ci);
+ });
+ toscaTemplate.setImports(imports);
+ toscaTemplate.setDependencies(dependecies);
+ }
+ } else {
+ log.debug("currently imports supported for VF and service only");
+ }
+ return Either.left(new ImmutablePair<ToscaTemplate, Map<String, Component>>(toscaTemplate, componentCache));
+ }
+
+ private void createDependency(Map<String, Component> componentCache, List<Map<String, Map<String, String>>> imports, List<Triple<String, String, Component>> dependecies, ComponentInstance ci) {
+ Map<String, String> files = new HashMap<>();
+ Map<String, Map<String, String>> importsListMember = new HashMap<>();
+
+ Component componentRI = componentCache.get(ci.getComponentUid());
+ if (componentRI == null) {
+ // all resource must be only once!
+ Either<Resource, StorageOperationStatus> resource = resourceOperation.getResource(ci.getComponentUid(), true);
+ if (resource.isRight()) {
+ log.debug("Failed to fetch resource with id {} for instance {}");
+ }
+ Resource fetchedComponent = resource.left().value();
+ componentCache.put(fetchedComponent.getUniqueId(), fetchedComponent);
+ componentRI = fetchedComponent;
+
+ Map<String, ArtifactDefinition> toscaArtifacts = componentRI.getToscaArtifacts();
+ ArtifactDefinition artifactDefinition = toscaArtifacts.get(ASSET_TOSCA_TEMPLATE);
+ if (artifactDefinition != null) {
+ String artifactName = artifactDefinition.getArtifactName();
+ files.put(IMPORTS_FILE_KEY, artifactName);
+ importsListMember.put(ci.getComponentName(), files);
+ dependecies.add(new ImmutableTriple<String, String, Component>(artifactName, artifactDefinition.getEsId(), fetchedComponent));
+ }
+ }
+ if (!importsListMember.isEmpty()) {
+ imports.add(importsListMember);
+ }
+ }
+
+ private Either<ToscaTemplate, ToscaError> convertNodeType(Component component, ToscaTemplate toscaNode, Map<String, ToscaNodeType> node_types) {
+ log.debug("start convert node type for {}", component.getUniqueId());
+ ToscaNodeType toscaNodeType = createNodeType(component);
+
+ Either<Map<String, DataTypeDefinition>, TitanOperationStatus> dataTypesEither = dataTypeCache.getAll();
+ if (dataTypesEither.isRight()) {
+ log.debug("Failed to fetch all data types :", dataTypesEither.right().value());
+ return Either.right(ToscaError.GENERAL_ERROR);
+ }
+
+ Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
+ Either<ToscaNodeType, ToscaError> properties = propertyConvertor.convertProperties(component, toscaNodeType, dataTypes);
+ if (properties.isRight()) {
+ return Either.right(properties.right().value());
+ }
+ toscaNodeType = properties.left().value();
+ log.debug("Properties converted for {}", component.getUniqueId());
+
+ Either<ToscaNodeType, ToscaError> capabilities = convertCapabilities(component, toscaNodeType, dataTypes);
+ if (capabilities.isRight()) {
+ return Either.right(capabilities.right().value());
+ }
+ toscaNodeType = capabilities.left().value();
+ log.debug("Capabilities converted for {}", component.getUniqueId());
+
+ Either<ToscaNodeType, ToscaError> requirements = capabiltyRequirementConvertor.convertRequirements(component, toscaNodeType);
+ if (requirements.isRight()) {
+ return Either.right(requirements.right().value());
+ }
+ toscaNodeType = requirements.left().value();
+ log.debug("Requirements converted for {}", component.getUniqueId());
+
+ String toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getToscaResourceName();
+ node_types.put(toscaResourceName, toscaNodeType);
+ toscaNode.setNode_types(node_types);
+ log.debug("finish convert node type for {}", component.getUniqueId());
+ return Either.left(toscaNode);
+ }
+
+ private Either<Map<String, ToscaNodeTemplate>, ToscaError> convertNodeTemplates(Component component, List<ComponentInstance> componentInstances, Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
+ Map<String, Component> componentCache, Map<String, DataTypeDefinition> dataTypes) {
+ log.debug("start convert topology template for {} for type {}", component.getUniqueId(), component.getComponentType());
+ Map<String, ToscaNodeTemplate> node_templates = new HashMap<>();
+
+ for (ComponentInstance componentInstance : componentInstances) {
+ ToscaNodeTemplate nodeTemplate = new ToscaNodeTemplate();
+ nodeTemplate.setType(componentInstance.getToscaComponentName());
+
+ Either<ToscaNodeTemplate, ToscaError> requirements = convertComponentInstanceRequirements(component, componentInstance, component.getComponentInstancesRelations(), nodeTemplate);
+ if (requirements.isRight()) {
+ return Either.right(requirements.right().value());
+ }
+ log.debug("Component instance Requirements converted for instance {}", componentInstance.getUniqueId());
+
+ nodeTemplate = requirements.left().value();
+
+ Component componentOfInstance = componentCache.get(componentInstance.getComponentUid());
+ nodeTemplate.setMetadata(convertMetadata(componentOfInstance, true));
+
+ Either<ToscaNodeTemplate, ToscaError> capabilties = capabiltyRequirementConvertor.convertComponentInstanceCapabilties(componentInstance, dataTypes, nodeTemplate);
+ if (capabilties.isRight()) {
+ return Either.right(requirements.right().value());
+ }
+ log.debug("Component instance Capabilties converted for instance {}", componentInstance.getUniqueId());
+
+ nodeTemplate = capabilties.left().value();
+
+ if (componentInstancesProperties.containsKey(componentInstance.getUniqueId())) {
+ Map<String, Object> props = null;
+ List<ComponentInstanceProperty> propList = componentInstancesProperties.get(componentInstance.getUniqueId());
+ List<ComponentInstanceProperty> collect = propList.stream().filter(e -> e.getValueUniqueUid() != null && !e.getValueUniqueUid().isEmpty()).collect(Collectors.toList());
+ if (collect != null && !collect.isEmpty()) {
+ props = new HashMap<String, Object>();
+ for (ComponentInstanceProperty prop : collect) {
+ Object convertedValue = convertInstanceProperty(dataTypes, componentInstance, prop);
+ props.put(prop.getName(), convertedValue);
+ }
+ }
+ if (props != null && !props.isEmpty()) {
+ nodeTemplate.setProperties(props);
+ }
+ }
+ node_templates.put(componentInstance.getName(), nodeTemplate);
+ }
+ log.debug("finish convert topology template for {} for type {}", component.getUniqueId(), component.getComponentType());
+ return Either.left(node_templates);
+ }
+
+ private Object convertInstanceProperty(Map<String, DataTypeDefinition> dataTypes, ComponentInstance componentInstance, ComponentInstanceProperty prop) {
+ log.debug("Convert property {} for instance {}", prop.getName(), componentInstance.getUniqueId());
+ String propertyType = prop.getType();
+ String innerType = null;
+ if (prop.getSchema() != null && prop.getSchema().getProperty() != null) {
+ innerType = prop.getSchema().getProperty().getType();
+ }
+ Object convertedValue = propertyConvertor.convertToToscaObject(propertyType, prop.getValue(), innerType, dataTypes);
+ return convertedValue;
+ }
+
+ private ToscaGroupTemplate convertGroup(GroupDefinition group, Component component) {
+ ToscaGroupTemplate toscaGroup = new ToscaGroupTemplate();
+ Map<String, String> members = group.getMembers();
+ toscaGroup.setType(group.getType());
+ if (members != null)
+ toscaGroup.setMembers(new ArrayList(members.keySet()));
+
+ boolean isVfModule = group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE) ? true : false;
+ IToscaMetadata toscaMetadata;
+ if (!isVfModule) {
+ toscaMetadata = new ToscaMetadata();
+ } else {
+ toscaMetadata = new VfModuleToscaMetadata();
+ Map<String, Object> properties = new HashMap<>();
+
+ for (GroupProperty gp : group.getProperties()) {
+ if (gp.getName().equals(Constants.IS_BASE)) {
+ Boolean isBase = Boolean.parseBoolean(gp.getValue());
+ String type = isBase ? VF_MODULE_TYPE_BASE : VF_MODULE_TYPE_EXPANSION;
+ properties.put(VF_MODULE_TYPE_KEY, type);
+ break;
+ }
+ }
+ properties.put(VF_MODULE_DESC_KEY, group.getDescription());
+ boolean isVolume = false;
+ List<String> artifactsList = group.getArtifacts();
+ if (artifactsList != null && !artifactsList.isEmpty()) {
+
+ for (String artifactId : artifactsList) {
+ Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
+ Optional<ArtifactDefinition> findFirst = deploymentArtifacts.values().stream().filter(p -> p.getUniqueId().equals(artifactId)).findFirst();
+ if (findFirst.isPresent()) {
+ ArtifactDefinition artifactDefinition = findFirst.get();
+ if (artifactDefinition.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) {
+ isVolume = true;
+ break;
+ }
+ }
+ }
+ }
+ properties.put(VOLUME_GROUP_KEY, isVolume);
+ toscaGroup.setProperties(properties);
+ }
+ toscaMetadata.setName(group.getName());
+ toscaMetadata.setInvariantUUID(group.getInvariantUUID());
+ toscaMetadata.setUUID(group.getGroupUUID());
+ toscaMetadata.setVersion(group.getVersion());
+ toscaGroup.setMetadata(toscaMetadata);
+ return toscaGroup;
+ }
+
+ private ToscaNodeType createNodeType(Component component) {
+ ToscaNodeType toscaNodeType = new ToscaNodeType();
+ if (ToscaUtils.isNodeType(component) && ((Resource) component).getDerivedFrom() != null) {
+ toscaNodeType.setDerived_from(((Resource) component).getDerivedFrom().get(0));
+ }
+ toscaNodeType.setDescription(component.getDescription()); // or name??
+ return toscaNodeType;
+ }
+
+ private Either<ToscaNodeTemplate, ToscaError> convertComponentInstanceRequirements(Component component, ComponentInstance componentInstance, List<RequirementCapabilityRelDef> relations, ToscaNodeTemplate nodeTypeTemplate) {
+
+ List<ComponentInstance> instancesList = component.getComponentInstances();
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
+ Map<String, List<RequirementDefinition>> reqMap = componentInstance.getRequirements();
+
+ relations.stream().filter(p -> componentInstance.getUniqueId().equals(p.getFromNode())).forEach(req -> {
+ ComponentInstance toComponentInstance = instancesList.stream().filter(i -> req.getToNode().equals(i.getUniqueId())).findFirst().orElse(null);
+ if (toComponentInstance == null) {
+ log.debug("Faild to create relation between node {} to node {}", componentInstance.getName(), req.getToNode());
+ return;
+
+ }
+ RequirementAndRelationshipPair reqAndRelationshopPair = req.getRelationships().get(0);
+ ToscaTemplateRequirement toscaRequirement = new ToscaTemplateRequirement();
+ toscaRequirement.setRelationship(reqAndRelationshopPair.getRelationship().getType());
+ toscaRequirement.setNode(toComponentInstance.getName());
+ Optional<RequirementDefinition> findAny = reqMap.values().stream().flatMap(e -> e.stream()).filter(e -> e.getName().equals(reqAndRelationshopPair.getRequirement())).findAny();
+ if (findAny.isPresent()) {
+ RequirementDefinition regDefinition = findAny.get();
+ toscaRequirement.setCapability(regDefinition.getCapability());
+ } else {
+ log.debug("Faild to find relation between node {} to node {}", componentInstance.getName(), req.getToNode());
+ return;
+ }
+ Map<String, ToscaTemplateRequirement> reqmap = new HashMap<String, ToscaTemplateRequirement>();
+ reqmap.put(reqAndRelationshopPair.getRequirement(), toscaRequirement);
+ toscaRequirements.add(reqmap);
+
+ });
+
+ if (!toscaRequirements.isEmpty()) {
+ nodeTypeTemplate.setRequirements(toscaRequirements);
+ }
+ log.debug("Finish convert Requirements for node type");
+ return Either.left(nodeTypeTemplate);
+ }
+
+ private Either<SubstitutionMapping, ToscaError> convertCapabilities(Component component, SubstitutionMapping substitutionMapping, Map<String, DataTypeDefinition> dataTypes) {
+ Map<String, ToscaCapability> toscaCapabilities = capabiltyRequirementConvertor.convertCapabilities(component, dataTypes);
+ if (!toscaCapabilities.isEmpty()) {
+ substitutionMapping.setCapabilities(toscaCapabilities);
+ }
+ log.debug("Finish convert Capabilities for node type");
+
+ return Either.left(substitutionMapping);
+ }
+
+ private Either<ToscaNodeType, ToscaError> convertCapabilities(Component component, ToscaNodeType nodeType, Map<String, DataTypeDefinition> dataTypes) {
+ Map<String, ToscaCapability> toscaCapabilities = capabiltyRequirementConvertor.convertCapabilities(component, dataTypes);
+ if (!toscaCapabilities.isEmpty()) {
+ nodeType.setCapabilities(toscaCapabilities);
+ }
+ log.debug("Finish convert Capabilities for node type");
+
+ return Either.left(nodeType);
+ }
+
+ private static class CustomRepresenter extends Representer {
+ public CustomRepresenter() {
+ super();
+ // null representer is exceptional and it is stored as an instance
+ // variable.
+ this.nullRepresenter = new RepresentNull();
+
+ }
+
+ @Override
+ protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
+ if (propertyValue == null) {
+ return null;
+ } else {
+ // skip not relevant for Tosca property
+ if (property.getName().equals("dependencies")) {
+ return null;
+ }
+ NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
+
+ return property.getName().equals("_defaultp_") ? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
+ }
+ }
+
+ @Override
+ protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
+ // remove the bean type from the output yaml (!! ...)
+ if (!classTags.containsKey(javaBean.getClass()))
+ addClassTag(javaBean.getClass(), Tag.MAP);
+
+ return super.representJavaBean(properties, javaBean);
+ }
+
+ private class RepresentNull implements Represent {
+ public Node representData(Object data) {
+ // possible values are here http://yaml.org/type/null.html
+ return representScalar(Tag.NULL, "");
+ }
+ }
+ }
+
+ private static class UnsortedPropertyUtils extends PropertyUtils {
+ @Override
+ protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bAccess) throws IntrospectionException {
+ Collection<Property> fields = getPropertiesMap(type, BeanAccess.FIELD).values();
+ Set<Property> result = new LinkedHashSet<Property>(fields);
+ return result;
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java
new file mode 100644
index 0000000000..6b1895b6ec
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.util.List;
+
+import org.apache.commons.lang3.tuple.Triple;
+import org.openecomp.sdc.be.model.Component;
+
+public class ToscaRepresentation {
+
+ private String mainYaml;
+ private List<Triple<String, String, Component>> dependencies;
+
+ public String getMainYaml() {
+ return mainYaml;
+ }
+
+ public void setMainYaml(String mainYaml) {
+ this.mainYaml = mainYaml;
+ }
+
+ public List<Triple<String, String, Component>> getDependencies() {
+ return dependencies;
+ }
+
+ public void setDependencies(List<Triple<String, String, Component>> dependancies) {
+ this.dependencies = dependancies;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java
new file mode 100644
index 0000000000..db03ad2307
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.Component;
+
+public class ToscaUtils {
+
+ public static boolean isNodeType(Component component) {
+ ComponentTypeEnum componentType = component.getComponentType();
+ if (ComponentTypeEnum.RESOURCE.equals(componentType)) {
+ ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType();
+ if (ResourceTypeEnum.CP.equals(resourceType) || ResourceTypeEnum.VL.equals(resourceType) || ResourceTypeEnum.VFC.equals(resourceType)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static Map<String, Object> objectToMap(Object objectToConvert, Class clazz) throws IllegalArgumentException, IllegalAccessException {
+ Map<String, Object> map = new HashMap<>();
+ List<Field> fields = new ArrayList<>();
+
+ fields = getAllFields(fields, clazz);
+
+ for (Field field : fields) {
+ field.setAccessible(true);
+ map.put(field.getName(), field.get(objectToConvert));
+ }
+ return map;
+ }
+
+ public static List<Field> getAllFields(List<Field> fields, Class<?> type) {
+ fields.addAll(Arrays.asList(type.getDeclaredFields()));
+
+ if (type.getSuperclass() != null) {
+ fields = getAllFields(fields, type.getSuperclass());
+ }
+ return fields;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/EntrySchema.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/EntrySchema.java
new file mode 100644
index 0000000000..0c586c7043
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/EntrySchema.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+public class EntrySchema {
+ private String type;
+ private String description;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/IToscaMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/IToscaMetadata.java
new file mode 100644
index 0000000000..46f4fd032e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/IToscaMetadata.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+public interface IToscaMetadata {
+
+ public void setName(String name);
+
+ public void setInvariantUUID(String invariantUUID);
+
+ public void setUUID(String uUID);
+
+ public void setVersion(String version);
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java
new file mode 100644
index 0000000000..0fd9daef7d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.Map;
+
+public class SubstitutionMapping {
+ private String node_type;
+
+ private Map<String, ToscaCapability> capabilities;
+ private Map<String, ToscaRequirement> requirements;
+
+ public SubstitutionMapping() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public String getNode_type() {
+ return node_type;
+ }
+
+ public void setNode_type(String node_type) {
+ this.node_type = node_type;
+ }
+
+ public Map<String, ToscaCapability> getCapabilities() {
+ return capabilities;
+ }
+
+ public void setCapabilities(Map<String, ToscaCapability> capabilities) {
+ this.capabilities = capabilities;
+ }
+
+ public Map<String, ToscaRequirement> getRequirements() {
+ return requirements;
+ }
+
+ public void setRequirements(Map<String, ToscaRequirement> requirements) {
+ this.requirements = requirements;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaCapability.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaCapability.java
new file mode 100644
index 0000000000..2688e5e6b3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaCapability.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaCapability {
+
+ private String type;
+ private String description;
+
+ private List<Object> occurrences;
+
+ private List<String> valid_source_types;
+
+ private Map<String, ToscaProperty> properties;
+
+ public List<String> getValid_source_types() {
+ return valid_source_types;
+ }
+
+ public void setValid_source_types(List<String> valid_source_types) {
+ this.valid_source_types = valid_source_types;
+ }
+
+ public ToscaCapability() {
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public List<Object> getOccurrences() {
+ return occurrences;
+ }
+
+ public void setOccurrences(List<Object> occurrences) {
+ this.occurrences = occurrences;
+ }
+
+ public Map<String, ToscaProperty> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, ToscaProperty> properties) {
+ this.properties = properties;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaGroupTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaGroupTemplate.java
new file mode 100644
index 0000000000..b91cffa5be
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaGroupTemplate.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaGroupTemplate {
+ private String type;
+ List<String> members;
+ private IToscaMetadata metadata;
+ private Map<String, Object> properties;
+
+ public ToscaGroupTemplate() {
+ super();
+
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public List<String> getMembers() {
+ return members;
+ }
+
+ public void setMembers(List<String> members) {
+ this.members = members;
+ }
+
+ public IToscaMetadata getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(IToscaMetadata metadata) {
+ this.metadata = metadata;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
new file mode 100644
index 0000000000..38cd002726
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+public class ToscaMetadata implements IToscaMetadata {
+ private String invariantUUID;
+ private String UUID;
+ private String version;
+ private String name;
+ private String description;
+ private String type;
+ private String category;
+ private String subcategory;
+ private String resourceVendor;
+ private String resourceVendorRelease;
+ private Boolean serviceEcompNaming;
+ private Boolean serviceHoming;
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getInvariantUUID() {
+ return invariantUUID;
+ }
+
+ @Override
+ public void setInvariantUUID(String invariantUUID) {
+ this.invariantUUID = invariantUUID;
+ }
+
+ public String getUUID() {
+ return UUID;
+ }
+
+ @Override
+ public void setUUID(String uUID) {
+ UUID = uUID;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getSubcategory() {
+ return subcategory;
+ }
+
+ public void setSubcategory(String subcategory) {
+ this.subcategory = subcategory;
+ }
+
+ public String getResourceVendor() {
+ return resourceVendor;
+ }
+
+ public void setResourceVendor(String resourceVendor) {
+ this.resourceVendor = resourceVendor;
+ }
+
+ public String getResourceVendorRelease() {
+ return resourceVendorRelease;
+ }
+
+ public void setResourceVendorRelease(String resourceVendorRelease) {
+ this.resourceVendorRelease = resourceVendorRelease;
+ }
+
+ public Boolean isServiceEcompNaming() {
+ return serviceEcompNaming;
+ }
+
+ public void setServiceEcompNaming(Boolean serviceEcompNaming) {
+ this.serviceEcompNaming = serviceEcompNaming;
+ }
+
+ public Boolean isServiceHoming() {
+ return serviceHoming;
+ }
+
+ public void setServiceHoming(Boolean serviceHoming) {
+ this.serviceHoming = serviceHoming;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ @Override
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java
new file mode 100644
index 0000000000..b2d7ef5ab6
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaNodeTemplate {
+ private String type;
+ private ToscaMetadata metadata;
+ private Map<String, Object> properties;
+ private List<Map<String, ToscaTemplateRequirement>> requirements;
+ private Map<String, ToscaTemplateCapability> capabilities;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+ public List<Map<String, ToscaTemplateRequirement>> getRequirements() {
+ return requirements;
+ }
+
+ public void setRequirements(List<Map<String, ToscaTemplateRequirement>> requirements) {
+ this.requirements = requirements;
+ }
+
+ public Map<String, ToscaTemplateCapability> getCapabilities() {
+ return capabilities;
+ }
+
+ public void setCapabilities(Map<String, ToscaTemplateCapability> capabilities) {
+ this.capabilities = capabilities;
+ }
+
+ public ToscaMetadata getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(ToscaMetadata metadata) {
+ this.metadata = metadata;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java
new file mode 100644
index 0000000000..df9070f49c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaNodeType {
+ public ToscaNodeType() {
+ }
+
+ private ToscaMetadata metadata;
+ private String derived_from;
+ private String description;
+
+ private Map<String, ToscaProperty> properties;
+ private Map<String, ToscaCapability> capabilities;
+
+ private List<Map<String, ToscaRequirement>> requirements;
+
+ public Map<String, ToscaProperty> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, ToscaProperty> properties) {
+ this.properties = properties;
+ }
+
+ public Map<String, ToscaCapability> getCapabilities() {
+ return capabilities;
+ }
+
+ public void setCapabilities(Map<String, ToscaCapability> capabilities) {
+ this.capabilities = capabilities;
+ }
+
+ public List<Map<String, ToscaRequirement>> getRequirements() {
+ return requirements;
+ }
+
+ public void setRequirements(List<Map<String, ToscaRequirement>> requirements) {
+ this.requirements = requirements;
+ }
+
+ public String getDerived_from() {
+ return derived_from;
+ }
+
+ public void setDerived_from(String derived_from) {
+ this.derived_from = derived_from;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public ToscaMetadata getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(ToscaMetadata metadata) {
+ this.metadata = metadata;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java
new file mode 100644
index 0000000000..8b5c60b1d4
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+public class ToscaProperty {
+
+ private String type;
+ private Object _defaultp_;
+ private String description;
+ private Boolean required;
+ private EntrySchema entry_schema;
+ private String status;
+
+ public EntrySchema getEntry_schema() {
+ return entry_schema;
+ }
+
+ public void setEntry_schema(EntrySchema entry_schema) {
+ this.entry_schema = entry_schema;
+ }
+
+ public ToscaProperty() {
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Object getDefaultp() {
+ return _defaultp_;
+ }
+
+ public void setDefaultp(Object defaultp) {
+ this._defaultp_ = defaultp;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Boolean getRequired() {
+ return required;
+ }
+
+ public void setRequired(Boolean required) {
+ this.required = required;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaRequirement.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaRequirement.java
new file mode 100644
index 0000000000..21fdc9f722
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaRequirement.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaRequirement extends ToscaTemplateRequirement {
+
+ private List<Object> occurrences;
+
+ public ToscaRequirement() {
+ }
+
+ public List<Object> getOccurrences() {
+ return occurrences;
+ }
+
+ public void setOccurrences(List<Object> occurrences) {
+ this.occurrences = occurrences;
+ }
+
+ public Map<String, Object> toMap() throws IllegalArgumentException, IllegalAccessException {
+ return super.toMap();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java
new file mode 100644
index 0000000000..e80d52167c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.tuple.Triple;
+import org.openecomp.sdc.be.model.Component;
+
+public class ToscaTemplate {
+ private String tosca_definitions_version;
+ private ToscaMetadata metadata;
+ private List<Map<String, Map<String, String>>> imports;
+ private Map<String, ToscaNodeType> node_types;
+ private ToscaTopolgyTemplate topology_template;
+
+ private List<Triple<String, String, Component>> dependencies;
+
+ public ToscaTemplate(String tosca_definitions_version) {
+ this.tosca_definitions_version = tosca_definitions_version;
+ }
+
+ public Map<String, ToscaNodeType> getNode_types() {
+ return node_types;
+ }
+
+ public void setNode_types(Map<String, ToscaNodeType> node_types) {
+ this.node_types = node_types;
+ }
+
+ public List<Map<String, Map<String, String>>> getImports() {
+ return imports;
+ }
+
+ public void setImports(List<Map<String, Map<String, String>>> imports) {
+ this.imports = imports;
+ }
+
+ public String getTosca_definitions_version() {
+ return tosca_definitions_version;
+ }
+
+ public void setTosca_definitions_version(String tosca_definitions_version) {
+ this.tosca_definitions_version = tosca_definitions_version;
+ }
+
+ public ToscaMetadata getMetadata() {
+ return metadata;
+ }
+
+ public void setMetadata(ToscaMetadata metadata) {
+ this.metadata = metadata;
+ }
+
+ public ToscaTopolgyTemplate getTopology_template() {
+ return topology_template;
+ }
+
+ public void setTopology_template(ToscaTopolgyTemplate topology_template) {
+ this.topology_template = topology_template;
+ }
+
+ public List<Triple<String, String, Component>> getDependencies() {
+ return dependencies;
+ }
+
+ public void setDependencies(List<Triple<String, String, Component>> dependencies) {
+ this.dependencies = dependencies;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateCapability.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateCapability.java
new file mode 100644
index 0000000000..9adb9edfe1
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateCapability.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+
+public class ToscaTemplateCapability {
+ private List<String> valid_source_types;
+ private Map<String, Object> properties;
+
+ public List<String> getValid_source_types() {
+ return valid_source_types;
+ }
+
+ public void setValid_source_types(List<String> valid_source_types) {
+ this.valid_source_types = valid_source_types;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirement.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirement.java
new file mode 100644
index 0000000000..71bae81f9c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplateRequirement.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ToscaTemplateRequirement {
+ private String capability;
+ private String node;
+ private String relationship;
+
+ public ToscaTemplateRequirement() {
+ }
+
+ public String getCapability() {
+ return capability;
+ }
+
+ public void setCapability(String capability) {
+ this.capability = capability;
+ }
+
+ public String getNode() {
+ return node;
+ }
+
+ public void setNode(String node) {
+ this.node = node;
+ }
+
+ public String getRelationship() {
+ return relationship;
+ }
+
+ public void setRelationship(String relationship) {
+ this.relationship = relationship;
+ }
+
+ public Map<String, Object> toMap() throws IllegalArgumentException, IllegalAccessException {
+ Map<String, Object> map = new HashMap<>();
+ Field[] fields = this.getClass().getDeclaredFields();
+ for (Field field : fields) {
+ field.setAccessible(true);
+ map.put(field.getName(), field.get(this));
+ }
+ return map;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTopolgyTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTopolgyTemplate.java
new file mode 100644
index 0000000000..6804bf6968
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTopolgyTemplate.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.Map;
+
+public class ToscaTopolgyTemplate {
+ private Map<String, ToscaProperty> inputs;
+ private Map<String, ToscaNodeTemplate> node_templates;
+ private Map<String, ToscaGroupTemplate> groups;
+ private SubstitutionMapping substitution_mappings;
+
+ public Map<String, ToscaNodeTemplate> getNode_templates() {
+ return node_templates;
+ }
+
+ public void setNode_templates(Map<String, ToscaNodeTemplate> node_templates) {
+ this.node_templates = node_templates;
+ }
+
+ public Map<String, ToscaGroupTemplate> getGroups() {
+ return groups;
+ }
+
+ public void setGroups(Map<String, ToscaGroupTemplate> groups) {
+ this.groups = groups;
+ }
+
+ public SubstitutionMapping getSubstitution_mappings() {
+ return substitution_mappings;
+ }
+
+ public void setSubstitution_mappings(SubstitutionMapping substitution_mapping) {
+ this.substitution_mappings = substitution_mapping;
+ }
+
+ public Map<String, ToscaProperty> getInputs() {
+ return inputs;
+ }
+
+ public void setInputs(Map<String, ToscaProperty> inputs) {
+ this.inputs = inputs;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/VfModuleToscaMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/VfModuleToscaMetadata.java
new file mode 100644
index 0000000000..5f978227ef
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/VfModuleToscaMetadata.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+public class VfModuleToscaMetadata implements IToscaMetadata {
+
+ private String vfModuleModelName;
+ private String vfModuleModelInvariantUUID;
+ private String vfModuleModelUUID;
+ private String vfModuleModelVersion;
+
+ @Override
+ public void setName(String name) {
+ vfModuleModelName = name;
+ }
+
+ @Override
+ public void setInvariantUUID(String invariantUUID) {
+ vfModuleModelInvariantUUID = invariantUUID;
+ }
+
+ @Override
+ public void setUUID(String uUID) {
+ vfModuleModelUUID = uUID;
+ }
+
+ @Override
+ public void setVersion(String version) {
+ vfModuleModelVersion = version;
+ }
+
+ public String getVfModuleModelName() {
+ return vfModuleModelName;
+ }
+
+ public String getVfModuleModelInvariantUUID() {
+ return vfModuleModelInvariantUUID;
+ }
+
+ public String getVfModuleModelUUID() {
+ return vfModuleModelUUID;
+ }
+
+ public String getVfModuleModelVersion() {
+ return vfModuleModelVersion;
+ }
+
+}