2 * Copyright © 2020 Aarna Networks, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts
19 import com.fasterxml.jackson.databind.node.ObjectNode
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
21 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifactNB
22 import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties
23 import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties
24 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService
25 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
26 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
27 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
28 import org.slf4j.LoggerFactory
29 import org.springframework.http.HttpMethod
30 import org.springframework.web.client.RestTemplate
31 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfClientService
32 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDevice
33 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDeviceInfo
35 open class ConfigDeploy : AbstractScriptComponentFunction() {
37 private val log = LoggerFactory.getLogger(ConfigDeploy::class.java)!!
39 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
42 * Here resolution-key could be day-1, day-2 etc..
43 * This will come as part of config-deploy request payload.
46 val resolution_key = getDynamicProperties("resolution-key").asText()
47 log.info("Got the resolution_key: $resolution_key from config-deploy going to retrive the data from DB")
49 // Read the config-assing data using the resolution key + Prefix name for the template
50 // We can select the given configuration using the resolution_key=day-1 or day-2
51 // With the template prefix name for example "netconfrpc" to load the
52 // Store configuration from the CDS DB
53 val payload = storedContentFromResolvedArtifactNB(resolution_key, "netconfrpc")
54 log.info("PNF configuration data from DB : \n$payload\n")
56 // "netconf-connection" is the tosca Node reference to "execute"
58 val netconf_device = netconfDevice("netconf-connection")
59 val netconf_rpc_client = netconf_device.netconfRpcService
60 val netconf_session = netconf_device.netconfSession
61 netconf_session.connect()
64 * Invoke the NETCONF RPC, we already have the teamplate loaded
65 * using "resolution-key" & template name prefix.
67 val dev_response = netconf_rpc_client.invokeRpc(payload)
68 log.info("NETCONF device response message : dev_response\n")
71 netconf_rpc_client.lock("candidate")
72 netconf_rpc_client.discardConfig()
73 netconf_rpc_client.editConfig(payload, "candidate", "merge")
74 netconf_rpc_client.commit()
75 netconf_rpc_client.unLock("candidate")
76 netconf_rpc_client.getConfig("", "running")
79 log.info("Closing NETCONF device sessing with the device\n")
80 netconf_session.disconnect()
84 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
85 log.info("Executing Recovery")