Controller Blueprints Microservice 57/66157/1
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Wed, 12 Sep 2018 16:26:31 +0000 (16:26 +0000)
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Wed, 12 Sep 2018 16:26:31 +0000 (16:26 +0000)
Add dynamic resource source mapping rest service.

Change-Id: I59274a4c0162bc6718c4248788c0e7f36830a129
Issue-ID: CCSDK-556
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
14 files changed:
components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt
components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt [new file with mode: 0644]
components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java [new file with mode: 0644]
ms/controllerblueprints/application/load/resource_dictionary/default-source.json [new file with mode: 0644]
ms/controllerblueprints/application/opt/app/onap/config/application.properties
ms/controllerblueprints/application/src/test/resources/application.properties
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt [moved from components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt with 90% similarity]
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java [moved from components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java with 78% similarity]
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java
ms/controllerblueprints/modules/service/src/test/resources/application.properties
ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json [moved from components/resource-dict/src/test/resources/enrich/simple-enrich.json with 100% similarity]

index ff26087..d141ed0 100644 (file)
@@ -1,5 +1,6 @@
 /*
  *  Copyright © 2018 IBM.
+ *  Modifications Copyright © 2017-2018 AT&T Intellectual Property.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -92,3 +93,8 @@ open class ResourceAssignment {
  * Default Source, Database Source, Rest Sources, etc)
  */
 interface ResourceSource : Serializable
+
+
+open class ResourceSourceMapping {
+    lateinit var resourceSourceMappings: MutableMap<String, String>
+}
diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt
new file mode 100644 (file)
index 0000000..2911ab2
--- /dev/null
@@ -0,0 +1,47 @@
+/*\r
+ *  Copyright © 2017-2018 AT&T Intellectual Property.\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory\r
+\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
+import org.onap.ccsdk.apps.controllerblueprints.core.format\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping\r
+\r
+/**\r
+ * ResourceSourceMappingFactory.\r
+ *\r
+ * @author Brinda Santh\r
+ */\r
+object ResourceSourceMappingFactory {\r
+\r
+    private val resourceSourceMappings: MutableMap<String, String> = hashMapOf()\r
+\r
+    fun registerSourceMapping(sourceInstance: String, nodeTypeName: String) {\r
+        resourceSourceMappings[sourceInstance] = nodeTypeName\r
+    }\r
+\r
+    fun getRegisterSourceMapping(sourceInstance: String): String {\r
+        return resourceSourceMappings[sourceInstance]\r
+                ?: throw BluePrintException(format("failed to get source({}) mapping", sourceInstance))\r
+    }\r
+\r
+    fun getRegisterSourceMapping(): ResourceSourceMapping {\r
+        val resourceSourceMapping = ResourceSourceMapping()\r
+        resourceSourceMapping.resourceSourceMappings = resourceSourceMappings\r
+        return resourceSourceMapping\r
+    }\r
+}\r
+\r
diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java
new file mode 100644 (file)
index 0000000..b67aa79
--- /dev/null
@@ -0,0 +1,42 @@
+/*\r
+ *  Copyright © 2017-2018 AT&T Intellectual Property.\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory;\r
+\r
+import org.junit.Test;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping;\r
+import org.springframework.util.Assert;\r
+\r
+public class ResourceSourceMappingFactoryTest {\r
+\r
+    @Test\r
+    public void testRegisterResourceMapping() {\r
+\r
+        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("db", "source-db");\r
+        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input");\r
+        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default");\r
+        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("mdsal", "source-rest");\r
+\r
+        String nodeTypeName = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping("db");\r
+        Assert.notNull(nodeTypeName, "Failed to get db mapping");\r
+\r
+        ResourceSourceMapping resourceSourceMapping = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping();\r
+        Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping");\r
+        Assert.notNull(resourceSourceMapping.getResourceSourceMappings(), "Failed to get resource source mappings");\r
+\r
+    }\r
+\r
+}\r
diff --git a/ms/controllerblueprints/application/load/resource_dictionary/default-source.json b/ms/controllerblueprints/application/load/resource_dictionary/default-source.json
new file mode 100644 (file)
index 0000000..64bfa0c
--- /dev/null
@@ -0,0 +1,16 @@
+{\r
+  "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com",\r
+  "name": "default-source",\r
+  "property" :{\r
+    "description": "name of the ",\r
+    "type": "string"\r
+  },\r
+  "updated-by": "brindasanth@onap.com",\r
+  "sources": {\r
+    "default": {\r
+      "type": "source-default",\r
+      "properties": {\r
+      }\r
+    }\r
+  }\r
+}
\ No newline at end of file
index b65d5bf..d281482 100644 (file)
@@ -53,4 +53,7 @@ load.dataTypePath=load/model_type/data_type
 load.nodeTypePath=load/model_type/node_type
 load.artifactTypePath=load/model_type/artifact_type
 load.resourceDictionaryPath=load/resource_dictionary
-load.blueprintsPath=load/blueprints
\ No newline at end of file
+load.blueprintsPath=load/blueprints
+
+# Load Resource Source Mappings
+resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest
\ No newline at end of file
index 3bcbbd9..e2d040c 100644 (file)
@@ -33,4 +33,7 @@ load.dataTypePath=load/model_type/data_type
 load.nodeTypePath=load/model_type/node_type\r
 load.artifactTypePath=load/model_type/artifact_type\r
 load.resourceDictionaryPath=load/resource_dictionary\r
-load.blueprintsPath=load/blueprints
\ No newline at end of file
+load.blueprintsPath=load/blueprints\r
+\r
+# Load Resource Source Mappings\r
+resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest
\ No newline at end of file
index 5a4a287..fc7410f 100644 (file)
 \r
 package org.onap.ccsdk.apps.controllerblueprints.service;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import org.apache.commons.collections.CollectionUtils;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory;\r
+import org.springframework.beans.factory.annotation.Value;\r
 import org.springframework.stereotype.Component;\r
 \r
 import javax.annotation.PostConstruct;\r
+import java.util.List;\r
 \r
 @Component\r
 @SuppressWarnings("unused")\r
 public class ApplicationRegistrationService {\r
+    private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationRegistrationService.class);\r
+\r
+    @Value("#{'${resourceSourceMappings}'.split(',')}")\r
+    private List<String> resourceSourceMappings;\r
 \r
     @PostConstruct\r
-    public void register(){\r
+    public void register() {\r
         registerDictionarySources();\r
     }\r
 \r
-    public void registerDictionarySources(){\r
-\r
+    public void registerDictionarySources() {\r
+        log.info("Registering Dictionary Sources : {}", resourceSourceMappings);\r
+        if (CollectionUtils.isNotEmpty(resourceSourceMappings)) {\r
+            resourceSourceMappings.forEach(resourceSourceMapping -> {\r
+                String[] mappingKeyValue = resourceSourceMapping.split("=");\r
+                if (mappingKeyValue != null && mappingKeyValue.length == 2) {\r
+                    ResourceSourceMappingFactory.INSTANCE.registerSourceMapping(mappingKeyValue[0].trim(), mappingKeyValue[1].trim());\r
+                } else {\r
+                    log.warn("failed to get resource source mapping {}", resourceSourceMapping);\r
+                }\r
+            });\r
+        }\r
     }\r
 }\r
index 62aa0e2..fd73db3 100644 (file)
@@ -22,8 +22,9 @@ import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.validator.ResourceDictionaryValidator;\r
@@ -105,7 +106,7 @@ public class ResourceDictionaryService {
      */\r
     public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) {\r
         Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing");\r
-        Preconditions.checkNotNull(resourceDictionary.getDefinition(),"Resource Dictionary definition information is missing");\r
+        Preconditions.checkNotNull(resourceDictionary.getDefinition(), "Resource Dictionary definition information is missing");\r
 \r
         ResourceDefinition resourceDefinition = resourceDictionary.getDefinition();\r
         Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content");\r
@@ -153,4 +154,12 @@ public class ResourceDictionaryService {
         Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing.");\r
         resourceDictionaryRepository.deleteByName(name);\r
     }\r
+\r
+    /**\r
+     * This is a getResourceSourceMapping service\r
+     *\r
+     */\r
+    public ResourceSourceMapping getResourceSourceMapping() {\r
+        return ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping();\r
+    }\r
 }\r
index e0cf6c6..287d413 100644 (file)
@@ -18,6 +18,7 @@
 package org.onap.ccsdk.apps.controllerblueprints.service.rs;\r
 \r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\r
 import org.springframework.http.MediaType;\r
@@ -76,4 +77,10 @@ public class ResourceDictionaryRest {
 \r
     }\r
 \r
+    @GetMapping(path = "/source-mapping", produces = MediaType.APPLICATION_JSON_VALUE)\r
+    public @ResponseBody\r
+    ResourceSourceMapping getResourceSourceMapping() {\r
+        return resourceDictionaryService.getResourceSourceMapping();\r
+    }\r
+\r
 }\r
@@ -14,7 +14,7 @@
  *  limitations under the License.\r
  */\r
 \r
-package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service\r
+package org.onap.ccsdk.apps.controllerblueprints.service.enhancer\r
 \r
 import com.att.eelf.configuration.EELFLogger\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
@@ -24,6 +24,8 @@ import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerSe
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition\r
 import com.att.eelf.configuration.EELFManager\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService\r
 \r
 /**\r
  * ResourceAssignmentEnhancerService.\r
@@ -81,6 +83,6 @@ open class ResourceAssignmentEnhancerDefaultService(private val resourceDefiniti
     }\r
 \r
     private fun getResourceDefinition(name: String): ResourceDefinition {\r
-        return resourceDefinitionRepoService.getResourceDefinition(name)!!.block()!!\r
+        return resourceDefinitionRepoService.getResourceDefinition(name).block()!!\r
     }\r
 }
\ No newline at end of file
@@ -14,7 +14,7 @@
  *  limitations under the License.\r
  */\r
 \r
-package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service;\r
+package org.onap.ccsdk.apps.controllerblueprints.service.enhancer;\r
 \r
 import org.junit.Assert;\r
 import org.junit.Test;\r
@@ -22,6 +22,8 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionFileRepoService;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService;\r
 \r
 import java.util.List;\r
 \r
@@ -36,9 +38,9 @@ public class ResourceAssignmentEnhancerServiceTest {
     public void testEnhanceBluePrint() throws BluePrintException {\r
 \r
         List<ResourceAssignment> resourceAssignments = JacksonReactorUtils\r
-                .getListFromClassPathFile("enrich/simple-enrich.json", ResourceAssignment.class).block();\r
+                .getListFromClassPathFile("enhance/simple-enrich.json", ResourceAssignment.class).block();\r
         Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments);\r
-        ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("load");\r
+        ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("./../../application/load");\r
         ResourceAssignmentEnhancerService resourceAssignmentEnhancerService =\r
                 new ResourceAssignmentEnhancerDefaultService(resourceDefinitionRepoService);\r
         ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments);\r
index 5955ae1..ac786d0 100644 (file)
@@ -26,6 +26,7 @@ import org.junit.runners.MethodSorters;
 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\r
 import com.att.eelf.configuration.EELFLogger;\r
 import com.att.eelf.configuration.EELFManager;\r
@@ -103,4 +104,11 @@ public class ResourceDictionaryRestTest {
 \r
     }\r
 \r
+    @Test\r
+    public void test03GetResourceSourceMapping() {\r
+        ResourceSourceMapping resourceSourceMapping = resourceDictionaryRest.getResourceSourceMapping();\r
+        org.springframework.util.Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping");\r
+        org.springframework.util.Assert.notNull(resourceSourceMapping.getResourceSourceMappings(), "Failed to get resource source mappings");\r
+    }\r
+\r
 }\r
index 429588b..3a913b7 100644 (file)
@@ -28,4 +28,7 @@ load.dataTypePath=./../../application/load/model_type/data_type
 load.nodeTypePath=./../../application/load/model_type/node_type
 load.artifactTypePath=./../../application/load/model_type/artifact_type
 load.resourceDictionaryPath=./../../application/load/resource_dictionary
-load.blueprintsPath=./../../application/load/blueprints
\ No newline at end of file
+load.blueprintsPath=./../../application/load/blueprints
+
+# Load Resource Source Mappings
+resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest
\ No newline at end of file