aboutsummaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
Diffstat (limited to 'ms')
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/pom.xml14
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt42
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts75
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt50
-rwxr-xr-xms/blueprintsprocessor/parent/pom.xml13
5 files changed, 188 insertions, 6 deletions
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/pom.xml b/ms/blueprintsprocessor/functions/restconf-executor/pom.xml
index 5fdae5e6e..dea3a8af3 100644
--- a/ms/blueprintsprocessor/functions/restconf-executor/pom.xml
+++ b/ms/blueprintsprocessor/functions/restconf-executor/pom.xml
@@ -34,6 +34,20 @@
<groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
<artifactId>python-executor</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
+ <artifactId>blueprint-scripts</artifactId>
+ </dependency>
+
+ <!--Testing dependencies-->
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-test-junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.mockk</groupId>
+ <artifactId>mockk</artifactId>
+ </dependency>
</dependencies>
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
index 67202df49..e91b95ff2 100644
--- 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
@@ -20,6 +20,10 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInp
import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.getAsString
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.ApplicationContext
@@ -30,16 +34,28 @@ import org.springframework.stereotype.Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
open class ComponentRestconfExecutor(private var applicationContext: ApplicationContext,
private val blueprintJythonService: BlueprintJythonService,
- var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService) :
+ private val bluePrintScriptsService: BluePrintScriptsService,
+ private var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService) :
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"
+ }
+
override fun process(executionRequest: ExecutionServiceInput) {
- scriptComponent = blueprintJythonService.jythonComponentInstance(this) as RestconfComponentFunction
- checkNotNull(scriptComponent) { "failed to get netconf script component" }
+
+ val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
+ val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
+ /**
+ * Populate the Script Instance based on the Type
+ */
+ restconfComponentFunction(scriptType, scriptClassReference)
+ checkNotNull(scriptComponent) { "failed to get restconf script component" }
scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService
scriptComponent.processId = processId
@@ -59,4 +75,24 @@ open class ComponentRestconfExecutor(private var applicationContext: Application
override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
scriptComponent.recover(runtimeException, executionRequest)
}
+
+ fun restconfComponentFunction(scriptType: String, scriptClassReference: String): RestconfComponentFunction {
+ log.info("processing restconf script type($scriptType), reference name($scriptClassReference)")
+ when (scriptType) {
+ BluePrintConstants.SCRIPT_INTERNAL -> {
+ scriptComponent = bluePrintScriptsService.scriptInstance<RestconfComponentFunction>(scriptClassReference)
+ }
+ BluePrintConstants.SCRIPT_KOTLIN -> {
+ scriptComponent = bluePrintScriptsService.scriptInstance<RestconfComponentFunction>(bluePrintRuntimeService
+ .bluePrintContext(), scriptClassReference, false)
+ }
+ BluePrintConstants.SCRIPT_JYTHON -> {
+ scriptComponent = blueprintJythonService.jythonComponentInstance(this) as RestconfComponentFunction
+ }
+ else -> {
+ throw BluePrintProcessorException("script type($scriptType) is not supported")
+ }
+ }
+ return scriptComponent
+ }
} \ 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..1c4ba9b66
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/scripts/InternalSimpleRestconf.cba.kts
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor.RestconfComponentFunction
+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..")
+ }
+} \ No newline at end of file
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
index b195fe0fe..77d469165 100644
--- 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
@@ -16,13 +16,26 @@
package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
+import com.fasterxml.jackson.databind.JsonNode
+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.BluePrintProperties
import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration
+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.python.executor.BlueprintJythonService
import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+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.DefaultBluePrintRuntimeService
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+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
@@ -33,7 +46,7 @@ import kotlin.test.assertNotNull
@RunWith(SpringRunner::class)
@ContextConfiguration(classes = [RestconfExecutorConfiguration::class, ComponentRestconfExecutor::class,
BlueprintJythonService::class, PythonExecutorProperty::class, BluePrintRestLibPropertyService::class,
- BlueprintPropertyConfiguration::class,BluePrintProperties::class])
+ BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintScriptsServiceImpl::class])
@TestPropertySource(properties =
["server.port=9111",
"blueprintsprocessor.restconfEnabled=true",
@@ -48,9 +61,40 @@ class ComponentRestconfExecutorTest {
@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()
+ 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/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml
index 5fe7641bb..6b16a7f8c 100755
--- a/ms/blueprintsprocessor/parent/pom.xml
+++ b/ms/blueprintsprocessor/parent/pom.xml
@@ -46,6 +46,7 @@
<h2database.version>1.4.197</h2database.version>
<onap.logger.slf4j>1.2.2</onap.logger.slf4j>
<powermock.version>1.7.4</powermock.version>
+ <mockk.version>1.9</mockk.version>
</properties>
<dependencyManagement>
<dependencies>
@@ -347,6 +348,12 @@
</dependency>
<!-- Test Dependency -->
<dependency>
+ <groupId>io.mockk</groupId>
+ <artifactId>mockk</artifactId>
+ <version>${mockk.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
@@ -359,6 +366,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.jetbrains.kotlinx</groupId>
+ <artifactId>kotlinx-coroutines-test</artifactId>
+ <version>${kotlin.couroutines.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-testing</artifactId>
<version>${grpc.version}</version>