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.TopologyTemplateBuilder
28 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType
30 /** Relationships Types DSL for Message Producer */
31 fun BluePrintTypes.relationshipTypeConnectsToMessageProducer(): RelationshipType {
32 return relationshipType(
33 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER,
34 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
35 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
36 description = "Relationship connects to through message producer."
39 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
40 BluePrintConstants.DATA_TYPE_MAP,
42 "Connection Config details."
44 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
48 fun BluePrintTypes.relationshipTypeConnectsToMessageConsumer(): RelationshipType {
49 return relationshipType(
50 id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER,
51 version = BluePrintConstants.DEFAULT_VERSION_NUMBER,
52 derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO,
53 description = "Relationship type connects to message consumer."
56 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
57 BluePrintConstants.DATA_TYPE_MAP,
59 "Connection Config details."
61 validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT))
65 /** Relationships Templates DSL for Message Producer */
66 fun TopologyTemplateBuilder.relationshipTemplateMessageProducer(
69 block: MessageProducerRelationshipTemplateBuilder.() -> Unit
71 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
72 val relationshipTemplate =
73 MessageProducerRelationshipTemplateBuilder(name, description).apply(block).build()
74 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
77 class MessageProducerRelationshipTemplateBuilder(name: String, description: String) :
78 RelationshipTemplateBuilder(
80 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_PRODUCER, description
83 fun kafkaBasicAuth(block: KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit) {
85 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
86 BluePrintTypes.kafkaBasicAuthMessageProducerProperties(block)
91 fun BluePrintTypes.kafkaBasicAuthMessageProducerProperties(block: KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder.() -> Unit): JsonNode {
92 val assignments = KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder().apply(block).build()
93 assignments[KafkaBasicAuthMessageProducerProperties::type.name] =
94 MessageLibConstants.TYPE_KAFKA_BASIC_AUTH.asJsonPrimitive()
95 return assignments.asJsonType()
98 open class MessageProducerPropertiesAssignmentBuilder : PropertiesAssignmentBuilder()
100 class KafkaBasicAuthMessageProducerPropertiesAssignmentBuilder : MessageProducerPropertiesAssignmentBuilder() {
102 fun bootstrapServers(bootstrapServers: String) = bootstrapServers(bootstrapServers.asJsonPrimitive())
104 fun bootstrapServers(bootstrapServers: JsonNode) =
105 property(KafkaBasicAuthMessageProducerProperties::bootstrapServers, bootstrapServers)
107 fun topic(topic: String) = topic(topic.asJsonPrimitive())
109 fun topic(topic: JsonNode) =
110 property(KafkaBasicAuthMessageProducerProperties::topic, topic)
112 fun clientId(clientId: String) = bootstrapServers(clientId.asJsonPrimitive())
114 fun clientId(clientId: JsonNode) =
115 property(KafkaBasicAuthMessageProducerProperties::clientId, clientId)
117 fun acks(acks: String) = acks(acks.asJsonPrimitive())
119 fun acks(acks: JsonNode) = property(KafkaBasicAuthMessageProducerProperties::acks, acks)
121 fun retries(retries: Int) = retries(retries.asJsonPrimitive())
123 fun retries(retries: JsonNode) = property(KafkaBasicAuthMessageProducerProperties::retries, retries)
125 fun enableIdempotence(enableIdempotence: Boolean) = enableIdempotence(enableIdempotence.asJsonPrimitive())
127 fun enableIdempotence(enableIdempotence: JsonNode) =
128 property(KafkaBasicAuthMessageProducerProperties::enableIdempotence, enableIdempotence)
131 /** Relationships Templates DSL for Message Consumer */
132 fun TopologyTemplateBuilder.relationshipTemplateMessageConsumer(
135 block: MessageConsumerRelationshipTemplateBuilder.() -> Unit
137 if (relationshipTemplates == null) relationshipTemplates = hashMapOf()
138 val relationshipTemplate =
139 MessageConsumerRelationshipTemplateBuilder(name, description).apply(block).build()
140 relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate
143 class MessageConsumerRelationshipTemplateBuilder(name: String, description: String) :
144 RelationshipTemplateBuilder(
146 BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_MESSAGE_CONSUMER, description
149 fun kafkaBasicAuth(block: KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit) {
151 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
152 BluePrintTypes.kafkaBasicAuthMessageConsumerProperties(block)
156 fun kafkaStreamsBasicAuth(block: KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder.() -> Unit) {
158 BluePrintConstants.PROPERTY_CONNECTION_CONFIG,
159 BluePrintTypes.kafkaStreamsBasicAuthConsumerProperties(block)
164 fun BluePrintTypes.kafkaBasicAuthMessageConsumerProperties(block: KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode {
165 val assignments = KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder().apply(block).build()
166 assignments[KafkaBasicAuthMessageConsumerProperties::type.name] =
167 MessageLibConstants.TYPE_KAFKA_BASIC_AUTH.asJsonPrimitive()
168 return assignments.asJsonType()
171 fun BluePrintTypes.kafkaStreamsBasicAuthConsumerProperties(block: KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder.() -> Unit): JsonNode {
172 val assignments = KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder().apply(block).build()
173 assignments[KafkaStreamsBasicAuthConsumerProperties::type.name] =
174 MessageLibConstants.TYPE_KAFKA_STREAMS_BASIC_AUTH.asJsonPrimitive()
175 return assignments.asJsonType()
178 open class MessageConsumerPropertiesAssignmentBuilder : PropertiesAssignmentBuilder()
180 open class KafkaMessageConsumerPropertiesAssignmentBuilder : MessageConsumerPropertiesAssignmentBuilder() {
182 fun bootstrapServers(bootstrapServers: String) = bootstrapServers(bootstrapServers.asJsonPrimitive())
184 fun bootstrapServers(bootstrapServers: JsonNode) =
185 property(KafkaMessageConsumerProperties::bootstrapServers, bootstrapServers)
187 fun groupId(groupId: String) = groupId(groupId.asJsonPrimitive())
189 fun groupId(groupId: JsonNode) =
190 property(KafkaMessageConsumerProperties::groupId, groupId)
192 fun clientId(clientId: String) = clientId(clientId.asJsonPrimitive())
194 fun clientId(clientId: JsonNode) =
195 property(KafkaMessageConsumerProperties::clientId, clientId)
197 fun topic(topic: String) = topic(topic.asJsonPrimitive())
199 fun topic(topic: JsonNode) =
200 property(KafkaMessageConsumerProperties::topic, topic)
202 fun autoCommit(autoCommit: Boolean) = autoCommit(autoCommit.asJsonPrimitive())
204 fun autoCommit(autoCommit: JsonNode) =
205 property(KafkaMessageConsumerProperties::autoCommit, autoCommit)
207 fun autoOffsetReset(autoOffsetReset: String) = autoOffsetReset(autoOffsetReset.asJsonPrimitive())
209 fun autoOffsetReset(autoOffsetReset: JsonNode) =
210 property(KafkaMessageConsumerProperties::autoOffsetReset, autoOffsetReset)
212 fun pollMillSec(pollMillSec: Int) = pollMillSec(pollMillSec.asJsonPrimitive())
214 fun pollMillSec(pollMillSec: JsonNode) =
215 property(KafkaMessageConsumerProperties::pollMillSec, pollMillSec)
217 fun pollRecords(pollRecords: Int) = pollRecords(pollRecords.asJsonPrimitive())
219 fun pollRecords(pollRecords: JsonNode) =
220 property(KafkaMessageConsumerProperties::pollRecords, pollRecords)
223 /** KafkaBasicAuthMessageConsumerProperties assignment builder */
224 class KafkaBasicAuthMessageConsumerPropertiesAssignmentBuilder : KafkaMessageConsumerPropertiesAssignmentBuilder()
226 /** KafkaStreamsConsumerProperties assignment builder */
227 open class KafkaStreamsConsumerPropertiesAssignmentBuilder : MessageConsumerPropertiesAssignmentBuilder() {
229 fun bootstrapServers(bootstrapServers: String) = bootstrapServers(bootstrapServers.asJsonPrimitive())
231 fun bootstrapServers(bootstrapServers: JsonNode) =
232 property(KafkaStreamsConsumerProperties::bootstrapServers, bootstrapServers)
234 fun applicationId(applicationId: String) = bootstrapServers(applicationId.asJsonPrimitive())
236 fun applicationId(applicationId: JsonNode) =
237 property(KafkaStreamsConsumerProperties::applicationId, applicationId)
239 fun topic(topic: String) = topic(topic.asJsonPrimitive())
241 fun topic(topic: JsonNode) =
242 property(KafkaStreamsConsumerProperties::topic, topic)
244 fun autoOffsetReset(autoOffsetReset: String) = autoOffsetReset(autoOffsetReset.asJsonPrimitive())
246 fun autoOffsetReset(autoOffsetReset: JsonNode) =
247 property(KafkaStreamsConsumerProperties::autoOffsetReset, autoOffsetReset)
249 fun processingGuarantee(processingGuarantee: String) = processingGuarantee(processingGuarantee.asJsonPrimitive())
251 fun processingGuarantee(processingGuarantee: JsonNode) =
252 property(KafkaStreamsConsumerProperties::processingGuarantee, processingGuarantee)
255 class KafkaStreamsBasicAuthConsumerPropertiesAssignmentBuilder : KafkaStreamsConsumerPropertiesAssignmentBuilder()