2 * Copyright © 2017-2018 AT&T Intellectual Property.
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.apps.blueprintsprocessor.functions.resource.resolution.processor
19 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource
20 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceResolutionUtils
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
22 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
23 import org.springframework.beans.factory.annotation.Autowired
24 import org.springframework.context.ApplicationContext
25 import org.springframework.stereotype.Service
27 @Service("resource-assignment-processor-capability")
28 open class CapabilityResourceAssignmentProcessor : ResourceAssignmentProcessor() {
31 const val CAPABILITY_TYPE_JAVA_COMPONENT = "JAVA-COMPONENT"
32 const val CAPABILITY_TYPE_JYTHON_COMPONENT = "JYTHON-COMPONENT"
36 private lateinit var applicationContext: ApplicationContext
38 override fun getName(): String {
39 return "resource-assignment-processor-capability"
42 override fun process(executionRequest: ResourceAssignment) {
44 val resourceDefinition = resourceDictionaries[executionRequest.dictionaryName]
45 ?: throw BluePrintProcessorException("couldn't get resource definition for ${executionRequest.dictionaryName}")
47 val resourceSource = resourceDefinition.sources[executionRequest.dictionarySource]
48 ?: throw BluePrintProcessorException("couldn't get resource definition ${executionRequest.dictionaryName} source(${executionRequest.dictionarySource})")
50 checkNotNull(resourceSource.properties) { "failed to get ${executionRequest.dictionarySource} properties" }
52 val capabilityResourceSourceProperty = ResourceResolutionUtils.transformResourceSource(resourceSource.properties!!, CapabilityResourceSource::class.java)
54 val instanceType = capabilityResourceSourceProperty.type
55 val instanceName = capabilityResourceSourceProperty.instanceName
58 var componentResourceAssignmentProcessor: ResourceAssignmentProcessor? = null
61 CAPABILITY_TYPE_JAVA_COMPONENT -> {
62 // Initialize Capability Resource Assignment Processor
63 componentResourceAssignmentProcessor = applicationContext.getBean(instanceName, ResourceAssignmentProcessor::class.java)
65 CAPABILITY_TYPE_JYTHON_COMPONENT -> {
66 TODO(" No implementation")
70 checkNotNull(componentResourceAssignmentProcessor) { "failed to get capability resource assignment processor($instanceName)" }
72 // Assign Current Blueprint runtime and ResourceDictionaries
73 componentResourceAssignmentProcessor.bluePrintRuntimeService = bluePrintRuntimeService
74 componentResourceAssignmentProcessor.resourceDictionaries = resourceDictionaries
76 // Invoke componentResourceAssignmentProcessor
77 componentResourceAssignmentProcessor.apply(executionRequest)
80 override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) {