From 48c15ed0d02d98acac81773d84e928d0bd5ff07d Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 26 Aug 2018 16:20:04 -0400 Subject: Controller Blueprints Microservice Add Standardized resource definition in Initial data loading and Dictionary management services. Change-Id: Ib33ba2ecf3cb1e1fb9b5dea71532e6bc8280bcbb Issue-ID: CCSDK-487 Signed-off-by: Brinda Santh --- .../load/model_type/node_type/source-db.json | 44 ++++++++++++++++ .../load/model_type/node_type/source-default.json | 18 +++++++ .../load/model_type/node_type/source-input.json | 18 +++++++ .../load/model_type/node_type/source-rest.json | 61 ++++++++++++++++++++++ .../node_type/tosca.nodes.ResourceSource.json | 5 ++ .../load/resource_dictionary/db-source.json | 25 +++++---- .../load/resource_dictionary/input-source.json | 16 +++--- .../load/resource_dictionary/v4-ip-type.json | 29 +++++----- .../service/AutoResourceMappingService.java | 7 +-- .../service/DataBaseInitService.java | 25 ++++----- .../service/ResourceDictionaryService.java | 37 ++++++++----- .../service/rs/ResourceDictionaryRestTest.java | 9 +--- .../resourcedictionary/default_definition.json | 34 ++++++------ 13 files changed, 244 insertions(+), 84 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json (limited to 'ms/controllerblueprints/modules/service') diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json new file mode 100644 index 000000000..661a9503b --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json @@ -0,0 +1,44 @@ +{ + "description": "This is Database Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": true, + "type": "string", + "constraints": [ + { + "valid_values": [ + "SQL", + "PLSQL" + ] + } + ] + }, + "query": { + "required": true, + "type": "string" + }, + "input-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "output-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json new file mode 100644 index 000000000..13e234e1b --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json @@ -0,0 +1,18 @@ +{ + "description": "This is Default Resource Source Node Type", + "version": "1.0.0", + "properties": { + "key": { + "required": false, + "type": "string" + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json new file mode 100644 index 000000000..126ea30bd --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json @@ -0,0 +1,18 @@ +{ + "description": "This is Input Resource Source Node Type", + "version": "1.0.0", + "properties": { + "key": { + "required": false, + "type": "string" + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json new file mode 100644 index 000000000..f8dd8b6fc --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json @@ -0,0 +1,61 @@ +{ + "description": "This is Rest Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": false, + "type": "string", + "default": "JSON", + "constraints": [ + { + "valid_values": [ + "JSON" + ] + } + ] + }, + "url-path": { + "required": true, + "type": "string" + }, + "path": { + "required": true, + "type": "string" + }, + "expression-type": { + "required": false, + "type": "string", + "default": "JSON_PATH", + "constraints": [ + { + "valid_values": [ + "JSON_PATH", + "JSON_POINTER" + ] + } + ] + }, + "input-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "output-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json new file mode 100644 index 000000000..2ef553e24 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json @@ -0,0 +1,5 @@ +{ + "description": "TOSCA base type for Resource Sources", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json index 862523544..cd4e282b4 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json @@ -1,20 +1,25 @@ { "name": "bundle-id", - "description": "name of the ", + "property" :{ + "description": "name of the ", + "type": "string" + }, "resource-type": "ONAP", "resource-path": "vnf/bundle-id", "updated-by": "brindasanth@onap.com", - "data-type": "String", "tags": "bundle-id, brindasanth@onap.com", - "source": { + "sources": { "db": { - "query": "SELECT bundle-id FROM DEVICE_PROFILE WHERE profile_name = :profile_name", - "input-key-mapping": { - "profile_name": "profile_name" - }, - "output-key-mapping": { - "db-country": "country", - "db-state": "state" + "type": "source-db", + "properties": { + "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name", + "input-key-mapping": { + "profile_name": "profile_name" + }, + "output-key-mapping": { + "db-country": "country", + "db-state": "state" + } } } }, diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json index 35736b663..c34c252b3 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json @@ -1,17 +1,19 @@ { "name": "action-name", + "property" :{ + "description": "name of the ", + "type": "string" + }, "resource-path": "action-name", "resource-type": "ONAP", - "description": "To be provided", - "valid-values": null, - "sample-value": null, "updated-by": "brindasanth@onap.com", "tags": null, - "default": null, - "data-type": "string", - "source": { + "sources": { "input": { - "key": "action-name" + "type": "source-input", + "properties": { + "key": "action-name" + } } } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json index c6c0f9851..349183bd9 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json @@ -1,14 +1,19 @@ { - "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com", - "name": "v4-ip-type", - "description": "To be provided", - "updated-by": "brindasanth@onap.com", - "resource-type": "ONAP", - "resource-path": "vnf/v4-ip-type", - "data-type": "string", - "source": { - "input": { - - } - } + "name": "v4-ip-type", + "property": { + "description": "name of the ", + "type": "string" + }, + "resource-path": "vnf/v4-ip-type", + "resource-type": "ONAP", + "updated-by": "brindasanth@onap.com", + "tags": null, + "sources": { + "input": { + "type": "source-input", + "properties": { + "key": "v4-ip-type" + } + } + } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java index 6b09c81ff..2c443783e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +23,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; @@ -102,7 +103,7 @@ public class AutoResourceMappingService { ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName()); if (dbDataDictionary != null && StringUtils.isNotBlank(dbDataDictionary.getDefinition())) { - DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), DictionaryDefinition.class); + ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), ResourceDefinition.class); if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName()) && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { @@ -186,7 +187,7 @@ public class AutoResourceMappingService { } if (dictionaries != null) { for (ResourceDictionary resourcedictionary : dictionaries) { - DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), DictionaryDefinition.class); + ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class); PropertyDefinition property = new PropertyDefinition(); property.setRequired(true); ResourceAssignment resourceAssignment = new ResourceAssignment(); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 9ab319cb7..3a5c4fde8 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.google.common.base.Preconditions; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -26,7 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType; import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; @@ -160,26 +162,21 @@ public class DataBaseInitService { fileName = file.getFilename(); log.trace("Loading : {}", fileName); String definitionContent = getResourceContent(file); - DictionaryDefinition dictionaryDefinition = - JacksonUtils.readValue(definitionContent, DictionaryDefinition.class); + ResourceDefinition dictionaryDefinition = + JacksonUtils.readValue(definitionContent, ResourceDefinition.class); if (dictionaryDefinition != null) { + Preconditions.checkNotNull(dictionaryDefinition.getProperty(), "Failed to get Property Definition"); ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath()); resourceDictionary.setName(dictionaryDefinition.getName()); resourceDictionary.setDefinition(definitionContent); - if (dictionaryDefinition.getValidValues() != null) - resourceDictionary - .setValidValues(String.valueOf(dictionaryDefinition.getValidValues())); - - if (dictionaryDefinition.getSampleValue() != null) - resourceDictionary - .setValidValues(String.valueOf(dictionaryDefinition.getSampleValue())); - resourceDictionary.setResourceType(dictionaryDefinition.getResourceType()); - resourceDictionary.setDataType(dictionaryDefinition.getDataType()); - resourceDictionary.setEntrySchema(dictionaryDefinition.getEntrySchema()); - resourceDictionary.setDescription(dictionaryDefinition.getDescription()); + resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription()); + resourceDictionary.setDataType(dictionaryDefinition.getProperty().getType()); + if(dictionaryDefinition.getProperty().getEntrySchema() != null){ + resourceDictionary.setEntrySchema(dictionaryDefinition.getProperty().getEntrySchema().getType()); + } resourceDictionary.setUpdatedBy(dictionaryDefinition.getUpdatedBy()); if (StringUtils.isBlank(dictionaryDefinition.getTags())) { resourceDictionary.setTags( diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java index b9567db13..4bb87d7fc 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +19,10 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema; +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; import org.onap.ccsdk.apps.controllerblueprints.service.validator.ResourceDictionaryValidator; @@ -108,24 +111,32 @@ public class ResourceDictionaryService { if (resourceDictionary != null) { ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); - DictionaryDefinition dictionaryDefinition = - JacksonUtils.readValue(resourceDictionary.getDefinition(), DictionaryDefinition.class); + ResourceDefinition resourceDefinition = + JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); - if (dictionaryDefinition == null) { + if (resourceDefinition == null) { throw new BluePrintException( "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition()); } - dictionaryDefinition.setName(resourceDictionary.getName()); - dictionaryDefinition.setResourcePath(resourceDictionary.getResourcePath()); - dictionaryDefinition.setResourceType(resourceDictionary.getResourceType()); - dictionaryDefinition.setDataType(resourceDictionary.getDataType()); - dictionaryDefinition.setEntrySchema(resourceDictionary.getEntrySchema()); - dictionaryDefinition.setTags(resourceDictionary.getTags()); - dictionaryDefinition.setDescription(resourceDictionary.getDescription()); - dictionaryDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); + resourceDefinition.setName(resourceDictionary.getName()); + resourceDefinition.setResourcePath(resourceDictionary.getResourcePath()); + resourceDefinition.setResourceType(resourceDictionary.getResourceType()); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(resourceDictionary.getDataType()); + propertyDefinition.setDescription(resourceDictionary.getDescription()); + if(StringUtils.isNotBlank(resourceDictionary.getEntrySchema())){ + EntrySchema entrySchema = new EntrySchema(); + entrySchema.setType(resourceDictionary.getEntrySchema()); + propertyDefinition.setEntrySchema(entrySchema); + }else{ + propertyDefinition.setEntrySchema(null); + } + resourceDefinition.setTags(resourceDictionary.getTags()); + resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); - String definitionContent = JacksonUtils.getJson(dictionaryDefinition, true); + String definitionContent = JacksonUtils.getJson(resourceDefinition, true); resourceDictionary.setDefinition(definitionContent); Optional dbResourceDictionaryData = diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java index 73d6eca99..8257dc365 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,14 +51,6 @@ public class ResourceDictionaryRestTest { @Autowired protected ResourceDictionaryRest resourceDictionaryRest; - @Before - public void setUp() { - SourceDeserializer.registerSource("db", SourceDb.class); - SourceDeserializer.registerSource("input", SourceInput.class); - SourceDeserializer.registerSource("mdsal", SourceMdsal.class); - SourceDeserializer.registerSource("default", SourceDefault.class); - } - @Test public void test01SaveDataDictionary() throws Exception { String definition = IOUtils.toString( diff --git a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json index 2b392054d..986ba7066 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json +++ b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json @@ -1,19 +1,19 @@ { - "name": "v4-aggregat-list", - "description": "This collection v4-aggregate list", - "valid-values": null, - "sample-value": null, - "updated-by": "Brinda Santh (bs2796)", - "resource-type": "ONAP", - "resource-path": "/v4-aggregat-list", - "data-type": "list", - "entry-schema": "dt-v4-aggregate", - "tags": null, - "default": null, - "source": { - "input": { - - } - }, - "candidate-dependency": null + "name": "v4-aggregat-list", + "property": { + "description": "name of the ", + "type": "list", + "entry_schema": { + "type": "dt-v4-aggregate" + } + }, + "updated-by": "Brinda Santh (bs2796)", + "resource-type": "ONAP", + "resource-path": "/v4-aggregat-list", + "tags": null, + "sources": { + "input": { + "type": "source-input" + } + } } \ No newline at end of file -- cgit 1.2.3-korg