aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2018-02-18 11:52:25 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-03-15 09:14:51 +0000
commit704247137bdba671e55c0ebde7e226fff422b608 (patch)
treead4124c20d60e37917376ebca977ac8f04cb2ec8 /openecomp-be/lib
parent9c40f569b817e0886d95ad8b1ac235d8644873da (diff)
Change Tosca structure
change Tosca Service Template according to Tosca-spec-1.1 Change-Id: I8f689b02e0349fc8c787868661f498d7d530d445 Issue-ID: SDC-1043 Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java73
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java48
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java49
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceObjectErrorBuilder.java24
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceOperationObjectErrorBuilder.java22
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaErrorCodes.java3
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidInterfaceValueErrorBuilder.java21
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java155
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java174
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml12
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml109
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml112
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml112
13 files changed, 800 insertions, 114 deletions
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
index 25c89e1270..18750e4d0a 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,6 +20,8 @@
package org.openecomp.sdc.common.utils;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -39,12 +41,16 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class CommonUtil {
+ private static final String DEFAULT = "default";
+ private static final String _DEFAULT = "_default";
private CommonUtil() {
// prevent instantiation
@@ -53,37 +59,37 @@ public class CommonUtil {
public static FileContentHandler validateAndUploadFileContent(OnboardingTypesEnum type,
byte[] uploadedFileData)
throws IOException {
- return getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders(type, uploadedFileData);
+ return getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders(type,
+ uploadedFileData);
}
/**
* Gets files out of the zip AND validates zip is flat (no folders)
*
- *
- * @param type
* @param uploadFileData zip file
* @return FileContentHandler if input is valid and has no folders
*/
private static FileContentHandler getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders(
OnboardingTypesEnum type, byte[] uploadFileData)
throws IOException {
- Pair<FileContentHandler,List<String> > pair = getFileContentMapFromOrchestrationCandidateZip(uploadFileData);
+ Pair<FileContentHandler, List<String>> pair =
+ getFileContentMapFromOrchestrationCandidateZip(uploadFileData);
- if(isFileOriginFromZip(type.toString())) {
+ if (isFileOriginFromZip(type.toString())) {
validateNoFolders(pair.getRight());
}
return pair.getLeft();
}
- public static Pair<FileContentHandler,List<String> > getFileContentMapFromOrchestrationCandidateZip(
- byte[] uploadFileData)
- throws IOException {
+ public static Pair<FileContentHandler, List<String>> getFileContentMapFromOrchestrationCandidateZip(
+ byte[] uploadFileData)
+ throws IOException {
ZipEntry zipEntry;
List<String> folderList = new ArrayList<>();
FileContentHandler mapFileContent = new FileContentHandler();
- try ( ByteArrayInputStream in = new ByteArrayInputStream(uploadFileData);
- ZipInputStream inputZipStream = new ZipInputStream(in)){
+ try (ByteArrayInputStream in = new ByteArrayInputStream(uploadFileData);
+ ZipInputStream inputZipStream = new ZipInputStream(in)) {
byte[] fileByteContent;
String currentEntryName;
@@ -93,10 +99,10 @@ public class CommonUtil {
fileByteContent = FileUtils.toByteArray(inputZipStream);
int index = lastIndexFileSeparatorIndex(currentEntryName);
- if (index != -1) { //todo ?
+ if (index != -1) {
folderList.add(currentEntryName);
}
- if(isFile(currentEntryName)) {
+ if (isFile(currentEntryName)) {
mapFileContent.addFile(currentEntryName, fileByteContent);
}
}
@@ -105,7 +111,7 @@ public class CommonUtil {
throw new IOException(exception);
}
- return new ImmutablePair<>(mapFileContent,folderList);
+ return new ImmutablePair<>(mapFileContent, folderList);
}
private static boolean isFile(String currentEntryName) {
@@ -149,8 +155,41 @@ public class CommonUtil {
return validateFilesExtensions(allowedExtensions, files);
}
- public static boolean isFileOriginFromZip(String fileOrigin){
- return Objects.nonNull(fileOrigin)
+ public static boolean isFileOriginFromZip(String fileOrigin) {
+ return Objects.nonNull(fileOrigin)
&& fileOrigin.equalsIgnoreCase(OnboardingTypesEnum.ZIP.toString());
}
+
+ public static Set<String> getClassFieldNames(Class<? extends Object> classType) {
+ Set<String> fieldNames = new HashSet<>();
+ Arrays.stream(classType.getDeclaredFields()).forEach(field -> fieldNames.add(field.getName()));
+
+ return fieldNames;
+ }
+
+ public static <T> Optional<T> createObjectUsingSetters(Object objectCandidate,
+ Class<T> classToCreate)
+ throws Exception {
+ if (Objects.isNull(objectCandidate)) {
+ return Optional.empty();
+ }
+
+ Map<String, Object> objectAsMap = getObjectAsMap(objectCandidate);
+ T result = classToCreate.newInstance();
+ BeanUtils.populate(result, objectAsMap);
+
+ return Optional.of(result);
+ }
+
+ public static Map<String, Object> getObjectAsMap(Object obj) {
+ Map<String, Object> objectAsMap = obj instanceof Map ? (Map<String, Object>) obj
+ : new ObjectMapper().convertValue(obj, Map.class);
+
+ if (objectAsMap.containsKey(DEFAULT)) {
+ Object defaultValue = objectAsMap.get(DEFAULT);
+ objectAsMap.remove(DEFAULT);
+ objectAsMap.put(_DEFAULT, defaultValue);
+ }
+ return objectAsMap;
+ }
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
index f8b9f75b8f..e9a8f58426 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
@@ -436,36 +436,24 @@ public class ToscaConverterImpl implements ToscaConverter {
return CsarFileTypes.externalFile;
}
- private Optional<Manifest> getCsarManifest(Map<String, byte[]> csarFiles) throws IOException {
- Optional<byte[]> manifestContent = getManifestContent(csarFiles);
-
- if (manifestContent.isPresent()) {
- ByteArrayInputStream byteInputStream = new ByteArrayInputStream(manifestContent.get());
-
- return Optional.of(new Manifest(byteInputStream));
- }
-
- return Optional.empty();
- }
-
- private NodeTemplate convertNodeTemplate(Object candidateNodeTemplate) {
- NodeTemplate nodeTemplate = new NodeTemplate();
-
- Map<String, Object> nodeTemplateAsMap = (Map<String, Object>) candidateNodeTemplate;
- nodeTemplate.setArtifacts((Map<String, ArtifactDefinition>) nodeTemplateAsMap.get("artifacts"));
- nodeTemplate.setAttributes((Map<String, Object>) nodeTemplateAsMap.get("attributes"));
- nodeTemplate.setCopy((String) nodeTemplateAsMap.get("copy"));
- nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description"));
- nodeTemplate.setDirectives((List<String>) nodeTemplateAsMap.get("directives"));
- nodeTemplate.setInterfaces(
- (Map<String, InterfaceDefinition>) nodeTemplateAsMap.get("interfaces"));
- nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter"));
- nodeTemplate.setProperties((Map<String, Object>) nodeTemplateAsMap.get("properties"));
- nodeTemplate.setRequirements(
- (List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements"));
- nodeTemplate.setType((String) nodeTemplateAsMap.get("type"));
- nodeTemplate.setCapabilities(
- convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities")));
+ private NodeTemplate convertNodeTemplate(Object candidateNodeTemplate) {
+ NodeTemplate nodeTemplate = new NodeTemplate();
+
+ Map<String, Object> nodeTemplateAsMap = (Map<String, Object>) candidateNodeTemplate;
+ nodeTemplate.setArtifacts((Map<String, ArtifactDefinition>) nodeTemplateAsMap.get("artifacts"));
+ nodeTemplate.setAttributes((Map<String, Object>) nodeTemplateAsMap.get("attributes"));
+ nodeTemplate.setCopy((String) nodeTemplateAsMap.get("copy"));
+ nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description"));
+ nodeTemplate.setDirectives((List<String>) nodeTemplateAsMap.get("directives"));
+ nodeTemplate.setInterfaces(
+ (Map<String, Object>) nodeTemplateAsMap.get("interfaces"));
+ nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter"));
+ nodeTemplate.setProperties((Map<String, Object>) nodeTemplateAsMap.get("properties"));
+ nodeTemplate.setRequirements(
+ (List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements"));
+ nodeTemplate.setType((String) nodeTemplateAsMap.get("type"));
+ nodeTemplate.setCapabilities(
+ convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities")));
return nodeTemplate;
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
index 802827e343..2236622222 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java
@@ -17,13 +17,12 @@
package org.openecomp.core.impl;
import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
import org.openecomp.core.converter.errors.CreateToscaObjectErrorBuilder;
import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.utils.CommonUtil;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
@@ -34,13 +33,10 @@ import java.util.stream.Stream;
public class ToscaConverterUtil {
- private static final String SET = "set";
private static final String DEFAULT = "default";
private static final String DEFAULT_CAPITAL = "Default";
private static final Set<String> DEFAULT_VALUE_KEYS;
- private static final Logger LOGGER = LoggerFactory.getLogger(ToscaConverterUtil.class);
-
static {
DEFAULT_VALUE_KEYS =
Stream.of(DEFAULT, DEFAULT_CAPITAL).collect(Collectors.toSet());
@@ -50,11 +46,11 @@ public class ToscaConverterUtil {
// static utility methods only, prevent instantiation
}
- public static <T> Optional<T> createObjectFromClass(String objectId,
+ static <T> Optional<T> createObjectFromClass(String objectId,
Object objectCandidate,
Class<T> classToCreate) {
try {
- return createObjectUsingSetters(objectCandidate, classToCreate);
+ return CommonUtil.createObjectUsingSetters(objectCandidate, classToCreate);
} catch (Exception ex) {
throw new CoreException(
new CreateToscaObjectErrorBuilder(classToCreate.getSimpleName(), objectId)
@@ -62,45 +58,8 @@ public class ToscaConverterUtil {
}
}
- private static <T> Optional<T> createObjectUsingSetters(Object objectCandidate,
- Class<T> classToCreate)
- throws ReflectiveOperationException {
- if (Objects.isNull(objectCandidate)
- || !(objectCandidate instanceof Map)) {
- return Optional.empty();
- }
-
- Map<String, Object> objectAsMap = (Map<String, Object>) objectCandidate;
- Field[] classFields = classToCreate.getDeclaredFields();
- T result = classToCreate.newInstance();
-
- for (Field field : classFields) {
- Object fieldValueToAssign = objectAsMap.get(field.getName());
- String methodName = SET + StringUtils.capitalize(field.getName());
-
- if(shouldSetterMethodNeedsToGetInvoked(classToCreate, field, fieldValueToAssign, methodName)) {
- classToCreate.getMethod(methodName, field.getType()).invoke(result, fieldValueToAssign);
- }
- }
-
- return Optional.of(result);
- }
- private static <T> boolean shouldSetterMethodNeedsToGetInvoked(Class<T> classToCreate,
- Field field,
- Object fieldValueToAssign,
- String methodName) {
-
- try {
- return Objects.nonNull(fieldValueToAssign)
- && Objects.nonNull(classToCreate.getMethod(methodName, field.getType()));
- } catch (NoSuchMethodException e) {
- LOGGER.debug(String.format("Could not extract method '%s' from class '%s'. returning false " +
- "with filedType '%s'.", methodName, classToCreate, field.getType()), e);
- return false;
- }
- }
- public static Optional<Object> getDefaultValue(Object entryValue,
+ static Optional<Object> getDefaultValue(Object entryValue,
Object objectToAssignDefaultValue) {
if (!(entryValue instanceof Map)
|| Objects.isNull(objectToAssignDefaultValue)) {
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceObjectErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceObjectErrorBuilder.java
new file mode 100644
index 0000000000..9eb2a4d5b2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceObjectErrorBuilder.java
@@ -0,0 +1,24 @@
+package org.openecomp.sdc.tosca.errors;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+
+public class CreateInterfaceObjectErrorBuilder {
+
+ private static final String COULD_NOT_CREATE_OBJECT_MSG =
+ "Could not create %s from %s. Reason - %s";
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+
+ public CreateInterfaceObjectErrorBuilder(String interfaceClassName,
+ String interfaceId,
+ String reason) {
+ builder.withId(ToscaErrorCodes.INVALID_INTERFACE_VALUE);
+ builder.withCategory(ErrorCategory.APPLICATION);
+ builder.withMessage(
+ String.format(COULD_NOT_CREATE_OBJECT_MSG, interfaceClassName, interfaceId, reason));
+ }
+
+ public ErrorCode build() {
+ return builder.build();
+ }
+}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceOperationObjectErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceOperationObjectErrorBuilder.java
new file mode 100644
index 0000000000..83ead4fe66
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/CreateInterfaceOperationObjectErrorBuilder.java
@@ -0,0 +1,22 @@
+package org.openecomp.sdc.tosca.errors;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+
+public class CreateInterfaceOperationObjectErrorBuilder {
+ private static final String COULD_NOT_CREATE_OBJECT_MSG =
+ "Could not create Operation from %s. Reason - %s";
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+
+ public CreateInterfaceOperationObjectErrorBuilder(String operationId,
+ String reason) {
+ builder.withId(ToscaErrorCodes.INVALID_INTERFACE_VALUE);
+ builder.withCategory(ErrorCategory.APPLICATION);
+ builder.withMessage(
+ String.format(COULD_NOT_CREATE_OBJECT_MSG, operationId, reason));
+ }
+
+ public ErrorCode build() {
+ return builder.build();
+ }
+}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaErrorCodes.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaErrorCodes.java
index 099f0771f2..2e449e4acc 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaErrorCodes.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaErrorCodes.java
@@ -20,7 +20,7 @@
package org.openecomp.sdc.tosca.errors;
-public class ToscaErrorCodes {
+class ToscaErrorCodes {
static final String INVALID_SUBSTITUTE_NODE_TEMPLATE = "INVALID_SUBSTITUTE_NODE_TEMPLATE";
static final String INVALID_SUBSTITUTION_SERVICE_TEMPLATE =
@@ -31,6 +31,7 @@ public class ToscaErrorCodes {
static final String TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE =
"TOSCA_INVALID_SUBSTITUTE_NODE_TEMPLATE";
static final String TOSCA_INVALID_ADD_ACTION_NULL_ENTITY = "TOSCA_INVALID_ADD_ACTION_NULL_ENTITY";
+ static final String INVALID_INTERFACE_VALUE = "INVALID_INTERFACE_VALUE";
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidInterfaceValueErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidInterfaceValueErrorBuilder.java
new file mode 100644
index 0000000000..09b36a083c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/errors/ToscaInvalidInterfaceValueErrorBuilder.java
@@ -0,0 +1,21 @@
+package org.openecomp.sdc.tosca.errors;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+
+public class ToscaInvalidInterfaceValueErrorBuilder {
+
+ private static final String INVALID_INTERFACE_MSG =
+ "Cannot create interface object. reason - %s";
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+
+ public ToscaInvalidInterfaceValueErrorBuilder(String reason) {
+ builder.withId(ToscaErrorCodes.INVALID_INTERFACE_VALUE);
+ builder.withCategory(ErrorCategory.APPLICATION);
+ builder.withMessage(String.format(INVALID_INTERFACE_MSG, reason));
+ }
+
+ public ErrorCode build() {
+ return builder.build();
+ }
+}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
index 8da2fc8c54..aef23be03f 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
@@ -20,10 +20,13 @@
package org.openecomp.sdc.tosca.services;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.utils.CommonUtil;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
@@ -36,8 +39,11 @@ import org.openecomp.sdc.tosca.datatypes.model.Constraint;
import org.openecomp.sdc.tosca.datatypes.model.EntrySchema;
import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition;
import org.openecomp.sdc.tosca.datatypes.model.Import;
+import org.openecomp.sdc.tosca.datatypes.model.InterfaceDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.InterfaceType;
import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.OperationDefinition;
import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
import org.openecomp.sdc.tosca.datatypes.model.PolicyDefinition;
import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
@@ -49,8 +55,11 @@ import org.openecomp.sdc.tosca.datatypes.model.Status;
import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping;
import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate;
import org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
+import org.openecomp.sdc.tosca.errors.CreateInterfaceObjectErrorBuilder;
+import org.openecomp.sdc.tosca.errors.CreateInterfaceOperationObjectErrorBuilder;
import org.openecomp.sdc.tosca.errors.InvalidAddActionNullEntityErrorBuilder;
import org.openecomp.sdc.tosca.errors.InvalidRequirementAssignmentErrorBuilder;
+import org.openecomp.sdc.tosca.errors.ToscaInvalidInterfaceValueErrorBuilder;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
import java.io.ByteArrayInputStream;
@@ -67,6 +76,7 @@ import java.util.ListIterator;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+import java.util.Set;
/**
* The type Data model util.
@@ -83,6 +93,7 @@ public class DataModelUtil {
private static final Logger logger = LoggerFactory.getLogger(DataModelUtil.class);
private static final String SERVICE_TEMPLATE = "Service Template";
private static final String NODE_TYPE = "Node Type";
+ private static final String OPERATIONS = "operations";
/**
* Add substitution mapping.
@@ -1162,6 +1173,150 @@ public class DataModelUtil {
return capabilityMapping;
}
+
+ public static void addInterfaceOperation(ServiceTemplate serviceTemplate,
+ String interfaceId,
+ String operationId,
+ OperationDefinition operationDefinition) {
+ Map<String, Object> interfaceTypes = serviceTemplate.getInterface_types();
+ if (MapUtils.isEmpty(interfaceTypes)
+ || Objects.isNull(interfaceTypes.get(interfaceId))) {
+ return;
+ }
+
+ Object interfaceObject = interfaceTypes.get(interfaceId);
+ Map<String, Object> interfaceAsMap = CommonUtil.getObjectAsMap(interfaceObject);
+ interfaceAsMap.put(operationId, operationDefinition);
+ }
+
+ public static Map<String, InterfaceType> getInterfaceTypes(ServiceTemplate serviceTemplate) {
+ Map<String, Object> interfaceTypes = serviceTemplate.getInterface_types();
+
+ if (MapUtils.isEmpty(interfaceTypes)) {
+ return new HashMap<>();
+ }
+
+ Map<String, InterfaceType> convertedInterfaceTypes = new HashMap<>();
+ for (Map.Entry<String, Object> interfaceEntry : interfaceTypes.entrySet()) {
+ try {
+ Optional<InterfaceType> interfaceType =
+ convertObjToInterfaceType(interfaceEntry.getKey(), interfaceEntry.getValue());
+ interfaceType.ifPresent(
+ interfaceValue -> convertedInterfaceTypes.put(interfaceEntry.getKey(), interfaceValue));
+ } catch (Exception e) {
+ throw new CoreException(
+ new ToscaInvalidInterfaceValueErrorBuilder(e.getMessage()).build());
+ }
+ }
+
+ return convertedInterfaceTypes;
+ }
+
+ public static Optional<InterfaceDefinition> convertObjToInterfaceDefinition(
+ String interfaceId, Object interfaceObj)
+ throws CoreException {
+
+ try {
+ Optional<InterfaceDefinition> interfaceDefinition =
+ CommonUtil.createObjectUsingSetters(interfaceObj, InterfaceDefinition.class);
+ interfaceDefinition.ifPresent(interfaceDefinition1 -> updateInterfaceDefinitionOperations(
+ CommonUtil.getObjectAsMap(interfaceObj),
+ interfaceDefinition1));
+ return interfaceDefinition;
+ } catch (Exception ex) {
+ throw new CoreException(
+ new CreateInterfaceObjectErrorBuilder(InterfaceDefinition.class.getName(), interfaceId,
+ ex.getMessage()).build());
+ }
+
+ }
+
+ public static Optional<Object> convertInterfaceDefinitionToObj(
+ InterfaceDefinition interfaceDefinition) {
+ return converInetrfaceToToscaInterfaceObj(interfaceDefinition);
+ }
+
+ public static Optional<InterfaceType> convertObjToInterfaceType(String interfaceId,
+ Object interfaceObj)
+ throws CoreException {
+ try {
+ Optional<InterfaceType> interfaceType =
+ CommonUtil.createObjectUsingSetters(interfaceObj, InterfaceType.class);
+ interfaceType.ifPresent(
+ interfaceType1 -> updateInterfaceTypeOperations(CommonUtil.getObjectAsMap(interfaceObj),
+ interfaceType1));
+ return interfaceType;
+ } catch (Exception ex) {
+ throw new CoreException(
+ new CreateInterfaceObjectErrorBuilder(InterfaceType.class.getName(), interfaceId,
+ ex.getMessage()).build());
+ }
+ }
+
+ public static Optional<Object> convertInterfaceTypeToObj(InterfaceType interfaceType) {
+ return converInetrfaceToToscaInterfaceObj(interfaceType);
+ }
+
+ private static Optional<Object> converInetrfaceToToscaInterfaceObj(Object interfaceEntity) {
+ if (Objects.isNull(interfaceEntity)) {
+ return Optional.empty();
+ }
+
+ Map<String, Object> interfaceAsMap = CommonUtil.getObjectAsMap(interfaceEntity);
+ Map<String, Object> operations = (Map<String, Object>) interfaceAsMap.get(OPERATIONS);
+ if (MapUtils.isNotEmpty(operations)) {
+ interfaceAsMap.remove(OPERATIONS);
+ interfaceAsMap.putAll(operations);
+ }
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
+ return Optional.of(objectMapper.convertValue(interfaceAsMap, Object.class));
+ }
+
+ private static void updateInterfaceTypeOperations(Map<String, Object> interfaceAsMap,
+ InterfaceType interfaceType) {
+
+ Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceType.class);
+
+ for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
+ Optional<OperationDefinition> operationDefinition =
+ createOperation(entry.getKey(), entry.getValue(), fieldNames);
+ operationDefinition
+ .ifPresent(operation -> interfaceType.addOperation(entry.getKey(), operation));
+ }
+ }
+
+ private static Optional<OperationDefinition> createOperation(String propertyName,
+ Object operationCandidate,
+ Set<String> fieldNames)
+ throws CoreException {
+ if (!fieldNames.contains(propertyName)) {
+ try {
+ return CommonUtil.createObjectUsingSetters(operationCandidate, OperationDefinition.class);
+ } catch (Exception ex) {
+ throw new CoreException(
+ new CreateInterfaceOperationObjectErrorBuilder(propertyName, ex.getMessage()).build());
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ private static void updateInterfaceDefinitionOperations(Map<String, Object> interfaceAsMap,
+ InterfaceDefinition interfaceDefinition) {
+
+ Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceDefinition.class);
+
+ for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
+ Optional<OperationDefinition> operationDefinition =
+ createOperation(entry.getKey(), entry.getValue(), fieldNames);
+ operationDefinition
+ .ifPresent(operation -> interfaceDefinition.addOperation(entry.getKey(), operation));
+
+ }
+ }
+
public static void addSubstitutionNodeTypeRequirements(NodeType substitutionNodeType,
List<Map<String, RequirementDefinition>>
requirementsList,
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
index 60f59dbd81..31dc3ab035 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
@@ -29,9 +29,12 @@ import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
import org.openecomp.sdc.tosca.datatypes.model.Constraint;
import org.openecomp.sdc.tosca.datatypes.model.Directive;
import org.openecomp.sdc.tosca.datatypes.model.Import;
+import org.openecomp.sdc.tosca.datatypes.model.InterfaceDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.InterfaceType;
import org.openecomp.sdc.tosca.datatypes.model.NodeFilter;
import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.OperationDefinition;
import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
@@ -52,13 +55,23 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
public class ToscaModelTest {
+ private YamlUtil yamlUtil = new YamlUtil();
+ private static final String INTERFACE_ID = "inter_1";
+ private static final String NODE_TEMPLATE_ID = "firstNodeTemplate";
+ private static final String BASE_DIR = "/mock/model";
+ private static final String ST = "/serviceTemplate.yaml";
+ private static final String ST_WITH_INTERFACE = "/serviceTemplateWithInterface.yaml";
+ private static final String ST_WITH_OPERATIONS = "/serviceTemplateWithInterfaceAndOperation.yaml";
+ private static final String ST_WITH_INTERFACE_DEF =
+ "/serviceTemplateWithNodeTemplateInterface.yaml";
+
@Test
public void testServiceTemplateJavaToYaml() {
-
ServiceTemplate serviceTemplate = new ServiceTemplate();
Map<String, String> metadata = new HashMap<>();
metadata.put("Template_author", "OPENECOMP");
@@ -80,6 +93,14 @@ public class ToscaModelTest {
imports.add(importsMap);
serviceTemplate.setImports(imports);
+ OperationDefinition operationDefinition = new OperationDefinition();
+ operationDefinition.setDescription("test operation");
+ InterfaceType interfaceType = new InterfaceType();
+ interfaceType.setDerived_from("derived_from");
+ interfaceType.setDescription("desc");
+ interfaceType.addOperation("test", operationDefinition);
+ serviceTemplate.addInterfaceType("test_interface", interfaceType);
+
ArtifactType artifact = new ArtifactType();
artifact.setMime_type("application/java-archive");
ArrayList<String> ext = new ArrayList<>();
@@ -272,30 +293,163 @@ public class ToscaModelTest {
@Test
public void testYamlToServiceTemplateObj() throws IOException {
- try (InputStream yamlFile = new YamlUtil().loadYamlFileIs("/mock/model/serviceTemplate.yaml")) {
- ServiceTemplate serviceTemplateFromYaml =
- new YamlUtil().yamlToObject(yamlFile, ServiceTemplate.class);
- Assert.assertNotNull(serviceTemplateFromYaml);
- }
+ ServiceTemplate serviceTemplateFromYaml =
+ getServiceTemplate(BASE_DIR + ST);
+ Assert.assertNotNull(serviceTemplateFromYaml);
}
+ @Test
+ public void testYamlWithInterfaceToServiceTemplateObj() throws IOException {
+ ServiceTemplate serviceTemplateWithOperation =
+ getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
+ Assert.assertNotNull(serviceTemplateWithOperation);
+
+ InterfaceType expectedInterfaceType = getInterfaceType();
+
+ Map<String, InterfaceType> interfaceTypes =
+ DataModelUtil.getInterfaceTypes(serviceTemplateWithOperation);
+ Assert.assertEquals(1, interfaceTypes.size());
+ InterfaceType actualInterfaceType = interfaceTypes.get(INTERFACE_ID);
+ Assert.assertEquals(expectedInterfaceType, actualInterfaceType);
+ }
+
+ @Test
+ public void testAddOperationToInterface() throws IOException {
+ YamlUtil yamlUtil = new YamlUtil();
+ ServiceTemplate serviceTemplateWithInterface =
+ getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE);
+ ServiceTemplate serviceTemplateWithOperation =
+ getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
+
+ OperationDefinition operationDefinition = getOperationDefinition();
+
+ DataModelUtil
+ .addInterfaceOperation(serviceTemplateWithInterface, INTERFACE_ID, "start",
+ operationDefinition);
+ String expectedServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithOperation);
+ String actualServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithInterface);
+ Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate);
+ }
+
+ @Test
+ public void testInterfaceTypeToObjConversion() throws IOException {
+ ServiceTemplate serviceTemplateWithInterface =
+ getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE);
+ ServiceTemplate serviceTemplateWithOperation =
+ getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
+ InterfaceType interfaceType = getInterfaceType();
+
+ Optional<Object> interfaceAsObj = DataModelUtil.convertInterfaceTypeToObj(interfaceType);
+ Assert.assertTrue(interfaceAsObj.isPresent());
+
+ Map<String, Object> interfaceTypes = new HashMap<>();
+ interfaceTypes.put(INTERFACE_ID, interfaceAsObj.get());
+ serviceTemplateWithInterface.setInterface_types(interfaceTypes);
+
+ String expectedServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithOperation);
+ String actualServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithInterface);
+ Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate);
+ }
+
+ @Test
+ public void testObjToInterfaceTypeConversion() throws IOException, ReflectiveOperationException {
+ ServiceTemplate serviceTemplateWithOperation =
+ getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
+ Map<String, Object> interfaceTypes = serviceTemplateWithOperation.getInterface_types();
+ Object interfaceObj = interfaceTypes.get(INTERFACE_ID);
+ Optional<InterfaceType> actualInterfaceType =
+ DataModelUtil.convertObjToInterfaceType(INTERFACE_ID, interfaceObj);
+
+ Assert.assertTrue(actualInterfaceType.isPresent());
+ InterfaceType expectedInterfaceType = getInterfaceType();
+ Assert.assertEquals(expectedInterfaceType, actualInterfaceType.get());
+ }
+
+ @Test
+ public void testInterfaceDefinitionToObjConversion() throws IOException {
+ ServiceTemplate serviceTemplate =
+ getServiceTemplate(BASE_DIR + ST);
+ ServiceTemplate serviceTemplateWithInterfaceDef =
+ getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE_DEF);
+
+ NodeTemplate nodeTemplate =
+ DataModelUtil.getNodeTemplate(serviceTemplate, NODE_TEMPLATE_ID);
+ InterfaceDefinition interfaceDefinition = getInterfaceDefinition();
+ Optional<Object> interfaceObj = DataModelUtil.convertInterfaceDefinitionToObj(interfaceDefinition);
+
+ Assert.assertTrue(interfaceObj.isPresent());
+ Map<String, Object> interfaces = new HashMap<>();
+ interfaces.put(INTERFACE_ID, interfaceObj.get());
+ nodeTemplate.setInterfaces(interfaces);
+
+ String expectedServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithInterfaceDef);
+ String actualServiceTemplate = yamlUtil.objectToYaml(serviceTemplate);
+ Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate);
+ }
+
+ @Test
+ public void testObjToInterfaceDefinitionConversion()
+ throws IOException, ReflectiveOperationException {
+ ServiceTemplate serviceTemplateWithInterfaceDef =
+ getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE_DEF);
+ NodeTemplate nodeTemplateWithInterface =
+ DataModelUtil.getNodeTemplate(serviceTemplateWithInterfaceDef, NODE_TEMPLATE_ID);
+ Map<String, Object> interfaces = nodeTemplateWithInterface.getInterfaces();
+ Object interfaceObj = interfaces.get(INTERFACE_ID);
+ Optional<InterfaceDefinition> actualInterfaceDefinition =
+ DataModelUtil.convertObjToInterfaceDefinition(INTERFACE_ID, interfaceObj);
+
+ Assert.assertTrue(actualInterfaceDefinition.isPresent());
+
+ InterfaceDefinition expectedInterfaceDefinition = getInterfaceDefinition();
+ Assert.assertEquals(expectedInterfaceDefinition, actualInterfaceDefinition.get());
+ }
@Test
public void testYamlToServiceTemplateIncludingHeatExtend() throws IOException {
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
try (InputStream yamlFile =
- toscaExtensionYamlUtil.loadYamlFileIs("/mock/model/serviceTemplateHeatExtend.yaml")) {
+ toscaExtensionYamlUtil.loadYamlFileIs(BASE_DIR + "/serviceTemplateHeatExtend.yaml")) {
ServiceTemplate serviceTemplateFromYaml =
- toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
+ toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
ParameterDefinitionExt parameterDefinitionExt =
- (ParameterDefinitionExt) serviceTemplateFromYaml.getTopology_template().getInputs()
- .get("inParam1");
+ (ParameterDefinitionExt) serviceTemplateFromYaml.getTopology_template().getInputs()
+ .get("inParam1");
Assert.assertNotNull(parameterDefinitionExt.getLabel());
String backToYamlString = toscaExtensionYamlUtil.objectToYaml(serviceTemplateFromYaml);
Assert.assertNotNull(backToYamlString);
}
}
+ private ServiceTemplate getServiceTemplate(String inputPath) throws IOException {
+ try (InputStream yamlFile = yamlUtil.loadYamlFileIs(inputPath)) {
+ return yamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
+ }
+ }
+
+ private InterfaceType getInterfaceType() {
+ OperationDefinition operationDefinition = getOperationDefinition();
+ InterfaceType interfaceType = new InterfaceType();
+ interfaceType.setDescription("test interface");
+ interfaceType.addOperation("start", operationDefinition);
+ return interfaceType;
+ }
+
+ private OperationDefinition getOperationDefinition() {
+ OperationDefinition operationDefinition = new OperationDefinition();
+ operationDefinition.setDescription("start operation");
+ operationDefinition.setImplementation("start.sh");
+ return operationDefinition;
+ }
+
+ private InterfaceDefinition getInterfaceDefinition() {
+ OperationDefinition operationDefinition = getOperationDefinition();
+ InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType("test interface");
+ interfaceDefinition.addOperation("start", operationDefinition);
+ return interfaceDefinition;
+ }
+
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml
index c49f30f97b..a2bc15ea19 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml
@@ -68,7 +68,7 @@ topology_template:
entry_schema:
type: tosca.myType
node_templates:
- firatNodeTemplate:
+ firstNodeTemplate:
type: nodeTypeRef
directives:
- selectable
@@ -98,16 +98,6 @@ topology_template:
capability: capA
node: nodeA
relationship: relationB
- capabilities:
- cap1:
- properties:
- num_cpus: '{ get_input: cpus }'
- attributes:
- num_cpus: '66'
- node_filter:
- properties:
- test1:
- - equal: 1 MB
substitution_mappings:
node_type: myNodeType.node
capabilities:
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml
new file mode 100644
index 0000000000..46d61079a2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml
@@ -0,0 +1,109 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: Test
+ template_author: OPENECOMP
+ template_version: 1.0.0
+description: testing desc tosca service template
+imports:
+- myfile1:
+ file: path1/path2/file1.yaml
+- myfile2:
+ file: path1/path2/file2.yaml
+artifact_types:
+ one_artifact:
+ mime_type: application/java-archive
+ file_ext:
+ - yaml
+ - xml
+interface_types:
+ inter_1:
+ description: test interface
+node_types:
+ compute_node_type:
+ derived_from: tosca.nodes.Root
+ version: 1.0.0
+ description: tosca compute test
+ properties:
+ cpu_num:
+ type: integer
+ description: Number of CPUs requested for a software node instance
+ required: true
+ default: 1
+ status: SUPPORTED
+ constraints:
+ - greater_or_equal: 5.0
+ - equal: 5
+ - greater_than: 6.02
+ - in_range:
+ - 0
+ - UNBOUNDED
+ attributes:
+ attDef1:
+ type: string
+ default: hi
+ status: SUPPORTED
+ requirements:
+ - re1:
+ capability: tosca.cap1
+ occurrences:
+ - 5
+ - 1
+ capabilities:
+ cap1:
+ type: tosca.cap
+ valid_source_types:
+ - node1
+ - node2
+ occurrences:
+ - 1
+ - UNBOUNDED
+topology_template:
+ description: topologi template descroption
+ inputs:
+ inParam1:
+ type: string
+ description: desc
+ required: false
+ default: my default val
+ constraints:
+ - greater_than: 6
+ - greater_or_equal: 9
+ entry_schema:
+ type: tosca.myType
+ node_templates:
+ firstNodeTemplate:
+ type: nodeTypeRef
+ directives:
+ - selectable
+ - substitutable
+ properties:
+ prop2: '{ get_input: my_mysql_rootpw }'
+ prop1: abcd
+ attributes:
+ att2: '{ get_input: my_mysql_rootpw }'
+ att1: att1Val
+ requirements:
+ - req1:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ node_filter:
+ properties:
+ propName1:
+ - greater_or_equal: 9
+ propName2:
+ - min_length: 1
+ - max_length: 2
+ occurrences:
+ - 1
+ - 2
+ - req2:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ substitution_mappings:
+ node_type: myNodeType.node
+ capabilities:
+ database_endpoint:
+ - database
+ - database_endpoint
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml
new file mode 100644
index 0000000000..90376b7205
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml
@@ -0,0 +1,112 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: Test
+ template_author: OPENECOMP
+ template_version: 1.0.0
+description: testing desc tosca service template
+imports:
+- myfile1:
+ file: path1/path2/file1.yaml
+- myfile2:
+ file: path1/path2/file2.yaml
+artifact_types:
+ one_artifact:
+ mime_type: application/java-archive
+ file_ext:
+ - yaml
+ - xml
+interface_types:
+ inter_1:
+ description: test interface
+ start:
+ description: start operation
+ implementation: start.sh
+node_types:
+ compute_node_type:
+ derived_from: tosca.nodes.Root
+ version: 1.0.0
+ description: tosca compute test
+ properties:
+ cpu_num:
+ type: integer
+ description: Number of CPUs requested for a software node instance
+ required: true
+ default: 1
+ status: SUPPORTED
+ constraints:
+ - greater_or_equal: 5.0
+ - equal: 5
+ - greater_than: 6.02
+ - in_range:
+ - 0
+ - UNBOUNDED
+ attributes:
+ attDef1:
+ type: string
+ default: hi
+ status: SUPPORTED
+ requirements:
+ - re1:
+ capability: tosca.cap1
+ occurrences:
+ - 5
+ - 1
+ capabilities:
+ cap1:
+ type: tosca.cap
+ valid_source_types:
+ - node1
+ - node2
+ occurrences:
+ - 1
+ - UNBOUNDED
+topology_template:
+ description: topologi template descroption
+ inputs:
+ inParam1:
+ type: string
+ description: desc
+ required: false
+ default: my default val
+ constraints:
+ - greater_than: 6
+ - greater_or_equal: 9
+ entry_schema:
+ type: tosca.myType
+ node_templates:
+ firstNodeTemplate:
+ type: nodeTypeRef
+ directives:
+ - selectable
+ - substitutable
+ properties:
+ prop2: '{ get_input: my_mysql_rootpw }'
+ prop1: abcd
+ attributes:
+ att2: '{ get_input: my_mysql_rootpw }'
+ att1: att1Val
+ requirements:
+ - req1:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ node_filter:
+ properties:
+ propName1:
+ - greater_or_equal: 9
+ propName2:
+ - min_length: 1
+ - max_length: 2
+ occurrences:
+ - 1
+ - 2
+ - req2:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ substitution_mappings:
+ node_type: myNodeType.node
+ capabilities:
+ database_endpoint:
+ - database
+ - database_endpoint
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml
new file mode 100644
index 0000000000..6df071c570
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml
@@ -0,0 +1,112 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: Test
+ template_author: OPENECOMP
+ template_version: 1.0.0
+description: testing desc tosca service template
+imports:
+- myfile1:
+ file: path1/path2/file1.yaml
+- myfile2:
+ file: path1/path2/file2.yaml
+artifact_types:
+ one_artifact:
+ mime_type: application/java-archive
+ file_ext:
+ - yaml
+ - xml
+node_types:
+ compute_node_type:
+ derived_from: tosca.nodes.Root
+ version: 1.0.0
+ description: tosca compute test
+ properties:
+ cpu_num:
+ type: integer
+ description: Number of CPUs requested for a software node instance
+ required: true
+ default: 1
+ status: SUPPORTED
+ constraints:
+ - greater_or_equal: 5.0
+ - equal: 5
+ - greater_than: 6.02
+ - in_range:
+ - 0
+ - UNBOUNDED
+ attributes:
+ attDef1:
+ type: string
+ default: hi
+ status: SUPPORTED
+ requirements:
+ - re1:
+ capability: tosca.cap1
+ occurrences:
+ - 5
+ - 1
+ capabilities:
+ cap1:
+ type: tosca.cap
+ valid_source_types:
+ - node1
+ - node2
+ occurrences:
+ - 1
+ - UNBOUNDED
+topology_template:
+ description: topologi template descroption
+ inputs:
+ inParam1:
+ type: string
+ description: desc
+ required: false
+ default: my default val
+ constraints:
+ - greater_than: 6
+ - greater_or_equal: 9
+ entry_schema:
+ type: tosca.myType
+ node_templates:
+ firstNodeTemplate:
+ type: nodeTypeRef
+ directives:
+ - selectable
+ - substitutable
+ interfaces:
+ inter_1:
+ type: test interface
+ start:
+ description: start operation
+ implementation: start.sh
+ properties:
+ prop2: '{ get_input: my_mysql_rootpw }'
+ prop1: abcd
+ attributes:
+ att2: '{ get_input: my_mysql_rootpw }'
+ att1: att1Val
+ requirements:
+ - req1:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ node_filter:
+ properties:
+ propName1:
+ - greater_or_equal: 9
+ propName2:
+ - min_length: 1
+ - max_length: 2
+ occurrences:
+ - 1
+ - 2
+ - req2:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ substitution_mappings:
+ node_type: myNodeType.node
+ capabilities:
+ database_endpoint:
+ - database
+ - database_endpoint