summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java76
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java14
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java13
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java12
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java4
-rw-r--r--catalog-be/src/test/resources/csars/nonOnapCsar.csarbin13948 -> 14013 bytes
-rw-r--r--catalog-be/src/test/resources/mock_service.csarbin1602 -> 1744 bytes
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java21
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabels.java1
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabelsTest.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/DerivedNodeTypeResolver.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCache.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ByToscaNameDerivedNodeTypeResolver.java4
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java4
20 files changed, 144 insertions, 56 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
index f5a1409e68..14ede6305b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
@@ -85,6 +85,9 @@ public class CsarInfo {
private boolean isUpdate;
@Getter
private Map<String, Resource> createdNodes;
+ private Map<String, Object> datatypeDefinitions;
+ private List<Map.Entry<String, byte[]>> globalSubstitutes;
+
@SuppressWarnings("unchecked")
public CsarInfo(User modifier, String csarUUID, Map<String, byte[]> csar, String vfResourceName, String mainTemplateName,
@@ -101,7 +104,18 @@ public class CsarInfo {
this.isUpdate = isUpdate;
this.createdNodes = new HashMap<>();
this.nonManoConfiguration = NonManoConfigurationManager.getInstance().getNonManoConfiguration();
+ this.globalSubstitutes = getGlobalSubstitutes(csar);
}
+
+ private List<Map.Entry<String, byte[]>> getGlobalSubstitutes(final Map<String, byte[]> csar){
+ final List<Map.Entry<String, byte[]>> globalSubstitutesInCsar = new ArrayList<>();
+ for (Map.Entry<String, byte[]> entry : csar.entrySet()) {
+ if (isAServiceTemplate(entry.getKey()) && isGlobalSubstitute(entry.getKey())) {
+ globalSubstitutesInCsar.add(entry);
+ }
+ }
+ return globalSubstitutesInCsar;
+ }
@VisibleForTesting
CsarInfo(final NonManoConfiguration nonManoConfiguration) {
@@ -153,37 +167,56 @@ public class CsarInfo {
this.isUpdate = isUpdate;
}
- public Map<String, NodeTypeInfo> extractNodeTypesInfo() {
+ public Map<String, NodeTypeInfo> extractTypesInfo() {
Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
- List<Map.Entry<String, byte[]>> globalSubstitutes = new ArrayList<>();
final Set<String> nodeTypesUsedInNodeTemplates = new HashSet<>();
for (Map.Entry<String, byte[]> entry : getCsar().entrySet()) {
- extractNodeTypeInfo(nodeTypesInfo, globalSubstitutes, nodeTypesUsedInNodeTemplates, entry);
+ extractNodeTypeInfo(nodeTypesInfo, nodeTypesUsedInNodeTemplates, entry);
}
if (CollectionUtils.isNotEmpty(globalSubstitutes)) {
- setDerivedFrom(nodeTypesInfo, globalSubstitutes);
- addGlobalSubstitutionsToNodeTypes(globalSubstitutes, nodeTypesUsedInNodeTemplates, nodeTypesInfo);
+ setDerivedFrom(nodeTypesInfo);
+ addGlobalSubstitutionsToNodeTypes(nodeTypesUsedInNodeTemplates, nodeTypesInfo);
}
+
markNestedVfc(getMappedToscaMainTemplate(), nodeTypesInfo);
return nodeTypesInfo;
}
+
+ public Map<String, Object> getDataTypes() {
+ if (datatypeDefinitions == null) {
+ datatypeDefinitions = new HashMap<>();
+ for (Map.Entry<String, byte[]> entry : globalSubstitutes) {
+ final String yamlFileContents = new String(entry.getValue());
+ final Map<String, Object> mappedToscaTemplate = new Yaml().load(yamlFileContents);
+ datatypeDefinitions.putAll(getDataTypesFromTemplate(mappedToscaTemplate));
+ }
+ datatypeDefinitions.putAll(getDataTypesFromTemplate(mappedToscaMainTemplate));
+ }
+ return datatypeDefinitions;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, Object> getDataTypesFromTemplate(final Map<String, Object> mappedToscaTemplate) {
+ final Either<Object, ResultStatusEnum> dataTypesEither = findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.DATA_TYPES,
+ ToscaElementTypeEnum.MAP);
+ if (dataTypesEither != null && dataTypesEither.isLeft()) {
+ return (Map<String, Object>) dataTypesEither.left().value();
+ }
+ return Collections.emptyMap();
+ }
@SuppressWarnings("unchecked")
- private void extractNodeTypeInfo(Map<String, NodeTypeInfo> nodeTypesInfo, List<Map.Entry<String, byte[]>> globalSubstitutes,
+ private void extractNodeTypeInfo(Map<String, NodeTypeInfo> nodeTypesInfo,
final Set<String> nodeTypesUsedInNodeTemplates, Map.Entry<String, byte[]> entry) {
- if (isAServiceTemplate(entry.getKey())) {
- if (isGlobalSubstitute(entry.getKey())) {
- globalSubstitutes.add(entry);
- } else {
- Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(new String(entry.getValue()));
- findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS, ToscaElementTypeEnum.MAP).right()
- .on(sub -> handleSubstitutionMappings(nodeTypesInfo, entry, mappedToscaTemplate, (Map<String, Object>) sub));
- final Either<Object, ResultStatusEnum> nodeTypesEither = findToscaElement(mappedToscaTemplate,
- TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP);
- if (nodeTypesEither.isLeft()) {
- final Map<String, Map<String, Object>> nodeTemplates = (Map<String, Map<String, Object>>) nodeTypesEither.left().value();
- nodeTypesUsedInNodeTemplates.addAll(findNodeTypesUsedInNodeTemplates(nodeTemplates));
- }
+ if (isAServiceTemplate(entry.getKey()) && !isGlobalSubstitute(entry.getKey())) {
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(new String(entry.getValue()));
+ findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS, ToscaElementTypeEnum.MAP).right()
+ .on(sub -> handleSubstitutionMappings(nodeTypesInfo, entry, mappedToscaTemplate, (Map<String, Object>) sub));
+ final Either<Object, ResultStatusEnum> nodeTypesEither = findToscaElement(mappedToscaTemplate,
+ TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP);
+ if (nodeTypesEither.isLeft()) {
+ final Map<String, Map<String, Object>> nodeTemplates = (Map<String, Map<String, Object>>) nodeTypesEither.left().value();
+ nodeTypesUsedInNodeTemplates.addAll(findNodeTypesUsedInNodeTemplates(nodeTemplates));
}
}
}
@@ -232,7 +265,7 @@ public class CsarInfo {
}
@SuppressWarnings("unchecked")
- private void setDerivedFrom(Map<String, NodeTypeInfo> nodeTypesInfo, List<Map.Entry<String, byte[]>> globalSubstitutes) {
+ private void setDerivedFrom(Map<String, NodeTypeInfo> nodeTypesInfo) {
for (Map.Entry<String, byte[]> entry : globalSubstitutes) {
String yamlFileContents = new String(entry.getValue());
Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(yamlFileContents);
@@ -259,8 +292,7 @@ public class CsarInfo {
}
@SuppressWarnings("unchecked")
- private void addGlobalSubstitutionsToNodeTypes(final List<Map.Entry<String, byte[]>> globalSubstitutes,
- final Set<String> nodeTypesUsedInNodeTemplates, final Map<String, NodeTypeInfo> nodeTypesInfo) {
+ private void addGlobalSubstitutionsToNodeTypes(final Set<String> nodeTypesUsedInNodeTemplates, final Map<String, NodeTypeInfo> nodeTypesInfo) {
for (Map.Entry<String, byte[]> entry : globalSubstitutes) {
final String yamlFileContents = new String(entry.getValue());
final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(yamlFileContents);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
index de79ec165d..99349395b9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java
@@ -43,10 +43,18 @@ public class ModelBusinessLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(ModelBusinessLogic.class);
private final ModelOperation modelOperation;
+ private final DataTypeImportManager dataTypeImportManager;
@Autowired
- public ModelBusinessLogic(final ModelOperation modelOperation) {
+ public ModelBusinessLogic(final ModelOperation modelOperation, final DataTypeImportManager dataTypeImportManager) {
this.modelOperation = modelOperation;
+ this.dataTypeImportManager = dataTypeImportManager;
+ }
+
+ public Model createModel(final Model model, final String datatypesYaml) {
+ createModel(model);
+ dataTypeImportManager.createDataTypes(datatypesYaml, model.getName());
+ return model;
}
public Model createModel(final Model model) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index c291c571d7..6185dc9b0e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -118,6 +118,7 @@ import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Model;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
@@ -212,6 +213,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
private final CsarBusinessLogic csarBusinessLogic;
private final PropertyBusinessLogic propertyBusinessLogic;
private final PolicyBusinessLogic policyBusinessLogic;
+ private final ModelBusinessLogic modelBusinessLogic;
private IInterfaceLifecycleOperation interfaceTypeOperation;
private LifecycleBusinessLogic lifecycleBusinessLogic;
@Autowired
@@ -225,6 +227,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
@Autowired
private SoftwareInformationBusinessLogic softwareInformationBusinessLogic;
+
@Autowired
public ResourceBusinessLogic(final IElementOperation elementDao, final IGroupOperation groupOperation,
final IGroupInstanceOperation groupInstanceOperation, final IGroupTypeOperation groupTypeOperation,
@@ -242,7 +245,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
final ComponentNameValidator componentNameValidator, final ComponentTagsValidator componentTagsValidator,
final ComponentValidator componentValidator, final ComponentIconValidator componentIconValidator,
final ComponentProjectCodeValidator componentProjectCodeValidator,
- final ComponentDescriptionValidator componentDescriptionValidator, final PolicyBusinessLogic policyBusinessLogic) {
+ final ComponentDescriptionValidator componentDescriptionValidator, final PolicyBusinessLogic policyBusinessLogic,
+ final ModelBusinessLogic modelBusinessLogic) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation,
interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
@@ -258,6 +262,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
this.csarBusinessLogic = csarBusinessLogic;
this.propertyBusinessLogic = propertyBusinessLogic;
this.policyBusinessLogic = policyBusinessLogic;
+ this.modelBusinessLogic = modelBusinessLogic;
}
static <T> Either<T, RuntimeException> rollbackWithEither(final JanusGraphDao janusGraphDao, final ActionStatus actionStatus,
@@ -508,7 +513,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(newResource, oldResource, user, csarUIPayload, csarUUID);
lockComponent(lockedResourceId, oldResource, "update Resource From Csar");
- Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractNodeTypesInfo();
+ Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo();
Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(
nodeTypesInfo, csarInfo, oldResource);
if (findNodeTypesArtifactsToHandleRes.isRight()) {
@@ -1017,7 +1022,23 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
.log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML, StatusCode.STARTED, "Starting to create Resource From Csar by user {}",
user.getUserId());
CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, csarUIPayload, csarUUID);
- Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractNodeTypesInfo();
+ Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo();
+ if (StringUtils.isNotEmpty(resource.getModel())) {
+ final Map<String, Object> dataTypesToCreate = new HashMap<>();
+ for (final String dataType: csarInfo.getDataTypes().keySet()) {
+ final Either<DataTypeDefinition, StorageOperationStatus> result = propertyOperation.getDataTypeByName(dataType, resource.getModel());
+ if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ dataTypesToCreate.put(dataType, csarInfo.getDataTypes().get(dataType));
+ }
+ }
+ if (MapUtils.isNotEmpty(dataTypesToCreate)) {
+ final String nameForGeneratedModel = resource.getModel() + "_" + csarInfo.getVfResourceName() + resource.getCsarVersion();
+ final Model model = new Model(nameForGeneratedModel, resource.getModel());
+ modelBusinessLogic.createModel(model, new Yaml().dump(dataTypesToCreate));
+ resource.setModel(nameForGeneratedModel);
+ }
+ }
+
Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(
nodeTypesInfo, csarInfo, resource);
if (findNodeTypesArtifactsToHandleRes.isRight()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index 1a5a996a46..6bb7fdadb9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -226,7 +226,7 @@ public class ServiceImportBusinessLogic {
log.trace("************* created successfully from YAML, resource TOSCA ");
try {
CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID);
- Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractNodeTypesInfo();
+ Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo();
Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = serviceImportParseLogic
.findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo, service);
if (findNodeTypesArtifactsToHandleRes.isRight()) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
index fddb79afb6..07a8ded378 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
@@ -127,10 +127,10 @@ public class CsarInfoTest {
}
@Test
- public void csarCheckNodeTypesInfoTest() {
+ public void csarCheckTypesInfoTest() {
// when
- Map<String, NodeTypeInfo> nodeTypeInfoMap = csarInfo.extractNodeTypesInfo();
+ Map<String, NodeTypeInfo> nodeTypeInfoMap = csarInfo.extractTypesInfo();
NodeTypeInfo nodeTypeInfo = nodeTypeInfoMap.get(NODE_TYPE);
// then
@@ -140,6 +140,10 @@ public class CsarInfoTest {
assertEquals(MAIN_TEMPLATE_NAME, csarInfo.getMainTemplateName());
assertEquals(csarInfo.getMainTemplateName(), nodeTypeInfo.getTemplateFileName());
+
+ Map<String, Object> dataTypes = csarInfo.getDataTypes();
+ assertTrue(dataTypes.containsKey("tosca.datatypes.testDataType.FromMainTemplate"));
+ assertTrue(dataTypes.containsKey("tosca.datatypes.testDataType.FromGlobalSub"));
}
@Test
@@ -176,15 +180,15 @@ public class CsarInfoTest {
final String nodeTypeInSubstitutionMapping = (String) ((Map<String, Object>)((Map<String, Object>)csarInfo.getMappedToscaMainTemplate().get("topology_template")).get("substitution_mappings")).get("node_type");
assertTrue(((Map<String, Object>) csarInfo.getMappedToscaMainTemplate().get("node_types")).containsKey(nodeTypeInSubstitutionMapping));
- assertTrue(csarInfo.extractNodeTypesInfo().isEmpty());
+ assertTrue(csarInfo.extractTypesInfo().isEmpty());
}
@Test
public void testCreateCsarInfoVnfWithNodeTypeInGlobalSub() throws URISyntaxException, ZipException {
final CsarInfo csarInfo = createCsarInfo("nodeTypeInGlobalSub.csar", "Definitions/MainServiceTemplate.yaml");
- assertEquals(1, csarInfo.extractNodeTypesInfo().size());
- final NodeTypeInfo nodeTypeInfo = csarInfo.extractNodeTypesInfo().get("tosca.nodes.l3vpn");
+ assertEquals(1, csarInfo.extractTypesInfo().size());
+ final NodeTypeInfo nodeTypeInfo = csarInfo.extractTypesInfo().get("tosca.nodes.l3vpn");
assertNotNull(nodeTypeInfo);
assertEquals("Definitions/GlobalSubstitutionTypesServiceTemplate.yaml", nodeTypeInfo.getTemplateFileName());
assertEquals("tosca.nodes.l3vpn", nodeTypeInfo.getType());
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java
index ef334f5510..08d0787b27 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogicTest.java
@@ -58,6 +58,8 @@ class ModelBusinessLogicTest {
private ModelBusinessLogic modelBusinessLogic;
@Mock
private ModelOperation modelOperation;
+ @Mock
+ private DataTypeImportManager dataTypeImportManager;
private Model model;
private final Path modelImportsResourcePath = Path.of("src/test/resources/modelImports");
@@ -78,6 +80,17 @@ class ModelBusinessLogicTest {
assertThat(result).isNotNull();
assertThat(result.getName()).isEqualTo(model.getName());
}
+
+ @Test
+ void createModelWithDataTypesTest() {
+ final String dataTypes = "dummyString";
+ when(modelOperation.createModel(model, false)).thenReturn(model);
+ final Model result = modelBusinessLogic.createModel(model, dataTypes);
+ assertThat(result).isNotNull();
+ assertThat(result.getName()).isEqualTo(model.getName());
+
+ verify(dataTypeImportManager).createDataTypes(dataTypes, model.getName());
+ }
@Test
void createModelFailTest() {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index 542b142c21..6b52ed8d87 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -190,7 +190,8 @@ public class ResourceBusinessLogicTest {
private final IGroupOperation groupOperation = Mockito.mock(IGroupOperation.class);
private final IGroupInstanceOperation groupInstanceOperation = Mockito.mock(IGroupInstanceOperation.class);
private final IGroupTypeOperation groupTypeOperation = Mockito.mock(IGroupTypeOperation.class);
- private final GroupBusinessLogic groupBusinessLogic = Mockito.mock(GroupBusinessLogic.class);
+ private final GroupBusinessLogic groupBusinessLogic = Mockito.mock(GroupBusinessLogic.class);
+ private final ModelBusinessLogic modelBusinessLogic = Mockito.mock(ModelBusinessLogic.class);
private final InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
private final ArtifactsOperations artifactToscaOperation = Mockito.mock(ArtifactsOperations.class);
private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
@@ -313,7 +314,7 @@ public class ResourceBusinessLogicTest {
csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator,
- componentDescriptionValidator, policyBusinessLogic);
+ componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic);
bl.setElementDao(mockElementDao);
bl.setUserAdmin(mockUserAdmin);
bl.setCapabilityTypeOperation(capabilityTypeOperation);
@@ -1460,6 +1461,8 @@ public class ResourceBusinessLogicTest {
YamlTemplateParsingHandler yamlTemplateParser = new YamlTemplateParsingHandler(mockJanusGraphDao, null, Mockito.mock(AnnotationBusinessLogic.class), null);
final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml, Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse);
+ when(propertyOperation.getDataTypeByName("tosca.datatypes.testDataType.FromMainTemplate", "testModel")).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+
when(toscaOperationFacade.getLatestByToscaResourceName(anyString(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
Resource vduCp = new Resource();
vduCp.setToscaResourceName("tosca.nodes.nfv.VduCp");
@@ -1502,6 +1505,7 @@ public class ResourceBusinessLogicTest {
resourceResponse.setModel("testModel");
resourceResponse.setResourceType(ResourceTypeEnum.VF);
resourceResponse.setProperties(new ArrayList<>());
+ resourceResponse.setCsarVersion("1.0");
Resource derivedFrom = new Resource();
List<PropertyDefinition> properties = new ArrayList<>();
@@ -1513,7 +1517,7 @@ public class ResourceBusinessLogicTest {
when(genericTypeBusinessLogic.fetchDerivedFromGenericType(any(), eq("tosca.nodes.nfv.VNF"))).thenReturn(Either.left(derivedFrom));
when(toscaOperationFacade
- .validateComponentNameAndModelExists("myVnf", "testModel", ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(false));
+ .validateComponentNameAndModelExists("myVnf", "testModel_myVnf1.0", ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(false));
when(toscaOperationFacade.addPropertyToComponent(any(), any(), any())).thenReturn(Either.left(new PropertyDefinition()));
when(toscaOperationFacade.associateComponentInstancePropertiesToComponent(any(), any())).thenReturn(Either.left(Collections.emptyMap()));
@@ -1521,7 +1525,7 @@ public class ResourceBusinessLogicTest {
when(toscaOperationFacade.associateDeploymentArtifactsToInstances(any(), any(), any())).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacade.associateInstAttributeToComponentToInstances(any(), any())).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacade.associateResourceInstances(any(Component.class), anyString(), anyList())).thenReturn(Either.left(Collections.EMPTY_LIST));
- when(applicationDataTypeCache.getAll(resourceResponse.getModel())).thenReturn(Either.left(emptyDataTypes));
+ when(applicationDataTypeCache.getAll("testModel_myVnf1.0")).thenReturn(Either.left(emptyDataTypes));
doAnswer(invocation -> {
Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instReqs = invocation.getArgument(1);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
index 059dde3254..3b7ffd70cf 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
@@ -149,7 +149,7 @@ public class YamlTemplateParsingHandlerTest {
Resource resource = new Resource();
ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
- csarInfo.extractNodeTypesInfo(), NODE_NAME, resource);
+ csarInfo.extractTypesInfo(), NODE_NAME, resource);
validateParsedYaml(parsedYaml, NESTED_GROUP_NAME,
Lists.newArrayList("heat_file", "description"));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
index 47ca94dbdc..46040ca2d6 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
@@ -30,6 +30,7 @@ import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.CompositionBusinessLogic;
import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ModelBusinessLogic;
import org.openecomp.sdc.be.components.impl.OutputsBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
@@ -68,6 +69,7 @@ public class CheckoutTest extends LifecycleTestBase {
private final ComponentContactIdValidator componentContactIdValidator = new ComponentContactIdValidator(componentsUtils);
private final ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
private final PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class);
+ private final ModelBusinessLogic modelBusinessLogic = Mockito.mock(ModelBusinessLogic.class);
@InjectMocks
ResourceBusinessLogic bl = new ResourceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic,
@@ -75,7 +77,7 @@ public class CheckoutTest extends LifecycleTestBase {
resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils,
uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic,
componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator,
- componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator ,policyBusinessLogic);
+ componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator ,policyBusinessLogic, modelBusinessLogic);
@Before
public void setup() {
diff --git a/catalog-be/src/test/resources/csars/nonOnapCsar.csar b/catalog-be/src/test/resources/csars/nonOnapCsar.csar
index fcf6b7f2ae..9e097051ec 100644
--- a/catalog-be/src/test/resources/csars/nonOnapCsar.csar
+++ b/catalog-be/src/test/resources/csars/nonOnapCsar.csar
Binary files differ
diff --git a/catalog-be/src/test/resources/mock_service.csar b/catalog-be/src/test/resources/mock_service.csar
index 536080508c..58f064f4fa 100644
--- a/catalog-be/src/test/resources/mock_service.csar
+++ b/catalog-be/src/test/resources/mock_service.csar
Binary files differ
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java
index 76fddc070b..8614f4beb4 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java
@@ -587,16 +587,21 @@ public class JanusGraphDao {
}
private boolean vertexValidForModel(final JanusGraphVertex vertex, final String model) {
- final Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> modelVertices = getParentVerticies(vertex, GraphEdgeLabels.MODEL_ELEMENT);
+ final String vertexLabel = (String)vertex.property(GraphPropertyEnum.LABEL.getProperty()).value();
+ final VertexTypeEnum vertexType = VertexTypeEnum.getByName(vertexLabel);
+ final GraphEdgeLabels edgeLabel = vertexType.equals(VertexTypeEnum.TOPOLOGY_TEMPLATE) ? GraphEdgeLabels.MODEL : GraphEdgeLabels.MODEL_ELEMENT;
+ final Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> modelVertices = getParentVerticies(vertex, edgeLabel);
- if (modelVertices.isLeft()) {
- for (ImmutablePair<JanusGraphVertex, Edge> vertexPair : modelVertices.left().value()) {
- if (model.equals((String)vertexPair.getLeft().property("name").value())) {
- return true;
- }
- }
+ return modelVertices.isLeft() && modelVertices.left().value().stream().anyMatch(vertexPair -> modelVertexMatchesModel(vertexPair.getLeft(), model));
+ }
+
+ private boolean modelVertexMatchesModel(final JanusGraphVertex modelVertex, final String model) {
+ if (model.equals((String)modelVertex.property("name").value())) {
+ return true;
}
- return false;
+ final Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> derivedModels =
+ getParentVerticies(modelVertex, GraphEdgeLabels.DERIVED_FROM);
+ return derivedModels.isLeft() && derivedModels.left().value().stream().anyMatch(derivedModel ->modelVertexMatchesModel(derivedModel.left, model));
}
private Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getParentVerticies(
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabels.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabels.java
index 7dbcc87eb4..4ed16a42ec 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabels.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabels.java
@@ -71,6 +71,7 @@ public enum GraphEdgeLabels {
PARAMETER_VALUE("PARAMETER_VALUE"),
PARAMETER_IMPL("PARAMETER_IMPL"),
MODEL_ELEMENT("MODEL_ELEMENT"),
+ MODEL("MODEL"),
// VF additions
CALCULATED_REQUIREMENT("CALCULATED_REQUIREMENT"),
CALCULATED_CAPABILITY("CALCULATED_CAPABILITY"),
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabelsTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabelsTest.java
index bfa940929a..37f1707e41 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabelsTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/neo4j/GraphEdgeLabelsTest.java
@@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
public class GraphEdgeLabelsTest {
@Test
public void testGetAllProperties() throws Exception {
- assertEquals(56, GraphEdgeLabels.getAllProperties().size());
+ assertEquals(57, GraphEdgeLabels.getAllProperties().size());
}
@Test
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DerivedNodeTypeResolver.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DerivedNodeTypeResolver.java
index 934a43bc38..4cf78adfca 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DerivedNodeTypeResolver.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DerivedNodeTypeResolver.java
@@ -26,5 +26,5 @@ import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
public interface DerivedNodeTypeResolver {
- Either<List<GraphVertex>, JanusGraphOperationStatus> findDerivedResources(String parentResource);
+ Either<List<GraphVertex>, JanusGraphOperationStatus> findDerivedResources(String parentResource, String modelName);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCache.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCache.java
index 070ebf72e3..954df91552 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCache.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/ApplicationDataTypeCache.java
@@ -168,7 +168,7 @@ public class ApplicationDataTypeCache implements ApplicationCache<DataTypeDefini
public Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> getAll(final String model) {
try {
readWriteLock.readLock().lock();
- if (MapUtils.isEmpty(dataTypesByModelCacheMap)) {
+ if (MapUtils.isEmpty(dataTypesByModelCacheMap) || !dataTypesByModelCacheMap.containsKey(model)) {
final var dataTypesFound = getAllDataTypesFromGraph();
if (dataTypesFound.isRight()) {
return Either.right(dataTypesFound.right().value());
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ByToscaNameDerivedNodeTypeResolver.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ByToscaNameDerivedNodeTypeResolver.java
index 743fcdec44..4b6c084a89 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ByToscaNameDerivedNodeTypeResolver.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ByToscaNameDerivedNodeTypeResolver.java
@@ -41,10 +41,10 @@ public class ByToscaNameDerivedNodeTypeResolver implements DerivedNodeTypeResolv
private JanusGraphDao janusGraphDao;
@Override
- public Either<List<GraphVertex>, JanusGraphOperationStatus> findDerivedResources(String parentResource) {
+ public Either<List<GraphVertex>, JanusGraphOperationStatus> findDerivedResources(String parentResource, final String modelName) {
Map<GraphPropertyEnum, Object> propertiesToMatch = new HashMap<>();
propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, parentResource);
- return janusGraphDao.getByCriteria(VertexTypeEnum.NODE_TYPE, propertiesToMatch, JsonParseFlagEnum.ParseMetadata);
+ return janusGraphDao.getByCriteria(VertexTypeEnum.NODE_TYPE, propertiesToMatch, null, JsonParseFlagEnum.ParseMetadata, modelName);
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
index 76d8e71c69..2025a103a6 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
@@ -576,7 +576,7 @@ public class NodeTypeOperation extends ToscaElementOperation {
if (derivedFromResources != null && !derivedFromResources.isEmpty()) {
for (String parentResource : derivedFromResources) {
Either<List<GraphVertex>, JanusGraphOperationStatus> getParentResources = derivedResourceResolver
- .findDerivedResources(parentResource);
+ .findDerivedResources(parentResource, nodeType.getModel());
List<GraphVertex> resources = null;
if (getParentResources.isRight()) {
log.error("Cannot find parent resource by tosca resource name {} in the graph.", parentResource);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
index d0f1c3a9dd..a288953a71 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
@@ -279,7 +279,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
.getParentVertex(previousToscaElement, EdgeLabelEnum.MODEL, JsonParseFlagEnum.NoParse);
if (modelElementVertexResponse.isLeft()) {
final JanusGraphOperationStatus status = janusGraphDao
- .createEdge(nextToscaElement.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.MODEL, new HashMap<>());
+ .createEdge(modelElementVertexResponse.left().value().getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.MODEL, new HashMap<>());
if (JanusGraphOperationStatus.OK != status) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.MODEL,
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index 6466683db6..2f11fa9e8f 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -2191,9 +2191,7 @@ public class ToscaOperationFacade {
hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
hasNotProps.put(GraphPropertyEnum.IS_ARCHIVED, true);
hasProps.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
- if (modelName != null) {
- hasProps.put(GraphPropertyEnum.MODEL, modelName);
- }
+
if (VertexTypeEnum.NODE_TYPE == internalVertexType) {
hasProps.put(GraphPropertyEnum.IS_ABSTRACT, isAbstract);
if (internalComponentType != null) {