Add Restconf Kotlin script sample 28/83428/2
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Wed, 27 Mar 2019 03:08:06 +0000 (23:08 -0400)
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Wed, 27 Mar 2019 17:25:48 +0000 (13:25 -0400)
Change-Id: Ia6196c7e45b1f3d8a3598f858f0d8380a3463ae9
Issue-ID: CCSDK-1080
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
14 files changed:
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/activation-blueprint.json
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/node_types.json
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/resources_definition_types.json
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/kotlin/DefaultRestconf.cba.kts [new file with mode: 0644]
components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/kotlin/ResourceAssignmentProcessor.cba.kts
ms/blueprintsprocessor/application/src/main/resources/application-dev.properties
ms/blueprintsprocessor/application/src/main/resources/application.properties
ms/blueprintsprocessor/application/src/main/resources/logback.xml
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/InternalRAProcessor.cba.kts [new file with mode: 0644]
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt
ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctionTest.kt [new file with mode: 0644]
ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt

index a8329b8..fdc18c5 100644 (file)
           }
         }
       },
+      "activate-restconf": {
+        "type": "component-restconf-executor",
+        "interfaces": {
+          "ComponentRestconfExecutor": {
+            "operations": {
+              "process": {
+                "implementation": {
+                  "primary": "component-script"
+                },
+                "inputs": {
+                  "script-type": "kotlin",
+                  "script-class-reference": "DefaultRestconf_cba$MountNEditConfigure",
+                  "instance-dependencies": []
+                },
+                "outputs": {
+                  "response-data": "",
+                  "status": "success"
+                }
+              }
+            }
+          }
+        }
+      },
       "sample-netconf-device": {
         "type": "vnf-netconf-device",
         "capabilities": {
           }
         }
       },
+      "activate-restconf": {
+        "steps": {
+          "activate-process": {
+            "description": "Activate Restconf flow",
+            "target": "activate-restconf",
+            "activities": [
+              {
+                "call_operation": "ComponentRestconfExecutor.process"
+              }
+            ]
+          }
+        }
+      },
       "assign-activate": {
         "inputs": {
           "assign-activate-properties": {
index 68a8ae6..c550306 100644 (file)
           "operations": {
             "process": {
               "inputs": {
+                "resolution-key": {
+                  "description": "Key for service instance related correlation.",
+                  "required": false,
+                  "type": "string"
+                },
+                "store-result": {
+                  "description": "Whether or not to store the output.",
+                  "required": false,
+                  "type": "boolean"
+                },
                 "resource-type": {
                   "description": "Request type.",
                   "required": false,
       },
       "derived_from": "tosca.nodes.Component"
     },
+    "component-restconf-executor": {
+      "description": "This is Restconf Transaction Configuration Component API",
+      "version": "1.0.0",
+      "capabilities": {
+        "component-node": {
+          "type": "tosca.capabilities.Node"
+        }
+      },
+      "interfaces": {
+        "ComponentRestconfExecutor": {
+          "operations": {
+            "process": {
+              "inputs": {
+                "script-type": {
+                  "description": "Script type, kotlin type is supported",
+                  "required": true,
+                  "type": "string",
+                  "constraints": [
+                    {
+                      "valid_values": [
+                        "kotlin",
+                        "jython",
+                        "internal"
+                      ]
+                    }
+                  ],
+                  "default": "internal"
+                },
+                "script-class-reference": {
+                  "description": "Kotlin Script class name or jython script name.",
+                  "required": true,
+                  "type": "string"
+                },
+                "instance-dependencies": {
+                  "description": "Instance names to inject to Jython or Kotlin Script.",
+                  "required": true,
+                  "type": "list",
+                  "entry_schema": {
+                    "type": "string"
+                  }
+                },
+                "dynamic-properties": {
+                  "description": "Dynamic Json Content or DSL Json reference.",
+                  "required": false,
+                  "type": "json"
+                }
+              },
+              "outputs": {
+                "response-data": {
+                  "description": "Execution Response Data in JSON format.",
+                  "required": false,
+                  "type": "string"
+                },
+                "status": {
+                  "description": "Status of the Component Execution ( success or failure )",
+                  "required": true,
+                  "type": "string"
+                }
+              }
+            }
+          }
+        }
+      },
+      "derived_from": "tosca.nodes.Component"
+    },
     "dg-generic": {
       "description": "This is Generic Directed Graph Type",
       "version": "1.0.0",
       },
       "derived_from": "tosca.nodes.DG"
     },
+    "source-capability": {
+      "description": "This is Component Resource Source Node Type",
+      "version": "1.0.0",
+      "properties": {
+        "script-type": {
+          "required": true,
+          "type": "string",
+          "constraints": [
+            {
+              "valid_values": [
+                "kotlin",
+                "internal",
+                "jython"
+              ]
+            }
+          ],
+          "default": "kotlin"
+        },
+        "script-class-reference": {
+          "description": "Capability reference name for internal and kotlin, for jython script file path",
+          "required": true,
+          "type": "string"
+        },
+        "instance-dependencies": {
+          "description": "Instance dependency Names to Inject to Kotlin / Jython Script.",
+          "required": false,
+          "type": "list",
+          "entry_schema": {
+            "type": "string"
+          }
+        },
+        "key-dependencies": {
+          "description": "Resource Resolution dependency dictionary names.",
+          "required": true,
+          "type": "list",
+          "entry_schema": {
+            "type": "string"
+          }
+        }
+      },
+      "derived_from": "tosca.nodes.ResourceSource"
+    },
     "source-input": {
       "description": "This is Input Resource Source Node Type",
       "version": "1.0.0",
       },
       "derived_from": "tosca.nodes.ResourceSource"
     },
-    "source-processor-db": {
+    "source-primary-db": {
       "description": "This is Database Resource Source Node Type",
       "version": "1.0.0",
       "properties": {
           ],
           "default": "JSON"
         },
+        "verb": {
+          "required": false,
+          "type": "string",
+          "constraints": [
+            {
+              "valid_values": [
+                "GET",
+                "POST",
+                "DELETE",
+                "PUT"
+              ]
+            }
+          ],
+          "default": "GET"
+        },
+        "payload": {
+          "required": false,
+          "type": "string",
+          "default": ""
+        },
         "endpoint-selector": {
           "required": false,
           "type": "string"
index 6e3d5e9..d926aa3 100644 (file)
@@ -27,7 +27,7 @@
         "properties": {}
       },
       "processor-db": {
-        "type": "source-processor-db",
+        "type": "source-primary-db",
         "properties": {
           "endpoint-selector": "dynamic-db-source",
           "query": "SELECT artifact_name FROM sdnctl.BLUEPRINT_RUNTIME where artifact_version=\"1.0.0\"",
diff --git a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/kotlin/DefaultRestconf.cba.kts b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/kotlin/DefaultRestconf.cba.kts
new file mode 100644 (file)
index 0000000..770c363
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ *  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.
+ */
+
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor.RestconfComponentFunction
+import org.slf4j.LoggerFactory
+
+open class MountNEditConfigure : RestconfComponentFunction() {
+
+    val log = LoggerFactory.getLogger(MountNEditConfigure::class.java)!!
+
+    override fun getName(): String {
+        return "MountNEditConfigure"
+    }
+
+    override fun process(executionRequest: ExecutionServiceInput) {
+        log.info("processing request..")
+
+    }
+
+    override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+        log.info("processing request..")
+    }
+}
\ No newline at end of file
index a471349..de2f15d 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * 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.
  * limitations under the License.
  */
 
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.*
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintScriptsService
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
-import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.slf4j.LoggerFactory
 
 open class ScriptResourceAssignmentProcessor : ResourceAssignmentProcessor() {
 
-    lateinit var resourceAssignment: ResourceAssignment
+    private val log = LoggerFactory.getLogger(ScriptResourceAssignmentProcessor::class.java)!!
 
     override fun getName(): String {
-        return "resource-assignment-processor-custom-capability"
+        return "ScriptResourceAssignmentProcessor"
     }
 
-    override fun process(resourceAssignment: ResourceAssignment) {
-        this.resourceAssignment = resourceAssignment
+    override fun process(executionRequest: ResourceAssignment) {
+        log.info("Processing input")
     }
 
-    override fun prepareResponse(): ResourceAssignment {
-        return resourceAssignment
+    override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) {
+        log.info("Recovering input")
     }
-
-    override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
-        TODO("To Implement")
-    }
-
 }
\ No newline at end of file
index e64dee2..7ed4cc9 100755 (executable)
 # Web server config\r
 server.port=8080\r
 \r
-blueprintsprocessor.grpcEnable=false\r
+blueprintsprocessor.grpcEnable=true\r
 blueprintsprocessor.httpPort=8080\r
 blueprintsprocessor.grpcPort=9111\r
+\r
 # Blueprint Processor File Execution and Handling Properties\r
-blueprintsprocessor.blueprintDeployPath=/opt/app/onap/blueprints/deploy\r
-blueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive\r
+blueprintsprocessor.blueprintDeployPath=blueprints/deploy\r
+blueprintsprocessor.blueprintArchivePath=blueprints/archive\r
+blueprintsprocessor.blueprintWorkingPath=blueprints/work\r
 # Primary Database Configuration\r
 blueprintsprocessor.db.primary.url=jdbc:mysql://localhost:3306/sdnctl\r
 blueprintsprocessor.db.primary.username=sdnctl\r
index 3b97e67..c51dda7 100755 (executable)
@@ -25,7 +25,7 @@ blueprintsprocessor.grpcPort=9111
 # Blueprint Processor File Execution and Handling Properties
 blueprintsprocessor.blueprintDeployPath=/opt/app/onap/blueprints/deploy
 blueprintsprocessor.blueprintArchivePath=/opt/app/onap/blueprints/archive
-
+blueprintsprocessor.blueprintWorkingPath=/opt/app/onap/blueprints/work
 # Primary Database Configuration
 blueprintsprocessor.db.primary.url=jdbc:mysql://db:3306/sdnctl
 blueprintsprocessor.db.primary.username=sdnctl
index 48fc057..a6caf92 100644 (file)
@@ -19,7 +19,7 @@
         <!-- encoders are assigned the type\r
              ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->\r
         <encoder>\r
-            <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>\r
+            <pattern>%d{HH:mm:ss.SSS} %-5level %logger{50} - %msg%n</pattern>\r
         </encoder>\r
     </appender>\r
 \r
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/InternalRAProcessor.cba.kts b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/scripts/InternalRAProcessor.cba.kts
new file mode 100644 (file)
index 0000000..e6fc2ba
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ *  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.
+ */
+
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.slf4j.LoggerFactory
+
+open class SimpleRAProcessor : ResourceAssignmentProcessor() {
+
+    private val log = LoggerFactory.getLogger(SimpleRAProcessor::class.java)!!
+
+    override fun getName(): String {
+        return "ScriptResourceAssignmentProcessor"
+    }
+
+    override fun process(executionRequest: ResourceAssignment) {
+        log.info("Processing input")
+    }
+
+    override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) {
+        log.info("Recovering input")
+    }
+}
index bf0fb44..0120a8f 100644 (file)
@@ -59,7 +59,7 @@ class ExecutionServiceHandler(private val bluePrintPathConfiguration: BluePrintP
             // Copy the File Part to Local File
             copyFromFilePart(filePart, compressedFile)
             // Save the Copied file to Database
-            return bluePrintCatalogService.saveToDatabase(saveId, compressedFile, false)
+            return bluePrintCatalogService.saveToDatabase(saveId, compressedFile, true)
         } catch (e: IOException) {
             throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value,
                     "Error in Upload CBA: ${e.message}", e)
index 35fef96..be4327b 100644 (file)
@@ -22,7 +22,6 @@ import com.fasterxml.jackson.databind.JsonNode
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status
-import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.asObjectNode
@@ -120,6 +119,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
             prepareRequest(executionServiceInput)
             process(executionServiceInput)
         } catch (runtimeException: RuntimeException) {
+            log.error("failed in ${getName()} : ${runtimeException.message}", runtimeException)
             recover(runtimeException, executionServiceInput)
         }
         return prepareResponse()
index 6712a7f..df250ae 100644 (file)
@@ -77,7 +77,7 @@ class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService {
     }
 
     override fun registerExecutors(name: String, svcLogicNodeExecutor: AbstractSvcLogicNodeExecutor) {
-        log.info("Registering executors($name) with type(${svcLogicNodeExecutor.javaClass}")
+        log.debug("Registering executors($name) with type(${svcLogicNodeExecutor.javaClass}")
         nodeExecutors[name] = svcLogicNodeExecutor
     }
 
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctionTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/FileExtensionFunctionTest.kt
new file mode 100644 (file)
index 0000000..9a0da69
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ *  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.cds.controllerblueprints.core
+
+import org.junit.Test
+import kotlin.test.assertTrue
+
+class FileExtensionFunctionTest {
+    val blueprintBasePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+
+    @Test
+    fun testCompress() {
+        val blueprintFile = normalizedFile(blueprintBasePath)
+        val targetZip = normalizedFile("target", "compress.zip")
+        targetZip.deleteRecursively()
+        blueprintFile.compress(targetZip)
+        assertTrue(blueprintFile.exists(), "failed to create compressed file(${targetZip.absolutePath} ")
+    }
+
+}
\ No newline at end of file
index fb466f7..dbcd879 100644 (file)
@@ -19,7 +19,6 @@ package org.onap.ccsdk.cds.controllerblueprints.validation
 
 import com.att.eelf.configuration.EELFLogger
 import com.att.eelf.configuration.EELFManager
-import org.onap.ccsdk.cds.controllerblueprints.validation.utils.PropertyAssignmentValidationUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
 import org.onap.ccsdk.cds.controllerblueprints.core.data.*
@@ -27,6 +26,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTemp
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.validation.utils.PropertyAssignmentValidationUtils
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Service
@@ -44,7 +44,7 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator
     var paths: MutableList<String> = arrayListOf()
 
     override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
-        log.info("Validating NodeTemplate($name)")
+        log.debug("Validating NodeTemplate($name)")
 
         this.bluePrintRuntimeService = bluePrintRuntimeService
         this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
@@ -132,7 +132,8 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator
     @Throws(BluePrintException::class)
     open fun validateRequirementAssignment(nodeTemplateName: String, requirementAssignmentName: String,
                                            requirementDefinition: RequirementDefinition, requirementAssignment: RequirementAssignment) {
-        log.info("Validating NodeTemplate({}) requirement assignment ({}) ", nodeTemplateName, requirementAssignmentName)
+        log.debug("Validating NodeTemplate({}) requirement assignment ({}) ", nodeTemplateName,
+                requirementAssignmentName)
         val requirementNodeTemplateName = requirementAssignment.node!!
         val capabilityName = requirementAssignment.capability
         val relationship = requirementAssignment.relationship!!
@@ -197,7 +198,8 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator
                 val operationDefinition = interfaceDefinition.operations?.get(operationAssignmentName)
                         ?: throw BluePrintException("Failed to get NodeTemplate($nodeTemplateName) operation definition ($operationAssignmentName)")
 
-                log.info("Validation NodeTemplate($nodeTemplateName) Interface($interfaceAssignmentName) Operation ($operationAssignmentName)")
+                log.debug("Validation NodeTemplate($nodeTemplateName) Interface($interfaceAssignmentName) Operation " +
+                        "($operationAssignmentName)")
 
                 val inputs = operationAssignments.inputs
                 val outputs = operationAssignments.outputs