summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions
diff options
context:
space:
mode:
authorJessica Wagantall <jwagantall@linuxfoundation.org>2019-03-22 11:03:50 -0700
committerJessica Wagantall <jwagantall@linuxfoundation.org>2019-03-22 11:04:20 -0700
commitc3fe53367983309c659ac19b01b9b638ed2d011d (patch)
treede96787f8e661c0b7a109823517d0a7582ed87c8 /ms/blueprintsprocessor/functions
parent995a36660fc855447d69a41a9a25b6b27fa57bf0 (diff)
parent669f7a860035fd944699a85ee8726c831efe299c (diff)
Migrate "ms/blueprintsprocess" from ccsdk/apps
Migrate code from ccsdk/apps ms/blueprintsprocess subfolder into ccsdk/cds Issue-ID: CIMAN-245 Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Diffstat (limited to 'ms/blueprintsprocessor/functions')
-rw-r--r--ms/blueprintsprocessor/functions/cli-executor/pom.xml37
-rw-r--r--ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/CliExecutorConfiguration.kt22
-rw-r--r--ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/api/CliExecutorService.kt22
-rw-r--r--ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/service/CliExecutorServiceImpl.kt25
-rw-r--r--ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/service/CliExecutorServiceImplTest.kt38
-rw-r--r--ms/blueprintsprocessor/functions/cli-executor/src/test/resources/logback-test.xml35
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/pom.xml54
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt75
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt24
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt70
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt31
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt43
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt24
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt74
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt142
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt86
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt21
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt243
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt220
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt287
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt90
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt404
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt79
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt111
-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/mocks/NetconfDeviceSimulator.kt62
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt125
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt306
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/application-test.properties32
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml35
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/payload/requests/sample-activate-request.json31
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/running-config-input.json15
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/sample-activate-request.json28
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/sample-resourceresolution-request.json28
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/response/get-config-123456.xml10
-rwxr-xr-xms/blueprintsprocessor/functions/pom.xml75
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/pom.xml38
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt105
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt68
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/mock/MockInstanceConfiguration.kt32
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/test/resources/logback-test.xml35
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/test/resources/payload/requests/sample-activate-request.json31
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/pom.xml58
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentProcessorScriptConfiguration.kt42
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt88
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt62
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt26
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt31
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt228
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt79
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt25
-rwxr-xr-xms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResult.kt69
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt64
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt104
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt190
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt65
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt68
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt115
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt204
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt159
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt79
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt91
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt126
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties43
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml35
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json19
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/dt-location.json15
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-array.json35
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-complex.json27
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-simple.json26
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/resource-assignments-simple.json22
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/inputs/input.json18
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json32
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/pom.xml42
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt73
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt58
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfExecutorConfiguration.kt29
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts82
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt102
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/application-test.properties32
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml35
81 files changed, 6135 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/functions/cli-executor/pom.xml b/ms/blueprintsprocessor/functions/cli-executor/pom.xml
new file mode 100644
index 000000000..9077c13c6
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/cli-executor/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2019 IBM.
+ ~
+ ~ 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.
+ -->
+<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.2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>cli-executor</artifactId>
+ <name>Blueprints Processor Function - CLI Executor</name>
+ <description>Blueprints Processor Function - CLI Executor</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.sshd</groupId>
+ <artifactId>sshd-core</artifactId>
+ </dependency>
+
+ </dependencies>
+
+
+</project>
diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/CliExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/CliExecutorConfiguration.kt
new file mode 100644
index 000000000..c26524959
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/CliExecutorConfiguration.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * 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.functions.cli.executor
+
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+open class CliExecutorConfiguration \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/api/CliExecutorService.kt b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/api/CliExecutorService.kt
new file mode 100644
index 000000000..3c5c95886
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/api/CliExecutorService.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * 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.functions.cli.executor.api
+
+interface CliExecutorService {
+
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/service/CliExecutorServiceImpl.kt b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/service/CliExecutorServiceImpl.kt
new file mode 100644
index 000000000..02a74fa0c
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/service/CliExecutorServiceImpl.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * 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.functions.cli.executor.service
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.cli.executor.api.CliExecutorService
+import org.springframework.stereotype.Service
+
+@Service
+open class CliExecutorServiceImpl : CliExecutorService {
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/service/CliExecutorServiceImplTest.kt b/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/service/CliExecutorServiceImplTest.kt
new file mode 100644
index 000000000..347aba794
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/cli/executor/service/CliExecutorServiceImplTest.kt
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * 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.functions.cli.executor.service
+
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.cli.executor.api.CliExecutorService
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertNotNull
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [CliExecutorServiceImpl::class])
+class CliExecutorServiceImplTest {
+
+ @Autowired
+ lateinit var cliExecutorService: CliExecutorService
+
+ @Test
+ fun testCliExecutorService() {
+ assertNotNull(cliExecutorService, "failed to intilise cliExecutorService")
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/cli-executor/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..071c79431
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/cli-executor/src/test/resources/logback-test.xml
@@ -0,0 +1,35 @@
+<!--
+ ~ Copyright © 2019 IBM.
+ ~
+ ~ 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.
+ -->
+
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.springframework.test" level="warn"/>
+ <logger name="org.springframework" level="warn"/>
+ <logger name="org.hibernate" level="info"/>
+ <logger name="org.onap.ccsdk.apps.blueprintsprocessor" level="info"/>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+</configuration>
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/pom.xml b/ms/blueprintsprocessor/functions/netconf-executor/pom.xml
new file mode 100644
index 000000000..2e6d77edc
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<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>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
+ <artifactId>functions</artifactId>
+ <version>0.4.2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+ <artifactId>netconf-executor</artifactId>
+ <name>Blueprints Processor Function - Netconf Executor</name>
+ <description>Blueprints Processor Function - Netconf Executor</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+ <artifactId>resource-resolution</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jettison</groupId>
+ <artifactId>jettison</artifactId>
+ <version>${jettison.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sshd</groupId>
+ <artifactId>sshd-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.jcraft</groupId>
+ <artifactId>jsch</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
new file mode 100644
index 000000000..c2ccdafd1
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
@@ -0,0 +1,75 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Modifications Copyright © 2019 IBM, Bell Canada.
+ *
+ * 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.functions.netconf.executor
+
+import com.fasterxml.jackson.databind.node.ArrayNode
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.apps.controllerblueprints.core.getAsString
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Component
+
+@Component("component-netconf-executor")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class ComponentNetconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService)
+ : AbstractComponentFunction() {
+
+ private val log = LoggerFactory.getLogger(ComponentNetconfExecutor::class.java)
+
+ companion object {
+ const val SCRIPT_TYPE = "script-type"
+ const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
+ const val INSTANCE_DEPENDENCIES = "instance-dependencies"
+ }
+
+
+ lateinit var scriptComponent: NetconfComponentFunction
+
+ override fun process(executionRequest: ExecutionServiceInput) {
+
+ val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
+ val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
+ val instanceDependenciesNode = operationInputs.get(INSTANCE_DEPENDENCIES) as? ArrayNode
+
+ val scriptDependencies: MutableList<String> = arrayListOf()
+ scriptDependencies.add(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+
+ instanceDependenciesNode?.forEach { instanceName ->
+ scriptDependencies.add(instanceName.textValue())
+ }
+
+ scriptComponent = componentFunctionScriptingService.scriptInstance<NetconfComponentFunction>(this, scriptType,
+ scriptClassReference, scriptDependencies)
+
+
+ checkNotNull(scriptComponent) { "failed to get netconf script component" }
+
+ scriptComponent.process(executionServiceInput)
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ scriptComponent.recover(runtimeException, executionRequest)
+ }
+
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt
new file mode 100644
index 000000000..111736633
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt
@@ -0,0 +1,24 @@
+/*
+ * 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.functions.netconf.executor
+
+import org.springframework.stereotype.Service
+
+@Service("json-parser-service")
+class JsonParserService {
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
new file mode 100644
index 000000000..fe8ba54dd
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2018-2019 IBM, Bell Canada.
+ *
+ * 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.functions.netconf.executor
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+
+abstract class NetconfComponentFunction : AbstractScriptComponentFunction() {
+
+ open fun resourceResolutionService(): ResourceResolutionService =
+ functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+
+ // Called from python script
+ fun initializeNetconfConnection(requirementName: String): NetconfDevice {
+ val deviceInfo = deviceProperties(requirementName)
+ return NetconfDevice(deviceInfo)
+ }
+
+ fun generateMessage(artifactName: String): String {
+ return bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
+ }
+
+ fun resolveFromDatabase(resolutionKey: String, artifactName: String): String {
+ return resourceResolutionService().resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey)
+ }
+
+ fun resolveAndGenerateMessage(artifactMapping: String, artifactTemplate: String): String {
+ return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
+ artifactMapping, artifactTemplate)
+ }
+
+ fun resolveAndGenerateMessage(artifactPrefix: String): String {
+ return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
+ artifactPrefix, mapOf())
+ }
+
+ private fun deviceProperties(requirementName: String): DeviceInfo {
+
+ val blueprintContext = bluePrintRuntimeService.bluePrintContext()
+
+ val requirement = blueprintContext.nodeTemplateRequirement(nodeTemplateName, requirementName)
+
+ val capabilityProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(requirement
+ .node!!, requirement.capability!!)
+
+ return deviceProperties(capabilityProperties)
+ }
+
+ private fun deviceProperties(capabilityProperty: MutableMap<String, JsonNode>): DeviceInfo {
+ return JacksonUtils.getInstanceFromMap(capabilityProperty, DeviceInfo::class.java)
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt
new file mode 100644
index 000000000..1c07c5e6c
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2019 Bell Canada.
+ *
+ * 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.functions.netconf.executor
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfSession
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfRpcServiceImpl
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl
+
+data class NetconfDevice(val deviceInfo: DeviceInfo) {
+ val netconfRpcService = NetconfRpcServiceImpl(deviceInfo)
+ val netconfSession: NetconfSession
+
+ init {
+ netconfSession = NetconfSessionImpl(deviceInfo, netconfRpcService)
+ netconfRpcService.setNetconfSession(netconfSession)
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt
new file mode 100644
index 000000000..466e6b5ed
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt
@@ -0,0 +1,43 @@
+/*
+ * 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.functions.netconf.executor.api
+
+import com.fasterxml.jackson.annotation.JsonIgnore
+import com.fasterxml.jackson.annotation.JsonProperty
+
+class DeviceInfo {
+ @get:JsonProperty("login-account")
+ var username: String? = null
+ @get:JsonProperty("login-key")
+ var password: String? = null
+ @get:JsonProperty("target-ip-address")
+ var ipAddress: String? = null
+ @get:JsonProperty("port-number")
+ var port: Int = 0
+ @get:JsonProperty("connection-time-out")
+ var connectTimeout: Long = 5
+ @get:JsonIgnore
+ var source: String? = null
+ @get:JsonIgnore
+ var replyTimeout: Int = 5
+ @get:JsonIgnore
+ var idleTimeout: Int = 99999
+
+ override fun toString(): String {
+ return "$ipAddress:$port"
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt
new file mode 100644
index 000000000..d7642e75f
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt
@@ -0,0 +1,24 @@
+/*
+ * Copyright © 2017-2019 AT&T, Bell Canada
+ *
+ * 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.functions.netconf.executor.api
+
+class NetconfException : Exception {
+
+ constructor(cause: Throwable) : super(cause)
+ constructor(message: String) : super(message)
+ constructor(message: String, cause: Throwable) : super(message, cause)
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt
new file mode 100644
index 000000000..da7466143
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2017-2019 AT&T, Bell Canada
+ *
+ * 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.functions.netconf.executor.api
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus
+
+class DeviceResponse {
+ var status: String? = null
+ var errorMessage: String? = null
+ var responseMessage: String? = null
+ var requestMessage: String? = null
+ private var subDeviceResponse: MutableMap<Any, Any>? = null
+
+ fun addSubDeviceResponse(key: String, subDeviceResponse: DeviceResponse) {
+ if (this.subDeviceResponse == null) {
+ this.subDeviceResponse = hashMapOf()
+ }
+ this.subDeviceResponse!![key] = subDeviceResponse
+ }
+
+ fun isSuccess(): Boolean {
+ if (this.status != RpcStatus.SUCCESS && !this.errorMessage.isNullOrEmpty()) {
+ return false
+ }
+ return true
+ }
+}
+
+
+/**
+ * Creates an event of a given type and for the specified subject and the current time.
+ *
+ * @param type event type
+ * @param payload message from the device
+ * @param messageId id of the message related to the event
+ * @param deviceInfo device of event
+ */
+class NetconfReceivedEvent
+ (private var type: Type, private var payload: String = "", private var messageId: String = "",
+ private var deviceInfo: DeviceInfo) {
+
+ enum class Type {
+ DEVICE_REPLY,
+ DEVICE_UNREGISTERED,
+ DEVICE_ERROR,
+ SESSION_CLOSED
+ }
+
+ fun getType(): Type {
+ return type
+ }
+
+ fun getMessagePayload(): String {
+ return payload
+ }
+
+ fun getMessageID(): String {
+ return messageId
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt
new file mode 100644
index 000000000..02c0a3426
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt
@@ -0,0 +1,142 @@
+/*
+ * 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.functions.netconf.executor.api
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.ModifyAction
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfDatastore
+
+interface NetconfRpcService {
+
+ /**
+ * Lock
+ *
+ * @param configTarget running or candidate, default candidate
+ * @return Device response
+ */
+ fun lock(configTarget: String = NetconfDatastore.CANDIDATE.datastore): DeviceResponse
+
+ /**
+ * Get-config
+ *
+ * @param filter filter content, default empty
+ * @param configTarget running or candidate, default running
+ * @return Device response
+ */
+ fun getConfig(filter: String = "", configTarget: String = NetconfDatastore.RUNNING.datastore): DeviceResponse
+
+ /**
+ * Delete config
+ *
+ * @param configTarget running or candidate, default candidate
+ * @return Device response
+ */
+ fun deleteConfig(configTarget: String = NetconfDatastore.CANDIDATE.datastore): DeviceResponse
+
+ /**
+ * Edit-config
+ *
+ * @param messageContent edit config content.
+ * @param configTarget running or candidate, default candidate
+ * @param editDefaultOperation, default set to none. Valid values: merge, replace, create, delete, none
+ * @return Device response
+ */
+ fun editConfig(messageContent: String, configTarget: String = NetconfDatastore.CANDIDATE.datastore,
+ editDefaultOperation: String = ModifyAction.NONE.action): DeviceResponse
+
+ /**
+ * Invoke custom RPC as provided as input.
+ *
+ * Some use cases might required one to directly invoke a device
+ * specific RPC. The RPC must be correctly formatted.
+ *
+ * Ex: in order to rollback last submitted configuration
+ * for JUNOS devices, such RPC can be use:
+ * <code>
+ * &lt;rpc>
+ * &lt;load-configuration rollback="1"/>
+ * &lt;/rpc>
+ * </code>
+ *
+ * @param rpc the rpc content.
+ */
+ fun invokeRpc(rpc: String): DeviceResponse
+
+ /**
+ * Validate
+ *
+ * @param configTarget running or candidate, default candidate
+ * @return Device response
+ */
+ fun validate(configTarget: String = NetconfDatastore.CANDIDATE.datastore): DeviceResponse
+
+ /**
+ * Commit
+ *
+ * @param confirmed Perform a confirmed <commit> operation. If flag set to true,
+ * then it is expected to have a follow-up <commit> operation to confirm the request
+ * @param confirmTimeout Timeout period for confirmed commit, in seconds.
+ * @param persist Make the confirmed commit survive a session termination, and
+ * set a token on the ongoing confirmed commit.
+ * @param persistId Used to issue a follow-up confirmed commit or a confirming
+ * commit from any session, with the token from the previous <commit> operation.
+ * If unspecified, the confirm timeout defaults to 600 seconds.
+ * @return Device response
+ */
+ fun commit(confirmed: Boolean = false, confirmTimeout: Int = 60, persist: String = "",
+ persistId: String = ""): DeviceResponse
+
+ /**
+ * Cancels an ongoing confirmed commit. If the <persist-id> parameter is not given,
+ * the <cancel-commit> operation MUST be issued on the same session that issued
+ * the confirmed commit.
+ *
+ * @param persistId Cancels a persistent confirmed commit. The value MUST be equal
+ * to the value given in the <persist> parameter to the <commit> operation.
+ * If the value does not match, the operation fails with an "invalid-value" error.
+ */
+ fun cancelCommit(persistId: String = ""): DeviceResponse
+
+ /**
+ * Unlock
+ *
+ * @param configTarget running or candidate, default candidate
+ * @return Device response
+ */
+ fun unLock(configTarget: String = NetconfDatastore.CANDIDATE.datastore): DeviceResponse
+
+ /**
+ * Discard config
+ *
+ * @return Device response
+ */
+ fun discardConfig(): DeviceResponse
+
+ /**
+ * Close session
+ *
+ * @param force force closeSession
+ * @return Device response
+ */
+ fun closeSession(force: Boolean): DeviceResponse
+
+ /**
+ * Executes an RPC request to the netconf server.
+ *
+ * @param request the XML containing the RPC request for the server.
+ * @return Device response
+ */
+ fun asyncRpc(request: String, messageId: String): DeviceResponse
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt
new file mode 100644
index 000000000..6a655d91f
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt
@@ -0,0 +1,86 @@
+/*
+ * 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.functions.netconf.executor.api
+
+import java.util.concurrent.CompletableFuture
+
+interface NetconfSession {
+
+ /**
+ * Establish netconf session
+ */
+ fun connect()
+
+
+ /**
+ * Disconnect netconf session
+ */
+ fun disconnect()
+
+ /**
+ * Reconnect netconf session
+ */
+ fun reconnect()
+
+ /**
+ * Executes an synchronous RPC request.
+ *
+ * @param request the XML request
+ * @param messageId message id of the request.
+ * @return Response
+ */
+ @Throws(NetconfException::class)
+ fun syncRpc(request: String, messageId: String): String
+
+ /**
+ * Executes an asynchronous RPC request.
+ *
+ * @param request the XML request
+ * @param messageId message id of the request.
+ * @return Response
+ */
+ @Throws(NetconfException::class)
+ fun asyncRpc(request: String, messageId: String): CompletableFuture<String>
+
+ /**
+ * Checks the state of the underlying SSH session and connection and if necessary it reestablishes
+ * it.
+ */
+ @Throws(NetconfException::class)
+ fun checkAndReestablish()
+
+ /**
+ * Get the device information for initialised session.
+ *
+ * @return DeviceInfo as device information
+ */
+ fun getDeviceInfo(): DeviceInfo
+
+ /**
+ * Gets the session ID of the Netconf session.
+ *
+ * @return Session ID as a string.
+ */
+ fun getSessionId(): String
+
+ /**
+ * Gets the capabilities of the remote Netconf device associated to this session.
+ *
+ * @return Network capabilities as strings in a Set.
+ */
+ fun getDeviceCapabilitiesSet(): Set<String>
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt
new file mode 100644
index 000000000..8854894fa
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt
@@ -0,0 +1,21 @@
+/*
+ * Copyright © 2017-2019 AT&T, Bell Canada
+ *
+ * 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.functions.netconf.executor.api
+
+interface NetconfSessionListener {
+
+ fun notify(event: NetconfReceivedEvent)
+}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt
new file mode 100644
index 000000000..694756195
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt
@@ -0,0 +1,243 @@
+/*
+ * Copyright © 2017-2019 AT&T, Bell Canada
+ *
+ * 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.functions.netconf.executor.core
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfReceivedEvent
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfSessionListener
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfMessageUtils
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.RpcMessageUtils
+import org.slf4j.LoggerFactory
+import java.io.BufferedReader
+import java.io.IOException
+import java.io.InputStream
+import java.io.InputStreamReader
+import java.io.OutputStream
+import java.io.OutputStreamWriter
+import java.nio.charset.StandardCharsets
+import java.util.concurrent.CompletableFuture
+
+class NetconfDeviceCommunicator(private var inputStream: InputStream,
+ private var out: OutputStream,
+ private val deviceInfo: DeviceInfo,
+ private val sessionListener: NetconfSessionListener,
+ private var replies: MutableMap<String, CompletableFuture<String>>) : Thread() {
+
+ private val log = LoggerFactory.getLogger(NetconfDeviceCommunicator::class.java)
+ private var state = NetconfMessageState.NO_MATCHING_PATTERN
+
+ init {
+ start()
+ }
+
+ override fun run() {
+ var bufferReader: BufferedReader? = null
+ while (bufferReader == null) {
+ bufferReader = BufferedReader(InputStreamReader(inputStream, StandardCharsets.UTF_8))
+ }
+
+ try {
+ var socketClosed = false
+ val deviceReplyBuilder = StringBuilder()
+ while (!socketClosed) {
+ val cInt = bufferReader.read()
+ if (cInt == -1) {
+ log.error("$deviceInfo: Received cInt = -1")
+// bufferReader.close()
+ socketClosed = true
+// sessionListener.notify(NetconfReceivedEvent(
+// NetconfReceivedEvent.Type.SESSION_CLOSED,
+// deviceInfo = deviceInfo))
+ }
+ val c = cInt.toChar()
+ state = state.evaluateChar(c)
+ deviceReplyBuilder.append(c)
+ if (state === NetconfMessageState.END_PATTERN) {
+ var deviceReply = deviceReplyBuilder.toString()
+ if (deviceReply == RpcMessageUtils.END_PATTERN) {
+ socketClosed = true
+ bufferReader.close()
+ sessionListener.notify(NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_UNREGISTERED,
+ deviceInfo = deviceInfo))
+ } else {
+ deviceReply = deviceReply.replace(RpcMessageUtils.END_PATTERN, "")
+ receivedMessage(deviceReply)
+ deviceReplyBuilder.setLength(0)
+ }
+ } else if (state === NetconfMessageState.END_CHUNKED_PATTERN) {
+ var deviceReply = deviceReplyBuilder.toString()
+ if (!NetconfMessageUtils.validateChunkedFraming(deviceReply)) {
+ log.debug("$deviceInfo: Received badly framed message $deviceReply")
+ socketClosed = true
+ sessionListener.notify(NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_ERROR,
+ deviceInfo = deviceInfo))
+ } else {
+ deviceReply = deviceReply.replace(RpcMessageUtils.MSGLEN_REGEX_PATTERN.toRegex(), "")
+ deviceReply = deviceReply.replace(NetconfMessageUtils.CHUNKED_END_REGEX_PATTERN.toRegex(), "")
+ receivedMessage(deviceReply)
+ deviceReplyBuilder.setLength(0)
+ }
+ }
+ }
+
+ } catch (e: IOException) {
+ log.warn("$deviceInfo: Fail while reading from channel", e)
+ sessionListener.notify(NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_ERROR,
+ deviceInfo = deviceInfo))
+ }
+
+ }
+
+ private enum class NetconfMessageState {
+ NO_MATCHING_PATTERN {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return if (c == ']') {
+ FIRST_BRACKET
+ } else if (c == '\n') {
+ FIRST_LF
+ } else {
+ this
+ }
+ }
+ },
+ FIRST_BRACKET {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return if (c == ']') {
+ SECOND_BRACKET
+ } else {
+ NO_MATCHING_PATTERN
+ }
+ }
+ },
+ SECOND_BRACKET {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return if (c == '>') {
+ FIRST_BIGGER
+ } else {
+ NO_MATCHING_PATTERN
+ }
+ }
+ },
+ FIRST_BIGGER {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return if (c == ']') {
+ THIRD_BRACKET
+ } else {
+ NO_MATCHING_PATTERN
+ }
+ }
+ },
+ THIRD_BRACKET {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return if (c == ']') {
+ ENDING_BIGGER
+ } else {
+ NO_MATCHING_PATTERN
+ }
+ }
+ },
+ ENDING_BIGGER {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return if (c == '>') {
+ END_PATTERN
+ } else {
+ NO_MATCHING_PATTERN
+ }
+ }
+ },
+ FIRST_LF {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return if (c == '#') {
+ FIRST_HASH
+ } else if (c == ']') {
+ FIRST_BRACKET
+ } else if (c == '\n') {
+ this
+ } else {
+ NO_MATCHING_PATTERN
+ }
+ }
+ },
+ FIRST_HASH {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return if (c == '#') {
+ SECOND_HASH
+ } else {
+ NO_MATCHING_PATTERN
+ }
+ }
+ },
+ SECOND_HASH {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return if (c == '\n') {
+ END_CHUNKED_PATTERN
+ } else {
+ NO_MATCHING_PATTERN
+ }
+ }
+ },
+ END_CHUNKED_PATTERN {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return NO_MATCHING_PATTERN
+ }
+ },
+ END_PATTERN {
+ override fun evaluateChar(c: Char): NetconfMessageState {
+ return NO_MATCHING_PATTERN
+ }
+ };
+
+ internal abstract fun evaluateChar(c: Char): NetconfMessageState
+ }
+
+ fun sendMessage(request: String, messageId: String): CompletableFuture<String> {
+ log.info("$deviceInfo: Sending message: \n $request")
+ val future = CompletableFuture<String>()
+ replies.put(messageId, future)
+ val outputStream = OutputStreamWriter(out, StandardCharsets.UTF_8)
+ synchronized(this) {
+ try {
+ outputStream.write(request)
+ outputStream.flush()
+ } catch (e: IOException) {
+ log.error("$deviceInfo: Failed to send message : \n $request", e)
+ future.completeExceptionally(e)
+ }
+
+ }
+ return future
+ }
+
+ private fun receivedMessage(deviceReply: String) {
+ if (deviceReply.contains(RpcMessageUtils.RPC_REPLY) || deviceReply.contains(RpcMessageUtils.RPC_ERROR)
+ || deviceReply.contains(RpcMessageUtils.HELLO)) {
+ log.info("$deviceInfo: Received message with messageId: {} \n $deviceReply",
+ NetconfMessageUtils.getMsgId(deviceReply))
+
+ } else {
+ log.error("$deviceInfo: Invalid message received: \n $deviceReply")
+ }
+ sessionListener.notify(NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_REPLY,
+ deviceReply,
+ NetconfMessageUtils.getMsgId(deviceReply),
+ deviceInfo))
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt
new file mode 100644
index 000000000..15fb3122c
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt
@@ -0,0 +1,220 @@
+/*
+ * Copyright © 2017-2019 AT&T, Bell Canada
+ *
+ * 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.functions.netconf.executor.core
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceResponse
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfException
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfRpcService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfSession
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfMessageUtils
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus
+import org.slf4j.LoggerFactory
+import java.util.concurrent.TimeUnit
+import java.util.concurrent.atomic.AtomicInteger
+
+class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcService {
+
+ private val log = LoggerFactory.getLogger(NetconfRpcService::class.java)
+
+ private var responseTimeout: Int = deviceInfo.replyTimeout
+
+ private lateinit var netconfSession: NetconfSession
+
+ private val messageIdInteger = AtomicInteger(1)
+
+ fun setNetconfSession(netconfSession: NetconfSession) {
+ this.netconfSession = netconfSession
+ }
+
+ override fun invokeRpc(rpc: String): DeviceResponse {
+ var output = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ log.info("$deviceInfo: invokeRpc: messageId($messageId)")
+ try {
+ output = asyncRpc(rpc, messageId)
+ } catch (e: Exception) {
+ output.status = RpcStatus.FAILURE
+ output.errorMessage = "$deviceInfo: failed in invokeRpc command $e.message"
+ }
+ return output
+ }
+
+ override fun getConfig(filter: String, configTarget: String): DeviceResponse {
+ var output = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ log.info("$deviceInfo: getConfig: messageId($messageId)")
+ try {
+ val message = NetconfMessageUtils.getConfig(messageId, configTarget, filter)
+ output = asyncRpc(message, messageId)
+ } catch (e: Exception) {
+ output.status = RpcStatus.FAILURE
+ output.errorMessage = "$deviceInfo: failed in get-config command $e.message"
+ }
+ return output
+ }
+
+ override fun deleteConfig(configTarget: String): DeviceResponse {
+ var output = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ log.info("$deviceInfo: deleteConfig: messageId($messageId)")
+ try {
+ val deleteConfigMessage = NetconfMessageUtils.deleteConfig(messageId, configTarget)
+ output.requestMessage = deleteConfigMessage
+ output = asyncRpc(deleteConfigMessage, messageId)
+ } catch (e: Exception) {
+ output.status = RpcStatus.FAILURE
+ output.errorMessage = "$deviceInfo: failed in delete config command $e.message"
+ }
+ return output
+ }
+
+ override fun lock(configTarget: String): DeviceResponse {
+ var output = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ log.info("$deviceInfo: lock: messageId($messageId)")
+ try {
+ val lockMessage = NetconfMessageUtils.lock(messageId, configTarget)
+ output.requestMessage = lockMessage
+ output = asyncRpc(lockMessage, messageId)
+ } catch (e: Exception) {
+ output.status = RpcStatus.FAILURE
+ output.errorMessage = "$deviceInfo: failed in lock command $e.message"
+ }
+
+ return output
+ }
+
+ override fun unLock(configTarget: String): DeviceResponse {
+ var output = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ log.info("$deviceInfo: unLock: messageId($messageId)")
+ try {
+ val unlockMessage = NetconfMessageUtils.unlock(messageId, configTarget)
+ output.requestMessage = unlockMessage
+ output = asyncRpc(unlockMessage, messageId)
+ } catch (e: Exception) {
+ output.status = RpcStatus.FAILURE
+ output.errorMessage = "$deviceInfo: failed in lock command $e.message"
+ }
+ return output
+ }
+
+ override fun commit(confirmed: Boolean, confirmTimeout: Int, persist: String, persistId: String): DeviceResponse {
+ var output = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ log.info("$deviceInfo: commit: messageId($messageId)")
+ try {
+ val messageContent = NetconfMessageUtils.commit(messageId, confirmed, confirmTimeout, persist, persistId)
+ output = asyncRpc(messageContent, messageId)
+ } catch (e: Exception) {
+ output.status = RpcStatus.FAILURE
+ output.errorMessage = "$deviceInfo: failed in commit command $e.message"
+ }
+ return output
+ }
+
+ override fun cancelCommit(persistId: String): DeviceResponse {
+ var output = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ log.info("$deviceInfo: cancelCommit: messageId($messageId)")
+ try {
+ val messageContent = NetconfMessageUtils.cancelCommit(messageId, persistId)
+ output = asyncRpc(messageContent, messageId)
+ } catch (e: Exception) {
+ output.status = RpcStatus.FAILURE
+ output.errorMessage = "$deviceInfo: failed in cancelCommit command $e.message"
+ }
+ return output
+ }
+
+ override fun discardConfig(): DeviceResponse {
+ var output = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ log.info("$deviceInfo: discard: messageId($messageId)")
+ try {
+ val discardChangesMessage = NetconfMessageUtils.discardChanges(messageId)
+ output.requestMessage = discardChangesMessage
+ output = asyncRpc(discardChangesMessage, messageId)
+ } catch (e: Exception) {
+ output.status = RpcStatus.FAILURE
+ output.errorMessage = "$deviceInfo: failed in discard changes command " + e.message
+ }
+ return output
+ }
+
+ override fun editConfig(messageContent: String, configTarget: String,
+ editDefaultOperation: String): DeviceResponse {
+ var response = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ log.info("$deviceInfo: editConfig: messageId($messageId)")
+ try {
+ val editMessage =
+ NetconfMessageUtils.editConfig(messageId, configTarget, editDefaultOperation, messageContent)
+ response.requestMessage = editMessage
+ response = asyncRpc(editMessage, messageId)
+ } catch (e: Exception) {
+ response.status = RpcStatus.FAILURE
+ response.errorMessage = e.message
+ }
+ return response
+ }
+
+ override fun validate(configTarget: String): DeviceResponse {
+ var output = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ try {
+ val validateMessage = NetconfMessageUtils.validate(messageId, configTarget)
+ output.requestMessage = validateMessage
+ output = asyncRpc(validateMessage, messageId)
+ } catch (e: Exception) {
+ output.status = RpcStatus.FAILURE
+ output.errorMessage = "$deviceInfo: failed in validate command " + e.message
+ }
+ return output
+ }
+
+ override fun closeSession(force: Boolean): DeviceResponse {
+ var output = DeviceResponse()
+ val messageId = messageIdInteger.getAndIncrement().toString()
+ log.info("$deviceInfo: closeSession: messageId($messageId)")
+ try {
+ val messageContent = NetconfMessageUtils.closeSession(messageId, force)
+ output = asyncRpc(messageContent, messageId)
+ } catch (e: Exception) {
+ output.status = RpcStatus.FAILURE
+ output.errorMessage = "$deviceInfo: failed in closeSession command " + e.message
+ }
+ return output
+ }
+
+ @Throws(NetconfException::class)
+ override fun asyncRpc(request: String, messageId: String): DeviceResponse {
+ val response = DeviceResponse()
+ log.info("$deviceInfo: send asyncRpc with messageId($messageId)")
+ response.requestMessage = request
+
+ val rpcResponse = netconfSession.asyncRpc(request, messageId).get(responseTimeout.toLong(), TimeUnit.SECONDS)
+ if (!NetconfMessageUtils.checkReply(rpcResponse)) {
+ throw NetconfException(rpcResponse)
+ }
+ response.responseMessage = rpcResponse
+ response.status = RpcStatus.SUCCESS
+ response.errorMessage = null
+ return response
+ }
+} \ No newline at end of file
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
new file mode 100644
index 000000000..2dd73ef18
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt
@@ -0,0 +1,287 @@
+/*
+ * Copyright © 2017-2019 AT&T, Bell Canada
+ *
+ * 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.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
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfException
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfReceivedEvent
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfRpcService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfSession
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfSessionListener
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfMessageUtils
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.RpcMessageUtils
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus
+import org.slf4j.LoggerFactory
+import java.io.IOException
+import java.util.*
+import java.util.concurrent.CompletableFuture
+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 {
+
+ private val log = LoggerFactory.getLogger(NetconfSessionImpl::class.java)
+
+ private val errorReplies: MutableList<String> = Collections.synchronizedList(listOf())
+ private val replies: MutableMap<String, CompletableFuture<String>> = ConcurrentHashMap()
+ private val deviceCapabilities = setOf<String>()
+
+ private var connectionTimeout: Long = 0
+ private var replyTimeout: Int = 0
+ private var idleTimeout: Int = 0
+ private var sessionId: String? = null
+
+ private lateinit var session: ClientSession
+ private lateinit var client: SshClient
+ private lateinit var channel: ClientChannel
+ private lateinit var streamHandler: NetconfDeviceCommunicator
+
+ private var capabilities =
+ ImmutableList.of(RpcMessageUtils.NETCONF_10_CAPABILITY, RpcMessageUtils.NETCONF_11_CAPABILITY)
+
+ override fun connect() {
+ try {
+ log.info("$deviceInfo: Connecting to Netconf Device with timeouts C:${deviceInfo.connectTimeout}, " +
+ "R:${deviceInfo.replyTimeout}, I:${deviceInfo.idleTimeout}")
+ startConnection()
+ log.info("$deviceInfo: Connected to Netconf Device")
+ } catch (e: NetconfException) {
+ log.error("$deviceInfo: Netconf Device Connection Failed. ${e.message}")
+ throw NetconfException(e)
+ }
+ }
+
+ override fun disconnect() {
+ if (rpcService.closeSession(false).status.equals(
+ RpcStatus.FAILURE, true)) {
+ rpcService.closeSession(true)
+ }
+
+ session.close()
+ // Closes the socket which should interrupt the streamHandler
+ channel.close()
+ client.close()
+ }
+
+ override fun reconnect() {
+ disconnect()
+ connect()
+ }
+
+ override fun syncRpc(request: String, messageId: String): String {
+ val formattedRequest = NetconfMessageUtils.formatRPCRequest(request, messageId, deviceCapabilities)
+
+ checkAndReestablish()
+
+ try {
+ return streamHandler.sendMessage(formattedRequest, messageId).get(replyTimeout.toLong(), TimeUnit.SECONDS)
+// replies.remove(messageId)
+ } catch (e: InterruptedException) {
+ Thread.currentThread().interrupt()
+ throw NetconfException("$deviceInfo: Interrupted while waiting for reply for request: $formattedRequest", e)
+ } catch (e: TimeoutException) {
+ throw NetconfException("$deviceInfo: Timed out while waiting for reply for request $formattedRequest after $replyTimeout sec.",
+ e)
+ } catch (e: ExecutionException) {
+ log.warn("$deviceInfo: Closing session($sessionId) due to unexpected Error", e)
+ try {
+ session.close()
+ // Closes the socket which should interrupt the streamHandler
+ channel.close()
+ client.close()
+ } catch (ioe: IOException) {
+ log.warn("$deviceInfo: Error closing session($sessionId) for host($deviceInfo)", ioe)
+ }
+
+// NetconfReceivedEvent(NetconfReceivedEvent.Type.SESSION_CLOSED, "",
+// "Closed due to unexpected error " + e.cause, "-1", deviceInfo)
+ errorReplies.clear() // move to cleanUp()?
+ replies.clear()
+
+ throw NetconfException("$deviceInfo: Closing session $sessionId for request $formattedRequest", e)
+ }
+ }
+
+ override fun asyncRpc(request: String, messageId: String): CompletableFuture<String> {
+ val formattedRequest = NetconfMessageUtils.formatRPCRequest(request, messageId, deviceCapabilities)
+
+ checkAndReestablish()
+
+ return streamHandler.sendMessage(formattedRequest, messageId).handleAsync { reply, t ->
+ if (t != null) {
+ throw NetconfException(messageId, t)
+ }
+ reply
+ }
+ }
+
+ override fun checkAndReestablish() {
+ try {
+ if (client.isClosed) {
+ log.info("Trying to restart the whole SSH connection with {}", deviceInfo)
+ replies.clear()
+ startConnection()
+ } else if (session.isClosed) {
+ log.info("Trying to restart the session with {}", deviceInfo)
+ replies.clear()
+ startSession()
+ } else if (channel.isClosed) {
+ log.info("Trying to reopen the channel with {}", deviceInfo)
+ replies.clear()
+ openChannel()
+ } else {
+ return
+ }
+ } catch (e: IOException) {
+ log.error("Can't reopen connection for device {}", e.message)
+ throw NetconfException(String.format("Cannot re-open the connection with device (%s)", deviceInfo), e)
+ } catch (e: IllegalStateException) {
+ log.error("Can't reopen connection for device {}", e.message)
+ throw NetconfException(String.format("Cannot re-open the connection with device (%s)", deviceInfo), e)
+ }
+
+ }
+
+ override fun getDeviceInfo(): DeviceInfo {
+ return deviceInfo
+ }
+
+ override fun getSessionId(): String {
+ return this.sessionId!!
+ }
+
+ override fun getDeviceCapabilitiesSet(): Set<String> {
+ return Collections.unmodifiableSet(deviceCapabilities)
+ }
+
+ private fun startConnection() {
+ connectionTimeout = deviceInfo.connectTimeout
+ replyTimeout = deviceInfo.replyTimeout
+ idleTimeout = deviceInfo.idleTimeout
+ try {
+ startClient()
+ } catch (e: Exception) {
+ throw NetconfException("$deviceInfo: Failed to establish SSH session", e)
+ }
+
+ }
+
+ private fun startClient() {
+ client = SshClient.setUpDefaultClient()
+ client.properties.putIfAbsent(FactoryManager.IDLE_TIMEOUT, TimeUnit.SECONDS.toMillis(idleTimeout.toLong()))
+ client.properties.putIfAbsent(FactoryManager.NIO2_READ_TIMEOUT, TimeUnit.SECONDS.toMillis(idleTimeout + 15L))
+ client.keyPairProvider = SimpleGeneratorHostKeyProvider()
+ client.start()
+
+ startSession()
+ }
+
+ private fun startSession() {
+ log.info("$deviceInfo: Starting SSH session")
+ val connectFuture = client.connect(deviceInfo.username, deviceInfo.ipAddress, deviceInfo.port)
+ .verify(connectionTimeout, TimeUnit.SECONDS)
+ session = connectFuture.session
+ log.info("$deviceInfo: SSH session created")
+
+ authSession()
+ }
+
+ private fun authSession() {
+ session.addPasswordIdentity(deviceInfo.password)
+ session.auth().verify(connectionTimeout, TimeUnit.SECONDS)
+ val event = session.waitFor(ImmutableSet.of(ClientSession.ClientSessionEvent.WAIT_AUTH,
+ ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.AUTHED), 0)
+ if (!event.contains(ClientSession.ClientSessionEvent.AUTHED)) {
+ throw NetconfException("$deviceInfo: Failed to authenticate session.")
+ }
+ log.info("$deviceInfo: SSH session authenticated")
+
+ openChannel()
+ }
+
+ private fun openChannel() {
+ channel = session.createSubsystemChannel("netconf")
+ val channelFuture = channel.open()
+ if (channelFuture.await(connectionTimeout, TimeUnit.SECONDS) && channelFuture.isOpened) {
+ log.info("$deviceInfo: SSH NETCONF subsystem channel opened")
+ setupHandler()
+ } else {
+ throw NetconfException("$deviceInfo: Failed to open SSH subsystem channel")
+ }
+ }
+
+ private fun setupHandler() {
+ val sessionListener: NetconfSessionListener = NetconfSessionListenerImpl()
+ streamHandler = NetconfDeviceCommunicator(channel.invertedOut, channel.invertedIn, deviceInfo,
+ sessionListener, replies)
+
+ exchangeHelloMessage()
+ }
+
+ private fun exchangeHelloMessage() {
+ sessionId = "-1"
+ val messageId = "-1"
+
+ val serverHelloResponse = syncRpc(NetconfMessageUtils.createHelloString(capabilities), messageId)
+ val sessionIDMatcher = NetconfMessageUtils.SESSION_ID_REGEX_PATTERN.matcher(serverHelloResponse)
+
+ if (sessionIDMatcher.find()) {
+ sessionId = sessionIDMatcher.group(1)
+ } else {
+ throw NetconfException("$deviceInfo: Missing sessionId in server hello message: $serverHelloResponse")
+ }
+
+ val capabilityMatcher = NetconfMessageUtils.CAPABILITY_REGEX_PATTERN.matcher(serverHelloResponse)
+ while (capabilityMatcher.find()) {
+ deviceCapabilities.plus(capabilityMatcher.group(1))
+ }
+ }
+
+ inner class NetconfSessionListenerImpl : NetconfSessionListener {
+ override fun notify(event: NetconfReceivedEvent) {
+ val messageId = event.getMessageID()
+
+ when (event.getType()) {
+ NetconfReceivedEvent.Type.DEVICE_UNREGISTERED -> disconnect()
+ NetconfReceivedEvent.Type.DEVICE_ERROR -> errorReplies.add(event.getMessagePayload())
+ NetconfReceivedEvent.Type.DEVICE_REPLY -> replies[messageId]?.complete(event.getMessagePayload())
+ NetconfReceivedEvent.Type.SESSION_CLOSED -> disconnect()
+ }
+ }
+ }
+
+ 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/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt
new file mode 100644
index 000000000..3b3b0c025
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt
@@ -0,0 +1,90 @@
+/*
+ * Copyright © 2017-2019 AT&T, Bell Canada
+ *
+ * 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.functions.netconf.executor.utils
+
+enum class NetconfDatastore(val datastore: String) {
+ RUNNING("running"),
+ CANDIDATE("candidate");
+}
+
+enum class ModifyAction(val action: String) {
+ MERGE("merge"),
+ REPLACE("replace"),
+ NONE("none")
+}
+
+object RpcStatus {
+ const val SUCCESS = "success"
+ const val FAILURE = "failure"
+}
+
+object RpcMessageUtils {
+ const val OPEN = "<"
+ const val CLOSE = ">"
+ const val EQUAL = "="
+
+ const val HASH = "#"
+ const val HASH_CHAR = '#'
+
+ const val LF_CHAR = '\n'
+ const val NEW_LINE = "\n"
+
+ const val QUOTE = "\""
+ const val QUOTE_SPACE = "\" "
+
+ const val TAG_CLOSE = "/>"
+ const val END_OF_RPC_OPEN_TAG = "\">"
+ const val END_PATTERN = "]]>]]>"
+
+ const val HELLO = "hello"
+ const val RPC_REPLY = "rpc-reply"
+ const val RPC_ERROR = "rpc-error"
+
+ const val RPC_OPEN = "<rpc "
+ const val RPC_CLOSE = "</rpc>"
+ const val WITH_DEFAULT_OPEN = "<with-defaults "
+ const val WITH_DEFAULT_CLOSE = "</with-defaults>"
+ const val DEFAULT_OPERATION_OPEN = "<default-operation>"
+ const val DEFAULT_OPERATION_CLOSE = "</default-operation>"
+ const val SUBTREE_FILTER_OPEN = "<filter type=\"subtree\">"
+ const val SUBTREE_FILTER_CLOSE = "</filter>"
+ const val TARGET_OPEN = "<target>"
+ const val TARGET_CLOSE = "</target>"
+ const val SOURCE_OPEN = "<source>"
+ const val SOURCE_CLOSE = "</source>"
+ const val CONFIG_OPEN = "<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
+ const val CONFIG_CLOSE = "</config>"
+ const val MSGLEN_REGEX_PATTERN = "\n#\\d+\n"
+
+ const val NUMBER_BETWEEN_QUOTES_MATCHER = "\"+([0-9]+)+\""
+
+ const val XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ const val NETCONF_BASE_NAMESPACE = "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\""
+ const val NETCONF_WITH_DEFAULTS_NAMESPACE = "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""
+ const val SUBSCRIPTION_SUBTREE_FILTER_OPEN =
+ "<filter xmlns:base10=\"urn:ietf:params:xml:ns:netconf:base:1.0\" base10:type=\"subtree\">"
+
+ const val INTERLEAVE_CAPABILITY_STRING = "urn:ietf:params:netconf:capability:interleave:1.0"
+
+ const val CAPABILITY_REGEX = "capability>\\s*(.*?)\\s*capability>"
+
+ const val SESSION_ID_REGEX = "session-id>\\s*(.*?)\\s*session-id>"
+
+ const val MESSAGE_ID_STRING = "message-id"
+
+ const val NETCONF_10_CAPABILITY = "urn:ietf:params:netconf:base:1.0"
+ const val NETCONF_11_CAPABILITY = "urn:ietf:params:netconf:base:1.1"
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt
new file mode 100644
index 000000000..4de3860c5
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt
@@ -0,0 +1,404 @@
+/*
+ * Copyright © 2017-2019 AT&T, Bell Canada
+ *
+ * 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.functions.netconf.executor.utils
+
+import org.apache.commons.lang3.StringUtils
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfException
+import org.slf4j.LoggerFactory
+import org.xml.sax.InputSource
+import java.io.StringReader
+import java.nio.charset.StandardCharsets
+import java.util.regex.MatchResult
+import java.util.regex.Pattern
+import javax.xml.XMLConstants
+import javax.xml.parsers.DocumentBuilderFactory
+import kotlin.text.Charsets.UTF_8
+
+
+class NetconfMessageUtils {
+
+ companion object {
+ val log = LoggerFactory.getLogger(NetconfMessageUtils::class.java)
+
+ const val NEW_LINE = "\n"
+ const val CHUNKED_END_REGEX_PATTERN = "\n##\n"
+
+ val CAPABILITY_REGEX_PATTERN: Pattern = Pattern.compile(RpcMessageUtils.CAPABILITY_REGEX)
+ val SESSION_ID_REGEX_PATTERN: Pattern = Pattern.compile(RpcMessageUtils.SESSION_ID_REGEX)
+
+ private val CHUNKED_FRAMING_PATTERN: Pattern =
+ Pattern.compile("(\\n#([1-9][0-9]*)\\n(.+))+\\n##\\n", Pattern.DOTALL)
+ private val CHUNKED_SIZE_PATTERN: Pattern = Pattern.compile("\\n#([1-9][0-9]*)\\n")
+ private val MSG_ID_STRING_PATTERN = Pattern.compile("${RpcMessageUtils.MESSAGE_ID_STRING}=\"(.*?)\"")
+
+ fun getConfig(messageId: String, configType: String, filterContent: String?): String {
+ val request = StringBuilder()
+
+ request.append("<get-config>").append(NEW_LINE)
+ request.append(RpcMessageUtils.SOURCE_OPEN).append(NEW_LINE)
+ request.append(RpcMessageUtils.OPEN).append(configType).append(RpcMessageUtils.TAG_CLOSE)
+ .append(NEW_LINE)
+ request.append(RpcMessageUtils.SOURCE_CLOSE).append(NEW_LINE)
+
+ if (!filterContent.isNullOrEmpty()) {
+ request.append(RpcMessageUtils.SUBTREE_FILTER_OPEN).append(NEW_LINE)
+ request.append(filterContent).append(NEW_LINE)
+ request.append(RpcMessageUtils.SUBTREE_FILTER_CLOSE).append(NEW_LINE)
+ }
+ request.append("</get-config>").append(NEW_LINE)
+
+ return doWrappedRpc(messageId, request.toString())
+ }
+
+ fun doWrappedRpc(messageId: String, request: String): String {
+ val rpc = StringBuilder(RpcMessageUtils.XML_HEADER).append(NEW_LINE)
+ rpc.append(RpcMessageUtils.RPC_OPEN)
+ rpc.append(RpcMessageUtils.MESSAGE_ID_STRING).append(RpcMessageUtils.EQUAL)
+ rpc.append(RpcMessageUtils.QUOTE).append(messageId).append(RpcMessageUtils.QUOTE_SPACE)
+ rpc.append(RpcMessageUtils.NETCONF_BASE_NAMESPACE).append(RpcMessageUtils.CLOSE)
+ .append(NEW_LINE)
+ rpc.append(request)
+ rpc.append(RpcMessageUtils.RPC_CLOSE)
+ // rpc.append(NEW_LINE).append(END_PATTERN);
+
+ return rpc.toString()
+ }
+
+ fun editConfig(messageId: String, configType: String, defaultOperation: String?,
+ newConfiguration: String): String {
+
+ val request = StringBuilder()
+
+ request.append("<edit-config>").append(NEW_LINE)
+ request.append(RpcMessageUtils.TARGET_OPEN).append(NEW_LINE)
+ request.append(RpcMessageUtils.OPEN).append(configType).append(RpcMessageUtils.TAG_CLOSE)
+ .append(NEW_LINE)
+ request.append(RpcMessageUtils.TARGET_CLOSE).append(NEW_LINE)
+
+ if (defaultOperation != null) {
+ request.append(RpcMessageUtils.DEFAULT_OPERATION_OPEN).append(defaultOperation)
+ .append(RpcMessageUtils.DEFAULT_OPERATION_CLOSE)
+ request.append(NEW_LINE)
+ }
+
+ request.append(RpcMessageUtils.CONFIG_OPEN).append(NEW_LINE)
+ request.append(newConfiguration.trim { it <= ' ' }).append(NEW_LINE)
+ request.append(RpcMessageUtils.CONFIG_CLOSE).append(NEW_LINE)
+ request.append("</edit-config>").append(NEW_LINE)
+
+ return doWrappedRpc(messageId, request.toString())
+ }
+
+ fun validate(messageId: String, configType: String): String {
+ val request = StringBuilder()
+
+ request.append("<validate>").append(NEW_LINE)
+ request.append(RpcMessageUtils.SOURCE_OPEN).append(NEW_LINE)
+ request.append(RpcMessageUtils.OPEN).append(configType).append(RpcMessageUtils.TAG_CLOSE)
+ .append(NEW_LINE)
+ request.append(RpcMessageUtils.SOURCE_CLOSE).append(NEW_LINE)
+ request.append("</validate>").append(NEW_LINE)
+
+ return doWrappedRpc(messageId, request.toString())
+ }
+
+ fun commit(messageId: String, confirmed: Boolean, confirmTimeout: Int, persist: String,
+ persistId: String): String {
+
+ if (!persist.isEmpty() && !persistId.isEmpty()) {
+ throw NetconfException("Can't proceed <commit> with both persist($persist) and " +
+ "persistId($persistId) specified. Only one should be specified.")
+ }
+ if (confirmed && !persistId.isEmpty()) {
+ throw NetconfException("Can't proceed <commit> with both confirmed flag and " +
+ "persistId($persistId) specified. Only one should be specified.")
+ }
+
+ val request = StringBuilder()
+ request.append("<commit>").append(NEW_LINE)
+ if (confirmed) {
+ request.append("<confirmed/>")
+ request.append("<confirm-timeout>$confirmTimeout</confirm-timeout>")
+ if (!persist.isEmpty()) {
+ request.append("<persist>$persist</persist>")
+ }
+ }
+ if (!persistId.isEmpty()) {
+ request.append("<persist-id>$persistId</persist-id>")
+ }
+ request.append("</commit>").append(NEW_LINE)
+
+ return doWrappedRpc(messageId, request.toString())
+ }
+
+ fun cancelCommit(messageId: String, persistId: String): String {
+ val request = StringBuilder()
+ request.append("<cancel-commit>").append(NEW_LINE)
+ if (!persistId.isEmpty()) {
+ request.append("<persist-id>$persistId</persist-id>")
+ }
+ request.append("</cancel-commit>").append(NEW_LINE)
+
+ return doWrappedRpc(messageId, request.toString())
+ }
+
+ fun unlock(messageId: String, configType: String): String {
+ val request = StringBuilder()
+
+ request.append("<unlock>").append(NEW_LINE)
+ request.append(RpcMessageUtils.TARGET_OPEN).append(NEW_LINE)
+ request.append(RpcMessageUtils.OPEN).append(configType).append(RpcMessageUtils.TAG_CLOSE)
+ .append(NEW_LINE)
+ request.append(RpcMessageUtils.TARGET_CLOSE).append(NEW_LINE)
+ request.append("</unlock>").append(NEW_LINE)
+
+ return doWrappedRpc(messageId, request.toString())
+ }
+
+ @Throws(NetconfException::class)
+ fun deleteConfig(messageId: String, configType: String): String {
+ if (configType == NetconfDatastore.RUNNING.datastore) {
+ log.warn("Target configuration for delete operation can't be \"running\" {}", configType)
+ throw NetconfException("Target configuration for delete operation can't be running")
+ }
+
+ val request = StringBuilder()
+
+ request.append("<delete-config>").append(NEW_LINE)
+ request.append(RpcMessageUtils.TARGET_OPEN).append(NEW_LINE)
+ request.append(RpcMessageUtils.OPEN).append(configType)
+ .append(RpcMessageUtils.TAG_CLOSE)
+ .append(NEW_LINE)
+ request.append(RpcMessageUtils.TARGET_CLOSE).append(NEW_LINE)
+ request.append("</delete-config>").append(NEW_LINE)
+
+ return doWrappedRpc(messageId, request.toString())
+ }
+
+ fun discardChanges(messageId: String): String {
+ val request = StringBuilder()
+ request.append("<discard-changes/>").append(NEW_LINE)
+ return doWrappedRpc(messageId, request.toString())
+ }
+
+ fun lock(messageId: String, configType: String): String {
+ val request = StringBuilder()
+
+ request.append("<lock>").append(NEW_LINE)
+ request.append(RpcMessageUtils.TARGET_OPEN).append(NEW_LINE)
+ request.append(RpcMessageUtils.OPEN).append(configType).append(RpcMessageUtils.TAG_CLOSE)
+ .append(NEW_LINE)
+ request.append(RpcMessageUtils.TARGET_CLOSE).append(NEW_LINE)
+ request.append("</lock>").append(NEW_LINE)
+
+ return doWrappedRpc(messageId, request.toString())
+ }
+
+ fun closeSession(messageId: String, force: Boolean): String {
+ val request = StringBuilder()
+
+ if (force) {
+ request.append("<kill-session/>").append(NEW_LINE)
+ } else {
+ request.append("<close-session/>").append(NEW_LINE)
+ }
+
+ return doWrappedRpc(messageId, request.toString())
+ }
+
+ fun validateRPCXML(rpcRequest: String): Boolean {
+ try {
+ if (StringUtils.isBlank(rpcRequest)) {
+ return false
+ }
+ val dbf = DocumentBuilderFactory.newInstance()
+ dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true)
+ dbf.setFeature("http://xml.org/sax/features/external-general-entities", false)
+ dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false)
+ dbf.newDocumentBuilder()
+ .parse(InputSource(StringReader(rpcRequest.replace(RpcMessageUtils.END_PATTERN, ""))))
+ return true
+ } catch (e: Exception) {
+ return false
+ }
+
+ }
+
+ fun getMsgId(message: String): String {
+ val matcher = MSG_ID_STRING_PATTERN.matcher(message)
+ if (matcher.find()) {
+ return matcher.group(1)
+ }
+ return if (message.contains(RpcMessageUtils.HELLO)) {
+ (-1).toString()
+ } else ""
+ }
+
+ fun validateChunkedFraming(reply: String): Boolean {
+ val matcher = CHUNKED_FRAMING_PATTERN.matcher(reply)
+ if (!matcher.matches()) {
+ log.debug("Error Reply: {}", reply)
+ return false
+ }
+ val chunkM = CHUNKED_SIZE_PATTERN.matcher(reply)
+ val chunks = ArrayList<MatchResult>()
+ var chunkdataStr = ""
+ while (chunkM.find()) {
+ chunks.add(chunkM.toMatchResult())
+ // extract chunk-data (and later) in bytes
+ val bytes = Integer.parseInt(chunkM.group(1))
+ val chunkdata = reply.substring(chunkM.end()).toByteArray(StandardCharsets.UTF_8)
+ if (bytes > chunkdata.size) {
+ log.debug("Error Reply - wrong chunk size {}", reply)
+ return false
+ }
+ // convert (only) chunk-data part into String
+ chunkdataStr = String(chunkdata, 0, bytes, StandardCharsets.UTF_8)
+ // skip chunk-data part from next match
+ chunkM.region(chunkM.end() + chunkdataStr.length, reply.length)
+ }
+ if (!CHUNKED_END_REGEX_PATTERN.equals(reply.substring(chunks[chunks.size - 1].end() + chunkdataStr.length))) {
+ log.debug("Error Reply: {}", reply)
+ return false
+ }
+ return true
+ }
+
+ fun createHelloString(capabilities: List<String>): String {
+ val helloMessage = StringBuilder()
+ helloMessage.append(RpcMessageUtils.XML_HEADER).append(NEW_LINE)
+ helloMessage.append("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">").append(NEW_LINE)
+ helloMessage.append(" <capabilities>").append(NEW_LINE)
+ if (capabilities.isNotEmpty()) {
+ capabilities.forEach { cap ->
+ helloMessage.append(" <capability>").append(cap).append("</capability>").append(NEW_LINE)
+ }
+ }
+ helloMessage.append(" </capabilities>").append(NEW_LINE)
+ helloMessage.append("</hello>").append(NEW_LINE)
+ helloMessage.append(RpcMessageUtils.END_PATTERN)
+ return helloMessage.toString()
+ }
+
+ fun formatRPCRequest(request: String, messageId: String, deviceCapabilities: Set<String>): String {
+ var request = request
+ request = NetconfMessageUtils.formatNetconfMessage(deviceCapabilities, request)
+ request = NetconfMessageUtils.formatXmlHeader(request)
+ request = NetconfMessageUtils.formatRequestMessageId(request, messageId)
+
+ return request
+ }
+
+ /**
+ * Validate and format netconf message. - NC1.0 if no EOM sequence present on `message`,
+ * append. - NC1.1 chunk-encode given message unless it already is chunk encoded
+ *
+ * @param deviceCapabilities Set containing Device Capabilities
+ * @param message to format
+ * @return formated message
+ */
+ fun formatNetconfMessage(deviceCapabilities: Set<String>, message: String): String {
+ var message = message
+ if (deviceCapabilities.contains(RpcMessageUtils.NETCONF_11_CAPABILITY)) {
+ message = formatChunkedMessage(message)
+ } else if (!message.endsWith(RpcMessageUtils.END_PATTERN)) {
+ message = message + NEW_LINE + RpcMessageUtils.END_PATTERN
+ }
+ return message
+ }
+
+ /**
+ * Validate and format message according to chunked framing mechanism.
+ *
+ * @param message to format
+ * @return formated message
+ */
+ fun formatChunkedMessage(message: String): String {
+ var message = message
+ if (message.endsWith(RpcMessageUtils.END_PATTERN)) {
+ // message given had Netconf 1.0 EOM pattern -> remove
+ message = message.substring(0, message.length - RpcMessageUtils.END_PATTERN.length)
+ }
+ if (!message.startsWith(RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH)) {
+ // chunk encode message
+ message =
+ (RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + message.toByteArray(UTF_8).size + RpcMessageUtils.NEW_LINE + message + RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH
+ + RpcMessageUtils.NEW_LINE)
+ }
+ return message
+ }
+
+ /**
+ * Ensures xml start directive/declaration appears in the `request`.
+ *
+ * @param request RPC request message
+ * @return XML RPC message
+ */
+ fun formatXmlHeader(request: String): String {
+ var request = request
+ if (!request.contains(RpcMessageUtils.XML_HEADER)) {
+ if (request.startsWith(RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH)) {
+ request =
+ request.split("<".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0] + RpcMessageUtils.XML_HEADER + request.substring(
+ request.split("<".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0].length)
+ } else {
+ request = RpcMessageUtils.XML_HEADER + "\n" + request
+ }
+ }
+ return request
+ }
+
+ fun formatRequestMessageId(request: String, messageId: String): String {
+ var request = request
+ if (request.contains(RpcMessageUtils.MESSAGE_ID_STRING)) {
+ request =
+ request.replaceFirst((RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.NUMBER_BETWEEN_QUOTES_MATCHER).toRegex(),
+ RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.QUOTE + messageId + RpcMessageUtils.QUOTE)
+ } else if (!request.contains(RpcMessageUtils.MESSAGE_ID_STRING) && !request.contains(
+ RpcMessageUtils.HELLO)) {
+ request = request.replaceFirst(RpcMessageUtils.END_OF_RPC_OPEN_TAG.toRegex(),
+ RpcMessageUtils.QUOTE_SPACE + RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.QUOTE + messageId + RpcMessageUtils.QUOTE + ">")
+ }
+ return updateRequestLength(request)
+ }
+
+ fun updateRequestLength(request: String): String {
+ if (request.contains(NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH + NEW_LINE)) {
+ val oldLen =
+ Integer.parseInt(request.split(RpcMessageUtils.HASH.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[1].split(
+ NEW_LINE.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[0])
+ val rpcWithEnding = request.substring(request.indexOf('<'))
+ val firstBlock =
+ request.split(RpcMessageUtils.MSGLEN_REGEX_PATTERN.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[1].split(
+ (NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH + NEW_LINE).toRegex()).dropLastWhile(
+ { it.isEmpty() }).toTypedArray()[0]
+ var newLen = 0
+ newLen = firstBlock.toByteArray(UTF_8).size
+ if (oldLen != newLen) {
+ return NEW_LINE + RpcMessageUtils.HASH + newLen + NEW_LINE + rpcWithEnding
+ }
+ }
+ return request
+ }
+
+ fun checkReply(reply: String?): Boolean {
+ return if (reply != null) {
+ !reply.contains("rpc-error>") || reply.contains("warning") || reply.contains("ok/>")
+ } 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/ComponentNetconfExecutorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt
new file mode 100644
index 000000000..e2b901998
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt
@@ -0,0 +1,79 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Modifications Copyright © 2019 IBM, Bell Canada.
+ *
+ * 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.functions.netconf.executor
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
+import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.test.annotation.DirtiesContext
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+
+@RunWith(SpringRunner::class)
+@EnableAutoConfiguration
+@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
+@DirtiesContext
+@TestPropertySource(properties =
+["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf,./../../../../components/scripts/python/ccsdk_blueprints",
+ "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_netconf"],
+ locations = ["classpath:application-test.properties"])
+class ComponentNetconfExecutorTest {
+
+ @Autowired
+ lateinit var componentNetconfExecutor: ComponentNetconfExecutor
+
+
+ @Test
+ fun testComponentNetconfExecutor() {
+
+ val executionServiceInput = JacksonUtils.readValueFromClassPathFile("requests/sample-activate-request.json",
+ ExecutionServiceInput::class.java)!!
+
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+
+ val executionContext = bluePrintRuntimeService.getExecutionContext()
+
+
+ componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
+
+ //TODO("Set Attribute properties")
+ val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-netconf")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentNetconfExecutor")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
+ // Set Step Inputs in Blueprint Runtime Service
+ bluePrintRuntimeService.put("activate-netconf-step-inputs", stepMetaData.asJsonNode())
+
+ componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
+ componentNetconfExecutor.stepName = "activate-netconf"
+ componentNetconfExecutor.apply(executionServiceInput)
+
+ }
+}
+
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
new file mode 100644
index 000000000..e7a514347
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt
@@ -0,0 +1,111 @@
+/*
+ * 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.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 {
+
+ 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()
+ }
+
+ @Throws(Exception::class)
+ fun testNetconfSession() {
+ val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(DeviceInfo()))
+
+ Assert.assertNotNull(netconfSession.getSessionId())
+ Assert.assertEquals("localhost:2224", netconfSession.getDeviceInfo().toString())
+
+ netconfSession.checkAndReestablish()
+
+ Assert.assertNotNull(netconfSession.getSessionId())
+ Assert.assertEquals("localhost:2224", netconfSession.getDeviceInfo().toString())
+
+ 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 000000000..8f1f71501
--- /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/mocks/NetconfDeviceSimulator.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfDeviceSimulator.kt
new file mode 100644
index 000000000..a2a3946db
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfDeviceSimulator.kt
@@ -0,0 +1,62 @@
+/*
+ * 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.functions.netconf.executor.mocks
+
+
+import org.apache.sshd.common.NamedFactory
+import org.apache.sshd.server.Command
+import org.apache.sshd.server.SshServer
+import org.apache.sshd.server.auth.UserAuth
+import org.apache.sshd.server.auth.UserAuthNoneFactory
+import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfSubsystemFactory
+import java.util.*
+
+
+class NetconfDeviceSimulator(private val port: Int) {
+
+ private var sshd: SshServer? = null
+
+ fun start() {
+ sshd = SshServer.setUpDefaultServer()
+ sshd!!.port = port
+ sshd!!.keyPairProvider = SimpleGeneratorHostKeyProvider()
+
+ val userAuthFactories = ArrayList<NamedFactory<UserAuth>>()
+ userAuthFactories.add(UserAuthNoneFactory())
+ sshd!!.userAuthFactories = userAuthFactories
+
+ val namedFactoryList = ArrayList<NamedFactory<Command>>()
+ namedFactoryList.add(NetconfSubsystemFactory())
+ sshd!!.subsystemFactories = namedFactoryList
+
+ try {
+ sshd!!.start()
+ } catch (e: Exception) {
+ e.printStackTrace()
+ }
+
+ }
+
+ fun stop() {
+ try {
+ sshd!!.stop(true)
+ } catch (e: Exception) {
+ e.printStackTrace()
+ }
+
+ }
+} \ 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/mocks/NetconfSubsystemFactory.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt
new file mode 100644
index 000000000..7eaef030b
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt
@@ -0,0 +1,125 @@
+/*
+ * 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.functions.netconf.executor.utils
+
+
+import java.io.IOException
+import java.io.InputStream
+import java.io.OutputStream
+import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.server.Command;
+import org.apache.sshd.server.Environment;
+import org.apache.sshd.server.ExitCallback;
+
+
+class NetconfSubsystemFactory : NamedFactory<Command> {
+
+ private val END_CHAR_SEQUENCE = "]]>]]>"
+
+ override fun create(): Command {
+ return NetconfSubsystem()
+ }
+
+ override fun getName(): String {
+ return "netconf"
+ }
+
+ /**
+ * Simple implementation of netconf reading 1 request, sending a 'hello' response and quitting
+ */
+ inner class NetconfSubsystem : Command {
+ private var input: InputStream? = null
+ private var out: OutputStream? = null
+ private var clientThread: Thread? = null
+ private var r: Int = 0
+
+ @Throws(IOException::class)
+ override fun start(env: Environment) {
+ clientThread = Thread(object : Runnable {
+
+ override fun run() {
+ try {
+ val message = StringBuilder()
+ while (true) {
+ process(createHelloString())
+ r = input!!.read()
+ if (r == -1) {
+ break
+ } else {
+ val c = r.toChar()
+ message.append(c)
+ val messageString = message.toString()
+ if (messageString.endsWith(END_CHAR_SEQUENCE)) {
+ println("Detected end message:\n$messageString")
+ process(createHelloString())
+ message.setLength(0)
+ break
+ }
+ }
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+
+ }
+
+ @Throws(IOException::class)
+ private fun process(xmlMessage: String) {
+ println("Sending message:\n$xmlMessage")
+ out!!.write(xmlMessage.toByteArray(charset("UTF-8")))
+ out!!.write((END_CHAR_SEQUENCE + "\n").toByteArray(charset("UTF-8")))
+ out!!.flush()
+ }
+
+ private fun createHelloString(): String {
+ val sessionId = "" + (Math.random() * Integer.MAX_VALUE).toInt()
+ return ("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+ + "<capabilities>\n<capability>urn:ietf:params:netconf:base:1.0</capability>\n"
+ + "<capability>urn:ietf:params:netconf:base:1.1</capability>\n</capabilities>\n"
+ + "<session-id>" + sessionId + "</session-id>\n</hello>")
+ }
+ })
+
+ clientThread!!.start()
+ }
+
+ @Throws(Exception::class)
+ override fun destroy() {
+ try {
+ clientThread!!.join(2000)
+ } catch (e: InterruptedException) {
+ // log.warn("Error joining Client thread" + e.getMessage());
+ }
+
+ clientThread!!.interrupt()
+ }
+
+ override fun setInputStream(input: InputStream) {
+ this.input = input
+ }
+
+ override fun setOutputStream(out: OutputStream) {
+ this.out = out
+ }
+
+ override fun setErrorStream(err: OutputStream) {}
+
+ override fun setExitCallback(callback: ExitCallback) {}
+
+
+
+ }
+} \ 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
new file mode 100644
index 000000000..8a60d8097
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt
@@ -0,0 +1,306 @@
+/*
+ * 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.functions.netconf.executor.utils
+
+import org.junit.Assert
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfException
+import kotlin.test.fail
+
+class RpcMessageUtilsTest {
+
+ @Test
+ fun getConfig() {
+ 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>")
+
+ val messageId = "Test-Message-ID"
+ val configType = NetconfDatastore.CANDIDATE.datastore
+ val filterContent = "Test-Filter-Content"
+
+ val result =
+ NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(result))
+ Assert.assertEquals(checkString, result)
+ }
+
+
+ @Test
+ 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\">"
+ + "<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.editConfig(messageId, configType, defaultOperation, filterContent).replace("[\n\r\t]".toRegex(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(result))
+ Assert.assertEquals(checkString, result)
+ }
+
+ @Test
+ fun validate() {
+ 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\">"
+ + "<validate><source><candidate/></source></validate></rpc>")
+
+ val messageId = "Test-Message-ID"
+ val configType = NetconfDatastore.CANDIDATE.datastore
+
+ val result = NetconfMessageUtils.validate(messageId, configType).replace("[\n\r\t]".toRegex(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(result))
+ Assert.assertEquals(checkString, result)
+ }
+
+ @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>")
+
+ val messageId = "Test-Message-ID"
+
+ val cancelCommitPersistId =
+ NetconfMessageUtils.cancelCommit(messageId, "1234").replace("[\n\r\t]".toRegex(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitPersistId))
+ Assert.assertEquals(checkString, cancelCommitPersistId)
+ }
+
+ @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>")
+
+ val messageId = "Test-Message-ID"
+
+ val cancelCommitNoPersistId = NetconfMessageUtils.cancelCommit(messageId, "").replace("[\n\r\t]".toRegex(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitNoPersistId))
+ Assert.assertEquals(checkString, cancelCommitNoPersistId)
+ }
+
+ @Test
+ fun commit() {
+ 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></commit></rpc>")
+
+ val messageId = "Test-Message-ID"
+
+ 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(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(commit))
+ Assert.assertEquals(checkString, commit)
+ Assert.assertEquals(checkString, commitWithPersistButNotConfirmed)
+
+ }
+
+ @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>")
+
+ val messageId = "Test-Message-ID"
+
+ val result = NetconfMessageUtils.commit(messageId, false, 30, "", "1234").replace("[\n\r\t]".toRegex(), "")
+ assertTrue(NetconfMessageUtils.validateRPCXML(result))
+ Assert.assertEquals(checkString, result)
+
+ try {
+ 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)
+ return
+ }
+
+ fail()
+ }
+
+ @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>")
+
+ val messageId = "Test-Message-ID"
+
+ val result = NetconfMessageUtils.commit(messageId, true, 30, "1234", "").replace("[\n\r\t]".toRegex(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(result))
+ Assert.assertEquals(checkString, result)
+
+ try {
+ 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)
+ return
+ }
+ fail()
+ }
+
+ @Test
+ fun unlock() {
+ 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\">"
+ + "<unlock><target><candidate/></target></unlock></rpc>")
+
+ val messageId = "Test-Message-ID"
+ val configType = NetconfDatastore.CANDIDATE.datastore
+
+ val result = NetconfMessageUtils.unlock(messageId, configType).replace("[\n\r\t]".toRegex(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(result))
+ Assert.assertEquals(checkString, result)
+ }
+
+ @Test
+ fun deleteConfig() {
+ 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\">"
+ + "<delete-config><target><candidate/></target></delete-config></rpc>")
+
+ val messageId = "Test-Message-ID"
+ val netconfTargetConfig = NetconfDatastore.CANDIDATE.datastore
+
+ val result = NetconfMessageUtils.deleteConfig(messageId, netconfTargetConfig).replace("[\n\r\t]".toRegex(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(result))
+ Assert.assertEquals(checkString, result)
+ }
+
+ @Test
+ fun discardChanges() {
+ 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\">"
+ + "<discard-changes/></rpc>")
+
+ val messageId = "Test-Message-ID"
+
+ val result = NetconfMessageUtils.discardChanges(messageId).replace("[\n\r\t]".toRegex(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(result))
+ Assert.assertEquals(checkString, result)
+ }
+
+ @Test
+ fun lock() {
+ 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\">"
+ + "<lock><target><candidate/></target></lock></rpc>")
+
+ val messageId = "Test-Message-ID"
+ val configType = NetconfDatastore.CANDIDATE.datastore
+ val result = NetconfMessageUtils.lock(messageId, configType).replace("[\n\r\t]".toRegex(), "")
+
+ assertTrue(NetconfMessageUtils.validateRPCXML(result))
+ 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/netconf-executor/src/test/resources/application-test.properties b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/application-test.properties
new file mode 100644
index 000000000..6d8b62ff9
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/application-test.properties
@@ -0,0 +1,32 @@
+#
+# Copyright © 2017-2018 AT&T Intellectual Property.
+#
+# Modifications Copyright © 2019 IBM, Bell Canada.
+#
+# 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.
+#
+blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
+blueprintsprocessor.db.primary.username=sa
+blueprintsprocessor.db.primary.password=
+blueprintsprocessor.db.primary.driverClassName=org.h2.Driver
+blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop
+blueprintsprocessor.db.primary.hibernateDDLAuto=update
+blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
+# Controller Blueprints Core Configuration
+blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy
+blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
+
+# Python executor
+blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
+blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..f9ec9fe57
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml
@@ -0,0 +1,35 @@
+<!--
+ ~ 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.
+ -->
+
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.springframework.test" level="warn"/>
+ <logger name="org.springframework" level="warn"/>
+ <logger name="org.hibernate" level="info"/>
+ <logger name="org.onap.ccsdk.apps.blueprintsprocessor" level="info"/>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+</configuration>
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/payload/requests/sample-activate-request.json b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/payload/requests/sample-activate-request.json
new file mode 100644
index 000000000..694589de1
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/payload/requests/sample-activate-request.json
@@ -0,0 +1,31 @@
+{
+ "actionIdentifiers": {
+ "actionName": "activate",
+ "blueprintName": "baseconfiguration",
+ "blueprintVersion": "1.0.0",
+ "mode": "sync"
+ },
+ "commonHeader": {
+ "flags": {
+ "force": true,
+ "ttl": 3600
+ },
+ "originatorId": "sdnc",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "timestamp": "2012-04-23T18:25:43.511Z"
+ },
+ "payload": {
+ "resource-assignment-request": {
+ "resource-assignment-properties": {
+ "request-id": "1234",
+ "service-instance-id": "siid_1234",
+ "vnf-id": "vnf_1234",
+ "action-name": "assign-activate",
+ "scope-type": "vnf-type",
+ "hostname": "localhost",
+ "vnf_name": "temp_vnf"
+ }
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/running-config-input.json b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/running-config-input.json
new file mode 100644
index 000000000..381cc16cd
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/running-config-input.json
@@ -0,0 +1,15 @@
+{
+ "api-ver": "2.00",
+ "originator-id": "MSO",
+ "request-id": "123456",
+ "service-instance-id": "ibcx0001vm001",
+ "service-type": "AVPN",
+ "vnf-type": "vUSP - vDBE-IPX HUB",
+ "vnf-id": "123456",
+ "service-template-name": "VRR-baseconfiguration",
+ "service-template-version": "1.0.0",
+ "action-name": "running-config-action",
+ "hostname": "localhost",
+ "host-port": "22",
+ "reservation-id": "hostname"
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/sample-activate-request.json b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/sample-activate-request.json
new file mode 100644
index 000000000..d0b4a0c1e
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/sample-activate-request.json
@@ -0,0 +1,28 @@
+{
+ "actionIdentifiers": {
+ "actionName": "activate",
+ "blueprintName": "baseconfiguration",
+ "blueprintVersion": "1.0.0",
+ "mode": "sync"
+ },
+ "commonHeader": {
+ "flags": {
+ "force": true,
+ "ttl": 3600
+ },
+ "originatorId": "sdnc",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "timestamp": "2012-04-23T18:25:43.511Z"
+ },
+ "payload": {
+ "resource-assignment-request": {
+ "resource-assignment-properties": {
+ "request-id": "1234",
+ "action-name": "assign-activate",
+ "scope-type": "vnf-type",
+ "hostname": "localhost"
+ }
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/sample-resourceresolution-request.json b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/sample-resourceresolution-request.json
new file mode 100644
index 000000000..c37e88912
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/requests/sample-resourceresolution-request.json
@@ -0,0 +1,28 @@
+{
+ "actionIdentifiers": {
+ "actionName": "sample-action",
+ "blueprintName": "sample-blurprint",
+ "blueprintVersion": "1.0.0",
+ "mode": "sync"
+ },
+ "commonHeader": {
+ "flags": {
+ "force": true,
+ "ttl": 3600
+ },
+ "originatorId": "sdnc",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "timestamp": "2012-04-23T18:25:43.511Z"
+ },
+ "payload": {
+ "resource-assignment-request": {
+ "resource-assignment-properties": {
+ "request-id": "1234",
+ "action-name": "assign-activate",
+ "scope-type": "vnf-type",
+ "hostname": "localhost"
+ }
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/response/get-config-123456.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/response/get-config-123456.xml
new file mode 100644
index 000000000..85cbeeac4
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/response/get-config-123456.xml
@@ -0,0 +1,10 @@
+<rpc-reply message-id="runningconfig-template-123456"
+ xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
+ xmlns:junos="http://xml.juniper.net/junos/17.4R1/junos">
+ <interface-information
+ xmlns="http://xml.juniper.net/junos/17.4R1/junos-interface">
+ <physical-interface>
+ <name>ge-2/3/0</name>
+ </physical-interface>
+ </interface-information>
+</rpc-reply>
diff --git a/ms/blueprintsprocessor/functions/pom.xml b/ms/blueprintsprocessor/functions/pom.xml
new file mode 100755
index 000000000..5bc26d5f4
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2017-2018 AT&T Intellectual Property.
+ ~ Modifications Copyright © 2018 IBM.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ 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.
+ -->
+<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>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.4.2-SNAPSHOT</version>
+ <relativePath>../parent</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>pom</packaging>
+ <artifactId>functions</artifactId>
+ <name>Blueprints Processor Functions</name>
+ <description>Blueprints Processor Functions</description>
+ <modules>
+ <module>resource-resolution</module>
+ <module>python-executor</module>
+ <module>netconf-executor</module>
+ <module>restconf-executor</module>
+ <module>cli-executor</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
+ <artifactId>execution-service</artifactId>
+ </dependency>
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>io.mockk</groupId>
+ <artifactId>mockk</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-test-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlinx</groupId>
+ <artifactId>kotlinx-coroutines-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.projectreactor</groupId>
+ <artifactId>reactor-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/ms/blueprintsprocessor/functions/python-executor/pom.xml b/ms/blueprintsprocessor/functions/python-executor/pom.xml
new file mode 100644
index 000000000..e0c617493
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/pom.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<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.2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+ <artifactId>python-executor</artifactId>
+ <name>Blueprints Processor Function - Python Executor</name>
+ <description>Blueprints Processor Function - Python Executor</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.python</groupId>
+ <artifactId>jython-standalone</artifactId>
+ </dependency>
+ </dependencies>
+
+
+</project>
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
new file mode 100644
index 000000000..b7f77719e
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Modifications Copyright © 2019 IBM, Bell Canada.
+ *
+ * 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.functions.python.executor
+
+import com.fasterxml.jackson.databind.node.ArrayNode
+import org.apache.commons.io.FilenameUtils
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
+import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationAssignment
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.ApplicationContext
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Component
+
+@Component("component-jython-executor")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class ComponentJythonExecutor(private var applicationContext: ApplicationContext,
+ private val blueprintJythonService: BlueprintJythonService) : AbstractComponentFunction() {
+
+ private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java)
+
+ private var componentFunction: AbstractComponentFunction? = null
+
+ override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
+ val request = super.prepareRequest(executionRequest)
+ // Populate Component Instance
+ populateJythonComponentInstance()
+ return request
+ }
+
+ override fun process(executionRequest: ExecutionServiceInput) {
+ log.info("Processing : $operationInputs")
+ // Invoke Jython Component Script
+ componentFunction!!.process(executionServiceInput)
+
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ componentFunction!!.recover(runtimeException, executionRequest)
+ }
+
+ private fun populateJythonComponentInstance() {
+ val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
+
+ val operationAssignment: OperationAssignment = bluePrintContext
+ .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName)
+
+ val artifactName: String = operationAssignment.implementation?.primary
+ ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)")
+
+ val artifactDefinition = bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName)
+
+ val pythonFileName = artifactDefinition.file
+ ?: throw BluePrintProcessorException("missing file name for node template ($nodeTemplateName)'s artifactName($artifactName)")
+
+ val pythonClassName = FilenameUtils.getBaseName(pythonFileName)
+
+ val content: String? = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
+
+ checkNotEmptyOrThrow(content, "artifact ($artifactName) content is empty")
+
+ val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode
+ ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})")
+
+ val jythonInstance: MutableMap<String, Any> = hashMapOf()
+ jythonInstance["log"] = LoggerFactory.getLogger(pythonClassName)
+ jythonInstance["bluePrintRuntimeService"] = bluePrintRuntimeService
+
+ instanceDependenciesNode.forEach { instanceName ->
+ jythonInstance[instanceName.textValue()] = applicationContext.getBean(instanceName.textValue())
+ }
+
+ // Setup componentFunction
+ componentFunction = blueprintJythonService.jythonInstance(bluePrintContext, pythonClassName,
+ content!!, jythonInstance)
+ componentFunction?.bluePrintRuntimeService = bluePrintRuntimeService
+ componentFunction?.executionServiceInput = executionServiceInput
+ componentFunction?.stepName = stepName
+ componentFunction?.interfaceName = interfaceName
+ componentFunction?.operationName = operationName
+ componentFunction?.processId = processId
+ componentFunction?.workflowName = workflowName
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt
new file mode 100644
index 000000000..dd8eb5033
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt
@@ -0,0 +1,68 @@
+/*
+ * 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.functions.python.executor
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.mock.MockInstanceConfiguration
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorConfiguration
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
+import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [PythonExecutorConfiguration::class, PythonExecutorProperty::class,
+ ComponentJythonExecutor::class, MockInstanceConfiguration::class])
+@TestPropertySource(properties =
+["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints",
+ "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"])
+class ComponentJythonExecutorTest {
+
+ @Autowired
+ lateinit var componentJythonExecutor: ComponentJythonExecutor
+
+ @Test
+ fun testPythonComponentInjection() {
+ val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-activate-request.json",
+ ExecutionServiceInput::class.java)!!
+
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+
+ val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-jython")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentJythonExecutor")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
+ bluePrintRuntimeService.put("activate-jython-step-inputs", stepMetaData.asJsonNode())
+
+ componentJythonExecutor.bluePrintRuntimeService = bluePrintRuntimeService
+ componentJythonExecutor.stepName = "activate-jython"
+
+
+ componentJythonExecutor.apply(executionServiceInput)
+
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/mock/MockInstanceConfiguration.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/mock/MockInstanceConfiguration.kt
new file mode 100644
index 000000000..41250e0ca
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/mock/MockInstanceConfiguration.kt
@@ -0,0 +1,32 @@
+/*
+ * 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.functions.python.executor.mock
+
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+open class MockInstanceConfiguration {
+ @Bean(name = ["json-parser-service", "netconf-rpc-service"])
+ open fun createComponentFunction(): MockJythonService {
+ return MockJythonService()
+ }
+}
+
+class MockJythonService {
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/python-executor/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..a816a06c5
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/src/test/resources/logback-test.xml
@@ -0,0 +1,35 @@
+<!--
+ ~ 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.
+ -->
+
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+
+ <logger name="org.springframework" level="warn"/>
+ <logger name="org.hibernate" level="info"/>
+ <logger name="org.onap.ccsdk.apps.blueprintsprocessor" level="info"/>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+</configuration>
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/resources/payload/requests/sample-activate-request.json b/ms/blueprintsprocessor/functions/python-executor/src/test/resources/payload/requests/sample-activate-request.json
new file mode 100644
index 000000000..7142f0457
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/python-executor/src/test/resources/payload/requests/sample-activate-request.json
@@ -0,0 +1,31 @@
+{
+ "actionIdentifiers": {
+ "actionName": "activate",
+ "blueprintName": "baseconfiguration",
+ "blueprintVersion": "1.0.0",
+ "mode": "sync"
+ },
+ "commonHeader": {
+ "flags": {
+ "force": true,
+ "ttl": 3600
+ },
+ "originatorId": "sdnc",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "timestamp": "2012-04-23T18:25:43.511Z"
+ },
+ "payload": {
+ "resource-assignment-request": {
+ "resource-assignment-properties": {
+ "request-id": "1234",
+ "service-instance-id": "siid_1234",
+ "vnf-id": "vnf_1234",
+ "action-name": "assign-activate",
+ "scope-type": "vnf-type",
+ "hostname": "localhost",
+ "vnf_name": "temp_vnf"
+ }
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml
new file mode 100644
index 000000000..eafdb9a01
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
+ <artifactId>functions</artifactId>
+ <version>0.4.2-SNAPSHOT</version>
+ </parent>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+ <artifactId>resource-resolution</artifactId>
+ <packaging>jar</packaging>
+ <name>Blueprints Processor Function - Resource Resolution</name>
+ <description>Blueprints Processor Function - Resource Resolution</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
+ <artifactId>db-lib</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+ <artifactId>python-executor</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mariadb.jdbc</groupId>
+ <artifactId>mariadb-java-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentProcessorScriptConfiguration.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentProcessorScriptConfiguration.kt
new file mode 100644
index 000000000..ffe09e4df
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentProcessorScriptConfiguration.kt
@@ -0,0 +1,42 @@
+/*
+ * 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.functions.resource.resolution
+
+import org.jetbrains.kotlin.script.util.DependsOn
+import org.jetbrains.kotlin.script.util.Repository
+import kotlin.script.experimental.annotations.KotlinScript
+import kotlin.script.experimental.api.ScriptCompilationConfiguration
+import kotlin.script.experimental.api.defaultImports
+import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
+import kotlin.script.experimental.jvm.jvm
+
+@KotlinScript(fileExtension = "resourceassignmentprocessor.kts",
+ compilationConfiguration = ResourceAssignmentProcessorScriptConfiguration::class)
+abstract class ResourceAssignmentProcessorScript {
+
+}
+
+object ResourceAssignmentProcessorScriptConfiguration : ScriptCompilationConfiguration(
+ {
+ defaultImports(DependsOn::class, Repository::class)
+ jvm {
+ dependenciesFromCurrentContext(
+ wholeClasspath = true
+ )
+ }
+ }
+) \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt
new file mode 100644
index 000000000..c4ae13975
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceAssignmentRuntimeService.kt
@@ -0,0 +1,88 @@
+package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
+
+class ResourceAssignmentRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext)
+ : DefaultBluePrintRuntimeService(id, bluePrintContext) {
+
+ private lateinit var resolutionId: String
+ private var resourceStore: MutableMap<String, JsonNode> = hashMapOf()
+
+ fun createUniqueId(key: String) {
+ resolutionId = "$id-$key"
+ }
+
+ fun cleanResourceStore() {
+ resourceStore.clear()
+ }
+
+ fun putResolutionStore(key: String, value: JsonNode) {
+ resourceStore[key] = value
+ }
+
+ fun getResolutionStore(key: String): JsonNode {
+ return resourceStore[key]
+ ?: throw BluePrintProcessorException("failed to get execution property ($key)")
+ }
+
+ fun checkResolutionStore(key: String): Boolean {
+ return resourceStore.containsKey(key)
+ }
+
+ fun getJsonNodeFromResolutionStore(key: String): JsonNode {
+ return getResolutionStore(key)
+ }
+
+ fun getStringFromResolutionStore(key: String): String? {
+ return getResolutionStore(key).asText()
+ }
+
+ fun getBooleanFromResolutionStore(key: String): Boolean? {
+ return getResolutionStore(key).asBoolean()
+ }
+
+ fun getIntFromResolutionStore(key: String): Int? {
+ return getResolutionStore(key).asInt()
+ }
+
+ fun getDoubleFromResolutionStore(key: String): Double? {
+ return getResolutionStore(key).asDouble()
+ }
+
+ fun putDictionaryStore(key: String, value: JsonNode) {
+ resourceStore["dictionary-$key"] = value
+ }
+
+ fun getDictionaryStore(key: String): JsonNode {
+ return resourceStore["dictionary-$key"]
+ ?: throw BluePrintProcessorException("failed to get execution property (dictionary-$key)")
+ }
+
+ fun checkDictionaryStore(key: String): Boolean {
+ return resourceStore.containsKey("dictionary-$key")
+ }
+
+ fun getJsonNodeFromDictionaryStore(key: String): JsonNode {
+ return getResolutionStore("dictionary-$key")
+ }
+
+ fun getStringFromDictionaryStore(key: String): String? {
+ return getResolutionStore("dictionary-$key").asText()
+ }
+
+ fun getBooleanFromDictionaryStore(key: String): Boolean? {
+ return getResolutionStore("dictionary-$key").asBoolean()
+ }
+
+ fun getIntFromDictionaryStore(key: String): Int? {
+ return getResolutionStore("dictionary-$key").asInt()
+ }
+
+ fun getDoubleFromDictionaryStore(key: String): Double? {
+ return getResolutionStore("dictionary-$key").asDouble()
+ }
+
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
new file mode 100644
index 000000000..98d8c65db
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
@@ -0,0 +1,62 @@
+/*
+ * 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.functions.resource.resolution
+
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Component
+
+@Component("component-resource-resolution")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) :
+ AbstractComponentFunction() {
+
+ override fun process(executionRequest: ExecutionServiceInput) {
+
+ val properties: MutableMap<String, Any> = mutableMapOf()
+
+ try {
+ val key = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY)
+ val storeResult = getOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY] = key.asText()
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult.asBoolean()
+ } catch (e: BluePrintProcessorException) {
+ // NoOp - these property aren't mandatory, so don't fail the process if not provided.
+ }
+
+ val artifactPrefixNamesNode = getOperationInput(ResourceResolutionConstants.INPUT_ARTIFACT_PREFIX_NAMES)
+ val artifactPrefixNames = JacksonUtils.getListFromJsonNode(artifactPrefixNamesNode, String::class.java)
+
+ val resolvedParamContents = resourceResolutionService.resolveResources(bluePrintRuntimeService,
+ nodeTemplateName,
+ artifactPrefixNames,
+ properties)
+
+ // Set Output Attributes
+ bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName,
+ ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, resolvedParamContents.asJsonNode())
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ bluePrintRuntimeService.getBluePrintError().addError(runtimeException.message!!)
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt
new file mode 100644
index 000000000..4c24ac695
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConfiguration.kt
@@ -0,0 +1,26 @@
+/*
+ * 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.functions.resource.resolution
+
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan
+open class ResourceResolutionConfiguration
+
+
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
new file mode 100644
index 000000000..b57b88b7b
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
+ *
+ * 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.functions.resource.resolution
+
+object ResourceResolutionConstants {
+
+ const val SERVICE_RESOURCE_RESOLUTION = "resource-resolution-service"
+ const val PREFIX_RESOURCE_RESOLUTION_PROCESSOR = "rr-processor-"
+ const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
+ const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params"
+ const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json"
+ const val RESOURCE_RESOLUTION_INPUT_KEY = "resolution-key";
+ const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result";
+
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
new file mode 100644
index 000000000..620696f86
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
@@ -0,0 +1,228 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.resource.resolution
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionResultService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintTemplateService
+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.ResourceDefinition
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.BulkResourceSequencingUtils
+import org.slf4j.LoggerFactory
+import org.springframework.context.ApplicationContext
+import org.springframework.stereotype.Service
+import java.io.File
+
+interface ResourceResolutionService {
+
+ fun registeredResourceSources(): List<String>
+
+ fun resolveFromDatabase(bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactTemplate: String,
+ resolutionKey: String): String
+
+ fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+ artifactNames: List<String>, properties: Map<String, Any>): MutableMap<String, String>
+
+ fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+ artifactPrefix: String, properties: Map<String, Any>): String
+
+ fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+ artifactMapping: String, artifactTemplate: String?): String
+
+ fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
+ resourceDictionaries: MutableMap<String, ResourceDefinition>,
+ resourceAssignments: MutableList<ResourceAssignment>,
+ identifierName: String)
+}
+
+@Service(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext,
+ private var resolutionResultService: ResourceResolutionResultService) :
+ ResourceResolutionService {
+
+ private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java)
+
+ override fun registeredResourceSources(): List<String> {
+ return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java)
+ .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) }
+ .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) }
+ }
+
+ override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+ artifactNames: List<String>,
+ properties: Map<String, Any>): MutableMap<String, String> {
+
+ val resolvedParams: MutableMap<String, String> = hashMapOf()
+ artifactNames.forEach { artifactName ->
+ val resolvedContent = resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactName, properties)
+ resolvedParams[artifactName] = resolvedContent
+ }
+ return resolvedParams
+ }
+
+ override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+ artifactPrefix: String, properties: Map<String, Any>): String {
+
+ // Velocity Artifact Definition Name
+ val artifactTemplate = "$artifactPrefix-template"
+ // Resource Assignment Artifact Definition Name
+ val artifactMapping = "$artifactPrefix-mapping"
+
+ val result = resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactMapping, artifactTemplate)
+
+ if (properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)
+ && properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean) {
+ resolutionResultService.write(properties, result, bluePrintRuntimeService, artifactPrefix)
+ }
+
+ return result
+ }
+
+ override fun resolveFromDatabase(bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactTemplate: String,
+ resolutionKey: String): String {
+ return resolutionResultService.read(bluePrintRuntimeService, artifactTemplate, resolutionKey)
+ }
+
+ override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
+ artifactMapping: String, artifactTemplate: String?): String {
+
+ var resolvedContent = ""
+ log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)")
+
+ val identifierName = artifactTemplate ?: "no-template"
+
+ val resourceAssignmentContent =
+ bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping)
+
+ val resourceAssignments: MutableList<ResourceAssignment> =
+ JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java)
+ as? MutableList<ResourceAssignment>
+ ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")
+
+ // Get the Resource Dictionary Name
+ val dictionaryFile = bluePrintRuntimeService.bluePrintContext().rootPath.plus(File.separator)
+ .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator)
+ .plus(ResourceResolutionConstants.FILE_NAME_RESOURCE_DEFINITION_TYPES)
+
+ val resourceDictionaries: MutableMap<String, ResourceDefinition> =
+ JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java)
+ ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")
+
+ // Resolve resources
+ resolveResourceAssignments(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, identifierName)
+
+ val resolvedParamJsonContent =
+ ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
+
+ // Check Template is there
+ if (artifactTemplate != null) {
+ val templateContent =
+ bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate)
+ resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent)
+ } else {
+ resolvedContent = resolvedParamJsonContent
+ }
+
+ return resolvedContent
+ }
+
+ /**
+ * Iterate the Batch, get the Resource Assignment, dictionary Name, Look for the Resource definition for the
+ * name, then get the type of the Resource Definition, Get the instance for the Resource Type and process the
+ * request.
+ */
+ override fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
+ resourceDictionaries: MutableMap<String, ResourceDefinition>,
+ resourceAssignments: MutableList<ResourceAssignment>,
+ identifierName: String) {
+
+ val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments)
+ val resourceAssignmentRuntimeService =
+ ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName)
+
+ bulkSequenced.map { batchResourceAssignments ->
+ batchResourceAssignments.filter { it.name != "*" && it.name != "start" }
+ .forEach { resourceAssignment ->
+ val dictionaryName = resourceAssignment.dictionaryName
+ val dictionarySource = resourceAssignment.dictionarySource
+ /**
+ * Get the Processor name
+ */
+ val processorName = processorName(dictionaryName!!, dictionarySource!!, resourceDictionaries)
+
+ val resourceAssignmentProcessor =
+ applicationContext.getBean(processorName) as? ResourceAssignmentProcessor
+ ?: throw BluePrintProcessorException("failed to get resource processor for name($processorName) " +
+ "for resource assignment(${resourceAssignment.name})")
+ try {
+ // Set BluePrint Runtime Service
+ resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
+ // Set Resource Dictionaries
+ resourceAssignmentProcessor.resourceDictionaries = resourceDictionaries
+ // Invoke Apply Method
+ resourceAssignmentProcessor.apply(resourceAssignment)
+
+ // Set errors from RA
+ blueprintRuntimeService.setBluePrintError(resourceAssignmentRuntimeService.getBluePrintError())
+ } catch (e: RuntimeException) {
+ throw BluePrintProcessorException(e)
+ }
+ }
+ }
+ }
+
+
+ /**
+ * If the Source instance is "input", then it is not mandatory to have source Resource Definition, So it can
+ * derive the default input processor.
+ */
+ private fun processorName(dictionaryName: String, dictionarySource: String,
+ resourceDictionaries: MutableMap<String, ResourceDefinition>): String {
+ var processorName: String? = null
+ when (dictionarySource) {
+ "input" -> {
+ processorName = "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input"
+ }
+ "default" -> {
+ processorName = "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default"
+ }
+ else -> {
+ val resourceDefinition = resourceDictionaries[dictionaryName]
+ ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName")
+
+ val resourceSource = resourceDefinition.sources[dictionarySource]
+ ?: throw BluePrintProcessorException("couldn't get resource definition $dictionaryName source($dictionarySource)")
+
+ processorName = ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
+ .plus(resourceSource.type)
+ }
+ }
+ checkNotEmptyOrThrow(processorName,
+ "couldn't get processor name for resource dictionary definition($dictionaryName) source" +
+ "($dictionarySource)")
+
+ return processorName
+
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt
new file mode 100644
index 000000000..25fc8c010
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt
@@ -0,0 +1,79 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.
+ */
+@file:Suppress("unused")
+
+package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
+
+import com.fasterxml.jackson.annotation.JsonProperty
+
+open class ResourceSourceProperties
+
+open class InputResourceSource : ResourceSourceProperties() {
+ lateinit var key: String
+ @get:JsonProperty("key-dependencies")
+ lateinit var keyDependencies: MutableList<String>
+}
+
+open class DefaultResourceSource : ResourceSourceProperties() {
+ lateinit var key: String
+ @get:JsonProperty("key-dependencies")
+ lateinit var keyDependencies: MutableList<String>
+}
+
+open class DatabaseResourceSource : ResourceSourceProperties() {
+ lateinit var type: String
+ @get:JsonProperty("endpoint-selector")
+ var endpointSelector: String? = null
+ lateinit var query: String
+ @get:JsonProperty("input-key-mapping")
+ var inputKeyMapping: MutableMap<String, String>? = null
+ @get:JsonProperty("output-key-mapping")
+ var outputKeyMapping: MutableMap<String, String>? = null
+ @get:JsonProperty("key-dependencies")
+ lateinit var keyDependencies: MutableList<String>
+}
+
+open class RestResourceSource : ResourceSourceProperties() {
+ lateinit var verb: String
+ @get:JsonProperty("payload")
+ var payload: String? = null
+ lateinit var type: String
+ @get:JsonProperty("endpoint-selector")
+ var endpointSelector: String? = null
+ @get:JsonProperty("url-path")
+ lateinit var urlPath: String
+ lateinit var path: String
+ @get:JsonProperty("expression-type")
+ lateinit var expressionType: String
+ @get:JsonProperty("input-key-mapping")
+ var inputKeyMapping: MutableMap<String, String>? = null
+ @get:JsonProperty("output-key-mapping")
+ var outputKeyMapping: MutableMap<String, String>? = null
+ @get:JsonProperty("key-dependencies")
+ lateinit var keyDependencies: MutableList<String>
+}
+
+open class CapabilityResourceSource : ResourceSourceProperties() {
+ @get:JsonProperty("script-type")
+ lateinit var scriptType: String
+ @get:JsonProperty("script-class-reference")
+ lateinit var scriptClassReference: String
+ @get:JsonProperty("instance-dependencies")
+ var instanceDependencies: List<String>? = null
+ @get:JsonProperty("key-dependencies")
+ lateinit var keyDependencies: MutableList<String>
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
new file mode 100644
index 000000000..e50c578d8
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2019 Bell Canada.
+ *
+ * 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.functions.resource.resolution.db
+
+import org.springframework.data.jpa.repository.JpaRepository
+
+interface ResourceResolutionRepository : JpaRepository<ResourceResolutionResult, String> {
+
+ fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(key: String, blueprintName: String?,
+ blueprintVersion: String?,
+ artifactName: String): ResourceResolutionResult
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResult.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResult.kt
new file mode 100755
index 000000000..814fba5ea
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResult.kt
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2019 Bell Canada
+ *
+ * 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.functions.resource.resolution.db
+
+import com.fasterxml.jackson.annotation.JsonFormat
+import org.hibernate.annotations.Proxy
+import org.springframework.data.annotation.LastModifiedDate
+import org.springframework.data.jpa.domain.support.AuditingEntityListener
+import java.io.Serializable
+import java.util.*
+import javax.persistence.Column
+import javax.persistence.Entity
+import javax.persistence.EntityListeners
+import javax.persistence.Id
+import javax.persistence.Lob
+import javax.persistence.Table
+import javax.persistence.Temporal
+import javax.persistence.TemporalType
+
+@EntityListeners(AuditingEntityListener::class)
+@Entity
+@Table(name = "RESOURCE_RESOLUTION_RESULT")
+@Proxy(lazy = false)
+class ResourceResolutionResult : Serializable {
+
+ @Id
+ @Column(name = "resource_resolution_result_id")
+ var id: String? = null
+
+ @Column(name = "resolution_key", nullable = false)
+ var resolutionKey: String? = null
+
+ @Column(name = "blueprint_name", nullable = false)
+ var blueprintName: String? = null
+
+ @Column(name = "blueprint_version", nullable = false)
+ var blueprintVersion: String? = null
+
+ @Column(name = "artifact_name", nullable = false)
+ var artifactName: String? = null
+
+ @Lob
+ @Column(name = "result", nullable = false)
+ var result: String? = null
+
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ @Column(name = "creation_date")
+ var createdDate = Date()
+
+ companion object {
+ private const val serialVersionUID = 1L
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt
new file mode 100644
index 000000000..448782a80
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionResultService.kt
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2019 Bell Canada.
+ *
+ * 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.functions.resource.resolution.db
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
+import org.springframework.dao.DataIntegrityViolationException
+import org.springframework.stereotype.Service
+import java.util.*
+
+@Service
+class ResourceResolutionResultService(private val resourceResolutionRepository: ResourceResolutionRepository) {
+
+ fun write(properties: Map<String, Any>, result: String, bluePrintRuntimeService: BluePrintRuntimeService<*>,
+ artifactPrefix: String) {
+
+ val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
+
+ val resourceResolutionResult = ResourceResolutionResult()
+ resourceResolutionResult.id = UUID.randomUUID().toString()
+ resourceResolutionResult.artifactName = artifactPrefix
+ resourceResolutionResult.blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
+ resourceResolutionResult.blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
+ resourceResolutionResult.resolutionKey =
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY].toString()
+ resourceResolutionResult.result = result
+
+ try {
+ resourceResolutionRepository.saveAndFlush(resourceResolutionResult)
+ } catch (ex: DataIntegrityViolationException) {
+ throw BluePrintException("Failed to store resource resolution result.", ex)
+ }
+ }
+
+ fun read(bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactPrefix: String,
+ resolutionKey: String): String {
+
+ val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
+
+ val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
+ val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
+
+ return resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+ resolutionKey,
+ blueprintName,
+ blueprintVersion,
+ artifactPrefix).result!!
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
new file mode 100644
index 000000000..6469e78da
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Modifications Copyright © 2019 IBM, Bell Canada.
+ *
+ * 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.functions.resource.resolution.processor
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.ApplicationContext
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Service
+
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class CapabilityResourceResolutionProcessor(private val applicationContext: ApplicationContext,
+ private var componentFunctionScriptingService: ComponentFunctionScriptingService)
+ : ResourceAssignmentProcessor() {
+
+ private val log = LoggerFactory.getLogger(CapabilityResourceResolutionProcessor::class.java)
+
+ var componentResourceAssignmentProcessor: ResourceAssignmentProcessor? = null
+
+ override fun getName(): String {
+ return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability"
+ }
+
+ override fun process(resourceAssignment: ResourceAssignment) {
+
+ val resourceDefinition = resourceDictionaries[resourceAssignment.dictionaryName]
+ ?: throw BluePrintProcessorException("couldn't get resource definition for ${resourceAssignment.dictionaryName}")
+
+ val resourceSource = resourceDefinition.sources[resourceAssignment.dictionarySource]
+ ?: throw BluePrintProcessorException("couldn't get resource definition " +
+ "${resourceAssignment.dictionaryName} source(${resourceAssignment.dictionarySource})")
+
+ val resourceSourceProps = checkNotNull(resourceSource.properties) { "failed to get $resourceSource properties" }
+ /**
+ * Get the Capability Resource Source Info from Property Definitions.
+ */
+ val capabilityResourceSourceProperty = JacksonUtils
+ .getInstanceFromMap(resourceSourceProps, CapabilityResourceSource::class.java)
+
+ val scriptType = capabilityResourceSourceProperty.scriptType
+ val scriptClassReference = capabilityResourceSourceProperty.scriptClassReference
+ val instanceDependencies = capabilityResourceSourceProperty.instanceDependencies ?: listOf()
+
+ componentResourceAssignmentProcessor = scriptInstance(scriptType, scriptClassReference, instanceDependencies)
+
+ checkNotNull(componentResourceAssignmentProcessor) {
+ "failed to get capability resource assignment processor($scriptClassReference)"
+ }
+
+ // Assign Current Blueprint runtime and ResourceDictionaries
+ componentResourceAssignmentProcessor!!.raRuntimeService = raRuntimeService
+ componentResourceAssignmentProcessor!!.resourceDictionaries = resourceDictionaries
+
+ // Invoke componentResourceAssignmentProcessor
+ componentResourceAssignmentProcessor!!.apply(resourceAssignment)
+ }
+
+ override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ log.info("Recovering for : ${resourceAssignment.name} : ${runtimeException.toString()}")
+ if (componentResourceAssignmentProcessor != null) {
+ componentResourceAssignmentProcessor!!.recover(runtimeException, resourceAssignment)
+ }
+ }
+
+ fun scriptInstance(scriptType: String, scriptClassReference: String, instanceDependencies: List<String>)
+ : ResourceAssignmentProcessor {
+
+ log.info("creating resource resolution of script type($scriptType), reference name($scriptClassReference) and" +
+ "instanceDependencies($instanceDependencies)")
+
+ val scriptComponent = componentFunctionScriptingService
+ .scriptInstance<ResourceAssignmentProcessor>(raRuntimeService.bluePrintContext(), scriptType,
+ scriptClassReference)
+
+ instanceDependencies.forEach { instanceDependency ->
+ scriptPropertyInstances[instanceDependency] = applicationContext
+ .getBean(instanceDependency)
+ }
+ return scriptComponent
+ }
+} \ No newline at end of file
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
new file mode 100644
index 000000000..a192989e5
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
@@ -0,0 +1,190 @@
+/*
+ * Copyright © 2018 IBM.
+ * Modifications Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.resource.resolution.processor
+
+import com.fasterxml.jackson.databind.node.JsonNodeFactory
+import com.fasterxml.jackson.databind.node.MissingNode
+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.*
+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.stereotype.Service
+import java.util.*
+
+/**
+ * DatabaseResourceAssignmentProcessor
+ *
+ * @author Kapil Singal
+ */
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-processor-db")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+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-processor-db"
+ }
+
+ override fun process(resourceAssignment: ResourceAssignment) {
+ try {
+ validate(resourceAssignment)
+
+ // Check if It has Input
+ 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 {
+ setValueFromDB(resourceAssignment)
+ }
+ } catch (e: BluePrintProcessorException) {
+ setValueFromDB(resourceAssignment)
+ }
+
+ // Check the value has populated for mandatory case
+ ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+ } catch (e: Exception) {
+ ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
+ throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e)
+ }
+ }
+
+ 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!!)
+ bluePrintDBLibPropertySevice.JdbcTemplate(dbPropertiesJson)
+ } else {
+ primaryDBLibGenericService
+ }
+
+ }
+
+ @Throws(BluePrintProcessorException::class)
+ 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_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)
+ private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: DatabaseResourceSource, rows: List<Map<String, Any>>) {
+ val dName = resourceAssignment.dictionaryName
+ val dSource = resourceAssignment.dictionarySource
+ val type = nullToEmpty(resourceAssignment.property?.type)
+
+ val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" }
+ logger.info("Response processing type($type)")
+
+ // Primitive Types
+ when (type) {
+ in BluePrintTypes.validPrimitiveTypes() -> {
+ val dbColumnValue = rows[0][outputKeyMapping[dName]]
+ logger.info("For template key (${resourceAssignment.name}) setting value as ($dbColumnValue)")
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, dbColumnValue)
+ }
+ in BluePrintTypes.validCollectionTypes() -> {
+ val entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
+ val arrayNode = JsonNodeFactory.instance.arrayNode()
+ rows.forEach {
+ if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) {
+ val dbColumnValue = it[outputKeyMapping[dName]]
+ // Add Array JSON
+ JacksonUtils.populatePrimitiveValues(dbColumnValue!!, entrySchemaType, arrayNode)
+ } else {
+ val arrayChildNode = JsonNodeFactory.instance.objectNode()
+ for (mapping in outputKeyMapping.entries) {
+ val dbColumnValue = checkNotNull(it[mapping.key])
+ val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, mapping.key)
+ JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, arrayChildNode)
+ }
+ arrayNode.add(arrayChildNode)
+ }
+ }
+ logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)")
+ // Set the List of Complex Values
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode)
+ }
+ else -> {
+ // Complex Types
+ val row = rows[0]
+ val objectNode = JsonNodeFactory.instance.objectNode()
+ for (mapping in outputKeyMapping.entries) {
+ val dbColumnValue = checkNotNull(row[mapping.key])
+ val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key)
+ JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, objectNode)
+ }
+ logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)")
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode)
+ }
+ }
+ }
+
+ override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ raRuntimeService.getBluePrintError().addError(runtimeException.message!!)
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt
new file mode 100644
index 000000000..0f51e4bff
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt
@@ -0,0 +1,65 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.resource.resolution.processor
+
+import com.fasterxml.jackson.databind.node.MissingNode
+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.resource.dict.ResourceAssignment
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Service
+
+/**
+ * DefaultResourceResolutionProcessor
+ *
+ * @author Kapil Singal
+ */
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() {
+
+ private val logger = LoggerFactory.getLogger(DefaultResourceResolutionProcessor::class.java)
+
+ override fun getName(): String {
+ return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default"
+ }
+
+ override fun process(resourceAssignment: ResourceAssignment) {
+ try {
+ var value = getFromInput(resourceAssignment)
+ if (value == null || value is MissingNode) {
+ value = resourceAssignment.property?.defaultValue
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
+ }
+ // Check the value has populated for mandatory case
+ ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+ } catch (e: Exception) {
+ ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
+ throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}",
+ e)
+ }
+
+ }
+
+ override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ raRuntimeService.getBluePrintError().addError(runtimeException.message!!)
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
new file mode 100644
index 000000000..579989a61
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
@@ -0,0 +1,68 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.resource.resolution.processor
+
+import com.fasterxml.jackson.databind.node.MissingNode
+import com.fasterxml.jackson.databind.node.NullNode
+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.checkNotEmpty
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Service
+
+/**
+ * InputResourceResolutionProcessor
+ *
+ * @author Kapil Singal
+ */
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() {
+
+ private val logger = LoggerFactory.getLogger(InputResourceResolutionProcessor::class.java)
+
+ override fun getName(): String {
+ return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input"
+ }
+
+ override fun process(resourceAssignment: ResourceAssignment) {
+ try {
+ if (checkNotEmpty(resourceAssignment.name)) {
+ val value = raRuntimeService.getInputValue(resourceAssignment.name)
+ // if value is null don't call setResourceDataValue to populate the value
+ if (value !is MissingNode && value !is NullNode) {
+ logger.info("input source template key (${resourceAssignment.name}) found from input and value is ($value)")
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
+ }
+ }
+ // Check the value has populated for mandatory case
+ ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+ } catch (e: Exception) {
+ ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
+ throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with : (${e.message})", e)
+ }
+ }
+
+ override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ raRuntimeService.getBluePrintError().addError(runtimeException.message!!)
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
new file mode 100644
index 000000000..3f0c1b4ff
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
@@ -0,0 +1,115 @@
+/*
+ * Copyright © 2018 IBM.
+ * Modifications Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.resource.resolution.processor
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.apache.commons.collections.MapUtils
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
+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.interfaces.BlueprintFunctionNode
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintTemplateService
+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.ResourceDefinition
+import org.slf4j.LoggerFactory
+import java.util.*
+
+abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssignment, Boolean> {
+
+ private val log = LoggerFactory.getLogger(ResourceAssignmentProcessor::class.java)
+
+ lateinit var raRuntimeService: ResourceAssignmentRuntimeService
+ lateinit var resourceDictionaries: MutableMap<String, ResourceDefinition>
+
+ var scriptPropertyInstances: MutableMap<String, Any> = hashMapOf()
+
+ /**
+ * This will be called from the scripts to serve instance from runtime to scripts.
+ */
+ open fun <T> scriptPropertyInstanceType(name: String): T {
+ return scriptPropertyInstances as? T
+ ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")
+ }
+
+ open fun getFromInput(resourceAssignment: ResourceAssignment): JsonNode? {
+ var value: JsonNode? = null
+ try {
+ value = raRuntimeService.getInputValue(resourceAssignment.name)
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
+ } catch (e: BluePrintProcessorException) {
+ // NoOp - couldn't find value from input
+ }
+ return value
+ }
+
+ open fun resourceDefinition(name: String): ResourceDefinition {
+ return resourceDictionaries[name]
+ ?: throw BluePrintProcessorException("couldn't get resource definition for ($name)")
+ }
+
+ open fun resolveInputKeyMappingVariables(inputKeyMapping: Map<String, String>): Map<String, Any> {
+ val resolvedInputKeyMapping = HashMap<String, Any>()
+ if (MapUtils.isNotEmpty(inputKeyMapping)) {
+ for ((key, value) in inputKeyMapping) {
+ val resultValue = raRuntimeService.getResolutionStore(value)
+ val expressionValue = JacksonUtils.getValue(resultValue)
+ log.trace("Reference dictionary key ({}), value ({})", key, expressionValue)
+ resolvedInputKeyMapping[key] = expressionValue
+ }
+ }
+ return resolvedInputKeyMapping
+ }
+
+ open fun resolveFromInputKeyMapping(valueToResolve: String, keyMapping: Map<String, Any>): String {
+ if (valueToResolve.isEmpty() || !valueToResolve.contains("$")) {
+ return valueToResolve
+ }
+ return BluePrintTemplateService.generateContent(valueToResolve, additionalContext = keyMapping)
+ }
+
+ override fun prepareRequest(resourceAssignment: ResourceAssignment): ResourceAssignment {
+ log.info("prepareRequest for ${resourceAssignment.name}, dictionary(${resourceAssignment.dictionaryName})," +
+ "source(${resourceAssignment.dictionarySource})")
+ return resourceAssignment
+ }
+
+ override fun prepareResponse(): Boolean {
+ log.info("Preparing Response...")
+ return true
+ }
+
+ override fun apply(resourceAssignment: ResourceAssignment): Boolean {
+ try {
+ prepareRequest(resourceAssignment)
+ process(resourceAssignment)
+ } catch (runtimeException: RuntimeException) {
+ recover(runtimeException, resourceAssignment)
+ }
+ return prepareResponse()
+ }
+
+ fun addError(type: String, name: String, error: String) {
+ raRuntimeService.getBluePrintError().addError(type, name, error)
+ }
+
+ fun addError(error: String) {
+ raRuntimeService.getBluePrintError().addError(error)
+ }
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
new file mode 100644
index 000000000..091220b5e
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
@@ -0,0 +1,204 @@
+/*
+ * Copyright © 2018 IBM.
+ * Modifications Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.resource.resolution.processor
+
+import com.fasterxml.jackson.databind.node.ArrayNode
+import com.fasterxml.jackson.databind.node.JsonNodeFactory
+import com.fasterxml.jackson.databind.node.MissingNode
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.RestResourceSource
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BlueprintWebClientService
+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.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.stereotype.Service
+
+/**
+ * RestResourceResolutionProcessor
+ *
+ * @author Kapil Singal
+ */
+@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-rest")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService)
+ : ResourceAssignmentProcessor() {
+
+ private val logger = LoggerFactory.getLogger(RestResourceResolutionProcessor::class.java)
+
+ override fun getName(): String {
+ return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-rest"
+ }
+
+ override fun process(resourceAssignment: ResourceAssignment) {
+ try {
+ 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, RestResourceSource::class.java)
+ val path = nullToEmpty(sourceProperties.path)
+ val inputKeyMapping =
+ checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
+ val resolvedInputKeyMapping = resolveInputKeyMappingVariables(inputKeyMapping)
+
+ // Resolving content Variables
+ val payload = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.payload), resolvedInputKeyMapping)
+ val urlPath =
+ resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
+ val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping)
+
+ logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
+ // Get the Rest Client Service
+ val restClientService = blueprintWebClientService(resourceAssignment, sourceProperties)
+
+ val response = restClientService.exchangeResource(verb, urlPath, payload)
+ if (response.isBlank()) {
+ logger.warn("Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath)")
+ } else {
+ populateResource(resourceAssignment, sourceProperties, response, path)
+ }
+ }
+ // Check the value has populated for mandatory case
+ ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+ } catch (e: Exception) {
+ ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
+ throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}",
+ e)
+ }
+ }
+
+ private fun blueprintWebClientService(resourceAssignment: ResourceAssignment,
+ restResourceSource: RestResourceSource): BlueprintWebClientService {
+ return if (checkNotEmpty(restResourceSource.endpointSelector)) {
+ val restPropertiesJson = raRuntimeService.resolveDSLExpression(restResourceSource.endpointSelector!!)
+ blueprintRestLibPropertyService.blueprintWebClientService(restPropertiesJson)
+ } else {
+ blueprintRestLibPropertyService.blueprintWebClientService(resourceAssignment.dictionarySource!!)
+ }
+ }
+
+ @Throws(BluePrintProcessorException::class)
+ private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource,
+ restResponse: String, path: String) {
+ val dName = resourceAssignment.dictionaryName
+ val dSource = resourceAssignment.dictionarySource
+ val type = nullToEmpty(resourceAssignment.property?.type)
+ lateinit var entrySchemaType: String
+
+ val outputKeyMapping =
+ checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" }
+ logger.info("Response processing type($type)")
+
+ val responseNode =
+ checkNotNull(JacksonUtils.jsonNode(restResponse).at(path)) { "Failed to find path ($path) in response ($restResponse)" }
+ logger.info("populating value for output mapping ($outputKeyMapping), from json ($responseNode)")
+
+
+ when (type) {
+ in BluePrintTypes.validPrimitiveTypes() -> {
+ logger.info("For template key (${resourceAssignment.name}) setting value as ($responseNode)")
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, responseNode)
+ }
+ in BluePrintTypes.validCollectionTypes() -> {
+ // Array Types
+ entrySchemaType =
+ returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
+ val arrayNode = responseNode as ArrayNode
+
+ if (entrySchemaType !in BluePrintTypes.validPrimitiveTypes()) {
+ val responseArrayNode = responseNode.toList()
+ for (responseSingleJsonNode in responseArrayNode) {
+ val arrayChildNode = JsonNodeFactory.instance.objectNode()
+ outputKeyMapping.map {
+ val responseKeyValue = responseSingleJsonNode.get(it.key)
+ val propertyTypeForDataType =
+ ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key)
+ logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})")
+ JacksonUtils.populateJsonNodeValues(it.value,
+ responseKeyValue,
+ propertyTypeForDataType,
+ arrayChildNode)
+ }
+ arrayNode.add(arrayChildNode)
+ }
+ }
+ logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)")
+ // Set the List of Complex Values
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode)
+ }
+ else -> {
+ // Complex Types
+ entrySchemaType =
+ returnNotEmptyOrThrow(resourceAssignment.property?.type) { "Entry schema is not defined for dictionary ($dName) info" }
+ val objectNode = JsonNodeFactory.instance.objectNode()
+ outputKeyMapping.map {
+ val responseKeyValue = responseNode.get(it.key)
+ val propertyTypeForDataType =
+ ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key)
+ logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})")
+ JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode)
+ }
+
+ logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)")
+ // Set the List of Complex Values
+ ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode)
+ }
+ }
+ }
+
+ @Throws(BluePrintProcessorException::class)
+ 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_CONFIG_DATA,
+ resourceAssignment.dictionarySource) {
+ "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA} but it is ${resourceAssignment.dictionarySource}"
+ }
+ checkNotEmptyOrThrow(resourceAssignment.dictionaryName,
+ "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
+ }
+
+ override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+ raRuntimeService.getBluePrintError().addError(runtimeException.message!!)
+ }
+
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
new file mode 100644
index 000000000..d55ccacb2
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
@@ -0,0 +1,159 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
+ *
+ * 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.functions.resource.resolution.utils
+
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.databind.node.NullNode
+import com.fasterxml.jackson.databind.node.ObjectNode
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
+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.service.BluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import java.util.*
+
+class ResourceAssignmentUtils {
+ companion object {
+
+ private val logger: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentUtils::class.toString())
+
+ // TODO("Modify Value type from Any to JsonNode")
+ @Throws(BluePrintProcessorException::class)
+ fun setResourceDataValue(resourceAssignment: ResourceAssignment,
+ raRuntimeService: ResourceAssignmentRuntimeService, value: Any?) {
+
+ val resourceProp = checkNotNull(resourceAssignment.property) { "Failed in setting resource value for resource mapping $resourceAssignment" }
+ checkNotEmptyOrThrow(resourceAssignment.name, "Failed in setting resource value for resource mapping $resourceAssignment")
+
+ if (resourceAssignment.dictionaryName.isNullOrEmpty()) {
+ resourceAssignment.dictionaryName = resourceAssignment.name
+ logger.warn("Missing dictionary key, setting with template key (${resourceAssignment.name}) as dictionary key (${resourceAssignment.dictionaryName})")
+ }
+
+ try {
+ if (resourceProp.type.isNotEmpty()) {
+ val convertedValue = convertResourceValue(resourceProp.type, value)
+ logger.info("Setting Resource Value ($convertedValue) for Resource Name (${resourceAssignment.dictionaryName}) of type (${resourceProp.type})")
+ setResourceValue(resourceAssignment, raRuntimeService, convertedValue)
+ resourceAssignment.updatedDate = Date()
+ resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM
+ resourceAssignment.status = BluePrintConstants.STATUS_SUCCESS
+ }
+ } catch (e: Exception) {
+ throw BluePrintProcessorException("Failed in setting value for template key (${resourceAssignment.name}) and " +
+ "dictionary key (${resourceAssignment.dictionaryName}) of type (${resourceProp.type}) with error message (${e.message})", e)
+ }
+ }
+
+ private fun setResourceValue(resourceAssignment: ResourceAssignment, raRuntimeService: ResourceAssignmentRuntimeService, value: JsonNode) {
+ raRuntimeService.putResolutionStore(resourceAssignment.name, value)
+ raRuntimeService.putDictionaryStore(resourceAssignment.dictionaryName!!, value)
+ resourceAssignment.property!!.value = value
+ }
+
+ private fun convertResourceValue(type: String, value: Any?): JsonNode {
+
+ return if (value == null || value is NullNode) {
+ logger.info("Returning {} value from convertResourceValue", value)
+ NullNode.instance
+ } else if (BluePrintTypes.validPrimitiveTypes().contains(type) && value is String) {
+ JacksonUtils.convertPrimitiveResourceValue(type, value)
+ } else if (value is String) {
+ JacksonUtils.jsonNode(value)
+ } else {
+ JacksonUtils.getJsonNode(value)
+ }
+
+ }
+
+ fun setFailedResourceDataValue(resourceAssignment: ResourceAssignment, message: String?) {
+ if (checkNotEmpty(resourceAssignment.name)) {
+ resourceAssignment.updatedDate = Date()
+ resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM
+ resourceAssignment.status = BluePrintConstants.STATUS_FAILURE
+ resourceAssignment.message = message
+ }
+ }
+
+ @Throws(BluePrintProcessorException::class)
+ fun assertTemplateKeyValueNotNull(resourceAssignment: ResourceAssignment) {
+ val resourceProp = checkNotNull(resourceAssignment.property) { "Failed to populate mandatory resource resource mapping $resourceAssignment" }
+ if (resourceProp.required != null && resourceProp.required!! && (resourceProp.value == null || resourceProp.value !is NullNode)) {
+ logger.error("failed to populate mandatory resource mapping ($resourceAssignment)")
+ throw BluePrintProcessorException("failed to populate mandatory resource mapping ($resourceAssignment)")
+ }
+ }
+
+ @Throws(BluePrintProcessorException::class)
+ fun generateResourceDataForAssignments(assignments: List<ResourceAssignment>): String {
+ val result: String
+ try {
+ val mapper = ObjectMapper()
+ val root: ObjectNode = mapper.createObjectNode()
+
+ assignments.forEach {
+ if (checkNotEmpty(it.name) && it.property != null) {
+ val rName = it.name
+ val type = nullToEmpty(it.property?.type).toLowerCase()
+ val value = it.property?.value
+ logger.info("Generating Resource name ($rName), type ($type), value ($value)")
+ root.set(rName, value)
+ }
+ }
+ result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root)
+ logger.info("Generated Resource Param Data ($result)")
+ } catch (e: Exception) {
+ throw BluePrintProcessorException("Resource Assignment is failed with $e.message", e)
+ }
+
+ return result
+ }
+
+ fun transformToRARuntimeService(blueprintRuntimeService: BluePrintRuntimeService<*>, templateArtifactName: String): ResourceAssignmentRuntimeService {
+ val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService(blueprintRuntimeService.id(), blueprintRuntimeService.bluePrintContext())
+ resourceAssignmentRuntimeService.createUniqueId(templateArtifactName)
+ resourceAssignmentRuntimeService.setExecutionContext(blueprintRuntimeService.getExecutionContext() as MutableMap<String, JsonNode>)
+
+ return resourceAssignmentRuntimeService
+ }
+
+ @Throws(BluePrintProcessorException::class)
+ fun getPropertyType(raRuntimeService: ResourceAssignmentRuntimeService, dataTypeName: String, propertyName: String): String {
+ lateinit var type: String
+ try {
+ val dataTypeProps = checkNotNull(raRuntimeService.bluePrintContext().dataTypeByName(dataTypeName)?.properties)
+ val propertyDefinition = checkNotNull(dataTypeProps[propertyName])
+ type = returnNotEmptyOrThrow(propertyDefinition.type) { "Couldn't get data type ($dataTypeName)" }
+ logger.trace("Data type({})'s property ({}) is ({})", dataTypeName, propertyName, type)
+ } catch (e: Exception) {
+ logger.error("couldn't get data type($dataTypeName)'s property ($propertyName), error message $e")
+ throw BluePrintProcessorException("${e.message}", e)
+ }
+ return type
+ }
+ }
+} \ No newline at end of file
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
new file mode 100644
index 000000000..91997e34a
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
@@ -0,0 +1,79 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.resource.resolution
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration
+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.functions.resource.resolution.processor.*
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
+import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
+import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
+ InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
+ DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
+ CapabilityResourceResolutionProcessor::class,
+ BlueprintPropertyConfiguration::class, BluePrintProperties::class,
+ BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
+@TestPropertySource(locations = ["classpath:application-test.properties"])
+@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
+@EnableAutoConfiguration
+class ResourceResolutionComponentTest {
+
+ @Autowired
+ lateinit var resourceResolutionComponent: ResourceResolutionComponent
+
+ @Test
+ fun testProcess() {
+
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+
+ val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java)!!
+
+ // Prepare Inputs
+ PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
+
+ val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
+ bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
+
+ resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService
+ resourceResolutionComponent.stepName = "resource-assignment"
+ resourceResolutionComponent.apply(executionServiceInput)
+ }
+} \ No newline at end of file
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
new file mode 100644
index 000000000..d560e8c35
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
@@ -0,0 +1,91 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.resource.resolution
+
+import org.junit.Assert
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
+import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration
+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.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
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
+
+/**
+ * ResourceResolutionServiceTest
+ *
+ * @author Brinda Santh DATE : 8/15/2018
+ */
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
+ InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
+ DatabaseResourceAssignmentProcessor::class, RestResourceResolutionProcessor::class,
+ CapabilityResourceResolutionProcessor::class,
+ BlueprintPropertyConfiguration::class, BluePrintProperties::class,
+ BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
+@TestPropertySource(locations = ["classpath:application-test.properties"])
+@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
+@EnableAutoConfiguration
+class ResourceResolutionServiceTest {
+
+ private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java)
+
+ @Autowired
+ lateinit var resourceResolutionService: ResourceResolutionService
+
+ @Test
+ fun testRegisteredSource() {
+ val sources = resourceResolutionService.registeredResourceSources()
+ assertNotNull(sources, "failed to get registered sources")
+ assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-processor-db",
+ "source-rest")), "failed to get registered sources : $sources")
+ }
+
+ @Test
+ @Throws(Exception::class)
+ fun testResolveResource() {
+
+ Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
+
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+
+ val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java)!!
+
+ // Prepare Inputs
+ PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment")
+
+ resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", "baseconfig", mapOf())
+
+ }
+
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
new file mode 100644
index 000000000..5a14a2964
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Modifications Copyright © 2019 IBM, Bell Canada.
+ *
+ * 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.functions.resource.resolution.processor
+
+import org.junit.Ignore
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty
+import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+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.ResourceDefinition
+import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertNotNull
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [CapabilityResourceResolutionProcessor::class, ComponentFunctionScriptingService::class,
+ BluePrintScriptsServiceImpl::class,
+ BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class])
+@TestPropertySource(properties =
+["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints",
+ "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"])
+class CapabilityResourceResolutionProcessorTest {
+
+ @Autowired
+ lateinit var capabilityResourceResolutionProcessor: CapabilityResourceResolutionProcessor
+
+ @Ignore
+ @Test
+ fun `test kotlin capability`() {
+
+ val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+
+ val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
+
+ capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
+ capabilityResourceResolutionProcessor.resourceDictionaries = hashMapOf()
+
+
+ val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
+ scriptPropertyInstances["mock-service1"] = MockCapabilityService()
+ scriptPropertyInstances["mock-service2"] = MockCapabilityService()
+
+ val instanceDependencies: List<String> = listOf()
+
+ val resourceAssignmentProcessor = capabilityResourceResolutionProcessor
+ .scriptInstance("kotlin",
+ "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", instanceDependencies)
+
+ assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor")
+
+ val resourceAssignment = ResourceAssignment().apply {
+ name = "ra-name"
+ dictionaryName = "ra-dict-name"
+ dictionarySource = "capability"
+ property = PropertyDefinition().apply {
+ type = "string"
+ }
+ }
+
+ val processorName = resourceAssignmentProcessor.apply(resourceAssignment)
+ assertNotNull(processorName, "couldn't get kotlin script resource assignment processor name")
+ println(processorName)
+ }
+
+ @Test
+ fun `test jython capability`() {
+
+ val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python")
+
+ val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
+
+ capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
+
+ val resourceDefinition = JacksonUtils
+ .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json",
+ ResourceDefinition::class.java)!!
+ val resourceDefinitions: MutableMap<String, ResourceDefinition> = mutableMapOf()
+ resourceDefinitions[resourceDefinition.name] = resourceDefinition
+ capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions
+
+ val resourceAssignment = ResourceAssignment().apply {
+ name = "service-instance-id"
+ dictionaryName = "service-instance-id"
+ dictionarySource = "capability"
+ property = PropertyDefinition().apply {
+ type = "string"
+ }
+ }
+
+ val processorName = capabilityResourceResolutionProcessor.apply(resourceAssignment)
+ assertNotNull(processorName, "couldn't get Jython script resource assignment processor name")
+
+ }
+
+}
+
+open class MockCapabilityService {
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties
new file mode 100644
index 000000000..3f37d1b9e
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties
@@ -0,0 +1,43 @@
+# suppress inspection "UnusedProperty" for whole file
+#
+# Copyright © 2017-2018 AT&T Intellectual Property.
+#
+# Modifications Copyright © 2019 IBM, Bell Canada.
+#
+# 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.
+#
+blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
+blueprintsprocessor.db.primary.username=sa
+blueprintsprocessor.db.primary.password=
+blueprintsprocessor.db.primary.driverClassName=org.h2.Driver
+blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop
+blueprintsprocessor.db.primary.hibernateDDLAuto=update
+blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
+# Controller Blueprints Core Configuration
+blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy
+blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
+
+blueprintsprocessor.restclient.primary-config-data.type=basic-auth
+blueprintsprocessor.restclient.primary-config-data.url=http://127.0.0.1:9111
+blueprintsprocessor.restclient.primary-config-data.userId=sampleuser
+blueprintsprocessor.restclient.primary-config-data.token=sampletoken
+
+# Python executor
+blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
+blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
+
+
+# CBA examples for tests cases
+controllerblueprints.loadBlueprintsExamplesPath=./../../../../components/model-catalog/blueprint-model/test-blueprint
+controllerblueprints.loadBluePrintPaths=./../../../../components/model-catalog/blueprint-model/test-blueprint \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..a816a06c5
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml
@@ -0,0 +1,35 @@
+<!--
+ ~ 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.
+ -->
+
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+
+ <logger name="org.springframework" level="warn"/>
+ <logger name="org.hibernate" level="info"/>
+ <logger name="org.onap.ccsdk.apps.blueprintsprocessor" level="info"/>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+</configuration>
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json
new file mode 100644
index 000000000..b565eec81
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json
@@ -0,0 +1,19 @@
+{
+ "tags": "service-instance-id, tosca.datatypes.Root, data_type",
+ "name": "service-instance-id",
+ "property": {
+ "description": "To be provided",
+ "type": "string"
+ },
+ "updated-by": "Singal, Kapil <ks220y@att.com>",
+ "sources": {
+ "capability": {
+ "type": "source-capability",
+ "properties": {
+ "script-type": "jython",
+ "script-class-reference": "Scripts/python/SampleRAProcessor.py",
+ "instance-dependencies": []
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/dt-location.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/dt-location.json
new file mode 100644
index 000000000..52e0a7967
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/dt-location.json
@@ -0,0 +1,15 @@
+{
+ "version": "1.0.0",
+ "description": "test Data Type",
+ "properties": {
+ "country": {
+ "required": true,
+ "type": "string"
+ },
+ "state": {
+ "required": false,
+ "type": "string"
+ }
+ },
+ "derived_from": "tosca.datatypes.Root"
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-array.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-array.json
new file mode 100644
index 000000000..7082a4341
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-array.json
@@ -0,0 +1,35 @@
+{
+ "locations": {
+ "name": "locations",
+ "data-type": "list",
+ "entry-schema": "dt-location",
+ "source": {
+ "primary-db": {
+ "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
+ "input-key-mapping": {
+ "profile_name": "profile_name"
+ },
+ "output-key-mapping": {
+ "db-country": "country",
+ "db-state": "state"
+ }
+ }
+ },
+ "candidate-dependency": {
+ "primary-db": {
+ "names": [
+ "profile_name"
+ ]
+ }
+ }
+ },
+ "profile_name": {
+ "name": "profile_name",
+ "data-type": "string",
+ "source": {
+ "input": {
+
+ }
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-complex.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-complex.json
new file mode 100644
index 000000000..53e2a11c3
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-complex.json
@@ -0,0 +1,27 @@
+{
+ "location": {
+ "name": "location",
+ "data-type": "dt-location",
+ "source": {
+ "primary-db": {
+ "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
+ "input-key-mapping": {
+ "profile_name": "profile_name"
+ },
+ "output-key-mapping": {
+ "db-country": "country",
+ "db-state": "state"
+ }
+ }
+ }
+ },
+ "profile_name": {
+ "name": "profile_name",
+ "data-type": "string",
+ "source": {
+ "input": {
+
+ }
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-simple.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-simple.json
new file mode 100644
index 000000000..fad088877
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/primary-db-simple.json
@@ -0,0 +1,26 @@
+{
+ "country": {
+ "name": "country",
+ "data-type": "string",
+ "source": {
+ "primary-db": {
+ "query": "SELECT country FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
+ "input-key-mapping": {
+ "profile_name": "profile_name"
+ },
+ "output-key-mapping": {
+ "country": "country"
+ }
+ }
+ }
+ },
+ "profile_name": {
+ "name": "profile_name",
+ "data-type": "string",
+ "source": {
+ "input": {
+
+ }
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/resource-assignments-simple.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/resource-assignments-simple.json
new file mode 100644
index 000000000..bb392d7be
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/primary-db/resource-assignments-simple.json
@@ -0,0 +1,22 @@
+[
+ {
+ "name": "country",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "country",
+ "dictionary-source": "primary-db",
+ "dependencies": ["state"]
+ },
+ {
+ "name": "state",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "state",
+ "dictionary-source": "input",
+ "dependencies": []
+ }
+]
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/inputs/input.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/inputs/input.json
new file mode 100644
index 000000000..cd6fac128
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/inputs/input.json
@@ -0,0 +1,18 @@
+{
+ "api-ver": "2.00",
+ "originator-id": "MSO",
+ "request-id": "123456",
+ "service-instance-id": "ibcx0001vm001",
+ "service-type": "AVPN",
+ "vnf-type": "vUSP - vDBE-IPX HUB",
+ "vnf-id": 123456,
+ "service-template-name": "VRR-baseconfiguration",
+ "service-template-version": "1.0.0",
+ "action-name": "resource-assignment-action",
+ "group-name": "sample group name",
+ "bundle-id": "sample bundle id",
+ "bundle-mac": [
+ "Sample bundle mac",
+ "Sample bundle mac"
+ ]
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json
new file mode 100644
index 000000000..6a7b4c2a2
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/payload/requests/sample-resourceresolution-request.json
@@ -0,0 +1,32 @@
+{
+ "actionIdentifiers": {
+ "actionName": "sample-action",
+ "blueprintName": "sample-blurprint",
+ "blueprintVersion": "1.0.0",
+ "mode": "sync"
+ },
+ "commonHeader": {
+ "flags": {
+ "force": true,
+ "ttl": 3600
+ },
+ "originatorId": "sdnc",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "timestamp": "2012-04-23T18:25:43.511Z"
+ },
+ "payload": {
+ "resource-assignment-request": {
+ "resource-assignment-properties": {
+ "request-id": "1234",
+ "profile_name": "1.0.0",
+ "service-instance-id": "siid_1234",
+ "vnf-id": "vnf_1234",
+ "action-name": "assign-activate",
+ "scope-type": "vnf-type",
+ "hostname": "localhost",
+ "vnf_name": "temp_vnf"
+ }
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/pom.xml b/ms/blueprintsprocessor/functions/restconf-executor/pom.xml
new file mode 100644
index 000000000..1ee23d3d0
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restconf-executor/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2018 IBM.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ 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.
+ -->
+<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.2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+ <artifactId>restconf-executor</artifactId>
+ <name>Blueprints Processor Function - Restconf Executor</name>
+ <description>Blueprints Processor Function - Restconf Executor</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+ <artifactId>resource-resolution</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+
+</project>
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
new file mode 100644
index 000000000..7166ec279
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
@@ -0,0 +1,73 @@
+/*
+ * Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.restconf.executor
+
+import com.fasterxml.jackson.databind.node.ArrayNode
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestLibConstants
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.apps.controllerblueprints.core.getAsString
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
+import org.springframework.stereotype.Component
+
+@Component("component-restconf-executor")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class ComponentRestconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) :
+ AbstractComponentFunction() {
+
+ private val log = LoggerFactory.getLogger(ComponentRestconfExecutor::class.java)
+
+ lateinit var scriptComponent: RestconfComponentFunction
+
+ companion object {
+ const val SCRIPT_TYPE = "script-type"
+ const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
+ const val INSTANCE_DEPENDENCIES = "instance-dependencies"
+ }
+
+ override fun process(executionRequest: ExecutionServiceInput) {
+
+ val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
+ val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
+ val instanceDependenciesNode = operationInputs.get(INSTANCE_DEPENDENCIES) as? ArrayNode
+
+ val scriptDependencies: MutableList<String> = arrayListOf()
+ scriptDependencies.add(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+ scriptDependencies.add(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+
+ instanceDependenciesNode?.forEach { instanceName ->
+ scriptDependencies.add(instanceName.textValue())
+ }
+ /**
+ * Populate the Script Instance based on the Type
+ */
+ scriptComponent = componentFunctionScriptingService.scriptInstance<RestconfComponentFunction>(this, scriptType,
+ scriptClassReference, scriptDependencies)
+
+ checkNotNull(scriptComponent) { "failed to get restconf script component" }
+
+ scriptComponent.process(executionServiceInput)
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ scriptComponent.recover(runtimeException, executionRequest)
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt
new file mode 100644
index 000000000..1914616e8
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.
+ */
+@file:Suppress("unused")
+
+package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestLibConstants
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BlueprintWebClientService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
+
+
+abstract class RestconfComponentFunction : AbstractScriptComponentFunction() {
+
+ open fun bluePrintRestLibPropertyService(): BluePrintRestLibPropertyService =
+ functionDependencyInstanceAsType(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+
+ open fun resourceResolutionService(): ResourceResolutionService =
+ functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+
+
+ fun restClientService(selector: String): BlueprintWebClientService {
+ return bluePrintRestLibPropertyService().blueprintWebClientService(selector)
+ }
+
+ fun resolveFromDatabase(resolutionKey: String, artifactName: String): String {
+ return resourceResolutionService().resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey)
+ }
+
+ fun generateMessage(artifactName: String): String {
+ return bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
+ }
+
+ fun resolveAndGenerateMessage(artifactMapping: String, artifactTemplate: String): String {
+ return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
+ artifactMapping, artifactTemplate)
+ }
+
+ fun resolveAndGenerateMessage(artifactPrefix: String): String {
+ return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
+ artifactPrefix, mapOf())
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfExecutorConfiguration.kt
new file mode 100644
index 000000000..300f5be13
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfExecutorConfiguration.kt
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.restconf.executor
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
+import org.springframework.boot.context.properties.EnableConfigurationProperties
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+
+@Configuration
+@ComponentScan
+@EnableConfigurationProperties
+@ConditionalOnProperty(name = ["blueprintsprocessor.restconfEnabled"], havingValue = "true")
+open class RestconfExecutorConfiguration \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts
new file mode 100644
index 000000000..588f7f108
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts
@@ -0,0 +1,82 @@
+/*
+ * Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.
+ */
+@file:Suppress("unused") //TODO remove this line!
+
+
+import com.fasterxml.jackson.databind.node.ObjectNode
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor.RestconfComponentFunction
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.slf4j.LoggerFactory
+
+open class EditConfigure : RestconfComponentFunction() {
+
+ val log = LoggerFactory.getLogger(EditConfigure::class.java)!!
+
+ override fun getName(): String {
+ return "EditConfigure"
+ }
+
+ override fun process(executionRequest: ExecutionServiceInput) {
+ //val webClientService = restClientService("odlparent")
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+}
+
+open class MountNEditConfigure : RestconfComponentFunction() {
+
+ val log = LoggerFactory.getLogger(MountNEditConfigure::class.java)!!
+
+ override fun getName(): String {
+ return "MountNEditConfigure"
+ }
+
+ override fun process(executionRequest: ExecutionServiceInput) {
+ val webClientService = restClientService("odlparent")
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+}
+
+/**
+ * This is for used for Testing only
+ */
+open class TestRestconfConfigure : RestconfComponentFunction() {
+
+ val log = LoggerFactory.getLogger(TestRestconfConfigure::class.java)!!
+
+ override fun getName(): String {
+ return "TestRestconfConfigure"
+ }
+
+ override fun process(executionRequest: ExecutionServiceInput) {
+ log.info("processing request..")
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ log.info("recovering..")
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt
new file mode 100644
index 000000000..5d903bc72
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt
@@ -0,0 +1,102 @@
+/*
+ * Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.functions.restconf.executor
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.ArrayNode
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.mockk.every
+import io.mockk.mockk
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.test.annotation.DirtiesContext
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertNotNull
+
+@RunWith(SpringRunner::class)
+@EnableAutoConfiguration
+@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
+@DirtiesContext
+@TestPropertySource(properties =
+["server.port=9111",
+ "blueprintsprocessor.restconfEnabled=true",
+ "blueprintsprocessor.restclient.odlPrimary.type=basic-auth",
+ "blueprintsprocessor.restclient.odlPrimary.url=http://127.0.0.1:9111",
+ "blueprintsprocessor.restclient.odlPrimary.userId=sampleuser",
+ "blueprintsprocessor.restclient.odlPrimary.token=sampletoken"],
+ locations = ["classpath:application-test.properties"])
+class ComponentRestconfExecutorTest {
+
+ @Autowired
+ lateinit var componentRestconfExecutor: ComponentRestconfExecutor
+
+ @Test
+ fun `test Restconf Component Instance`() {
+ assertNotNull(componentRestconfExecutor, "failed to get ComponentRestconfExecutor instance")
+ val executionServiceInput = ExecutionServiceInput().apply {
+ commonHeader = CommonHeader().apply {
+ requestId = "1234"
+ }
+ actionIdentifiers = ActionIdentifiers().apply {
+ actionName = "activate"
+ }
+ payload = JacksonUtils.jsonNode("{}") as ObjectNode
+ }
+ val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
+ componentRestconfExecutor.bluePrintRuntimeService = bluePrintRuntime
+ componentRestconfExecutor.stepName = "sample-step"
+
+ val operationInputs = hashMapOf<String, JsonNode>()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-restconf".asJsonPrimitive()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
+ operationInputs[ComponentRestconfExecutor.SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
+ operationInputs[ComponentRestconfExecutor.SCRIPT_CLASS_REFERENCE] =
+ "InternalSimpleRestconf_cba\$TestRestconfConfigure".asJsonPrimitive()
+ operationInputs[ComponentRestconfExecutor.INSTANCE_DEPENDENCIES] = JacksonUtils.jsonNode("[]") as ArrayNode
+
+ val blueprintContext = mockk<BluePrintContext>()
+ every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
+ every { bluePrintRuntime.get("sample-step-step-inputs") } returns operationInputs.asJsonNode()
+ every {
+ bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs("activate-restconf",
+ "interfaceName", "operationName")
+ } returns operationInputs
+
+ val operationOutputs = hashMapOf<String, JsonNode>()
+ every {
+ bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs("activate-restconf",
+ "interfaceName", "operationName")
+ } returns operationOutputs
+ every { bluePrintRuntime.put("sample-step-step-outputs", any()) } returns Unit
+
+ componentRestconfExecutor.apply(executionServiceInput)
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/application-test.properties b/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/application-test.properties
new file mode 100644
index 000000000..6d8b62ff9
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/application-test.properties
@@ -0,0 +1,32 @@
+#
+# Copyright © 2017-2018 AT&T Intellectual Property.
+#
+# Modifications Copyright © 2019 IBM, Bell Canada.
+#
+# 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.
+#
+blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
+blueprintsprocessor.db.primary.username=sa
+blueprintsprocessor.db.primary.password=
+blueprintsprocessor.db.primary.driverClassName=org.h2.Driver
+blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop
+blueprintsprocessor.db.primary.hibernateDDLAuto=update
+blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
+blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
+# Controller Blueprints Core Configuration
+blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy
+blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive
+
+# Python executor
+blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints
+blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..56ea7bb50
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml
@@ -0,0 +1,35 @@
+<!--
+ ~ 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.
+ -->
+
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.springframework.test" level="warn"/>
+ <logger name="org.springframework" level="warn"/>
+ <logger name="org.hibernate" level="info"/>
+ <logger name="org.onap.ccsdk.apps.blueprintsprocessor" level="info"/>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT"/>
+ </root>
+
+</configuration>