aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib
diff options
context:
space:
mode:
authorshiria <shiri.amichai@amdocs.com>2018-03-19 15:23:23 +0200
committershiria <shiri.amichai@amdocs.com>2018-03-22 08:21:36 +0200
commit43187c8495b88589f3187e110cf8d592a091c37f (patch)
tree87ffaf38a95344d76547478f0306b2a923896e44 /openecomp-be/lib/openecomp-tosca-lib
parentd049ca05bbfb6fa6b86b2a093b09ffc1fc0a6e37 (diff)
Update FlatEntity in TOSCA
Add support of dataType entity flat hierarchy in TOSCA Fix existing nodeType entity flat hierarchy in TOSCA Change-Id: I52cd188c595a263c70c2067fd1aac9752f7e24a4 Issue-ID: SDC-1147 Signed-off-by: shiria <shiri.amichai@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaInterfaceType.java31
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java7
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java53
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java55
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/NestedServiceTemplateReqTest.yaml38
5 files changed, 176 insertions, 8 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaInterfaceType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaInterfaceType.java
new file mode 100644
index 0000000000..6a74f765e6
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaInterfaceType.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.openecomp.sdc.tosca.datatypes;
+
+import org.openecomp.config.api.Configuration;
+import org.openecomp.config.api.ConfigurationManager;
+
+public class ToscaInterfaceType {
+
+ private static Configuration config = ConfigurationManager.lookup();
+
+ //TOSCA native types
+ public static final String NATIVE_ROOT = " tosca.interfaces.Root";
+ public static final String NATIVE_LIFECYCLE_STANDARD = "tosca.interfaces.node.lifecycle.Standard";
+
+
+}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java
index 1aa171961f..5d4b7dfa00 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2016-2017 European Support Limited
+ * Copyright © 2016-2018 European Support Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@ public class ToscaConstants {
//General
public static final String TOSCA_DEFINITIONS_VERSION = "tosca_simple_yaml_1_0_0";
public static final String MODELABLE_ENTITY_NAME_SELF = "SELF";
+ public static final String MODELABLE_ENTITY_NAME_HOST = "HOST";
public static final String NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE = "substitutable";
public static final String NATIVE_TYPES_SERVICE_TEMPLATE_NAME = "NativeTypesServiceTemplate";
public static final String UNBOUNDED = "UNBOUNDED";
@@ -55,6 +56,7 @@ public class ToscaConstants {
public static final String SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME =
"substitute_service_template";
public static final String COUNT_PROPERTY_NAME = "count";
+ public static final String MANDATORY_PROPERTY_NAME = "mandatory";
public static final String INDEX_VALUE_PROPERTY_NAME = "index_value";
public static final String SCALING_ENABLED_PROPERTY_NAME = "scaling_enabled";
@@ -73,9 +75,10 @@ public class ToscaConstants {
public static final String VF_MODULE_LABEL_PROPERTY_NAME = "vf_module_label";
public static final String PARAM_NAME_PROPERTY_NAME = "param_name";
- // propertiies valid values
+ // properties valid values
public static final String HEAT_SOURCE_TYPE = "HEAT";
public static final String GENERIC_SOURCE_TYPE = "Generic";
+
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
index 6f514c03fe..411c50db5b 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
@@ -27,6 +27,7 @@ import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
import org.openecomp.sdc.tosca.datatypes.model.CapabilityType;
import org.openecomp.sdc.tosca.datatypes.model.DefinitionOfDataType;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
import org.openecomp.sdc.tosca.datatypes.model.Import;
import org.openecomp.sdc.tosca.datatypes.model.InterfaceDefinitionType;
import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
@@ -422,14 +423,20 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
case NODE_TYPE:
returnEntity = new NodeType();
break;
+ case DATA_TYPE:
+ returnEntity = new DataType();
+ break;
default:
throw new RuntimeException(
"Entity[" + elementType + "] id[" + typeId + "] flat not supported");
}
- scanAnFlatEntity(elementType, typeId, returnEntity, serviceTemplate, toscaModel,
- new ArrayList<>(), 0);
-
+ boolean isEntityFound =
+ scanAnFlatEntity(elementType, typeId, returnEntity, serviceTemplate, toscaModel,
+ new ArrayList<>(), 0);
+ if (!isEntityFound) {
+ throw new CoreException(new ToscaElementTypeNotFoundErrorBuilder(typeId).build());
+ }
return returnEntity;
}
@@ -635,6 +642,12 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return false;
}
break;
+ case DATA_TYPE:
+ if (enrichDataTypeInfo(elementType, typeId, entity, serviceTemplate, toscaModel,
+ filesScanned, rootScanStartInx)) {
+ return false;
+ }
+ break;
default:
throw new RuntimeException(
"Entity[" + elementType + "] id[" + typeId + "] flat not supported");
@@ -667,6 +680,28 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return false;
}
+ private boolean enrichDataTypeInfo(ToscaElementTypes elementType, String typeId, Object entity,
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
+ List<String> filesScanned, int rootScanStartInx) {
+ String derivedFrom;
+ if (serviceTemplate.getData_types() != null
+ && serviceTemplate.getData_types().containsKey(typeId)) {
+
+ filesScanned.clear();
+ DataType targetDataType = (DataType) entity;
+ DataType sourceDataType = serviceTemplate.getData_types().get(typeId);
+ derivedFrom = sourceDataType.getDerived_from();
+ if (derivedFrom != null) {
+ scanAnFlatEntity(elementType, derivedFrom, entity, serviceTemplate, toscaModel,
+ filesScanned, rootScanStartInx);
+ }
+ combineDataTypeInfo(sourceDataType, targetDataType);
+ } else {
+ return true;
+ }
+ return false;
+ }
+
private boolean enrichCapabilityType(ToscaElementTypes elementType, String typeId, Object entity,
ServiceTemplate serviceTemplate,
ToscaServiceModel toscaModel, List<String> filesScanned,
@@ -709,6 +744,16 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
+ private void combineDataTypeInfo(DataType sourceDataType, DataType targetDataType) {
+ targetDataType.setDerived_from(sourceDataType.getDerived_from());
+ targetDataType.setDescription(sourceDataType.getDescription());
+ targetDataType.setVersion(sourceDataType.getVersion());
+ targetDataType.setProperties(
+ CommonMethods.mergeMaps(targetDataType.getProperties(), sourceDataType.getProperties()));
+ targetDataType.setConstraints(
+ CommonMethods.mergeLists(targetDataType.getConstraints(), sourceDataType.getConstraints()));
+ }
+
private void combineCapabilityTypeInfo(CapabilityType sourceCapabilityType,
CapabilityType targetCapabilityType) {
@@ -883,6 +928,4 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
throw new RuntimeException(e);
}
}
-
-
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
index 4e17e50e25..713e8d2eaa 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
@@ -34,6 +34,7 @@ import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
import org.openecomp.sdc.tosca.datatypes.model.DataType;
import org.openecomp.sdc.tosca.datatypes.model.DefinitionOfDataType;
+import org.openecomp.sdc.tosca.datatypes.model.DataType;
import org.openecomp.sdc.tosca.datatypes.model.Import;
import org.openecomp.sdc.tosca.datatypes.model.InterfaceDefinitionType;
import org.openecomp.sdc.tosca.datatypes.model.InterfaceType;
@@ -107,7 +108,26 @@ public class ToscaAnalyzerServiceImplTest {
}
@Test
- public void testGetFlatEntity() throws Exception {
+ public void testGetFlatEntityNotFound() throws Exception {
+ thrown.expect(CoreException.class);
+ thrown.expectMessage(
+ "Entity Type 'org.openecomp.resource.vfc.notFound' or one of its derivedFrom type hierarchy, is not defined in tosca service model");
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (InputStream yamlFile = toscaExtensionYamlUtil
+ .loadYamlFileIs("/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
+
+ ServiceTemplate
+ serviceTemplateFromYaml =
+ toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
+
+ toscaAnalyzerService
+ .getFlatEntity(ToscaElementTypes.NODE_TYPE, "org.openecomp.resource.vfc.notFound",
+ serviceTemplateFromYaml, toscaServiceModel);
+ }
+ }
+
+ @Test
+ public void testGetFlatEntityNodeType() throws Exception {
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
try (InputStream yamlFile = toscaExtensionYamlUtil
.loadYamlFileIs("/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
@@ -123,6 +143,39 @@ public class ToscaAnalyzerServiceImplTest {
Assert.assertNotNull(flatEntity);
Assert.assertEquals("org.openecomp.resource.vfc.nodes.heat.nova.Server", flatEntity
.getDerived_from());
+ Assert.assertEquals(20, flatEntity.getProperties().size());
+ Assert.assertEquals("overridden default value",
+ flatEntity.getProperties().get("admin_pass").get_default());
+ Assert.assertEquals("REBUILD",
+ flatEntity.getProperties().get("image_update_policy").get_default());
+ Assert.assertNotNull(flatEntity.getProperties().get("new_property"));
+ }
+ }
+
+ @Test
+ public void testGetFlatEntityDataType() throws Exception {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (InputStream yamlFile = toscaExtensionYamlUtil
+ .loadYamlFileIs("/mock/analyzerService/NestedServiceTemplateReqTest.yaml")) {
+
+ ServiceTemplate
+ serviceTemplateFromYaml =
+ toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
+
+ final DataType flatEntity = (DataType) toscaAnalyzerService
+ .getFlatEntity(ToscaElementTypes.DATA_TYPE,
+ "org.openecomp.datatypes.heat.network.MyNewAddressPair", serviceTemplateFromYaml,
+ toscaServiceModel);
+
+ Assert.assertNotNull(flatEntity);
+ Assert.assertEquals("org.openecomp.datatypes.heat.network.MyAddressPair", flatEntity
+ .getDerived_from());
+ Assert.assertEquals(3, flatEntity.getProperties().size());
+ Assert.assertEquals("overridden default value",
+ flatEntity.getProperties().get("mac_address").get_default());
+ Assert.assertEquals(true,
+ flatEntity.getProperties().get("mac_address").getRequired());
+ Assert.assertNotNull(flatEntity.getProperties().get("new_property"));
}
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/NestedServiceTemplateReqTest.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/NestedServiceTemplateReqTest.yaml
index ce02d0c034..8022d996b7 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/NestedServiceTemplateReqTest.yaml
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/NestedServiceTemplateReqTest.yaml
@@ -25,6 +25,44 @@ imports:
node_types:
org.openecomp.resource.vfc.nodes.heat.cmaui_image:
derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server
+ properties:
+ admin_pass:
+ description: The administrator password for the server
+ type: string
+ status: SUPPORTED
+ default: overridden default value
+ required: false
+ new_property:
+ description: new property
+ type: string
+ status: SUPPORTED
+ required: false
+data_types:
+ org.openecomp.datatypes.heat.network.MyAddressPair:
+ derived_from: org.openecomp.datatypes.heat.network.AddressPair
+ description: My MAC/IP address pairs
+ properties:
+ mac_address:
+ description: MAC address
+ type: string
+ status: SUPPORTED
+ required: false
+ default: overridden default value
+ new_property:
+ description: new property
+ type: string
+ status: SUPPORTED
+ required: false
+ org.openecomp.datatypes.heat.network.MyNewAddressPair:
+ derived_from: org.openecomp.datatypes.heat.network.MyAddressPair
+ description: My new MAC/IP address pairs
+ properties:
+ mac_address:
+ description: MAC address
+ type: string
+ status: SUPPORTED
+ required: true
+ default: overridden default value
topology_template:
inputs:
cmaui_names: