Update vLB CDS Kotlin Package
[ccsdk/cds.git] / components / model-catalog / blueprint-model / service-blueprint / vLB_CDS_Kotlin / Scripts / kotlin / kotlin.kt
diff --git a/components/model-catalog/blueprint-model/service-blueprint/vLB_CDS_Kotlin/Scripts/kotlin/kotlin.kt b/components/model-catalog/blueprint-model/service-blueprint/vLB_CDS_Kotlin/Scripts/kotlin/kotlin.kt
new file mode 100644 (file)
index 0000000..ef0876f
--- /dev/null
@@ -0,0 +1,68 @@
+/*\r
+ * Copyright © 2019 IBM, Bell Canada, AT&T, Orange\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts\r
+\r
+import com.fasterxml.jackson.databind.node.ObjectNode\r
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput\r
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifactNB\r
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties\r
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties\r
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService\r
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService\r
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction\r
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils\r
+import org.slf4j.LoggerFactory\r
+import org.springframework.http.HttpMethod\r
+import org.springframework.http.client.support.BasicAuthorizationInterceptor\r
+import org.springframework.web.client.RestTemplate\r
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfClientService\r
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDevice\r
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDeviceInfo\r
+\r
+open class ConfigDeploy : AbstractScriptComponentFunction() {\r
+\r
+    private val log = LoggerFactory.getLogger(ConfigDeploy::class.java)!!\r
+\r
+    override suspend fun processNB(executionRequest: ExecutionServiceInput) {\r
+        val resolution_key = getDynamicProperties("resolution-key").asText()\r
+        log.info("resolution_key: $resolution_key"\n)\r
+        val payload = storedContentFromResolvedArtifactNB(resolution_key, "baseconfig")\r
+        log.info("configuration: \n$payload"\n)\r
+        log.info("Waiting 1 minute and 30 seconds or vLB to initialize ...")\r
+        Thread.sleep(90000)\r
+        val netconf_device = netconfDevice("netconf-connection")\r
+        val netconf_rpc_client = netconf_device.netconfRpcService\r
+        val netconf_session = netconf_device.netconfSession\r
+        netconf_session.connect()\r
+        netconf_rpc_client.lock("candidate")\r
+        netconf_rpc_client.discardConfig()\r
+        netconf_rpc_client.editConfig(payload, "candidate", "merge")\r
+        netconf_rpc_client.commit()\r
+        netconf_rpc_client.unLock("candidate")\r
+        netconf_rpc_client.getConfig("", "running")\r
+\r
+        //var payloadObject = JacksonUtils.jsonNode(payload) as ObjectNode\r
+        //var vdns_ip: String = payloadObject.get("vdns-instance")[0].get("ip-addr").asText()\r
+        netconf_session.disconnect()\r
+\r
+\r
+    }\r
+\r
+    override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {\r
+        log.info("Executing Recovery")\r
+    }\r
+}\r