Merge "Fix Sonar report by creating src/test where miss"
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / main / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / functions / resource / resolution / processor / ResourceAssignmentProcessor.kt
1 /*
2  *  Copyright © 2018 IBM.
3  *  Modifications Copyright © 2017-2018 AT&T Intellectual Property.
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.apps.blueprintsprocessor.functions.resource.resolution.processor
19
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
21 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode
22 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
23 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
24 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
25 import org.slf4j.LoggerFactory
26
27 abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssignment, ResourceAssignment> {
28
29     private val log = LoggerFactory.getLogger(ResourceAssignmentProcessor::class.java)
30
31     lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
32
33     lateinit var resourceDictionaries: Map<String, ResourceDefinition>
34
35
36     open fun resourceDefinition(name: String): ResourceDefinition {
37         return resourceDictionaries[name]
38                 ?: throw BluePrintProcessorException("couldn't get resource definition($name)")
39     }
40
41     override fun prepareRequest(resourceAssignment: ResourceAssignment): ResourceAssignment {
42         log.info("prepareRequest for ${resourceAssignment.name}, dictionary(${resourceAssignment.dictionaryName})," +
43                 "source(${resourceAssignment.dictionarySource})")
44         return resourceAssignment
45     }
46
47     override fun prepareResponse(): ResourceAssignment {
48         log.info("Preparing Response...")
49         return ResourceAssignment()
50     }
51
52     override fun apply(executionServiceInput: ResourceAssignment): ResourceAssignment {
53         prepareRequest(executionServiceInput)
54         process(executionServiceInput)
55         return prepareResponse()
56     }
57
58 }