2 * Copyright © 2018-2019 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.cds.blueprintsprocessor.message
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
22 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
23 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType
25 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder
26 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder
27 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder
29 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType
31 /** Relationships Types DSL for Message Producer */
32 fun ServiceTemplateBuilder.relationshipTypeConnectsToMessageProducer() {
33 val relationshipType = BluePrintTypes.relationshipTypeConnectsToMessageProducer()
34 if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf()
35 this.relationshipTypes!![relationshipType.id!!] = relationshipType
38 fun BluePrintTypes.relationshipTypeConnectsToMessageProducer(): RelationshipType {
39 return relationshipType(
40 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER,
41 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
42 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
43 description = "Relationship connects to through message producer."
46 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
47 BluePrintConstants.DATA_TYPE_MAP,
49 "Connection Config details."
51 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
55 fun ServiceTemplateBuilder.relationshipTypeConnectsToMessageConsumer() {
56 val relationshipType = BluePrintTypes.relationshipTypeConnectsToMessageConsumer()
57 if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf()
58 this.relationshipTypes!![relationshipType.id!!] = relationshipType
61 fun BluePrintTypes.relationshipTypeConnectsToMessageConsumer(): RelationshipType {
62 return relationshipType(
63 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER,
64 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
65 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
66 description = "Relationship type connects to message consumer."
69 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
70 BluePrintConstants.DATA_TYPE_MAP,
72 "Connection Config details."
74 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
78 /** Relationships Templates DSL for Message Producer */
79 fun TopologyTemplateBuilder.relationshipTemplateMessageProducer(
82 block: MessageProducerRelationshipTemplateBuilder.() -> Unit
84 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
85 val relationshipTemplate =
86 MessageProducerRelationshipTemplateBuilder(name, description).apply(block).build()
87 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
90 class MessageProducerRelationshipTemplateBuilder(name: String, description: String) :
91 RelationshipTemplateBuilder(
93 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER, description
96 fun kafkaBasicAuth(block: KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit) {
98 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
99 BluePrintTypes.kafkaBasicAuthMessageProducerProperties(block)
104 fun BluePrintTypes.kafkaBasicAuthMessageProducerProperties(block: KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit): JsonNode {
105 val assignments = KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder().apply(block).build()
106 assignments[KafkaBasicAuthMessageProducerProperties::type.name] =
107 MessageLibConstants.TYPE_KAFKA_BASIC_AUTH.asJsonPrimitive()
108 return assignments.asJsonType()
111 open class MessageProducerPropertiesAssignmentBuilder : PropertiesAssignmentBuilder()
113 class KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder : MessageProducerPropertiesAssignmentBuilder() {
115 fun bootstrapServers(bootstrapServers: String) = bootstrapServers(bootstrapServers.asJsonPrimitive())
117 fun bootstrapServers(bootstrapServers: JsonNode) =
118 property(KafkaBasicAuthMessageProducerProperties::bootstrapServers, bootstrapServers)
120 fun topic(topic: String) = topic(topic.asJsonPrimitive())
122 fun topic(topic: JsonNode) =
123 property(KafkaBasicAuthMessageProducerProperties::topic, topic)
125 fun clientId(clientId: String) = bootstrapServers(clientId.asJsonPrimitive())
127 fun clientId(clientId: JsonNode) =
128 property(KafkaBasicAuthMessageProducerProperties::clientId, clientId)
130 fun acks(acks: String) = acks(acks.asJsonPrimitive())
132 fun acks(acks: JsonNode) = property(KafkaBasicAuthMessageProducerProperties::acks, acks)
134 fun retries(retries: Int) = retries(retries.asJsonPrimitive())
136 fun retries(retries: JsonNode) = property(KafkaBasicAuthMessageProducerProperties::retries, retries)
138 fun enableIdempotence(enableIdempotence: Boolean) = enableIdempotence(enableIdempotence.asJsonPrimitive())
140 fun enableIdempotence(enableIdempotence: JsonNode) =
141 property(KafkaBasicAuthMessageProducerProperties::enableIdempotence, enableIdempotence)
144 /** Relationships Templates DSL for Message Consumer */
145 fun TopologyTemplateBuilder.relationshipTemplateMessageConsumer(
148 block: MessageConsumerRelationshipTemplateBuilder.() -> Unit
150 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
151 val relationshipTemplate =
152 MessageConsumerRelationshipTemplateBuilder(name, description).apply(block).build()
153 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
156 class MessageConsumerRelationshipTemplateBuilder(name: String, description: String) :
157 RelationshipTemplateBuilder(
159 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER, description
162 fun kafkaBasicAuth(block: KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit) {
164 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
165 BluePrintTypes.kafkaBasicAuthMessageConsumerProperties(block)
169 fun kafkaStreamsBasicAuth(block: KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder.() -> Unit) {
171 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
172 BluePrintTypes.kafkaStreamsBasicAuthConsumerProperties(block)
177 fun BluePrintTypes.kafkaBasicAuthMessageConsumerProperties(block: KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode {
178 val assignments = KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder().apply(block).build()
179 assignments[KafkaBasicAuthMessageConsumerProperties::type.name] =
180 MessageLibConstants.TYPE_KAFKA_BASIC_AUTH.asJsonPrimitive()
181 return assignments.asJsonType()
184 fun BluePrintTypes.kafkaStreamsBasicAuthConsumerProperties(block: KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode {
185 val assignments = KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder().apply(block).build()
186 assignments[KafkaStreamsBasicAuthConsumerProperties::type.name] =
187 MessageLibConstants.TYPE_KAFKA_STREAMS_BASIC_AUTH.asJsonPrimitive()
188 return assignments.asJsonType()
191 open class MessageConsumerPropertiesAssignmentBuilder : PropertiesAssignmentBuilder()
193 open class KafkaMessageConsumerPropertiesAssignmentBuilder : MessageConsumerPropertiesAssignmentBuilder() {
195 fun bootstrapServers(bootstrapServers: String) = bootstrapServers(bootstrapServers.asJsonPrimitive())
197 fun bootstrapServers(bootstrapServers: JsonNode) =
198 property(KafkaMessageConsumerProperties::bootstrapServers, bootstrapServers)
200 fun groupId(groupId: String) = groupId(groupId.asJsonPrimitive())
202 fun groupId(groupId: JsonNode) =
203 property(KafkaMessageConsumerProperties::groupId, groupId)
205 fun clientId(clientId: String) = clientId(clientId.asJsonPrimitive())
207 fun clientId(clientId: JsonNode) =
208 property(KafkaMessageConsumerProperties::clientId, clientId)
210 fun topic(topic: String) = topic(topic.asJsonPrimitive())
212 fun topic(topic: JsonNode) =
213 property(KafkaMessageConsumerProperties::topic, topic)
215 fun autoCommit(autoCommit: Boolean) = autoCommit(autoCommit.asJsonPrimitive())
217 fun autoCommit(autoCommit: JsonNode) =
218 property(KafkaMessageConsumerProperties::autoCommit, autoCommit)
220 fun autoOffsetReset(autoOffsetReset: String) = autoOffsetReset(autoOffsetReset.asJsonPrimitive())
222 fun autoOffsetReset(autoOffsetReset: JsonNode) =
223 property(KafkaMessageConsumerProperties::autoOffsetReset, autoOffsetReset)
225 fun pollMillSec(pollMillSec: Int) = pollMillSec(pollMillSec.asJsonPrimitive())
227 fun pollMillSec(pollMillSec: JsonNode) =
228 property(KafkaMessageConsumerProperties::pollMillSec, pollMillSec)
230 fun pollRecords(pollRecords: Int) = pollRecords(pollRecords.asJsonPrimitive())
232 fun pollRecords(pollRecords: JsonNode) =
233 property(KafkaMessageConsumerProperties::pollRecords, pollRecords)
236 /** KafkaBasicAuthMessageConsumerProperties assignment builder */
237 class KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder : KafkaMessageConsumerPropertiesAssignmentBuilder()
239 /** KafkaStreamsConsumerProperties assignment builder */
240 open class KafkaStreamsConsumerPropertiesAssignmentBuilder : MessageConsumerPropertiesAssignmentBuilder() {
242 fun bootstrapServers(bootstrapServers: String) = bootstrapServers(bootstrapServers.asJsonPrimitive())
244 fun bootstrapServers(bootstrapServers: JsonNode) =
245 property(KafkaStreamsConsumerProperties::bootstrapServers, bootstrapServers)
247 fun applicationId(applicationId: String) = bootstrapServers(applicationId.asJsonPrimitive())
249 fun applicationId(applicationId: JsonNode) =
250 property(KafkaStreamsConsumerProperties::applicationId, applicationId)
252 fun topic(topic: String) = topic(topic.asJsonPrimitive())
254 fun topic(topic: JsonNode) =
255 property(KafkaStreamsConsumerProperties::topic, topic)
257 fun autoOffsetReset(autoOffsetReset: String) = autoOffsetReset(autoOffsetReset.asJsonPrimitive())
259 fun autoOffsetReset(autoOffsetReset: JsonNode) =
260 property(KafkaStreamsConsumerProperties::autoOffsetReset, autoOffsetReset)
262 fun processingGuarantee(processingGuarantee: String) = processingGuarantee(processingGuarantee.asJsonPrimitive())
264 fun processingGuarantee(processingGuarantee: JsonNode) =
265 property(KafkaStreamsConsumerProperties::processingGuarantee, processingGuarantee)
268 class KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder : KafkaStreamsConsumerPropertiesAssignmentBuilder()