Merge "Add workflow output resolution"
authorDan Timoney <dtimoney@att.com>
Fri, 22 Mar 2019 16:07:47 +0000 (16:07 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 22 Mar 2019 16:07:47 +0000 (16:07 +0000)
41 files changed:
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/node_types.json
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/resources_definition_types.json
components/model-catalog/blueprint-model/test-blueprint/golden/Definitions/node_types.json
components/model-catalog/blueprint-model/test-blueprint/golden/Definitions/resources_definition_types.json
components/model-catalog/blueprint-model/test-blueprint/golden/Templates/vf-module-1-mapping.json
components/model-catalog/blueprint-model/test-blueprint/golden/Templates/vfw-interface-mapping.json
components/model-catalog/definition-type/starter-type/node_type/source-processor-db.json [new file with mode: 0644]
components/model-catalog/resource-dictionary/test-dictionary/vf-module-type.json
docs/index.rst
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt
ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibConfiguration.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BluePrintDBLibData.kt
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt [deleted file]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt [new file with mode: 0644]
ms/cds-sdc-listener/application/pom.xml
ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerApplication.java
ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerClient.java [new file with mode: 0644]
ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerConfiguration.java [new file with mode: 0644]
ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerDto.java [new file with mode: 0644]
ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerNotificationCallback.java [new file with mode: 0644]
ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/exceptions/CdsSdcListenerException.java [new file with mode: 0644]
ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/service/ListenerService.java [new file with mode: 0644]
ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/service/ListenerServiceImpl.java [new file with mode: 0644]
ms/cds-sdc-listener/application/src/main/resources/application.yml [new file with mode: 0644]
ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerClientTest.java [new file with mode: 0644]
ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerConfigurationTest.java [new file with mode: 0644]
ms/controllerblueprints/application/src/main/resources/application-dev.properties
ms/controllerblueprints/application/src/main/resources/application.properties
ms/controllerblueprints/application/src/test/resources/application.properties
ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt
ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java
ms/controllerblueprints/modules/service/src/test/resources/application.properties

index 8f6c44f..68a8ae6 100644 (file)
       },
       "derived_from": "tosca.nodes.ResourceSource"
     },
-    "source-primary-db": {
+    "source-processor-db": {
       "description": "This is Database Resource Source Node Type",
       "version": "1.0.0",
       "properties": {
index eaf45b3..6e3d5e9 100644 (file)
@@ -26,8 +26,8 @@
         "type": "source-input",
         "properties": {}
       },
-      "primary-db": {
-        "type": "source-primary-db",
+      "processor-db": {
+        "type": "source-processor-db",
         "properties": {
           "endpoint-selector": "dynamic-db-source",
           "query": "SELECT artifact_name FROM sdnctl.BLUEPRINT_RUNTIME where artifact_version=\"1.0.0\"",
index b058692..f143e56 100644 (file)
       },
       "derived_from" : "tosca.nodes.ResourceSource"
     },
-    "source-primary-db" : {
+    "source-processor-db" : {
       "description" : "This is Database Resource Source Node Type",
       "version" : "1.0.0",
       "properties" : {
index 446a8a6..15f02a1 100644 (file)
     },
     "updated-by" : "adetalhouet",
     "sources" : {
-      "primary-db" : {
-        "type" : "source-primary-db",
+      "processor-db" : {
+        "type" : "source-processor-db",
         "properties" : {
           "type" : "SQL",
           "query" : "select sdnctl.demo.value as value from sdnctl.demo where sdnctl.demo.id=:vfmoduleid",
index eba259e..b7335b5 100644 (file)
@@ -18,7 +18,7 @@
       "type": "string"
     },
     "dictionary-name": "vf-module-type",
-    "dictionary-source": "primary-db",
+    "dictionary-source": "processor-db",
     "dependencies": [
       "vf-module-number"
     ]
index 149d3eb..c1ebe56 100644 (file)
@@ -55,7 +55,7 @@
       "type": "string"
     },
     "dictionary-name": "vf-module-type",
-    "dictionary-source": "primary-db",
+    "dictionary-source": "processor-db",
     "dependencies": [
       "vf-module-number"
     ]
diff --git a/components/model-catalog/definition-type/starter-type/node_type/source-processor-db.json b/components/model-catalog/definition-type/starter-type/node_type/source-processor-db.json
new file mode 100644 (file)
index 0000000..702748f
--- /dev/null
@@ -0,0 +1,48 @@
+{
+  "description": "This is Database Resource Source Node Type",
+  "version": "1.0.0",
+  "properties": {
+    "type": {
+      "required": true,
+      "type": "string",
+      "constraints": [
+        {
+          "valid_values": [
+            "SQL",
+            "PLSQL"
+          ]
+        }
+      ]
+    },
+    "endpoint-selector": {
+      "required": false,
+      "type": "string"
+    },
+    "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
index b06057c..9e8c409 100644 (file)
@@ -7,8 +7,8 @@
   },
   "updated-by": "adetalhouet",
   "sources": {
-    "primary-db": {
-      "type": "source-primary-db",
+    "processor-db": {
+      "type": "source-processor-db",
       "properties": {
         "type": "SQL",
         "query": "select sdnctl.demo.value as value from sdnctl.demo where sdnctl.demo.id=:vfmoduleid",
index d2a0e8d..d472559 100644 (file)
@@ -3,7 +3,7 @@
 .. Copyright (C) 2019 IBM.
 
 CCSDK APPS DOCUMENTATION REPOSITORY
-------------------------------------------------
+------------------------------------
 .. toctree::
    :maxdepth: 1
 
@@ -14,6 +14,9 @@ Introduction:
 Microservices:
 =============
 
+.. toctree::
+   :maxdepth: 1
+   
    microservices/controllerBlueprintStudioProcessor
    microservices/bluePrintsProcessor
    microservices/neng
index cf11cfd..2dd73ef 100644 (file)
@@ -19,8 +19,10 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core
 import com.google.common.collect.ImmutableList
 import com.google.common.collect.ImmutableSet
 import org.apache.sshd.client.SshClient
+import org.apache.sshd.client.channel.ChannelSubsystem
 import org.apache.sshd.client.channel.ClientChannel
 import org.apache.sshd.client.session.ClientSession
+import org.apache.sshd.client.session.ClientSessionImpl
 import org.apache.sshd.common.FactoryManager
 import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
@@ -40,6 +42,7 @@ import java.util.concurrent.ConcurrentHashMap
 import java.util.concurrent.ExecutionException
 import java.util.concurrent.TimeUnit
 import java.util.concurrent.TimeoutException
+import java.util.concurrent.atomic.AtomicReference
 
 class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcService: NetconfRpcService) :
     NetconfSession {
@@ -273,4 +276,12 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
             }
         }
     }
+
+    fun sessionstatus(state:String): Boolean{
+        return when (state){
+            "Close" -> channel.isClosed
+            "Open" -> channel.isOpen
+            else -> false
+        }
+    }
 }
\ No newline at end of file
index 045725c..e7a5143 100644 (file)
  */
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
 
+import org.apache.sshd.client.channel.ChannelSubsystem
+import org.apache.sshd.client.session.ClientSessionImpl
 import org.junit.After
 import org.junit.Assert
 import org.junit.Before
+import org.junit.Test
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfRpcServiceImpl
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.mocks.NetconfDeviceSimulator
+import java.util.concurrent.atomic.AtomicReference
+import kotlin.script.experimental.api.asSuccess
 
 class NetconfSessionImplTest {
 
@@ -62,4 +67,45 @@ class NetconfSessionImplTest {
         Assert.assertTrue(!netconfSession.getDeviceCapabilitiesSet().isEmpty())
     }
 
+    @Test
+    fun testNetconfSessionconnect() {
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
+        netconfSession.connect()
+        Assert.assertTrue(netconfSession.sessionstatus("Open"))
+    }
+
+    @Test
+    fun testNetconfSessionreconnect() {
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
+        netconfSession.connect()
+        netconfSession.reconnect()
+        Assert.assertTrue(netconfSession.sessionstatus("Open"))
+
+    }
+    @Test
+    fun testNetconfSessiondisconnect() {
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
+        netconfSession.connect()
+        netconfSession.disconnect()
+        Assert.assertTrue(netconfSession.sessionstatus("Close"))
+
+    }
+    @Test
+    fun testNetconfSessioncheckAndReestablish() {
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
+        netconfSession.connect()
+        netconfSession.checkAndReestablish()
+        Assert.assertTrue(netconfSession.sessionstatus("Open"))
+
+
+    }
+    @Test
+    fun testNetconfSessionconnecgetDeviceInfo() {
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
+        netconfSession.connect()
+        Assert.assertNotNull(netconfSession.getDeviceInfo())
+        Assert.assertFalse(!netconfSession.getDeviceCapabilitiesSet().isEmpty())
+    }
+
+
 }
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt
new file mode 100644 (file)
index 0000000..8f1f715
--- /dev/null
@@ -0,0 +1,124 @@
+package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core
+
+import org.junit.After
+import org.junit.Assert
+import org.junit.Before
+import org.junit.Test
+
+import org.junit.Assert.*
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.mocks.NetconfDeviceSimulator
+
+class NetconfRpcServiceImplTest {
+
+    private var device: NetconfDeviceSimulator? = null
+    private var deviceInfo: DeviceInfo? = null
+
+    @Before
+    fun before() {
+        deviceInfo = DeviceInfo().apply {
+            username = "username"
+            password = "password"
+            ipAddress = "localhost"
+            port = 2224
+            connectTimeout = 10
+        }
+
+        device = NetconfDeviceSimulator(deviceInfo!!.port)
+        device!!.start()
+    }
+
+    @After
+    fun after() {
+        device!!.stop()
+    }
+
+    @Test
+    fun setNetconfSession() {
+
+    }
+
+    @Test
+    fun getConfig() {
+
+        val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+        netconfRpcServiceImpl.setNetconfSession(netconfSession)
+        netconfSession.connect()
+        Assert.assertTrue(netconfRpcServiceImpl.getConfig("filter","target").status.equals("failure"))
+    }
+
+
+    @Test
+    fun deleteConfig() {
+
+        val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+        netconfRpcServiceImpl.setNetconfSession(netconfSession)
+        netconfSession.connect()
+        Assert.assertTrue(netconfRpcServiceImpl.deleteConfig("target").status.equals("failure"))
+    }
+
+    @Test
+    fun lock() {
+        val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+        netconfRpcServiceImpl.setNetconfSession(netconfSession)
+        netconfSession.connect()
+        Assert.assertTrue(netconfRpcServiceImpl.lock("target").status.equals("failure"))
+    }
+
+    @Test
+    fun unLock() {
+        val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+        netconfRpcServiceImpl.setNetconfSession(netconfSession)
+        netconfSession.connect()
+        Assert.assertTrue(netconfRpcServiceImpl.unLock("target").status.equals("failure"))
+    }
+
+    @Test
+    fun commit() {
+        val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+        netconfRpcServiceImpl.setNetconfSession(netconfSession)
+        netconfSession.connect()
+        Assert.assertTrue(netconfRpcServiceImpl.commit(true,60,"persist","1").status.equals("failure"))
+
+    }
+
+    @Test
+    fun cancelCommit() {
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(DeviceInfo()))
+        val netconfRpcServiceImpl = NetconfRpcServiceImpl(DeviceInfo())
+        netconfRpcServiceImpl.setNetconfSession(netconfSession)
+        netconfSession.connect()
+
+        Assert.assertNotNull(netconfRpcServiceImpl.cancelCommit("1"))
+    }
+
+    @Test
+    fun discardConfig() {
+        val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+        netconfRpcServiceImpl.setNetconfSession(netconfSession)
+        netconfSession.connect()
+        Assert.assertTrue(netconfRpcServiceImpl.discardConfig().status.equals("failure"))
+
+    }
+
+    @Test
+    fun editConfig() {
+    }
+
+    @Test
+    fun validate() {
+        val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!)
+        val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl)
+        netconfRpcServiceImpl.setNetconfSession(netconfSession)
+        netconfSession.connect()
+        Assert.assertTrue(netconfRpcServiceImpl.validate("target").status.equals("failure"))
+
+    }
+
+}
\ No newline at end of file
index d4c27b1..8a60d80 100644 (file)
@@ -35,7 +35,7 @@ class RpcMessageUtilsTest {
         val filterContent = "Test-Filter-Content"
 
         val result =
-            NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "")
+                NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "")
 
         assertTrue(NetconfMessageUtils.validateRPCXML(result))
         Assert.assertEquals(checkString, result)
@@ -46,15 +46,16 @@ class RpcMessageUtilsTest {
     fun editConfig() {
         val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                 + "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
-                + "<get-config><source><candidate/></source><filter type=\"subtree\">Test-Filter-Content</filter>"
-                + "</get-config></rpc>")
+                + "<edit-config><target><candidate/></target><default-operation>Test-Default-Operation</default-operation>"
+                + "<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">Test-Filter-Content</config></edit-config></rpc>")
 
         val messageId = "Test-Message-ID"
         val configType = NetconfDatastore.CANDIDATE.datastore
         val filterContent = "Test-Filter-Content"
+        val defaultOperation = "Test-Default-Operation"
 
         val result =
-            NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "")
+                NetconfMessageUtils.editConfig(messageId, configType, defaultOperation, filterContent).replace("[\n\r\t]".toRegex(), "")
 
         assertTrue(NetconfMessageUtils.validateRPCXML(result))
         Assert.assertEquals(checkString, result)
@@ -78,16 +79,16 @@ class RpcMessageUtilsTest {
     @Test
     fun cancelCommit() {
         val checkString =
-            ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
-                    "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
-                    "<cancel-commit>" +
-                    "<persist-id>1234</persist-id>" +
-                    "</cancel-commit></rpc>")
+                ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+                        "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+                        "<cancel-commit>" +
+                        "<persist-id>1234</persist-id>" +
+                        "</cancel-commit></rpc>")
 
         val messageId = "Test-Message-ID"
 
         val cancelCommitPersistId =
-            NetconfMessageUtils.cancelCommit(messageId, "1234").replace("[\n\r\t]".toRegex(), "")
+                NetconfMessageUtils.cancelCommit(messageId, "1234").replace("[\n\r\t]".toRegex(), "")
 
         assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitPersistId))
         Assert.assertEquals(checkString, cancelCommitPersistId)
@@ -96,10 +97,10 @@ class RpcMessageUtilsTest {
     @Test
     fun cancelCommitNoPersistId() {
         val checkString =
-            ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
-                    "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
-                    "<cancel-commit>" +
-                    "</cancel-commit></rpc>")
+                ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+                        "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+                        "<cancel-commit>" +
+                        "</cancel-commit></rpc>")
 
         val messageId = "Test-Message-ID"
 
@@ -120,7 +121,7 @@ class RpcMessageUtilsTest {
         val commit = NetconfMessageUtils.commit(messageId, false, 0, "", "").replace("[\n\r\t]".toRegex(), "")
 
         val commitWithPersistButNotConfirmed =
-            NetconfMessageUtils.commit(messageId, false, 0, "1234", "").replace("[\n\r\t]".toRegex(), "")
+                NetconfMessageUtils.commit(messageId, false, 0, "1234", "").replace("[\n\r\t]".toRegex(), "")
 
         assertTrue(NetconfMessageUtils.validateRPCXML(commit))
         Assert.assertEquals(checkString, commit)
@@ -131,11 +132,11 @@ class RpcMessageUtilsTest {
     @Test
     fun commitPersistId() {
         val checkString =
-            ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
-                    "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
-                    "<commit>" +
-                    "<persist-id>1234</persist-id>" +
-                    "</commit></rpc>")
+                ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+                        "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+                        "<commit>" +
+                        "<persist-id>1234</persist-id>" +
+                        "</commit></rpc>")
 
         val messageId = "Test-Message-ID"
 
@@ -147,7 +148,7 @@ class RpcMessageUtilsTest {
             NetconfMessageUtils.commit(messageId, true, 30, "", "1234").replace("[\n\r\t]".toRegex(), "")
         } catch (e: NetconfException) {
             Assert.assertEquals("Can't proceed <commit> with both confirmed flag and persistId(1234) specified. Only one should be specified.",
-                e.message)
+                    e.message)
             return
         }
 
@@ -157,13 +158,13 @@ class RpcMessageUtilsTest {
     @Test
     fun commitPersist() {
         val checkString =
-            ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
-                    "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
-                    "<commit>" +
-                    "<confirmed/>" +
-                    "<confirm-timeout>30</confirm-timeout>" +
-                    "<persist>1234</persist>" +
-                    "</commit></rpc>")
+                ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+                        "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+                        "<commit>" +
+                        "<confirmed/>" +
+                        "<confirm-timeout>30</confirm-timeout>" +
+                        "<persist>1234</persist>" +
+                        "</commit></rpc>")
 
         val messageId = "Test-Message-ID"
 
@@ -176,7 +177,7 @@ class RpcMessageUtilsTest {
             NetconfMessageUtils.commit(messageId, false, 30, "1234", "1234").replace("[\n\r\t]".toRegex(), "")
         } catch (e: NetconfException) {
             Assert.assertEquals("Can't proceed <commit> with both persist(1234) and persistId(1234) specified. Only one should be specified.",
-                e.message)
+                    e.message)
             return
         }
         fail()
@@ -240,5 +241,66 @@ class RpcMessageUtilsTest {
         Assert.assertEquals(checkString, result)
     }
 
+    @Test
+    fun getMsgId() {
+        val checkString = ("testmessage")
+
+        var messageId = "message-id=\"testmessage\""
+        var result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "")
+        Assert.assertEquals(checkString, result)
+
+        messageId = "message-id=\"hello\""
+        result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "")
+        Assert.assertEquals("hello", result)
+
+        messageId = "message-id"
+        result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "")
+        Assert.assertEquals("", result)
+    }
+
+    @Test
+    fun createHelloString() {
+        val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">  "
+                +"<capabilities>    <capability>hi</capability>    <capability>hello</capability>  </capabilities></hello>]]>]]>")
+
+        val capability = listOf<String>("hi", "hello")
+
+        val result = NetconfMessageUtils.createHelloString(capability).replace("[\n\r\t]".toRegex(), "")
+        Assert.assertEquals(checkString, result)
+    }
+
+    @Test
+    fun validateChunkedFraming() {
+        val reply = ("hello")
+        val result = NetconfMessageUtils.validateChunkedFraming(reply)
+        Assert.assertFalse(result)
+    }
+
+    @Test
+    fun checkReply(){
+        assertTrue(NetconfMessageUtils.checkReply("ok"))
+    }
+
+    @Test
+    fun formatRPCRequest(){
+        val checkString = ("#199" +
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">  <capabilities>    <capability>hi</capability>    <capability>hello</capability>  </capabilities></hello>" +
+                "##")
+
+        val request = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">  "
+                +"<capabilities>    <capability>hi</capability>    <capability>hello</capability>  </capabilities></hello>]]>]]>")
+
+        val messageId = "Test-Message-ID"
+
+        val capabilities = setOf<String>("hi", "hello","urn:ietf:params:netconf:base:1.1")
+
+        val result = NetconfMessageUtils.formatRPCRequest(request,messageId,capabilities).replace("[\n\r\t]".toRegex(), "")
+        Assert.assertEquals(checkString, result)
+
+
+    }
+
+
+
 
 }
\ No newline at end of file
index e38a1cc..a192989 100644 (file)
@@ -19,40 +19,37 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr
 
 import com.fasterxml.jackson.databind.node.JsonNodeFactory
 import com.fasterxml.jackson.databind.node.MissingNode
-import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.DBLibGenericService
+import com.fasterxml.jackson.databind.node.NullNode
+import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibGenericService
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.BluePrintDBLibPropertySevice
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.PrimaryDBLibGenericService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
-import org.onap.ccsdk.apps.controllerblueprints.core.checkEqualsOrThrow
-import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty
-import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
-import org.onap.ccsdk.apps.controllerblueprints.core.nullToEmpty
-import org.onap.ccsdk.apps.controllerblueprints.core.returnNotEmptyOrThrow
+import org.onap.ccsdk.apps.controllerblueprints.core.*
 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.ResourceDictionaryConstants
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.annotation.Scope
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
 import org.springframework.stereotype.Service
+import java.util.*
 
 /**
  * DatabaseResourceAssignmentProcessor
  *
  * @author Kapil Singal
  */
-@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-primary-db")
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-processor-db")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService: DBLibGenericService)
+open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropertySevice: BluePrintDBLibPropertySevice, private val primaryDBLibGenericService: PrimaryDBLibGenericService)
     : ResourceAssignmentProcessor() {
 
     private val logger = LoggerFactory.getLogger(DatabaseResourceAssignmentProcessor::class.java)
 
     override fun getName(): String {
-        return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-primary-db"
+        return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-processor-db"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
@@ -60,33 +57,16 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
             validate(resourceAssignment)
 
             // Check if It has Input
-            val value = getFromInput(resourceAssignment)
-            if (value == null || value is MissingNode) {
-                val dName = resourceAssignment.dictionaryName
-                val dSource = resourceAssignment.dictionarySource
-                val resourceDefinition = resourceDictionaries[dName]
-                        ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName")
-                val resourceSource = resourceDefinition.sources[dSource]
-                        ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
-                val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
-                val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, DatabaseResourceSource::class.java)
-
-                val sql = checkNotNull(sourceProperties.query) { "failed to get request query for $dName under $dSource properties" }
-                val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
-
-                val resolvedInputKeyMapping = resolveInputKeyMappingVariables(inputKeyMapping)
-
-                val resolvedSql = resolveFromInputKeyMapping(sql, resolvedInputKeyMapping)
-
-                logger.info("$dSource dictionary information : ($resolvedSql), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
-                val jdbcTemplate = blueprintDBLibService(sourceProperties)
-
-                val rows = jdbcTemplate.queryForList(resolvedSql, resolvedInputKeyMapping)
-                if (rows.isNullOrEmpty()) {
-                    logger.warn("Failed to get $dSource result for dictionary name ($dName) the query ($resolvedSql)")
+            try {
+                val value = raRuntimeService.getInputValue(resourceAssignment.name)
+                if (value !is NullNode && value !is MissingNode) {
+                    logger.info("processor-db source template key (${resourceAssignment.name}) found from input and value is ($value)")
+                    ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
                 } else {
-                    populateResource(resourceAssignment, sourceProperties, rows)
+                    setValueFromDB(resourceAssignment)
                 }
+            } catch (e: BluePrintProcessorException) {
+                setValueFromDB(resourceAssignment)
             }
 
             // Check the value has populated for mandatory case
@@ -97,12 +77,36 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
         }
     }
 
-    private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): NamedParameterJdbcTemplate {
+    private fun setValueFromDB(resourceAssignment: ResourceAssignment) {
+        val dName = resourceAssignment.dictionaryName
+        val dSource = resourceAssignment.dictionarySource
+        val resourceDefinition = resourceDictionaries[dName]
+                ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName")
+        val resourceSource = resourceDefinition.sources[dSource]
+                ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
+        val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
+        val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, DatabaseResourceSource::class.java)
+
+        val sql = checkNotNull(sourceProperties.query) { "failed to get request query for $dName under $dSource properties" }
+        val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
+
+        logger.info("$dSource dictionary information : ($sql), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
+        val jdbcTemplate = blueprintDBLibService(sourceProperties)
+
+        val rows = jdbcTemplate.query(sql, populateNamedParameter(inputKeyMapping))
+        if (rows.isNullOrEmpty()) {
+            logger.warn("Failed to get $dSource result for dictionary name ($dName) the query ($sql)")
+        } else {
+            populateResource(resourceAssignment, sourceProperties, rows)
+        }
+    }
+
+    private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): BluePrintDBLibGenericService {
         return if (checkNotEmpty(sourceProperties.endpointSelector)) {
             val dbPropertiesJson = raRuntimeService.resolveDSLExpression(sourceProperties.endpointSelector!!)
-            dBLibGenericService.remoteJdbcTemplate(dbPropertiesJson)
+            bluePrintDBLibPropertySevice.JdbcTemplate(dbPropertiesJson)
         } else {
-            dBLibGenericService.primaryJdbcTemplate()
+            primaryDBLibGenericService
         }
 
     }
@@ -111,9 +115,20 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
     private fun validate(resourceAssignment: ResourceAssignment) {
         checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined")
         checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
-        checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_DB, resourceAssignment.dictionarySource) {
-            "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_DB} but it is ${resourceAssignment.dictionarySource}"
+        checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, resourceAssignment.dictionarySource) {
+            "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PROCESSOR_DB} but it is ${resourceAssignment.dictionarySource}"
+        }
+    }
+
+    private fun populateNamedParameter(inputKeyMapping: Map<String, String>): Map<String, Any> {
+        val namedParameters = HashMap<String, Any>()
+        inputKeyMapping.forEach {
+            val expressionValue = raRuntimeService.getDictionaryStore(it.value).textValue()
+            logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)")
+            namedParameters[it.key] = expressionValue
         }
+        logger.info("Parameter information : ({})", namedParameters)
+        return namedParameters
     }
 
     @Throws(BluePrintProcessorException::class)
@@ -126,7 +141,7 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
         logger.info("Response processing type($type)")
 
         // Primitive Types
-        when(type) {
+        when (type) {
             in BluePrintTypes.validPrimitiveTypes() -> {
                 val dbColumnValue = rows[0][outputKeyMapping[dName]]
                 logger.info("For template key (${resourceAssignment.name}) setting value as ($dbColumnValue)")
@@ -134,7 +149,7 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
             }
             in BluePrintTypes.validCollectionTypes() -> {
                 val entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
-                var arrayNode = JsonNodeFactory.instance.arrayNode()
+                val arrayNode = JsonNodeFactory.instance.arrayNode()
                 rows.forEach {
                     if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) {
                         val dbColumnValue = it[outputKeyMapping[dName]]
@@ -157,7 +172,7 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
             else -> {
                 // Complex Types
                 val row = rows[0]
-                var objectNode = JsonNodeFactory.instance.objectNode()
+                val objectNode = JsonNodeFactory.instance.objectNode()
                 for (mapping in outputKeyMapping.entries) {
                     val dbColumnValue = checkNotNull(row[mapping.key])
                     val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key)
index b3e3e4e..91997e3 100644 (file)
@@ -25,7 +25,6 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfigurati
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.apps.blueprintsprocessor.core.utils.PayloadUtils
 import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration
-import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.DBLibGenericService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.*
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
@@ -44,7 +43,7 @@ import org.springframework.test.context.junit4.SpringRunner
 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
     InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
     DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
-    CapabilityResourceResolutionProcessor::class, DBLibGenericService::class,
+    CapabilityResourceResolutionProcessor::class,
     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
 @TestPropertySource(locations = ["classpath:application-test.properties"])
index 905c8e0..d560e8c 100644 (file)
@@ -25,12 +25,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfigurati
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.apps.blueprintsprocessor.core.utils.PayloadUtils
 import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibConfiguration
-import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.DBLibGenericService
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.CapabilityResourceResolutionProcessor
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.DatabaseResourceAssignmentProcessor
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.DefaultResourceResolutionProcessor
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.InputResourceResolutionProcessor
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.RestResourceResolutionProcessor
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.*
 import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
@@ -53,7 +48,7 @@ import kotlin.test.assertTrue
 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
     InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
     DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
-    CapabilityResourceResolutionProcessor::class, DBLibGenericService::class,
+    CapabilityResourceResolutionProcessor::class,
     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
 @TestPropertySource(locations = ["classpath:application-test.properties"])
@@ -70,7 +65,7 @@ class ResourceResolutionServiceTest {
     fun testRegisteredSource() {
         val sources = resourceResolutionService.registeredResourceSources()
         assertNotNull(sources, "failed to get registered sources")
-        assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-primary-db",
+        assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db",
                 "source-rest")), "failed to get registered sources : $sources")
     }
 
index 276ece1..3e9ec0c 100644 (file)
@@ -40,6 +40,7 @@ class DBLibConstants {
 
         //list of database
         const val MARIA_DB: String = "maria-db"
+        const val PRIMARY_DB: String = "primary-db"
         const val MYSQL_DB: String = "mysql-db"
         const val ORACLE_DB: String = "oracle-db"
         const val POSTGRES_DB: String = "postgres-db"
index a16e556..ab2c19a 100644 (file)
 package org.onap.ccsdk.apps.blueprintsprocessor.db
 
 
-open class PrimaryDataSourceProperties {
+open class DBDataSourceProperties {
     lateinit var url: String
     lateinit var username: String
     lateinit var password: String
-    lateinit var driverClassName: String
+    open lateinit var driverClassName: String
+
+}
+
+open class PrimaryDataSourceProperties: DBDataSourceProperties() {
+    lateinit var hibernateHbm2ddlAuto: String
+    lateinit var hibernateDDLAuto: String
+    lateinit var hibernateNamingStrategy: String
+    lateinit var hibernateDialect: String
+}
+
+open class MariaDataSourceProperties: DBDataSourceProperties() {
     lateinit var hibernateHbm2ddlAuto: String
     lateinit var hibernateDDLAuto: String
     lateinit var hibernateNamingStrategy: String
+    lateinit var type: String
     lateinit var hibernateDialect: String
-}
\ No newline at end of file
+    override var driverClassName = DBLibConstants.DRIVER_MARIA_DB
+}
+
+open class MySqlDataSourceProperties: DBDataSourceProperties() {
+    lateinit var hibernateHbm2ddlAuto: String
+    lateinit var hibernateDDLAuto: String
+    lateinit var hibernateNamingStrategy: String
+    lateinit var type: String
+    lateinit var hibernateDialect: String
+    override var driverClassName = DBLibConstants.DRIVER_MYSQL_DB
+}
+
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/BluePrintDBLibPropertyService.kt
new file mode 100644 (file)
index 0000000..f93c241
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright Â© 2019 Bell Canada Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
+import org.onap.ccsdk.apps.blueprintsprocessor.db.*
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.stereotype.Service
+
+@Service
+class BluePrintDBLibPropertySevice(private var bluePrintProperties: BluePrintProperties) {
+
+    fun JdbcTemplate(jsonNode: JsonNode): BluePrintDBLibGenericService {
+        val dBConnetionProperties = dBDataSourceProperties(jsonNode)
+        return blueprintDBDataSourceService(dBConnetionProperties)
+    }
+
+    fun JdbcTemplate(selector: String): BluePrintDBLibGenericService {
+        val prefix = "blueprintsprocessor.database.$selector"
+        val dBConnetionProperties = dBDataSourceProperties(prefix)
+        return blueprintDBDataSourceService(dBConnetionProperties)
+    }
+
+    private fun dBDataSourceProperties(jsonNode: JsonNode): DBDataSourceProperties {
+        val type = jsonNode.get("type").textValue()
+        return when (type) {
+            DBLibConstants.MYSQL_DB -> {
+                JacksonUtils.readValue(jsonNode, MySqlDataSourceProperties::class.java)!!
+            }
+            DBLibConstants.MARIA_DB -> {
+                JacksonUtils.readValue(jsonNode, MariaDataSourceProperties::class.java)!!
+            }
+            else -> {
+                throw BluePrintProcessorException("Rest adaptor($type) is not supported")
+            }
+        }
+    }
+
+    private fun dBDataSourceProperties(prefix: String): DBDataSourceProperties {
+        val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
+        return when (type) {
+            DBLibConstants.MARIA_DB -> {
+                mariaDBConnectionProperties(prefix)
+            }
+            DBLibConstants.MYSQL_DB -> {
+                mySqlDBConnectionProperties(prefix)
+            }
+            DBLibConstants.ORACLE_DB -> {
+                TODO("not implemented")
+            }
+            DBLibConstants.POSTGRES_DB -> {
+                TODO("not implemented")
+            }
+            DBLibConstants.PRIMARY_DB -> {
+                primaryDBConnectionProperties(prefix)
+            }
+            else -> {
+                throw BluePrintProcessorException("Rest adaptor($type) is not supported")
+            }
+        }
+    }
+
+    private fun blueprintDBDataSourceService(dBConnetionProperties: DBDataSourceProperties): BluePrintDBLibGenericService {
+        when (dBConnetionProperties) {
+            is MariaDataSourceProperties -> {
+                return MariaDatabaseConfiguration(dBConnetionProperties)
+            }
+            is MySqlDataSourceProperties -> {
+                return MySqlDatabaseConfiguration(dBConnetionProperties)
+            }
+            else -> {
+                throw BluePrintProcessorException("couldn't get rest service for")
+            }
+        }
+    }
+
+    private fun mySqlDBConnectionProperties(prefix: String): MySqlDataSourceProperties {
+        return bluePrintProperties.propertyBeanType(prefix, MySqlDataSourceProperties::class.java)
+    }
+
+    private fun mariaDBConnectionProperties(prefix: String): MariaDataSourceProperties {
+        return bluePrintProperties.propertyBeanType(prefix, MariaDataSourceProperties::class.java)
+    }
+
+    private fun primaryDBConnectionProperties(prefix: String): PrimaryDataSourceProperties {
+        return bluePrintProperties.propertyBeanType(prefix, PrimaryDataSourceProperties::class.java)
+    }
+
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/DBLibGenericService.kt
deleted file mode 100644 (file)
index af7ab05..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.ccsdk.apps.blueprintsprocessor.db.primary
-
-import com.fasterxml.jackson.databind.JsonNode
-import org.onap.ccsdk.apps.blueprintsprocessor.db.AbstractDBLibGenericService
-import org.onap.ccsdk.apps.blueprintsprocessor.db.DBLibConstants
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
-import org.springframework.boot.jdbc.DataSourceBuilder
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
-import org.springframework.stereotype.Service
-
-@Service
-open class DBLibGenericService(primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate)
-    : AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) {
-
-    fun primaryJdbcTemplate():NamedParameterJdbcTemplate{
-        return namedParameterJdbcTemplate()
-    }
-
-    fun remoteJdbcTemplate(jsonNode: JsonNode): NamedParameterJdbcTemplate {
-        val type = jsonNode.get("type").textValue()
-        val driverDB: String
-
-        return when (type) {
-            DBLibConstants.MARIA_DB -> {
-                driverDB = DBLibConstants.DRIVER_MARIA_DB
-                jdbcTemplate(jsonNode, driverDB)
-            }
-            DBLibConstants.MYSQL_DB -> {
-                driverDB = DBLibConstants.DRIVER_MYSQL_DB
-                jdbcTemplate(jsonNode, driverDB)
-            }
-            DBLibConstants.ORACLE_DB -> {
-                driverDB = DBLibConstants.DRIVER_ORACLE_DB
-                jdbcTemplate(jsonNode, driverDB)
-            }
-            DBLibConstants.POSTGRES_DB -> {
-                driverDB = DBLibConstants.DRIVER_POSTGRES_DB
-                jdbcTemplate(jsonNode, driverDB)
-            }
-            else -> {
-                throw BluePrintProcessorException("Rest adaptor($type) is not supported")
-            }
-        }
-    }
-
-    fun jdbcTemplate(jsonNode: JsonNode, driver: String): NamedParameterJdbcTemplate {
-        val dataSourceBuilder = DataSourceBuilder
-                .create()
-                .username(jsonNode.get("username").textValue())
-                .password(jsonNode.get("password").textValue())
-                .url(jsonNode.get("url").textValue())
-                .driverClassName(driver)
-                .build()
-        return NamedParameterJdbcTemplate(dataSourceBuilder)
-    }
-}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MariaDatabaseConfiguration.kt
new file mode 100644 (file)
index 0000000..c67fb33
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright Â© 2019 Bell Canada Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary
+
+import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibGenericService
+import org.onap.ccsdk.apps.blueprintsprocessor.db.MariaDataSourceProperties
+import org.slf4j.LoggerFactory
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
+import org.springframework.jdbc.datasource.DriverManagerDataSource
+import org.springframework.orm.jpa.JpaTransactionManager
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
+import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter
+import org.springframework.transaction.PlatformTransactionManager
+import java.util.*
+import javax.sql.DataSource
+
+class MariaDatabaseConfiguration(private val mariaDataSourceProperties: MariaDataSourceProperties) : BluePrintDBLibGenericService {
+
+    override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate {
+        return mariaNamedParameterJdbcTemplate(mariaDataSource())
+    }
+
+    override fun query(sql: String, params: Map<String, Any>): List<Map<String, Any>> {
+        return mariaNamedParameterJdbcTemplate(mariaDataSource()).queryForList(sql, params)
+    }
+
+    override fun update(sql: String, params: Map<String, Any>): Int {
+        return mariaNamedParameterJdbcTemplate(mariaDataSource()).update(sql, params)
+    }
+
+    val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!!
+
+    fun mariaDataSource(): DataSource {
+        val dataSource = DriverManagerDataSource()
+        dataSource.setDriverClassName(mariaDataSourceProperties.driverClassName)
+        dataSource.url = mariaDataSourceProperties.url
+        dataSource.username = mariaDataSourceProperties.username
+        dataSource.password = mariaDataSourceProperties.password
+        return dataSource
+    }
+
+    fun mariaNamedParameterJdbcTemplate(mariaDataSource: DataSource): NamedParameterJdbcTemplate {
+        return NamedParameterJdbcTemplate(mariaDataSource)
+    }
+}
\ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/MySqlDatabaseConfiguration.kt
new file mode 100644 (file)
index 0000000..2a0dec7
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright Â© 2019 Bell Canada Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary
+
+import org.onap.ccsdk.apps.blueprintsprocessor.db.BluePrintDBLibGenericService
+import org.onap.ccsdk.apps.blueprintsprocessor.db.MySqlDataSourceProperties
+import org.slf4j.LoggerFactory
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
+import org.springframework.jdbc.datasource.DriverManagerDataSource
+import javax.sql.DataSource
+
+class MySqlDatabaseConfiguration(private val mySqlDataSourceProperties: MySqlDataSourceProperties) : BluePrintDBLibGenericService {
+    override fun namedParameterJdbcTemplate(): NamedParameterJdbcTemplate {
+        return mySqlNamedParameterJdbcTemplate(mySqlDataSource())
+    }
+
+    override fun query(sql: String, params: Map<String, Any>): List<Map<String, Any>> {
+        return mySqlNamedParameterJdbcTemplate(mySqlDataSource()).queryForList(sql, params)
+    }
+
+    override fun update(sql: String, params: Map<String, Any>): Int {
+        return mySqlNamedParameterJdbcTemplate(mySqlDataSource()).update(sql, params)
+    }
+
+    val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!!
+
+    fun mySqlDataSource(): DataSource {
+        val dataSource = DriverManagerDataSource()
+        dataSource.setDriverClassName(mySqlDataSourceProperties.driverClassName)
+        dataSource.url = mySqlDataSourceProperties.url
+        dataSource.username = mySqlDataSourceProperties.username
+        dataSource.password = mySqlDataSourceProperties.password
+        return dataSource
+    }
+
+    fun mySqlNamedParameterJdbcTemplate(mySqlDataSource: DataSource): NamedParameterJdbcTemplate {
+        return NamedParameterJdbcTemplate(mySqlDataSource)
+    }
+
+
+}
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDBLibGenericService.kt
new file mode 100644 (file)
index 0000000..5a92653
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary
+
+import org.onap.ccsdk.apps.blueprintsprocessor.db.AbstractDBLibGenericService
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
+import org.springframework.stereotype.Service
+
+@Service
+open class PrimaryDBLibGenericService(primaryNamedParameterJdbcTemplate: NamedParameterJdbcTemplate)
+    : AbstractDBLibGenericService(primaryNamedParameterJdbcTemplate) {
+
+}
\ No newline at end of file
index 412c591..1df385f 100644 (file)
       <artifactId>spring-boot-devtools</artifactId>
       <optional>true</optional>
     </dependency>
+
+    <!-- SDC Distribution client dependency -->
+    <dependency>
+      <groupId>org.onap.sdc.sdc-distribution-client</groupId>
+      <artifactId>sdc-distribution-client</artifactId>
+      <version>1.3.0</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.jmockit</groupId>
+      <artifactId>jmockit</artifactId>
+      <version>1.19</version>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
 
   <build>
index 661f8cb..3bd34fb 100644 (file)
@@ -10,8 +10,10 @@ package org.onap.ccsdk.apps.cdssdclistener;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 
 @SpringBootApplication
+@EnableConfigurationProperties(CdsSdcListenerConfiguration.class)
 public class CdsSdcListenerApplication {
     public static void main(String[] args) {
         SpringApplication.run(CdsSdcListenerApplication.class, args);
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerClient.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerClient.java
new file mode 100644 (file)
index 0000000..af0bb40
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE:  All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+package org.onap.ccsdk.apps.cdssdclistener;
+
+import java.util.Optional;
+import org.onap.ccsdk.apps.cdssdclistener.exceptions.CdsSdcListenerException;
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.impl.DistributionClientFactory;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.event.EventListener;
+import org.springframework.stereotype.Component;
+
+@Component
+public class CdsSdcListenerClient {
+
+    private static Logger LOG = LoggerFactory.getLogger(CdsSdcListenerClient.class);
+
+    @Autowired
+    private CdsSdcListenerConfiguration configuration;
+
+    @Autowired
+    private CdsSdcListenerNotificationCallback notification;
+
+    @Autowired
+    private CdsSdcListenerDto listenerDto;
+
+    private IDistributionClient distributionClient;
+
+    /**
+     * This method initializes the SDC Distribution client.
+     */
+    @EventListener(ApplicationReadyEvent.class)
+    public void initSdcClient() throws CdsSdcListenerException {
+        LOG.info("Initialize the SDC distribution client");
+
+        distributionClient = Optional.of(DistributionClientFactory.createDistributionClient())
+            .orElseThrow(() -> new CdsSdcListenerException("Could not able to create SDC Distribution client"));
+
+        listenerDto.setDistributionClient(distributionClient);
+
+        IDistributionClientResult result = distributionClient.init(configuration, notification);
+
+        startSdcClientBasedOnTheResult(result);
+    }
+
+    private void startSdcClientBasedOnTheResult(IDistributionClientResult result) throws CdsSdcListenerException {
+        if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
+            throw new CdsSdcListenerException(
+                "SDC distribution client init failed with reason:" + result.getDistributionMessageResult());
+        }
+
+        // Start the client.
+        result = this.distributionClient.start();
+
+        if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
+            throw new CdsSdcListenerException(
+                "Startup of the SDC distribution client failed with reason: " + result.getDistributionMessageResult());
+        }
+    }
+
+    private void closeSdcDistributionclient() throws CdsSdcListenerException {
+
+        IDistributionClientResult status = this.distributionClient.stop();
+
+        LOG.info("Closing SDC distribution client");
+        if (status.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
+            throw new CdsSdcListenerException(
+                "Failed to close the SDC distribution client due to : " + status.getDistributionMessageResult());
+        }
+    }
+}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerConfiguration.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerConfiguration.java
new file mode 100644 (file)
index 0000000..0cbb917
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE:  All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+
+package org.onap.ccsdk.apps.cdssdclistener;
+
+import java.util.List;
+import org.onap.sdc.api.consumer.IConfiguration;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * In order to initiate a SDC distribution client we need to supply some pre-configuration values that
+ * distribution client needs.
+ */
+@ConfigurationProperties("listenerservice")
+public class CdsSdcListenerConfiguration implements IConfiguration {
+
+    public static final String TOSCA_CSAR = "TOSCA_CSAR";
+
+    @Value("${listenerservice.config.asdcAddress}")
+    private String asdcAddress;
+
+    @Value("${listenerservice.config.messageBusAddress}")
+    private List<String> messageBusAddress;
+
+    @Value("${listenerservice.config.user}")
+    private String user;
+
+    @Value("${listenerservice.config.password}")
+    private String password;
+
+    @Value("${listenerservice.config.pollingTimeout}")
+    private int pollingTimeout;
+
+    @Value("${listenerservice.config.pollingInterval}")
+    private int pollingInterval;
+
+    @Value("${listenerservice.config.relevantArtifactTypes}")
+    private List<String> relevantArtifactTypes;
+
+    @Value("${listenerservice.config.consumerGroup}")
+    private String consumerGroup;
+
+    @Value("${listenerservice.config.environmentName}")
+    private String envName;
+
+    @Value("${listenerservice.config.consumerId}")
+    private String consumerId;
+
+    @Value("${listenerservice.config.activateServerTLSAuth}")
+    private boolean activateServerTLSAuth;
+
+    @Value("${listenerservice.config.isUseHttpsWithDmaap}")
+    private boolean isUseHttpsWithDmaap;
+
+
+    @Override
+    public String getAsdcAddress() {
+        return asdcAddress;
+    }
+
+    @Override
+    public List<String> getMsgBusAddress() {
+        return messageBusAddress;
+    }
+
+    @Override
+    public String getUser() {
+        return user;
+    }
+
+    @Override
+    public String getPassword() {
+        return password;
+    }
+
+    @Override
+    public int getPollingInterval() {
+        return pollingInterval;
+    }
+
+    @Override
+    public int getPollingTimeout() {
+        return pollingTimeout;
+    }
+
+    @Override
+    public List<String> getRelevantArtifactTypes() {
+        return relevantArtifactTypes;
+    }
+
+    @Override
+    public String getConsumerGroup() {
+        return consumerGroup;
+    }
+
+    @Override
+    public String getEnvironmentName() {
+        return envName;
+    }
+
+    @Override
+    public String getConsumerID() {
+        return consumerId;
+    }
+
+    @Override
+    public String getKeyStorePath() {
+        return null;
+    }
+
+    @Override
+    public String getKeyStorePassword() {
+        return null;
+    }
+
+    @Override
+    public boolean activateServerTLSAuth() {
+        return activateServerTLSAuth;
+    }
+
+    @Override
+    public boolean isFilterInEmptyResources() {
+        return false;
+    }
+
+    @Override
+    public Boolean isUseHttpsWithDmaap() {
+        return isUseHttpsWithDmaap;
+    }
+}
+
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerDto.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerDto.java
new file mode 100644 (file)
index 0000000..afa753e
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE:  All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+package org.onap.ccsdk.apps.cdssdclistener;
+
+import org.onap.sdc.api.IDistributionClient;
+
+public class CdsSdcListenerDto {
+
+    private IDistributionClient distributionClient;
+
+    public IDistributionClient getDistributionClient() {
+        return distributionClient;
+    }
+
+    public void setDistributionClient(IDistributionClient distributionClient) {
+        this.distributionClient = distributionClient;
+    }
+}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerNotificationCallback.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerNotificationCallback.java
new file mode 100644 (file)
index 0000000..3574763
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE:  All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+
+package org.onap.ccsdk.apps.cdssdclistener;
+
+import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS;
+import java.util.List;
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.consumer.INotificationCallback;
+import org.onap.sdc.api.notification.IArtifactInfo;
+import org.onap.sdc.api.notification.INotificationData;
+import org.onap.sdc.api.results.IDistributionClientDownloadResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class CdsSdcListenerNotificationCallback implements INotificationCallback {
+
+    @Autowired
+    private CdsSdcListenerDto cdsSdcListenerDto;
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(CdsSdcListenerNotificationCallback.class);
+
+    @Override
+    public void activateCallback(INotificationData notificationData) {
+        LOGGER.info(notificationData.getDistributionID(), "The UUID generated by SDC {}");
+        processNotification(notificationData);
+    }
+
+    private void processNotification(INotificationData notificationData) {
+        downlaodCsarArtifacts(notificationData.getServiceArtifacts());
+    }
+
+    /**
+     * Download the TOSCA CSAR artifact.
+     * @param artifactInfo - An object consists of Artifact information.
+     */
+    private void downlaodCsarArtifacts(List<IArtifactInfo> artifactInfo) {
+        final IDistributionClient distributionClient = cdsSdcListenerDto.getDistributionClient();
+
+        artifactInfo.forEach(info -> {
+            final String url = info.getArtifactURL();
+            final String id = info.getArtifactUUID();
+            if (info.getArtifactType().equals(CdsSdcListenerConfiguration.TOSCA_CSAR)) {
+                LOGGER.info("Trying to download the artifact from : {} and UUID is {} ", url, id);
+
+                IDistributionClientDownloadResult result = distributionClient.download(info);
+
+                if (!result.getDistributionActionResult().equals(SUCCESS)) {
+                    LOGGER.info("Failed to download the artifact from : {} due to {} ", url,
+                        result.getDistributionActionResult());
+                } else {
+                    parseCBAFileFromCsar(result);
+                }
+            }
+        });
+    }
+
+    private void parseCBAFileFromCsar(IDistributionClientDownloadResult result) {
+
+    }
+}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/exceptions/CdsSdcListenerException.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/exceptions/CdsSdcListenerException.java
new file mode 100644 (file)
index 0000000..3f83b6a
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE:  All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+
+package org.onap.ccsdk.apps.cdssdclistener.exceptions;
+
+public class CdsSdcListenerException extends Exception {
+
+    /**
+     * @param message The message to dump
+     */
+    public CdsSdcListenerException(final String message) {
+        super(message);
+    }
+
+    /**
+     * @param message The message to dump
+     * @param cause The Throwable cause object
+     */
+    public CdsSdcListenerException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/service/ListenerService.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/service/ListenerService.java
new file mode 100644 (file)
index 0000000..d6c2c4f
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE:  All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+
+package org.onap.ccsdk.apps.cdssdclistener.service;
+
+import java.io.File;
+
+public interface ListenerService {
+
+    void extractBluePrint(File file);
+
+    void storeBluePrint(File file);
+}
diff --git a/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/service/ListenerServiceImpl.java b/ms/cds-sdc-listener/application/src/main/java/org/onap/ccsdk/apps/cdssdclistener/service/ListenerServiceImpl.java
new file mode 100644 (file)
index 0000000..864c485
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE:  All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+
+package org.onap.ccsdk.apps.cdssdclistener.service;
+
+import java.io.File;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ListenerServiceImpl implements ListenerService {
+
+    @Override
+    public void extractBluePrint(File file) {
+        //TODO
+
+    }
+
+    @Override
+    public void storeBluePrint(File file) {
+        //TODO
+    }
+}
diff --git a/ms/cds-sdc-listener/application/src/main/resources/application.yml b/ms/cds-sdc-listener/application/src/main/resources/application.yml
new file mode 100644 (file)
index 0000000..1daef58
--- /dev/null
@@ -0,0 +1,17 @@
+listenerservice:
+    config:
+      asdcAddress: localhost:8443
+      messageBusAddress: localhost
+      user: vid
+      password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U
+      pollingInterval: 15
+      pollingTimeout: 15
+      relevantArtifactTypes: TOSCA_CSAR
+      consumerGroup: cds-id-local
+      environmentName: AUTO
+      consumerId: cds-id-local
+      keyStorePassword:
+      keyStorePath:
+      activateServerTLSAuth : false
+      isUseHttpsWithDmaap: false
+
diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerClientTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerClientTest.java
new file mode 100644 (file)
index 0000000..3a634b8
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE:  All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+
+package org.onap.ccsdk.apps.cdssdclistener;
+
+import mockit.Expectations;
+import mockit.Injectable;
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Tested;
+import mockit.VerificationsInOrder;
+import mockit.integration.junit4.JMockit;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.ccsdk.apps.cdssdclistener.exceptions.CdsSdcListenerException;
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.impl.DistributionClientFactory;
+import org.onap.sdc.impl.DistributionClientResultImpl;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+
+@RunWith(JMockit.class)
+public class CdsSdcListenerClientTest {
+
+    @Tested
+    private CdsSdcListenerClient cdsSdcListenerClient;
+
+    @Test
+    public void testInitCdsClientSuccesfully(@Injectable IDistributionClient distributionClient,
+        @Injectable CdsSdcListenerConfiguration configuration,
+        @Injectable CdsSdcListenerNotificationCallback notification,
+        @Injectable CdsSdcListenerDto cdsSdcListenerDto) throws CdsSdcListenerException {
+
+        // Arrange
+        new MockUp<DistributionClientFactory>() {
+            @Mock
+            public IDistributionClient createDistributionClient() {
+                return distributionClient;
+            }
+        };
+
+        new Expectations() {{
+            distributionClient.init(configuration, notification);
+            result = getResult();
+        }};
+
+        new Expectations() {{
+            distributionClient.start();
+            result = getResult();
+        }};
+
+        // Act
+        cdsSdcListenerClient.initSdcClient();
+
+        // Verify
+        new VerificationsInOrder() {{
+            distributionClient.init(configuration, notification);
+            distributionClient.start();
+        }};
+    }
+
+    public IDistributionClientResult getResult() {
+        return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS,
+            DistributionActionResultEnum.SUCCESS.name());
+    }
+}
diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerConfigurationTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/apps/cdssdclistener/CdsSdcListenerConfigurationTest.java
new file mode 100644 (file)
index 0000000..886049d
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2019 Bell Canada. All rights reserved.
+ *
+ * NOTICE:  All the intellectual and technical concepts contained herein are
+ * proprietary to Bell Canada and are protected by trade secret or copyright law.
+ * Unauthorized copying of this file, via any medium is strictly prohibited.
+ */
+
+package org.onap.ccsdk.apps.cdssdclistener;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@EnableConfigurationProperties(CdsSdcListenerConfiguration.class)
+@SpringBootTest(classes = {CdsSdcListenerConfigurationTest.class})
+public class CdsSdcListenerConfigurationTest {
+
+    @Autowired
+    private CdsSdcListenerConfiguration listenerConfiguration;
+
+    @Test
+    public void testCdsSdcListenerConfiguration() {
+        assertEquals(listenerConfiguration.getAsdcAddress(), "localhost:8443");
+        assertEquals(listenerConfiguration.getMsgBusAddress().stream().findFirst().get(), "localhost");
+        assertEquals(listenerConfiguration.getUser(), "vid");
+        assertEquals(listenerConfiguration.getPassword(), "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U");
+        assertEquals(listenerConfiguration.getPollingInterval(), 15);
+        assertEquals(listenerConfiguration.getPollingTimeout(), 15);
+        assertEquals(listenerConfiguration.getRelevantArtifactTypes().stream().findFirst().get(), "TOSCA_CSAR");
+        assertEquals(listenerConfiguration.getConsumerGroup(), "cds-id-local");
+        assertEquals(listenerConfiguration.getEnvironmentName(), "AUTO");
+        assertEquals(listenerConfiguration.getConsumerID(), "cds-id-local");
+        assertEquals(listenerConfiguration.activateServerTLSAuth(), false);
+    }
+}
index 1c9029d..3401ece 100755 (executable)
@@ -49,7 +49,7 @@ spring.jpa.hibernate.ddl-auto=none
 spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
 # Load Resource Source Mappings
-resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
+resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
 # Controller Blueprints Core Configuration
 controllerblueprints.blueprintDeployPath=/etc/blueprints/deploy
 controllerblueprints.blueprintArchivePath=/etc/blueprints/archive
index 0340938..8789c24 100755 (executable)
@@ -52,7 +52,7 @@ spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
 
 # Load Resource Source Mappings
-resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
+resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
 
 # Controller Blueprints Core Configuration
 controllerblueprints.blueprintDeployPath=/etc/blueprints/deploy
index e0369ae..8ad9f2c 100755 (executable)
@@ -33,7 +33,7 @@ swagger.contact.url=www.onap.com
 swagger.contact.email=brindasanth@onap.com\r
 \r
 # Load Resource Source Mappings\r
-resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability\r
+resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability\r
 \r
 # Controller Blueprints Core Configuration\r
 controllerblueprints.blueprintDeployPath=./target/blueprints/deploy\r
index d33a2f0..7536868 100644 (file)
@@ -24,6 +24,8 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict
 object ResourceDictionaryConstants {
     const val SOURCE_INPUT = "input"
     const val SOURCE_DEFAULT = "default"
+    //const val SOURCE_PRIMARY_CONFIG_DATA = "rest"
+    const val SOURCE_PROCESSOR_DB = "processor-db"
     const val SOURCE_PRIMARY_CONFIG_DATA = "primary-config-data"
     const val SOURCE_PRIMARY_DB = "primary-db"
 
index e4ddac1..45fc739 100644 (file)
@@ -59,9 +59,9 @@ public class ResourceDictionaryUtilsTest {
         Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource());
 
         // To Check Assigned Source
-        resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_PRIMARY_DB);
+        resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB);
         ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);
-        Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_PRIMARY_DB, resourceAssignment.getDictionarySource());
+        Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, resourceAssignment.getDictionarySource());
 
     }
 
@@ -78,7 +78,7 @@ public class ResourceDictionaryUtilsTest {
         Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource);
 
         // TO check the multiple Source
-        sources.put(ResourceDictionaryConstants.SOURCE_PRIMARY_DB, new NodeTemplate());
+        sources.put(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, new NodeTemplate());
         String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources);
         Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource);
 
index 20450f4..011bad3 100755 (executable)
@@ -20,7 +20,7 @@ logging.level.org.springframework.web=INFO
 logging.level.org.hibernate.SQL=warn
 logging.level.org.hibernate.type.descriptor.sql=debug
 # Load Resource Source Mappings
-resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
+resourceSourceMappings=processor-db=source-processor-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
 # Controller Blueprints Core Configuration
 controllerblueprints.blueprintDeployPath=./target/blueprints/deploy
 controllerblueprints.blueprintArchivePath=./target/blueprints/archive