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.functions.message.prioritization.utils
19 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.CleanConfiguration
20 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.ExpiryConfiguration
21 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.KafkaConfiguration
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.NatsConfiguration
23 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.PrioritizationConfiguration
24 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.ShutDownConfiguration
25 import org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.db.MessagePrioritization
26 import org.onap.ccsdk.cds.controllerblueprints.core.utils.addDate
27 import org.onap.ccsdk.cds.controllerblueprints.core.utils.controllerDate
31 object MessagePrioritizationSample {
33 fun samplePrioritizationConfiguration(): PrioritizationConfiguration {
34 return PrioritizationConfiguration().apply {
35 kafkaConfiguration = KafkaConfiguration().apply {
36 inputTopicSelector = "prioritize-input"
37 outputTopic = "prioritize-output-topic"
38 expiredTopic = "prioritize-expired-topic"
40 natsConfiguration = NatsConfiguration().apply {
41 connectionSelector = "cds-controller"
42 inputSubject = "prioritize-input"
43 outputSubject = "prioritize-output"
44 expiredSubject = "prioritize-expired"
46 expiryConfiguration = ExpiryConfiguration().apply {
47 frequencyMilli = 10000L
50 shutDownConfiguration = ShutDownConfiguration().apply {
53 cleanConfiguration = CleanConfiguration().apply {
54 frequencyMilli = 10000L
55 expiredRecordsHoldDays = 5
60 fun sampleSchedulerPrioritizationConfiguration(): PrioritizationConfiguration {
61 return PrioritizationConfiguration().apply {
62 expiryConfiguration = ExpiryConfiguration().apply {
66 shutDownConfiguration = ShutDownConfiguration().apply {
69 cleanConfiguration = CleanConfiguration().apply {
71 expiredRecordsHoldDays = 5
76 private fun currentDatePlusDays(days: Int): Date {
77 return controllerDate().addDate(days)
80 fun sampleMessages(messageState: String, count: Int): List<MessagePrioritization> {
81 return sampleMessages("sample-group", messageState, count)
84 fun sampleMessages(groupName: String, messageState: String, count: Int): List<MessagePrioritization> {
85 val messages: MutableList<MessagePrioritization> = arrayListOf()
87 val backPressureMessage = createMessage(
88 groupName, messageState,
91 messages.add(backPressureMessage)
96 fun sampleMessageWithSameCorrelation(
100 ): List<MessagePrioritization> {
101 val messages: MutableList<MessagePrioritization> = arrayListOf()
103 val backPressureMessage = createMessage(
104 groupName, messageState, "sample-type",
105 "key1=value1,key2=value2"
107 messages.add(backPressureMessage)
112 fun sampleMessageWithDifferentTypeSameCorrelation(
114 messageState: String,
116 ): List<MessagePrioritization> {
117 val messages: MutableList<MessagePrioritization> = arrayListOf()
119 val backPressureMessage = createMessage(
120 groupName, messageState, "type-$it",
121 "key1=value1,key2=value2"
123 messages.add(backPressureMessage)
130 messageState: String,
132 messageCorrelationId: String?
133 ): MessagePrioritization {
135 return MessagePrioritization().apply {
136 id = UUID.randomUUID().toString()
140 priority = (1..10).shuffled().first()
141 correlationId = messageCorrelationId
142 message = "I am the Message"
145 expiryDate = currentDatePlusDays(3)