Controller Blueprints Microservice
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>
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/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt [deleted file]
components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java [new file with mode: 0644]
components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java [deleted file]
components/resource-dict/src/test/resources/enrich/simple-enrich.json [deleted file]

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/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt
deleted file mode 100644 (file)
index c5a78a9..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*\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.service\r
-\r
-import com.att.eelf.configuration.EELFLogger\r
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate\r
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDefaultService\r
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerService\r
-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
-\r
-/**\r
- * ResourceAssignmentEnhancerService.\r
- *\r
- * @author Brinda Santh\r
- */\r
-interface ResourceAssignmentEnhancerService {\r
-\r
-    @Throws(BluePrintException::class)\r
-    fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService,\r
-                         resourceAssignments: List<ResourceAssignment>)\r
-\r
-    @Throws(BluePrintException::class)\r
-    fun enhanceBluePrint(resourceAssignments: List<ResourceAssignment>): ServiceTemplate\r
-}\r
-\r
-/**\r
- * ResourceAssignmentEnhancerDefaultService.\r
- *\r
- * @author Brinda Santh\r
- */\r
-open class ResourceAssignmentEnhancerDefaultService(private val resourceDefinitionRepoService: ResourceDefinitionRepoService)\r
-    : ResourceAssignmentEnhancerService {\r
-    private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java)\r
-\r
-    /**\r
-     * Get the defined source instance from the ResourceAssignment,\r
-     * then get the NodeType of the Sources assigned\r
-     */\r
-    override fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService,\r
-                                  resourceAssignments: List<ResourceAssignment>) {\r
-\r
-        // Iterate the Resource Assignment and\r
-        resourceAssignments.map { resourceAssignment ->\r
-            val dictionaryName = resourceAssignment.dictionaryName!!\r
-            val dictionarySource = resourceAssignment.dictionarySource!!\r
-            log.info("Enriching Assignment name({}), dictionary name({}), source({})", resourceAssignment.name,\r
-                    dictionaryName, dictionarySource)\r
-            // Get the Resource Definition from Repo\r
-            val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName)\r
-\r
-            val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource)\r
-\r
-            // Enrich as NodeTemplate\r
-            bluePrintEnhancerService.enrichNodeTemplate(dictionarySource, sourceNodeTemplate!!)\r
-        }\r
-    }\r
-\r
-    override fun enhanceBluePrint(resourceAssignments: List<ResourceAssignment>): ServiceTemplate {\r
-        val bluePrintEnhancerService = BluePrintEnhancerDefaultService(resourceDefinitionRepoService)\r
-        bluePrintEnhancerService.serviceTemplate = ServiceTemplate()\r
-        bluePrintEnhancerService.initialCleanUp()\r
-        enhanceBluePrint(bluePrintEnhancerService, resourceAssignments)\r
-        return bluePrintEnhancerService.serviceTemplate\r
-    }\r
-\r
-    private fun getResourceDefinition(name: String): ResourceDefinition {\r
-        return resourceDefinitionRepoService.getResourceDefinition(name)!!.block()!!\r
-    }\r
-}
\ No newline at end of file
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/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java
deleted file mode 100644 (file)
index 57c8509..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*\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.service;\r
-\r
-import org.junit.Assert;\r
-import org.junit.Test;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
-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
-\r
-import java.util.List;\r
-\r
-/**\r
- * ResourceAssignmentEnhancerService.\r
- *\r
- * @author Brinda Santh\r
- */\r
-public class ResourceAssignmentEnhancerServiceTest {\r
-\r
-    @Test\r
-    public void testEnhanceBluePrint() throws BluePrintException {\r
-\r
-        List<ResourceAssignment> resourceAssignments = JacksonReactorUtils\r
-                .getListFromClassPathFile("enrich/simple-enrich.json", ResourceAssignment.class).block();\r
-        Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments);\r
-        ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("load");\r
-        ResourceAssignmentEnhancerService resourceAssignmentEnhancerService =\r
-                new ResourceAssignmentEnhancerDefaultService(resourceDefinitionRepoService);\r
-        ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments);\r
-        Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate);\r
-    }\r
-}\r
-\r
diff --git a/components/resource-dict/src/test/resources/enrich/simple-enrich.json b/components/resource-dict/src/test/resources/enrich/simple-enrich.json
deleted file mode 100644 (file)
index 641da80..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-[\r
-  {\r
-    "name": "rs-db-source",\r
-    "input-param": true,\r
-    "property": {\r
-      "type": "string",\r
-      "required": true\r
-    },\r
-    "dictionary-name": "db-source",\r
-    "dictionary-source": "db",\r
-    "dependencies": [\r
-      "input-source"\r
-    ]\r
-  },\r
-  {\r
-    "name": "ra-default-source",\r
-    "input-param": true,\r
-    "property": {\r
-      "type": "string",\r
-      "required": true\r
-    },\r
-    "dictionary-name": "default-source",\r
-    "dictionary-source": "default",\r
-    "dependencies": []\r
-  },\r
-  {\r
-    "name": "ra-input-source",\r
-    "input-param": true,\r
-    "property": {\r
-      "type": "string",\r
-      "required": true\r
-    },\r
-    "dictionary-name": "input-source",\r
-    "dictionary-source": "input",\r
-    "dependencies": []\r
-  }\r
-]\r