summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor/functions')
-rw-r--r--ms/blueprintsprocessor/functions/cli-executor/pom.xml9
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/pom.xml2
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt11
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt46
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt124
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt120
-rwxr-xr-xms/blueprintsprocessor/functions/pom.xml2
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/pom.xml2
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/pom.xml2
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt105
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt3
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt11
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/pom.xml2
13 files changed, 344 insertions, 95 deletions
diff --git a/ms/blueprintsprocessor/functions/cli-executor/pom.xml b/ms/blueprintsprocessor/functions/cli-executor/pom.xml
index 52a78907..9077c13c 100644
--- a/ms/blueprintsprocessor/functions/cli-executor/pom.xml
+++ b/ms/blueprintsprocessor/functions/cli-executor/pom.xml
@@ -14,14 +14,11 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>functions</artifactId>
<groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
- <version>0.4.1-SNAPSHOT</version>
+ <version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cli-executor</artifactId>
@@ -37,4 +34,4 @@
</dependencies>
-</project> \ No newline at end of file
+</project>
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/pom.xml b/ms/blueprintsprocessor/functions/netconf-executor/pom.xml
index 3041132d..2e6d77ed 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/pom.xml
+++ b/ms/blueprintsprocessor/functions/netconf-executor/pom.xml
@@ -18,7 +18,7 @@
<parent>
<groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
<artifactId>functions</artifactId>
- <version>0.4.1-SNAPSHOT</version>
+ <version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
index cf11cfdd..2dd73ef1 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
@@ -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
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt
index 045725c7..e7a51434 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt
@@ -15,13 +15,18 @@
*/
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
index 00000000..8f1f7150
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt
@@ -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
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt
index d4c27b1c..8a60d809 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt
@@ -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
diff --git a/ms/blueprintsprocessor/functions/pom.xml b/ms/blueprintsprocessor/functions/pom.xml
index 4bc0159f..5bc26d5f 100755
--- a/ms/blueprintsprocessor/functions/pom.xml
+++ b/ms/blueprintsprocessor/functions/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
<artifactId>parent</artifactId>
- <version>0.4.1-SNAPSHOT</version>
+ <version>0.4.2-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
diff --git a/ms/blueprintsprocessor/functions/python-executor/pom.xml b/ms/blueprintsprocessor/functions/python-executor/pom.xml
index 120ded78..e0c61749 100644
--- a/ms/blueprintsprocessor/functions/python-executor/pom.xml
+++ b/ms/blueprintsprocessor/functions/python-executor/pom.xml
@@ -18,7 +18,7 @@
<parent>
<artifactId>functions</artifactId>
<groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
- <version>0.4.1-SNAPSHOT</version>
+ <version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml
index 840124fa..eafdb9a0 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml
+++ b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
<artifactId>functions</artifactId>
- <version>0.4.1-SNAPSHOT</version>
+ <version>0.4.2-SNAPSHOT</version>
</parent>
<groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
<artifactId>resource-resolution</artifactId>
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
index e38a1cca..a192989e 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
@@ -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)
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
index b3e3e4ed..91997e34 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
@@ -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"])
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
index 905c8e0b..d560e8c3 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
@@ -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")
}
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/pom.xml b/ms/blueprintsprocessor/functions/restconf-executor/pom.xml
index e81c5276..1ee23d3d 100644
--- a/ms/blueprintsprocessor/functions/restconf-executor/pom.xml
+++ b/ms/blueprintsprocessor/functions/restconf-executor/pom.xml
@@ -18,7 +18,7 @@
<parent>
<artifactId>functions</artifactId>
<groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
- <version>0.4.1-SNAPSHOT</version>
+ <version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>