blueprint scripting services
authorMuthuramalingam, Brinda Santh <bs2796@att.com>
Wed, 30 Jan 2019 20:52:30 +0000 (15:52 -0500)
committerSteve Alphonse Siani <alphonse.steve.siani.djissitchi@ibm.com>
Mon, 4 Feb 2019 14:45:59 +0000 (09:45 -0500)
Change-Id: I834b83e0c2716eceadeec8a5f17a7604e938166a
Issue-ID: CCSDK-941
Signed-off-by: Muthuramalingam, Brinda Santh <bs2796@att.com>
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt [new file with mode: 0644]
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt
components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Scripts/kotlin/ResourceAssignmentProcessor.cba.kts [new file with mode: 0644]
components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Scripts/kotlin/ScriptComponent.cba.kts [new file with mode: 0644]
components/model-catalog/definition-type/starter-type/node_type/source-capability.json

index 4ef0e82..b1a7daa 100644 (file)
@@ -27,13 +27,13 @@ object BluePrintConstants {
     const val RESPONSE_HEADER_TRANSACTION_ID: String = "X-ONAP-RequestID"\r
     const val RESPONSE_HEADER_MINOR_VERSION: String = "X-MinorVersion"\r
     const val RESPONSE_HEADER_PATCH_VERSION: String = "X-PatchVersion"\r
-    const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion"
-
-    const val STATUS_SUCCESS: String = "success"
-    const val STATUS_PROCESSING: String = "processing"
-    const val STATUS_FAILURE: String = "failure"
-
-    const val TYPE_DEFAULT: String = "default"
+    const val RESPONSE_HEADER_LATEST_VERSION: String = "X-LatestVersion"\r
+\r
+    const val STATUS_SUCCESS: String = "success"\r
+    const val STATUS_PROCESSING: String = "processing"\r
+    const val STATUS_FAILURE: String = "failure"\r
+\r
+    const val TYPE_DEFAULT: String = "default"\r
 \r
     const val DATA_TYPE_STRING: String = "string"\r
     const val DATA_TYPE_INTEGER: String = "integer"\r
@@ -102,6 +102,7 @@ object BluePrintConstants {
     const val MODEL_TYPE_NODES_COMPONENT_SCRIPT: String = "tosca.nodes.component.Script"\r
     const val MODEL_TYPE_NODES_COMPONENT_PYTHON: String = "tosca.nodes.component.Python"\r
     const val MODEL_TYPE_NODES_COMPONENT_JYTHON: String = "tosca.nodes.component.Jython"\r
+    const val MODEL_TYPE_NODES_COMPONENT_KOTLIN: String = "tosca.nodes.component.Kotlin"\r
     const val MODEL_TYPE_NODES_COMPONENT_JAVA_SCRIPT: String = "tosca.nodes.component.JavaScript"\r
 \r
     const val MODEL_TYPE_ARTIFACT_TYPE_IMPLEMENTATION = "tosca.artifacts.Implementation"\r
@@ -148,6 +149,7 @@ object BluePrintConstants {
     const val TOSCA_SCRIPTS_DIR: String = "Scripts"\r
     const val TOSCA_MAPPINGS_DIR: String = "Mappings"\r
     const val TOSCA_TEMPLATES_DIR: String = "Templates"\r
+    const val TOSCA_SCRIPTS_KOTLIN_DIR: String = "$TOSCA_SCRIPTS_DIR/kotlin"\r
 \r
     const val METADATA_USER_GROUPS = "user-groups"\r
     const val METADATA_TEMPLATE_NAME = "template_name"\r
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
new file mode 100644 (file)
index 0000000..124c167
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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.controllerblueprints.core.interfaces
+
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+
+interface BluePrintScriptsService{
+
+    fun <T> scriptInstance(blueprintContext: BluePrintContext, scriptClassName: String,
+                           reCompile: Boolean): T
+}
\ No newline at end of file
index 1a6d096..7936045 100644 (file)
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
  */\r
+@file:Suppress("unused")\r
 \r
 package org.onap.ccsdk.apps.controllerblueprints.core.service\r
 \r
 import com.att.eelf.configuration.EELFLogger\r
 import com.att.eelf.configuration.EELFManager\r
 import com.fasterxml.jackson.databind.JsonNode\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.*\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
@@ -55,6 +57,15 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) {
         return JacksonUtils.getJson(serviceTemplate, pretty)\r
     }\r
 \r
+    fun name(): String = metadata?.get(BluePrintConstants.METADATA_TEMPLATE_NAME)\r
+            ?: throw BluePrintException("could't get template name from meta data")\r
+\r
+    fun version(): String = metadata?.get(BluePrintConstants.METADATA_TEMPLATE_VERSION)\r
+            ?: throw BluePrintException("could't get template version from meta data")\r
+\r
+    fun author(): String = metadata?.get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR)\r
+            ?: throw BluePrintException("could't get template author from meta data")\r
+\r
     // Workflow\r
     val workflows: MutableMap<String, Workflow>? = serviceTemplate.topologyTemplate?.workflows\r
 \r
@@ -148,7 +159,7 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) {
     val nodeTemplates: MutableMap<String, NodeTemplate>? = serviceTemplate.topologyTemplate?.nodeTemplates\r
 \r
     fun nodeTemplateByName(name: String): NodeTemplate =\r
-            nodeTemplates?.get(name) ?: throw BluePrintException("could't get node template for the name($name)")
+            nodeTemplates?.get(name) ?: throw BluePrintException("could't get node template for the name($name)")\r
 \r
     fun nodeTemplateForNodeType(name: String): MutableMap<String, NodeTemplate>? {\r
         return nodeTemplates?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap()\r
diff --git a/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Scripts/kotlin/ResourceAssignmentProcessor.cba.kts b/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Scripts/kotlin/ResourceAssignmentProcessor.cba.kts
new file mode 100644 (file)
index 0000000..f1da614
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.*
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+
+open class ScriptResourceAssignmentProcessor : ResourceAssignmentProcessor() {
+
+    lateinit var resourceAssignment: ResourceAssignment
+
+    override fun getName(): String {
+        return "resource-assignment-processor-custom-capability"
+    }
+
+    override fun process(resourceAssignment: ResourceAssignment) {
+        this.resourceAssignment = resourceAssignment
+    }
+
+    override fun prepareResponse(): ResourceAssignment {
+        return resourceAssignment
+    }
+
+    override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+        TODO("To Implement")
+    }
+
+}
\ No newline at end of file
diff --git a/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Scripts/kotlin/ScriptComponent.cba.kts b/components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Scripts/kotlin/ScriptComponent.cba.kts
new file mode 100644 (file)
index 0000000..184c493
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode
+
+open class SampleKotlinComponent : BlueprintFunctionNode<String, String> {
+
+    override fun getName(): String {
+        return "my Name"
+    }
+
+    override fun prepareRequest(executionRequest: String): String {
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    }
+
+    override fun process(executionRequest: String) {
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    }
+
+    override fun recover(runtimeException: RuntimeException, executionRequest: String) {
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    }
+
+    override fun prepareResponse(): String {
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    }
+
+    override fun apply(t: String): String {
+        return "Successfully Executed Scripts"
+    }
+}
index e4eb90e..2bdd7d5 100644 (file)
       ]
     },
     "instance-name": {
-      "description": "Capability component instance reference name.",
+      "description": "Capability component instance reference name for JAVA-COMPONENT, Script Class name for KOTLIN-COMPONENT.",
       "required": true,
       "type": "string"
     },
+    "instance-dependencies": {
+      "required": false,
+      "description": "Instance dependency Names to Inject to Kotlin / Jython Script.",
+      "type": "list",
+      "entry_schema": {
+        "type": "string"
+      }
+    },
     "input-key-mapping": {
       "description": "Context name to input parameters name mapping.",
       "required": false,