Update vLB CDS Kotlin Package
[ccsdk/cds.git] / components / model-catalog / blueprint-model / service-blueprint / vLB_CDS_Kotlin / Scripts / kotlin / kotlin.kt
1 /*\r
2  * Copyright © 2019 IBM, Bell Canada, AT&T, Orange\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts\r
18 \r
19 import com.fasterxml.jackson.databind.node.ObjectNode\r
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput\r
21 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifactNB\r
22 import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties\r
23 import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties\r
24 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService\r
25 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService\r
26 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction\r
27 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils\r
28 import org.slf4j.LoggerFactory\r
29 import org.springframework.http.HttpMethod\r
30 import org.springframework.http.client.support.BasicAuthorizationInterceptor\r
31 import org.springframework.web.client.RestTemplate\r
32 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfClientService\r
33 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDevice\r
34 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDeviceInfo\r
35 \r
36 open class ConfigDeploy : AbstractScriptComponentFunction() {\r
37 \r
38     private val log = LoggerFactory.getLogger(ConfigDeploy::class.java)!!\r
39 \r
40     override suspend fun processNB(executionRequest: ExecutionServiceInput) {\r
41         val resolution_key = getDynamicProperties("resolution-key").asText()\r
42         log.info("resolution_key: $resolution_key"\n)\r
43         val payload = storedContentFromResolvedArtifactNB(resolution_key, "baseconfig")\r
44         log.info("configuration: \n$payload"\n)\r
45         log.info("Waiting 1 minute and 30 seconds or vLB to initialize ...")\r
46         Thread.sleep(90000)\r
47         val netconf_device = netconfDevice("netconf-connection")\r
48         val netconf_rpc_client = netconf_device.netconfRpcService\r
49         val netconf_session = netconf_device.netconfSession\r
50         netconf_session.connect()\r
51         netconf_rpc_client.lock("candidate")\r
52         netconf_rpc_client.discardConfig()\r
53         netconf_rpc_client.editConfig(payload, "candidate", "merge")\r
54         netconf_rpc_client.commit()\r
55         netconf_rpc_client.unLock("candidate")\r
56         netconf_rpc_client.getConfig("", "running")\r
57 \r
58         //var payloadObject = JacksonUtils.jsonNode(payload) as ObjectNode\r
59         //var vdns_ip: String = payloadObject.get("vdns-instance")[0].get("ip-addr").asText()\r
60         netconf_session.disconnect()\r
61 \r
62 \r
63     }\r
64 \r
65     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {\r
66         log.info("Executing Recovery")\r
67     }\r
68 }\r