2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
20 package cba.pnf.config.aai
23 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
24 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.contentFromResolvedArtifactNB
25 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifactNB
26 import org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor.restconfMountDevice
27 import org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor.restconfApplyDeviceConfig
28 import org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor.restconfUnMountDevice
29 import org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor.restconfDeviceConfig
30 import org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor.restconfClientService
31 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
32 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
33 import org.onap.ccsdk.cds.controllerblueprints.core.logger
35 class RestconfConfigDeploy : AbstractScriptComponentFunction() {
36 private val CONFIGLET_TEMPLATE_NAME = "config-assign"
37 private val CONFIGLET_RESOURCE_PATH = "yang-ext:mount/mynetconf:netconflist"
38 private val RESTCONF_SERVER_IDENTIFIER = "sdnc"
39 private val log = logger(AbstractScriptComponentFunction::class.java)
41 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
42 log.info("Started execution of process method")
44 // Extract Resolution key & Device ID
45 val resolutionKey = getDynamicProperties("resolution-key").asText()
46 log.info("resolution_key: $resolutionKey")
47 val deviceID: String = requestPayloadActionProperty("config-deploy-properties")?.get(0)?.get("pnf-id")?.textValue()!!
48 log.info("device_id: $deviceID")
49 val webclientService = restconfClientService(RESTCONF_SERVER_IDENTIFIER)
53 val mountPayload = contentFromResolvedArtifactNB("config-deploy")
54 log.debug("Mounting Device : $deviceID")
55 restconfMountDevice(webclientService, deviceID, mountPayload, mutableMapOf("Content-Type" to "application/json"))
57 //Log the current configuration for the subtree
58 val currentConfig: Any = restconfDeviceConfig(webclientService, deviceID, CONFIGLET_RESOURCE_PATH)
59 log.info("Current configuration subtree : $currentConfig")
61 restconfApplyDeviceConfig(webclientService, deviceID, CONFIGLET_RESOURCE_PATH,
62 storedContentFromResolvedArtifactNB(resolutionKey, CONFIGLET_TEMPLATE_NAME),
63 mutableMapOf("Content-Type" to "application/yang.patch+json"))
65 } catch (err: Exception) {
66 log.error("an error occurred while configuring device {}", err)
69 restconfUnMountDevice(webclientService, deviceID, "")
71 } catch (bpe: BluePrintProcessorException) {
72 log.error("Error looking up server identifier ", bpe)
77 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
78 log.info("Recover function called!")
79 log.info("Execution request : $executionRequest")
80 log.error("Exception", runtimeException)