Formatting Code base with ktlint
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / netconf-executor / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / netconf / executor / NetconfComponentFunction.kt
1 /*
2  *  Copyright © 2018-2019 IBM, Bell Canada.
3  *  Modifications Copyright © 2019 IBM.
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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  */
17
18 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor
19
20 import kotlinx.coroutines.runBlocking
21 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
23 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
24
25 @Deprecated("Methods defined as extension function of AbstractComponentFunction")
26 abstract class NetconfComponentFunction : AbstractScriptComponentFunction() {
27
28     @Deprecated(
29         " Use resourceResolutionService method directly",
30         replaceWith = ReplaceWith(
31             "resourceResolutionService()",
32             "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resourceResolutionService"
33         )
34     )
35     open fun resourceResolutionService(): ResourceResolutionService =
36         functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
37
38     // Called from python script
39     @Deprecated(
40         " Use netconfDeviceInfo method directly",
41         replaceWith = ReplaceWith(
42             "netconfDeviceInfo(requirementName)",
43             "org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDeviceInfo"
44         )
45     )
46     fun initializeNetconfConnection(requirementName: String): NetconfDevice {
47         val deviceInfo = netconfDeviceInfo(requirementName)
48         return NetconfDevice(deviceInfo)
49     }
50
51     @Deprecated(
52         " Use artifactContent method directly",
53         replaceWith = ReplaceWith(
54             "artifactContent(artifactName)",
55             "org.onap.ccsdk.cds.blueprintsprocessor.services.execution.artifactContent"
56         )
57     )
58     fun generateMessage(artifactName: String): String {
59         return bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
60     }
61
62     @Deprecated(
63         " Use storedContentFromResolvedArtifact method directly",
64         replaceWith = ReplaceWith(
65             "storedContentFromResolvedArtifact(resolutionKey, artifactName)",
66             "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifact"
67         )
68     )
69     fun resolveFromDatabase(resolutionKey: String, artifactName: String): String = runBlocking {
70         resourceResolutionService().resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey)
71     }
72
73     @Deprecated(
74         " Use contentFromResolvedArtifact method directly",
75         replaceWith = ReplaceWith(
76             "resolveAndGenerateMessage(artifactPrefix)",
77             "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resolveAndGenerateMessage"
78         )
79     )
80     fun resolveAndGenerateMessage(artifactPrefix: String): String = runBlocking {
81         resourceResolutionService().resolveResources(
82             bluePrintRuntimeService, nodeTemplateName,
83             artifactPrefix, mapOf()
84         )
85     }
86 }