Enabling Code Formatter
[ccsdk/cds.git] / components / model-catalog / blueprint-model / test-blueprint / resource-audit / Scripts / kotlin / cba / resource / audit / functions / ConfigCollector.kt
1 /*
2  *  Copyright © 2019 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package cba.resource.audit.functions
18
19 import cba.resource.audit.deviceResourceDefinitions
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
21 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
22 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
24 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
25 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
26 import org.onap.ccsdk.cds.controllerblueprints.core.logger
27
28 class ConfigCollector : AbstractScriptComponentFunction() {
29
30     val log = logger(ConfigCollector::class)
31
32     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
33
34         val deviceId = bluePrintRuntimeService.getInputValue("device-id").textValue()
35         val sources = bluePrintRuntimeService.getInputValue("sources")
36
37         log.info("Processing Config Collection for device($deviceId), for sources($sources)")
38         deviceResourceDefinitions.forEach { name, resourceDefinition ->
39             log.info("collecting for the property : $name")
40             resourceDefinition.sources.forEach { sourceName, source ->
41                 log.info("collecting for the Source : $sourceName")
42             }
43         }
44
45         // Set the Attributes
46         setAttribute(ComponentScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.STATUS_SUCCESS.asJsonPrimitive())
47         setAttribute(
48             ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA,
49             """{
50                       "port-speed" : "10MBS"
51         }
52             """.trimIndent().jsonAsJsonType()
53         )
54     }
55
56     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
57     }
58 }