2 * Copyright © 2019 IBM.
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.cds.blueprintsprocessor.message.service
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
21 import org.onap.ccsdk.cds.blueprintsprocessor.message.*
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
23 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
24 import org.springframework.stereotype.Service
26 @Service(MessageLibConstants.SERVICE_BLUEPRINT_MESSAGE_LIB_PROPERTY)
27 open class BluePrintMessageLibPropertyService(private var bluePrintProperties: BluePrintProperties) {
29 fun blueprintMessageProducerService(jsonNode: JsonNode): BlueprintMessageProducerService {
30 val messageClientProperties = messageProducerProperties(jsonNode)
31 return blueprintMessageProducerService(messageClientProperties)
34 fun blueprintMessageProducerService(selector: String): BlueprintMessageProducerService {
35 val prefix = "${MessageLibConstants.PROPERTY_MESSAGE_PRODUCER_PREFIX}$selector"
36 val messageClientProperties = messageProducerProperties(prefix)
37 return blueprintMessageProducerService(messageClientProperties)
40 fun messageProducerProperties(prefix: String): MessageProducerProperties {
41 val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
43 MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> {
44 kafkaBasicAuthMessageProducerProperties(prefix)
47 throw BluePrintProcessorException("Message adaptor($type) is not supported")
52 fun messageProducerProperties(jsonNode: JsonNode): MessageProducerProperties {
53 val type = jsonNode.get("type").textValue()
55 MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> {
56 JacksonUtils.readValue(jsonNode, KafkaBasicAuthMessageProducerProperties::class.java)!!
59 throw BluePrintProcessorException("Message adaptor($type) is not supported")
64 private fun blueprintMessageProducerService(MessageProducerProperties: MessageProducerProperties)
65 : BlueprintMessageProducerService {
67 when (MessageProducerProperties) {
68 is KafkaBasicAuthMessageProducerProperties -> {
69 return KafkaBasicAuthMessageProducerService(MessageProducerProperties)
72 throw BluePrintProcessorException("couldn't get Message client service for")
77 private fun kafkaBasicAuthMessageProducerProperties(prefix: String): KafkaBasicAuthMessageProducerProperties {
78 return bluePrintProperties.propertyBeanType(
79 prefix, KafkaBasicAuthMessageProducerProperties::class.java)
82 /** Consumer Property Lib Service Implementation **/
84 /** Return Message Consumer Service for [jsonNode] definitions. */
85 fun blueprintMessageConsumerService(jsonNode: JsonNode): BlueprintMessageConsumerService {
86 val messageConsumerProperties = messageConsumerProperties(jsonNode)
87 return blueprintMessageConsumerService(messageConsumerProperties)
90 /** Return Message Consumer Service for [selector] definitions. */
91 fun blueprintMessageConsumerService(selector: String): BlueprintMessageConsumerService {
92 val prefix = "${MessageLibConstants.PROPERTY_MESSAGE_CONSUMER_PREFIX}$selector"
93 val messageClientProperties = messageConsumerProperties(prefix)
94 return blueprintMessageConsumerService(messageClientProperties)
97 /** Return Message Consumer Properties for [prefix] definitions. */
98 fun messageConsumerProperties(prefix: String): MessageConsumerProperties {
99 val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
101 MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> {
102 kafkaBasicAuthMessageConsumerProperties(prefix)
105 throw BluePrintProcessorException("Message adaptor($type) is not supported")
110 fun messageConsumerProperties(jsonNode: JsonNode): MessageConsumerProperties {
111 val type = jsonNode.get("type").textValue()
113 MessageLibConstants.TYPE_KAFKA_BASIC_AUTH -> {
114 JacksonUtils.readValue(jsonNode, KafkaBasicAuthMessageConsumerProperties::class.java)!!
117 throw BluePrintProcessorException("Message adaptor($type) is not supported")
122 private fun blueprintMessageConsumerService(messageConsumerProperties: MessageConsumerProperties)
123 : BlueprintMessageConsumerService {
125 when (messageConsumerProperties) {
126 is KafkaBasicAuthMessageConsumerProperties -> {
127 return KafkaBasicAuthMessageConsumerService(messageConsumerProperties)
130 throw BluePrintProcessorException("couldn't get Message client service for")
135 private fun kafkaBasicAuthMessageConsumerProperties(prefix: String): KafkaBasicAuthMessageConsumerProperties {
136 return bluePrintProperties.propertyBeanType(
137 prefix, KafkaBasicAuthMessageConsumerProperties::class.java)